Post-completion factory improvement analysis. Guides the retrospective agent through artifact discovery, pattern analysis, suggestion generation, and presenting proposed changes for approval. Use when the retrospective agent starts its post-completion phase.
This skill guides the retrospective agent through analyzing a completed session and producing actionable improvements to the factory. The goal is to make the factory better over time by examining what happened, identifying patterns, and proposing concrete changes to skills, agent prompts, and AGENTS.md.
Core principle: Evidence-based improvement. Every suggestion must be grounded in artifacts from the session, not speculation.
state.json PathsThere are TWO different state.json files in the system:
.sgai/retrospectives/<session-id>/state.json — A snapshot of the workflow state captured at session end. This file MAY NOT always exist (it depends on whether the session completed normally and the copy was made)..sgai/state.json — The live workflow state file. This file is ALWAYS present after the factory starts.Fallback logic (use this whenever a step says to "read state.json"):
.sgai/retrospectives/<session-id>/state.json (the session copy).sgai/state.json (always present)CRITICAL: You MUST write to .sgai/SGAI_NOTES.md EARLY and REPEATEDLY throughout the retrospective. This file records internal factory operational notes — how the factory could operate better, known internal issues, and agent patterns. It is distinct from AGENTS.md, which contains project-level instructions. It must be written incrementally so that partial analysis is preserved even if the retrospective is interrupted.
Always APPEND (not replace) a new dated section to .sgai/SGAI_NOTES.md:
## Factory Health Notes (YYYY-MM-DD)
### Status
[in-progress | complete]
### Known Issues
- [issue descriptions from this session]
### Agent Patterns
- [patterns observed across agents]
### Efficiency Suggestions
- [suggestions for improving factory efficiency]
Write to .sgai/SGAI_NOTES.md at these specific moments — do NOT wait until the end:
If the retrospective is interrupted between steps, the most recently written state persists in SGAI_NOTES.md.
Before writing, always read the current .sgai/SGAI_NOTES.md to append without overwriting prior sessions:
1. Read .sgai/SGAI_NOTES.md (it may or may not exist)
2. If it exists, append your new dated section
3. If it does not exist, create it with just your new dated section
Read artifacts in THIS ORDER (priority matters — richest signal sources first):
state.json FIRST (highest priority).sgai/PROJECT_MANAGEMENT.md frontmatter to find the retrospective session directory path (key: Retrospective Session: .sgai/retrospectives/<session-id>)state.json FIRST — This is the single richest signal source. Use fallback logic: try .sgai/retrospectives/<session-id>/state.json first; if missing, fall back to .sgai/state.json. It contains:
.sgai/retrospectives/<session-id>/state.json AND .sgai/state.json are missing or unreadable, STOP and report this in your analysis log — do NOT proceed to Step 2 without acknowledging this gap.sgai/SGAI_NOTES.md with format:
## Factory Health Notes (YYYY-MM-DD)
### Status
in-progress
### Known Issues
- [Any obvious issues seen in state.json so far]
### Agent Patterns
- Visit counts: [agent: N visits, ...]
- Message count: [N total inter-agent messages]
### Efficiency Suggestions
- [Preliminary thoughts, to be refined]
GOAL.md copy (what was supposed to happen)PROJECT_MANAGEMENT.md copy (what actually happened — decisions, issues, backtracks)NNNN-<agent>-<timestamp>.json) — these contain the full conversation transcriptsReading session JSONs: Process files in numerical order (0001, 0002, ...). Each contains the full transcript for one agent iteration. Focus on:
stdout.log and stderr.log for build/test output signalsAGENTS.md exists in the repository rootAGENTS.md MISSING as an artifact finding — this will trigger a creation proposal in Step 2.5Session directory structure:
.sgai/retrospectives/<session-id>/
├── GOAL.md
├── PROJECT_MANAGEMENT.md
├── state.json # Session copy (MAY NOT EXIST — use .sgai/state.json as fallback)
├── stdout.log
├── stderr.log
├── screenshots/
└── NNNN-<agent>-<timestamp>.json # Session transcripts
GATE: You MUST complete this step before proceeding to Step 2. You may NOT skip this step.
After reading all artifacts in Step 1, write a structured analysis summary to your progress notes using sgai_update_workflow_state. This summary MUST contain:
state.json (or .sgai/state.json fallback) — which agents ran, how many visits eachstate.json (or .sgai/state.json fallback) — total inter-agent messages, notable message patternsIf you cannot produce at least 1 observation per category:
Example analysis log:
Analysis Summary:
- Files: Read 15/15 session JSONs, session state.json (from .sgai/retrospectives/<session-id>/state.json), GOAL.md, PROJECT_MANAGEMENT.md, stdout.log, stderr.log
- Visits: coordinator(8), backend-go-developer(3), go-readability-reviewer(2), react-developer(1), project-critic-council(1)
- Messages: 19 inter-agent messages, 3 reviewer feedback rounds
- Efficiency: Backend developer visited 3 times due to reviewer feedback — could skills reduce this?
- Quality: Reviewer caught SQL formatting issues 3 times — suggests missing skill
- Knowledge gaps: Agent asked about migration workflow mid-session — no skill exists for this
- Process gaps: stpa-analyst.md was a 17-line stub that needed emergency expansion in-session
- AGENTS.md Health: AGENTS.md present (53 lines), 2 rules appear stale (no React code was modified but 4 React-specific rules exist), no contradictions detected
After completing the analysis log, UPDATE .sgai/SGAI_NOTES.md with the per-category observations:
### Agent Patterns
- [Updated with observations from analysis log]
### Known Issues
- [Updated with quality and process gap observations]
Analyze the artifacts for these signal types:
state.json (or .sgai/state.json fallback), how many times was each agent visited? High counts suggest rework or unclear instructions.GATE: This step is MANDATORY. You may NOT skip it, even if other analysis steps produced sufficient findings.
Analyze AGENTS.md health across five dimensions:
.sgai/SGAI_NOTES.md exists, check for historical patterns)AGENTS-go.md, AGENTS-react.md)For each pattern identified in Step 2 and Step 2.5, produce a concrete suggestion. Each suggestion must have:
new-skill, modify-skill, new-agent-prompt, modify-agent-prompt, update-agents-md, create-agents-md, restructure-agents-mdAfter generating suggestions, UPDATE .sgai/SGAI_NOTES.md with the suggestion list:
### Efficiency Suggestions
- [List of suggestions from Step 3, even before human approval]
Before presenting any suggestion, verify the target path:
.sgai/ (except .sgai/SGAI_NOTES.md).sgai/, translate it to the sgai/ overlay equivalent:
.sgai/agent/foo.md -> sgai/agent/foo.md.sgai/skills/bar/SKILL.md -> sgai/skills/bar/SKILL.md.sgai/ directory is the runtime directory rebuilt from skeleton + overlay on every startup — changes there are lost immediatelyNew Skills (sgai/skills/<name>/SKILL.md)
Modify Existing Skills (sgai/skills/<name>/SKILL.md)
New/Modified Agent Prompts (sgai/agent/<name>.md)
Update AGENTS.md
AGENTS.md-specific suggestion types (from Step 2.5):
| Trigger | Suggestion Type | What to Propose |
|---|---|---|
| AGENTS.md missing | create-agents-md | Create AGENTS.md pre-populated with observed session patterns. Extract style rules, conventions, and recurring human corrections into a structured initial file. |
| Contradiction found | update-agents-md | Either update the contradicted rule to match the human's new preference, or remove it if clearly outdated. Always cite the session evidence. |
| Stale rule found | update-agents-md | Propose removal of the stale rule with rationale explaining why it's no longer relevant. |
| File too large | restructure-agents-md | Propose splitting AGENTS.md into multiple files. Specify which rules go where and provide proposed filenames. |
| Override pattern found | update-agents-md | Propose either relaxing the rule or removing it, based on the pattern of agents/humans consistently ignoring it. |
new-skill and modify-skillnew-agent-prompt and modify-agent-promptupdate-agents-md, create-agents-md, and restructure-agents-mdImpact assessment:
| Impact Level | Criteria |
|---|---|
| High | Would have saved 3+ iterations or prevented a major backtrack |
| Medium | Would have improved clarity or reduced one review round |
| Low | Nice-to-have, minor improvement |
PREREQUISITES — You may NOT invoke this case unless ALL of the following are true:
state.json (via .sgai/retrospectives/<session-id>/state.json, or the .sgai/state.json fallback) and recorded visit counts and message counts in your analysis logIf ALL prerequisites are met and you genuinely have zero actionable suggestions after thorough analysis, send RETRO_COMPLETE and exit:
sgai_send_message({
toAgent: "coordinator",
body: "RETRO_COMPLETE: No actionable improvements identified for this session. Analysis summary: Read X/Y session JSONs, session state.json (from [path used]) showed Z agent visits and W messages. Per-category findings: [brief summary of each category observation from Step 1.5]."
})
sgai_update_workflow_state({ status: "agent-done", task: "", addProgress: "No actionable suggestions found after thorough analysis. Sent RETRO_COMPLETE." })
// STOP HERE. Make NO more tool calls. Your turn is OVER.
// This means: no check_inbox, no check_outbox, no file reads, no file writes, no bash, NOTHING.
// Extra tool calls cause system deadlock requiring manual SIGTERM.
CRITICAL: The RETRO_COMPLETE message MUST include your analysis summary (files read, visit counts, per-category observations) as proof that you actually completed the analysis. A bare "No actionable improvements identified" without evidence is NOT acceptable.
MANDATORY YIELD PROTOCOL: After every sgai_send_message() call in this step, you MUST:
sgai_update_workflow_state({status: "agent-done"})check_inbox or check_outbox — the coordinator cannot respond until you yieldMANDATORY: You MUST send at least one RETRO_QUESTION: message to the coordinator during your run. This is NOT optional. If you found zero suggestions, follow the "No Suggestions Case" above instead.
Present proposed changes to the human partner by sending RETRO_QUESTION: messages to the coordinator, grouped by category. For each non-empty category bucket (Skills, Agent Prompts, AGENTS.md), send ONE message containing ALL proposals in that category.
For each non-empty category, send a single RETRO_QUESTION with this structure:
sgai_send_message({
toAgent: "coordinator",
body: "RETRO_QUESTION [MULTI-SELECT]: **Skills Changes** (N proposals)\n\n### 1. [Title of first proposal]\nEvidence: [1-line evidence from session artifacts]\n```diff\n--- a/[file path]\n+++ b/[file path]\n@@ ... @@\n[unified diff content]\n```\nRationale: [why this helps future sessions]\n\n### 2. [Title of second proposal]\nEvidence: [1-line evidence]\n[full proposed file content for new files, or diff for modifications]\nRationale: [why this helps]\n\nSelect which to approve (multi-select):\n- 1. [Title of first proposal]\n- 2. [Title of second proposal]"
})
// Then yield immediately
sgai_update_workflow_state({ status: "agent-done", task: "Waiting for human response via coordinator", addProgress: "Sent Skills category RETRO_QUESTION to coordinator" })
// STOP HERE. Make NO more tool calls. Do NOT check inbox or outbox. Your turn is OVER.
// This means: no check_inbox, no check_outbox, no file reads, no file writes, no bash, NOTHING.
// Extra tool calls cause system deadlock requiring manual SIGTERM.
sgai_send_message({
toAgent: "coordinator",
body: "RETRO_QUESTION [MULTI-SELECT]: **Skills Changes** (2 proposals)\n\n### 1. Add SQL formatting section to go-code-review\nEvidence: Reviewer flagged SQL formatting 3 times in session\n```diff\n--- a/sgai/skills/go-code-review/SKILL.md\n+++ b/sgai/skills/go-code-review/SKILL.md\n@@ -45,6 +45,12 @@\n+## SQL Formatting\n+- Align VALUES with INSERT columns\n+- Each column on its own line\n```\nRationale: Prevents repeated reviewer catches\n\n### 2. Create db-migration-testing skill\n[full proposed file content]\nRationale: Standardizes migration testing workflow\n\nSelect which to approve (multi-select):\n- 1. Add SQL formatting section to go-code-review\n- 2. Create db-migration-testing skill"
})
sgai_update_workflow_state({ status: "agent-done", task: "Waiting for human response via coordinator", addProgress: "Sent Skills RETRO_QUESTION to coordinator" })
// STOP HERE. Your turn is OVER.
// This means: no check_inbox, no check_outbox, no file reads, no file writes, no bash, NOTHING.
// Extra tool calls cause system deadlock requiring manual SIGTERM.
When the coordinator relays the human's response (which numbered items were selected):
RETRO_QUESTION [MULTI-SELECT]:[MULTI-SELECT] marker — So the coordinator knows to use multiSelect: true when relayingApply only the individually-approved changes. Skip any rejected or unselected changes entirely.
The sgai/ directory is an overlay — files placed there wholly replace their skeleton defaults. This has critical implications for how you apply changes:
For MODIFYING an existing skill, agent prompt, or snippet:
.sgai/ (the live runtime directory — skeleton + overlay merged)sgai/ (the overlay directory)For CREATING a new skill, agent prompt, or snippet:
sgai/CRITICAL: Partial edits are NOT possible via the overlay. Every file in sgai/ must be a complete, self-contained version of the file it overrides. If you write only your changes without the rest of the file content, the original content will be lost.
For each approved change:
.sgai/ first, then write the COMPLETE modified version to sgai/sgai/sgai/ overlay or AGENTS.md)SKILL.md with YAML frontmatter (name, description)sgai/agent/ overlay directoryNew skills must follow the Agent Skills spec:
---