@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
package/dist/opener.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { win32 } from 'node:path';
|
|
3
|
+
import { spawnSync, spawn, system32 } from './spawn.js';
|
|
4
|
+
// Platform default openers. `start` is a cmd builtin, hence the shell wrapper — System32's
|
|
5
|
+
// cmd.exe by absolute path (row 201), never a bare name another cmd.exe on PATH answers to.
|
|
6
|
+
export function platformOpener(platform = process.platform, env = process.env) {
|
|
7
|
+
if (platform === 'darwin')
|
|
5
8
|
return ['open'];
|
|
6
|
-
if (
|
|
7
|
-
return ['cmd', '/c', 'start', ''];
|
|
9
|
+
if (platform === 'win32')
|
|
10
|
+
return [system32(env, 'cmd.exe'), '/c', 'start', ''];
|
|
8
11
|
return ['xdg-open'];
|
|
9
12
|
}
|
|
10
|
-
// win32 has no `sh`, so a POSIX probe there would report every opener missing and
|
|
11
|
-
//
|
|
13
|
+
// win32 has no `sh`, so a POSIX probe there would report every opener missing and make approve
|
|
14
|
+
// permanently unreachable. System32's `where` is the cmd equivalent, but it matches name
|
|
15
|
+
// patterns, never paths, so an absolute opener there is probed by existence.
|
|
16
|
+
export function probeArgv(cmd, platform = process.platform, env = process.env) {
|
|
17
|
+
if (platform !== 'win32')
|
|
18
|
+
return { file: 'sh', args: ['-c', `command -v ${cmd}`] };
|
|
19
|
+
return win32.isAbsolute(cmd) ? { exists: cmd } : { file: system32(env, 'where.exe'), args: [cmd] };
|
|
20
|
+
}
|
|
12
21
|
export function resolves(cmd) {
|
|
13
|
-
const probe =
|
|
14
|
-
|
|
15
|
-
: spawnSync('sh', ['-c', `command -v ${cmd}`], { encoding: 'utf8' });
|
|
16
|
-
return probe.status === 0;
|
|
22
|
+
const probe = probeArgv(cmd);
|
|
23
|
+
return 'exists' in probe ? existsSync(probe.exists) : spawnSync(probe.file, probe.args, { encoding: 'utf8' }).status === 0;
|
|
17
24
|
}
|
|
18
25
|
// Show a file to the human. Returns the resolved command alongside the outcome so the
|
|
19
26
|
// caller can journal WHAT was run — a degenerate opener (`opener: /usr/bin/true` in
|
package/dist/recommend.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { anchorRecurrence, boundReached, ladderSpent, lastGateRun, notePrefill, pendingDecision, repairGranted, roundBudget, roundsSinceApprove, } from './rounds.js';
|
|
1
|
+
import { anchorRecurrence, boundReached, ladderSpent, lastGateRun, notePrefill, pendingDecision, repairsOnRegate, repairGranted, roundBudget, roundsSinceApprove, } from './rounds.js';
|
|
2
2
|
// Commands are emitted raw (D120): `esc` would quote the `--note "…"` argument and the
|
|
3
3
|
// line would paste into a shell as an empty note.
|
|
4
4
|
export function renderDecision(d) {
|
|
@@ -129,7 +129,11 @@ function recommendCore(ctx) {
|
|
|
129
129
|
key: 'next', rule: 'malformed-rerun',
|
|
130
130
|
options: [
|
|
131
131
|
opt(`witness gate ${gate} ${target}`, 'root', {
|
|
132
|
-
why: `the battery emitted ${last.malformed?.length ?? 0} schema violation(s) and no verdict — this round judged nothing, and malformed rounds do not spend the budget, so re-running is free${
|
|
132
|
+
why: `the battery emitted ${last.malformed?.length ?? 0} schema violation(s) and no verdict — this round judged nothing, and malformed rounds do not spend the budget, so re-running is free${
|
|
133
|
+
// A promise of what appendKind does (row 209): moved content is a fresh round, every
|
|
134
|
+
// lens asked; a revise since makes it changed-nothing; a fallen-back round re-runs.
|
|
135
|
+
last.malformed?.length && !stale && repairsOnRegate(entries, gate)
|
|
136
|
+
? `, and on unchanged content and setup it re-asks only ${last.malformed.map((m) => m.reviewer).join(' · ')}` : ''}`,
|
|
133
137
|
note: 'a second malformed round on the same pin and prompts trips malformed-streak, which names the config remedy',
|
|
134
138
|
}),
|
|
135
139
|
],
|
package/dist/reviewer.js
CHANGED
|
@@ -200,7 +200,7 @@ export async function invokeReviewerAsync(ctx, harness, opts) {
|
|
|
200
200
|
const limit = usageLimitOf(c, clock.now());
|
|
201
201
|
if (!limit)
|
|
202
202
|
return c;
|
|
203
|
-
// A wait spends no timeout retry: the same
|
|
203
|
+
// A wait spends no timeout retry: the same model is asked again after the reset.
|
|
204
204
|
const wait = waitFor(limit, streak, clock.now());
|
|
205
205
|
// Inside a drive session the wait must also end before drive kills the session (F14).
|
|
206
206
|
const deadline = Number(ctx.env[DRIVE_DEADLINE_ENV]);
|
package/dist/rounds.js
CHANGED
|
@@ -254,6 +254,19 @@ export function openReopen(entries, gate) {
|
|
|
254
254
|
}
|
|
255
255
|
return undefined;
|
|
256
256
|
}
|
|
257
|
+
const revisedAfter = (entries, runIdx, gate) => entries.slice(runIdx + 1).some((e) => isDecision(e, gate) && ['revise', 'revise-upstream'].includes(e.decision));
|
|
258
|
+
// Row 209: does a re-gate on unchanged content and setup repair the last run — re-ask only its
|
|
259
|
+
// lenses with no verdict — rather than re-run, resume or refuse? appendKind's own rule, minus the
|
|
260
|
+
// key only the gate can build, so the recommender's promise of a repair reads the same rule.
|
|
261
|
+
export function repairsOnRegate(entries, gate) {
|
|
262
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
263
|
+
if (!isRun(entries[i], gate))
|
|
264
|
+
continue;
|
|
265
|
+
const last = entries[i];
|
|
266
|
+
return last.outcome === 'malformed' && !fellBack(last) && !revisedAfter(entries, i, gate);
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
257
270
|
export function appendKind(entries, gate, key) {
|
|
258
271
|
let lastRunIdx = -1;
|
|
259
272
|
for (let i = entries.length - 1; i >= 0; i--) {
|
|
@@ -276,9 +289,7 @@ export function appendKind(entries, gate, key) {
|
|
|
276
289
|
// re-ran nothing while its own block said re-running is free. A re-gate repairs it instead —
|
|
277
290
|
// the lenses that answered are carried and the ones that did not are asked again.
|
|
278
291
|
if (!fellBack(last) && sameKey(keyOf(last), key)) {
|
|
279
|
-
|
|
280
|
-
['revise', 'revise-upstream'].includes(e.decision));
|
|
281
|
-
if (revised)
|
|
292
|
+
if (revisedAfter(entries, lastRunIdx, gate))
|
|
282
293
|
return { kind: 'changed-nothing', entry: last };
|
|
283
294
|
return last.outcome === 'malformed' ? { kind: 'repair', from: last } : { kind: 'resume', entry: last };
|
|
284
295
|
}
|
package/dist/session-clock.js
CHANGED
|
@@ -17,6 +17,8 @@ export const monotonicTicker = {
|
|
|
17
17
|
now: () => performance.now(),
|
|
18
18
|
after: (ms, fn) => { const t = setTimeout(fn, ms); return () => clearTimeout(t); },
|
|
19
19
|
};
|
|
20
|
+
// Row 214: `tick` hears every check with the awake time, so what drive does once a second for a
|
|
21
|
+
// running session (its quiet line, its journal watch) runs on this one clock, in awake time.
|
|
20
22
|
export function sessionClock(limitMs, ticker, on) {
|
|
21
23
|
const t0 = ticker.now();
|
|
22
24
|
let last = t0; // when the pending check was armed
|
|
@@ -39,10 +41,13 @@ export function sessionClock(limitMs, ticker, on) {
|
|
|
39
41
|
wait = Math.min(SESSION_TICK_MS, limitMs - awake);
|
|
40
42
|
cancel = ticker.after(wait, check);
|
|
41
43
|
};
|
|
44
|
+
// The next check is armed before `tick` runs: a tick that threw would otherwise leave the
|
|
45
|
+
// session with no limit at all, and one that stopped the clock cancels the check it armed.
|
|
42
46
|
const check = () => {
|
|
43
47
|
const awake = account(ticker.now());
|
|
44
48
|
if (awake < limitMs) {
|
|
45
49
|
arm(awake);
|
|
50
|
+
on.tick?.(awake);
|
|
46
51
|
return;
|
|
47
52
|
}
|
|
48
53
|
expired = true;
|
package/dist/toon.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// A shell word is quoted only when it needs it, so the common line stays the one a human
|
|
2
2
|
// types — a path in drive's watch line, a command in a `--cmd` grant (row 205).
|
|
3
3
|
export const shellArg = (p) => /^[\w@%+=:,./-]+$/.test(p) ? p : `'${p.replaceAll("'", "'\\''")}'`;
|
|
4
|
+
// Row 214. The same rule for a PowerShell word — drive's Windows watch line. Bare only when no
|
|
5
|
+
// character in it means anything to PowerShell: a bare `,` builds an array, a leading `@` splats
|
|
6
|
+
// and a leading `-` binds as a parameter, so none of them is bare here as in a POSIX word. Else
|
|
7
|
+
// single-quoted, where nothing expands and the one special character is a single quote — any of
|
|
8
|
+
// the five PowerShell reads as one (' ‘ ’ ‚ ‛) — written twice.
|
|
9
|
+
export const psArg = (p) => /^[\w%+=:./\\][\w%+=:./\\-]*$/.test(p) ? p : `'${p.replace(/['‘’‚‛]/g, (q) => q + q)}'`;
|
|
4
10
|
// Security review. A command a human is asked to trust is repo-authored text: a carriage return
|
|
5
11
|
// or an escape sequence could paint a different command over the real one, a bidi override
|
|
6
12
|
// reorder it (Trojan Source), an invisible filler hide a second command beside it. A denylist of
|
|
@@ -8,8 +14,19 @@ export const shellArg = (p) => /^[\w@%+=:,./-]+$/.test(p) ? p : `'${p.replaceAll
|
|
|
8
14
|
// is, anything else is spelled out, and a command carrying any of it is never granted.
|
|
9
15
|
const UNSHOWABLE = /[^\x20-\x7e]/u;
|
|
10
16
|
export const hasControl = (s) => UNSHOWABLE.test(s);
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
// One character spelled out: the one spelling `visible` and `logSafe` share.
|
|
18
|
+
const spell = (c) => c === '\n' ? '\\n' : c === '\r' ? '\\r' : c === '\t' ? '\\t'
|
|
19
|
+
: c.codePointAt(0) < 0x100 ? `\\x${c.codePointAt(0).toString(16).padStart(2, '0')}` : `\\u{${c.codePointAt(0).toString(16)}}`;
|
|
20
|
+
export const visible = (s) => s.replace(new RegExp(UNSHOWABLE.source, 'gu'), spell);
|
|
21
|
+
// Row 214. What a session drive runs wrote, on the human's terminal and in .witness/drive.log: the
|
|
22
|
+
// same paint-over and reorder attacks, from text an agent controls (a command, a path, its prose).
|
|
23
|
+
// Nobody grants a log line, so the rule is narrower than `visible`'s — control and format
|
|
24
|
+
// characters (ESC, CR, TAB, bidi overrides, zero-width fillers) and the line and paragraph
|
|
25
|
+
// separators U+2028/U+2029, which editors and some terminals render as a line break, are spelled
|
|
26
|
+
// out, and printable text in any script stays as written: `visible` would mangle drive's own `·`
|
|
27
|
+
// and `→`, and every sentence an agent writes in another language.
|
|
28
|
+
const UNLOGGABLE = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu;
|
|
29
|
+
export const logSafe = (s) => s.replace(UNLOGGABLE, spell);
|
|
13
30
|
function esc(value) {
|
|
14
31
|
const s = String(value ?? '');
|
|
15
32
|
return /[,"\n]|^\s|\s$/.test(s) ? `"${s.replaceAll('"', '""')}"` : s;
|
package/dist/usage.js
CHANGED
|
@@ -115,12 +115,15 @@ export function limitIn(text, now) {
|
|
|
115
115
|
return found.find((l) => l.kind === 'usage') ?? found[0];
|
|
116
116
|
}
|
|
117
117
|
// A session's end reads as a limit only from its last three lines. A usage shape counts at
|
|
118
|
-
// any exit code (claude may exit 0 on one)
|
|
118
|
+
// any exit code (claude may exit 0 on one). A transient shape counts on a session that failed:
|
|
119
|
+
// its stream ended in an error, which pi's JSON mode reports at exit 0 (row 214), or it exited
|
|
120
|
+
// non-zero by itself. A session drive timed out ended on drive's signal, not on the 529 its
|
|
121
|
+
// harness retried a while before and that still sits in its tail.
|
|
119
122
|
export function sessionLimit(end, now) {
|
|
120
123
|
const limit = limitIn(end.tail.slice(-3).join('\n'), now);
|
|
121
124
|
if (!limit)
|
|
122
125
|
return undefined;
|
|
123
|
-
if (limit.kind === 'transient' && end.code === 0)
|
|
126
|
+
if (limit.kind === 'transient' && end.failed !== true && (end.code === 0 || end.outcome === 'timeout'))
|
|
124
127
|
return undefined;
|
|
125
128
|
return limit;
|
|
126
129
|
}
|
package/dist/verbs/log.js
CHANGED
|
@@ -10,7 +10,8 @@ import { short } from '../sha.js';
|
|
|
10
10
|
import { stepProgress, stepsLine } from '../steps.js';
|
|
11
11
|
import { kv, rows } from '../toon.js';
|
|
12
12
|
import { decidedBy } from '../autonomy.js';
|
|
13
|
-
|
|
13
|
+
// Row 214: drive's `journal:` lines print an act as `witness log` does.
|
|
14
|
+
export function entryDetail(e) {
|
|
14
15
|
switch (e.t) {
|
|
15
16
|
case 'recap': {
|
|
16
17
|
const size = (k) => (Array.isArray(e[k]) ? e[k].length : 0);
|
|
@@ -129,7 +130,7 @@ export async function run(ctx, argv) {
|
|
|
129
130
|
const root = rootRes.value;
|
|
130
131
|
if (values.all) {
|
|
131
132
|
const merged = mergedRows(root);
|
|
132
|
-
rows('all', ['n', 'stream', 't', 'detail'], merged.map((r, i) => ({ n: i + 1, stream: r.stream, t: r.entry.t, detail:
|
|
133
|
+
rows('all', ['n', 'stream', 't', 'detail'], merged.map((r, i) => ({ n: i + 1, stream: r.stream, t: r.entry.t, detail: entryDetail(r.entry) })))
|
|
133
134
|
.forEach(ctx.out);
|
|
134
135
|
return EXIT.OK;
|
|
135
136
|
}
|
|
@@ -140,7 +141,7 @@ export async function run(ctx, argv) {
|
|
|
140
141
|
const chain = lineageChain(root, id);
|
|
141
142
|
ctx.out(`lineage: ${chain.join(' → ')}`);
|
|
142
143
|
const merged = chain.flatMap((sid) => readStream(root, sid).map((entry) => ({ stream: sid, entry })));
|
|
143
|
-
rows('lineage', ['n', 'stream', 't', 'detail'], merged.map((r, i) => ({ n: i + 1, stream: r.stream, t: r.entry.t, detail:
|
|
144
|
+
rows('lineage', ['n', 'stream', 't', 'detail'], merged.map((r, i) => ({ n: i + 1, stream: r.stream, t: r.entry.t, detail: entryDetail(r.entry) })))
|
|
144
145
|
.forEach(ctx.out);
|
|
145
146
|
return EXIT.OK;
|
|
146
147
|
}
|
|
@@ -149,7 +150,7 @@ export async function run(ctx, argv) {
|
|
|
149
150
|
return EXIT.REFUSED;
|
|
150
151
|
}
|
|
151
152
|
const entries = readStream(root, id);
|
|
152
|
-
rows('entries', ['n', 't', 'detail'], entries.map((e, i) => ({ n: i + 1, t: e.t, detail:
|
|
153
|
+
rows('entries', ['n', 't', 'detail'], entries.map((e, i) => ({ n: i + 1, t: e.t, detail: entryDetail(e) })))
|
|
153
154
|
.forEach(ctx.out);
|
|
154
155
|
// Row 191 §4.3. A plan's stream ends with where the plan stands; an effort has no steps.
|
|
155
156
|
const plan = findById(loadCanon(root), id);
|