agent-orchestrator-kit 0.1.14 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +50 -16
  3. package/bin/agent-orchestrator.js +405 -3
  4. package/package.json +1 -1
  5. package/profiles/generic/orchestrator.yaml +2 -1
  6. package/profiles/mvp/openspec-config.yaml.example +2 -0
  7. package/profiles/mvp/orchestrator.yaml +2 -1
  8. package/profiles/node/orchestrator.yaml +2 -1
  9. package/profiles/vue3/openspec-config.yaml.example +2 -0
  10. package/profiles/vue3/orchestrator.yaml +2 -1
  11. package/templates/.agents/commands/opsx-apply.md +18 -46
  12. package/templates/.agents/commands/opsx-archive.md +10 -163
  13. package/templates/.agents/commands/opsx-design.md +3 -10
  14. package/templates/.agents/commands/opsx-explore.md +3 -10
  15. package/templates/.agents/commands/opsx-propose.md +14 -10
  16. package/templates/.agents/commands/opsx-quick.md +3 -10
  17. package/templates/.agents/commands/opsx-review.md +27 -55
  18. package/templates/.agents/commands/opsx-sync.md +2 -0
  19. package/templates/.agents/rules/agent-orchestration.mdc +21 -69
  20. package/templates/.agents/rules/figma-token-setup.mdc +1 -1
  21. package/templates/.agents/rules/memory-mcp-autosetup.mdc +4 -67
  22. package/templates/.agents/rules/session-handoff.mdc +21 -37
  23. package/templates/.agents/skills/agent-orchestration/SKILL.md +28 -29
  24. package/templates/.agents/skills/openspec-apply-change/SKILL.md +15 -20
  25. package/templates/.agents/skills/openspec-archive-change/SKILL.md +12 -99
  26. package/templates/.agents/skills/openspec-propose/SKILL.md +11 -0
  27. package/templates/.agents/subagents/session-handoff.md +5 -5
  28. package/templates/.agents/subagents/spec-architect.md +1 -1
  29. package/templates/.agents/subagents/spec-archiver.md +1 -1
  30. package/templates/.agents/subagents/spec-reviewer.md +11 -7
  31. package/templates/AGENTS.md +22 -124
  32. package/templates/CLAUDE.md +6 -68
  33. package/templates/orchestrator.yaml +2 -1
@@ -5,9 +5,9 @@ category: Workflow
5
5
  description: Read-only spec review of an OpenSpec change — approve or request changes before apply
6
6
  ---
7
7
 
8
- ## Session Start (Before Any Work)
8
+ ## Session Start
9
9
 
10
- Honor the pasted command and announce the Spec Reviewer role. Run `npx agent-orchestrator-kit status` or `npx openspec list --json`, then `npx agent-orchestrator-kit handoff --restore` (or `handoff <name> --restore`). Read Memory `Change:<name>`, `Handoff:<name>`, and `Decision:*` when MCP works. If restore CLI fails and Memory is empty, read `openspec/changes/<name>/handoff.md`; this fallback is not a blocker. Spawn `session-handoff` in restore mode when context is incomplete (Amp: isolated `subagent-session-handoff`). For free-form “continue” / “next” with one active change, execute its `Handoff.next_command` instead of asking for the phase. Only then spawn the routed phase specialist (Amp: isolated `subagent-<name>`, never the main thread). Follow `.agents/rules/session-handoff.mdc`.
10
+ Follow the canonical Session Start protocol in `.agents/rules/session-handoff.mdc`, then announce the Spec Reviewer role.
11
11
 
12
12
  Review an OpenSpec change. Read artifacts, validate structure, output Approve or Request Changes.
13
13
 
@@ -15,7 +15,7 @@ Review an OpenSpec change. Read artifacts, validate structure, output Approve or
15
15
 
16
16
  **Input**: Optionally specify a change name (e.g., `/opsx:review add-auth`). If omitted, auto-select if one active change exists, otherwise list and ask.
17
17
 
18
- **Conductor delegation is mandatory:** after selecting the change, spawn `spec-reviewer` with the complete change paths and project constraints. The parent MUST NOT review artifacts or write `review.md`; it only verifies the structured report and that `review.md` contains the reported verdict. Never substitute `code-reviewer`.
18
+ **Review is two-tiered:** Tier 1 is a deterministic script (`gate-check --review`) run by the parent **before** any artifact is read by an LLM. Tier 2 is the `spec-reviewer` subagent with a shortened, LLM-only checklist. Spawning `spec-reviewer` is mandatory only when Tier 1 passes. The parent MUST NOT review artifacts or write `review.md` itself when Tier 2 runs. Never substitute `code-reviewer`.
19
19
 
20
20
  ---
21
21
 
@@ -30,59 +30,36 @@ If name provided — use it. Otherwise:
30
30
 
31
31
  Announce: "Reviewing change: **<name>**"
32
32
 
33
- ### 2. Spawn the specialist
34
-
35
- Spawn `spec-reviewer` and delegate steps 3–6 below. Require `## Subagent report: spec-reviewer`. Do not perform the review in the parent session.
36
-
37
- ### 3. Validate structure
33
+ ### 2. Tier 1 — deterministic gate-check
38
34
 
39
35
  ```bash
40
- npx openspec validate <name> --strict --type change
36
+ npx agent-orchestrator-kit gate-check --review <name>
41
37
  ```
42
38
 
43
- If list each error and immediately output **Request Changes** with the validation errors. Stop here.
39
+ The script runs `openspec validate --strict --type change`, the task-contract lint (Files/Do/Done-when), the `Non-goals` / `Acceptance criteria` proposal sections check, and non-empty ADDED/MODIFIED/REMOVED delta-spec sections check. Add `--json` for a `{pass, errors[]}` report.
44
40
 
45
- ### 4. Read all artifacts
41
+ **If Tier 1 fails (exit ≠ 0):** do NOT spawn `spec-reviewer` and do NOT read the artifacts. Write `openspec/changes/<name>/review.md` with `Verdict: REQUEST CHANGES` listing the gate-check errors (source: gate-check), output the Request Changes verdict in chat, and go straight to Session Exit.
46
42
 
47
- ```bash
48
- npx openspec status --change "<name>" --json
49
- ```
43
+ ### 3. Tier 2 — spawn the specialist
50
44
 
51
- Read every file from `artifactPaths`:
52
- - `proposal.md`
53
- - `design.md`
54
- - `tasks.md`
55
- - all `specs/<domain>/spec.md` files
45
+ Only after Tier 1 passes: spawn `spec-reviewer` with the complete change paths, project constraints, and the shortened checklist below. Require `## Subagent report: spec-reviewer`. Do not perform the review in the parent session.
56
46
 
57
- Also read related `openspec/specs/` domain files to check consistency.
47
+ ### 4. Review checklist (Tier 2 LLM-only)
58
48
 
59
- ### 5. Review checklist
49
+ Do NOT re-check what Tier 1 already covered (strict validation, contract field presence, proposal sections, delta-spec section structure). Evaluate each item. Mark ✓ or ✗:
60
50
 
61
- Evaluate each item. Mark ✓ or ✗:
51
+ **Consistency**
52
+ - [ ] proposal ↔ design ↔ tasks tell the same story — no contradictions or drift
53
+ - [ ] Delta specs cover all changed/added behavior described in design
62
54
 
63
- **Proposal**
64
- - [ ] Problem statement is clear and specific (not vague)
65
- - [ ] Non-goals are listed
66
- - [ ] Acceptance criteria are present and testable (not "should work" — must be verifiable)
67
- - [ ] Scope matches a ~1–3 day change
55
+ **Main specs**
56
+ - [ ] No conflicts with existing `openspec/specs/` requirements
68
57
 
69
- **Design**
70
- - [ ] Approach is concrete (not "we will handle this")
71
- - [ ] Trade-offs or alternatives mentioned
72
- - [ ] Does not contradict existing `openspec/specs/` domain specs
58
+ **Scope**
73
59
  - [ ] No scope creep vs proposal Non-goals
74
60
 
75
- **Tasks**
76
- - [ ] Each task is ~2 hours of work
77
- - [ ] Each task has a clear done condition
78
- - [ ] Tasks are in logical implementation order
79
- - [ ] No task requires information not in design/spec
80
- - [ ] No task says "update X as needed" (must be specific)
81
-
82
- **Delta Specs**
83
- - [ ] Cover all changed/added behavior
84
- - [ ] ADDED/MODIFIED/REMOVED sections used correctly
85
- - [ ] No conflicts with main `openspec/specs/`
61
+ **Task self-sufficiency**
62
+ - [ ] A blind implementer can execute each task from Files/Do/Done-when alone, without reading design.md
86
63
 
87
64
  **Vue 3** (when `project.stack: vue3` in `.agents/orchestrator.yaml`)
88
65
  - [ ] Components use `<script setup>` + Composition API (no Options API)
@@ -91,7 +68,7 @@ Evaluate each item. Mark ✓ or ✗:
91
68
  - [ ] Tasks reference concrete component/store paths under `src/`
92
69
  - [ ] No scope creep into unrelated UI refactors
93
70
 
94
- ### 6. Write and report the verdict
71
+ ### 5. Write and report the verdict
95
72
 
96
73
  #### If all ✓ (or only minor notes):
97
74
 
@@ -131,11 +108,13 @@ Create or update `openspec/changes/<name>/review.md`:
131
108
  <optional notes>
132
109
  ```
133
110
 
134
- For **REQUEST CHANGES**, write the same file with `Verdict: REQUEST CHANGES` and issues list.
111
+ On **APPROVE**, `spec-reviewer` also writes `openspec/changes/<name>/apply-notes.md` (≤ 20 lines): critical constraints, pitfalls, what NOT to touch, verification commands. It is the distilled input for `/opsx:apply` and the **second allowed file** next to `review.md`.
112
+
113
+ For **REQUEST CHANGES**, write only `review.md` with `Verdict: REQUEST CHANGES` and the issues list.
135
114
 
136
- This is the **only file** you may write during review (not `src/`, not `tasks.md` checkboxes).
115
+ `review.md` (always) and `apply-notes.md` (on APPROVE) are the **only files** you may write during review (not `src/`, not `tasks.md` checkboxes).
137
116
 
138
- The conductor verifies the subagent's `Status: done`, checks that `review.md` exists with the reported verdict, and relays the result without editing it.
117
+ The conductor verifies the subagent's `Status: done`, checks that `review.md` exists with the reported verdict (and `apply-notes.md` on APPROVE), and relays the result without editing them.
139
118
 
140
119
  #### If any ✗:
141
120
 
@@ -162,19 +141,12 @@ Fix the above, then re-run `/opsx:review <name>`.
162
141
 
163
142
  ## Session Exit (HARD STOP)
164
143
 
165
- You have NOT finished until every step succeeds. Do not say done/готово, do not start apply, and do not omit the fenced next-thread prompt.
166
-
167
- 1. Spawn `session-handoff` in persist mode (Amp: isolated `subagent-session-handoff`). If spawn fails, persist in the parent — never skip.
168
- 2. Write `openspec/changes/<name>/handoff.md` with: Closed role, Change, Done, Decisions, Blocked, Next command, Next role, Attach, Subagents to spawn, Constraints.
169
- 3. Run `npx agent-orchestrator-kit handoff <name>` and require exit 0. The CLI upserts Memory JSON (absolute path) and prints the expanded self-contained prompt on stdout.
170
- 4. If Memory MCP tools work, also update `Change:<name>`, `Handoff:<name>`, and new `Decision:*`.
171
- 5. Paste CLI stdout into chat as one fenced block beginning with the next `/opsx:*` command (`/opsx:apply <name>` only after APPROVE). Keep it complete. No banner.
172
- 6. Stop. Do not start the next phase in this chat.
144
+ Close via the canonical Session Exit protocol in `.agents/rules/session-handoff.mdc`. First line of the pasted prompt is the next `/opsx:*` command (`/opsx:apply <name>` only after APPROVE). Do not start the next phase in this chat.
173
145
 
174
146
  ## Guardrails
175
147
 
176
148
  - **Never** edit source code, `src/`, or `tasks.md` checkboxes
177
- - **May write only** `openspec/changes/<name>/review.md` (verdict record for apply gate)
149
+ - **May write only** `openspec/changes/<name>/review.md` (verdict record for apply gate) and, on APPROVE, `openspec/changes/<name>/apply-notes.md`
178
150
  - **Never** run apply commands
179
151
  - Ask for clarification only if a critical artifact is missing or unreadable
180
152
  - If proposal is ambiguous on scope, flag as ✗ — do not assume intent
@@ -7,6 +7,8 @@ description: Sync delta specs from a change to main specs
7
7
 
8
8
  Sync delta specs from a change to main specs.
9
9
 
10
+ If run as a standalone `/opsx:*` session, follow the canonical Session Start / Session Exit protocol in `.agents/rules/session-handoff.mdc`.
11
+
10
12
  This is an **agent-driven** operation - you will read delta specs and directly edit main specs to apply the changes. This allows intelligent merging (e.g., adding a scenario without copying the entire requirement).
11
13
 
12
14
  **Input**: Optionally specify a change name after `/opsx:sync` (e.g., `/opsx:sync add-auth`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
@@ -5,78 +5,30 @@ alwaysApply: true
5
5
 
6
6
  # Agent Orchestration Rules
7
7
 
8
- This project uses a spec-driven role pipeline. Read `.agents/orchestrator.yaml` for config.
8
+ Spec-driven pipeline. Read `.agents/orchestrator.yaml`. Details: skill `agent-orchestration`. Handoff: `.agents/rules/session-handoff.mdc`. CLI: `npx` only (`.agents/rules/cli-via-npm.mdc`).
9
9
 
10
- ## Role Commands
11
- - `/opsx:explore` read-only thinking, no code
12
- - `/opsx:design <name>` → writes only `design-brief.md` + `assets/` (optional design intake)
13
- - `/opsx:propose <name>` → creates `openspec/changes/<name>/` artifacts only
14
- - `/opsx:review <name>` → read-only spec review, writes `review.md`, outputs Approve or Request Changes
15
- - `/opsx:apply <name>` → writes `src/`, marks `tasks.md [x]` (blocked if no review when `require_spec_review: true`)
16
- - `/opsx:quick <name>` → MVP: propose + apply in one session (when `require_spec_review: false`)
17
- - `/opsx:archive` → merges delta specs, moves change to archive
10
+ ## Commands
11
+ `/opsx:explore` read-only · `/opsx:design <name>` brief+assets only · `/opsx:propose <name>` change artifacts · `/opsx:review <name>` review.md · `/opsx:apply <name>` code (blocked without Approve when `require_spec_review`) · `/opsx:quick <name>` MVP propose+apply · `/opsx:archive`
18
12
 
19
- ## Conductor Routing (Mandatory and Exclusive)
13
+ The parent `/opsx:*` session is the **conductor**. Delegation is differentiated by phase: propose/review MUST spawn their specialist; apply is parent-driven with optional subagents; archive is a CLI call with phase subagents forbidden. Only the parent marks `tasks.md`. `spec-reviewer` ≠ `code-reviewer`.
20
14
 
21
- The parent `/opsx:*` session is the conductor. For specialist work it MUST spawn the one subagent selected below with a self-contained prompt, MUST verify the structured report, and MUST NOT perform that specialist's work itself. One signal maps to one primary subagent; do not substitute a generic agent.
15
+ | Phase / signal | Subagent | Status |
16
+ |--------|------------|--------|
17
+ | Status / gate / next command | `openspec-guide` | optional |
18
+ | Restore/persist when handoff CLI failed | `session-handoff` | fallback only |
19
+ | Broken kit / MCP / sync | `setup-doctor` | on signal |
20
+ | `/opsx:explore` | `codebase-explorer` | mandatory |
21
+ | `/opsx:design` | `design-intake` | mandatory |
22
+ | `/opsx:propose` | `spec-architect` | mandatory |
23
+ | `/opsx:review` (after `gate-check --review` passes) | `spec-reviewer` | mandatory |
24
+ | Apply + design brief/Figma/image | `design-implementer` | mandatory on signal |
25
+ | Apply: ≥ 2 independent tasks, no shared files, or explicit request | `code-writer` / `test-writer` | optional |
26
+ | Apply pre-PR | `code-reviewer` | optional |
27
+ | `/opsx:archive` | — use `npx agent-orchestrator-kit archive <name>` | CLI; subagent forbidden (`spec-archiver` = CLI-failure fallback only) |
22
28
 
23
- | Phase / signal | MUST spawn | Specialist scope the conductor MUST NOT do |
24
- |----------------|------------|--------------------------------------------|
25
- | Status, gate failure, next command | `openspec-guide` | Pipeline diagnosis |
26
- | Session start restore / session exit persist | `session-handoff` | Memory, `handoff.md`, next-thread prompt |
27
- | Broken kit, MCP, or generated-file sync | `setup-doctor` | Kit setup repair |
28
- | `/opsx:explore` repository investigation | `codebase-explorer` | Repository research; no specs or code |
29
- | `/opsx:design` | `design-intake` | `design-brief.md` and `assets/` |
30
- | `/opsx:propose` | `spec-architect` | Change proposal/design/specs/tasks |
31
- | `/opsx:review` | `spec-reviewer` | Pre-apply spec verdict and `review.md` |
32
- | Apply task with design brief/Figma/image | `design-implementer` | UI implementation |
33
- | Apply ordinary implementation task | `code-writer` | One task's production code |
34
- | Apply after implementation | `test-writer` | Automated tests |
35
- | Apply before PR/MR | `code-reviewer` | Post-implementation spec review |
36
- | `/opsx:archive` | `spec-archiver` | Delta merge and archive move |
29
+ ## Session
30
+ Start: honor pasted `/opsx:*` → `npx agent-orchestrator-kit status` → `handoff --restore`. Spawn `session-handoff` restore **only if** restore CLI failed or printed no briefing (Amp: isolated `subagent-session-handoff`). Then spawn the phase specialist isolated. Free-form continue → `Handoff.next_command`.
37
31
 
38
- `spec-reviewer` is never interchangeable with `code-reviewer`. During apply, only the conductor may mark a `tasks.md` checkbox, and only after a subagent reports `Status: done` and the conductor verifies the reported files.
32
+ Exit HARD STOP: persist via `session-handoff` `handoff.md` `npx agent-orchestrator-kit handoff <name>` (exit 0) paste CLI stdout as one fenced `/opsx:*` prompt. Do not start the next phase here.
39
33
 
40
- ## Session Start Protocol (Before Any Specialist Work)
41
-
42
- 1. Honor the pasted `/opsx:<phase> <name>` command and announce that role.
43
- 2. Run `npx agent-orchestrator-kit status` or `npx openspec list --json`; resolve the active change without exceeding `max_active_changes`.
44
- 3. Run `npx agent-orchestrator-kit handoff --restore` (or `handoff <name> --restore`). Use the printed briefing.
45
- 4. Read Memory entities `Change:<name>`, `Handoff:<name>`, and `Decision:*` when MCP works.
46
- 5. If restore CLI fails and Memory is empty, read `openspec/changes/<name>/handoff.md`. Memory failure alone MUST NOT block the session when the file exists.
47
- 6. Spawn `session-handoff` in restore mode when context is incomplete (Amp: isolated `subagent-session-handoff`, never the main thread).
48
- 7. Only after context is restored, spawn the routed phase specialist. Amp MUST spawn `subagent-<name>` isolated.
49
-
50
- If the user says “continue” / “next” / «продовжуй» / «далі» without a command and exactly one active change has `Handoff.next_command` (from Memory, CLI restore, or `handoff.md`), execute that command instead of asking which phase to run.
51
-
52
- Follow `.agents/rules/session-handoff.mdc`.
53
-
54
- ## Session Exit Protocol (HARD STOP)
55
-
56
- A phase is not closed until the conductor performs these steps in order. FORBIDDEN: saying done/готово, starting the next phase, or omitting the fenced prompt.
57
-
58
- 1. Spawn `session-handoff` in persist mode (Amp: isolated `subagent-session-handoff`). If spawn fails, persist in the parent — never skip.
59
- 2. Write `openspec/changes/<name>/handoff.md` with sections **Closed role**, **Change**, **Done**, **Decisions**, **Blocked**, **Next command**, **Next role**, **Attach**, **Subagents to spawn**, and **Constraints**. Do this even if Memory MCP is unavailable.
60
- 3. Run `npx agent-orchestrator-kit handoff <name>` and require exit 0. The CLI upserts `.cursor/memory.json` with an absolute path and prints the expanded self-contained next-session prompt on stdout.
61
- 4. If Memory MCP tools work, also update `Change:<name>` (`status`, `tasks n/m`, `last_role`, `review`), `Handoff:<name>` (`next_role`, `next_command`, `session_count`, `summary`, `blocked`), and each new `Decision:<topic>` (`chosen`, `reason`).
62
- 5. Paste the CLI stdout as one fenced copy/paste prompt. First line MUST be `/opsx:<next> <name>`; body MUST use `project.agent_language`; MUST keep Done/Decisions/Blocked/spawn/HARD STOP complete. Do not add a banner or shorten the prompt. Amp often skips Memory MCP — the pasted prompt is the next thread's operating brief.
63
- 6. Do NOT start the next phase in this chat.
64
-
65
- ## Session Rules
66
- - One active change at a time (unless mvp profile: up to 3)
67
- - Each role = new chat session (except `/opsx:quick` combines propose+apply)
68
- - No code in explore, design, or review sessions
69
- - Design Intake may write only `openspec/changes/<name>/design-brief.md` and `assets/`
70
- - No apply without review when `pipeline.require_spec_review: true` — check `review.md` or Approve in context
71
- - When `require_design_brief: true` and the change touches UI — need `design-brief.md`, or `Design: none` in `proposal.md` for non-UI
72
- - Apply uses the design brief, not live Figma MCP
73
- - After apply: build + lint before PR
74
- - After merge: run `/opsx:archive` (when `archive_after_merge: true`)
75
- - CLI: `npx agent-orchestrator-kit status`, `npx openspec …` — never bare globals (see `cli-via-npm.mdc`)
76
-
77
- ## Never
78
- - Mix propose and apply in one session
79
- - Edit `src/` during explore, design, or review
80
- - Skip spec review before apply
81
- - Call live Figma MCP during apply when a design brief exists
82
- - Leave changes un-archived after merge
34
+ Never mix propose+apply (except `/opsx:quick`). No `src/` in explore/design/review. Skip live Figma during apply when a brief exists.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  description: Figma personal access token setup — local env file, never ask for token in chat
3
- alwaysApply: true
3
+ alwaysApply: false
4
4
  ---
5
5
 
6
6
  # Figma Token Setup
@@ -3,73 +3,10 @@ description: Memory MCP auto-setup for Cursor and Amp
3
3
  alwaysApply: true
4
4
  ---
5
5
 
6
- # Memory MCP Auto-Setup
6
+ # Memory MCP
7
7
 
8
- At session start: check `.mcp.json` (Cursor) and `.amp/settings.json` (Amp).
9
- If `memory` MCP is absent or uses a **relative** `MEMORY_FILE_PATH` — run `npx agent-orchestrator-kit memory-setup` silently.
8
+ If `.mcp.json` / `.amp/settings.json` lacks `memory`, or `MEMORY_FILE_PATH` is relative: run `npx agent-orchestrator-kit memory-setup`. Relative paths resolve inside npx `dist/` and look like “memory ignored”.
10
9
 
11
- Shared memory file: `.cursor/memory.json` (same path for Cursor and Amp).
10
+ Use `node scripts/memory-mcp-launcher.cjs` (no relative `MEMORY_FILE_PATH`). Shared file: `.cursor/memory.json` (gitignored). Do not delete other MCP servers.
12
11
 
13
- **CRITICAL:** never set `MEMORY_FILE_PATH` to a relative path. Relative `.cursor/memory.json` resolves inside npx `dist/` Amp then reads the wrong graph (looks like "memory ignored"). Always start Memory via `node scripts/memory-mcp-launcher.cjs`, which injects an absolute path.
14
-
15
- ## Cursor (.mcp.json)
16
-
17
- ```json
18
- "memory": {
19
- "command": "node",
20
- "args": ["scripts/memory-mcp-launcher.cjs"]
21
- }
22
- ```
23
-
24
- ## Amp (.amp/settings.json)
25
-
26
- ```json
27
- "amp.mcpServers": {
28
- "memory": {
29
- "command": "node",
30
- "args": ["scripts/memory-mcp-launcher.cjs"]
31
- }
32
- }
33
- ```
34
-
35
- If Amp CLI is available and memory is missing:
36
-
37
- ```bash
38
- npx agent-orchestrator-kit memory-setup
39
- ```
40
-
41
- Do not run `amp mcp add` with a relative `MEMORY_FILE_PATH`.
42
-
43
- ## .gitignore
44
-
45
- Ensure present (do not duplicate):
46
- ```
47
- .cursor/memory.json
48
- .amp/settings.json
49
- ```
50
-
51
- ## Memory Entity Format
52
-
53
- Use these keys and fields for orchestration state:
54
-
55
- | Key | Required fields |
56
- |-----|-----------------|
57
- | `Change:<name>` | `status`, `tasks n/m`, `last_role`, `review` |
58
- | `Handoff:<name>` | `next_role`, `next_command`, `session_count`, `summary`, `blocked` |
59
- | `Decision:<topic>` | `chosen`, `reason` |
60
- | `Convention:<area>` | project-specific rules |
61
-
62
- The deterministic writer is `npx agent-orchestrator-kit handoff <name>` — it upserts `.cursor/memory.json` even when MCP tools are ignored. Also call Memory MCP create/update when tools work.
63
-
64
- ## Session Lifecycle
65
-
66
- At the start of every `/opsx:*` role session, after resolving the change and before specialist work: `npx agent-orchestrator-kit handoff --restore`, then read `Change:<name>`, `Handoff:<name>`, and `Decision:*`. If Memory MCP is unavailable or those entities are empty, read `openspec/changes/<name>/handoff.md` and continue; Memory failure is not a blocker.
67
-
68
- At session exit, spawn `session-handoff` (Amp: isolated `subagent-session-handoff`), write `handoff.md`, then run `npx agent-orchestrator-kit handoff <name>` (exit 0 required). Paste the CLI stdout prompt complete. Only after that attempt Memory MCP updates. You are not done without the fenced prompt.
69
-
70
- ## Rules
71
- - Do not overwrite existing correct launcher config
72
- - Do not delete other MCP servers
73
- - Notify once: "Memory MCP connected."
74
- - Never treat unavailable Memory MCP as a reason to skip `handoff.md` or the CLI
75
- - Never leave a relative `MEMORY_FILE_PATH` in Cursor or Amp config
12
+ Entities: `Change:<name>` (status, tasks n/m, last_role, review) · `Handoff:<name>` (next_role, next_command, session_count, summary, blocked) · `Decision:<topic>` (chosen, reason). Writer: `npx agent-orchestrator-kit handoff <name>`. Notify once: “Memory MCP connected.”
@@ -1,46 +1,30 @@
1
1
  ---
2
- description: Mandatory session restore, Memory persist, subagent spawn, and next-thread prompt
2
+ description: Canonical Session Start and Session Exit protocol for every /opsx:* session
3
3
  alwaysApply: true
4
4
  ---
5
5
 
6
- # Session Handoff — HARD STOP (Amp / Cursor / Claude)
6
+ # Session Handoff — canonical protocol (HARD STOP)
7
7
 
8
- This rule overrides convenience. A `/opsx:*` session that skips these steps is incomplete.
8
+ This rule is the single source of the Session Start / Session Exit protocol. Commands reference it; they do not duplicate it. A `/opsx:*` session is incomplete without persist + the fenced next-thread prompt. FORBIDDEN until persist succeeds: done/готово, next phase, or omitting the prompt.
9
9
 
10
- Amp ignores soft reminders. Treat every MUST below as a gate. If a spawn tool exists, use it. If it does not, run the CLI yourself. Never skip persist because “the user already knows”.
10
+ ## Session Start (before any work)
11
+ 1. Honor pasted `/opsx:<phase> <name>` and announce the role.
12
+ 2. `npx agent-orchestrator-kit status`
13
+ 3. `npx agent-orchestrator-kit handoff --restore` (or `handoff <name> --restore`). The CLI briefing is canonical — it already reads memory.json and handoff.md; no separate Memory MCP read step.
14
+ 4. If the restore CLI failed → read `openspec/changes/<name>/handoff.md` directly.
15
+ 5. Spawn `session-handoff` in restore mode ONLY if both the CLI and handoff.md are unavailable (Amp: isolated `subagent-session-handoff`). This is a fallback, never a routine step.
16
+ 6. Free-form continue/next/«далі» with one active change → execute `Handoff.next_command`.
17
+ 7. Only then start phase work (spawn a specialist when the phase routing requires one).
11
18
 
12
- ## You are not done
19
+ ## Session Exit (order)
20
+ 1. The parent writes `openspec/changes/<name>/handoff.md` itself: Closed role, Change, Done, Decisions, Blocked, Next command, Next role, Attach, Subagents to spawn, Constraints.
21
+ 2. `npx agent-orchestrator-kit handoff <name>` — require exit 0 (upserts absolute-path Memory JSON, prints the expanded prompt on stdout).
22
+ 3. Spawn `session-handoff` in persist mode ONLY if step 2 failed (Amp: isolated `subagent-session-handoff`). Fallback, never routine.
23
+ 4. Memory MCP is an optional mirror: if tools are available, update `Change:<name>`, `Handoff:<name>`, `Decision:*` in one call; unavailability never blocks closing.
24
+ 5. Paste CLI stdout as one fenced block. First line `/opsx:…`. Body uses `project.agent_language`. Self-contained (Done/Decisions/Blocked/spawn/HARD STOP). No banner.
25
+ 6. Stop. Next role = new chat.
13
26
 
14
- FORBIDDEN until persist succeeds: saying done / готово, starting the next phase, or omitting the fenced next-thread prompt.
27
+ ## Archive exception
28
+ `npx agent-orchestrator-kit archive <name>` writes the final `handoff.md` (`next_command: none`) in the archive folder and upserts memory itself. After a successful archive no fenced next-prompt is required — the pipeline is complete.
15
29
 
16
- ## Session start (before any specialist work)
17
-
18
- 1. Honor the pasted `/opsx:<phase> <name>` command and announce that role.
19
- 2. Run `npx agent-orchestrator-kit status`.
20
- 3. Run `npx agent-orchestrator-kit handoff --restore` (or `handoff <name> --restore`). Use the printed briefing.
21
- 4. Read Memory `Change:<name>`, `Handoff:<name>`, `Decision:*` when MCP works.
22
- 5. If restore CLI fails and Memory is empty, read `openspec/changes/<name>/handoff.md`. Memory failure is not a blocker when the file exists.
23
- 6. Spawn `session-handoff` in restore mode when context is incomplete (Amp: isolated `subagent-session-handoff`, never the main thread).
24
- 7. Spawn the routed phase specialist from `.agents/rules/agent-orchestration.mdc`. Amp: isolated `subagent-<name>`. Executing specialist work in the parent thread is a protocol violation.
25
- 8. Free-form “continue” / “next” / «продовжуй» / «далі» with one active change → execute `Handoff.next_command`. Do not ask which phase.
26
-
27
- ## Session exit (mandatory order)
28
-
29
- 1. Spawn `session-handoff` in persist mode (Amp: isolated `subagent-session-handoff`). If spawn fails, do the persist steps in the parent — never skip.
30
- 2. Write `openspec/changes/<name>/handoff.md` with: Closed role, Change, Done, Decisions, Blocked, Next command, Next role, Attach, Subagents to spawn, Constraints.
31
- 3. Run `npx agent-orchestrator-kit handoff <name>` and require exit 0. The CLI upserts `.cursor/memory.json` with an absolute path and prints the expanded prompt on stdout.
32
- 4. If Memory MCP tools work, also update `Change:<name>`, `Handoff:<name>`, `Decision:*` to match.
33
- 5. Paste the CLI stdout into chat as one fenced block. Keep it complete. No `NEXT_SESSION_PROMPT` banner. First line is `/opsx:…`. Body uses `project.agent_language`.
34
- 6. Stop. The next role starts in a **new** chat with that pasted prompt.
35
-
36
- ## Next-thread prompt must be self-contained
37
-
38
- The prompt is the next thread’s operating brief. It MUST include: role, change name, language, hard constraints, start checklist, which subagent to spawn (including Amp isolated wrapper name), full Done / Decisions / Blocked / tasks / review / attach, and the exit HARD STOP. Do not emit a thin “read Memory” stub. Amp often skips Memory MCP; the pasted prompt must still be enough to work.
39
-
40
- ## Memory path
41
-
42
- Never configure Memory MCP with a relative `MEMORY_FILE_PATH`. Relative `.cursor/memory.json` resolves inside npx `dist/` and looks like “memory ignored”. Use `node scripts/memory-mcp-launcher.cjs` (Cursor `.mcp.json` and Amp `.amp/settings.json`). Run `npx agent-orchestrator-kit memory-setup` when the launcher is missing or the path is relative.
43
-
44
- ## Amp isolation
45
-
46
- Every `subagent-*` skill MUST be spawned as an isolated subagent with fresh context. Running the wrapper body in the main Amp thread is a protocol violation. If spawn is unavailable, STOP and report blocked — do not impersonate the specialist.
30
+ Memory MCP: launcher `node scripts/memory-mcp-launcher.cjs`, never a relative `MEMORY_FILE_PATH`.
@@ -42,26 +42,25 @@ Read `.agents/orchestrator.yaml` for project-specific config (language, flags, M
42
42
  | Quick (MVP) | `/opsx:quick <name>` | specs+code | strong | `openspec/changes/` + `src/` |
43
43
  | Verifier | CI / local scripts | — | — | exit codes |
44
44
 
45
- ## Conductor Routing (Mandatory and Exclusive)
46
-
47
- The parent `/opsx:*` session is the conductor. It MUST spawn the selected specialist with a self-contained prompt, MUST verify the structured report, and MUST NOT do the specialist's work itself. Each signal has exactly one primary subagent.
48
-
49
- | Phase / signal | MUST spawn | Specialist scope |
50
- |----------------|------------|------------------|
51
- | Status, gate failure, next command | `openspec-guide` | Read-only pipeline diagnosis |
52
- | Session start restore / session exit persist | `session-handoff` | Memory, `handoff.md`, next-thread prompt |
53
- | Broken kit, MCP, or generated-file sync | `setup-doctor` | Kit setup repair only |
54
- | `/opsx:explore` repository investigation | `codebase-explorer` | Read-only repository research |
55
- | `/opsx:design` | `design-intake` | `design-brief.md` and `assets/` only |
56
- | `/opsx:propose` | `spec-architect` | Change artifacts only |
57
- | `/opsx:review` | `spec-reviewer` | Pre-apply verdict and `review.md` only |
58
- | Apply task with design brief/Figma/image | `design-implementer` | UI implementation |
59
- | Apply ordinary implementation task | `code-writer` | One production-code task |
60
- | Apply after implementation | `test-writer` | Automated tests |
61
- | Apply before PR/MR | `code-reviewer` | Post-implementation spec review |
62
- | `/opsx:archive` | `spec-archiver` | Delta merge and archive move |
63
-
64
- `spec-reviewer` is not `code-reviewer`. During apply, specialists MUST NOT edit `tasks.md`; only the conductor may mark a checkbox after a `Status: done` report and verification that the reported files exist.
45
+ ## Conductor Routing (Differentiated by Phase)
46
+
47
+ The parent `/opsx:*` session is the conductor. Delegation cost must match phase uncertainty: **propose and review MUST spawn their specialist** (the parent never writes artifacts or the verdict); **apply is parent-driven** the parent writes code and tests itself from `tasks.md` + `apply-notes.md`, subagents are optional; **archive is one CLI call** — phase subagents are forbidden.
48
+
49
+ | Phase / signal | Subagent | Status |
50
+ |----------------|------------|--------|
51
+ | Status, gate failure, next command | `openspec-guide` | optional |
52
+ | Restore/persist when handoff CLI failed | `session-handoff` | fallback only |
53
+ | Broken kit, MCP, or generated-file sync | `setup-doctor` | on signal |
54
+ | `/opsx:explore` repository investigation | `codebase-explorer` | mandatory |
55
+ | `/opsx:design` | `design-intake` | mandatory |
56
+ | `/opsx:propose` | `spec-architect` | mandatory |
57
+ | `/opsx:review` (Tier 2, after `gate-check --review` passes) | `spec-reviewer` | mandatory |
58
+ | Apply task with design brief/Figma/image | `design-implementer` | mandatory on signal |
59
+ | Apply: 2 independent tasks with no shared files, or explicit user request | `code-writer` / `test-writer` | optional |
60
+ | Apply before PR/MR | `code-reviewer` | optional |
61
+ | `/opsx:archive` | run `npx agent-orchestrator-kit archive <name>` | CLI; phase subagent forbidden (`spec-archiver` = CLI-failure fallback only) |
62
+
63
+ `spec-reviewer` is not `code-reviewer`. Spawned specialists MUST NOT edit `tasks.md`; the parent checks a box only after verifying the task's Done-when condition. If an apply task requires information beyond its Files/Do/Done-when contract + `apply-notes.md` + referenced artifacts, STOP: record the gap in `handoff.md` and route back to `/opsx:propose <name>` — improvisation is forbidden.
65
64
 
66
65
  ## Handoff Protocol
67
66
 
@@ -127,6 +126,7 @@ After PR merged + CI green:
127
126
  ```
128
127
  /opsx:archive <name>
129
128
  ```
129
+ Archive is one deterministic CLI call — `npx agent-orchestrator-kit archive <name> [--sync | --no-sync --force]` — which checks gates, merges delta specs on `--sync`, moves the change to the dated archive, validates with rollback, and writes the final handoff. No phase subagent.
130
130
 
131
131
  ## Session Rules
132
132
 
@@ -136,7 +136,7 @@ After PR merged + CI green:
136
136
  3. Run `npx agent-orchestrator-kit handoff --restore` (or `handoff <name> --restore`).
137
137
  4. Read Memory entities `Change:<name>`, `Handoff:<name>`, and `Decision:*` when MCP works.
138
138
  5. If restore CLI fails and Memory is empty, read `openspec/changes/<name>/handoff.md`; Memory failure alone is not a blocker.
139
- 6. Spawn `session-handoff` in restore mode when context is incomplete (Amp: isolated `subagent-session-handoff`).
139
+ 6. Spawn `session-handoff` in restore mode **only if** `handoff --restore` failed or printed no briefing (Amp: isolated `subagent-session-handoff`). Skip this spawn when CLI restore exits 0.
140
140
  7. Only after restoration, spawn the routed phase specialist. If the user said “continue” / “next” and exactly one active change has `Handoff.next_command`, execute it instead of asking for a phase.
141
141
 
142
142
  **During session:**
@@ -145,12 +145,11 @@ After PR merged + CI green:
145
145
  - Never edit files outside your role's allowed output
146
146
 
147
147
  **End of each session (HARD STOP — you are NOT done):**
148
- 1. Spawn `session-handoff` in persist mode (Amp: isolated `subagent-session-handoff`). If spawn fails, persist in the parent — never skip.
149
- 2. Write `openspec/changes/<name>/handoff.md` using the template below even if Memory MCP fails.
150
- 3. Run `npx agent-orchestrator-kit handoff <name>` and require exit 0. The CLI upserts Memory JSON with an absolute path and prints the expanded self-contained prompt on stdout.
151
- 4. If Memory MCP tools work, also update `Change:<name>`, `Handoff:<name>`, and new `Decision:<topic>` entities.
152
- 5. Paste the CLI stdout as one fenced next-session prompt. First line is `/opsx:<next> <name>`; body uses `project.agent_language`; keep Done/Decisions/Blocked/spawn/HARD STOP complete. No banner. Do not emit a thin “read Memory” stub.
153
- 6. Do not start the next phase in this chat. If apply, include build/lint status in the persisted Done section.
148
+ 1. Write `openspec/changes/<name>/handoff.md` in the parent using the template below.
149
+ 2. Run `npx agent-orchestrator-kit handoff <name>` and require exit 0. The CLI upserts Memory JSON with an absolute path and prints the expanded self-contained prompt on stdout. Spawn `session-handoff` in persist mode ONLY if this CLI step failed.
150
+ 3. If Memory MCP tools are available, mirror `Change:<name>`, `Handoff:<name>`, and new `Decision:<topic>` entities in one call optional; its absence never blocks closing.
151
+ 4. Paste the CLI stdout as one fenced next-session prompt. First line is `/opsx:<next> <name>`; body uses `project.agent_language`; keep Done/Decisions/Blocked/spawn/HARD STOP complete. No banner. Do not emit a thin “read Memory” stub.
152
+ 5. Do not start the next phase in this chat. If apply, include build/lint status in the persisted Done section.
154
153
 
155
154
  `handoff.md` template:
156
155
 
@@ -213,9 +212,9 @@ The Prompt section is overwritten by `npx agent-orchestrator-kit handoff <name>`
213
212
 
214
213
  ## Mandatory Memory and Handoff Protocol
215
214
 
216
- Before specialist work, the conductor MUST restore context in order: honor the pasted `/opsx:*` command; run `npx agent-orchestrator-kit handoff --restore`; read Memory entities `Change:<name>`, `Handoff:<name>`, and `Decision:*`; if restore CLI and Memory fail, read `openspec/changes/<name>/handoff.md`. Memory failure is not a blocker when the file exists. With one active change, free-form “continue” uses `Handoff.next_command` instead of asking for the phase. Amp MUST spawn `session-handoff` and the phase specialist as isolated `subagent-*` skills.
215
+ Before specialist work, the parent MUST restore context in order: honor the pasted `/opsx:*` command; run `npx agent-orchestrator-kit handoff --restore` (the CLI briefing is canonical no separate Memory MCP read step); if the CLI failed, read `openspec/changes/<name>/handoff.md`; spawn `session-handoff` in restore mode ONLY when both failed. Missing Memory MCP never blocks a session. With one active change, free-form “continue” uses `Handoff.next_command` instead of asking for the phase. Amp spawns any needed subagent as an isolated `subagent-*` skill.
217
216
 
218
- Before declaring a session closed, the conductor MUST, in order: (1) spawn `session-handoff` persist, (2) write `openspec/changes/<name>/handoff.md`, (3) run `npx agent-orchestrator-kit handoff <name>` (exit 0), (4) paste the CLI stdout prompt whose first line is `/opsx:<next> <name>`. The prompt has no `NEXT_SESSION_PROMPT` label, uses `project.agent_language`, and MUST be self-contained (Done, Decisions, Blocked, attach, spawn, HARD STOP) so the next thread can run if Memory MCP is ignored. Never start the next phase in the current chat.
217
+ Before declaring a session closed, the parent MUST, in order: (1) write `openspec/changes/<name>/handoff.md` itself, (2) run `npx agent-orchestrator-kit handoff <name>` (exit 0) — spawn `session-handoff` persist ONLY if this CLI step failed, (3) paste the CLI stdout prompt whose first line is `/opsx:<next> <name>`. Memory MCP mirroring is an optional single call. The prompt has no `NEXT_SESSION_PROMPT` label, uses `project.agent_language`, and MUST be self-contained (Done, Decisions, Blocked, attach, spawn, HARD STOP) so the next thread can run if Memory MCP is ignored. Never start the next phase in the current chat.
219
218
 
220
219
  | Entity | Required fields |
221
220
  |--------|-----------------|
@@ -13,7 +13,9 @@ Implement tasks from an OpenSpec change.
13
13
 
14
14
  **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
15
15
 
16
- **Conductor delegation is mandatory:** the parent MUST NOT implement code or tests. For each task spawn `design-implementer` when a design brief/Figma/image signal exists, otherwise `code-writer`; then spawn `test-writer` for required tests and `code-reviewer` before PR/MR. Require each structured report. Only the conductor may edit `tasks.md` checkboxes.
16
+ **Parent-driven apply:** the parent reads `tasks.md` + `apply-notes.md` (open `design.md`/`proposal.md` only when a task explicitly references them or a contract field is incomplete) and writes code and tests itself, task by task, checking its own `tasks.md` checkboxes. Subagents are optional: spawn `code-writer`/`test-writer` for 2 independent tasks with no shared files (parallelization) or on explicit user request. `design-implementer` remains mandatory for tasks with a design-brief/Figma signal.
17
+
18
+ **Escape valve (STOP — improvisation is forbidden):** if a task requires information beyond its Files/Do/Done-when + `apply-notes.md` + artifacts it explicitly references, STOP: record the gap in `handoff.md`, set the next command to `/opsx:propose <name>` (plan amendment), and end the session. Do not guess.
17
19
 
18
20
  **Steps**
19
21
 
@@ -54,12 +56,9 @@ Implement tasks from an OpenSpec change.
54
56
 
55
57
  **Workspace guard:** If status JSON reports `actionContext.mode: "workspace-planning"` and `allowedEditRoots` is empty, explain that full workspace apply is not supported in this slice. Treat linked repos and folders as read-only context, ask the user to select an affected area through an explicit implementation workflow, and STOP before editing files.
56
58
 
57
- 4. **Read context files**
59
+ 4. **Read the working set**
58
60
 
59
- Read every file path listed under `contextFiles` from the apply instructions output.
60
- The files depend on the schema being used:
61
- - **spec-driven**: proposal, specs, design, tasks
62
- - Other schemas: follow the contextFiles from CLI output
61
+ Read `tasks.md` and `apply-notes.md` they are the primary input for apply. Open `design.md`, `proposal.md`, or delta specs only when a task explicitly references them or a contract field is incomplete. For non-spec-driven schemas, follow `contextFiles` from the CLI output.
63
62
 
64
63
  5. **Show current progress**
65
64
 
@@ -73,15 +72,13 @@ Implement tasks from an OpenSpec change.
73
72
 
74
73
  For each pending task:
75
74
  - Show which task is being worked on
76
- - Spawn the routed implementation subagent with one self-contained task; do not make code changes in the parent
77
- - Verify `Status: done` and that every reported file exists
78
- - Spawn `test-writer` for required tests and verify its report
79
- - Only then, as conductor, mark the task complete in the tasks file: `- [ ]` → `- [x]`
75
+ - Implement it in the parent session from its Files/Do/Done-when contract (spawn `code-writer`/`test-writer` only for 2 independent tasks with no shared files, or on explicit user request; `design-implementer` for design-brief/Figma tasks)
76
+ - Verify the task's Done-when condition actually holds
77
+ - Mark the task complete in the tasks file: `- [ ]` → `- [x]`
80
78
  - Continue to next task
81
79
 
82
- **Pause if:**
83
- - Task is unclearask for clarification
84
- - Implementation reveals a design issue → suggest updating artifacts
80
+ **STOP (escape valve) if:**
81
+ - The task requires information beyond its contract + `apply-notes.md` + referenced artifacts record the gap in `handoff.md`, next command `/opsx:propose <name>` — never improvise
85
82
  - Error or blocker encountered → report and wait for guidance
86
83
  - User interrupts
87
84
 
@@ -146,13 +143,11 @@ What would you like to do?
146
143
 
147
144
  **Guardrails**
148
145
  - Keep going through tasks until done or blocked
149
- - Always read context files before starting (from the apply instructions output)
150
- - If task is ambiguous, pause and ask before implementing
151
- - If implementation reveals issues, pause and suggest artifact updates
152
- - Keep code changes minimal and scoped to each task
153
- - Never let a specialist update `tasks.md`; the conductor updates a checkbox only after a verified `done` report
154
- - Pause on errors, blockers, or unclear requirements - don't guess
155
- - Use contextFiles from CLI output, don't assume specific file names
146
+ - Always read `tasks.md` + `apply-notes.md` before starting
147
+ - If a task contract is insufficient, STOP via the escape valve — don't guess or improvise
148
+ - Keep code changes minimal and scoped to each task's `Files:` list
149
+ - Never let a spawned specialist update `tasks.md`; the parent checks a box only after verifying Done-when
150
+ - Pause on errors and blockers
156
151
 
157
152
  **Fluid Workflow Integration**
158
153