sdd-dispatch · diff

git:20260831.e1e1453 to git:20260906.b53a8e9

54 added, 52 removed. Audit A to A.

---
name: sdd-dispatch
- description: Điều phối task team theo Claude Code Agent với ownership, checkpoint, evidence và bounded retry
+ description: Điều phối Agent worker theo ownership, checkpoint, evidence và bounded retry
user-invocable: true
---
- # Safe Claude Code Multi-Agent Dispatch (`/sdd-dispatch`)
+ # Safe Claude Code Agent Dispatch (`/sdd-dispatch`)
**Output language:** Mirror the invoking prompt. Canonical tokens, paths and commands remain language-invariant.
- Dùng skill này để điều phối team-mode task đã approved. `/add-execute` vẫn là quy trình atomic của worker. Dispatcher dùng Claude Code `Agent` tool khi runtime hiện diện; không tạo runtime service, không tự cấp quyền, không commit hoặc `git push`.
+ Dùng skill này để thực thi task đã approved theo hai trục độc lập: `Project Ownership` (Human accountability) và `Agent Execution` (direct hoặc orchestrated). `/add-execute` vẫn là quy trình atomic. Không tạo runtime service, không tự cấp quyền, không commit hoặc `git push`.
## Parameters
- `--feature=<feature-slug>`: Required feature identifier.
- - `--batch=<batch-id>`: Optional batch identifier. Default is the selected task set.
- - `--task=<T001,T002>`: Optional ordered task IDs. Omit only to select the next eligible batch.
- - `--team-size=solo|team`: Optional invocation override. Default comes from `.sdd/shared_context.md`.
+ - `--batch=<batch-id>`: Optional batch identifier; default is selected task set.
+ - `--task=<T001,T002>`: Optional ordered task IDs; omit only to select next eligible batch.
+ - `--project-ownership=solo|team`: Optional Human governance override.
+ - `--agent-execution=direct|orchestrated`: Optional execution override.
+ - `--team-size=solo|team`: Deprecated composite alias for one transition release. `solo` maps to `--project-ownership=solo --agent-execution=direct`; `team` maps to `--project-ownership=team --agent-execution=orchestrated`. Emit migration warning.
- `--retry`: Resume only an eligible `RETRY_PENDING` task.
- - `--resume`: Lead recovery for an interrupted `RUNNING`, resolved `BLOCKED`, or Human-dispositioned `ESCALATED` task; it is not a retry.
+ - `--resume`: Recover an interrupted `RUNNING`, resolved `BLOCKED`, or Human-dispositioned `ESCALATED` task; never a retry.
- ## Preconditions
+ ## Resolve the two axes
- Read [AI Review Protocol](../_shared/ai-review-protocol.md), [Architecture Profile Protocol](../_shared/architecture-profile-protocol.md), `AGENTS.md`, `CONSTITUTION.md`, constraints, `.sdd/mcp-config.yaml`, `.sdd/shared_context.md`, and the feature `CONTEXT.md`, `SPEC.md`, `PLAN.md`, `TASKS.md`, reviews and handoff state.
+ 1. Read `.sdd/shared_context.md`. Use canonical settings only when exactly one valid `# Project Ownership: solo|team` header and exactly one valid `# Agent Execution: direct|orchestrated` header exist; canonical flags override only their matching axis.
+ 2. Chỉ khi cả hai canonical header vắng mặt, dùng đúng một nguồn legacy hợp lệ: đúng một `# Collaboration Mode: solo|team` hoặc đúng một `--team-size=solo|team`. Header legacy thiếu, trùng hoặc malformed; alias lặp, malformed; hoặc header và alias coexist là `BLOCKED`. Source hợp lệ map theo documented composite pair, phải báo migration warning và không tự rewrite persisted governance.
+ 3. Missing, duplicate or malformed canonical headers are `BLOCKED`; never fall back to legacy. `--team-size` cannot be combined with `--project-ownership` or `--agent-execution`; the conflict is `BLOCKED`. A `--team-size` alias with either canonical header is `BLOCKED`, because aliases resolve only when both canonical headers are absent. A `canonical` Dispatch Record must not contain a legacy alias. A legacy header coexisting with a valid canonical pair is ignored for resolution and recorded for migration cleanup.
+ 4. `solo` means one Human project owner; `team` means multiple Human collaborators. `direct` means the current Agent executes; `orchestrated` means this dispatcher may launch observed Claude Code `Agent` workers. Do not infer either axis from the other.
- `TASKS.md` must already have Human Final Review `APPROVED`. For every selected task, require:
+ ## Preconditions
- 1. task marker is `[ ]`, or `[/]` only with `--retry` for an active `RETRY_PENDING` record or `--resume` for interrupted `RUNNING`, resolved `BLOCKED`, or Human-dispositioned `ESCALATED` record;
- 2. dependencies are `[x]`;
- 3. Intent/DoD, layer/file boundary, owner/dependencies, profile binding/exact command, scope category, checkpoint, contract/sync-back and high-risk route exist;
- 4. relevant profile binding and exact verification command are approved or explicitly `N/A` with valid reason;
- 5. contract version and owner match the frozen record;
- 6. boundaries do not overlap inside a parallel batch;
- 7. worker has no shared artifact or contract mutation unless it is the Lead/owner and a sequential handoff is selected.
+ Read [AI Review Protocol](../_shared/ai-review-protocol.md), [Architecture Profile Protocol](../_shared/architecture-profile-protocol.md), `AGENTS.md`, `CONSTITUTION.md`, constraints, `.sdd/mcp-config.yaml`, `.sdd/shared_context.md`, and the feature `CONTEXT.md`, `SPEC.md`, `PLAN.md`, `TASKS.md`, reviews and handoff state.
- Any missing evidence, contract drift, overlap, unapproved command, scope expansion, package/configuration change, policy violation or new material decision is `BLOCKED`. Do not infer a command, path, role or enforcement capability.
+ `TASKS.md` must already have Human Final Review `APPROVED`. For every selected task, require a valid marker/dependency chain, approved task intent/file boundary/profile binding/exact command/checkpoint, matching frozen contract owner/version, no parallel boundary overlap and no unauthorized shared-contract mutation. Markdown state alone cannot serialize concurrent sessions; serialize dispatcher-owned routes and persist grant consumption before action. When an observed host provides an atomic one-time or lease claim bound to feature/task/grant/route/consumer, record it as `VERIFIED`; otherwise record runtime enforcement as `UNVERIFIED` and do not claim host-level replay prevention. Missing evidence, drift, overlap, unapproved command, scope expansion, package/config change, policy violation or new material decision is `BLOCKED`.
## Batch classification and approval
- `single-owned`: one independent task without shared-contract impact.
- - `parallel-owned`: two or more independent tasks with non-overlapping exclusive boundaries and no shared-contract mutation.
- - `sequential-handoff`: dependency, shared file, contract producer/consumer ordering, retry or integration dependency.
- - `blocked`: a failed precondition.
+ - `parallel-owned`: two or more independent tasks with exclusive non-overlapping boundaries and no shared-contract mutation.
+ - `sequential-handoff`: dependency, shared file, producer/consumer ordering, retry or integration dependency.
+ - `blocked`: failed precondition.
- A batch requires a durable batch-specific Human Final Review before any worker mutation when it includes a material state change, shared/public contract, cross-contract work, or a changed task set, boundary, frozen version, exact command or checkpoint. Store it at `.sdd/reviews/dispatch-<feature>-<batch>.md` using the canonical recommendation/review block. A generic chat approval is invalid.
+ A material, cross-contract, changed-boundary, changed-command or changed-checkpoint batch needs durable batch-specific Human Final Review before mutation at `.sdd/reviews/dispatch-<feature>-<batch>.md`.
## Dispatch Record
- Append this record under `## Current Handoff State` in the feature `TASKS.md`. It is durable evidence; host task IDs and Agent references are supplemental only.
+ Append under `## Current Handoff State` in feature `TASKS.md`:
```markdown
## Dispatch Record — D-<feature>-<batch>-A<attempt>
- - Feature / batch / tasks: <slug; batch; ordered task IDs>
- - Dispatcher: Claude Code `/sdd-dispatch`
- - Dispatch mode: team | solo-bypass
- - Batch type: single-owned | parallel-owned | sequential-handoff | blocked
- - State: PLANNED | AWAITING_APPROVAL | READY | DISPATCHED | RUNNING | VERIFYING | RETRY_PENDING | COMPLETED | BLOCKED | ESCALATED
+ - Dispatcher: <Claude Code /sdd-dispatch or current Agent>
+ - Project ownership: solo | team
+ - Agent execution: direct | orchestrated
+ - Governance resolution: <canonical | legacy-header | legacy-alias>; invocation axis overrides: <none | project-ownership=<value> | agent-execution=<value> | both>
+ - Feature: <feature-slug>
+ - Batch/tasks/state: <batch, ordered task IDs; PLANNED | AWAITING_APPROVAL | READY | DISPATCHED | RUNNING | VERIFYING | RETRY_PENDING | COMPLETED | BLOCKED | ESCALATED>
+ - Task execution grants: <one append-only entry per selected task: task ID; grant ID; grant attempt; route=direct|orchestrated; task grant state=DISPATCHED|RUNNING|RETIRED|REVOKED; consumption state=UNCONSUMED|CONSUMED; dispatcher-issued opaque consumer reference; consumption evidence; terminal/retry evidence>
+ - Host execution-claim evidence: <host-controlled atomic claim reference or UNVERIFIED; matching feature/task/grant/route/consumer when available>
- Dependency and ownership check: <pass/fail evidence>
- Frozen contracts: <ID/version/owner or N/A>
- Approved scope and file boundaries: <task-owned paths>
- Profile bindings and exact commands: <approved evidence>
- State-change category: <none or categories>
- Human checkpoint: <review reference or N/A>
- - Runtime identity evidence: VERIFIED | UNVERIFIED; <observed Agent/session evidence>
- - Runtime enforcement evidence: VERIFIED | UNVERIFIED; <observed host evidence or absence>
+ - Runtime identity evidence: VERIFIED | UNVERIFIED; <observed evidence>
+ - Runtime enforcement evidence: VERIFIED | UNVERIFIED; <observed evidence or absence>
- Host task-tracking evidence: AVAILABLE | UNAVAILABLE | NOT_USED; <optional Task evidence>
- - Worker references: <Agent references or unavailable>
+ - Worker references: <Agent references, direct/no worker, or unavailable>
- Attempt and retry count: <attempt; consecutive failures; maximum 5>
- Worker results: <paths, Action Record, exact command/result>
- Integration validation: <boundary/contract/verification result>
- Residual blocker: <none or blocker>
- Sync-back decision: </sdd-trace, /sdd-sync, or N/A>
```
- State transitions are:
+ State transitions remain:
```text
PLANNED -> READY | AWAITING_APPROVAL | BLOCKED
AWAITING_APPROVAL -> READY | BLOCKED
READY -> DISPATCHED | BLOCKED
DISPATCHED -> RUNNING | BLOCKED
RUNNING -> VERIFYING | RETRY_PENDING | BLOCKED | ESCALATED
RETRY_PENDING -> DISPATCHED | BLOCKED
VERIFYING -> COMPLETED | RETRY_PENDING | BLOCKED | ESCALATED
BLOCKED -> PLANNED
ESCALATED -> PLANNED
```
- Use `[ ]` before dispatch, `[/]` from `DISPATCHED` through `VERIFYING` or retry, and `[x]` only after `COMPLETED`, exact verification and required sync-back.
+ Use `[ ]` before dispatch, `[/]` during execution/retry, and `[x]` only after required verification and sync-back. Allocate exactly one route-specific task execution grant per selected task only after preflight passes. A grant identifies its designated consumer through a dispatcher-issued opaque consumer reference: delivered as `--dispatch-consumer` for `direct`, or in the immutable worker packet for `orchestrated`. A grant is procedurally executable only when its task ID, feature, immutable inputs, route and designated consumer match, with `task grant state=DISPATCHED` and `consumption state=UNCONSUMED`; a matching observed host-controlled atomic claim adds host enforcement when available. The dispatcher alone may allocate, revoke, retire or renew grants. Retry retires the consumed grant and allocates a fresh grant only after immutable retry eligibility passes; `/add-execute` never resets consumption or grants a retry.
- ## Claude Code worker contract
+ ## Execution routes
- Use the current Claude Code `Agent` tool only after observing that it is available. `TaskCreate`, `TaskGet`, `TaskList` and `TaskUpdate` may mirror status when available; their absence must be recorded as `UNAVAILABLE`, not bypassed with an invented tool. `.sdd/mcp-config.yaml` is a policy specification and does not prove host enforcement.
+ ### Direct
- Each worker prompt must contain this immutable packet:
+ With `Agent Execution: direct`, complete the preflight and Dispatch Record, allocate one matching `DISPATCHED`/`UNCONSUMED` direct task execution grant with a dispatcher-issued opaque `consumer` reference, record observed host-controlled claim evidence when available, launch no worker, then invoke `/add-execute --feature=<feature> --task=<task> --dispatch-record=<reference> --dispatch-grant=<grant-id> --dispatch-consumer=<consumer-ref>`. `/add-execute` matches the preallocated consumer reference and any recorded claim, then consumes that grant before action. Shadow Plan, Action Record, material checkpoint, approved file boundary, exact command, validation and integration checks remain mandatory. `direct` is not a bypass.
+ ### Orchestrated
+
+ With `Agent Execution: orchestrated`, use the current Claude Code `Agent` tool only after observing availability. `TaskCreate`, `TaskGet`, `TaskList` and `TaskUpdate` may mirror state when available; absence is `UNAVAILABLE`, not a bypass. Each worker prompt must contain an immutable packet:
+
```text
DISPATCH ID: <id>
+ FEATURE: <feature-slug>
ROLE: <approved role>
+ TASK ID: <T00X>
+ DISPATCH GRANT ID: <grant-id>
+ GRANT ATTEMPT: <n>
+ GRANT STATE: DISPATCHED
+ CONSUMPTION STATE: UNCONSUMED
+ CONSUMER: <dispatcher-issued opaque consumer reference; must match grant and any recorded host claim>
TASK: <ID, title, Intent/DoD and REQ references>
OWNED FILE BOUNDARY: <exact paths only>
FROZEN CONTRACT: <ID/version/owner or N/A>
PROFILE EVIDENCE: <approved binding/version>
ALLOWED COMMANDS: <exact approved commands only>
STATE-CHANGE CATEGORY: <none/categories>
CHECKPOINT: <review reference or N/A>
AUDIT EVIDENCE REFERENCE: <Dispatch Record/review/action evidence>
+ HOST EXECUTION-CLAIM EVIDENCE: <host-controlled claim reference; matching feature/task/grant/route/consumer; CLAIMED; lease/one-time evidence | UNVERIFIED>
POLICY STATUS: policy-only; host evidence is <VERIFIED|UNVERIFIED>
PROHIBITIONS: no out-of-boundary edits, package/config/contract changes, self-approval, commit or push.
STOP CONDITIONS: drift, scope conflict, missing command/checkpoint, policy/security issue, retry ineligibility.
RETURN: Action Record-compatible result, changed paths, command/result, requirement coverage, residual blocker and sync-back decision.
```
- A prose completion claim without every return field is incomplete. Parallel workers are only allowed for `parallel-owned`; shared work, retries and integration validation are sequential. Lead alone creates/updates optional host task mirrors and integrates results.
-
- ## Retry and escalation
-
- Retry only an implementation defect within the original task boundary when scope, boundary, frozen contract, binding, exact command and checkpoint are unchanged. Retry the failed task serially, append another attempt to its Dispatch Record and rerun only its approved command.
-
- Never retry automatically for a Spec gap, profile/configuration gap, missing/revised/rejected checkpoint, shared-contract drift, ownership conflict, security/policy issue, dependency/runtime change, Agent launch/permission uncertainty, or any material action. Do not use retry to request broader permissions.
-
- `RUNNING` interrupted by a session or worker loss, and `BLOCKED` after its evidence gap is resolved, require Lead revalidation with `--resume`; Lead closes the old record as `BLOCKED` and creates a new `PLANNED` Dispatch Record. If immutable inputs changed, a new applicable batch approval is required. `--resume` never reuses an old worker reference without observing it in the current host.
-
- After five consecutive failures, set `ESCALATED`, retain `[/]`, create `.sdd/reviews/dispatch-<feature>-<batch>.md`, and require Human disposition under `AGT-S-02`. Only after that review explicitly authorizes recovery may Lead use `--resume`, close the escalated record and create a new `PLANNED` Dispatch Record; changed scope, boundary, frozen version, command or checkpoint requires a new batch approval.
-
- ## Solo mode
+ Worker verifies packet `DISPATCH ID`, `FEATURE`, `TASK ID`, grant ID/attempt/state/consumption, designated `CONSUMER`, any recorded host execution-claim evidence, frozen inputs and task boundary against the referenced Dispatch Record before `/add-execute`, then `/add-execute` verifies the consumer and consumes the matching grant before Shadow Plan or task action; stale or mismatched consumer or recorded claim is `BLOCKED`, while unavailable host claim remains `UNVERIFIED`. Parallel workers are only allowed for `parallel-owned`; shared work, retries and integration validation are sequential. Project ownership does not change worker eligibility.
- `--team-size=solo` records `solo-bypass`, creates no worker and preserves normal `/add-execute` Shadow Plan, Action Record, review, profile, checkpoint, commit and push restrictions.
+ ## Retry, completion and sync-back
- ## Completion and sync-back
+ Retry only an implementation defect inside unchanged task boundary, frozen contract, binding, exact command and checkpoint. Never retry a Spec/profile/command/checkpoint/contract/ownership/security/policy/dependency/runtime gap. For an eligible retry, retire the consumed task grant and allocate a new grant ID/attempt; never reactivate consumed grant. After five consecutive failures, set `ESCALATED`, retain `[/]`, create the dispatch review report and require Human disposition. Revalidate before `--resume`; never reuse an old worker reference without observing it in the current host.
- Lead validates every returned boundary, Action Record, exact command/result, frozen-contract compatibility and required `/sdd-trace` or `/sdd-sync` decision. Stop integration on unresolved conflict. Refresh a recommendation when dispatch scope changes; Agent never approves a dispatch, task or contract.
+ The contract owner validates returned boundaries, Action Record, exact command/result, frozen-contract compatibility and required `/sdd-trace` or `/sdd-sync` decision. Agent never approves a dispatch, task or contract.