@popovych.co/witness 0.26.0 → 0.26.2
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/README.md +1 -1
- package/dist/arbiter.js +2 -2
- package/dist/awake.js +18 -6
- package/dist/drive-presence.js +11 -5
- package/dist/drive.js +275 -43
- package/dist/harness.js +35 -6
- package/dist/opener.js +19 -12
- package/dist/recommend.js +6 -2
- package/dist/reviewer.js +1 -1
- package/dist/rounds.js +14 -3
- package/dist/session-clock.js +5 -0
- package/dist/toon.js +19 -2
- package/dist/usage.js +5 -2
- package/dist/verbs/log.js +5 -4
- package/dist/worker-stream.js +447 -0
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/witness.md +1 -1
- package/plugin/hooks/session-dashboard.sh +1 -1
- package/plugin/skills/witness-brainstorm/SKILL.md +1 -1
- package/plugin/skills/witness-decompose/SKILL.md +1 -1
- package/plugin/skills/witness-design/SKILL.md +1 -1
- package/plugin/skills/witness-implement/SKILL.md +1 -1
- package/plugin/skills/witness-plan/SKILL.md +1 -1
- package/plugin/skills/witness-ship/SKILL.md +1 -1
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { logSafe } from './toon.js';
|
|
2
|
+
// One action line is one terminal line: a heredoc or a 40 KB `Write` must not flood the log.
|
|
3
|
+
export const ACTION_MAX = 160;
|
|
4
|
+
// A record that is no event — a warning a harness printed, half a record — is shown as written,
|
|
5
|
+
// up to this many code points: one that runs to megabytes is still one line.
|
|
6
|
+
export const PASSTHROUGH_MAX = 400;
|
|
7
|
+
// The verbs a human reads at a glance, by lower-cased tool name — claude's `Read` and pi's `read`
|
|
8
|
+
// are one action. `path` marks an argument shown relative to the session's home. A Map, so a tool
|
|
9
|
+
// named `constructor` or `__proto__` is any other tool, never one of Object's own keys.
|
|
10
|
+
const ACTIONS = new Map([
|
|
11
|
+
['bash', { verb: '$', keys: ['command'] }],
|
|
12
|
+
['powershell', { verb: '$', keys: ['command'] }],
|
|
13
|
+
['read', { verb: 'read', keys: ['path', 'file_path'], path: true }],
|
|
14
|
+
['edit', { verb: 'edit', keys: ['path', 'file_path'], path: true }],
|
|
15
|
+
['multiedit', { verb: 'edit', keys: ['path', 'file_path'], path: true }],
|
|
16
|
+
['notebookedit', { verb: 'edit', keys: ['notebook_path'], path: true }],
|
|
17
|
+
['write', { verb: 'write', keys: ['path', 'file_path'], path: true }],
|
|
18
|
+
['grep', { verb: 'grep', keys: ['pattern'] }],
|
|
19
|
+
['find', { verb: 'find', keys: ['pattern'] }],
|
|
20
|
+
['glob', { verb: 'find', keys: ['pattern'] }],
|
|
21
|
+
['ls', { verb: 'ls', keys: ['path'], path: true }],
|
|
22
|
+
]);
|
|
23
|
+
const obj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v) ? v : undefined;
|
|
24
|
+
const str = (v) => typeof v === 'string' ? v : undefined;
|
|
25
|
+
// A count or a status as written; anything else is no value. `String()` of an object a record
|
|
26
|
+
// carries could throw (`{"toString": 1}`), so it is never called on one.
|
|
27
|
+
const scalar = (v) => typeof v === 'string' || typeof v === 'number' ? String(v) : undefined;
|
|
28
|
+
const lines = (text) => text.split('\n').map((l) => l.replace(/\r$/, '')).filter((l) => l.trim() !== '');
|
|
29
|
+
// Each index of a command line that sits outside quotes, `$(…)` and `${…}`. Unbalanced text never
|
|
30
|
+
// returns to the top, so a stray quote keeps the rest of the line whole.
|
|
31
|
+
function* topLevel(s) {
|
|
32
|
+
const open = []; // the closer each open context waits for
|
|
33
|
+
for (let i = 0; i < s.length; i++) {
|
|
34
|
+
const c = s[i];
|
|
35
|
+
const closer = open.at(-1);
|
|
36
|
+
if (closer === "'") {
|
|
37
|
+
if (c === "'")
|
|
38
|
+
open.pop();
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (c === '\\') {
|
|
42
|
+
i += 1;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (c === '$' && (s[i + 1] === '(' || s[i + 1] === '{')) {
|
|
46
|
+
open.push(s[i + 1] === '(' ? ')' : '}');
|
|
47
|
+
i += 1;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (closer === '"') {
|
|
51
|
+
if (c === '"')
|
|
52
|
+
open.pop();
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (c === "'" || c === '"') {
|
|
56
|
+
open.push(c);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (closer === ')' && c === '(') {
|
|
60
|
+
open.push(')');
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (closer !== undefined) {
|
|
64
|
+
if (c === closer)
|
|
65
|
+
open.pop();
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
yield i;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// The leading segment of a command line and what follows its separator: an `&&`, `;` or newline
|
|
72
|
+
// at the top level.
|
|
73
|
+
function leading(s) {
|
|
74
|
+
for (const i of topLevel(s)) {
|
|
75
|
+
if (s[i] === '\n' || s[i] === ';')
|
|
76
|
+
return { head: s.slice(0, i), rest: s.slice(i + 1) };
|
|
77
|
+
if (s[i] === '&' && s[i + 1] === '&')
|
|
78
|
+
return { head: s.slice(0, i), rest: s.slice(i + 2) };
|
|
79
|
+
}
|
|
80
|
+
return { head: s, rest: '' };
|
|
81
|
+
}
|
|
82
|
+
function words(s) {
|
|
83
|
+
const out = [];
|
|
84
|
+
let start = 0;
|
|
85
|
+
for (const i of topLevel(s)) {
|
|
86
|
+
if (/\s/.test(s[i])) {
|
|
87
|
+
if (i > start)
|
|
88
|
+
out.push(s.slice(start, i));
|
|
89
|
+
start = i + 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (s.length > start)
|
|
93
|
+
out.push(s.slice(start));
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
// What a command line sets up before the command it runs: `cd <dir>`, `[export ]NAME=<value>`,
|
|
97
|
+
// `set -<flags>[ <words>]` — and nothing, the empty segment an `&&` at a line's end leaves.
|
|
98
|
+
const ASSIGNMENT = /^[A-Za-z_]\w*=/;
|
|
99
|
+
function preamble(segment) {
|
|
100
|
+
const w = words(segment);
|
|
101
|
+
if (w.length === 0)
|
|
102
|
+
return true;
|
|
103
|
+
if (w[0] === 'cd')
|
|
104
|
+
return w.length === 2;
|
|
105
|
+
if (w[0] === 'set')
|
|
106
|
+
return w.length >= 2 && /^[-+][A-Za-z]+$/.test(w[1]);
|
|
107
|
+
if (w[0] === 'export')
|
|
108
|
+
return w.length === 2 && ASSIGNMENT.test(w[1]);
|
|
109
|
+
return w.length === 1 && ASSIGNMENT.test(w[0]);
|
|
110
|
+
}
|
|
111
|
+
const WITNESS_VAR = /"\$\{WITNESS\}"|"\$WITNESS"|\$\{WITNESS\}|\$WITNESS(?!\w)/g;
|
|
112
|
+
// P15: nine in ten of a real implement session's shell calls start `cd <worktree> && WITNESS=…;`,
|
|
113
|
+
// and cut at ACTION_MAX most witness calls lost their verb. The command a call runs is what is
|
|
114
|
+
// left once its leading setup is gone, with the stage skills' `$WITNESS` read as the `witness` it
|
|
115
|
+
// is. A line that is nothing but setup stays as written.
|
|
116
|
+
export function shellCommand(command) {
|
|
117
|
+
let rest = command;
|
|
118
|
+
for (;;) {
|
|
119
|
+
const { head, rest: after } = leading(rest);
|
|
120
|
+
if (!preamble(head))
|
|
121
|
+
break;
|
|
122
|
+
rest = after;
|
|
123
|
+
if (rest.trim() === '')
|
|
124
|
+
return command;
|
|
125
|
+
}
|
|
126
|
+
return rest.trimStart().replace(WITNESS_VAR, 'witness');
|
|
127
|
+
}
|
|
128
|
+
// A path under the session's home, from it. Compared on `/`, and without case under a drive
|
|
129
|
+
// letter, as Windows compares: `C:\R\src\a.rs` is `src/a.rs` in the home `c:/r`.
|
|
130
|
+
function relative(p, home) {
|
|
131
|
+
const h = home.replaceAll('\\', '/').replace(/\/+$/, '');
|
|
132
|
+
const q = p.replaceAll('\\', '/');
|
|
133
|
+
if (h === '')
|
|
134
|
+
return p;
|
|
135
|
+
const fold = /^[A-Za-z]:/.test(h) ? (x) => x.toLowerCase() : (x) => x;
|
|
136
|
+
if (fold(q) === fold(h))
|
|
137
|
+
return '.';
|
|
138
|
+
return q[h.length] === '/' && fold(q.slice(0, h.length)) === fold(h) ? q.slice(h.length + 1) : p;
|
|
139
|
+
}
|
|
140
|
+
// `$ cargo test discovery`, `read src/a.rs`: what a tool call does, in one line. Any other tool is
|
|
141
|
+
// its name and its first string argument (`Task review the diff`). In this order: a shell
|
|
142
|
+
// command loses its setup (shellCommand), only its first line is kept, a path is made relative to
|
|
143
|
+
// the home, the line is spelled out (logSafe), and then cut — so ACTION_MAX bounds what the
|
|
144
|
+
// terminal shows. An action line says what was attempted: a call a guard refused reads the same.
|
|
145
|
+
export function actionLine(tool, args, home) {
|
|
146
|
+
const a = obj(args) ?? {};
|
|
147
|
+
const known = ACTIONS.get(tool.toLowerCase());
|
|
148
|
+
const raw = known !== undefined ? known.keys.map((k) => str(a[k])).find((v) => v !== undefined) : Object.values(a).map(str).find((v) => v !== undefined);
|
|
149
|
+
const arg = raw !== undefined && known?.verb === '$' ? shellCommand(raw) : raw;
|
|
150
|
+
const [first = '', ...rest] = (arg ?? '').split('\n');
|
|
151
|
+
const more = rest.some((l) => l.trim() !== '') ? ' …' : '';
|
|
152
|
+
const head = known?.verb ?? tool;
|
|
153
|
+
const said = first.replace(/\r$/, '');
|
|
154
|
+
const shown = known?.path ? relative(said, home) : said;
|
|
155
|
+
const line = logSafe(shown === '' ? head : `${head} ${shown}${more}`);
|
|
156
|
+
const chars = [...line];
|
|
157
|
+
return chars.length <= ACTION_MAX ? line : `${chars.slice(0, ACTION_MAX - 1).join('')}…`;
|
|
158
|
+
}
|
|
159
|
+
// A record shown as written, spelled out, and cut past PASSTHROUGH_MAX code points with how long
|
|
160
|
+
// it was. Drive shows a record this way too when a renderer it holds fails, and every stderr line.
|
|
161
|
+
export function passthrough(record) {
|
|
162
|
+
const safe = logSafe(record);
|
|
163
|
+
let n = 0;
|
|
164
|
+
let end = 0;
|
|
165
|
+
for (const c of safe) {
|
|
166
|
+
if (n < PASSTHROUGH_MAX)
|
|
167
|
+
end += c.length;
|
|
168
|
+
n += 1;
|
|
169
|
+
}
|
|
170
|
+
return n <= PASSTHROUGH_MAX ? safe : `${safe.slice(0, end)} … (${n} characters)`;
|
|
171
|
+
}
|
|
172
|
+
function parse(record) {
|
|
173
|
+
if (!record.startsWith('{'))
|
|
174
|
+
return undefined;
|
|
175
|
+
try {
|
|
176
|
+
return obj(JSON.parse(record));
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const show = (text) => ({ kind: 'show', text: logSafe(text) });
|
|
183
|
+
const shown = (text) => lines(text).map(show);
|
|
184
|
+
// Heard lines are spelled out too: the merge sniff keeps one, and drive prints what it kept.
|
|
185
|
+
// `strip` takes off what the harness put before each line (claude's Read numbers its lines).
|
|
186
|
+
const heard = (text, strip) => lines(strip === undefined ? text : text.split('\n').map((l) => l.replace(strip, '')).join('\n'))
|
|
187
|
+
.map((l) => ({ kind: 'heard', text: logSafe(l) }));
|
|
188
|
+
// A tool result's text, whichever shape carries it: a string, or `{type: 'text'}` blocks.
|
|
189
|
+
const textOf = (content) => typeof content === 'string' ? content
|
|
190
|
+
: Array.isArray(content) ? content.map(obj).filter((c) => c?.type === 'text').map((c) => str(c?.text) ?? '').join('\n') : '';
|
|
191
|
+
const oldest = (open) => open.values().next().value;
|
|
192
|
+
// The oldest open call that is not in the background, else the oldest one that is: a server an
|
|
193
|
+
// agent left running is not what a call it is waiting on now waits for.
|
|
194
|
+
const oldestForeground = (open, background) => {
|
|
195
|
+
for (const [id, action] of open)
|
|
196
|
+
if (!background.has(id))
|
|
197
|
+
return action;
|
|
198
|
+
return oldest(open);
|
|
199
|
+
};
|
|
200
|
+
// A tool's result is heard and never shown, error or not: both harnesses mark every non-zero exit
|
|
201
|
+
// as a tool error (pi throws "Command exited with code N", claude answers `Exit code 1`), so a
|
|
202
|
+
// `failed` line would fire on every red test run and every grep that found nothing. The action
|
|
203
|
+
// line says what ran, and `journal:` what landed.
|
|
204
|
+
//
|
|
205
|
+
// pi (`pi -p --mode json`): a `session` header, then `tool_execution_start` / `_end` around each
|
|
206
|
+
// call, `message_start` / `message_end` around each message, token deltas, `turn_start` /
|
|
207
|
+
// `turn_end`, `agent_end` carrying the whole conversation, and `auto_retry_start` /
|
|
208
|
+
// `compaction_start`. pi writes an answer's `message_start` only once the provider's stream has
|
|
209
|
+
// begun, so the model is awaited from its turn's start until that answer ends.
|
|
210
|
+
export function piStream(home) {
|
|
211
|
+
const open = new Map(); // toolCallId → action line, oldest first
|
|
212
|
+
let named; // the session id last emitted
|
|
213
|
+
let turn = false; // the model is awaited: a turn started, its answer has not ended
|
|
214
|
+
let stop; // the last assistant message's stopReason
|
|
215
|
+
return {
|
|
216
|
+
line(record) {
|
|
217
|
+
const e = parse(record);
|
|
218
|
+
if (e === undefined)
|
|
219
|
+
return [{ kind: 'show', text: passthrough(record) }];
|
|
220
|
+
switch (e.type) {
|
|
221
|
+
case 'session': {
|
|
222
|
+
const id = str(e.id);
|
|
223
|
+
if (id === undefined || id === named)
|
|
224
|
+
return [];
|
|
225
|
+
named = id;
|
|
226
|
+
return [{ kind: 'session', id }];
|
|
227
|
+
}
|
|
228
|
+
case 'tool_execution_start': {
|
|
229
|
+
const action = actionLine(str(e.toolName) ?? 'tool', e.args, home);
|
|
230
|
+
const id = scalar(e.toolCallId);
|
|
231
|
+
if (id !== undefined)
|
|
232
|
+
open.set(id, action);
|
|
233
|
+
return [{ kind: 'show', text: action }];
|
|
234
|
+
}
|
|
235
|
+
case 'tool_execution_end': {
|
|
236
|
+
const id = scalar(e.toolCallId);
|
|
237
|
+
if (id !== undefined)
|
|
238
|
+
open.delete(id);
|
|
239
|
+
return heard(textOf(obj(e.result)?.content));
|
|
240
|
+
}
|
|
241
|
+
case 'turn_start':
|
|
242
|
+
turn = true;
|
|
243
|
+
return [];
|
|
244
|
+
case 'message_start':
|
|
245
|
+
if (obj(e.message)?.role === 'assistant')
|
|
246
|
+
turn = true;
|
|
247
|
+
return [];
|
|
248
|
+
case 'message_end': {
|
|
249
|
+
const m = obj(e.message);
|
|
250
|
+
if (m?.role !== 'assistant')
|
|
251
|
+
return [];
|
|
252
|
+
turn = false;
|
|
253
|
+
// A later answer that succeeded clears an earlier error: a retry that worked is no failure.
|
|
254
|
+
stop = str(m.stopReason);
|
|
255
|
+
const said = shown(textOf(m.content));
|
|
256
|
+
// What text mode prints on stderr for the same turn, and its exit 1.
|
|
257
|
+
if (stop === 'error' || stop === 'aborted')
|
|
258
|
+
said.push(...shown(str(m.errorMessage) || `Request ${stop}`));
|
|
259
|
+
return said;
|
|
260
|
+
}
|
|
261
|
+
case 'auto_retry_start':
|
|
262
|
+
return [show(`retrying · attempt ${scalar(e.attempt) ?? '?'}/${scalar(e.maxAttempts) ?? '?'} · ${lines(str(e.errorMessage) ?? '')[0] ?? ''}`)];
|
|
263
|
+
case 'compaction_start':
|
|
264
|
+
return [show('compacting context')];
|
|
265
|
+
default:
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
inFlight: () => oldest(open) ?? (turn ? 'the model' : undefined),
|
|
270
|
+
failed: () => stop === 'error' || stop === 'aborted',
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
// claude Read's line numbers, ` 1\t` (P12).
|
|
274
|
+
const READ_NUMBER = /^\s*\d+\t/;
|
|
275
|
+
// The statuses a `task_updated` patch ends a task with.
|
|
276
|
+
const TASK_ENDED = new Set(['completed', 'failed', 'killed']);
|
|
277
|
+
// claude (`claude -p --output-format stream-json --verbose`): `system:init` naming the session,
|
|
278
|
+
// one `assistant` record per content block (thinking, text, tool_use), a `user` record carrying
|
|
279
|
+
// each tool_result, hooks and `rate_limit_event`, `system:api_retry` / `compact_boundary`, and a
|
|
280
|
+
// `result` whose `is_error` is the failure.
|
|
281
|
+
//
|
|
282
|
+
// P12: a command that outruns the Bash limit runs on in the background. Its `task_started` comes
|
|
283
|
+
// before its tool_result, which only says it went to the background; a first `result` follows and
|
|
284
|
+
// the process keeps running; `task_notification` says the command ended, a second `init` names the
|
|
285
|
+
// same session, the agent reads the output file, and a second `result` closes. So a backgrounded
|
|
286
|
+
// call stays open past its tool_result until its task notifies (or a `task_updated` ends it), and
|
|
287
|
+
// there may be several results. P17: claude registers a task for a foreground call too — a
|
|
288
|
+
// subagent, a Bash that has run a while — so only a task marked `is_backgrounded` keeps a call
|
|
289
|
+
// open; claude 2.1.312 moves a Bash that outruns its limit to the background with a
|
|
290
|
+
// `task_updated` whose patch says so (its SDK schema: "A later move to the background arrives as
|
|
291
|
+
// task_updated patch.is_backgrounded"), not with a second `task_started`.
|
|
292
|
+
export function claudeStream(home) {
|
|
293
|
+
const open = new Map(); // tool_use id → action line, oldest first
|
|
294
|
+
const calls = new Map(); // every tool_use id → its action line
|
|
295
|
+
const background = new Set(); // tool_use ids a task runs past their tool_result
|
|
296
|
+
const tasks = new Map(); // a running task's id → its tool_use id
|
|
297
|
+
const reads = new Set(); // tool_use ids of Read calls, whose result is numbered
|
|
298
|
+
let named; // the session id last emitted
|
|
299
|
+
// The model is awaited from `init` or a tool_result until a record carrying a tool_use, or a
|
|
300
|
+
// result: its thinking and its text are the model still at work.
|
|
301
|
+
let awaiting = false;
|
|
302
|
+
let said; // the last text shown: a result often repeats it
|
|
303
|
+
let failed = false;
|
|
304
|
+
const close = (id) => {
|
|
305
|
+
if (id === undefined)
|
|
306
|
+
return;
|
|
307
|
+
background.delete(id);
|
|
308
|
+
open.delete(id);
|
|
309
|
+
};
|
|
310
|
+
// A call its task runs in the background: open until the task ends, even when the move to the
|
|
311
|
+
// background is told after the call's tool_result closed it.
|
|
312
|
+
const toBackground = (id) => {
|
|
313
|
+
if (id === undefined)
|
|
314
|
+
return;
|
|
315
|
+
background.add(id);
|
|
316
|
+
const action = calls.get(id);
|
|
317
|
+
if (!open.has(id) && action !== undefined)
|
|
318
|
+
open.set(id, action);
|
|
319
|
+
};
|
|
320
|
+
return {
|
|
321
|
+
line(record) {
|
|
322
|
+
const e = parse(record);
|
|
323
|
+
if (e === undefined)
|
|
324
|
+
return [{ kind: 'show', text: passthrough(record) }];
|
|
325
|
+
switch (e.type) {
|
|
326
|
+
case 'system':
|
|
327
|
+
switch (e.subtype) {
|
|
328
|
+
case 'init': {
|
|
329
|
+
awaiting = true;
|
|
330
|
+
const id = str(e.session_id);
|
|
331
|
+
if (id === undefined || id === named)
|
|
332
|
+
return [];
|
|
333
|
+
named = id;
|
|
334
|
+
return [{ kind: 'session', id }];
|
|
335
|
+
}
|
|
336
|
+
case 'api_retry': {
|
|
337
|
+
const why = [scalar(e.error_status), scalar(e.error)].filter((x) => x !== undefined).join(' ');
|
|
338
|
+
return [show(`retrying · attempt ${scalar(e.attempt) ?? '?'}/${scalar(e.max_retries) ?? '?'} · ${why}`)];
|
|
339
|
+
}
|
|
340
|
+
case 'compact_boundary':
|
|
341
|
+
return [show('compacting context')];
|
|
342
|
+
case 'task_started': {
|
|
343
|
+
const id = str(e.tool_use_id);
|
|
344
|
+
if (id === undefined)
|
|
345
|
+
return [];
|
|
346
|
+
const task = str(e.task_id);
|
|
347
|
+
if (task !== undefined)
|
|
348
|
+
tasks.set(task, id);
|
|
349
|
+
if (e.is_backgrounded === true)
|
|
350
|
+
toBackground(id);
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
case 'task_notification': {
|
|
354
|
+
const task = str(e.task_id);
|
|
355
|
+
close(str(e.tool_use_id) ?? (task !== undefined ? tasks.get(task) : undefined));
|
|
356
|
+
if (task !== undefined)
|
|
357
|
+
tasks.delete(task);
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
case 'task_updated': {
|
|
361
|
+
const task = str(e.task_id);
|
|
362
|
+
const patch = obj(e.patch);
|
|
363
|
+
if (task === undefined || patch === undefined)
|
|
364
|
+
return [];
|
|
365
|
+
if (patch.is_backgrounded === true)
|
|
366
|
+
toBackground(tasks.get(task));
|
|
367
|
+
const status = str(patch.status);
|
|
368
|
+
if (status !== undefined && TASK_ENDED.has(status)) {
|
|
369
|
+
close(tasks.get(task));
|
|
370
|
+
tasks.delete(task);
|
|
371
|
+
}
|
|
372
|
+
return [];
|
|
373
|
+
}
|
|
374
|
+
default:
|
|
375
|
+
return [];
|
|
376
|
+
}
|
|
377
|
+
case 'assistant': {
|
|
378
|
+
const content = obj(e.message)?.content;
|
|
379
|
+
if (!Array.isArray(content))
|
|
380
|
+
return [];
|
|
381
|
+
const out = [];
|
|
382
|
+
for (const b of content) {
|
|
383
|
+
const block = obj(b);
|
|
384
|
+
if (block?.type === 'tool_use') {
|
|
385
|
+
awaiting = false;
|
|
386
|
+
const tool = str(block.name) ?? 'tool';
|
|
387
|
+
const action = actionLine(tool, block.input, home);
|
|
388
|
+
const id = str(block.id);
|
|
389
|
+
if (id !== undefined) {
|
|
390
|
+
open.set(id, action);
|
|
391
|
+
calls.set(id, action);
|
|
392
|
+
if (tool.toLowerCase() === 'read')
|
|
393
|
+
reads.add(id);
|
|
394
|
+
}
|
|
395
|
+
out.push({ kind: 'show', text: action });
|
|
396
|
+
}
|
|
397
|
+
else if (block?.type === 'text') {
|
|
398
|
+
said = str(block.text) ?? '';
|
|
399
|
+
out.push(...shown(said));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return out;
|
|
403
|
+
}
|
|
404
|
+
case 'user': {
|
|
405
|
+
const content = obj(e.message)?.content;
|
|
406
|
+
// A string is a prompt, never a tool's result.
|
|
407
|
+
if (!Array.isArray(content))
|
|
408
|
+
return [];
|
|
409
|
+
const out = [];
|
|
410
|
+
for (const b of content) {
|
|
411
|
+
const block = obj(b);
|
|
412
|
+
if (block?.type !== 'tool_result')
|
|
413
|
+
continue;
|
|
414
|
+
awaiting = true;
|
|
415
|
+
const id = str(block.tool_use_id);
|
|
416
|
+
if (id !== undefined && !background.has(id))
|
|
417
|
+
open.delete(id);
|
|
418
|
+
const numbered = id !== undefined && reads.delete(id);
|
|
419
|
+
out.push(...heard(textOf(block.content), numbered ? READ_NUMBER : undefined));
|
|
420
|
+
}
|
|
421
|
+
return out;
|
|
422
|
+
}
|
|
423
|
+
case 'result': {
|
|
424
|
+
awaiting = false;
|
|
425
|
+
failed = e.is_error === true;
|
|
426
|
+
// Its text when it says something not just shown; P8's error subtypes carry no text,
|
|
427
|
+
// only `errors[]`, and an error with neither is named by its subtype.
|
|
428
|
+
const text = str(e.result);
|
|
429
|
+
if (text !== undefined) {
|
|
430
|
+
if (text.trim() === said?.trim())
|
|
431
|
+
return [];
|
|
432
|
+
said = text;
|
|
433
|
+
return shown(text);
|
|
434
|
+
}
|
|
435
|
+
if (!failed)
|
|
436
|
+
return [];
|
|
437
|
+
const errors = Array.isArray(e.errors) ? e.errors.map(str).filter((x) => x !== undefined) : [];
|
|
438
|
+
return errors.length > 0 ? errors.flatMap(shown) : shown(str(e.subtype) ?? '');
|
|
439
|
+
}
|
|
440
|
+
default:
|
|
441
|
+
return [];
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
inFlight: () => oldestForeground(open, background) ?? (awaiting ? 'the model' : undefined),
|
|
445
|
+
failed: () => failed,
|
|
446
|
+
};
|
|
447
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popovych.co/witness",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.2",
|
|
4
4
|
"description": "Evidence-gated spec-driven development pipeline for AI coding agents: brainstorm to PR in six stages, where specs are state, plans are motion, and no transition passes without evidence. Drives from Claude Code or Pi.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spec-driven-development",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"packageManager": "pnpm@10.22.0",
|
|
43
43
|
"bin": {
|
|
44
|
-
"witness": "
|
|
44
|
+
"witness": "dist/bin.js"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "witness",
|
|
3
3
|
"description": "Spec-driven development with evidence gates: brainstorm → PR through six stages and five gates. Skills author, the pinned witness CLI writes state and witnesses evidence; gates stop where judgment is owed.",
|
|
4
|
-
"version": "0.26.
|
|
4
|
+
"version": "0.26.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Kostiantyn Popovych"
|
|
7
7
|
},
|
|
@@ -12,7 +12,7 @@ Any other words in `$ARGUMENTS` are the human's ask: run `$WITNESS ask "<those w
|
|
|
12
12
|
Resolve the CLI once:
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.
|
|
15
|
+
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.2}"
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
If the repo has no `witness.config.yaml`, run `$WITNESS init` first (one bootstrap commit), then proceed. If init or any verb refuses on a dirty tree, the human commits or cleans it — **never `git commit` yourself, anywhere, at any stage**: the CLI makes its own state commits, and the ship phase makes the sole code commit.
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
# context). Silent everywhere that isn't a witness repo; failures swallowed:
|
|
4
4
|
# session start must never hang or die on this.
|
|
5
5
|
[ -f witness.config.yaml ] || exit 0
|
|
6
|
-
${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.
|
|
6
|
+
${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.2} 2>/dev/null || true
|
|
@@ -16,7 +16,7 @@ recap, keeps a local draft, writes no document. See NOTICE.md. -->
|
|
|
16
16
|
Resolve the CLI once per session:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.
|
|
19
|
+
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.2}"
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
- **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
|
|
@@ -10,7 +10,7 @@ description: Slice a witness effort's confirmed recap into vertical spec slices,
|
|
|
10
10
|
Resolve the CLI once per session:
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.
|
|
13
|
+
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.2}"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
- **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
|
|
@@ -16,7 +16,7 @@ No text copied verbatim; the design-critic lens is new material. -->
|
|
|
16
16
|
Resolve the CLI once per session:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.
|
|
19
|
+
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.2}"
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
- **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
|
|
@@ -15,7 +15,7 @@ tests carry the parent spec's tag in their NAME. See NOTICE.md. -->
|
|
|
15
15
|
Resolve the CLI once per session:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.
|
|
18
|
+
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.2}"
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
- **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
|
|
@@ -15,7 +15,7 @@ parent's criteria. See NOTICE.md. -->
|
|
|
15
15
|
Resolve the CLI once per session:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.
|
|
18
|
+
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.2}"
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
- **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
|
|
@@ -15,7 +15,7 @@ model can. See NOTICE.md. -->
|
|
|
15
15
|
Resolve the CLI once per session:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.
|
|
18
|
+
WITNESS="${WITNESS_BIN:-npx -y @popovych.co/witness@0.26.2}"
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
- **Render the CLI's decision output verbatim and in full — every line, unmodified.** Never print a command set you remember; never recompose, reformat, summarise or reorder what the CLI emitted. Which decisions are live, how they rank, and what each costs are the CLI's answers, and they change with the round, the bound, the repair grant and the content sha — a remembered set is wrong in more states than it is right.
|