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.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +74 -0
- package/README.md +56 -6
- package/agents/debugger.md +12 -1
- package/agents/git-committer.md +1 -0
- package/agents/implementer.md +11 -2
- package/agents/investigator.md +75 -0
- package/agents/reviewer.md +7 -0
- package/agents/speaker.md +44 -0
- package/agents/verifier.md +4 -3
- package/bin/draht-tools.cjs +472 -41
- package/bin/judge +613 -0
- package/cli.mjs +769 -46
- package/commands/atomic-commit.md +1 -12
- package/commands/create-verification-skill.md +105 -0
- package/commands/discuss-phase.md +3 -14
- package/commands/execute-phase.md +7 -14
- package/commands/fix.md +38 -17
- package/commands/grill.md +66 -0
- package/commands/init-project.md +5 -15
- package/commands/map-codebase.md +1 -13
- package/commands/new-project.md +5 -15
- package/commands/next-milestone.md +2 -13
- package/commands/orchestrate.md +1 -1
- package/commands/pause-work.md +1 -8
- package/commands/plan-phase.md +2 -11
- package/commands/progress.md +0 -8
- package/commands/quick.md +3 -11
- package/commands/resolve-conflicts.md +72 -0
- package/commands/resume-work.md +0 -8
- package/commands/review.md +4 -13
- package/commands/speak.md +45 -0
- package/commands/triage.md +161 -0
- package/commands/verify-work.md +5 -13
- package/commands/why.md +137 -0
- package/graph-archive.mjs +125 -0
- package/graph-manifest.mjs +97 -0
- package/hooks/hooks.json +39 -0
- package/package.json +5 -3
- package/scripts/gsd-quality-gate.cjs +3 -3
- package/scripts/judge-hook.cjs +42 -0
- package/scripts/judge-hook.py +391 -0
- package/scripts/judgegates.py +673 -0
- package/scripts/judgelib.py +382 -0
- package/scripts/speak.cjs +202 -0
- package/skills/atomic-commit/SKILL.md +1 -1
- package/skills/atomic-commit/command.md +62 -0
- package/skills/blast-radius/SKILL.md +55 -0
- package/skills/brainstorming/SKILL.md +11 -4
- package/skills/cinematic-continuation/SKILL.md +111 -0
- package/skills/cinematic-continuation/references/continuity-schema.md +75 -0
- package/skills/cinematic-continuation/references/seedance-adapter.md +44 -0
- package/skills/cinematic-continuation/references/style-bible.md +223 -0
- package/skills/cinematic-continuation/scripts/compile-continuation.mjs +173 -0
- package/skills/cinematic-continuation/templates/continuation-spec.json +50 -0
- package/skills/create-verification-skill/SKILL.md +14 -0
- package/skills/create-verification-skill/command.md +105 -0
- package/skills/debugging-workflow/SKILL.md +38 -10
- package/skills/discuss-phase/SKILL.md +1 -1
- package/skills/discuss-phase/command.md +44 -0
- package/skills/draht/SKILL.md +118 -0
- package/skills/epistemics/SKILL.md +99 -0
- package/skills/execute-phase/SKILL.md +1 -1
- package/skills/execute-phase/command.md +170 -0
- package/skills/fix/SKILL.md +1 -1
- package/skills/fix/command.md +154 -0
- package/skills/grill/SKILL.md +14 -0
- package/skills/grill/command.md +66 -0
- package/skills/gsd-workflow/SKILL.md +2 -0
- package/skills/init-project/SKILL.md +1 -1
- package/skills/init-project/command.md +57 -0
- package/skills/judge/SKILL.md +57 -0
- package/skills/map-codebase/SKILL.md +1 -1
- package/skills/map-codebase/command.md +61 -0
- package/skills/new-project/SKILL.md +1 -1
- package/skills/new-project/command.md +64 -0
- package/skills/next-milestone/SKILL.md +1 -1
- package/skills/next-milestone/command.md +42 -0
- package/skills/orchestrate/SKILL.md +1 -1
- package/skills/orchestrate/command.md +106 -0
- package/skills/orchestrate-loop/SKILL.md +1 -1
- package/skills/orchestrate-loop/command.md +100 -0
- package/skills/pause-work/SKILL.md +1 -1
- package/skills/pause-work/command.md +32 -0
- package/skills/plan-phase/SKILL.md +1 -1
- package/skills/plan-phase/command.md +139 -0
- package/skills/progress/SKILL.md +1 -1
- package/skills/progress/command.md +22 -0
- package/skills/quick/SKILL.md +1 -1
- package/skills/quick/command.md +91 -0
- package/skills/resolve-conflicts/SKILL.md +14 -0
- package/skills/resolve-conflicts/command.md +72 -0
- package/skills/resume-work/SKILL.md +1 -1
- package/skills/resume-work/command.md +27 -0
- package/skills/review/SKILL.md +1 -1
- package/skills/review/command.md +81 -0
- package/skills/saga-spawner/SKILL.md +131 -0
- package/skills/speak/SKILL.md +14 -0
- package/skills/speak/command.md +45 -0
- package/skills/tdd-workflow/SKILL.md +2 -0
- package/skills/triage/SKILL.md +14 -0
- package/skills/triage/command.md +161 -0
- package/skills/typescript-discipline/SKILL.md +50 -0
- package/skills/typescript-discipline/references/patterns.md +294 -0
- package/skills/unslop/SKILL.md +101 -0
- package/skills/verify-work/SKILL.md +1 -1
- package/skills/verify-work/command.md +116 -0
- package/skills/why/SKILL.md +14 -0
- package/skills/why/command.md +137 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"""Shared state for the judge queue: the cards, per-session inboxes,
|
|
2
|
+
TUI heartbeat, and transcript summarisation.
|
|
3
|
+
|
|
4
|
+
Layout under $CLAUDE_CONFIG_DIR/judge:
|
|
5
|
+
|
|
6
|
+
cards/<id>.json one open or decided decision card
|
|
7
|
+
inbox/<session>/<id>.json feedback waiting to be delivered to a session
|
|
8
|
+
heartbeat touched by the TUI every second while it runs
|
|
9
|
+
|
|
10
|
+
Cards:
|
|
11
|
+
kind "permission" | "review"
|
|
12
|
+
status "open" | "decided" | "expired"
|
|
13
|
+
verdict "approve" | "reject" (once decided)
|
|
14
|
+
comment free text from the human (optional)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import os
|
|
19
|
+
import time
|
|
20
|
+
import uuid
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
CONFIG_DIR = Path(os.environ.get("CLAUDE_CONFIG_DIR") or Path.home() / ".claude")
|
|
24
|
+
ROOT = CONFIG_DIR / "judge"
|
|
25
|
+
CARDS = ROOT / "cards"
|
|
26
|
+
INBOX = ROOT / "inbox"
|
|
27
|
+
HEARTBEAT = ROOT / "heartbeat"
|
|
28
|
+
|
|
29
|
+
HEARTBEAT_STALE = 5.0 # seconds without a heartbeat → TUI considered gone
|
|
30
|
+
REVIEW_TTL = 24 * 3600 # review cards older than this are dropped
|
|
31
|
+
DECIDED_TTL = 3 * 24 * 3600 # decided cards kept this long for history
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def ensure_dirs():
|
|
35
|
+
for d in (CARDS, INBOX):
|
|
36
|
+
d.mkdir(parents=True, exist_ok=True)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _write_json(path, data):
|
|
40
|
+
tmp = path.with_suffix(path.suffix + f".{os.getpid()}.tmp")
|
|
41
|
+
tmp.write_text(json.dumps(data, indent=1))
|
|
42
|
+
os.replace(tmp, path)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _read_json(path):
|
|
46
|
+
try:
|
|
47
|
+
return json.loads(path.read_text())
|
|
48
|
+
except Exception:
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# --------------------------------------------------------------------------- #
|
|
53
|
+
# heartbeat
|
|
54
|
+
# --------------------------------------------------------------------------- #
|
|
55
|
+
|
|
56
|
+
def beat():
|
|
57
|
+
ensure_dirs()
|
|
58
|
+
HEARTBEAT.write_text(str(os.getpid()))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def tui_alive():
|
|
62
|
+
try:
|
|
63
|
+
return time.time() - HEARTBEAT.stat().st_mtime < HEARTBEAT_STALE
|
|
64
|
+
except OSError:
|
|
65
|
+
return False
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# --------------------------------------------------------------------------- #
|
|
69
|
+
# cards
|
|
70
|
+
# --------------------------------------------------------------------------- #
|
|
71
|
+
|
|
72
|
+
def new_card(kind, session_id, cwd, title, body, **meta):
|
|
73
|
+
ensure_dirs()
|
|
74
|
+
card = {
|
|
75
|
+
"id": uuid.uuid4().hex[:12],
|
|
76
|
+
"kind": kind,
|
|
77
|
+
"status": "open",
|
|
78
|
+
"session_id": session_id,
|
|
79
|
+
"cwd": cwd,
|
|
80
|
+
"title": title,
|
|
81
|
+
"body": body,
|
|
82
|
+
"created": time.time(),
|
|
83
|
+
"meta": meta,
|
|
84
|
+
}
|
|
85
|
+
_write_json(CARDS / f"{card['id']}.json", card)
|
|
86
|
+
return card
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def load_card(card_id):
|
|
90
|
+
return _read_json(CARDS / f"{card_id}.json")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def save_card(card):
|
|
94
|
+
_write_json(CARDS / f"{card['id']}.json", card)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def all_cards():
|
|
98
|
+
ensure_dirs()
|
|
99
|
+
cards = []
|
|
100
|
+
for p in CARDS.glob("*.json"):
|
|
101
|
+
c = _read_json(p)
|
|
102
|
+
if c:
|
|
103
|
+
cards.append(c)
|
|
104
|
+
return cards
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
BLOCKING_KINDS = ("permission", "gate")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def open_cards():
|
|
111
|
+
"""Open cards, blocking ones first (a session is waiting), then newest reviews."""
|
|
112
|
+
cards = [c for c in all_cards() if c["status"] == "open"]
|
|
113
|
+
order = {"permission": 0, "gate": 1}
|
|
114
|
+
cards.sort(key=lambda c: (order.get(c["kind"], 2),
|
|
115
|
+
c["created"] if c["kind"] in BLOCKING_KINDS else -c["created"]))
|
|
116
|
+
return cards
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def decide(card, verdict, comment=""):
|
|
120
|
+
card["status"] = "decided"
|
|
121
|
+
card["verdict"] = verdict
|
|
122
|
+
card["comment"] = comment.strip()
|
|
123
|
+
card["decided_at"] = time.time()
|
|
124
|
+
save_card(card)
|
|
125
|
+
# Review feedback travels to the session's inbox; permission verdicts are
|
|
126
|
+
# picked up directly by the waiting hook.
|
|
127
|
+
if card["kind"] == "review" and (verdict == "reject" or card["comment"]):
|
|
128
|
+
post_inbox(card["session_id"], {
|
|
129
|
+
"card_id": card["id"],
|
|
130
|
+
"verdict": verdict,
|
|
131
|
+
"comment": card["comment"],
|
|
132
|
+
"title": card["title"],
|
|
133
|
+
"ts": card["decided_at"],
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def undo(card):
|
|
138
|
+
"""Reopen a decided card. Returns (ok, note).
|
|
139
|
+
|
|
140
|
+
Review: pull the inbox item back if it is still waiting; if the session
|
|
141
|
+
already consumed it, post a retraction so the session disregards it.
|
|
142
|
+
Permission: the waiting hook already returned — cannot be taken back.
|
|
143
|
+
"""
|
|
144
|
+
if card["status"] != "decided":
|
|
145
|
+
return False, "nothing to undo"
|
|
146
|
+
if card["kind"] in BLOCKING_KINDS:
|
|
147
|
+
return False, f"{card['kind']} already answered to the session — cannot undo"
|
|
148
|
+
note = "reopened"
|
|
149
|
+
p = INBOX / card["session_id"] / f"{card['id']}.json"
|
|
150
|
+
if card.get("verdict") == "reject" or card.get("comment"):
|
|
151
|
+
if p.exists():
|
|
152
|
+
p.unlink()
|
|
153
|
+
note = "reopened · feedback pulled back before delivery"
|
|
154
|
+
else:
|
|
155
|
+
post_inbox(card["session_id"], {
|
|
156
|
+
"card_id": card["id"] + "-retract",
|
|
157
|
+
"verdict": "retract",
|
|
158
|
+
"comment": card.get("comment", ""),
|
|
159
|
+
"title": card["title"],
|
|
160
|
+
"ts": time.time(),
|
|
161
|
+
})
|
|
162
|
+
note = "reopened · feedback was already delivered — retraction sent"
|
|
163
|
+
for k in ("verdict", "comment", "decided_at"):
|
|
164
|
+
card.pop(k, None)
|
|
165
|
+
card["status"] = "open"
|
|
166
|
+
save_card(card)
|
|
167
|
+
return True, note
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def expire(card):
|
|
171
|
+
card["status"] = "expired"
|
|
172
|
+
save_card(card)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def supersede_open_reviews(session_id):
|
|
176
|
+
"""A session's newer turn replaces any still-open review card for it."""
|
|
177
|
+
for c in all_cards():
|
|
178
|
+
if c["status"] == "open" and c["kind"] == "review" and c["session_id"] == session_id:
|
|
179
|
+
expire(c)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def gc():
|
|
183
|
+
now = time.time()
|
|
184
|
+
for c in all_cards():
|
|
185
|
+
age = now - c["created"]
|
|
186
|
+
if c["status"] == "open" and c["kind"] in ("review", "gate") and age > REVIEW_TTL:
|
|
187
|
+
expire(c)
|
|
188
|
+
elif c["status"] != "open" and age > DECIDED_TTL:
|
|
189
|
+
try:
|
|
190
|
+
(CARDS / f"{c['id']}.json").unlink()
|
|
191
|
+
except OSError:
|
|
192
|
+
pass
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# --------------------------------------------------------------------------- #
|
|
196
|
+
# inbox
|
|
197
|
+
# --------------------------------------------------------------------------- #
|
|
198
|
+
|
|
199
|
+
def post_inbox(session_id, item):
|
|
200
|
+
d = INBOX / session_id
|
|
201
|
+
d.mkdir(parents=True, exist_ok=True)
|
|
202
|
+
_write_json(d / f"{item['card_id']}.json", item)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def pending_inbox(session_id):
|
|
206
|
+
d = INBOX / session_id
|
|
207
|
+
if not d.is_dir():
|
|
208
|
+
return []
|
|
209
|
+
items = [i for i in (_read_json(p) for p in sorted(d.glob("*.json"))) if i]
|
|
210
|
+
items.sort(key=lambda i: i.get("ts", 0))
|
|
211
|
+
return items
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def drain_inbox(session_id):
|
|
215
|
+
"""Return pending feedback and remove it (it is about to be delivered)."""
|
|
216
|
+
items = pending_inbox(session_id)
|
|
217
|
+
for i in items:
|
|
218
|
+
try:
|
|
219
|
+
(INBOX / session_id / f"{i['card_id']}.json").unlink()
|
|
220
|
+
except OSError:
|
|
221
|
+
pass
|
|
222
|
+
return items
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def format_feedback(items):
|
|
226
|
+
lines = ["[judge] Human review feedback on your recent work (from the judge TUI):"]
|
|
227
|
+
for i in items:
|
|
228
|
+
if i["verdict"] == "retract":
|
|
229
|
+
lines.append(f"- RETRACTED — the reviewer withdrew their earlier feedback on "
|
|
230
|
+
f"\"{i.get('title', '')}\"; disregard it (it was a mistake), undo nothing.")
|
|
231
|
+
continue
|
|
232
|
+
mark = "REJECTED" if i["verdict"] == "reject" else "approved, with a note"
|
|
233
|
+
lines.append(f"- {mark} — re: \"{i.get('title', '')}\"")
|
|
234
|
+
if i.get("comment"):
|
|
235
|
+
lines.append(f" comment: {i['comment']}")
|
|
236
|
+
elif i["verdict"] == "reject":
|
|
237
|
+
lines.append(" (no comment given — the reviewer was not happy with this turn; "
|
|
238
|
+
"re-examine it critically and ask what is off if unclear)")
|
|
239
|
+
lines.append("Address this feedback before continuing with anything else.")
|
|
240
|
+
return "\n".join(lines)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
# --------------------------------------------------------------------------- #
|
|
244
|
+
# transcript summarisation
|
|
245
|
+
# --------------------------------------------------------------------------- #
|
|
246
|
+
|
|
247
|
+
EDIT_TOOLS = {"Edit", "Write", "MultiEdit", "NotebookEdit"}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _text_of(content):
|
|
251
|
+
if isinstance(content, str):
|
|
252
|
+
return content
|
|
253
|
+
out = []
|
|
254
|
+
for block in content or []:
|
|
255
|
+
if isinstance(block, dict) and block.get("type") == "text":
|
|
256
|
+
out.append(block.get("text", ""))
|
|
257
|
+
return "\n".join(out)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _is_human(rec):
|
|
261
|
+
if rec.get("type") != "user" or rec.get("isMeta"):
|
|
262
|
+
return False
|
|
263
|
+
content = (rec.get("message") or {}).get("content")
|
|
264
|
+
text = _text_of(content).lstrip()
|
|
265
|
+
if not text:
|
|
266
|
+
return False
|
|
267
|
+
# harness-injected "user" turns are not the human typing
|
|
268
|
+
return not text.startswith(("<task-notification", "<system-reminder", "<local-command",
|
|
269
|
+
"<command-name", "<bash-input", "<bash-stdout"))
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def tail_records(path, max_bytes=2_000_000):
|
|
273
|
+
"""Parse the last `max_bytes` of a transcript into records."""
|
|
274
|
+
try:
|
|
275
|
+
size = os.path.getsize(path)
|
|
276
|
+
with open(path, "rb") as fh:
|
|
277
|
+
if size > max_bytes:
|
|
278
|
+
fh.seek(size - max_bytes)
|
|
279
|
+
fh.readline() # drop partial line
|
|
280
|
+
raw = fh.read()
|
|
281
|
+
except OSError:
|
|
282
|
+
return []
|
|
283
|
+
recs = []
|
|
284
|
+
for line in raw.splitlines():
|
|
285
|
+
try:
|
|
286
|
+
recs.append(json.loads(line))
|
|
287
|
+
except Exception:
|
|
288
|
+
continue
|
|
289
|
+
return recs
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def summarise_turn(transcript_path):
|
|
293
|
+
"""What happened since the last human message.
|
|
294
|
+
|
|
295
|
+
Returns dict(prompt, reply, files, bash, tools, slug, branch, model).
|
|
296
|
+
"""
|
|
297
|
+
recs = tail_records(transcript_path)
|
|
298
|
+
slug = branch = model = ""
|
|
299
|
+
for r in reversed(recs):
|
|
300
|
+
slug = slug or r.get("slug", "")
|
|
301
|
+
branch = branch or r.get("gitBranch", "")
|
|
302
|
+
if not model and r.get("type") == "assistant":
|
|
303
|
+
m = (r.get("message") or {}).get("model", "")
|
|
304
|
+
if m and not m.startswith("<"):
|
|
305
|
+
model = m
|
|
306
|
+
if slug and branch and model:
|
|
307
|
+
break
|
|
308
|
+
|
|
309
|
+
start = 0
|
|
310
|
+
for i in range(len(recs) - 1, -1, -1):
|
|
311
|
+
if _is_human(recs[i]):
|
|
312
|
+
start = i
|
|
313
|
+
break
|
|
314
|
+
|
|
315
|
+
prompt = _text_of((recs[start].get("message") or {}).get("content")) if recs and _is_human(recs[start]) else ""
|
|
316
|
+
reply = ""
|
|
317
|
+
files, bash, tools = [], [], {}
|
|
318
|
+
for r in recs[start:]:
|
|
319
|
+
if r.get("type") != "assistant" or r.get("isApiErrorMessage"):
|
|
320
|
+
continue
|
|
321
|
+
for block in (r.get("message") or {}).get("content") or []:
|
|
322
|
+
if not isinstance(block, dict):
|
|
323
|
+
continue
|
|
324
|
+
if block.get("type") == "text" and block.get("text", "").strip():
|
|
325
|
+
reply = block["text"]
|
|
326
|
+
elif block.get("type") == "tool_use":
|
|
327
|
+
name = block.get("name", "?")
|
|
328
|
+
tools[name] = tools.get(name, 0) + 1
|
|
329
|
+
inp = block.get("input") or {}
|
|
330
|
+
if name in EDIT_TOOLS and inp.get("file_path"):
|
|
331
|
+
if inp["file_path"] not in files:
|
|
332
|
+
files.append(inp["file_path"])
|
|
333
|
+
elif name == "Bash" and inp.get("command"):
|
|
334
|
+
bash.append(inp["command"].strip().splitlines()[0][:120])
|
|
335
|
+
return {
|
|
336
|
+
"prompt": prompt.strip(),
|
|
337
|
+
"reply": reply.strip(),
|
|
338
|
+
"files": files,
|
|
339
|
+
"bash": bash[-8:],
|
|
340
|
+
"tools": tools,
|
|
341
|
+
"slug": slug,
|
|
342
|
+
"branch": branch,
|
|
343
|
+
"model": model,
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
# Turns below this bar are not worth a human's attention.
|
|
348
|
+
MIN_REPLY_CHARS = 700
|
|
349
|
+
MIN_TOOL_CALLS = 4
|
|
350
|
+
SLASH_MARK = "<command-message>"
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def is_substantive(info, reply):
|
|
354
|
+
"""Did this turn do anything a reviewer should look at?"""
|
|
355
|
+
if info["prompt"].startswith(SLASH_MARK) and not info["files"]:
|
|
356
|
+
return False # slash-command bookkeeping turn
|
|
357
|
+
if info["files"]:
|
|
358
|
+
return True
|
|
359
|
+
if sum(info["tools"].values()) >= MIN_TOOL_CALLS:
|
|
360
|
+
return True
|
|
361
|
+
return len(reply) >= MIN_REPLY_CHARS
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def pretty_prompt(prompt):
|
|
365
|
+
"""'<command-message>judge:judge</command-message>…' → '/judge:judge'."""
|
|
366
|
+
if prompt.startswith(SLASH_MARK):
|
|
367
|
+
end = prompt.find("</command-message>")
|
|
368
|
+
if end > 0:
|
|
369
|
+
return "/" + prompt[len(SLASH_MARK):end].strip()
|
|
370
|
+
return prompt
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def short_dir(path):
|
|
374
|
+
home = str(Path.home())
|
|
375
|
+
if path == home:
|
|
376
|
+
return "~"
|
|
377
|
+
if path.startswith(home + "/"):
|
|
378
|
+
path = "~/" + path[len(home) + 1:]
|
|
379
|
+
parts = path.split("/")
|
|
380
|
+
if len(parts) > 3:
|
|
381
|
+
return ".../" + "/".join(parts[-2:])
|
|
382
|
+
return path
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* draht speak — ElevenLabs text-to-speech helper.
|
|
4
|
+
*
|
|
5
|
+
* Synthesizes text with the ElevenLabs /v1/text-to-speech API and plays it
|
|
6
|
+
* on the local audio device. Self-contained: no dependencies beyond Node 18+
|
|
7
|
+
* (global fetch) and a local audio player (afplay on macOS; mpv/ffplay/mpg123
|
|
8
|
+
* elsewhere).
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* node speak.cjs [options] "text to speak"
|
|
12
|
+
* echo "text" | node speak.cjs [options]
|
|
13
|
+
*
|
|
14
|
+
* Options:
|
|
15
|
+
* --voice <id> ElevenLabs voice id (default: $DRAHT_SPEAK_VOICE_ID or George)
|
|
16
|
+
* --model <id> model id (default: $DRAHT_SPEAK_MODEL_ID or eleven_flash_v2_5)
|
|
17
|
+
* --speed <n> speaking speed 0.25–4.0 (default 1.0)
|
|
18
|
+
* --lang <code> ISO 639-1 language hint (flash/turbo/v3 models only)
|
|
19
|
+
* --out <file> also keep the mp3 at this path
|
|
20
|
+
* --no-play synthesize only, do not play audio
|
|
21
|
+
* --force bypass the character-count cost guard
|
|
22
|
+
*
|
|
23
|
+
* API key resolution order:
|
|
24
|
+
* 1. $ELEVENLABS_API_KEY
|
|
25
|
+
* 2. ELEVENLABS_API_KEY=... line in ./.env
|
|
26
|
+
* 3. ~/.draht/keys/elevenlabs.key (file containing only the key)
|
|
27
|
+
*/
|
|
28
|
+
"use strict";
|
|
29
|
+
|
|
30
|
+
const { execFileSync, spawnSync } = require("node:child_process");
|
|
31
|
+
const { existsSync, mkdtempSync, readFileSync } = require("node:fs");
|
|
32
|
+
const { writeFile } = require("node:fs/promises");
|
|
33
|
+
const { homedir, tmpdir } = require("node:os");
|
|
34
|
+
const { join } = require("node:path");
|
|
35
|
+
|
|
36
|
+
const DEFAULT_VOICE = "JBFqnCBsd6RMkjVDRZzb"; // George — multilingual narrative
|
|
37
|
+
const DEFAULT_MODEL = "eleven_flash_v2_5"; // 32 languages, ~75ms latency, half price
|
|
38
|
+
const MAX_CHARS = Number(process.env.DRAHT_SPEAK_MAX_CHARS || 4000);
|
|
39
|
+
|
|
40
|
+
function fail(msg) {
|
|
41
|
+
console.error(`speak: ${msg}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function parseArgs(argv) {
|
|
46
|
+
const opts = { play: true, force: false, textParts: [] };
|
|
47
|
+
for (let i = 0; i < argv.length; i++) {
|
|
48
|
+
const a = argv[i];
|
|
49
|
+
switch (a) {
|
|
50
|
+
case "--voice":
|
|
51
|
+
opts.voice = argv[++i];
|
|
52
|
+
break;
|
|
53
|
+
case "--model":
|
|
54
|
+
opts.model = argv[++i];
|
|
55
|
+
break;
|
|
56
|
+
case "--speed":
|
|
57
|
+
opts.speed = Number(argv[++i]);
|
|
58
|
+
break;
|
|
59
|
+
case "--lang":
|
|
60
|
+
opts.lang = argv[++i];
|
|
61
|
+
break;
|
|
62
|
+
case "--out":
|
|
63
|
+
opts.out = argv[++i];
|
|
64
|
+
break;
|
|
65
|
+
case "--no-play":
|
|
66
|
+
opts.play = false;
|
|
67
|
+
break;
|
|
68
|
+
case "--force":
|
|
69
|
+
opts.force = true;
|
|
70
|
+
break;
|
|
71
|
+
case "-h":
|
|
72
|
+
case "--help":
|
|
73
|
+
console.log("usage: speak.cjs [--voice id] [--model id] [--speed n] [--lang code] [--out file] [--no-play] [--force] \"text\"");
|
|
74
|
+
process.exit(0);
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
opts.textParts.push(a);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return opts;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readEnvFileKey(path) {
|
|
84
|
+
if (!existsSync(path)) return undefined;
|
|
85
|
+
try {
|
|
86
|
+
const line = readFileSync(path, "utf-8")
|
|
87
|
+
.split("\n")
|
|
88
|
+
.find((l) => l.trim().startsWith("ELEVENLABS_API_KEY="));
|
|
89
|
+
if (!line) return undefined;
|
|
90
|
+
const value = line.slice(line.indexOf("=") + 1).trim();
|
|
91
|
+
return value.replace(/^["']|["']$/g, "") || undefined;
|
|
92
|
+
} catch {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function resolveApiKey() {
|
|
98
|
+
if (process.env.ELEVENLABS_API_KEY?.trim()) return process.env.ELEVENLABS_API_KEY.trim();
|
|
99
|
+
const fromDotenv = readEnvFileKey(join(process.cwd(), ".env"));
|
|
100
|
+
if (fromDotenv) return fromDotenv;
|
|
101
|
+
const keyFile = join(homedir(), ".draht", "keys", "elevenlabs.key");
|
|
102
|
+
if (existsSync(keyFile)) {
|
|
103
|
+
const value = readFileSync(keyFile, "utf-8").trim();
|
|
104
|
+
if (value) return value;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function readStdin() {
|
|
110
|
+
try {
|
|
111
|
+
return readFileSync(0, "utf-8");
|
|
112
|
+
} catch {
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function findPlayer() {
|
|
118
|
+
if (process.platform === "darwin") return { cmd: "afplay", args: [] };
|
|
119
|
+
for (const candidate of [
|
|
120
|
+
{ cmd: "mpv", args: ["--no-video", "--really-quiet"] },
|
|
121
|
+
{ cmd: "ffplay", args: ["-nodisp", "-autoexit", "-loglevel", "quiet"] },
|
|
122
|
+
{ cmd: "mpg123", args: ["-q"] },
|
|
123
|
+
]) {
|
|
124
|
+
const probe = spawnSync(candidate.cmd, ["--version"], { stdio: "ignore" });
|
|
125
|
+
if (!probe.error) return candidate;
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function main() {
|
|
131
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
132
|
+
let text = opts.textParts.join(" ").trim();
|
|
133
|
+
if (!text && !process.stdin.isTTY) text = readStdin().trim();
|
|
134
|
+
if (!text) fail("no text given (pass as argument or on stdin)");
|
|
135
|
+
|
|
136
|
+
if (text.length > MAX_CHARS && !opts.force) {
|
|
137
|
+
fail(
|
|
138
|
+
`text is ${text.length} chars (> ${MAX_CHARS} guard, billed per character). ` +
|
|
139
|
+
"Shorten it for the ear, or pass --force / set DRAHT_SPEAK_MAX_CHARS.",
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const apiKey = resolveApiKey();
|
|
144
|
+
if (!apiKey) {
|
|
145
|
+
fail(
|
|
146
|
+
"no ElevenLabs API key found. Set ELEVENLABS_API_KEY, add it to ./.env, " +
|
|
147
|
+
"or write it to ~/.draht/keys/elevenlabs.key",
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const voice = opts.voice || process.env.DRAHT_SPEAK_VOICE_ID || DEFAULT_VOICE;
|
|
152
|
+
const model = opts.model || process.env.DRAHT_SPEAK_MODEL_ID || DEFAULT_MODEL;
|
|
153
|
+
|
|
154
|
+
const body = { text, model_id: model };
|
|
155
|
+
if (opts.lang) body.language_code = opts.lang;
|
|
156
|
+
const speed = opts.speed ?? (process.env.DRAHT_SPEAK_SPEED ? Number(process.env.DRAHT_SPEAK_SPEED) : undefined);
|
|
157
|
+
if (speed !== undefined) {
|
|
158
|
+
if (!(speed >= 0.25 && speed <= 4)) fail("--speed must be between 0.25 and 4.0");
|
|
159
|
+
body.voice_settings = { speed };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const url = `https://api.elevenlabs.io/v1/text-to-speech/${encodeURIComponent(voice)}?output_format=mp3_44100_128`;
|
|
163
|
+
const res = await fetch(url, {
|
|
164
|
+
method: "POST",
|
|
165
|
+
headers: { "xi-api-key": apiKey, "Content-Type": "application/json" },
|
|
166
|
+
body: JSON.stringify(body),
|
|
167
|
+
});
|
|
168
|
+
if (!res.ok) {
|
|
169
|
+
const detail = (await res.text().catch(() => "")).slice(0, 400);
|
|
170
|
+
const hint =
|
|
171
|
+
res.status === 401
|
|
172
|
+
? " (invalid or missing API key)"
|
|
173
|
+
: res.status === 422
|
|
174
|
+
? " (check voice/model id)"
|
|
175
|
+
: res.status === 429
|
|
176
|
+
? " (rate limited — retry shortly)"
|
|
177
|
+
: "";
|
|
178
|
+
fail(`ElevenLabs API error ${res.status}${hint}: ${detail}`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const audio = Buffer.from(await res.arrayBuffer());
|
|
182
|
+
const mp3 = opts.out || join(mkdtempSync(join(tmpdir(), "draht-speak-")), "speech.mp3");
|
|
183
|
+
await writeFile(mp3, audio);
|
|
184
|
+
|
|
185
|
+
const chars = res.headers.get("x-character-count") || String(text.length);
|
|
186
|
+
console.log(`spoke ${chars} chars · voice ${voice} · model ${model} · ${mp3}`);
|
|
187
|
+
|
|
188
|
+
if (opts.play) {
|
|
189
|
+
const player = findPlayer();
|
|
190
|
+
if (!player) {
|
|
191
|
+
console.error("speak: no audio player found (afplay/mpv/ffplay/mpg123) — audio saved but not played");
|
|
192
|
+
process.exit(2);
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
execFileSync(player.cmd, [...player.args, mp3], { stdio: "ignore" });
|
|
196
|
+
} catch (err) {
|
|
197
|
+
fail(`playback failed via ${player.cmd}: ${err.message}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
main().catch((err) => fail(err?.message || String(err)));
|
|
@@ -8,7 +8,7 @@ description: Draht command prompt wrapper for atomic-commit. Use when the user s
|
|
|
8
8
|
This skill exposes the Draht prompt command template to Codex's `$draht` and `/skills` surfaces.
|
|
9
9
|
|
|
10
10
|
When invoked:
|
|
11
|
-
1. Read
|
|
11
|
+
1. Read `./command.md` in this skill's directory.
|
|
12
12
|
2. Treat the user's text after the skill mention as `$ARGUMENTS`. If the template uses `$1`, use the first positional argument.
|
|
13
13
|
3. Follow that command template as the active workflow.
|
|
14
14
|
4. Use Draht support skills such as `atomic-reasoning`, `tdd-workflow`, `verification-gate`, or `debugging-workflow` when the command template calls for that discipline.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Analyze uncommitted changes and create atomic conventional commits (one logical change per commit)
|
|
3
|
+
allowed-tools: Bash, Read, Task
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /atomic-commit
|
|
7
|
+
|
|
8
|
+
Analyze changes and create atomic commits.
|
|
9
|
+
|
|
10
|
+
## Red Flags — STOP
|
|
11
|
+
|
|
12
|
+
Do NOT proceed with a commit if **any** of these is true:
|
|
13
|
+
|
|
14
|
+
- A single proposed commit mixes unrelated concerns (e.g., a feature + an unrelated refactor + a config tweak)
|
|
15
|
+
- The change set contains potential secrets (`.env`, credentials, API keys in source)
|
|
16
|
+
- Staged content includes files unrelated to the user's stated intent (stale build artifacts, IDE configs, scratch files)
|
|
17
|
+
- Pre-commit hooks fail — fix the cause, never use `--no-verify`
|
|
18
|
+
- You cannot articulate the "why" of a commit in one sentence — that's a sign it contains more than one logical change
|
|
19
|
+
|
|
20
|
+
If any of these triggers, surface the issue to the user and split the change set before continuing.
|
|
21
|
+
|
|
22
|
+
## Atomic Reasoning
|
|
23
|
+
|
|
24
|
+
Decompose the work into independently verifiable units before acting; the `atomic-reasoning` skill holds the full discipline — load it when the decomposition is not obvious.
|
|
25
|
+
|
|
26
|
+
## Gathering Current State
|
|
27
|
+
|
|
28
|
+
First, gather the current state:
|
|
29
|
+
|
|
30
|
+
1. Run `git status` to see what changed
|
|
31
|
+
2. Run `git diff` to see unstaged changes
|
|
32
|
+
3. Run `git diff --cached` to see staged changes
|
|
33
|
+
|
|
34
|
+
## Strategy
|
|
35
|
+
|
|
36
|
+
Based on the changes, analyze and group them into logical, ATOMIC commits. Each commit should:
|
|
37
|
+
|
|
38
|
+
1. Contain ONE logical change only
|
|
39
|
+
2. Be self-contained and complete
|
|
40
|
+
3. Not break the build if applied independently
|
|
41
|
+
|
|
42
|
+
You may delegate this work to the `git-committer` subagent via Codex subagents with ``git-committer` agent prompt` if the change set is large or spans multiple areas. The git-committer will review diffs, group changes, and create commits with conventional commit messages.
|
|
43
|
+
|
|
44
|
+
For each group of changes you identify:
|
|
45
|
+
- List the specific files that belong together
|
|
46
|
+
- Generate a clear, descriptive commit message following conventional commits format
|
|
47
|
+
- Explain WHY these changes belong in one commit
|
|
48
|
+
|
|
49
|
+
Then execute the `git add <specific-files>` and `git commit` commands for each atomic commit in the order they should be applied.
|
|
50
|
+
|
|
51
|
+
Format each commit message as:
|
|
52
|
+
```
|
|
53
|
+
type(scope): brief description
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Common types: feat, fix, refactor, docs, test, chore, style, perf. For strict TDD cycles, also use `red:`, `green:`, `refactor:`.
|
|
57
|
+
|
|
58
|
+
## Rules
|
|
59
|
+
- NEVER use `git add -A` or `git add .` — always stage specific files
|
|
60
|
+
- NEVER use `git commit --no-verify`
|
|
61
|
+
- NEVER force push
|
|
62
|
+
- Review diffs before committing to ensure nothing unexpected is staged
|