@lvlup-sw/exarchos 2.0.1
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.
- package/.claude-plugin/marketplace.json +22 -0
- package/.claude-plugin/plugin.json +17 -0
- package/.mcp.json +17 -0
- package/AGENTS.md +59 -0
- package/CLAUDE.md.template +62 -0
- package/LICENSE +202 -0
- package/README.md +258 -0
- package/commands/autocompact.md +37 -0
- package/commands/checkpoint.md +85 -0
- package/commands/cleanup.md +99 -0
- package/commands/debug.md +145 -0
- package/commands/delegate.md +56 -0
- package/commands/ideate.md +82 -0
- package/commands/plan.md +150 -0
- package/commands/refactor.md +139 -0
- package/commands/reload.md +37 -0
- package/commands/resume.md +130 -0
- package/commands/review.md +51 -0
- package/commands/sync-schemas.md +74 -0
- package/commands/synthesize.md +122 -0
- package/commands/tdd.md +58 -0
- package/dist/exarchos-cli.js +8828 -0
- package/dist/exarchos-mcp.js +50 -0
- package/hooks/hooks.json +53 -0
- package/package.json +59 -0
- package/rules/coding-standards.md +46 -0
- package/rules/mcp-tool-guidance.md +26 -0
- package/rules/pr-descriptions.md +12 -0
- package/rules/rm-safety.md +9 -0
- package/rules/skill-path-resolution.md +10 -0
- package/rules/tdd.md +41 -0
- package/rules/telemetry-awareness.md +9 -0
- package/scripts/assess-refactor-scope.sh +239 -0
- package/scripts/check-benchmark-regression.sh +229 -0
- package/scripts/check-coderabbit.sh +288 -0
- package/scripts/check-coverage-thresholds.sh +194 -0
- package/scripts/check-polish-scope.sh +245 -0
- package/scripts/check-property-tests.sh +167 -0
- package/scripts/check-tdd-compliance.sh +265 -0
- package/scripts/coderabbit-review-gate.sh +518 -0
- package/scripts/debug-review-gate.sh +201 -0
- package/scripts/extract-fix-tasks.sh +179 -0
- package/scripts/extract-task.sh +67 -0
- package/scripts/generate-traceability.sh +209 -0
- package/scripts/investigation-timer.sh +171 -0
- package/scripts/needs-schema-sync.sh +174 -0
- package/scripts/new-project.sh +103 -0
- package/scripts/post-delegation-check.sh +317 -0
- package/scripts/pre-synthesis-check.sh +440 -0
- package/scripts/reconcile-state.sh +346 -0
- package/scripts/reconstruct-stack.sh +432 -0
- package/scripts/review-diff.sh +63 -0
- package/scripts/review-verdict.sh +169 -0
- package/scripts/security-scan.sh +248 -0
- package/scripts/select-debug-track.sh +186 -0
- package/scripts/setup-worktree.sh +323 -0
- package/scripts/spec-coverage-check.sh +230 -0
- package/scripts/static-analysis-gate.sh +236 -0
- package/scripts/sync-labels.sh +122 -0
- package/scripts/validate-companion.sh +161 -0
- package/scripts/validate-dotnet-standards.sh +267 -0
- package/scripts/validate-installation.sh +101 -0
- package/scripts/validate-plugin.sh +223 -0
- package/scripts/validate-refactor.sh +234 -0
- package/scripts/validate-rm.sh +93 -0
- package/scripts/verify-delegation-saga.sh +240 -0
- package/scripts/verify-doc-links.sh +211 -0
- package/scripts/verify-ideate-artifacts.sh +296 -0
- package/scripts/verify-plan-coverage.sh +228 -0
- package/scripts/verify-review-triage.sh +219 -0
- package/scripts/verify-worktree-baseline.sh +159 -0
- package/scripts/verify-worktree.sh +84 -0
- package/settings.json +47 -0
- package/skills/brainstorming/SKILL.md +127 -0
- package/skills/brainstorming/references/design-template.md +65 -0
- package/skills/cleanup/SKILL.md +147 -0
- package/skills/cleanup/references/merge-verification.md +40 -0
- package/skills/debug/SKILL.md +204 -0
- package/skills/debug/references/hotfix-track.md +134 -0
- package/skills/debug/references/investigation-checklist.md +217 -0
- package/skills/debug/references/rca-template.md +150 -0
- package/skills/debug/references/state-schema.md +294 -0
- package/skills/debug/references/thorough-track.md +194 -0
- package/skills/debug/references/triage-questions.md +155 -0
- package/skills/debug/references/troubleshooting.md +47 -0
- package/skills/delegation/SKILL.md +150 -0
- package/skills/delegation/references/adaptive-orchestration.md +31 -0
- package/skills/delegation/references/agent-teams-saga.md +248 -0
- package/skills/delegation/references/fix-mode.md +74 -0
- package/skills/delegation/references/fixer-prompt.md +162 -0
- package/skills/delegation/references/implementer-prompt.md +322 -0
- package/skills/delegation/references/parallel-strategy.md +124 -0
- package/skills/delegation/references/pbt-patterns.md +172 -0
- package/skills/delegation/references/pr-fixes-mode.md +154 -0
- package/skills/delegation/references/state-management.md +51 -0
- package/skills/delegation/references/testing-patterns.md +129 -0
- package/skills/delegation/references/troubleshooting.md +33 -0
- package/skills/delegation/references/workflow-steps.md +127 -0
- package/skills/delegation/references/worktree-enforcement.md +64 -0
- package/skills/dotnet-standards/SKILL.md +269 -0
- package/skills/dotnet-standards/references/csharp-standards.md +120 -0
- package/skills/dotnet-standards/templates/.editorconfig +366 -0
- package/skills/dotnet-standards/templates/Directory.Build.props +56 -0
- package/skills/dotnet-standards/templates/Directory.Packages.props +69 -0
- package/skills/dotnet-standards/templates/global.json +6 -0
- package/skills/dotnet-standards/templates/nuget.config +9 -0
- package/skills/dotnet-standards/templates/stylecop.json +37 -0
- package/skills/git-worktrees/SKILL.md +255 -0
- package/skills/implementation-planning/SKILL.md +233 -0
- package/skills/implementation-planning/references/plan-document-template.md +42 -0
- package/skills/implementation-planning/references/spec-tracing-guide.md +51 -0
- package/skills/implementation-planning/references/task-template.md +43 -0
- package/skills/implementation-planning/references/testing-strategy-guide.md +88 -0
- package/skills/quality-review/SKILL.md +278 -0
- package/skills/quality-review/references/code-quality-checklist.md +159 -0
- package/skills/quality-review/references/review-report-template.md +65 -0
- package/skills/quality-review/references/security-checklist.md +79 -0
- package/skills/quality-review/references/typescript-standards.md +24 -0
- package/skills/refactor/COMMAND.md +67 -0
- package/skills/refactor/SKILL.md +198 -0
- package/skills/refactor/phases/auto-chain.md +262 -0
- package/skills/refactor/phases/brief.md +176 -0
- package/skills/refactor/phases/explore.md +132 -0
- package/skills/refactor/phases/overhaul-delegate.md +136 -0
- package/skills/refactor/phases/overhaul-plan.md +312 -0
- package/skills/refactor/phases/overhaul-review.md +304 -0
- package/skills/refactor/phases/polish-implement.md +349 -0
- package/skills/refactor/phases/polish-validate.md +218 -0
- package/skills/refactor/phases/update-docs.md +234 -0
- package/skills/refactor/references/brief-template.md +81 -0
- package/skills/refactor/references/doc-update-checklist.md +110 -0
- package/skills/refactor/references/explore-checklist.md +73 -0
- package/skills/refactor/references/overhaul-track.md +215 -0
- package/skills/refactor/references/polish-track.md +170 -0
- package/skills/shared/prompts/context-reading.md +58 -0
- package/skills/shared/prompts/report-format.md +54 -0
- package/skills/shared/prompts/tdd-requirements.md +39 -0
- package/skills/shepherd/SKILL.md +264 -0
- package/skills/shepherd/references/assess-checklist.md +124 -0
- package/skills/shepherd/references/fix-strategies.md +191 -0
- package/skills/spec-review/SKILL.md +229 -0
- package/skills/spec-review/references/review-checklist.md +60 -0
- package/skills/sync-schemas/SKILL.md +114 -0
- package/skills/sync-schemas/references/configuration.md +73 -0
- package/skills/synthesis/SKILL.md +129 -0
- package/skills/synthesis/references/pr-descriptions.md +87 -0
- package/skills/synthesis/references/synthesis-steps.md +109 -0
- package/skills/synthesis/references/troubleshooting.md +115 -0
- package/skills/validate-all-skills.sh +57 -0
- package/skills/validate-frontmatter.sh +237 -0
- package/skills/workflow-state/SKILL.md +210 -0
- package/skills/workflow-state/references/mcp-tool-reference.md +111 -0
- package/skills/workflow-state/references/phase-transitions.md +141 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: delegation
|
|
3
|
+
description: "Dispatch implementation tasks to agent teammates in git worktrees. Use when the user says 'delegate', 'dispatch tasks', 'assign work', 'delegate tasks', or runs /delegate. Spawns teammates, creates worktrees, monitors progress, and collects results. Supports --fixes flag for review finding remediation. Do NOT use for single-file changes or polish-track refactors."
|
|
4
|
+
metadata:
|
|
5
|
+
author: exarchos
|
|
6
|
+
version: 1.0.0
|
|
7
|
+
mcp-server: exarchos
|
|
8
|
+
category: workflow
|
|
9
|
+
phase-affinity: delegate
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Delegation Skill
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
Dispatch implementation tasks to Claude Code subagents with proper context and TDD requirements.
|
|
17
|
+
|
|
18
|
+
## Triggers
|
|
19
|
+
|
|
20
|
+
Activate this skill when:
|
|
21
|
+
- User runs `/delegate` command
|
|
22
|
+
- Implementation plan is ready
|
|
23
|
+
- User wants to parallelize work
|
|
24
|
+
- Tasks are ready for execution
|
|
25
|
+
|
|
26
|
+
## Delegation Modes
|
|
27
|
+
|
|
28
|
+
| Mode | Mechanism | Best for |
|
|
29
|
+
|------|-----------|----------|
|
|
30
|
+
| `subagent` (default) | `Task` with `run_in_background` | 1-3 independent tasks, CI, headless |
|
|
31
|
+
| `agent-team` | `Task` with `team_name` | 3+ interdependent tasks, interactive sessions |
|
|
32
|
+
|
|
33
|
+
**Auto-detection:** tmux + `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` → `agent-team`. Otherwise → `subagent`. Override with `/delegate --mode subagent|agent-team`.
|
|
34
|
+
|
|
35
|
+
**CRITICAL:** Always specify `model: "opus"` for coding tasks.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
Task({
|
|
39
|
+
subagent_type: "general-purpose",
|
|
40
|
+
model: "opus",
|
|
41
|
+
description: "Implement user model",
|
|
42
|
+
prompt: `[Full implementer prompt from template]`
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For agent-team event payloads and YAML examples, see `references/agent-teams-saga.md`. For adaptive team composition, see `references/adaptive-orchestration.md`.
|
|
47
|
+
|
|
48
|
+
## Controller Responsibilities
|
|
49
|
+
|
|
50
|
+
The orchestrator (you) MUST:
|
|
51
|
+
|
|
52
|
+
1. **Extract tasks upfront** — Read plan, extract all task details
|
|
53
|
+
2. **Provide full context** — Never make subagents read files for task info
|
|
54
|
+
3. **Include TDD requirements** — Use implementer prompt template
|
|
55
|
+
4. **Track progress** — TodoWrite (subagent) or native TaskList (agent-team)
|
|
56
|
+
5. **Set up worktrees** — For parallel execution
|
|
57
|
+
6. **Single-writer discipline** (agent-team) — Only the orchestrator mutates `workflow.tasks[]`
|
|
58
|
+
|
|
59
|
+
## Implementer Prompt Template
|
|
60
|
+
|
|
61
|
+
Use `@skills/delegation/references/implementer-prompt.md` as template for Task tool prompts.
|
|
62
|
+
|
|
63
|
+
**Conditional PBT:** When a task has `testingStrategy.propertyTests: true`, include the PBT section from `references/pbt-patterns.md`. When `false`, omit entirely.
|
|
64
|
+
|
|
65
|
+
## Delegation Workflow — Subagent Mode
|
|
66
|
+
|
|
67
|
+
1. Prepare worktrees — `scripts/setup-worktree.sh`
|
|
68
|
+
2. Extract task details from plan
|
|
69
|
+
3. Check for benchmark tasks → set `verification.hasBenchmarks` in state
|
|
70
|
+
4. Create TodoWrite entries for tracking
|
|
71
|
+
5. Dispatch parallel subagents via Task tool
|
|
72
|
+
6. Monitor progress via TaskOutput
|
|
73
|
+
7. Collect and verify — `scripts/post-delegation-check.sh`
|
|
74
|
+
8. Schema sync if API files modified
|
|
75
|
+
|
|
76
|
+
For detailed step instructions, see `references/workflow-steps.md`.
|
|
77
|
+
|
|
78
|
+
## Delegation Workflow — Agent Team Mode (6-Step Saga)
|
|
79
|
+
|
|
80
|
+
Follow the event-first saga: **emit event → execute side effect** at every step.
|
|
81
|
+
|
|
82
|
+
| Step | Action | Type |
|
|
83
|
+
|------|--------|------|
|
|
84
|
+
| Pre-flight | Read tasks, prepare worktrees | — |
|
|
85
|
+
| 1 | Create team | Compensable |
|
|
86
|
+
| 2 | Create native tasks (batched) | Compensable |
|
|
87
|
+
| 3 | Spawn teammates (**pivot**) | Point of no return |
|
|
88
|
+
| 4 | Monitor (tiered) | Retryable |
|
|
89
|
+
| 5 | Disband | Retryable |
|
|
90
|
+
| 6 | Transition to review | Retryable |
|
|
91
|
+
|
|
92
|
+
For step-by-step instructions, idempotency checks, compensation protocol, and event payloads, see `references/agent-teams-saga.md`.
|
|
93
|
+
|
|
94
|
+
## Parallel Execution Strategy
|
|
95
|
+
|
|
96
|
+
Dispatch parallel tasks in a single message with multiple Task calls. See `references/parallel-strategy.md` for group identification, dispatching patterns, and model selection.
|
|
97
|
+
|
|
98
|
+
## Worktree Enforcement (MANDATORY)
|
|
99
|
+
|
|
100
|
+
All tasks MUST run in isolated worktrees. Use `scripts/setup-worktree.sh` for setup.
|
|
101
|
+
|
|
102
|
+
Before dispatching: run `scripts/verify-worktree.sh --cwd <path>`. If exit 1: stop dispatch, report invalid worktree. See `references/worktree-enforcement.md`.
|
|
103
|
+
|
|
104
|
+
## State Management
|
|
105
|
+
|
|
106
|
+
Track task progress in workflow state for context persistence. Read tasks with `action: "get"`, `query: "tasks"`. For benchmark labeling, state patterns, and agent-team consistency model, see `references/state-management.md`.
|
|
107
|
+
|
|
108
|
+
## Fix Mode (--fixes)
|
|
109
|
+
|
|
110
|
+
Handles review failures instead of initial implementation. Uses `references/fixer-prompt.md` template, dispatches fix tasks per issue, then re-invokes review.
|
|
111
|
+
|
|
112
|
+
**Arguments:** `--fixes <state-file-path>` — state JSON containing review results in `.reviews.<taskId>.specReview` or `.reviews.<taskId>.qualityReview`.
|
|
113
|
+
|
|
114
|
+
For detailed process, see `references/fix-mode.md`. For PR feedback workflows (`--pr-fixes`), see `references/pr-fixes-mode.md`.
|
|
115
|
+
|
|
116
|
+
## Completion Criteria
|
|
117
|
+
|
|
118
|
+
- [ ] All tasks extracted from plan (or read from state)
|
|
119
|
+
- [ ] Worktrees created and validated via verify-worktree.sh
|
|
120
|
+
- [ ] Implementers dispatched with full context
|
|
121
|
+
- [ ] All tasks report completion, all tests pass
|
|
122
|
+
- [ ] Schema sync run if API files modified
|
|
123
|
+
- [ ] State file reflects all task completions
|
|
124
|
+
|
|
125
|
+
## Transition
|
|
126
|
+
|
|
127
|
+
After all tasks complete, **auto-continue immediately** (no user confirmation):
|
|
128
|
+
|
|
129
|
+
1. Verify all `tasks[].status === 'complete'` in workflow state
|
|
130
|
+
2. Update state: `action: "set"`, `phase: "review"`
|
|
131
|
+
3. Invoke: `Skill({ skill: "exarchos:review", args: "<plan-path>" })`
|
|
132
|
+
|
|
133
|
+
This is NOT a human checkpoint — workflow continues autonomously.
|
|
134
|
+
|
|
135
|
+
## Known Limitations
|
|
136
|
+
|
|
137
|
+
- **Agent Teams:** No session resumption, task status lag, one team per session, no nested teams, requires tmux/iTerm2. Cold start falls back to plan's parallel group strategy.
|
|
138
|
+
- **Subagents:** No visual monitoring, individual context windows, limited observability.
|
|
139
|
+
|
|
140
|
+
## Troubleshooting
|
|
141
|
+
|
|
142
|
+
See `references/troubleshooting.md` for MCP tool failures, state desync, worktree creation, teammate spawn timeouts, and task claim conflicts.
|
|
143
|
+
|
|
144
|
+
## Exarchos Integration
|
|
145
|
+
|
|
146
|
+
**Subagent mode:** Emit `task.assigned` on dispatch, use `exarchos_orchestrate task_complete` on completion. Phase transitions auto-emit `workflow.transition`.
|
|
147
|
+
|
|
148
|
+
**Agent-team mode:** Follow the 6-step saga. Do NOT mix with subagent-mode patterns — the TeammateIdle hook handles completion. See `references/agent-teams-saga.md`.
|
|
149
|
+
|
|
150
|
+
**Claim guard** (subagent only): Use `exarchos_orchestrate task_claim` for optimistic concurrency. On `ALREADY_CLAIMED`, skip and check status before re-dispatching.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Adaptive Orchestration
|
|
2
|
+
|
|
3
|
+
When using Agent Teams mode, the orchestrator can leverage historical data for smarter team composition.
|
|
4
|
+
|
|
5
|
+
## Pre-Delegation Intelligence
|
|
6
|
+
|
|
7
|
+
Before creating the team, query the TeamPerformanceView for historical teammate metrics:
|
|
8
|
+
- `exarchos_view` with `action: 'team_performance'` -- teammate efficiency, module expertise, quality gate pass rates
|
|
9
|
+
- Use `synthesizeIntelligence()` from SubagentStart hook for historical fix-cycle patterns per module
|
|
10
|
+
|
|
11
|
+
## Team Composition
|
|
12
|
+
|
|
13
|
+
Informed by historical metrics:
|
|
14
|
+
- **Team sizing:** Use `teamSizing.avgTasksPerTeammate` to determine optimal teammate count
|
|
15
|
+
- **Task assignment:** Match modules to teammates with relevant `moduleExpertise`
|
|
16
|
+
- **Cold start:** When no historical data exists, fall back to plan's parallel groups for sizing
|
|
17
|
+
|
|
18
|
+
## Guard-Aware Task Graph
|
|
19
|
+
|
|
20
|
+
Before creating the native Claude Code task list:
|
|
21
|
+
1. Build a dependency graph from plan task `blockedBy` fields
|
|
22
|
+
2. Identify the critical path through the dependency chain
|
|
23
|
+
3. Front-load independent tasks for maximum parallelism
|
|
24
|
+
4. On TeammateIdle, scan the task graph for newly unblocked tasks (tasks whose `blockedBy` dependencies are all completed) so teammates can claim them
|
|
25
|
+
|
|
26
|
+
## Intelligence Views
|
|
27
|
+
|
|
28
|
+
Two CQRS views provide team analytics:
|
|
29
|
+
|
|
30
|
+
- `exarchos_view` with `action: 'team_performance'` -- Query before delegation for team sizing and module assignment. Returns teammate metrics (tasks completed, avg duration, module expertise, quality gate pass rates) and team sizing recommendations.
|
|
31
|
+
- `exarchos_view` with `action: 'delegation_timeline'` -- Query after delegation for retrospective analysis. Returns task timeline with bottleneck detection (longest task, blocking dependencies).
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# Agent Teams Delegation Saga
|
|
2
|
+
|
|
3
|
+
Event-first delegation saga for Agent Teams mode. Every coordination action is preceded by an Exarchos event emission. The event stream is the authoritative record; native API calls are side effects.
|
|
4
|
+
|
|
5
|
+
**Architectural principle:** Events record intent. Native API calls execute effects.
|
|
6
|
+
|
|
7
|
+
## Delegation Saga (6 Steps)
|
|
8
|
+
|
|
9
|
+
The dispatch follows a saga pattern with compensable, pivot, and retryable transactions.
|
|
10
|
+
|
|
11
|
+
### Step 1: Create Team (COMPENSABLE)
|
|
12
|
+
|
|
13
|
+
```yaml
|
|
14
|
+
# Emit event (source of truth)
|
|
15
|
+
exarchos_event append:
|
|
16
|
+
stream: {featureId}
|
|
17
|
+
event:
|
|
18
|
+
type: "team.spawned"
|
|
19
|
+
teamName: {featureId}
|
|
20
|
+
teamSize: {N}
|
|
21
|
+
taskCount: {M}
|
|
22
|
+
dispatchMode: "agent-team"
|
|
23
|
+
|
|
24
|
+
# Execute side effect
|
|
25
|
+
TeamCreate:
|
|
26
|
+
team_name: {featureId}
|
|
27
|
+
description: "SDLC delegation for {featureId}"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Idempotency: before retrying, check if `~/.claude/teams/{featureId}/` already exists.
|
|
31
|
+
|
|
32
|
+
### Gate: Team Verification
|
|
33
|
+
|
|
34
|
+
Before proceeding to Step 2:
|
|
35
|
+
1. Verify team config exists: `~/.claude/teams/{featureId}/config.json`
|
|
36
|
+
2. Verify config has valid `members` array
|
|
37
|
+
3. If check fails: emit `team.creation.failed` event, abort delegation
|
|
38
|
+
|
|
39
|
+
### Step 2: Create Native Tasks (COMPENSABLE)
|
|
40
|
+
|
|
41
|
+
Emit ALL task planning events in a single batched call (1 MCP call instead of N):
|
|
42
|
+
|
|
43
|
+
```yaml
|
|
44
|
+
# Emit ALL task events in one batch (source of truth)
|
|
45
|
+
exarchos_event batch_append:
|
|
46
|
+
stream: {featureId}
|
|
47
|
+
events:
|
|
48
|
+
- type: "team.task.planned"
|
|
49
|
+
taskId: "task-001"
|
|
50
|
+
title: {task.title}
|
|
51
|
+
modules: {task.files}
|
|
52
|
+
blockedBy: {task.blockedBy}
|
|
53
|
+
- type: "team.task.planned"
|
|
54
|
+
taskId: "task-002"
|
|
55
|
+
...
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`batch_append` atomicity: acquires the stream lock once, validates all events, writes with sequential sequence numbers in a single append. All-or-nothing -- if any event fails validation, none are written.
|
|
59
|
+
|
|
60
|
+
Then create native tasks and wire dependencies:
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
# Execute side effects (one TaskCreate per task)
|
|
64
|
+
TaskCreate:
|
|
65
|
+
subject: {task.title}
|
|
66
|
+
description: {task.fullDescription}
|
|
67
|
+
activeForm: "Implementing {task.title}"
|
|
68
|
+
# Returns nativeTaskId
|
|
69
|
+
|
|
70
|
+
# Wire dependencies (after ALL tasks created -- requires sequential creation)
|
|
71
|
+
TaskUpdate:
|
|
72
|
+
taskId: {nativeTaskId}
|
|
73
|
+
addBlockedBy: [{blockerNativeTaskIds}]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Idempotency: before retrying, check `TaskList` for existing tasks with matching subjects to avoid duplicates.
|
|
77
|
+
|
|
78
|
+
After all tasks are created, store the correlation (orchestrator is the **sole writer** of `workflow.tasks[]`):
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
exarchos_workflow set:
|
|
82
|
+
featureId: {featureId}
|
|
83
|
+
updates:
|
|
84
|
+
tasks: [{...task, nativeTaskId: "returned-id"}]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Step 3: Spawn Teammates (PIVOT -- point of no return)
|
|
88
|
+
|
|
89
|
+
> This is the **pivot transaction**. Once teammates start working, their side effects (file writes, commits, worktree modifications) cannot be cleanly reversed. Steps 1-2 are compensable; Step 3+ are not fully reversible.
|
|
90
|
+
|
|
91
|
+
For each teammate:
|
|
92
|
+
|
|
93
|
+
```yaml
|
|
94
|
+
# Emit event (source of truth)
|
|
95
|
+
exarchos_event append:
|
|
96
|
+
stream: {featureId}
|
|
97
|
+
event:
|
|
98
|
+
type: "team.teammate.dispatched"
|
|
99
|
+
teammateName: {name}
|
|
100
|
+
worktreePath: {path}
|
|
101
|
+
assignedTaskIds: [{taskIds}]
|
|
102
|
+
model: "opus"
|
|
103
|
+
|
|
104
|
+
# Execute side effect
|
|
105
|
+
# Note: teammates inherit the lead's permission mode (per Claude Code docs).
|
|
106
|
+
# Do NOT set `mode` at spawn -- it is not respected.
|
|
107
|
+
Task:
|
|
108
|
+
subagent_type: "general-purpose"
|
|
109
|
+
team_name: {featureId}
|
|
110
|
+
name: {teammateName}
|
|
111
|
+
model: "opus"
|
|
112
|
+
prompt: {spawnPrompt} # See implementer-prompt.md template
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Step 4: Monitor (RETRYABLE)
|
|
116
|
+
|
|
117
|
+
The orchestrator enters delegate mode (Shift+Tab). Hooks operate autonomously:
|
|
118
|
+
- **SubagentStart** -- injects live coordination data only (task status changes, newly unblocked tasks). Historical intelligence and team context are already in the spawn prompt.
|
|
119
|
+
- **TeammateIdle** -- runs quality gates, emits `team.task.completed` or `team.task.failed` events. Does NOT mutate `workflow.tasks[]` (single-writer principle). The orchestrator reads these events and updates state.
|
|
120
|
+
|
|
121
|
+
**Tiered monitoring strategy** (minimizes token cost):
|
|
122
|
+
|
|
123
|
+
| Tier | Tool | When | Cost |
|
|
124
|
+
|------|------|------|------|
|
|
125
|
+
| Routine | `exarchos_view workflow_status` | Every 30-60s | ~85 tokens |
|
|
126
|
+
| On task completion | `exarchos_workflow get` (fields: tasks) | When TeammateIdle fires | ~200 tokens |
|
|
127
|
+
| On-demand | `exarchos_view delegation_timeline` | Task stall or all complete | ~120 tokens |
|
|
128
|
+
|
|
129
|
+
Do NOT triple-read on every cycle. `delegation_timeline` replays the full event stream -- reserve for final summary or anomaly detection.
|
|
130
|
+
|
|
131
|
+
When the orchestrator detects `team.task.completed` events, it updates `workflow.tasks[]`:
|
|
132
|
+
```yaml
|
|
133
|
+
exarchos_workflow set:
|
|
134
|
+
featureId: {featureId}
|
|
135
|
+
updates:
|
|
136
|
+
tasks: [{...task, status: "complete", completedAt: timestamp}]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Step 5: Disband (RETRYABLE)
|
|
140
|
+
|
|
141
|
+
When all tasks complete:
|
|
142
|
+
|
|
143
|
+
```yaml
|
|
144
|
+
# Emit event
|
|
145
|
+
exarchos_event append:
|
|
146
|
+
stream: {featureId}
|
|
147
|
+
event:
|
|
148
|
+
type: "team.disbanded"
|
|
149
|
+
totalDurationMs: {calculated}
|
|
150
|
+
tasksCompleted: {count}
|
|
151
|
+
tasksFailed: {count}
|
|
152
|
+
|
|
153
|
+
# Shutdown remaining teammates
|
|
154
|
+
SendMessage:
|
|
155
|
+
type: "shutdown_request"
|
|
156
|
+
recipient: {each remaining teammate}
|
|
157
|
+
|
|
158
|
+
# Cleanup native team (after all teammates confirm shutdown)
|
|
159
|
+
TeamDelete
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Step 6: Transition (RETRYABLE)
|
|
163
|
+
|
|
164
|
+
```yaml
|
|
165
|
+
exarchos_workflow set:
|
|
166
|
+
featureId: {featureId}
|
|
167
|
+
phase: "review"
|
|
168
|
+
# auto-emits workflow.transition event
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Saga Compensation
|
|
172
|
+
|
|
173
|
+
When the saga fails at any step, compensate in reverse order:
|
|
174
|
+
|
|
175
|
+
| Failed At | Compensating Actions | Idempotency Check |
|
|
176
|
+
|-----------|---------------------|-------------------|
|
|
177
|
+
| Step 1 (team create) | `TeamDelete` | Check `~/.claude/teams/{featureId}/` exists before delete |
|
|
178
|
+
| Step 2 (task create) | Delete created tasks via `TaskUpdate(status: "deleted")` x created, then `TeamDelete` | Check `TaskList` for existing tasks before delete |
|
|
179
|
+
| Step 3 (spawn -- PIVOT) | `SendMessage(type: "shutdown_request")` x spawned teammates, delete tasks, `TeamDelete` | Check team config `members` array for active teammates |
|
|
180
|
+
| Step 4+ (monitoring) | `exarchos_workflow cancel` (handles full compensation) | Already idempotent via workflow state check |
|
|
181
|
+
|
|
182
|
+
Compensation steps themselves must be idempotent: deleting an already-deleted team is a no-op; shutting down an already-terminated teammate is a no-op.
|
|
183
|
+
|
|
184
|
+
If a compensating action itself fails after 3 retries, mark the workflow with `_compensationFailed: true` and emit `team.compensation.failed`. The SessionStart hook detects this on next session for manual resolution.
|
|
185
|
+
|
|
186
|
+
## Claude Code Agent Teams Constraints
|
|
187
|
+
|
|
188
|
+
| Constraint | Impact |
|
|
189
|
+
|------------|--------|
|
|
190
|
+
| **No session resumption** for teammates | Teammates are ephemeral. On restart, SessionStart detects orphaned teams but cannot restore them. Spawn new teammates if delegation is incomplete. |
|
|
191
|
+
| **One team per session** | Naturally enforces single-orchestrator invariant. No additional locking needed. |
|
|
192
|
+
| **No nested teams** | Teammates cannot spawn sub-teams. Team composition is flat. |
|
|
193
|
+
| **Permissions inherit from lead** | Do NOT set `mode` at spawn -- not respected. All teammates inherit the lead's permission mode. |
|
|
194
|
+
| **Teammates load MCP automatically** | Exarchos MCP tools are available without explicit instruction. The spawn prompt guides WHICH tools to use, not HOW to access them. |
|
|
195
|
+
|
|
196
|
+
**CRITICAL:** Ensure your session is using the opus model for coding tasks. All teammates inherit the session model -- use Task tool dispatch if you need per-task model selection.
|
|
197
|
+
|
|
198
|
+
## Event Payload Conventions
|
|
199
|
+
|
|
200
|
+
Keep event payloads lean. Move diagnostics to state files.
|
|
201
|
+
|
|
202
|
+
- `team.task.completed`: prefer `fileCount: number` over `filesChanged: string[]`
|
|
203
|
+
- `team.task.failed`: prefer `gateNames: string[]` (max 10) over `gateResults: Record<string, unknown>`
|
|
204
|
+
- `failureReason`: max 200 characters
|
|
205
|
+
- Move full diagnostics to state file `reviews[taskId]`, not event payloads
|
|
206
|
+
|
|
207
|
+
## State Bridge (TeammateIdle)
|
|
208
|
+
|
|
209
|
+
When using Agent Teams mode, the `TeammateIdle` hook fires when a teammate completes its work and becomes idle. It bridges real-time Agent Teams coordination with the Exarchos event stream:
|
|
210
|
+
|
|
211
|
+
- **On quality pass:** Emits `team.task.completed` event to the event stream. Does NOT mutate `workflow.tasks[]` -- the orchestrator is the sole writer (single-writer principle).
|
|
212
|
+
- **On quality fail:** Returns exit code 2 (sends feedback to teammate, keeps it working). Emits `team.task.failed` event with gate results.
|
|
213
|
+
- **Circuit breaker:** On repeated quality failures, emits `team.task.failed` with circuit open signal.
|
|
214
|
+
- **Graceful degradation:** If no matching workflow/worktree found, gate still passes.
|
|
215
|
+
|
|
216
|
+
**Single-writer principle:** The orchestrator reads `team.task.completed` events during its monitoring loop and updates `workflow.tasks[]` via `exarchos_workflow set`. This eliminates CAS race conditions between hook and orchestrator writes. The 30-60s latency between event emission and projection update is acceptable -- native task dependency unblocking is automatic (handled by Claude Code) and unaffected by this delay.
|
|
217
|
+
|
|
218
|
+
This implements a **layered coordination** model:
|
|
219
|
+
- Agent Teams handles real-time dispatch and self-coordination
|
|
220
|
+
- Exarchos event stream records all lifecycle events (source of truth)
|
|
221
|
+
- Orchestrator materializes events into `workflow.tasks[]` (working projection)
|
|
222
|
+
|
|
223
|
+
## Agent Teams Event Emission
|
|
224
|
+
|
|
225
|
+
When using Agent Teams mode, the delegation saga emits events at each lifecycle boundary:
|
|
226
|
+
|
|
227
|
+
**Orchestrator-emitted events (saga steps):**
|
|
228
|
+
- `team.spawned` -- Step 1: team creation (includes teamName, teamSize, taskCount, dispatchMode)
|
|
229
|
+
- `team.task.planned` -- Step 2: task planning via `batch_append` (includes taskId, title, modules, blockedBy)
|
|
230
|
+
- `team.teammate.dispatched` -- Step 3: teammate spawn (includes teammateName, worktreePath, assignedTaskIds, model)
|
|
231
|
+
- `team.disbanded` -- Step 5: team disbandment (includes totalDurationMs, tasksCompleted, tasksFailed)
|
|
232
|
+
|
|
233
|
+
**Hook-emitted events (automatic via TeammateIdle):**
|
|
234
|
+
- `team.task.completed` -- After quality gates pass (includes taskId, teammateName, durationMs, filesChanged, testsPassed). Hook emits only; does NOT mutate workflow state.
|
|
235
|
+
- `team.task.failed` -- After quality gates fail (includes taskId, teammateName, failureReason, gateResults). Hook emits only.
|
|
236
|
+
- `team.context.injected` -- From SubagentStart hook (includes phase, toolsAvailable)
|
|
237
|
+
|
|
238
|
+
**Superseded events:**
|
|
239
|
+
- `team.task.assigned` -- Superseded by the combination of `team.task.planned` (Step 2) + `team.teammate.dispatched` (Step 3). Existing event streams may still contain `team.task.assigned` events; CQRS views handle both old and new types during the transition period.
|
|
240
|
+
|
|
241
|
+
**Tool usage by delegation mode:**
|
|
242
|
+
|
|
243
|
+
| Delegation Mode | Task Completion Signal | State Update |
|
|
244
|
+
|----------------|----------------------|--------------|
|
|
245
|
+
| **Subagent mode** | `exarchos_orchestrate task_complete` (auto-emits `task.completed`) | Orchestrator calls `exarchos_workflow set` |
|
|
246
|
+
| **Agent team mode** | TeammateIdle hook emits `team.task.completed` | Orchestrator reads event, calls `exarchos_workflow set` |
|
|
247
|
+
|
|
248
|
+
> **Important:** Do NOT use `exarchos_orchestrate task_complete` or `task_fail` during agent team delegation. The TeammateIdle hook handles completion signaling. Using both would produce duplicate events in the stream.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fix-mode
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Fix Mode (--fixes)
|
|
6
|
+
|
|
7
|
+
When invoked with `--fixes`, delegation handles review failures instead of initial implementation.
|
|
8
|
+
|
|
9
|
+
## Trigger
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
/exarchos:delegate --fixes docs/plans/YYYY-MM-DD-feature.md
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or auto-invoked after review failures.
|
|
16
|
+
|
|
17
|
+
## Fix Mode Process
|
|
18
|
+
|
|
19
|
+
1. **Read failure details** from state using `mcp__exarchos__exarchos_workflow` with `action: "get"`:
|
|
20
|
+
- Query `reviews` for review failures
|
|
21
|
+
|
|
22
|
+
2. **Extract fix tasks** from failure reports:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
bash scripts/extract-fix-tasks.sh --state-file <path> [--review-report <path>] [--repo-root <path>]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**On exit 0:** Tasks extracted successfully (JSON array on stdout).
|
|
29
|
+
**On exit 1:** Parse error — review report or state file malformed.
|
|
30
|
+
|
|
31
|
+
3. **Create fix tasks** for each issue:
|
|
32
|
+
- Use `fixer-prompt.md` template
|
|
33
|
+
- Include full issue context
|
|
34
|
+
- Specify target worktree
|
|
35
|
+
|
|
36
|
+
4. **Dispatch fixers** (same as implementers, different prompt):
|
|
37
|
+
```typescript
|
|
38
|
+
Task({
|
|
39
|
+
subagent_type: "general-purpose",
|
|
40
|
+
model: "opus",
|
|
41
|
+
description: "Fix: [issue summary]",
|
|
42
|
+
prompt: "[fixer-prompt template with issue details]"
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
5. **Re-review after fixes**:
|
|
47
|
+
After all fix tasks complete, auto-invoke review phase:
|
|
48
|
+
```typescript
|
|
49
|
+
Skill({ skill: "exarchos:review", args: "<state-file>" })
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Fix Task Structure
|
|
53
|
+
|
|
54
|
+
Each fix task extracted should include:
|
|
55
|
+
|
|
56
|
+
| Field | Description |
|
|
57
|
+
|-------|-------------|
|
|
58
|
+
| issue | Problem description from review |
|
|
59
|
+
| file | File path needing fix |
|
|
60
|
+
| line | Line number (if known) |
|
|
61
|
+
| worktree | Which worktree to fix in |
|
|
62
|
+
| branch | Which branch owns this fix |
|
|
63
|
+
| priority | HIGH / MEDIUM / LOW |
|
|
64
|
+
|
|
65
|
+
## Transition After Fixes
|
|
66
|
+
|
|
67
|
+
Fix mode goes back to the integration phase after fixes are applied,
|
|
68
|
+
then re-enters review to re-integrate and re-verify:
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
/exarchos:delegate --fixes -> [fixes applied] -> re-integrate -> /exarchos:review
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This ensures fixed code is re-verified.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Fixer Prompt Template
|
|
2
|
+
|
|
3
|
+
Use this template when dispatching fix tasks via the Task tool after review failures.
|
|
4
|
+
|
|
5
|
+
## Template
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
8
|
+
# Fix Task: [Issue Summary]
|
|
9
|
+
|
|
10
|
+
## CRITICAL: Worktree Verification (MANDATORY)
|
|
11
|
+
|
|
12
|
+
Before making ANY changes:
|
|
13
|
+
1. Run: `pwd`
|
|
14
|
+
2. Verify path contains `.worktrees/`
|
|
15
|
+
3. If NOT in worktree: STOP and report error
|
|
16
|
+
|
|
17
|
+
## Working Directory
|
|
18
|
+
[Absolute path to worktree]
|
|
19
|
+
|
|
20
|
+
## Issue to Fix
|
|
21
|
+
|
|
22
|
+
**Source:** [Spec Review | Quality Review | PR Feedback]
|
|
23
|
+
**File:** `[path/to/file.ts]`
|
|
24
|
+
**Line:** [line number if applicable]
|
|
25
|
+
**Priority:** [HIGH | MEDIUM | LOW]
|
|
26
|
+
|
|
27
|
+
### Problem
|
|
28
|
+
[Clear description of the issue from review]
|
|
29
|
+
|
|
30
|
+
### Expected Behavior
|
|
31
|
+
[What the code should do instead]
|
|
32
|
+
|
|
33
|
+
### Suggested Fix
|
|
34
|
+
[Specific guidance on how to fix, from review report]
|
|
35
|
+
|
|
36
|
+
## Verification
|
|
37
|
+
|
|
38
|
+
After implementing the fix:
|
|
39
|
+
|
|
40
|
+
1. **Run tests:**
|
|
41
|
+
```bash
|
|
42
|
+
npm run test:run
|
|
43
|
+
```
|
|
44
|
+
Ensure all tests pass.
|
|
45
|
+
|
|
46
|
+
2. **If this fix requires a new test:**
|
|
47
|
+
- Write test FIRST (TDD)
|
|
48
|
+
- Verify it fails for the expected reason
|
|
49
|
+
- Implement fix
|
|
50
|
+
- Verify test passes
|
|
51
|
+
|
|
52
|
+
3. **Run quality checks:**
|
|
53
|
+
```bash
|
|
54
|
+
npm run typecheck
|
|
55
|
+
npm run lint
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## TDD for New Tests
|
|
59
|
+
|
|
60
|
+
If adding a test to prevent regression:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
describe('[ComponentName]', () => {
|
|
64
|
+
it('should [expected behavior] when [condition]', () => {
|
|
65
|
+
// Arrange
|
|
66
|
+
[Setup that reproduces the bug]
|
|
67
|
+
|
|
68
|
+
// Act
|
|
69
|
+
[Execute the code path]
|
|
70
|
+
|
|
71
|
+
// Assert
|
|
72
|
+
expect(result).[matcher](expected);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Success Criteria
|
|
78
|
+
|
|
79
|
+
- [ ] Worktree verified before changes
|
|
80
|
+
- [ ] Issue addressed per review feedback
|
|
81
|
+
- [ ] New test written if applicable
|
|
82
|
+
- [ ] All existing tests pass
|
|
83
|
+
- [ ] Type check passes
|
|
84
|
+
- [ ] Lint passes
|
|
85
|
+
- [ ] No regressions introduced
|
|
86
|
+
|
|
87
|
+
## Completion
|
|
88
|
+
|
|
89
|
+
When done, report:
|
|
90
|
+
1. Files modified
|
|
91
|
+
2. Test results
|
|
92
|
+
3. Summary of fix applied
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Usage Example
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
Task({
|
|
99
|
+
subagent_type: "general-purpose",
|
|
100
|
+
model: "opus",
|
|
101
|
+
description: "Fix: SQL injection vulnerability",
|
|
102
|
+
prompt: `
|
|
103
|
+
# Fix Task: SQL Injection in User Query
|
|
104
|
+
|
|
105
|
+
## CRITICAL: Worktree Verification (MANDATORY)
|
|
106
|
+
|
|
107
|
+
Before making ANY changes:
|
|
108
|
+
1. Run: \`pwd\`
|
|
109
|
+
2. Verify path contains \`.worktrees/\`
|
|
110
|
+
3. If NOT in worktree: STOP and report error
|
|
111
|
+
|
|
112
|
+
## Working Directory
|
|
113
|
+
/home/user/project/.worktrees/task-003
|
|
114
|
+
|
|
115
|
+
## Issue to Fix
|
|
116
|
+
|
|
117
|
+
**Source:** Quality Review
|
|
118
|
+
**File:** \`src/api/users.ts\`
|
|
119
|
+
**Line:** 42
|
|
120
|
+
**Priority:** HIGH
|
|
121
|
+
|
|
122
|
+
### Problem
|
|
123
|
+
Raw string interpolation in SQL query allows injection attacks.
|
|
124
|
+
|
|
125
|
+
### Expected Behavior
|
|
126
|
+
Use parameterized queries to prevent SQL injection.
|
|
127
|
+
|
|
128
|
+
### Suggested Fix
|
|
129
|
+
Replace:
|
|
130
|
+
\`\`\`typescript
|
|
131
|
+
db.query(\`SELECT * FROM users WHERE id = \${userId}\`)
|
|
132
|
+
\`\`\`
|
|
133
|
+
With:
|
|
134
|
+
\`\`\`typescript
|
|
135
|
+
db.query('SELECT * FROM users WHERE id = $1', [userId])
|
|
136
|
+
\`\`\`
|
|
137
|
+
|
|
138
|
+
## Verification
|
|
139
|
+
|
|
140
|
+
After implementing the fix:
|
|
141
|
+
|
|
142
|
+
1. Run tests: \`npm run test:run\`
|
|
143
|
+
2. Add test for SQL injection prevention
|
|
144
|
+
3. Run quality checks
|
|
145
|
+
|
|
146
|
+
## Success Criteria
|
|
147
|
+
|
|
148
|
+
- [ ] Worktree verified
|
|
149
|
+
- [ ] Parameterized query implemented
|
|
150
|
+
- [ ] Injection test added
|
|
151
|
+
- [ ] All tests pass
|
|
152
|
+
`
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Key Principles
|
|
157
|
+
|
|
158
|
+
1. **Always verify worktree** - First action is pwd check
|
|
159
|
+
2. **Clear issue description** - Include file, line, problem
|
|
160
|
+
3. **Specific fix guidance** - Show before/after when possible
|
|
161
|
+
4. **Verification steps** - Always run tests after fix
|
|
162
|
+
5. **TDD for regressions** - Add test to prevent recurrence
|