draht-codex 2026.7.13 → 2026.9.5-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.
Files changed (109) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +74 -0
  3. package/README.md +56 -6
  4. package/agents/debugger.md +12 -1
  5. package/agents/git-committer.md +1 -0
  6. package/agents/implementer.md +11 -2
  7. package/agents/investigator.md +75 -0
  8. package/agents/reviewer.md +7 -0
  9. package/agents/speaker.md +44 -0
  10. package/agents/verifier.md +4 -3
  11. package/bin/draht-tools.cjs +472 -41
  12. package/bin/judge +613 -0
  13. package/cli.mjs +769 -46
  14. package/commands/atomic-commit.md +1 -12
  15. package/commands/create-verification-skill.md +105 -0
  16. package/commands/discuss-phase.md +3 -14
  17. package/commands/execute-phase.md +7 -14
  18. package/commands/fix.md +38 -17
  19. package/commands/grill.md +66 -0
  20. package/commands/init-project.md +5 -15
  21. package/commands/map-codebase.md +1 -13
  22. package/commands/new-project.md +5 -15
  23. package/commands/next-milestone.md +2 -13
  24. package/commands/orchestrate.md +1 -1
  25. package/commands/pause-work.md +1 -8
  26. package/commands/plan-phase.md +2 -11
  27. package/commands/progress.md +0 -8
  28. package/commands/quick.md +3 -11
  29. package/commands/resolve-conflicts.md +72 -0
  30. package/commands/resume-work.md +0 -8
  31. package/commands/review.md +4 -13
  32. package/commands/speak.md +45 -0
  33. package/commands/triage.md +161 -0
  34. package/commands/verify-work.md +5 -13
  35. package/commands/why.md +137 -0
  36. package/graph-archive.mjs +125 -0
  37. package/graph-manifest.mjs +97 -0
  38. package/hooks/hooks.json +39 -0
  39. package/package.json +5 -3
  40. package/scripts/gsd-quality-gate.cjs +3 -3
  41. package/scripts/judge-hook.cjs +42 -0
  42. package/scripts/judge-hook.py +391 -0
  43. package/scripts/judgegates.py +673 -0
  44. package/scripts/judgelib.py +382 -0
  45. package/scripts/speak.cjs +202 -0
  46. package/skills/atomic-commit/SKILL.md +1 -1
  47. package/skills/atomic-commit/command.md +62 -0
  48. package/skills/blast-radius/SKILL.md +55 -0
  49. package/skills/brainstorming/SKILL.md +11 -4
  50. package/skills/cinematic-continuation/SKILL.md +111 -0
  51. package/skills/cinematic-continuation/references/continuity-schema.md +75 -0
  52. package/skills/cinematic-continuation/references/seedance-adapter.md +44 -0
  53. package/skills/cinematic-continuation/references/style-bible.md +223 -0
  54. package/skills/cinematic-continuation/scripts/compile-continuation.mjs +173 -0
  55. package/skills/cinematic-continuation/templates/continuation-spec.json +50 -0
  56. package/skills/create-verification-skill/SKILL.md +14 -0
  57. package/skills/create-verification-skill/command.md +105 -0
  58. package/skills/debugging-workflow/SKILL.md +38 -10
  59. package/skills/discuss-phase/SKILL.md +1 -1
  60. package/skills/discuss-phase/command.md +44 -0
  61. package/skills/draht/SKILL.md +118 -0
  62. package/skills/epistemics/SKILL.md +99 -0
  63. package/skills/execute-phase/SKILL.md +1 -1
  64. package/skills/execute-phase/command.md +170 -0
  65. package/skills/fix/SKILL.md +1 -1
  66. package/skills/fix/command.md +154 -0
  67. package/skills/grill/SKILL.md +14 -0
  68. package/skills/grill/command.md +66 -0
  69. package/skills/gsd-workflow/SKILL.md +2 -0
  70. package/skills/init-project/SKILL.md +1 -1
  71. package/skills/init-project/command.md +57 -0
  72. package/skills/judge/SKILL.md +57 -0
  73. package/skills/map-codebase/SKILL.md +1 -1
  74. package/skills/map-codebase/command.md +61 -0
  75. package/skills/new-project/SKILL.md +1 -1
  76. package/skills/new-project/command.md +64 -0
  77. package/skills/next-milestone/SKILL.md +1 -1
  78. package/skills/next-milestone/command.md +42 -0
  79. package/skills/orchestrate/SKILL.md +1 -1
  80. package/skills/orchestrate/command.md +106 -0
  81. package/skills/orchestrate-loop/SKILL.md +1 -1
  82. package/skills/orchestrate-loop/command.md +100 -0
  83. package/skills/pause-work/SKILL.md +1 -1
  84. package/skills/pause-work/command.md +32 -0
  85. package/skills/plan-phase/SKILL.md +1 -1
  86. package/skills/plan-phase/command.md +139 -0
  87. package/skills/progress/SKILL.md +1 -1
  88. package/skills/progress/command.md +22 -0
  89. package/skills/quick/SKILL.md +1 -1
  90. package/skills/quick/command.md +91 -0
  91. package/skills/resolve-conflicts/SKILL.md +14 -0
  92. package/skills/resolve-conflicts/command.md +72 -0
  93. package/skills/resume-work/SKILL.md +1 -1
  94. package/skills/resume-work/command.md +27 -0
  95. package/skills/review/SKILL.md +1 -1
  96. package/skills/review/command.md +81 -0
  97. package/skills/saga-spawner/SKILL.md +131 -0
  98. package/skills/speak/SKILL.md +14 -0
  99. package/skills/speak/command.md +45 -0
  100. package/skills/tdd-workflow/SKILL.md +2 -0
  101. package/skills/triage/SKILL.md +14 -0
  102. package/skills/triage/command.md +161 -0
  103. package/skills/typescript-discipline/SKILL.md +50 -0
  104. package/skills/typescript-discipline/references/patterns.md +294 -0
  105. package/skills/unslop/SKILL.md +101 -0
  106. package/skills/verify-work/SKILL.md +1 -1
  107. package/skills/verify-work/command.md +116 -0
  108. package/skills/why/SKILL.md +14 -0
  109. package/skills/why/command.md +137 -0
@@ -0,0 +1,391 @@
1
+ #!/usr/bin/env python3
2
+ """Hook entrypoint for the judge queue.
3
+
4
+ python3 judge-hook.py <event> (payload on stdin)
5
+
6
+ PostToolUse → remember every test file this session edits. Cheap, silent,
7
+ and the only way to know a gate was written.
8
+ PreToolUse → the red gate: the session has written tests and is now
9
+ reaching for the implementation. Replay the test against
10
+ the code as it stands, card the result, and hold the edit
11
+ until the human swipes. A test that passes without the
12
+ implementation is denied without asking anyone.
13
+ Stop → deliver pending human feedback (blocks the stop so the
14
+ session acts on it); run the mutation pass on gates whose
15
+ implementation has since landed; card any test written
16
+ without a following implementation edit; otherwise file a
17
+ review card for the turn.
18
+ UserPromptSubmit → deliver pending human feedback as additional context.
19
+ PermissionRequest → while the judge TUI is running, park the request as a card
20
+ and wait for the swipe; otherwise fall through to the
21
+ normal permission dialog.
22
+ """
23
+
24
+ import json
25
+ import os
26
+ import sys
27
+ import time
28
+
29
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
30
+ import judgegates as G # noqa: E402
31
+ import judgelib as J # noqa: E402
32
+
33
+ POLL = 0.3
34
+
35
+
36
+ def out(obj):
37
+ sys.stdout.write(json.dumps(obj))
38
+ sys.stdout.flush()
39
+
40
+
41
+ def describe_tool(name, inp):
42
+ """Human-readable one-liner + detail for a permission card."""
43
+ inp = inp or {}
44
+ if name == "Bash":
45
+ return inp.get("description") or "run shell command", inp.get("command", "")
46
+ if name in J.EDIT_TOOLS:
47
+ detail = ""
48
+ if name == "Write":
49
+ detail = (inp.get("content") or "")[:1500]
50
+ elif name == "Edit":
51
+ detail = f"--- old\n{inp.get('old_string', '')[:700]}\n+++ new\n{inp.get('new_string', '')[:700]}"
52
+ return f"{name} {J.short_dir(inp.get('file_path', ''))}", detail
53
+ if name in ("Read", "Glob", "Grep"):
54
+ return f"{name} {inp.get('file_path') or inp.get('pattern') or ''}", json.dumps(inp, indent=1)[:800]
55
+ if name in ("WebFetch", "WebSearch"):
56
+ return f"{name} {inp.get('url') or inp.get('query') or ''}", json.dumps(inp, indent=1)[:800]
57
+ return name, json.dumps(inp, indent=1)[:1500]
58
+
59
+
60
+ def permission_request(p):
61
+ if not J.tui_alive():
62
+ return # judge not open → regular dialog
63
+ name = p.get("tool_name", "?")
64
+ headline, detail = describe_tool(name, p.get("tool_input"))
65
+ info = J.summarise_turn(p.get("transcript_path", ""))
66
+ card = J.new_card(
67
+ "permission", p.get("session_id", ""), p.get("cwd", ""),
68
+ f"{name}: {headline}"[:140],
69
+ detail,
70
+ tool_name=name,
71
+ tool_input=p.get("tool_input"),
72
+ prompt=J.pretty_prompt(info["prompt"])[:600],
73
+ slug=info["slug"], branch=info["branch"], model=info["model"],
74
+ )
75
+ # Wait for the swipe. Give up (→ normal dialog) if the TUI disappears.
76
+ while True:
77
+ time.sleep(POLL)
78
+ cur = J.load_card(card["id"])
79
+ if cur is None:
80
+ return
81
+ if cur["status"] == "decided":
82
+ break
83
+ if cur["status"] == "expired":
84
+ return
85
+ if not J.tui_alive():
86
+ J.expire(cur)
87
+ return
88
+ if cur["verdict"] == "approve":
89
+ decision = {"behavior": "allow"}
90
+ else:
91
+ msg = cur.get("comment") or "Denied by the human reviewer in judge."
92
+ decision = {"behavior": "deny", "message": f"[judge] {msg}"}
93
+ out({"hookSpecificOutput": {"hookEventName": "PermissionRequest", "decision": decision}})
94
+
95
+
96
+ # --------------------------------------------------------------------------- #
97
+ # gates
98
+ # --------------------------------------------------------------------------- #
99
+
100
+ RED_HEADLINE = {
101
+ "real-red": "fails on an assertion — a real red",
102
+ "weak-red": "fails on an import or compile error, not on behaviour",
103
+ "not-a-gate": "PASSES without the implementation — this is not a gate",
104
+ "already-green": "passes against committed code — it checks behaviour that already exists",
105
+ "timeout": "the run timed out",
106
+ "unrunnable": "no runnable test command for this repo",
107
+ }
108
+
109
+ GREEN_HEADLINE = {
110
+ "bites": "every mutation was caught",
111
+ "partial": "some mutations survived",
112
+ "rubber-stamp": "every mutation survived — the test does not bite",
113
+ "unverified": "could not be scored",
114
+ }
115
+
116
+
117
+ def wait_for_swipe(card):
118
+ """Block until the human decides, the card expires, or the TUI disappears.
119
+
120
+ Returns the decided card, or None when nobody is going to answer — in which
121
+ case the caller must fall through and let the session proceed.
122
+ """
123
+ while True:
124
+ time.sleep(POLL)
125
+ current = J.load_card(card["id"])
126
+ if current is None:
127
+ return None
128
+ if current["status"] == "decided":
129
+ return current
130
+ if current["status"] == "expired":
131
+ return None
132
+ if not J.tui_alive():
133
+ J.expire(current)
134
+ return None
135
+
136
+
137
+ def gate_title(stage, claims, files, conclusion):
138
+ claim = claims[0] if claims else J.short_dir(files[0]) if files else "test change"
139
+ verdict = (RED_HEADLINE if stage == "red" else GREEN_HEADLINE).get(conclusion, conclusion)
140
+ return f"{claim} — {verdict}"[:140]
141
+
142
+
143
+ def file_gate_card(p, repo, stage, test_files, source_files, verify, extra=None):
144
+ info = J.summarise_turn(p.get("transcript_path", ""))
145
+ claims = G.added_test_names(repo, test_files)
146
+ body = G.added_lines_text(repo, test_files)
147
+ meta = {
148
+ "stage": stage,
149
+ "files": test_files,
150
+ "sources": source_files,
151
+ "claims": claims,
152
+ "smells": G.smells(body),
153
+ "verify": verify,
154
+ "prompt": J.pretty_prompt(info["prompt"])[:600],
155
+ "slug": info["slug"], "branch": info["branch"], "model": info["model"],
156
+ }
157
+ meta.update(extra or {})
158
+ return J.new_card("gate", p.get("session_id", ""), p.get("cwd", ""),
159
+ gate_title(stage, claims, test_files, verify.get("conclusion", "")),
160
+ body, **meta)
161
+
162
+
163
+ def deny(reason):
164
+ out({"hookSpecificOutput": {"hookEventName": "PreToolUse",
165
+ "permissionDecision": "deny",
166
+ "permissionDecisionReason": reason}})
167
+
168
+
169
+ def gate_feedback(card, stage, verify):
170
+ """What the session is told when a gate is rejected."""
171
+ lines = [f"[judge] The human reviewed the gate you just wrote and rejected it ({stage} stage)."]
172
+ conclusion = verify.get("conclusion", "")
173
+ if stage == "red":
174
+ lines.append(f"- mechanical result: {RED_HEADLINE.get(conclusion, conclusion)}")
175
+ else:
176
+ lines.append(f"- mutation result: {verify.get('killed', 0)}/{verify.get('scored', 0)} caught"
177
+ f" — {GREEN_HEADLINE.get(conclusion, conclusion)}")
178
+ for mutant in verify.get("mutants", []):
179
+ if not mutant.get("killed") and not mutant.get("invalid"):
180
+ lines.append(f" survived: {mutant['file']}:{mutant['line']} {mutant['op']} — "
181
+ f"the suite still passed with `{mutant['after']}`")
182
+ for smell in card["meta"].get("smells", []):
183
+ lines.append(f"- smell: {smell['code']} — {smell['note']}")
184
+ if card.get("comment"):
185
+ lines.append(f"- the human's comment: {card['comment']}")
186
+ else:
187
+ lines.append("- no comment given: work out from the evidence above why this gate is too weak,"
188
+ " and say what you think was wrong before changing it")
189
+ lines.append("Strengthen the test — assert the behaviour that would actually break, not that the code"
190
+ " was called — and do not write the implementation until the gate would catch a wrong one.")
191
+ return "\n".join(lines)
192
+
193
+
194
+ def pre_tool_use(p):
195
+ """The red gate. Runs only when tests are pending and the TUI is up."""
196
+ if p.get("tool_name") not in J.EDIT_TOOLS:
197
+ return
198
+ path = (p.get("tool_input") or {}).get("file_path") or ""
199
+ if not path or not G.is_gateable_source(path):
200
+ return
201
+ sid = p.get("session_id", "")
202
+ if not G.load_session(sid)["pending"]:
203
+ return
204
+ if not J.tui_alive():
205
+ return # judge not open → never gate anything
206
+
207
+ cwd = p.get("cwd", "")
208
+ repo = G.repo_root(cwd)
209
+ cfg = G.config(repo)
210
+ if not cfg["enabled"] or not repo:
211
+ return
212
+
213
+ pending = G.take_pending(sid)
214
+ tests = [rel for rel in (G.rel_in_repo(repo, f) for f in pending if os.path.exists(f)) if rel]
215
+ if not tests:
216
+ return
217
+ sources = [f for f in G.changed_files(repo) if G.is_gateable_source(f)]
218
+
219
+ # The card appears before the replay finishes so the human can start reading
220
+ # the test while the machine works out whether it fails for a good reason.
221
+ card = file_gate_card(p, repo, "red", tests, sources,
222
+ {"stage": "red", "status": "running"},
223
+ {"next_edit": G.rel_in_repo(repo, path) or path})
224
+ verify = G.verify_red(repo, cfg, tests, sources)
225
+ if verify.get("conclusion") == "passes":
226
+ # An implementation is one edit away. A test that already passes cannot
227
+ # fail when that implementation is wrong, whatever it turns out to be.
228
+ verify["conclusion"] = "not-a-gate"
229
+ card = J.load_card(card["id"]) or card
230
+ card["meta"]["verify"] = verify
231
+ card["title"] = gate_title("red", card["meta"]["claims"], tests, verify.get("conclusion", ""))
232
+ J.save_card(card)
233
+
234
+ # A test that passes with the implementation reverted is not a gate. That is
235
+ # a fact, not a judgement call, so it does not wait for a human.
236
+ if verify.get("conclusion") == "not-a-gate":
237
+ card["meta"]["auto"] = True
238
+ J.decide(card, "reject", "auto: the test passes with the implementation reverted")
239
+ G.append_ledger(J.load_card(card["id"]) or card)
240
+ deny(gate_feedback(J.load_card(card["id"]) or card, "red", verify))
241
+ return
242
+
243
+ decided = wait_for_swipe(card)
244
+ if decided is None:
245
+ return # nobody answered → do not hold the session up
246
+ G.append_ledger(decided)
247
+ if decided.get("verdict") == "reject":
248
+ deny(gate_feedback(decided, "red", verify))
249
+ return
250
+ G.remember_gate(sid, decided["id"], tests, "red")
251
+
252
+
253
+ def green_pass(p, sid, repo, cfg):
254
+ """Mutate the implementation behind an approved gate. Returns a block reason."""
255
+ awaiting = G.awaiting_green(sid)
256
+ if not awaiting:
257
+ return None
258
+ sources = [f for f in G.changed_files(repo) if G.is_gateable_source(f)]
259
+ if not sources:
260
+ return None # implementation not written yet — try again next turn
261
+
262
+ card_id, gate = sorted(awaiting.items(), key=lambda kv: kv[1]["ts"])[0]
263
+ tests = [f for f in gate["files"] if os.path.exists(os.path.join(repo, f))]
264
+ if not tests:
265
+ G.mark_green_done(sid, card_id)
266
+ return None
267
+
268
+ verify = G.verify_green(repo, cfg, tests, sources)
269
+ if verify.get("baseline") != "pass":
270
+ return None # still red — the implementation is not finished
271
+ G.mark_green_done(sid, card_id)
272
+ if verify.get("conclusion") in ("bites", "unverified"):
273
+ return None # nothing for a human to look at
274
+
275
+ card = file_gate_card(p, repo, "green", tests, sources, verify, {"parent": card_id})
276
+ decided = wait_for_swipe(card)
277
+ if decided is None:
278
+ return None
279
+ G.append_ledger(decided)
280
+ if decided.get("verdict") == "reject":
281
+ return gate_feedback(decided, "green", verify)
282
+ return None
283
+
284
+
285
+ def unfollowed_tests(p, sid, repo, cfg):
286
+ """Tests written with no implementation edit after them — card them at Stop."""
287
+ pending = G.load_session(sid)["pending"]
288
+ if not pending:
289
+ return None
290
+ taken = G.take_pending(sid)
291
+ tests = [rel for rel in (G.rel_in_repo(repo, f) for f in taken if os.path.exists(f)) if rel]
292
+ if not tests:
293
+ return None
294
+ sources = [f for f in G.changed_files(repo) if G.is_gateable_source(f)]
295
+ verify = G.verify_red(repo, cfg, tests, sources)
296
+ if verify.get("conclusion") == "passes":
297
+ # No implementation is coming, so this test pins behaviour that already
298
+ # works. Expected, and not something to hold a session over.
299
+ verify["conclusion"] = "already-green"
300
+ card = file_gate_card(p, repo, "red", tests, sources, verify, {"trigger": "stop"})
301
+ if verify.get("conclusion") == "already-green":
302
+ # Nothing was taken away, so the replay proves nothing and there is no
303
+ # red to hold. The card stands as a record; the session moves on.
304
+ G.remember_gate(sid, card["id"], tests, "red")
305
+ return None
306
+ decided = wait_for_swipe(card)
307
+ if decided is None:
308
+ return None
309
+ G.append_ledger(decided)
310
+ if decided.get("verdict") == "reject":
311
+ return gate_feedback(decided, "red", verify)
312
+ G.remember_gate(sid, decided["id"], tests, "red")
313
+ return None
314
+
315
+
316
+ def gates_at_stop(p):
317
+ """Gate work owed at the end of a turn. Returns a block reason, or None."""
318
+ sid = p.get("session_id", "")
319
+ if not J.tui_alive():
320
+ return None
321
+ repo = G.repo_root(p.get("cwd", ""))
322
+ cfg = G.config(repo)
323
+ if not repo or not cfg["enabled"]:
324
+ return None
325
+ return green_pass(p, sid, repo, cfg) or unfollowed_tests(p, sid, repo, cfg)
326
+
327
+
328
+ def post_tool_use(p):
329
+ """Remember test edits. Silent, and never blocks anything."""
330
+ if p.get("tool_name") not in J.EDIT_TOOLS:
331
+ return
332
+ path = (p.get("tool_input") or {}).get("file_path") or ""
333
+ if path and G.is_test_file(path):
334
+ G.record_test_edit(p.get("session_id", ""), path)
335
+
336
+
337
+ def stop(p):
338
+ sid = p.get("session_id", "")
339
+ J.gc()
340
+ items = J.drain_inbox(sid)
341
+ if items:
342
+ out({"decision": "block", "reason": J.format_feedback(items)})
343
+ return
344
+ blocked = gates_at_stop(p)
345
+ if blocked:
346
+ out({"decision": "block", "reason": blocked})
347
+ return
348
+ info = J.summarise_turn(p.get("transcript_path", ""))
349
+ reply = p.get("last_assistant_message") or info["reply"]
350
+ if not J.is_substantive(info, reply):
351
+ return
352
+ J.supersede_open_reviews(sid)
353
+ first_line = next((ln.strip("# ").strip() for ln in reply.splitlines() if ln.strip()), "") or "(no text reply)"
354
+ J.new_card(
355
+ "review", sid, p.get("cwd", ""),
356
+ first_line[:140],
357
+ reply[:6000],
358
+ prompt=J.pretty_prompt(info["prompt"])[:800],
359
+ files=info["files"],
360
+ bash=info["bash"],
361
+ tools=info["tools"],
362
+ slug=info["slug"], branch=info["branch"], model=info["model"],
363
+ )
364
+
365
+
366
+ def user_prompt_submit(p):
367
+ items = J.drain_inbox(p.get("session_id", ""))
368
+ if items:
369
+ out({"hookSpecificOutput": {"hookEventName": "UserPromptSubmit",
370
+ "additionalContext": J.format_feedback(items)}})
371
+
372
+
373
+ def main():
374
+ event = sys.argv[1] if len(sys.argv) > 1 else ""
375
+ try:
376
+ payload = json.load(sys.stdin)
377
+ except Exception:
378
+ payload = {}
379
+ try:
380
+ {"PermissionRequest": permission_request,
381
+ "PreToolUse": pre_tool_use,
382
+ "PostToolUse": post_tool_use,
383
+ "Stop": stop,
384
+ "UserPromptSubmit": user_prompt_submit}.get(event, lambda _: None)(payload)
385
+ except Exception as exc: # never break a session because of the judge
386
+ sys.stderr.write(f"judge hook error: {exc}\n")
387
+ sys.exit(0)
388
+
389
+
390
+ if __name__ == "__main__":
391
+ main()