@menghuan1918/dsh-apollo 0.0.0-stage → 0.4.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 (40) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +253 -2
  3. package/cordis.patch.yml +78 -0
  4. package/docs/DEVELOPMENT.md +682 -0
  5. package/package.json +76 -4
  6. package/presets/eng/NOTICE +3 -0
  7. package/presets/eng/plugins/exit-guard/index.js +111 -0
  8. package/presets/eng/plugins/exit-guard/package.json +7 -0
  9. package/presets/eng/plugins/mode-instructions/index.js +124 -0
  10. package/presets/eng/plugins/mode-instructions/package.json +7 -0
  11. package/presets/eng/plugins/wait-subagent/index.js +233 -0
  12. package/presets/eng/plugins/wait-subagent/package.json +7 -0
  13. package/presets/eng-ptc.patch.yml +186 -0
  14. package/presets/eng.patch.yml +338 -0
  15. package/skills/brainstorming/SKILL.md +90 -0
  16. package/skills/brainstorming/spec-document-reviewer-prompt.md +50 -0
  17. package/skills/code-review/SKILL.md +90 -0
  18. package/skills/dev/SKILL.md +41 -0
  19. package/skills/diagnosing-bugs/SKILL.md +132 -0
  20. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +55 -0
  21. package/skills/exec/SKILL.md +78 -0
  22. package/skills/handoff/SKILL.md +23 -0
  23. package/skills/main-agent-driven-development/SKILL.md +64 -0
  24. package/skills/tdd/SKILL.md +34 -0
  25. package/skills/tdd/mocking.md +59 -0
  26. package/skills/tdd/tests.md +77 -0
  27. package/src/cli/claude.js +166 -0
  28. package/src/cli/codex.js +164 -0
  29. package/src/cli/jsonl.js +216 -0
  30. package/src/cli-adapter.js +198 -0
  31. package/src/cli-sessions.js +69 -0
  32. package/src/client.js +1128 -0
  33. package/src/config.js +327 -0
  34. package/src/dsh-home.js +38 -0
  35. package/src/index.js +181 -0
  36. package/src/panel.js +844 -0
  37. package/src/settings.js +191 -0
  38. package/src/subagents.js +198 -0
  39. package/third-party/LICENSE-MIT-dsh-standard-preset +21 -0
  40. package/third-party/NOTICE-mattpocock-skills +21 -0
@@ -0,0 +1,50 @@
1
+ # Spec Document Reviewer Prompt Template
2
+
3
+ Use this template when dispatching a spec document reviewer via the `subagent` tool (fresh read-only child, quality tier).
4
+
5
+ **Purpose:** Verify a master Spec or sub-Spec is complete, consistent, and ready for implementation.
6
+
7
+ **Dispatch after:** Spec document is written to the workspace's spec directory (`.workspace-docs/specs/` where that convention exists, otherwise the target repo's own specs directory).
8
+
9
+ ```
10
+ subagent(
11
+ prompt="You are a spec document reviewer. Verify this spec is complete and ready for implementation.
12
+
13
+ **Spec to review:** [SPEC_FILE_PATH]
14
+ **Spec type:** [master | sub]
15
+ **Master Spec, if this is a sub-Spec:** [MASTER_SPEC_FILE_PATH or N/A]
16
+
17
+ ## What to Check
18
+
19
+ | Category | What to Look For |
20
+ |----------|------------------|
21
+ | Frontmatter | Where the workspace uses OKF: parseable YAML frontmatter with `type: Design Spec`, `title`, `description`, `tags`, `status`, and `repos` (plural `tags`, never a singular `tag`). Where it does not: the header matches the surrounding specs instead |
22
+ | Completeness | TODOs, placeholders, "TBD", incomplete sections |
23
+ | Consistency | Internal contradictions, conflicting requirements |
24
+ | Clarity | Requirements ambiguous enough to cause someone to build the wrong thing |
25
+ | Scope | Master Specs decompose large work into sub-Specs; sub-Specs are independently implementable and do not try to implement the whole master Spec |
26
+ | YAGNI | Unrequested features, over-engineering |
27
+
28
+ ## Calibration
29
+
30
+ **Only flag issues that would cause real problems during implementation.**
31
+ A missing section, a contradiction, or a requirement so ambiguous it could be
32
+ interpreted two different ways — those are issues. Minor wording improvements,
33
+ stylistic preferences, and "sections less detailed than others" are not.
34
+
35
+ Approve unless there are serious gaps that would lead to a flawed implementation. Do not reject a master Spec merely because it covers multiple subsystems; reject it only if it lacks clear sub-Specs, ordering, boundaries, or shared contracts. Do not reject a sub-Spec merely because it does not implement the whole master Spec.
36
+
37
+ ## Output Format
38
+
39
+ ## Spec Review
40
+
41
+ **Status:** Approved | Issues Found
42
+
43
+ **Issues (if any):**
44
+ - [Section X]: [specific issue] - [why it matters for implementation]
45
+
46
+ **Recommendations (advisory, do not block approval):**
47
+ - [suggestions for improvement]
48
+ ```
49
+
50
+ **Reviewer returns:** Status, Issues (if any), Recommendations
@@ -0,0 +1,90 @@
1
+ ---
2
+ name: code-review
3
+ description: Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes — Standards (does the code follow this repo's documented coding standards?) and Spec (does the code match what the originating issue/PRD asked for?). Runs both reviews as parallel `subagent` delegations and reports them side by side. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to "review since X".
4
+ ---
5
+
6
+ # Code Review
7
+
8
+ Two-axis review of the diff between `HEAD` and a fixed point the user supplies:
9
+
10
+ - **Standards** — does the code conform to this repo's documented coding standards?
11
+ - **Spec** — does the code faithfully implement the originating issue / PRD / spec?
12
+
13
+ Both axes run as parallel `subagent` delegations so they don't pollute each other's context, then this skill aggregates their findings.
14
+
15
+ ## Process
16
+
17
+ ### 1. Pin the fixed point
18
+
19
+ Whatever the user said is the fixed point — a commit SHA, branch name, tag, `main`, `HEAD~5`, etc. If they didn't specify one, ask for it.
20
+
21
+ Capture the diff command once: `git diff <fixed-point>...HEAD` (three-dot, so the comparison is against the merge-base). Also note the list of commits via `git log <fixed-point>..HEAD --oneline`.
22
+
23
+ Before going further, confirm the fixed point resolves (`git rev-parse <fixed-point>`) and the diff is non-empty. A bad ref or empty diff should fail here — not inside two parallel agents.
24
+
25
+ ### 2. Identify the spec source
26
+
27
+ Look for the originating spec, in this order:
28
+
29
+ 1. Issue references in the commit messages (`#123`, `Closes #45`, GitLab `!67`, etc.)
30
+ 2. A path the user passed as an argument.
31
+ 3. A spec/PRD file under `docs/`, `specs/`, `.workspace-docs/`, or `.scratch/` matching the branch name or feature.
32
+ 4. If nothing is found, ask the user where the spec is. If they say there isn't one, the **Spec** agent will skip and report "no spec available".
33
+
34
+ ### 3. Identify the standards sources
35
+
36
+ Anything in the repo that documents how code should be written, such as `CODING_STANDARDS.md`, `CONTRIBUTING.md`, `CLAUDE.md`, or `AGENTS.md`.
37
+
38
+ On top of whatever the repo documents, the Standards axis always carries the **smell baseline** below — a fixed set of Fowler code smells (_Refactoring_, ch.3) that applies even when a repo documents nothing. Two rules bind it:
39
+
40
+ - **The repo overrides.** A documented repo standard always wins; where it endorses something the baseline would flag, suppress the smell.
41
+ - **Always a judgement call.** Each smell is a labelled heuristic ("possible Feature Envy"), never a hard violation — and, like any standard here, skip anything tooling already enforces.
42
+
43
+ Each smell reads *what it is* → *how to fix*; match it against the diff:
44
+
45
+ - **Mysterious Name** — a function, variable, or type whose name doesn't reveal what it does or holds. → rename it; if no honest name comes, the design's murky.
46
+ - **Duplicated Code** — the same logic shape appears in more than one hunk or file in the change. → extract the shared shape, call it from both.
47
+ - **Feature Envy** — a method that reaches into another object's data more than its own. → move the method onto the data it envies.
48
+ - **Data Clumps** — the same few fields or params keep travelling together (a type wanting to be born). → bundle them into one type, pass that.
49
+ - **Primitive Obsession** — a primitive or string standing in for a domain concept that deserves its own type. → give the concept its own small type.
50
+ - **Repeated Switches** — the same `switch`/`if`-cascade on the same type recurs across the change. → replace with polymorphism, or one map both sites share.
51
+ - **Shotgun Surgery** — one logical change forces scattered edits across many files in the diff. → gather what changes together into one module.
52
+ - **Divergent Change** — one file or module is edited for several unrelated reasons. → split so each module changes for one reason.
53
+ - **Speculative Generality** — abstraction, parameters, or hooks added for needs the spec doesn't have. → delete it; inline back until a real need shows.
54
+ - **Message Chains** — long `a.b().c().d()` navigation the caller shouldn't depend on. → hide the walk behind one method on the first object.
55
+ - **Middle Man** — a class or function that mostly just delegates onward. → cut it, call the real target direct.
56
+ - **Refused Bequest** — a subclass or implementer that ignores or overrides most of what it inherits. → drop the inheritance, use composition.
57
+
58
+ ### 4. Spawn both sub-agents in parallel
59
+
60
+ Send both `subagent` calls in a single message — each a fresh quality-tier child with a fully self-contained prompt; children see none of this conversation.
61
+
62
+ **Standards sub-agent prompt** — include:
63
+
64
+ - The full diff command and commit list.
65
+ - The list of standards-source files you found in step 3, **plus the smell baseline from step 3** pasted in full — the sub-agent has no other access to it.
66
+ - The brief: "Report — per file/hunk where relevant — (a) every place the diff violates a documented standard: cite the standard (file + the rule); and (b) any baseline smell you spot: name it and quote the hunk. Distinguish hard violations from judgement calls — documented-standard breaches can be hard, but baseline smells are always judgement calls, and a documented repo standard overrides the baseline. Skip anything tooling enforces. Under 400 words."
67
+
68
+ **Spec sub-agent prompt** — include:
69
+
70
+ - The diff command and commit list.
71
+ - The path or fetched contents of the spec.
72
+ - The brief: "Report: (a) requirements the spec asked for that are missing or partial; (b) behaviour in the diff that wasn't asked for (scope creep); (c) requirements that look implemented but where the implementation looks wrong. Quote the spec line for each finding. Under 400 words."
73
+
74
+ If the spec is missing, skip the Spec agent and note this in the final report.
75
+
76
+ ### 5. Aggregate
77
+
78
+ Present the two reports under `## Standards` and `## Spec` headings, verbatim or lightly cleaned. Do **not** merge or rerank findings — the two axes are deliberately separate.
79
+
80
+ End with a one-line summary: total findings per axis, and the worst issue _within each axis_ (if any).
81
+
82
+ ## Handling review feedback
83
+
84
+ When you receive feedback from a review:
85
+
86
+ 1. **Verify before implementing.** Check each finding against the codebase — does it break existing functionality? Is the reviewer missing context? Is the current implementation intentional?
87
+ 2. **Push back with reasoning** when a finding is wrong — reference working code, tests, or architectural decisions.
88
+ 3. **No performative agreement.** State the fix, not "Great point!" or "You're absolutely right!" — just fix it and show the result.
89
+ 4. **YAGNI check.** When a reviewer suggests "implementing properly", grep for actual usage. If unused, propose removal instead.
90
+ 5. **Fix in order:** blocking issues → simple fixes → complex fixes. Test each fix individually.
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: dev
3
+ description: "Node contract for the DSH execution backend: prompt requirements, report formats, and failure semantics for implementation and review nodes."
4
+ ---
5
+
6
+ # Built-in development backend (node contracts)
7
+
8
+ This skill defines the execution backend's two node types. Wave orchestration (worktrees, merging, cleanup, review-loop scheduling) belongs to `/exec`; this skill must not create, merge, or delete worktrees. Subagents have no independent working directory and cannot see the orchestration session: every node input must come with the prompt (absolute worktree path, Spec path, shared contracts, verification commands), with bash always using `workdir` and file tools always using absolute paths.
9
+
10
+ ## Implementation node (develop)
11
+
12
+ One brand-new subagent (quality tier) handles exactly one sub-Spec, following `main-agent-driven-development` in prebuilt-worktree mode (in an `/exec` wave, skip its internal review step — the review loop is run by `/exec`, and nodes do not dispatch reviewers themselves).
13
+
14
+ Report format (JSON code block at the end of the closing message):
15
+
16
+ ```js
17
+ {
18
+ status: 'complete' | 'blocked',
19
+ commit: '<final commit SHA>',
20
+ verification: '<verification commands run this round and their results>',
21
+ summary: '<implementation summary for the reviewer and orchestrator>',
22
+ blocker: '<required when status=blocked>'
23
+ }
24
+ ```
25
+
26
+ ## Review node (review-only)
27
+
28
+ A brand-new read-only subagent (quality tier). The prompt supplies: absolute worktree path, diff range, Spec path, implementation summary, and verification already run. Four-state verdict format (JSON code block at the end of the closing message):
29
+
30
+ ```js
31
+ {
32
+ status: 'APPROVED' | 'APPROVED_WITH_NOTES' | 'CHANGES_REQUIRED' | 'BLOCKED',
33
+ findings: ['<issue, with file and line number>']
34
+ }
35
+ ```
36
+
37
+ Serious correctness errors, Spec gaps, integration risks, security issues, or missing verification must yield `CHANGES_REQUIRED`. Do not edit, commit, or merge.
38
+
39
+ ## Failure semantics
40
+
41
+ A subagent failure (error / empty return) = `node-failed`; `blocked`, timeouts, partial replies, or uncommitted results never count as complete. The caller decides whether to redispatch, or to continue via `send_message` only when unblocking the same sub-Spec. Never reuse a node for another sub-Spec.
@@ -0,0 +1,132 @@
1
+ ---
2
+ name: diagnosing-bugs
3
+ description: Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.
4
+ ---
5
+
6
+ # Diagnosing Bugs
7
+
8
+ A discipline for hard bugs. Skip phases only when explicitly justified.
9
+
10
+ ## Phase 1 — Build a feedback loop
11
+
12
+ **This is the skill.** Everything else is mechanical. If you have a **tight** pass/fail signal for the bug — one that goes red on _this_ bug — you will find the cause; bisection, hypothesis-testing, and instrumentation all just consume it. If you don't have one, no amount of staring at code will save you.
13
+
14
+ Spend disproportionate effort here. **Be aggressive. Be creative. Refuse to give up.**
15
+
16
+ ### Ways to construct one — try them in roughly this order
17
+
18
+ 1. **Failing test** at whatever seam reaches the bug — unit, integration, e2e.
19
+ 2. **Curl / HTTP script** against a running dev server.
20
+ 3. **CLI invocation** with a fixture input, diffing stdout against a known-good snapshot.
21
+ 4. **Headless browser script** (Playwright / Puppeteer) — drives the UI, asserts on DOM/console/network.
22
+ 5. **Replay a captured trace.** Save a real network request / payload / event log to disk; replay it through the code path in isolation.
23
+ 6. **Throwaway harness.** Spin up a minimal subset of the system (one service, mocked deps) that exercises the bug code path with a single function call.
24
+ 7. **Property / fuzz loop.** If the bug is "sometimes wrong output", run 1000 random inputs and look for the failure mode.
25
+ 8. **Bisection harness.** If the bug appeared between two known states (commit, dataset, version), automate "boot at state X, check, repeat" so you can `git bisect run` it.
26
+ 9. **Differential loop.** Run the same input through old-version vs new-version (or two configs) and diff outputs.
27
+ 10. **HITL bash script.** Last resort. If a human must click, drive _them_ with `scripts/hitl-loop.template.sh` so the loop is still structured. Captured output feeds back to you.
28
+
29
+ Build the right feedback loop, and the bug is 90% fixed.
30
+
31
+ ### Tighten the loop
32
+
33
+ Treat the loop as a product. Once you have _a_ loop, **tighten** it:
34
+
35
+ - Can I make it faster? (Cache setup, skip unrelated init, narrow the test scope.)
36
+ - Can I make the signal sharper? (Assert on the specific symptom, not "didn't crash".)
37
+ - Can I make it more deterministic? (Pin time, seed RNG, isolate filesystem, freeze network.)
38
+
39
+ A 30-second flaky loop is barely better than no loop; a 2-second deterministic one is tight — a debugging superpower.
40
+
41
+ ### Non-deterministic bugs
42
+
43
+ The goal is not a clean repro but a **higher reproduction rate**. Loop the trigger 100×, parallelise, add stress, narrow timing windows, inject sleeps. A 50%-flake bug is debuggable; 1% is not — keep raising the rate until it's debuggable.
44
+
45
+ ### When you genuinely cannot build a loop
46
+
47
+ Stop and say so explicitly. List what you tried. Ask the user for: (a) access to whatever environment reproduces it, (b) a captured artifact (HAR file, log dump, core dump, screen recording with timestamps), or (c) permission to add temporary production instrumentation. Do **not** proceed to hypothesise without a loop.
48
+
49
+ ### Completion criterion — a tight loop that goes red
50
+
51
+ Phase 1 is done when the loop is **tight** and **red-capable**: you can name **one command** — a script path, a test invocation, a curl — that you have **already run at least once** (paste the invocation and its output), and that is:
52
+
53
+ - [ ] **Red-capable** — it drives the actual bug code path and asserts the **user's exact symptom**, so it can go red on this bug and green once fixed. Not "runs without erroring" — it must be able to _catch this specific bug_.
54
+ - [ ] **Deterministic** — same verdict every run (flaky bugs: a pinned, high reproduction rate, per above).
55
+ - [ ] **Fast** — seconds, not minutes.
56
+ - [ ] **Agent-runnable** — you can run it unattended; a human in the loop only via `scripts/hitl-loop.template.sh`.
57
+
58
+ If you catch yourself reading code to build a theory before this command exists, **stop — jumping straight to a hypothesis is the exact failure this skill prevents.** No red-capable command, no Phase 2.
59
+
60
+ ## Phase 2 — Reproduce + minimise
61
+
62
+ Run the loop. Watch it go red — the bug appears.
63
+
64
+ Confirm:
65
+
66
+ - [ ] The loop produces the failure mode the **user** described — not a different failure that happens to be nearby. Wrong bug = wrong fix.
67
+ - [ ] The failure is reproducible across multiple runs (or, for non-deterministic bugs, reproducible at a high enough rate to debug against).
68
+ - [ ] You have captured the exact symptom (error message, wrong output, slow timing) so later phases can verify the fix actually addresses it.
69
+
70
+ ### Minimise
71
+
72
+ Once it's red, shrink the repro to the **smallest scenario that still goes red**. Cut inputs, callers, config, data, and steps **one at a time**, re-running the loop after each cut — keep only what is load-bearing for the failure.
73
+
74
+ Why bother: a minimal repro shrinks the hypothesis space in Phase 3 (fewer moving parts left to suspect) and becomes the clean regression test in Phase 5.
75
+
76
+ Done when **every remaining element is load-bearing** — removing any one of them makes the loop go green.
77
+
78
+ Do not proceed until you have reproduced **and** minimised.
79
+
80
+ ## Phase 3 — Hypothesise
81
+
82
+ Generate **3–5 ranked hypotheses** before testing any of them. Single-hypothesis generation anchors on the first plausible idea.
83
+
84
+ Each hypothesis must be **falsifiable**: state the prediction it makes.
85
+
86
+ > Format: "If <X> is the cause, then <changing Y> will make the bug disappear / <changing Z> will make it worse."
87
+
88
+ If you cannot state the prediction, the hypothesis is a vibe — discard or sharpen it.
89
+
90
+ **Show the ranked list to the user before testing.** They often have domain knowledge that re-ranks instantly ("we just deployed a change to #3"), or know hypotheses they've already ruled out. Cheap checkpoint, big time saver. Don't block on it — proceed with your ranking if the user is AFK.
91
+
92
+ ## Phase 4 — Instrument
93
+
94
+ Each probe must map to a specific prediction from Phase 3. **Change one variable at a time.**
95
+
96
+ Tool preference:
97
+
98
+ 1. **Debugger / REPL inspection** if the env supports it. One breakpoint beats ten logs.
99
+ 2. **Targeted logs** at the boundaries that distinguish hypotheses.
100
+ 3. Never "log everything and grep".
101
+
102
+ **Tag every debug log** with a unique prefix, e.g. `[DEBUG-a4f2]`. Cleanup at the end becomes a single grep. Untagged logs survive; tagged logs die.
103
+
104
+ **Perf branch.** For performance regressions, logs are usually wrong. Instead: establish a baseline measurement (timing harness, `performance.now()`, profiler, query plan), then bisect. Measure first, fix second.
105
+
106
+ ## Phase 5 — Fix + regression test
107
+
108
+ Write the regression test **before the fix** — but only if there is a **correct seam** for it.
109
+
110
+ A correct seam is one where the test exercises the **real bug pattern** as it occurs at the call site. If the only available seam is too shallow (single-caller test when the bug needs multiple callers, unit test that can't replicate the chain that triggered the bug), a regression test there gives false confidence.
111
+
112
+ **If no correct seam exists, that itself is the finding.** Note it. The codebase architecture is preventing the bug from being locked down. Flag this in the post-mortem.
113
+
114
+ If a correct seam exists:
115
+
116
+ 1. Turn the minimised repro into a failing test at that seam.
117
+ 2. Watch it fail.
118
+ 3. Apply the fix.
119
+ 4. Watch it pass.
120
+ 5. Re-run the Phase 1 feedback loop against the original (un-minimised) scenario.
121
+
122
+ ## Phase 6 — Cleanup + post-mortem
123
+
124
+ Required before declaring done:
125
+
126
+ - [ ] Original repro no longer reproduces (re-run the Phase 1 loop)
127
+ - [ ] Regression test passes (or absence of seam is documented)
128
+ - [ ] All `[DEBUG-...]` instrumentation removed (`grep` the prefix)
129
+ - [ ] Throwaway prototypes deleted (or moved to a clearly-marked debug location)
130
+ - [ ] The hypothesis that turned out correct is stated in the commit / PR message — so the next debugger learns
131
+
132
+ **Then ask: what would have prevented this bug?** If the answer involves architectural change (no good test seam, tangled callers, hidden coupling), flag it for the user as an architecture improvement opportunity. Make the recommendation **after** the fix is in, not before — you have more information now than when you started.
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+ # HITL (Human-In-The-Loop) debugging script template.
3
+ # Used when a human must interact to reproduce a bug.
4
+ # Drives the human through structured steps and captures output.
5
+
6
+ set -euo pipefail
7
+
8
+ LOG_DIR="${DEBUG_LOG_DIR:-/tmp/debug-hitl}"
9
+ mkdir -p "$LOG_DIR"
10
+
11
+ TIMESTAMP=$(date +%Y%m%d-%H%M%S)
12
+ LOG_FILE="$LOG_DIR/hitl-$TIMESTAMP.log"
13
+
14
+ echo "[HITL] Starting debug session. Output: $LOG_FILE"
15
+ echo "[HITL] Timestamp: $TIMESTAMP"
16
+ echo ""
17
+
18
+ step() {
19
+ local n=$1; shift
20
+ echo "" | tee -a "$LOG_FILE"
21
+ echo "=== Step $n: $* ===" | tee -a "$LOG_FILE"
22
+ echo "[HITL] Press Enter when ready..." | tee -a "$LOG_FILE"
23
+ read -r
24
+ }
25
+
26
+ capture() {
27
+ local label=$1; shift
28
+ echo "[HITL] Capturing: $label" | tee -a "$LOG_FILE"
29
+ echo "--- $label ---" >> "$LOG_FILE"
30
+ "$@" 2>&1 | tee -a "$LOG_FILE"
31
+ echo "--- end $label ---" >> "$LOG_FILE"
32
+ }
33
+
34
+ # --- Steps go here ---
35
+
36
+ step 1 "Reproduce the issue"
37
+ echo "Follow these steps to reproduce:" | tee -a "$LOG_FILE"
38
+ echo " 1. <describe step>" | tee -a "$LOG_FILE"
39
+ echo " 2. <describe step>" | tee -a "$LOG_FILE"
40
+ echo " 3. Observe: <expected vs actual>" | tee -a "$LOG_FILE"
41
+ echo ""
42
+ echo "[HITL] Paste the output or error message, then press Enter:" | tee -a "$LOG_FILE"
43
+ read -r user_output
44
+ echo "User observed: $user_output" >> "$LOG_FILE"
45
+
46
+ step 2 "Collect diagnostics"
47
+ capture "git-status" git status --short
48
+ capture "git-diff" git diff --stat
49
+ capture "recent-logs" tail -50 /var/log/app.log 2>/dev/null || echo "(no log file)"
50
+
51
+ step 3 "Check environment"
52
+ capture "env" env | grep -v -i -E 'secret|password|token|key' || true
53
+
54
+ echo "" | tee -a "$LOG_FILE"
55
+ echo "[HITL] Session complete. Log: $LOG_FILE" | tee -a "$LOG_FILE"
@@ -0,0 +1,78 @@
1
+ ---
2
+ name: exec
3
+ description: "Use when the user invokes /exec with an approved master Spec. Orchestrates per-Spec worktrees, wave-parallel subagent execution, merging, verification, and final review."
4
+ ---
5
+
6
+ # Execute multi-Spec tasks
7
+
8
+ Run approved sub-Specs in isolated worktrees under `.worktrees/` in the target repo. The main workspace is always the merge target; orchestration state lives only in the current session context.
9
+
10
+ ## Prerequisites
11
+
12
+ - The master Spec indexes at least two sub-Specs.
13
+ - Confirm a single target repo; the main workspace is on a named branch and its working tree is clean.
14
+ - `.worktrees/` is covered by the target repo's `.gitignore`; if not, ask the user to add it first.
15
+
16
+ ## Execution
17
+
18
+ 1. Read the master Spec and all sub-Specs; confirm shared contracts, dependency DAG, and verification commands.
19
+ 2. Build the task list by dependency wave.
20
+ 3. Per wave: create a branch from the main workspace HEAD, create a worktree at `<repo>/.worktrees/exec-<task>/<subtask>`, then dispatch the whole wave of nodes. Create the next wave's worktrees only after every prior wave has merged.
21
+
22
+ ## Wave execution: subagent + wait_subagent
23
+
24
+ The main agent orchestrates each wave; node contracts (prompt elements, report format, failure semantics) are in the `dev` skill.
25
+
26
+ 1. **Dispatch**: in a single message, call `subagent` once per sub-Spec in this wave (quality tier), and record "Spec → subagent id". Implementation-node prompt template:
27
+
28
+ ```
29
+ You work in the isolated worktree <worktree absolute path>: always run bash with workdir=<worktree>, and use absolute paths for file tools.
30
+ Follow the main-agent-driven-development skill in prebuilt-worktree mode (skip its internal review step; the review loop is run by /exec).
31
+ Implement only <sub-Spec path> and obey the shared contracts: <contracts>. Run verification: <verification command>.
32
+ After committing, report in the dev skill's implementation-node format. Do not merge or delete the worktree; if blocked, set status=blocked and fill in blocker.
33
+ ```
34
+
35
+ 2. **Collect**: pass every id in this wave to `wait_subagent` in one call; reports arrive with the settlement notice. A Spec with a missing report, `blocked`, or no commit is recorded as `node-failed` and does not affect the other Specs in the wave.
36
+ 3. **Review loop** (each completed Spec advances independently; batches may be dispatched in parallel):
37
+ - Dispatch a brand-new read-only reviewer (quality tier): `Read-only review of the full diff of worktree <worktree> against the baseline (always run bash with workdir=<worktree>). Spec: <path>. Implementation summary: <summary>. Verification already run: <verification>. List issues by severity, each with file and line number; judge with the dev skill's four-state format. Do not edit, commit, or merge.`
38
+ - `CHANGES_REQUIRED` → send the findings to the original implementation subagent with `send_message` (preserving its context), and require it to fix each real issue, explain false positives, rerun verification, commit, and report again; then `wait_subagent` and dispatch a brand-new reviewer.
39
+ - At most 5 rounds; if still failing, record `review-exhausted`.
40
+ 4. Only Specs judged `APPROVED` / `APPROVED_WITH_NOTES` proceed to merge.
41
+
42
+ Key points:
43
+
44
+ - Every review round uses a brand-new subagent; fixes reuse the original implementation subagent — never start another implementation node for the same Spec.
45
+ - Report any node question as blocked for the main agent to handle; do not ask the user within a wave.
46
+ - In PTC mode, a whole wave's dispatch and collection can be done in one `run_code`.
47
+
48
+ ## Merge
49
+
50
+ For each completed node: confirm it is committed and verification passed → check the changed files for out-of-scope edits → merge into the main workspace → verify after merging → delete the worktree and sub-branch.
51
+
52
+ Small, well-defined conflicts are resolved directly by the main agent. For complex conflicts, use a new fix worktree under `.worktrees/` and a development node. Never merge failed or blocked nodes.
53
+
54
+ ## Final review
55
+
56
+ Once all sub-Specs are merged, run the full integration verification, then dispatch a brand-new read-only reviewer subagent (quality tier) to review the whole integrated result:
57
+
58
+ ```
59
+ subagent(
60
+ prompt="Read-only review of the <base>..HEAD diff in <workspace> (always run bash with workdir=<workspace>).
61
+ Master Spec: <path> | all sub-Specs | shared contracts | changed files | implementation summary | verification results.
62
+ List issues by severity, each with file and line number.
63
+ Return APPROVED / APPROVED_WITH_NOTES / CHANGES_REQUIRED / BLOCKED. Do not edit, commit, or merge."
64
+ )
65
+ ```
66
+
67
+ Wait with `wait_subagent`. On `CHANGES_REQUIRED` there is no need to ask the user — the main agent classifies and fixes all real bugs directly, and briefly explains false positives and existing behavior in context; after fixing, verify again and dispatch a brand-new reviewer for re-review. If serious or blocking issues remain after a soft cap of 3 rounds, stop the fix loop and truthfully report the remaining issues to the user.
68
+
69
+ ## Wrap-up
70
+
71
+ Run the full verification, check the Specs, report branches, commits, verification results, and open issues, and ask the user what to do next. Do not create a PR or delete branches without the user's choice.
72
+
73
+ ## KISS
74
+
75
+ - One sub-Spec, one worktree, one development node.
76
+ - The main agent holds repo topology (branches/worktrees/merges/cleanup) and in-wave scheduling; implementation and review go to subagents.
77
+ - State lives only in session context; add no integration branch, scheduler scripts, or state files.
78
+ - Completion notices arrive automatically; wait only when you need results to proceed. Never poll with `sleep`.
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: handoff
3
+ description: Compress the current conversation into a handoff document for a fresh agent to continue from.
4
+ argument-hint: "What will the next session be used for?"
5
+ disable-model-invocation: true
6
+ ---
7
+
8
+ Compress the current conversation into a handoff document, so a brand-new agent can pick up the work without re-reading the parent session.
9
+
10
+ ## Storage and reuse
11
+
12
+ - **Rewrite if one exists**: if a handoff document is already in the session context (written earlier in this session, or injected when the session started), rewrite that file in full; do not create a new one.
13
+ - **Otherwise create one**: when the workspace has `.workspace-docs/`, write to `.workspace-docs/notes/<repo-or-topic>/` — a handoff is essentially a note; otherwise write to the target repo's existing docs directory. Prefix the file name with the date and follow the naming style already used in that directory.
14
+ - When writing under `.workspace-docs/`, new files carry an OKF header (`type: Note` plus `title`/`description`/`tags`/`status`/`repos`), and are not registered in `index.md`; commit/push follows that repo's existing discipline. Where the target repo has no such convention, use its existing doc format.
15
+ - If neither location exists, fall back to the OS temp directory.
16
+
17
+ ## Content requirements
18
+
19
+ - Include a "Suggested skills" section pointing the receiving agent at the skills it should invoke.
20
+ - Do not restate content already on disk (spec, plan, ADR, issue, commit, diff); give paths or URLs only.
21
+ - Record only objective facts and verification evidence; no self-justifying narrative.
22
+ - Redact sensitive content such as API keys, passwords, and personal identity information.
23
+ - When the user invokes it with an argument, that argument is the next session's focus; trim the document accordingly.
@@ -0,0 +1,64 @@
1
+ ---
2
+ name: main-agent-driven-development
3
+ description: "Use only when the user or an orchestration skill explicitly invokes /main-agent-driven-development to complete a well-bounded implementation task."
4
+ ---
5
+
6
+ # Main-agent-driven development
7
+
8
+ The current agent session implements a well-bounded Spec directly. The outer `/exec` orchestrator owns the worktree and merge lifecycle.
9
+
10
+ ## Worktree modes
11
+
12
+ Choose exactly one:
13
+
14
+ - **Prebuilt mode** — when the caller already provided an isolated worktree and owns its lifecycle, use it directly; do not create, merge, or delete worktrees.
15
+ - **Standalone mode** — otherwise, identify the target repo, require the baseline to be on a named branch, record the starting SHA, and create a worktree under the repo's `.worktrees/`.
16
+
17
+ All operations must happen inside the chosen worktree. After isolation, do not edit the original checkout.
18
+
19
+ ## Flow
20
+
21
+ 1. Read the assigned Spec and the relevant repo instructions.
22
+ 2. Confirm task boundaries, dependencies, acceptance criteria, and required verification. Ask questions only when a missing decision truly blocks implementation.
23
+ 3. Initialize the task list from the Spec.
24
+ 4. Project setup + baseline verification. Report first if the baseline fails; continue only when the failure is clearly unrelated and documented.
25
+ 5. Implement directly, limited to the Spec's scope. Follow the `tdd` skill (bundled in this package): write a failing test first, then the minimal implementation.
26
+ 6. After each logical step, run focused verification, self-review the diff, and commit when it is complete. Verification standard: run the command this round and confirm the output; never replace it with "it should pass".
27
+ 7. After implementation, run all required verification.
28
+ 8. When verification fails or review finds a bug, follow the `diagnosing-bugs` skill (bundled in this package): build a feedback loop to find the root cause first, then fix.
29
+ 9. Run the internal review loop (see below). Exception: when acting as an implementation node in an `/exec` wave, **skip this step** — the review loop is run by `/exec`, and the node only implements, verifies, commits, and reports.
30
+ 10. Commit all approved fixes and report to the caller.
31
+
32
+ Keep it KISS. Prefer reusing existing patterns, small and complete changes, and only the targeted refactoring the Spec requires.
33
+
34
+ ## Internal review loop
35
+
36
+ After full verification, dispatch exactly one brand-new read-only reviewer subagent (quality tier):
37
+
38
+ ```
39
+ subagent(
40
+ prompt="Review <worktree-abs-path> from <base_sha> to HEAD.
41
+ Spec: <path>
42
+ Implementation summary: <brief>
43
+ Changed files: <list>
44
+ Verification already run: <commands and results>"
45
+ )
46
+ ```
47
+
48
+ Require file and line numbers, and one status: `APPROVED` / `APPROVED_WITH_NOTES` / `CHANGES_REQUIRED` / `BLOCKED`.
49
+
50
+ Wait for the review with `wait_subagent`. Once results arrive, fix all necessary correctness errors, Spec gaps, security issues, integration risks, and verification gaps directly — no need to ask the user. After verifying and committing the fixes, dispatch a brand-new reviewer with `subagent` again. Repeat until `APPROVED` or only non-blocking suggestions remain.
51
+
52
+ Never self-approve, and never reuse an old reviewer.
53
+
54
+ ## Completion contract
55
+
56
+ Before reporting completion, all of the following must hold:
57
+
58
+ - All assigned acceptance criteria are implemented
59
+ - Required verification ran and passed this round (backed by command output)
60
+ - No uncommitted implementation changes
61
+ - Internal review passed with no required fixes
62
+ - The final commit SHA is available
63
+
64
+ Report blockers truthfully. Do not merge on your own; the caller owns integration and cleanup.
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: tdd
3
+ description: Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
4
+ ---
5
+
6
+ # Test-Driven Development
7
+
8
+ TDD is the red → green loop. This skill is the reference that makes that loop produce tests worth keeping: what a good test is, where tests go, the anti-patterns, and the rules of the loop. Every section applies on every cycle — consult them before and during the loop, not after.
9
+
10
+ ## What a good test is
11
+
12
+ Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't. A good test reads like a specification — "user can checkout with valid cart" tells you exactly what capability exists — and survives refactors because it doesn't care about internal structure.
13
+
14
+ See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
15
+
16
+ ## Seams — where tests go
17
+
18
+ A **seam** is the public boundary you test at: the interface where you observe behavior without reaching inside. Tests live at seams, never against internals.
19
+
20
+ **Test only at pre-agreed seams.** Before writing any test, write down the seams under test and confirm them with the user. No test is written at an unconfirmed seam. You can't test everything — agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.
21
+
22
+ Ask: "What's the public interface, and which seams should we test?"
23
+
24
+ ## Anti-patterns
25
+
26
+ - **Implementation-coupled** — mocks internal collaborators, tests private methods, or verifies through a side channel (querying the database instead of using the interface). The tell: the test breaks when you refactor but behavior hasn't changed.
27
+ - **Tautological** — the assertion recomputes the expected value the way the code does (`expect(add(a, b)).toBe(a + b)`, a snapshot derived by hand the same way, a constant asserted equal to itself), so it passes by construction and can never disagree with the code. Expected values must come from an independent source of truth — a known-good literal, a worked example, the spec.
28
+ - **Horizontal slicing** — writing all tests first, then all implementation. Bulk tests verify _imagined_ behavior: you test the _shape_ of things rather than user-facing behavior, the tests go insensitive to real changes, and you commit to test structure before understanding the implementation. Work in **vertical slices** instead — one test → one implementation → repeat, each test a **tracer bullet** that responds to what the last cycle taught you.
29
+
30
+ ## Rules of the loop
31
+
32
+ - **Red before green.** Write the failing test first, then only enough code to pass it. Don't anticipate future tests or add speculative features.
33
+ - **One slice at a time.** One seam, one test, one minimal implementation per cycle.
34
+ - **Refactoring is not part of the loop.** It belongs to the review stage (see the `code-review` skill), not the red → green implementation cycle.
@@ -0,0 +1,59 @@
1
+ # When to Mock
2
+
3
+ Mock at **system boundaries** only:
4
+
5
+ - External APIs (payment, email, etc.)
6
+ - Databases (sometimes - prefer test DB)
7
+ - Time/randomness
8
+ - File system (sometimes)
9
+
10
+ Don't mock:
11
+
12
+ - Your own classes/modules
13
+ - Internal collaborators
14
+ - Anything you control
15
+
16
+ ## Designing for Mockability
17
+
18
+ At system boundaries, design interfaces that are easy to mock:
19
+
20
+ **1. Use dependency injection**
21
+
22
+ Pass external dependencies in rather than creating them internally:
23
+
24
+ ```typescript
25
+ // Easy to mock
26
+ function processPayment(order, paymentClient) {
27
+ return paymentClient.charge(order.total);
28
+ }
29
+
30
+ // Hard to mock
31
+ function processPayment(order) {
32
+ const client = new StripeClient(process.env.STRIPE_KEY);
33
+ return client.charge(order.total);
34
+ }
35
+ ```
36
+
37
+ **2. Prefer SDK-style interfaces over generic fetchers**
38
+
39
+ Create specific functions for each external operation instead of one generic function with conditional logic:
40
+
41
+ ```typescript
42
+ // GOOD: Each function is independently mockable
43
+ const api = {
44
+ getUser: (id) => fetch(`/users/${id}`),
45
+ getOrders: (userId) => fetch(`/users/${userId}/orders`),
46
+ createOrder: (data) => fetch('/orders', { method: 'POST', body: data }),
47
+ };
48
+
49
+ // BAD: Mocking requires conditional logic inside the mock
50
+ const api = {
51
+ fetch: (endpoint, options) => fetch(endpoint, options),
52
+ };
53
+ ```
54
+
55
+ The SDK approach means:
56
+ - Each mock returns one specific shape
57
+ - No conditional logic in test setup
58
+ - Easier to see which endpoints a test exercises
59
+ - Type safety per endpoint