draht-codex 2026.7.7-1 → 2026.7.11
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/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +18 -0
- package/agents/advisor.md +45 -0
- package/agents/reviewer.md +1 -0
- package/agents/spec-reviewer.md +1 -1
- package/bin/draht-tools.cjs +1808 -988
- package/commands/execute-phase.md +4 -3
- package/commands/fix.md +1 -1
- package/commands/next-milestone.md +1 -0
- package/commands/orchestrate-loop.md +100 -0
- package/commands/orchestrate.md +25 -2
- package/commands/pause-work.md +4 -3
- package/commands/plan-phase.md +1 -0
- package/commands/quick.md +2 -2
- package/hooks/hooks.json +24 -0
- package/package.json +2 -2
- package/scripts/gsd-post-phase.cjs +24 -0
- package/scripts/gsd-post-task.cjs +9 -3
- package/scripts/gsd-quality-gate.cjs +8 -3
- package/scripts/post-edit-check.cjs +59 -0
- package/scripts/session-start.cjs +46 -0
- package/scripts/stop-quality-gate.cjs +68 -0
- package/skills/gsd-workflow/SKILL.md +162 -0
- package/skills/loop-workflow/SKILL.md +52 -0
- package/skills/model-tiering/SKILL.md +45 -0
- package/skills/orchestrate-loop/SKILL.md +14 -0
|
@@ -79,7 +79,7 @@ Before executing, decompose this phase execution into atomic reasoning units:
|
|
|
79
79
|
```
|
|
80
80
|
- `STATUS: DONE` → go to Stage 3.
|
|
81
81
|
- `STATUS: DONE_WITH_CONCERNS` → note, go to Stage 3.
|
|
82
|
-
- `STATUS: BLOCKED` → re-dispatch the implementer with the "Required Fixes" list to address the gaps. Repeat Stage 1+2 until `DONE`. **Never proceed to Stage 3 with a non-compliant diff.**
|
|
82
|
+
- `STATUS: BLOCKED` → re-dispatch the implementer with the "Required Fixes" list to address the gaps. Repeat Stage 1+2 until `DONE`. **Never proceed to Stage 3 with a non-compliant diff.** **Hard cap: 3 implementer re-dispatches per task (across Stage 2 and Stage 3 combined).** On the 3rd failed re-dispatch, record the task as failed via the post-task hook and STOP — report the disagreement to the user. Never negotiate past the cap.
|
|
83
83
|
|
|
84
84
|
### Stage 3 — Reviewer (code quality)
|
|
85
85
|
Once spec compliance is ✅, dispatch a Codex subagent using the `reviewer` agent prompt and a prompt of the form:
|
|
@@ -91,13 +91,14 @@ Before executing, decompose this phase execution into atomic reasoning units:
|
|
|
91
91
|
```
|
|
92
92
|
- `STATUS: DONE` → task is complete, run the post-task hook (below), then move to the next task.
|
|
93
93
|
- `STATUS: DONE_WITH_CONCERNS` → log the `Should fix` items; if any are correctness-critical, re-dispatch implementer; otherwise log and move on.
|
|
94
|
-
- `STATUS: BLOCKED` → `Must fix` issues exist; re-dispatch the implementer with the issue list. Repeat the three stages until `DONE
|
|
94
|
+
- `STATUS: BLOCKED` → `Must fix` issues exist; re-dispatch the implementer with the issue list. Repeat the three stages until `DONE` — subject to the same **hard cap of 3 implementer re-dispatches per task**; at the cap, record the task as failed and STOP.
|
|
95
95
|
|
|
96
96
|
### Post-task hook
|
|
97
|
-
After Stage 3 passes for a task
|
|
97
|
+
After Stage 3 passes for a task — or when a task hits the re-dispatch cap — record the result:
|
|
98
98
|
```bash
|
|
99
99
|
node "${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-$HOME/.draht/codex-marketplace/plugins/draht}}/scripts/gsd-post-task.cjs" <phase> <plan> <task-num> <status> <commit-hash>
|
|
100
100
|
```
|
|
101
|
+
If the hook exits non-zero (3+ recorded failures for the task), that is a **harness-enforced hard stop**: do not dispatch any further implementer runs for this task; report to the user or create a fix plan.
|
|
101
102
|
|
|
102
103
|
5. After all plans complete, run `draht-tools verify-phase $1` yourself (not the subagent)
|
|
103
104
|
6. Run the post-phase hook to generate the phase report:
|
package/commands/fix.md
CHANGED
|
@@ -37,7 +37,7 @@ Stop immediately if you catch yourself:
|
|
|
37
37
|
- Watching each fix reveal new problems elsewhere
|
|
38
38
|
- Implementing before a failing test exists for the bug
|
|
39
39
|
|
|
40
|
-
When you've tried **3 fix attempts and still failing**, STOP. This is an architectural problem, not a hypothesis problem. Report back to the user — do not try a 4th fix.
|
|
40
|
+
When you've tried **3 fix attempts and still failing**, STOP. This is a **hard cap**, not advice — an architectural problem, not a hypothesis problem. Report back to the user — do not try a 4th fix. Before reporting, append one line to `.planning/STATE.md` under `## Lessons`: what was tried, why it failed, dated — so the next session doesn't repeat the same three attempts.
|
|
41
41
|
|
|
42
42
|
## Atomic Reasoning
|
|
43
43
|
|
|
@@ -29,6 +29,7 @@ Before planning the next milestone, decompose progress into atomic reasoning uni
|
|
|
29
29
|
2. If any phase is not complete, STOP and tell the user which phase needs attention
|
|
30
30
|
3. Read all phase reports in `.planning/phase-N-report.md` to extract lessons learned
|
|
31
31
|
4. Read the execution log `.planning/execution-log.jsonl` for failure patterns
|
|
32
|
+
4b. **Write the distilled lessons back**: append each durable lesson from steps 3-4 as a dated bullet to `.planning/STATE.md` under `## Lessons` (create the section before `## Blockers` if missing). Extraction that only informs this planning session evaporates; the `## Lessons` section is what future sessions actually reread.
|
|
32
33
|
5. Refresh the living map if stale: `draht-tools map-graph --quiet` (guarded — skip if the post-phase hook already refreshed), then `draht-tools graph-clusters --surprising`. Compare clusters / bounded contexts / entry points against the milestone start to surface architectural drift before planning the next milestone
|
|
33
34
|
6. Review `.planning/DOMAIN.md` — is it still accurate? Any terms to add/revise (esp. drift flagged in step 5)?
|
|
34
35
|
7. Review `.planning/TEST-STRATEGY.md` — any updates needed?
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Run a verification-gated loop of fresh subagent iterations until a deterministic check passes
|
|
3
|
+
argument-hint: "<goal with a measurable success criterion> [--max-iterations N]"
|
|
4
|
+
allowed-tools: Bash, Read, Write, Edit, Task
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# /orchestrate-loop
|
|
8
|
+
|
|
9
|
+
Run fresh-context worker iterations against a fixed goal until an independent check passes — or a hard stop fires. The loop closes on a deterministic check, never on an agent's claim of completion.
|
|
10
|
+
|
|
11
|
+
Goal: $ARGUMENTS
|
|
12
|
+
|
|
13
|
+
> **Tool note**: Spawn Codex subagents using the matching Draht agent prompts. Workers are `implementer` (or `debugger` for pure-diagnosis goals); the final gate is `spec-reviewer`. One worker per iteration — never parallel workers inside the loop.
|
|
14
|
+
|
|
15
|
+
## When to Loop vs Orchestrate
|
|
16
|
+
|
|
17
|
+
| Situation | Command |
|
|
18
|
+
|---|---|
|
|
19
|
+
| Decomposition is known, sub-tasks dispatch once | `/orchestrate` |
|
|
20
|
+
| Phase plans exist in `.planning/phases/` | `/execute-phase` |
|
|
21
|
+
| Goal needs iteration until a measurable criterion holds | `/orchestrate-loop` |
|
|
22
|
+
|
|
23
|
+
Loops trade tokens for persistence: use one when the work is too large or too uncertain for a single pass AND success is checkable without human judgment.
|
|
24
|
+
|
|
25
|
+
## The Loop Contract — no check, no loop
|
|
26
|
+
|
|
27
|
+
A loop is only as good as its check. Before iterating, establish all four:
|
|
28
|
+
|
|
29
|
+
1. **GOAL** — one measurable end state, stated in one sentence.
|
|
30
|
+
2. **CHECK** — a command that proves the goal, pass/fail by exit code (test suite, typecheck + lint, a script comparing against a known-good oracle). Prefer terse output: failures only.
|
|
31
|
+
3. **STOP CONDITIONS** — check passes (verified independently), max iterations reached (default 10; `--max-iterations N` overrides), stall detected, or `STATUS: BLOCKED`.
|
|
32
|
+
4. **CONSTRAINTS** — what no iteration may touch: existing tests and the check itself are immutable (weakening either to "make it pass" is a hard-stop violation), plus anything out of scope.
|
|
33
|
+
|
|
34
|
+
If no deterministic check can be derived from the goal, STOP and ask the user to define one (or fall back to `/orchestrate`). Never start a loop whose only stop signal is "looks done" — without a check, you become the verification loop and it never closes.
|
|
35
|
+
|
|
36
|
+
Write the contract to `.planning/loop/LOOP.md`:
|
|
37
|
+
|
|
38
|
+
```markdown
|
|
39
|
+
# Loop: <slug>
|
|
40
|
+
Started: <date> | Max iterations: <N>
|
|
41
|
+
|
|
42
|
+
## Goal
|
|
43
|
+
<one sentence>
|
|
44
|
+
|
|
45
|
+
## Check
|
|
46
|
+
`<command>` — passes when <what the output proves>
|
|
47
|
+
|
|
48
|
+
## Constraints
|
|
49
|
+
- <immutables and out-of-scope items>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Create `.planning/loop/PROGRESS.md` alongside it (append-only iteration log).
|
|
53
|
+
|
|
54
|
+
## Iteration Protocol
|
|
55
|
+
|
|
56
|
+
Each iteration dispatches ONE fresh worker whose prompt contains, in full (workers cannot see this conversation):
|
|
57
|
+
|
|
58
|
+
1. The loop contract verbatim
|
|
59
|
+
2. The last 3 entries of `PROGRESS.md` and the last 5 `git log --oneline` lines — the recoverable state
|
|
60
|
+
3. The previous iteration's failure evidence, terse: the failing assertions or error lines, not full output
|
|
61
|
+
4. Standing orders:
|
|
62
|
+
- **Startup ritual** — read the progress log, run the CHECK first, observe the current failure before changing anything
|
|
63
|
+
- **One increment** — the smallest change that moves the check toward passing; do not batch
|
|
64
|
+
- **Commit the increment** even if the check still fails — state must survive context death
|
|
65
|
+
- **Append one `PROGRESS.md` entry** — what changed / check result observed / suggested next step
|
|
66
|
+
- Never edit or delete tests or the check to make it pass; never claim completion without quoting check output
|
|
67
|
+
|
|
68
|
+
## Independent Verification — the gate
|
|
69
|
+
|
|
70
|
+
After EVERY iteration, re-run the CHECK yourself and read exit code and output. Completion is decided by this re-run, never by the worker's report — worker claims are inputs, not verdicts.
|
|
71
|
+
|
|
72
|
+
- **Check passes** → dispatch `spec-reviewer` once over the full loop diff (contract vs everything changed since the loop started). Only a clean spec review ends the loop as DONE; concerns trigger one more targeted iteration.
|
|
73
|
+
- **Check fails** → extract the terse failure evidence and feed it into the next iteration's prompt as guidance.
|
|
74
|
+
|
|
75
|
+
## Stall Detection
|
|
76
|
+
|
|
77
|
+
Stop early when the loop is running but not progressing:
|
|
78
|
+
|
|
79
|
+
- Two consecutive iterations with the identical failure signature, or
|
|
80
|
+
- An iteration that produced no commit
|
|
81
|
+
|
|
82
|
+
On stall, do not dispatch the same input again — change something: decompose the goal, add context the workers were missing, switch worker (`implementer` → `debugger`), consult `advisor` for a course correction, or surface to the user with the evidence so far.
|
|
83
|
+
|
|
84
|
+
## Steps
|
|
85
|
+
|
|
86
|
+
1. Parse `$ARGUMENTS` into GOAL and flags; derive the CHECK; refuse to loop without one
|
|
87
|
+
2. Write `.planning/loop/LOOP.md` and `.planning/loop/PROGRESS.md`
|
|
88
|
+
3. Iterate: dispatch worker → re-run CHECK yourself → branch (pass → gate, fail → next iteration, stall / max / BLOCKED → hard stop)
|
|
89
|
+
4. On success: spec-review the full diff, then report — outcome first, check output quoted, iterations used
|
|
90
|
+
5. On any hard stop: append a handoff entry to `PROGRESS.md` (state observed, failure evidence, recommended next step) and report with observed / derived / assumed labels
|
|
91
|
+
6. Leave `.planning/loop/` in place as the loop's record
|
|
92
|
+
|
|
93
|
+
## Rules
|
|
94
|
+
|
|
95
|
+
- One worker, one increment, at least one commit per iteration
|
|
96
|
+
- Loops are volume work — run workers on the executor tier and keep steering (this context, `advisor`, `spec-reviewer`) on the strongest tier
|
|
97
|
+
- The worker never grades its own work — your re-run of the check plus a fresh-context spec review decide completion
|
|
98
|
+
- Never raise max iterations mid-loop without asking the user
|
|
99
|
+
- Tests and the check are immutable inside the loop; tampering means revert and hard stop
|
|
100
|
+
- Evidence discipline applies to the loop verdict: label results observed / derived / assumed
|
package/commands/orchestrate.md
CHANGED
|
@@ -10,7 +10,7 @@ Decompose a task and dispatch the right mix of specialist subagents.
|
|
|
10
10
|
|
|
11
11
|
Task: $ARGUMENTS
|
|
12
12
|
|
|
13
|
-
> **Tool note**: Spawn Codex subagents using the matching Draht `architect` agent prompt, `implementer`, `spec-reviewer`, `reviewer`, `debugger`, `verifier`, `git-committer`, `security-auditor`. Dispatch multiple tasks in the same assistant turn for parallel execution.
|
|
13
|
+
> **Tool note**: Spawn Codex subagents using the matching Draht `architect` agent prompt, `implementer`, `spec-reviewer`, `reviewer`, `debugger`, `verifier`, `git-committer`, `security-auditor`, `advisor`. Dispatch multiple tasks in the same assistant turn for parallel execution.
|
|
14
14
|
|
|
15
15
|
## Atomic Reasoning
|
|
16
16
|
|
|
@@ -33,9 +33,28 @@ Before delegating, decompose the task into atomic work units:
|
|
|
33
33
|
| Audit for security issues | `security-auditor` |
|
|
34
34
|
| Run lint / typecheck / tests | `verifier` |
|
|
35
35
|
| Create atomic commits | `git-committer` |
|
|
36
|
+
| Strategic steer at a decision point — rare, high-leverage | `advisor` |
|
|
36
37
|
|
|
37
38
|
`spec-reviewer` and `reviewer` are distinct on purpose. Spec-reviewer ONLY checks "did the diff implement what the spec asked, no more no less". Reviewer evaluates quality (naming, structure, type safety). For any task with a written spec, run spec-reviewer **before** reviewer — accepting "close enough" on spec is a known failure mode.
|
|
38
39
|
|
|
40
|
+
## Effort Scaling
|
|
41
|
+
|
|
42
|
+
Match orchestration weight to the task — over-orchestration burns tokens without adding verification value:
|
|
43
|
+
|
|
44
|
+
| Task shape | Dispatch |
|
|
45
|
+
|---|---|
|
|
46
|
+
| Single question or trivial fix | One agent, or handle it directly — no orchestration |
|
|
47
|
+
| One change set to evaluate | 2–4 parallel evaluators (reviewer, security-auditor, verifier) |
|
|
48
|
+
| Multi-part feature with known decomposition | Fan-out / fan-in |
|
|
49
|
+
| Goal needing iteration until a measurable criterion holds | `/orchestrate-loop` |
|
|
50
|
+
|
|
51
|
+
## Model Tiering
|
|
52
|
+
|
|
53
|
+
Bill volume tokens at the cheaper rate — see the `model-tiering` skill:
|
|
54
|
+
|
|
55
|
+
- **Orchestrator pattern** — run this command on the strongest tier (e.g. Claude Fable 5) and let workers execute on the executor tier (e.g. Claude Sonnet 5): planning quality where it matters, volume tokens at worker rates.
|
|
56
|
+
- **Advisor pattern** — when the session runs on the executor tier, dispatch `advisor` sparingly: once after orientation before committing to an approach, again when stuck or before declaring a hard task done. ~1–3 consults per task; treat its guidance with serious weight.
|
|
57
|
+
|
|
39
58
|
## Orchestration Modes
|
|
40
59
|
|
|
41
60
|
### Parallel
|
|
@@ -58,6 +77,9 @@ implementer → spec-reviewer → reviewer
|
|
|
58
77
|
|
|
59
78
|
Never run quality review on a spec-non-compliant diff. This is the standard pattern inside `/execute-phase`'s per-task loop.
|
|
60
79
|
|
|
80
|
+
### Loop (iterate until a check passes)
|
|
81
|
+
When the work cannot land in one dispatch but success is provable by a deterministic check, do not improvise retries here — hand off to `/orchestrate-loop`. It runs fresh worker iterations gated by an independent re-run of the check, with max-iteration and stall bounds. See the `loop-workflow` skill for the discipline.
|
|
82
|
+
|
|
61
83
|
## Reading Subagent Status
|
|
62
84
|
|
|
63
85
|
Every draht agent ends its response with one of four status lines. Branch on it:
|
|
@@ -77,7 +99,8 @@ Every draht agent ends its response with one of four status lines. Branch on it:
|
|
|
77
99
|
|
|
78
100
|
## Rules
|
|
79
101
|
- Prefer parallel dispatch when possible — it's faster and each subagent has its own context
|
|
80
|
-
-
|
|
102
|
+
- Every dispatch is a complete brief: objective, expected output format, tool guidance, and task boundaries — subagents cannot see the main conversation
|
|
81
103
|
- Do not nest delegations deeply — one level is usually enough
|
|
82
104
|
- Never retry the same agent on the same input after `BLOCKED` — change something
|
|
83
105
|
- For any spec-driven work, spec-reviewer runs before quality reviewer
|
|
106
|
+
- The agent that produced work never evaluates it — completion verdicts come from a fresh-context evaluator plus your own re-run of the decisive check
|
package/commands/pause-work.md
CHANGED
|
@@ -28,9 +28,10 @@ Before pausing, decompose session state into atomic reasoning units:
|
|
|
28
28
|
- `## Decisions Made This Session` — any design decisions or context
|
|
29
29
|
- `## Next Steps` — exact commands to run when resuming
|
|
30
30
|
- `## Blockers` — anything waiting on external input or clarification
|
|
31
|
-
4.
|
|
32
|
-
5.
|
|
33
|
-
6.
|
|
31
|
+
4. **Distill lessons before the context is lost**: for anything this session tried that failed, or an approach that worked against expectations, append one dated bullet to `.planning/STATE.md` under `## Lessons` (create the section before `## Blockers` if missing). Lessons name what to do differently — "runner hits TLS issue in PowerShell, use bash", not "had problems with tests".
|
|
32
|
+
5. Update `.planning/STATE.md` last activity timestamp via `draht-tools update-state`
|
|
33
|
+
6. Commit: `draht-tools commit-docs "pause work — handoff"`
|
|
34
|
+
7. Tell the user: "Resume with `/resume-work` in a fresh session."
|
|
34
35
|
|
|
35
36
|
## Rules
|
|
36
37
|
- Be specific — "fix bug in auth" is useless; "null check in src/auth/session.ts:42, test reproducing in test/auth-null.test.ts" is useful
|
package/commands/plan-phase.md
CHANGED
|
@@ -47,6 +47,7 @@ Before creating plans, decompose this phase goal into atomic reasoning units:
|
|
|
47
47
|
|
|
48
48
|
## Steps
|
|
49
49
|
1. Run `draht-tools load-phase-context $1` to gather all context
|
|
50
|
+
1b. Read `.planning/STATE.md` `## Lessons` — every plan this command produces must respect the recorded lessons; a plan that repeats a documented failure is invalid. Feed relevant lessons into each architect prompt.
|
|
50
51
|
2. Optional: `draht-tools research-phase $1` for domain research
|
|
51
52
|
3. Goal-backward planning:
|
|
52
53
|
a. State the goal (outcome, not activity)
|
package/commands/quick.md
CHANGED
|
@@ -71,7 +71,7 @@ Before executing, decompose this task into atomic reasoning units:
|
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
- `DONE` → go to Stage 3.
|
|
74
|
-
- `BLOCKED` → re-dispatch implementer with the "Required Fixes" list. Repeat Stage 1+2 until `DONE`.
|
|
74
|
+
- `BLOCKED` → re-dispatch implementer with the "Required Fixes" list. Repeat Stage 1+2 until `DONE`. **Hard cap: 3 implementer re-dispatches total (across Stage 2 and Stage 3).** At the cap, STOP and report the disagreement to the user.
|
|
75
75
|
|
|
76
76
|
5. **Stage 3 — Reviewer (optional code-quality pass).** For non-trivial quick tasks (touches more than one file or modifies domain code), _optionally_ run `draht-tools graph-impact <changed files>` and paste its reverse-dependents + boundary warnings into the Codex subagent prompt. Then dispatch a Codex subagent using the `reviewer` agent prompt:
|
|
77
77
|
```
|
|
@@ -81,7 +81,7 @@ Before executing, decompose this task into atomic reasoning units:
|
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
- `DONE` → quick task complete.
|
|
84
|
-
- `BLOCKED` → re-dispatch implementer with the Must-fix list.
|
|
84
|
+
- `BLOCKED` → re-dispatch implementer with the Must-fix list — subject to the same **hard cap of 3 re-dispatches**; at the cap, STOP and report.
|
|
85
85
|
|
|
86
86
|
6. Write summary: `draht-tools write-quick-summary NNN`
|
|
87
87
|
7. Update state: `draht-tools update-state`
|
package/hooks/hooks.json
CHANGED
|
@@ -21,6 +21,30 @@
|
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
}
|
|
24
|
+
],
|
|
25
|
+
"PostToolUse": [
|
|
26
|
+
{
|
|
27
|
+
"matcher": "Edit|Write|MultiEdit",
|
|
28
|
+
"hooks": [
|
|
29
|
+
{
|
|
30
|
+
"type": "command",
|
|
31
|
+
"command": "node \"${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT}}/scripts/post-edit-check.cjs\"",
|
|
32
|
+
"timeout": 30
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"Stop": [
|
|
38
|
+
{
|
|
39
|
+
"matcher": "",
|
|
40
|
+
"hooks": [
|
|
41
|
+
{
|
|
42
|
+
"type": "command",
|
|
43
|
+
"command": "node \"${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT}}/scripts/stop-quality-gate.cjs\"",
|
|
44
|
+
"timeout": 180
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
24
48
|
]
|
|
25
49
|
}
|
|
26
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "draht-codex",
|
|
3
|
-
"version": "2026.7.
|
|
3
|
+
"version": "2026.7.11",
|
|
4
4
|
"description": "Draht GSD, multi-agent, TDD and DDD workflows as a Codex plugin. Install with `npx draht-codex install`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"prepublishOnly": "node ../../scripts/sync-draht-tools.mjs"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@draht/tools": "2026.7.
|
|
28
|
+
"@draht/tools": "2026.7.11"
|
|
29
29
|
},
|
|
30
30
|
"keywords": [
|
|
31
31
|
"codex",
|
|
@@ -132,6 +132,30 @@ try {
|
|
|
132
132
|
}
|
|
133
133
|
} catch { /* map refresh is best-effort */ }
|
|
134
134
|
|
|
135
|
+
// 4.6 Seed lessons: persist phase failure patterns into STATE.md ## Lessons so
|
|
136
|
+
// they compound across sessions instead of living only in transient reports.
|
|
137
|
+
try {
|
|
138
|
+
const statePath = path.join(PLANNING, "STATE.md");
|
|
139
|
+
if (fs.existsSync(statePath) && (failed > 0 || tddViolations > 0 || warnings > 0)) {
|
|
140
|
+
let state = fs.readFileSync(statePath, "utf-8");
|
|
141
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
142
|
+
const lessonBits = [];
|
|
143
|
+
if (failed > 0) lessonBits.push(`${failed} task(s) failed`);
|
|
144
|
+
if (tddViolations > 0) lessonBits.push(`${tddViolations} TDD violation(s) (green: without red:)`);
|
|
145
|
+
if (warnings > 0) lessonBits.push(`${warnings} task(s) with warnings`);
|
|
146
|
+
const lesson = `- ${date}: Phase ${phaseNum}: ${lessonBits.join(", ")} — see phase-${phaseNum}-report.md; distill the root cause here before the next phase.`;
|
|
147
|
+
if (!state.includes(lesson)) {
|
|
148
|
+
if (/## Lessons\n/.test(state)) {
|
|
149
|
+
state = state.replace(/## Lessons\n(\(none yet[^\n]*\)\n)?/, (m) => `## Lessons\n${lesson}\n`);
|
|
150
|
+
} else {
|
|
151
|
+
state = state.replace(/## Blockers/, `## Lessons\n${lesson}\n\n## Blockers`);
|
|
152
|
+
}
|
|
153
|
+
fs.writeFileSync(statePath, state);
|
|
154
|
+
console.log(`STATE.md: lesson recorded for phase ${phaseNum}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
} catch { /* lessons are best-effort */ }
|
|
158
|
+
|
|
135
159
|
// 5. Summary
|
|
136
160
|
console.log(`\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
|
|
137
161
|
console.log(` Draht ► PHASE ${phaseNum} ${failed === 0 ? "COMPLETE ✅" : "NEEDS FIXES ❌"}`);
|
|
@@ -34,7 +34,9 @@ function detectToolchain(cwd) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function readHookConfig(cwd) {
|
|
37
|
-
|
|
37
|
+
// Strict by default: failing tests/types/lint fail the gate (exit 1).
|
|
38
|
+
// Opt out per-project with hooks.qualityGateStrict: false in .planning/config.json.
|
|
39
|
+
const defaults = { coverageThreshold: 80, tddMode: "advisory", qualityGateStrict: true };
|
|
38
40
|
const configPath = path.join(cwd, ".planning", "config.json");
|
|
39
41
|
if (!fs.existsSync(configPath)) return defaults;
|
|
40
42
|
try {
|
|
@@ -145,9 +147,13 @@ if (status === "pass") {
|
|
|
145
147
|
.map((l) => JSON.parse(l))
|
|
146
148
|
.filter((e) => e.phase === parseInt(phaseNum, 10) && e.plan === parseInt(planNum, 10) && e.task === parseInt(taskNum, 10) && e.status === "fail");
|
|
147
149
|
|
|
150
|
+
// Hard stop: 3 recorded failures for the same task ends the retry loop.
|
|
151
|
+
// The orchestrator must escalate to the user or a fix plan — never a 4th blind attempt.
|
|
148
152
|
if (taskFailures.length >= 3) {
|
|
149
|
-
console.
|
|
150
|
-
console.
|
|
153
|
+
console.error(`\n❌ HARD STOP: task ${phaseNum}-${planNum}-${taskNum} has failed ${taskFailures.length} times.`);
|
|
154
|
+
console.error(` Do NOT re-dispatch the implementer. Escalate: report to the user or create a fix plan:`);
|
|
155
|
+
console.error(` draht create-fix-plan ${phaseNum} ${planNum} "Task ${taskNum} failed repeatedly"`);
|
|
156
|
+
process.exit(1);
|
|
151
157
|
}
|
|
152
158
|
} else {
|
|
153
159
|
console.log(`⏭️ Task ${phaseNum}-${planNum}-${taskNum}: skipped`);
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* Runs after task completion to enforce quality standards.
|
|
7
7
|
* Called by the build agent after each verify step.
|
|
8
8
|
*
|
|
9
|
-
* Usage: node gsd-quality-gate.js [--strict]
|
|
9
|
+
* Usage: node gsd-quality-gate.js [--strict] [--no-tests]
|
|
10
|
+
* --no-tests skips the test-suite run (used by the Stop hook, where the
|
|
11
|
+
* post-task hook and /verify-work own test execution).
|
|
10
12
|
* Exit 0 = quality OK, Exit 1 = quality issues
|
|
11
13
|
*/
|
|
12
14
|
|
|
@@ -29,7 +31,9 @@ function detectToolchain(cwd) {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
function readHookConfig(cwd) {
|
|
32
|
-
|
|
34
|
+
// Strict by default: failing tests/types/lint fail the gate (exit 1).
|
|
35
|
+
// Opt out per-project with hooks.qualityGateStrict: false in .planning/config.json.
|
|
36
|
+
const defaults = { coverageThreshold: 80, tddMode: "advisory", qualityGateStrict: true };
|
|
33
37
|
const configPath = path.join(cwd, ".planning", "config.json");
|
|
34
38
|
if (!fs.existsSync(configPath)) return defaults;
|
|
35
39
|
try {
|
|
@@ -67,6 +71,7 @@ const cwd = process.cwd();
|
|
|
67
71
|
const toolchain = detectToolchain(cwd);
|
|
68
72
|
const hookConfig = readHookConfig(cwd);
|
|
69
73
|
const strict = process.argv.includes("--strict") || hookConfig.qualityGateStrict;
|
|
74
|
+
const skipTests = process.argv.includes("--no-tests");
|
|
70
75
|
const issues = [];
|
|
71
76
|
|
|
72
77
|
// 1. TypeScript check
|
|
@@ -92,7 +97,7 @@ if (fs.existsSync(path.join(cwd, "biome.json"))) {
|
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
// 3. Run tests
|
|
95
|
-
try {
|
|
100
|
+
if (!skipTests) try {
|
|
96
101
|
const testOutput = execSync(`${toolchain.testCmd} 2>&1`, { timeout: 120000, encoding: "utf-8", cwd });
|
|
97
102
|
const failMatch = testOutput.match(/(\d+) fail/);
|
|
98
103
|
if (failMatch && parseInt(failMatch[1], 10) > 0) {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Post-Edit Check Hook (PostToolUse: Edit|Write)
|
|
6
|
+
* Lints the edited file immediately, so formatting/lint rules hold on every
|
|
7
|
+
* edit instead of waiting for a commit or a prose-invoked gate.
|
|
8
|
+
*
|
|
9
|
+
* Reads the hook payload from stdin, runs a file-scoped `biome check` when the
|
|
10
|
+
* project uses Biome, and exits 2 with the findings on stderr so the agent
|
|
11
|
+
* sees and fixes them. Exits 0 (silent) in projects without Biome, for
|
|
12
|
+
* non-code files, and on any unexpected error — this hook must never wedge a
|
|
13
|
+
* session.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const { execSync } = require("node:child_process");
|
|
17
|
+
const fs = require("node:fs");
|
|
18
|
+
const path = require("node:path");
|
|
19
|
+
|
|
20
|
+
const CODE_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
|
|
21
|
+
|
|
22
|
+
function readStdin() {
|
|
23
|
+
try {
|
|
24
|
+
return fs.readFileSync(0, "utf-8");
|
|
25
|
+
} catch {
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const payload = JSON.parse(readStdin() || "{}");
|
|
32
|
+
const filePath = payload?.tool_input?.file_path;
|
|
33
|
+
if (!filePath || !fs.existsSync(filePath)) process.exit(0);
|
|
34
|
+
if (!CODE_EXTENSIONS.has(path.extname(filePath))) process.exit(0);
|
|
35
|
+
|
|
36
|
+
const cwd = payload?.cwd || process.cwd();
|
|
37
|
+
if (!fs.existsSync(path.join(cwd, "biome.json"))) process.exit(0);
|
|
38
|
+
|
|
39
|
+
const runner = fs.existsSync(path.join(cwd, "bun.lock")) || fs.existsSync(path.join(cwd, "bun.lockb"))
|
|
40
|
+
? "bunx"
|
|
41
|
+
: "npx";
|
|
42
|
+
try {
|
|
43
|
+
execSync(`${runner} biome check --error-on-warnings ${JSON.stringify(filePath)} 2>&1`, {
|
|
44
|
+
timeout: 15000,
|
|
45
|
+
encoding: "utf-8",
|
|
46
|
+
cwd,
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
const output = (error.stdout || error.stderr || "").toString();
|
|
50
|
+
if (error.signal || !output.trim()) process.exit(0); // timeout or tool failure — don't block
|
|
51
|
+
if (output.includes("No files were processed")) process.exit(0); // file ignored by biome config
|
|
52
|
+
console.error(`Lint issues in ${filePath} (fix before proceeding):`);
|
|
53
|
+
console.error(output.slice(0, 1500));
|
|
54
|
+
process.exit(2);
|
|
55
|
+
}
|
|
56
|
+
process.exit(0);
|
|
57
|
+
} catch {
|
|
58
|
+
process.exit(0);
|
|
59
|
+
}
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* Session Start Hook
|
|
6
6
|
* Surfaces draht planning state when a Codex session starts in a project.
|
|
7
7
|
* - Reports current phase and task from .planning/STATE.md
|
|
8
|
+
* - Rereads the standing spec: vision + constraints from .planning/PROJECT.md
|
|
9
|
+
* (goal-drift guard — the spec reaches every session, not just milestones)
|
|
10
|
+
* - Surfaces the most recent lessons from STATE.md ## Lessons
|
|
8
11
|
* - Flags CONTINUE-HERE.md if the previous session was paused
|
|
9
12
|
* - Silent in projects without .planning/
|
|
10
13
|
*/
|
|
@@ -36,6 +39,49 @@ if (fs.existsSync(statePath)) {
|
|
|
36
39
|
} catch {}
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
// PROJECT.md — standing spec digest (vision + constraints), reread every session
|
|
43
|
+
const projectPath = path.join(PLANNING, "PROJECT.md");
|
|
44
|
+
if (fs.existsSync(projectPath)) {
|
|
45
|
+
try {
|
|
46
|
+
const project = fs.readFileSync(projectPath, "utf-8");
|
|
47
|
+
const visionMatch = project.match(/## Vision\s*\n([^\n#]+)/);
|
|
48
|
+
if (visionMatch) {
|
|
49
|
+
lines.push("");
|
|
50
|
+
lines.push(`Vision: ${visionMatch[1].trim()}`);
|
|
51
|
+
}
|
|
52
|
+
const constraintsMatch = project.match(/## Constraints\s*\n([\s\S]*?)(?:\n## |$)/);
|
|
53
|
+
if (constraintsMatch) {
|
|
54
|
+
const constraints = constraintsMatch[1]
|
|
55
|
+
.split("\n")
|
|
56
|
+
.filter((l) => /^\s*[-*]\s/.test(l))
|
|
57
|
+
.slice(0, 6);
|
|
58
|
+
if (constraints.length > 0) {
|
|
59
|
+
lines.push("Constraints:");
|
|
60
|
+
for (const c of constraints) lines.push(c.trim());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} catch {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// STATE.md ## Lessons — most recent lessons, so past failures aren't repeated
|
|
67
|
+
if (fs.existsSync(statePath)) {
|
|
68
|
+
try {
|
|
69
|
+
const state = fs.readFileSync(statePath, "utf-8");
|
|
70
|
+
const lessonsMatch = state.match(/## Lessons\s*\n([\s\S]*?)(?:\n## |$)/);
|
|
71
|
+
if (lessonsMatch) {
|
|
72
|
+
const lessons = lessonsMatch[1]
|
|
73
|
+
.split("\n")
|
|
74
|
+
.filter((l) => /^\s*[-*]\s/.test(l))
|
|
75
|
+
.slice(-3);
|
|
76
|
+
if (lessons.length > 0) {
|
|
77
|
+
lines.push("");
|
|
78
|
+
lines.push("Recent lessons:");
|
|
79
|
+
for (const l of lessons) lines.push(l.trim());
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch {}
|
|
83
|
+
}
|
|
84
|
+
|
|
39
85
|
// CONTINUE-HERE.md — resume marker
|
|
40
86
|
const continuePath = path.join(PLANNING, "CONTINUE-HERE.md");
|
|
41
87
|
if (fs.existsSync(continuePath)) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Stop-Time Quality Gate Hook (Stop)
|
|
6
|
+
* Runs the draht quality gate when the agent tries to end its turn with
|
|
7
|
+
* uncommitted source changes in a .planning project — so the gate fires even
|
|
8
|
+
* when the command prose that should have invoked it was skipped.
|
|
9
|
+
*
|
|
10
|
+
* Loop safety: exits 0 when stop_hook_active is set (we already blocked one
|
|
11
|
+
* stop this turn), so a persistently red gate blocks at most one stop.
|
|
12
|
+
* Opt out per-project with hooks.stopGate: false in .planning/config.json.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const { execSync, spawnSync } = require("node:child_process");
|
|
16
|
+
const fs = require("node:fs");
|
|
17
|
+
const path = require("node:path");
|
|
18
|
+
|
|
19
|
+
function readStdin() {
|
|
20
|
+
try {
|
|
21
|
+
return fs.readFileSync(0, "utf-8");
|
|
22
|
+
} catch {
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const payload = JSON.parse(readStdin() || "{}");
|
|
29
|
+
if (payload?.stop_hook_active) process.exit(0);
|
|
30
|
+
|
|
31
|
+
const cwd = payload?.cwd || process.cwd();
|
|
32
|
+
const planning = path.join(cwd, ".planning");
|
|
33
|
+
if (!fs.existsSync(planning)) process.exit(0);
|
|
34
|
+
|
|
35
|
+
// Config opt-out
|
|
36
|
+
try {
|
|
37
|
+
const config = JSON.parse(fs.readFileSync(path.join(planning, "config.json"), "utf-8"));
|
|
38
|
+
if (config?.hooks?.stopGate === false) process.exit(0);
|
|
39
|
+
} catch { /* no config — gate stays on */ }
|
|
40
|
+
|
|
41
|
+
// Only gate when uncommitted source changes exist — a conversational turn
|
|
42
|
+
// with a clean tree has nothing to verify.
|
|
43
|
+
let dirty = "";
|
|
44
|
+
try {
|
|
45
|
+
dirty = execSync("git status --porcelain 2>/dev/null", { encoding: "utf-8", cwd, timeout: 10000 });
|
|
46
|
+
} catch {
|
|
47
|
+
process.exit(0); // not a git repo
|
|
48
|
+
}
|
|
49
|
+
const dirtySource = dirty
|
|
50
|
+
.split("\n")
|
|
51
|
+
.filter(Boolean)
|
|
52
|
+
.map((l) => l.slice(3))
|
|
53
|
+
.filter((f) => /\.(ts|tsx|js|jsx|mjs|cjs)$/.test(f));
|
|
54
|
+
if (dirtySource.length === 0) process.exit(0);
|
|
55
|
+
|
|
56
|
+
// --no-tests: types + lint only. Test runs belong to the post-task hook and
|
|
57
|
+
// /verify-work; a full suite on every turn-end would be unusable.
|
|
58
|
+
const gate = path.join(__dirname, "gsd-quality-gate.cjs");
|
|
59
|
+
const result = spawnSync("node", [gate, "--no-tests"], { encoding: "utf-8", cwd, timeout: 170000 });
|
|
60
|
+
if (result.status !== 0 && !result.error) {
|
|
61
|
+
console.error("Quality gate failed on uncommitted source changes — fix before ending the turn:");
|
|
62
|
+
console.error((result.stdout || "").slice(0, 1500));
|
|
63
|
+
process.exit(2);
|
|
64
|
+
}
|
|
65
|
+
process.exit(0);
|
|
66
|
+
} catch {
|
|
67
|
+
process.exit(0);
|
|
68
|
+
}
|