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
package/bin/judge
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""judge — swipe through open decisions across every agent session on this machine.
|
|
3
|
+
|
|
4
|
+
judge open the TUI in this terminal
|
|
5
|
+
judge open open the TUI in a new cmux split (right)
|
|
6
|
+
judge list print the open queue and exit
|
|
7
|
+
judge gates print the gate ledger and kill-rate trend
|
|
8
|
+
judge clear expire every open card
|
|
9
|
+
|
|
10
|
+
Keys: →/l approve ←/h reject c comment then swipe s skip
|
|
11
|
+
u undo last j/k scroll ? help q quit
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import curses
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
import textwrap
|
|
18
|
+
import threading
|
|
19
|
+
import time
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
|
|
22
|
+
HERE = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
|
|
23
|
+
sys.path.insert(0, os.path.join(HERE, "..", "scripts"))
|
|
24
|
+
import judgegates as G # noqa: E402
|
|
25
|
+
import judgelib as J # noqa: E402
|
|
26
|
+
|
|
27
|
+
REFRESH = 1.0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# --------------------------------------------------------------------------- #
|
|
31
|
+
# helpers
|
|
32
|
+
# --------------------------------------------------------------------------- #
|
|
33
|
+
|
|
34
|
+
def age(ts):
|
|
35
|
+
s = int(time.time() - ts)
|
|
36
|
+
if s < 60:
|
|
37
|
+
return f"{s}s"
|
|
38
|
+
if s < 3600:
|
|
39
|
+
return f"{s // 60}m"
|
|
40
|
+
if s < 86400:
|
|
41
|
+
return f"{s // 3600}h{(s % 3600) // 60:02d}"
|
|
42
|
+
return f"{s // 86400}d"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def wrap(text, width):
|
|
46
|
+
lines = []
|
|
47
|
+
for para in (text or "").splitlines() or [""]:
|
|
48
|
+
if not para.strip():
|
|
49
|
+
lines.append("")
|
|
50
|
+
continue
|
|
51
|
+
lines.extend(textwrap.wrap(para, width, replace_whitespace=False,
|
|
52
|
+
drop_whitespace=False, break_long_words=True) or [""])
|
|
53
|
+
return lines
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def heartbeat_loop(stop_evt):
|
|
57
|
+
while not stop_evt.is_set():
|
|
58
|
+
try:
|
|
59
|
+
J.beat()
|
|
60
|
+
except Exception:
|
|
61
|
+
pass
|
|
62
|
+
stop_evt.wait(1.0)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# --------------------------------------------------------------------------- #
|
|
66
|
+
# colours
|
|
67
|
+
# --------------------------------------------------------------------------- #
|
|
68
|
+
|
|
69
|
+
C = {}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def init_colours():
|
|
73
|
+
curses.start_color()
|
|
74
|
+
curses.use_default_colors()
|
|
75
|
+
pairs = {
|
|
76
|
+
"dim": 245, "blue": 75, "cyan": 80, "green": 114, "yellow": 179,
|
|
77
|
+
"red": 203, "magenta": 176, "white": 255,
|
|
78
|
+
}
|
|
79
|
+
for i, (name, fg) in enumerate(pairs.items(), start=1):
|
|
80
|
+
curses.init_pair(i, fg, -1)
|
|
81
|
+
C[name] = curses.color_pair(i)
|
|
82
|
+
curses.init_pair(20, 235, 114)
|
|
83
|
+
C["ok_bg"] = curses.color_pair(20)
|
|
84
|
+
curses.init_pair(21, 235, 203)
|
|
85
|
+
C["no_bg"] = curses.color_pair(21)
|
|
86
|
+
curses.init_pair(22, 235, 179)
|
|
87
|
+
C["warn_bg"] = curses.color_pair(22)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# --------------------------------------------------------------------------- #
|
|
91
|
+
# TUI
|
|
92
|
+
# --------------------------------------------------------------------------- #
|
|
93
|
+
|
|
94
|
+
class Judge:
|
|
95
|
+
def __init__(self, scr):
|
|
96
|
+
self.scr = scr
|
|
97
|
+
self.queue = []
|
|
98
|
+
self.idx = 0
|
|
99
|
+
self.scroll = 0
|
|
100
|
+
self.last_load = 0
|
|
101
|
+
self.flash = ("", 0)
|
|
102
|
+
self.history = [] # decided card ids this run
|
|
103
|
+
self.skipped = set()
|
|
104
|
+
self.drafts = {} # card id → comment typed but not yet swiped
|
|
105
|
+
|
|
106
|
+
# ---- data ----
|
|
107
|
+
def load(self, force=False):
|
|
108
|
+
if not force and time.time() - self.last_load < REFRESH:
|
|
109
|
+
return
|
|
110
|
+
self.last_load = time.time()
|
|
111
|
+
J.gc()
|
|
112
|
+
cards = J.open_cards()
|
|
113
|
+
# keep skipped cards at the back
|
|
114
|
+
cards.sort(key=lambda c: c["id"] in self.skipped)
|
|
115
|
+
cur_id = self.current()["id"] if self.current() else None
|
|
116
|
+
self.queue = cards
|
|
117
|
+
if cur_id:
|
|
118
|
+
for i, c in enumerate(self.queue):
|
|
119
|
+
if c["id"] == cur_id:
|
|
120
|
+
self.idx = i
|
|
121
|
+
break
|
|
122
|
+
else:
|
|
123
|
+
self.idx = 0
|
|
124
|
+
self.scroll = 0
|
|
125
|
+
self.idx = min(self.idx, max(0, len(self.queue) - 1))
|
|
126
|
+
|
|
127
|
+
def current(self):
|
|
128
|
+
return self.queue[self.idx] if self.queue else None
|
|
129
|
+
|
|
130
|
+
def say(self, msg, ttl=2.5):
|
|
131
|
+
self.flash = (msg, time.time() + ttl)
|
|
132
|
+
|
|
133
|
+
# ---- drawing ----
|
|
134
|
+
def put(self, y, x, s, attr=0):
|
|
135
|
+
h, w = self.scr.getmaxyx()
|
|
136
|
+
if 0 <= y < h and x < w:
|
|
137
|
+
try:
|
|
138
|
+
self.scr.addnstr(y, x, s, max(0, w - x - 1), attr)
|
|
139
|
+
except curses.error:
|
|
140
|
+
pass
|
|
141
|
+
|
|
142
|
+
def draw(self, x_off=0):
|
|
143
|
+
scr = self.scr
|
|
144
|
+
scr.erase()
|
|
145
|
+
h, w = scr.getmaxyx()
|
|
146
|
+
perms = sum(1 for c in self.queue if c["kind"] in J.BLOCKING_KINDS)
|
|
147
|
+
sessions = len({c["session_id"] for c in self.queue})
|
|
148
|
+
|
|
149
|
+
# header
|
|
150
|
+
self.put(0, 1, "judge", curses.A_BOLD | C["blue"])
|
|
151
|
+
stat = f" {len(self.queue)} open"
|
|
152
|
+
if perms:
|
|
153
|
+
stat += f" · {perms} blocking"
|
|
154
|
+
stat += f" · {sessions} session{'s' if sessions != 1 else ''}"
|
|
155
|
+
self.put(0, 7, stat, C["dim"])
|
|
156
|
+
clock = datetime.now().strftime("%H:%M")
|
|
157
|
+
self.put(0, w - len(clock) - 1, clock, C["dim"])
|
|
158
|
+
|
|
159
|
+
card = self.current()
|
|
160
|
+
if not card:
|
|
161
|
+
msg = "nothing to judge — sessions will feed cards here as they work"
|
|
162
|
+
self.put(h // 2, max(1, (w - len(msg)) // 2), msg, C["dim"])
|
|
163
|
+
self.footer()
|
|
164
|
+
return
|
|
165
|
+
|
|
166
|
+
# card frame
|
|
167
|
+
cw = min(w - 4, 100)
|
|
168
|
+
cx = max(1, (w - cw) // 2) + x_off
|
|
169
|
+
top, bottom = 2, h - 3
|
|
170
|
+
inner = cw - 4
|
|
171
|
+
|
|
172
|
+
conclusion = (m0 := card.get("meta") or {}).get("verify", {}).get("conclusion", "")
|
|
173
|
+
if card["kind"] == "permission":
|
|
174
|
+
kind_attr, kind_txt = C["warn_bg"], " PERMISSION "
|
|
175
|
+
elif card["kind"] == "gate":
|
|
176
|
+
kind_attr = C["no_bg"] if conclusion in ("not-a-gate", "rubber-stamp") else C["warn_bg"]
|
|
177
|
+
kind_txt = f" GATE · {m0.get('stage', '?').upper()} "
|
|
178
|
+
else:
|
|
179
|
+
kind_attr, kind_txt = C["cyan"] | curses.A_REVERSE, " REVIEW "
|
|
180
|
+
self.put(top, cx, "╭" + "─" * (cw - 2) + "╮", C["dim"])
|
|
181
|
+
self.put(top, cx + 2, kind_txt, kind_attr)
|
|
182
|
+
pos = f" {self.idx + 1}/{len(self.queue)} · {age(card['created'])} "
|
|
183
|
+
self.put(top, cx + cw - len(pos) - 2, pos, C["dim"])
|
|
184
|
+
for y in range(top + 1, bottom):
|
|
185
|
+
self.put(y, cx, "│", C["dim"])
|
|
186
|
+
self.put(y, cx + cw - 1, "│", C["dim"])
|
|
187
|
+
self.put(bottom, cx, "╰" + "─" * (cw - 2) + "╯", C["dim"])
|
|
188
|
+
|
|
189
|
+
m = card.get("meta", {})
|
|
190
|
+
y = top + 1
|
|
191
|
+
# where
|
|
192
|
+
where = J.short_dir(card.get("cwd", ""))
|
|
193
|
+
tag = []
|
|
194
|
+
if m.get("branch"):
|
|
195
|
+
tag.append(m["branch"][:40])
|
|
196
|
+
if m.get("slug"):
|
|
197
|
+
tag.append(m["slug"])
|
|
198
|
+
if m.get("model"):
|
|
199
|
+
tag.append(m["model"].replace("claude-", ""))
|
|
200
|
+
self.put(y, cx + 2, where, curses.A_BOLD | C["white"])
|
|
201
|
+
self.put(y, cx + 3 + len(where), " ".join(tag), C["dim"])
|
|
202
|
+
y += 1
|
|
203
|
+
if card["kind"] == "gate":
|
|
204
|
+
title_attr = C["red"] if conclusion in ("not-a-gate", "rubber-stamp") else (
|
|
205
|
+
C["yellow"] if conclusion in ("weak-red", "partial", "timeout", "unrunnable") else C["green"])
|
|
206
|
+
else:
|
|
207
|
+
title_attr = C["yellow"] if card["kind"] == "permission" else C["green"]
|
|
208
|
+
self.put(y, cx + 2, card["title"], curses.A_BOLD | title_attr)
|
|
209
|
+
y += 1
|
|
210
|
+
if m.get("prompt"):
|
|
211
|
+
first = m["prompt"].splitlines()[0][:inner - 6]
|
|
212
|
+
self.put(y, cx + 2, "you » " + first, C["dim"])
|
|
213
|
+
y += 1
|
|
214
|
+
self.put(y, cx + 1, "─" * (cw - 2), C["dim"])
|
|
215
|
+
y += 1
|
|
216
|
+
|
|
217
|
+
# body
|
|
218
|
+
body = []
|
|
219
|
+
if card["kind"] == "gate":
|
|
220
|
+
body += self.gate_body(card, inner)
|
|
221
|
+
elif card["kind"] == "review":
|
|
222
|
+
if m.get("files"):
|
|
223
|
+
body.append(("files", C["magenta"]))
|
|
224
|
+
body += [(" " + J.short_dir(f), C["dim"]) for f in m["files"][:12]]
|
|
225
|
+
if len(m["files"]) > 12:
|
|
226
|
+
body.append((f" … +{len(m['files']) - 12} more", C["dim"]))
|
|
227
|
+
if m.get("bash"):
|
|
228
|
+
body.append(("shell", C["magenta"]))
|
|
229
|
+
body += [(" $ " + b, C["dim"]) for b in m["bash"]]
|
|
230
|
+
if m.get("tools"):
|
|
231
|
+
tools = " ".join(f"{k}×{v}" for k, v in sorted(m["tools"].items(), key=lambda kv: -kv[1]))
|
|
232
|
+
body.append(("tools " + tools, C["dim"]))
|
|
233
|
+
if body:
|
|
234
|
+
body.append(("", 0))
|
|
235
|
+
body.append(("claude said", C["magenta"]))
|
|
236
|
+
body += [(ln, 0) for ln in wrap(card["body"], inner)]
|
|
237
|
+
else:
|
|
238
|
+
body += [(ln, 0) for ln in wrap(card["body"], inner)]
|
|
239
|
+
|
|
240
|
+
avail = bottom - y
|
|
241
|
+
max_scroll = max(0, len(body) - avail)
|
|
242
|
+
self.scroll = min(self.scroll, max_scroll)
|
|
243
|
+
for i, (ln, attr) in enumerate(body[self.scroll:self.scroll + avail]):
|
|
244
|
+
self.put(y + i, cx + 2, ln, attr)
|
|
245
|
+
if max_scroll:
|
|
246
|
+
frac = self.scroll / max_scroll
|
|
247
|
+
self.put(bottom, cx + cw - 12, f" {int(frac * 100):3d}% j/k ", C["dim"])
|
|
248
|
+
|
|
249
|
+
# comment preview
|
|
250
|
+
if self.drafts.get(card["id"]):
|
|
251
|
+
self.put(bottom - 1, cx + 2, ("✎ " + self.drafts[card["id"]])[:inner], C["yellow"])
|
|
252
|
+
|
|
253
|
+
self.footer(card)
|
|
254
|
+
|
|
255
|
+
def gate_body(self, card, inner):
|
|
256
|
+
"""The evidence, then the test. The evidence is why the human is here."""
|
|
257
|
+
m = card.get("meta", {})
|
|
258
|
+
v = m.get("verify") or {}
|
|
259
|
+
rows = []
|
|
260
|
+
|
|
261
|
+
if m.get("claims"):
|
|
262
|
+
rows.append(("claim", C["magenta"]))
|
|
263
|
+
rows += [(" " + c[:inner - 4], 0) for c in m["claims"][:6]]
|
|
264
|
+
if len(m["claims"]) > 6:
|
|
265
|
+
rows.append((f" … +{len(m['claims']) - 6} more", C["dim"]))
|
|
266
|
+
rows.append(("", 0))
|
|
267
|
+
|
|
268
|
+
rows.append(("evidence", C["magenta"]))
|
|
269
|
+
status = v.get("status")
|
|
270
|
+
if status == "running":
|
|
271
|
+
rows.append((" replaying the test against the code as it stands…", C["yellow"]))
|
|
272
|
+
elif status == "error":
|
|
273
|
+
rows.append((f" could not replay: {v.get('error', '')}"[:inner], C["red"]))
|
|
274
|
+
|
|
275
|
+
for run in v.get("runs", []):
|
|
276
|
+
label = {"assertion": "fails on an assertion", "error": "fails on an import/compile error",
|
|
277
|
+
"pass": "PASSES without the implementation", "timeout": "timed out",
|
|
278
|
+
"unrunnable": "no runnable test command"}.get(run["verdict"], run["verdict"])
|
|
279
|
+
attr = C["green"] if run["verdict"] == "assertion" else (
|
|
280
|
+
C["red"] if run["verdict"] == "pass" else C["yellow"])
|
|
281
|
+
rows.append((f" {J.short_dir(run['file'])}", C["dim"]))
|
|
282
|
+
rows.append((f" {label}", attr))
|
|
283
|
+
if run.get("command"):
|
|
284
|
+
rows.append((f" $ {run['command']}"[:inner], C["dim"]))
|
|
285
|
+
|
|
286
|
+
if v.get("stage") == "green":
|
|
287
|
+
scored, killed = v.get("scored", 0), v.get("killed", 0)
|
|
288
|
+
attr = C["green"] if scored and killed == scored else (C["red"] if killed == 0 else C["yellow"])
|
|
289
|
+
rows.append((f" mutations caught {killed}/{scored}", attr))
|
|
290
|
+
for mutant in v.get("mutants", []):
|
|
291
|
+
if mutant.get("invalid"):
|
|
292
|
+
continue
|
|
293
|
+
mark, mattr = ("killed", C["dim"]) if mutant["killed"] else ("SURVIVED", C["red"])
|
|
294
|
+
rows.append((f" {mark:>8} {mutant['file']}:{mutant['line']} {mutant['op']}"[:inner], mattr))
|
|
295
|
+
if not mutant["killed"]:
|
|
296
|
+
rows.append((f" still passed with: {mutant['after']}"[:inner], C["dim"]))
|
|
297
|
+
if v.get("note"):
|
|
298
|
+
rows.append((" " + v["note"], C["dim"]))
|
|
299
|
+
|
|
300
|
+
if m.get("smells"):
|
|
301
|
+
rows.append(("", 0))
|
|
302
|
+
rows.append(("smells", C["magenta"]))
|
|
303
|
+
for smell in m["smells"]:
|
|
304
|
+
rows.append((f" {smell['code']}", C["red"]))
|
|
305
|
+
rows += [(" " + ln, C["dim"]) for ln in wrap(smell["note"], inner - 6)]
|
|
306
|
+
|
|
307
|
+
if m.get("next_edit"):
|
|
308
|
+
rows.append(("", 0))
|
|
309
|
+
rows.append((f"held before editing {m['next_edit']}"[:inner], C["dim"]))
|
|
310
|
+
|
|
311
|
+
rows.append(("", 0))
|
|
312
|
+
rows.append(("the test", C["magenta"]))
|
|
313
|
+
rows += [(ln, 0) for ln in wrap(card["body"], inner)]
|
|
314
|
+
return rows
|
|
315
|
+
|
|
316
|
+
def footer(self, card=None):
|
|
317
|
+
h, w = self.scr.getmaxyx()
|
|
318
|
+
if card and card["kind"] == "permission":
|
|
319
|
+
left, right = "← deny", "allow →"
|
|
320
|
+
elif card and card["kind"] == "gate":
|
|
321
|
+
left, right = "← weak gate", "real gate →"
|
|
322
|
+
else:
|
|
323
|
+
left, right = "← reject", "approve →"
|
|
324
|
+
keys = [(left, C["red"]), (" c comment", C["dim"]), (" s skip", C["dim"]), (" u undo", C["dim"]),
|
|
325
|
+
(" ? help", C["dim"]), (" q quit", C["dim"])]
|
|
326
|
+
x = 1
|
|
327
|
+
for txt, attr in keys:
|
|
328
|
+
self.put(h - 1, x, txt, attr | curses.A_BOLD if attr == C["red"] else attr)
|
|
329
|
+
x += len(txt)
|
|
330
|
+
self.put(h - 1, w - len(right) - 1, right, C["green"] | curses.A_BOLD)
|
|
331
|
+
msg, until = self.flash
|
|
332
|
+
if msg and time.time() < until:
|
|
333
|
+
self.put(h - 2, max(1, (w - len(msg)) // 2), msg, C["yellow"] | curses.A_BOLD)
|
|
334
|
+
|
|
335
|
+
def swipe_anim(self, direction, label, attr):
|
|
336
|
+
h, w = self.scr.getmaxyx()
|
|
337
|
+
for step in range(1, 7):
|
|
338
|
+
self.draw(x_off=direction * step * max(2, w // 24))
|
|
339
|
+
self.put(h // 2, max(1, (w - len(label)) // 2), f" {label} ", attr | curses.A_BOLD)
|
|
340
|
+
self.scr.refresh()
|
|
341
|
+
time.sleep(0.03)
|
|
342
|
+
|
|
343
|
+
# ---- input ----
|
|
344
|
+
def read_line(self, prompt, initial=""):
|
|
345
|
+
h, w = self.scr.getmaxyx()
|
|
346
|
+
curses.curs_set(1)
|
|
347
|
+
self.scr.timeout(-1) # block while typing; the 1s refresh timeout would raise "no input"
|
|
348
|
+
buf = list(initial)
|
|
349
|
+
while True:
|
|
350
|
+
self.put(h - 2, 0, " " * (w - 1))
|
|
351
|
+
self.put(h - 1, 0, " " * (w - 1))
|
|
352
|
+
self.put(h - 2, 1, prompt, C["yellow"] | curses.A_BOLD)
|
|
353
|
+
shown = "".join(buf)[-(w - 3):]
|
|
354
|
+
self.put(h - 1, 1, shown)
|
|
355
|
+
self.scr.move(h - 1, min(w - 2, 1 + len(shown)))
|
|
356
|
+
self.scr.refresh()
|
|
357
|
+
try:
|
|
358
|
+
ch = self.scr.get_wch()
|
|
359
|
+
except curses.error:
|
|
360
|
+
continue
|
|
361
|
+
if ch in ("\n", "\r", curses.KEY_ENTER):
|
|
362
|
+
break
|
|
363
|
+
if ch == "\x1b":
|
|
364
|
+
buf = None
|
|
365
|
+
break
|
|
366
|
+
if ch in (curses.KEY_BACKSPACE, "\x7f", "\b"):
|
|
367
|
+
if buf:
|
|
368
|
+
buf.pop()
|
|
369
|
+
elif ch == "\x15": # ctrl-u
|
|
370
|
+
buf = []
|
|
371
|
+
elif isinstance(ch, str) and ch.isprintable():
|
|
372
|
+
buf.append(ch)
|
|
373
|
+
curses.curs_set(0)
|
|
374
|
+
self.scr.timeout(int(REFRESH * 1000))
|
|
375
|
+
return None if buf is None else "".join(buf).strip()
|
|
376
|
+
|
|
377
|
+
def decide(self, verdict):
|
|
378
|
+
card = self.current()
|
|
379
|
+
if not card:
|
|
380
|
+
return
|
|
381
|
+
comment = self.drafts.pop(card["id"], "")
|
|
382
|
+
labels = {"permission": ("ALLOW", "DENY"), "gate": ("REAL GATE", "WEAK GATE")}
|
|
383
|
+
yes, no = labels.get(card["kind"], ("APPROVE", "REJECT"))
|
|
384
|
+
if verdict == "approve":
|
|
385
|
+
self.swipe_anim(+1, yes, C["ok_bg"])
|
|
386
|
+
else:
|
|
387
|
+
self.swipe_anim(-1, no, C["no_bg"])
|
|
388
|
+
J.decide(card, verdict, comment)
|
|
389
|
+
self.history.append(card["id"])
|
|
390
|
+
if card["kind"] == "gate":
|
|
391
|
+
# The waiting hook writes the ledger for gates it decides itself; a
|
|
392
|
+
# human decision is recorded here, at the moment it is made.
|
|
393
|
+
G.append_ledger(J.load_card(card["id"]) or card)
|
|
394
|
+
note = "sent to session" if card["kind"] == "review" and (verdict == "reject" or comment) else ""
|
|
395
|
+
self.say(f"{verdict}{' · ' + note if note else ''}", 1.5)
|
|
396
|
+
self.scroll = 0
|
|
397
|
+
self.load(force=True)
|
|
398
|
+
|
|
399
|
+
def comment(self):
|
|
400
|
+
card = self.current()
|
|
401
|
+
if not card:
|
|
402
|
+
return
|
|
403
|
+
text = self.read_line("comment (enter to keep, esc to cancel) — then swipe ← / →", self.drafts.get(card["id"], ""))
|
|
404
|
+
if text is None:
|
|
405
|
+
return
|
|
406
|
+
self.drafts[card["id"]] = text
|
|
407
|
+
self.say("comment set — now swipe", 3)
|
|
408
|
+
|
|
409
|
+
def undo(self):
|
|
410
|
+
if not self.history:
|
|
411
|
+
self.say("nothing to undo")
|
|
412
|
+
return
|
|
413
|
+
card = J.load_card(self.history[-1])
|
|
414
|
+
if not card:
|
|
415
|
+
self.history.pop()
|
|
416
|
+
self.say("card gone")
|
|
417
|
+
return
|
|
418
|
+
ok, note = J.undo(card)
|
|
419
|
+
if ok:
|
|
420
|
+
self.history.pop()
|
|
421
|
+
self.load(force=True)
|
|
422
|
+
for i, c in enumerate(self.queue):
|
|
423
|
+
if c["id"] == card["id"]:
|
|
424
|
+
self.idx = i
|
|
425
|
+
break
|
|
426
|
+
self.say(note, 4)
|
|
427
|
+
|
|
428
|
+
def skip(self):
|
|
429
|
+
card = self.current()
|
|
430
|
+
if not card:
|
|
431
|
+
return
|
|
432
|
+
self.skipped.add(card["id"])
|
|
433
|
+
self.scroll = 0
|
|
434
|
+
self.load(force=True)
|
|
435
|
+
self.say("skipped to back", 1)
|
|
436
|
+
|
|
437
|
+
def help(self):
|
|
438
|
+
h, w = self.scr.getmaxyx()
|
|
439
|
+
lines = [
|
|
440
|
+
"judge — human judgment queue",
|
|
441
|
+
"",
|
|
442
|
+
"GATE cards are the point: a test the session just wrote, replayed",
|
|
443
|
+
"against the code to show whether it can actually fail. RED means the",
|
|
444
|
+
"implementation is still unwritten; GREEN means mutations were run.",
|
|
445
|
+
" → / l real gate ← / h weak gate → the session is",
|
|
446
|
+
" held and must strengthen the test before writing the code",
|
|
447
|
+
"PERMISSION cards block a session until you swipe.",
|
|
448
|
+
" → / l allow the tool call ← / h deny (your comment is the reason)",
|
|
449
|
+
"REVIEW cards summarise a finished turn.",
|
|
450
|
+
" → / l approve (comment optional) ← / h reject → comment lands in that",
|
|
451
|
+
" session on its next prompt/turn, which must address it",
|
|
452
|
+
"",
|
|
453
|
+
" c write a comment, then swipe s skip card to the back",
|
|
454
|
+
" u undo last decision (review cards; pulls back or retracts feedback)",
|
|
455
|
+
" j/k scroll body r reload q quit",
|
|
456
|
+
"",
|
|
457
|
+
"`judge gates` prints the kill-rate trend from every decided gate.",
|
|
458
|
+
"Closing judge hands pending prompts and gates back to their sessions.",
|
|
459
|
+
"any key to close",
|
|
460
|
+
]
|
|
461
|
+
self.scr.erase()
|
|
462
|
+
for i, ln in enumerate(lines):
|
|
463
|
+
self.put(h // 2 - len(lines) // 2 + i, max(1, (w - 78) // 2), ln, curses.A_BOLD if i == 0 else 0)
|
|
464
|
+
self.scr.refresh()
|
|
465
|
+
self.scr.timeout(-1)
|
|
466
|
+
self.scr.getch()
|
|
467
|
+
self.scr.timeout(int(REFRESH * 1000))
|
|
468
|
+
|
|
469
|
+
def run(self):
|
|
470
|
+
curses.curs_set(0)
|
|
471
|
+
self.scr.keypad(True)
|
|
472
|
+
self.scr.timeout(int(REFRESH * 1000))
|
|
473
|
+
self.load(force=True)
|
|
474
|
+
while True:
|
|
475
|
+
self.load()
|
|
476
|
+
self.draw()
|
|
477
|
+
self.scr.refresh()
|
|
478
|
+
try:
|
|
479
|
+
ch = self.scr.getch()
|
|
480
|
+
except KeyboardInterrupt:
|
|
481
|
+
return
|
|
482
|
+
if ch == -1:
|
|
483
|
+
continue
|
|
484
|
+
if ch in (ord("q"), 27):
|
|
485
|
+
return
|
|
486
|
+
if ch in (curses.KEY_RIGHT, ord("l"), ord("L")):
|
|
487
|
+
self.decide("approve")
|
|
488
|
+
elif ch in (curses.KEY_LEFT, ord("h"), ord("H")):
|
|
489
|
+
self.decide("reject")
|
|
490
|
+
elif ch == ord("c"):
|
|
491
|
+
self.comment()
|
|
492
|
+
elif ch == ord("s"):
|
|
493
|
+
self.skip()
|
|
494
|
+
elif ch == ord("u"):
|
|
495
|
+
self.undo()
|
|
496
|
+
elif ch in (ord("j"), curses.KEY_DOWN):
|
|
497
|
+
self.scroll += 1
|
|
498
|
+
elif ch in (ord("k"), curses.KEY_UP):
|
|
499
|
+
self.scroll = max(0, self.scroll - 1)
|
|
500
|
+
elif ch == ord(" ") or ch == curses.KEY_NPAGE:
|
|
501
|
+
self.scroll += 10
|
|
502
|
+
elif ch == curses.KEY_PPAGE:
|
|
503
|
+
self.scroll = max(0, self.scroll - 10)
|
|
504
|
+
elif ch == ord("r"):
|
|
505
|
+
self.load(force=True)
|
|
506
|
+
elif ch == ord("?"):
|
|
507
|
+
self.help()
|
|
508
|
+
elif ch == curses.KEY_RESIZE:
|
|
509
|
+
pass
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def tui():
|
|
513
|
+
sys.stdout.write("\033]0;judge\007") # pane / tab title
|
|
514
|
+
sys.stdout.flush()
|
|
515
|
+
stop_evt = threading.Event()
|
|
516
|
+
J.beat()
|
|
517
|
+
t = threading.Thread(target=heartbeat_loop, args=(stop_evt,), daemon=True)
|
|
518
|
+
t.start()
|
|
519
|
+
try:
|
|
520
|
+
curses.wrapper(lambda scr: (init_colours(), Judge(scr).run()))
|
|
521
|
+
finally:
|
|
522
|
+
stop_evt.set()
|
|
523
|
+
try:
|
|
524
|
+
J.HEARTBEAT.unlink()
|
|
525
|
+
except OSError:
|
|
526
|
+
pass
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def cmd_open():
|
|
530
|
+
"""Pop a cmux split to the right and start the TUI in it."""
|
|
531
|
+
import re
|
|
532
|
+
import shutil
|
|
533
|
+
import subprocess
|
|
534
|
+
cmux = shutil.which("cmux") or "/Applications/cmux.app/Contents/Resources/bin/cmux"
|
|
535
|
+
if not os.path.exists(cmux):
|
|
536
|
+
print("judge: cmux CLI not found — run `judge` in another terminal pane instead")
|
|
537
|
+
return 1
|
|
538
|
+
if J.tui_alive():
|
|
539
|
+
print("judge: already running")
|
|
540
|
+
return 0
|
|
541
|
+
res = subprocess.run([cmux, "new-split", "right", "--focus", "true"], capture_output=True, text=True)
|
|
542
|
+
m = re.search(r"surface:\d+", res.stdout + res.stderr)
|
|
543
|
+
if res.returncode != 0 or not m:
|
|
544
|
+
print(f"judge: cmux new-split failed: {(res.stdout + res.stderr).strip()}")
|
|
545
|
+
return 1
|
|
546
|
+
subprocess.run([cmux, "send", "--surface", m.group(0), f"clear; {os.path.realpath(__file__)}\n"], check=False)
|
|
547
|
+
print(f"judge: opened in cmux {m.group(0)}")
|
|
548
|
+
return 0
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
def cmd_list():
|
|
552
|
+
cards = J.open_cards()
|
|
553
|
+
if not cards:
|
|
554
|
+
print("judge: queue empty")
|
|
555
|
+
return
|
|
556
|
+
for c in cards:
|
|
557
|
+
print(f"{c['kind']:<10} {age(c['created']):>5} {J.short_dir(c['cwd']):<28} {c['title']}")
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
def cmd_gates(limit=25):
|
|
561
|
+
"""The gate ledger: what was judged, what the machine found, how it went."""
|
|
562
|
+
records = G.read_ledger()
|
|
563
|
+
if not records:
|
|
564
|
+
print("judge: no gates judged yet")
|
|
565
|
+
return
|
|
566
|
+
human = [r for r in records if not r.get("auto")]
|
|
567
|
+
weak = [r for r in records if r["verdict"] == "reject"]
|
|
568
|
+
scored = [r for r in records if r.get("scored")]
|
|
569
|
+
killed = sum(r.get("killed") or 0 for r in scored)
|
|
570
|
+
total = sum(r.get("scored") or 0 for r in scored)
|
|
571
|
+
print(f"judge gates — {len(records)} judged ({len(human)} by hand, "
|
|
572
|
+
f"{len(records) - len(human)} auto-denied), {len(weak)} called weak")
|
|
573
|
+
if total:
|
|
574
|
+
print(f"mutation kill rate across {len(scored)} scored gate(s): {killed}/{total}"
|
|
575
|
+
f" ({100 * killed // total}%)")
|
|
576
|
+
smells = {}
|
|
577
|
+
for record in records:
|
|
578
|
+
for code in record.get("smells", []):
|
|
579
|
+
smells[code] = smells.get(code, 0) + 1
|
|
580
|
+
if smells:
|
|
581
|
+
print("smells: " + " ".join(f"{k}×{v}" for k, v in sorted(smells.items(), key=lambda kv: -kv[1])))
|
|
582
|
+
print()
|
|
583
|
+
for record in records[-limit:]:
|
|
584
|
+
when = datetime.fromtimestamp(record["ts"]).strftime("%m-%d %H:%M")
|
|
585
|
+
mark = "weak" if record["verdict"] == "reject" else "real"
|
|
586
|
+
score = f"{record['killed']}/{record['scored']}" if record.get("scored") else "—"
|
|
587
|
+
claim = (record["claims"] or record["files"] or [""])[0]
|
|
588
|
+
print(f"{when} {record['stage']:<5} {mark:<4} {score:>5} "
|
|
589
|
+
f"{record.get('conclusion', ''):<12} {record['repo']:<16} {claim[:44]}")
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def cmd_clear():
|
|
593
|
+
n = 0
|
|
594
|
+
for c in J.open_cards():
|
|
595
|
+
J.expire(c)
|
|
596
|
+
n += 1
|
|
597
|
+
print(f"judge: expired {n} card(s)")
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
if __name__ == "__main__":
|
|
601
|
+
arg = sys.argv[1] if len(sys.argv) > 1 else ""
|
|
602
|
+
if arg in ("-h", "--help", "help"):
|
|
603
|
+
print(__doc__)
|
|
604
|
+
elif arg == "open":
|
|
605
|
+
sys.exit(cmd_open())
|
|
606
|
+
elif arg == "list":
|
|
607
|
+
cmd_list()
|
|
608
|
+
elif arg == "clear":
|
|
609
|
+
cmd_clear()
|
|
610
|
+
elif arg == "gates":
|
|
611
|
+
cmd_gates()
|
|
612
|
+
else:
|
|
613
|
+
tui()
|