@popovych.co/witness 0.14.8 → 0.16.0
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 +4 -1
- package/dist/arbiter.js +189 -0
- package/dist/autonomy.js +84 -0
- package/dist/battery.js +68 -0
- package/dist/cli.js +1 -1
- package/dist/config.js +63 -1
- package/dist/criteria.js +27 -4
- package/dist/deferral.js +19 -6
- package/dist/evidence.js +4 -2
- package/dist/gate.js +74 -51
- package/dist/gates/implement.js +4 -9
- package/dist/gates/ship.js +7 -11
- package/dist/recommend.js +46 -5
- package/dist/reviewer.js +135 -23
- package/dist/runner.js +5 -0
- package/dist/settle.js +172 -0
- package/dist/ship.js +232 -12
- package/dist/verbs/dashboard.js +37 -0
- package/dist/verbs/decide.js +232 -102
- package/dist/verbs/log.js +4 -1
- package/dist/verbs/next.js +98 -43
- package/dist/verbs/ship.js +2 -2
- package/dist/verbs/start.js +13 -0
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/witness.md +13 -3
- package/plugin/hooks/session-dashboard.sh +1 -1
- package/plugin/skills/witness-brainstorm/SKILL.md +5 -1
- package/plugin/skills/witness-decompose/SKILL.md +2 -1
- package/plugin/skills/witness-design/SKILL.md +2 -1
- package/plugin/skills/witness-implement/SKILL.md +2 -1
- package/plugin/skills/witness-plan/SKILL.md +2 -1
- package/plugin/skills/witness-ship/SKILL.md +3 -2
- package/prompts/arbiter.md +22 -0
package/README.md
CHANGED
|
@@ -149,6 +149,9 @@ either.
|
|
|
149
149
|
| `harness: claude-code \| pi` | **the judge** — which harness runs this repo's gate reviewers, is measured by `calibrate`, and is probed by `check`. Judgment resolves `harness:` → `PI_CODING_AGENT` → `CLAUDECODE` → `claude-code`; session lines (`next`'s handoff, `dispatch`'s relay, `init --agent auto`) resolve detection first, because those name the CLI you are about to type at. Committed, so it binds every teammate's gates; `witness init --agent` writes it once and never re-points it. Undeclared repos are judged by whichever agent's session is open — `witness check` and `witness status` say so |
|
|
150
150
|
| `gates.reviewerTimeoutMs` | milliseconds per reviewer invocation (default 600000) |
|
|
151
151
|
| `drive.sessionTimeoutMs` | milliseconds a `drive`-spawned session may run before SIGTERM (default 3600000) |
|
|
152
|
+
| `autonomy: on \| off` | whether the CLI settles its own stops — through its recommendation or the arbiter it launches — and merges its own PRs once CI is green (default off). A committed repo fact: it counts only once HEAD says it, and the merge also needs the ship branch on origin to say it. `--manual` on a gate run keeps that run's stop for a human, and three stops always reach one: the look of a new screen, an unmet plan need and a trust grant |
|
|
153
|
+
| `ship.merge: merge \| squash \| rebase` | how `witness ship` merges its own PR under `autonomy: on` (default merge) — only once the ship gate is approved and CI is green, and never when the approval lapsed or GitHub refuses |
|
|
154
|
+
| `ship.ciSettleMs` | milliseconds a green check set must hold still before `witness ship` merges under autonomy (default 60000, at most 1800000) — gh's watch ends the moment nothing is pending, so a check that registers late would otherwise be missed. Green means at least one check passed and none failed, was cancelled or is pending |
|
|
152
155
|
|
|
153
156
|
There is no `provider:` key. `witness gate` spawns the DECLARED harness's headless
|
|
154
157
|
mode for every reviewer (Decisions 88, 105): claude-code renders bare Anthropic ids, pi
|
|
@@ -187,7 +190,7 @@ the wrong file refuses. There are no `WITNESS_*` env vars for configuration.
|
|
|
187
190
|
| `start <plan-id>` | create/re-attach the plan's worktree (`.witness/worktrees/<id>`) — code only: the canon dirs are excluded from it, so a plan cannot go stale in there |
|
|
188
191
|
| `next` | the one next action across every effort |
|
|
189
192
|
| `drive [--flow <plan-id>] [--max-spawns <n>]` | schedule green-path work through headless sessions; you appear only at judgment stops. TTY-only — agents are what drive spawns, never what spawns drive |
|
|
190
|
-
| `ship <plan-id
|
|
193
|
+
| `ship <plan-id> [--manual]` | lanes → ship gate → PR → CI watch → under autonomy: merge on green · `--manual` keeps that run's stop and merge for a human |
|
|
191
194
|
| `test-evidence` / `verify-red` | journal red/green criteria evidence from a worktree |
|
|
192
195
|
| `adopt <path>` | absolve a finished hand-edit into the journal |
|
|
193
196
|
| `abandon <plan-id \| effort-slug>` | wind a plan/effort down; reverts only specs that effort itself wrote |
|
package/dist/arbiter.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { decidedBy } from './autonomy.js';
|
|
2
|
+
import { loadLocalConfig } from './config.js';
|
|
3
|
+
import { openDeferrals } from './deferral.js';
|
|
4
|
+
import { serializeDoc } from './fm.js';
|
|
5
|
+
import { resolveJudge } from './harness.js';
|
|
6
|
+
import { latestRecap, policyPins } from './journal.js';
|
|
7
|
+
import { loadMatrix, resolveModel, SESSION_DEFAULT } from './model.js';
|
|
8
|
+
import { PLACEHOLDER } from './recommend.js';
|
|
9
|
+
import { ok, refuse, v } from './refusal.js';
|
|
10
|
+
import { invokeReviewerAsync, parseVerdictText, promptsSha, resolvePrompt } from './reviewer.js';
|
|
11
|
+
import { effortOf, effortSpecs } from './reviewed.js';
|
|
12
|
+
import { anchorRecurrence, gateRuns, roundBudget } from './rounds.js';
|
|
13
|
+
import { findById } from './scan.js';
|
|
14
|
+
import { canonicalJson } from './sha.js';
|
|
15
|
+
// How a later mode (plan A2's recap check) adds its own prompt without a second invoker.
|
|
16
|
+
export const PROMPT_OF = { decision: 'arbiter' };
|
|
17
|
+
const TEXT_MAX = 600;
|
|
18
|
+
function renderOptions(menu) {
|
|
19
|
+
return menu.flatMap((o, i) => [
|
|
20
|
+
`${i + 1}. ${o.command}`,
|
|
21
|
+
...(o.why ? [` why: ${o.why}`] : []),
|
|
22
|
+
...(o.judgeFirst ? [` judge-first: ${o.judgeFirst}`] : []),
|
|
23
|
+
...(o.when ? [` when: ${o.when}`] : []),
|
|
24
|
+
...(o.tradeoff ? [` tradeoff: ${o.tradeoff}`] : []),
|
|
25
|
+
...(o.note ? [` note: ${o.note}`] : []),
|
|
26
|
+
]).join('\n');
|
|
27
|
+
}
|
|
28
|
+
function readRuling(text, n) {
|
|
29
|
+
const rawR = parseVerdictText(text);
|
|
30
|
+
if (!rawR.ok)
|
|
31
|
+
return rawR;
|
|
32
|
+
const raw = rawR.value;
|
|
33
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
34
|
+
return refuse([v('ruling', 'not-an-object', JSON.stringify(raw).slice(0, 120), '{"choice": <n>, "reason": "…"}')]);
|
|
35
|
+
}
|
|
36
|
+
const r = raw;
|
|
37
|
+
const rows = [];
|
|
38
|
+
if (typeof r.choice !== 'number' || !Number.isInteger(r.choice) || r.choice < 1 || r.choice > n) {
|
|
39
|
+
rows.push(v('choice', 'not-an-option', String(r.choice), `an option number from 1 to ${n}`));
|
|
40
|
+
}
|
|
41
|
+
if (typeof r.reason !== 'string' || r.reason.trim() === '' || r.reason.length > TEXT_MAX) {
|
|
42
|
+
rows.push(v('reason', 'invalid', typeof r.reason === 'string' ? `${r.reason.length} chars` : String(r.reason), `a non-empty reason of at most ${TEXT_MAX} characters`));
|
|
43
|
+
}
|
|
44
|
+
// An empty note is an absent one: the contract marks it optional, and a reroll spent on
|
|
45
|
+
// `"note": ""` would park a flow over a field that carried nothing.
|
|
46
|
+
const note = typeof r.note === 'string' && r.note.trim() === '' ? undefined : r.note;
|
|
47
|
+
if (note !== undefined && note !== null && (typeof note !== 'string' || note.length > TEXT_MAX)) {
|
|
48
|
+
rows.push(v('note', 'invalid', typeof note === 'string' ? `${note.length} chars` : String(note), `an optional note of at most ${TEXT_MAX} characters`));
|
|
49
|
+
}
|
|
50
|
+
if (rows.length > 0)
|
|
51
|
+
return refuse(rows);
|
|
52
|
+
return ok({ choice: r.choice, reason: r.reason, ...(typeof note === 'string' ? { note } : {}) });
|
|
53
|
+
}
|
|
54
|
+
export async function arbitrate(ctx, root, cfg, req) {
|
|
55
|
+
const lensR = resolvePrompt(PROMPT_OF[req.mode]);
|
|
56
|
+
if (!lensR.ok)
|
|
57
|
+
return lensR;
|
|
58
|
+
const lens = lensR.value;
|
|
59
|
+
const hxR = resolveJudge(ctx.env, cfg.raw);
|
|
60
|
+
if (!hxR.ok)
|
|
61
|
+
return refuse(hxR.violations);
|
|
62
|
+
const harness = hxR.value.harness;
|
|
63
|
+
const localR = loadLocalConfig(root);
|
|
64
|
+
if (!localR.ok)
|
|
65
|
+
return localR;
|
|
66
|
+
const modelR = resolveModel(cfg, loadMatrix(root, harness.name));
|
|
67
|
+
if (!modelR.ok)
|
|
68
|
+
return refuse(modelR.violations);
|
|
69
|
+
const chain = modelR.value.chain;
|
|
70
|
+
let prompt = `${lens.contents}\n${req.evidence.map((s) => `\n## ${s.title}\n\n${s.body}\n`).join('')}\n## Options\n\n${renderOptions(req.menu)}\n`;
|
|
71
|
+
let rung = 0;
|
|
72
|
+
for (let attempt = 0;; attempt++) {
|
|
73
|
+
let text;
|
|
74
|
+
for (;;) {
|
|
75
|
+
const id = chain[rung];
|
|
76
|
+
const r = await invokeReviewerAsync(ctx, harness, {
|
|
77
|
+
cwd: root, prompt, model: id === SESSION_DEFAULT ? undefined : id, lens: 'arbiter',
|
|
78
|
+
timeoutMs: cfg.gates.reviewerTimeoutMs, extensions: localR.value.reviewerExtensions,
|
|
79
|
+
});
|
|
80
|
+
if (r.ok) {
|
|
81
|
+
text = r.value.text;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
if (rung >= chain.length - 1)
|
|
85
|
+
return refuse(r.violations);
|
|
86
|
+
rung += 1;
|
|
87
|
+
}
|
|
88
|
+
const ruling = readRuling(text, req.menu.length);
|
|
89
|
+
if (ruling.ok) {
|
|
90
|
+
return ok({ ...ruling.value, model: chain[rung], prompts_sha: promptsSha([{ name: 'arbiter', contents: lens.contents }]) });
|
|
91
|
+
}
|
|
92
|
+
if (attempt === 0) {
|
|
93
|
+
// One self-repair reroll on the same rung, in the shape runBattery gives a lens.
|
|
94
|
+
prompt += `\n## Previous attempt rejected\n\n${ruling.violations.map((x) => `- ${x.field}: ${x.rule} — got ${x.got}; want ${x.want}`).join('\n')}\n\nRe-emit the complete corrected JSON object.\n`;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
return refuse([v('arbiter', 'arbiter-malformed', ruling.violations[0]?.got ?? '', 'a JSON object with choice and reason naming one listed option'), ...ruling.violations]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// The block minus every act the arbiter may never take: anything but a decision (which
|
|
101
|
+
// removes `witness abandon` — the CLI never discards work, D168), any trust grant (D154),
|
|
102
|
+
// any command whose id the CLI could not resolve (the arbiter fills a note, never an id),
|
|
103
|
+
// and every approve over a failed deterministic check — it may overrule a reviewer, never a
|
|
104
|
+
// check. `amendment-ack` alone is the exception: approving IS its acknowledgement.
|
|
105
|
+
// The design gate is the exception that holds whatever the evidence says: the look is the
|
|
106
|
+
// human's (§3 G2), so no approve of it is ever offered — at the bound, on a fallback round or
|
|
107
|
+
// past a spent ladder the arbiter may revise, reset upstream, repair or park, never stamp.
|
|
108
|
+
export function menuFor(block, run) {
|
|
109
|
+
const failed = run.checks.filter((c) => !c.ok);
|
|
110
|
+
const approveBarred = run.gate === 'design' || (failed.length > 0 && !failed.every((c) => c.name === 'amendment-ack'));
|
|
111
|
+
return block.options.filter((o) => o.command.startsWith('witness decide ') &&
|
|
112
|
+
!/ --trust-cmds\b/.test(o.command) &&
|
|
113
|
+
!PLACEHOLDER.test(o.command.replace(' --note "<why>"', '')) &&
|
|
114
|
+
!(approveBarred && / --approve\b/.test(o.command)));
|
|
115
|
+
}
|
|
116
|
+
const anchorText = (a) => (typeof a === 'string' ? a : `omission:${a.scope}`);
|
|
117
|
+
const HISTORY_RUNS = 10;
|
|
118
|
+
// The evidence the arbiter reads, composed by the CLI from the journal and canon. It never
|
|
119
|
+
// carries a session transcript: none exists to carry, and the author's narration is
|
|
120
|
+
// exactly what the arbiter must not hear (anti-goal 1).
|
|
121
|
+
export function decisionEvidence(root, canon, stop) {
|
|
122
|
+
const { gate, target, entries, run, block } = stop;
|
|
123
|
+
const findings = (run.verdicts ?? []).flatMap((rv) => rv.findings.map((f) => ({ reviewer: rv.reviewer, f })));
|
|
124
|
+
const sections = [
|
|
125
|
+
{
|
|
126
|
+
title: 'The stop',
|
|
127
|
+
body: [
|
|
128
|
+
`gate: ${gate} · target: ${target}`,
|
|
129
|
+
`round: ${run.round} of ${roundBudget(entries, gate)}`,
|
|
130
|
+
`rule: ${block.rule}`,
|
|
131
|
+
`standing: ${run.standing ?? 'none'}`,
|
|
132
|
+
`model: reviewers answered on ${run.model} · pinned ${run.pin ?? run.model}`,
|
|
133
|
+
].join('\n'),
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
title: 'Checks',
|
|
137
|
+
body: run.checks.length === 0 ? 'none'
|
|
138
|
+
: run.checks.map((c) => `- ${c.name}: ${c.ok ? 'ok' : 'FAILED'}${c.detail ? ` — ${c.detail}` : ''}`).join('\n'),
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
title: 'Findings',
|
|
142
|
+
body: findings.length === 0 ? 'none'
|
|
143
|
+
: findings.map(({ reviewer, f }) => `- [${reviewer} · ${f.blocking ? 'blocking' : 'non-blocking'}] ${anchorText(f.anchor)} — ${f.claim}${f.contradicts_pin !== undefined ? ` · contradicts pin #${f.contradicts_pin}` : ''}`).join('\n'),
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
const history = [];
|
|
147
|
+
const runs = gateRuns(entries, gate).slice(-HISTORY_RUNS);
|
|
148
|
+
for (const r of runs) {
|
|
149
|
+
const blocks = [...new Set((r.verdicts ?? []).flatMap((rv) => rv.findings.filter((f) => f.blocking).map((f) => anchorText(f.anchor))))];
|
|
150
|
+
history.push(`- round ${r.round} · @${r.reviewed_sha.slice(0, 7)} · ${r.outcome}${blocks.length ? ` · blocking: ${blocks.join(' · ')}` : ''}`);
|
|
151
|
+
const at = entries.indexOf(r);
|
|
152
|
+
for (const e of entries.slice(at + 1)) {
|
|
153
|
+
if (e.t === 'gate-run' && e.gate === gate)
|
|
154
|
+
break;
|
|
155
|
+
if (e.t !== 'human-decision' || e.gate !== gate)
|
|
156
|
+
continue;
|
|
157
|
+
const d = e;
|
|
158
|
+
history.push(` - ${d.decision} · ${decidedBy(d)}${d.rule ? ` · ${d.rule}` : ''}${d.note ? ` · ${d.note}` : ''}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const current = [...new Set(findings.filter(({ f }) => f.blocking).map(({ f }) => anchorText(f.anchor)))];
|
|
162
|
+
for (const a of current)
|
|
163
|
+
history.push(`- recurrence: ${a} · found in ${anchorRecurrence(entries, gate, a)} round(s) of this budget`);
|
|
164
|
+
for (const d of openDeferrals(entries))
|
|
165
|
+
history.push(`- open obligation ${d.id} · ${d.anchor} · ${d.kind}`);
|
|
166
|
+
for (const p of policyPins(entries))
|
|
167
|
+
history.push(`- pin #${p.ordinal}: ${p.text}`);
|
|
168
|
+
sections.push({ title: 'Round history', body: history.length === 0 ? 'none' : history.join('\n') });
|
|
169
|
+
if (gate === 'ship' || gate === 'decompose') {
|
|
170
|
+
const effort = gate === 'decompose' ? target : effortOf(root, target);
|
|
171
|
+
const recap = effort !== undefined ? latestRecap(root, effort) : undefined;
|
|
172
|
+
const scope = [`### The effort's recap\n\n${recap ? canonicalJson(recap) : 'none recorded'}`];
|
|
173
|
+
if (gate === 'ship') {
|
|
174
|
+
const plan = findById(canon, target);
|
|
175
|
+
const parent = plan ? findById(canon, String(plan.meta.parent)) : undefined;
|
|
176
|
+
if (parent)
|
|
177
|
+
scope.push(`### The spec: ${String(parent.meta.id)}\n\n${serializeDoc({ meta: parent.meta, body: parent.body })}`);
|
|
178
|
+
if (plan)
|
|
179
|
+
scope.push(`### The plan: ${target}\n\n${serializeDoc({ meta: plan.meta, body: plan.body })}`);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
for (const s of effortSpecs(root, canon, target)) {
|
|
183
|
+
scope.push(`### The spec: ${String(s.meta.id)}\n\n${serializeDoc({ meta: s.meta, body: s.body })}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
sections.push({ title: 'Scope', body: scope.join('\n\n') });
|
|
187
|
+
}
|
|
188
|
+
return sections;
|
|
189
|
+
}
|
package/dist/autonomy.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { boundReached, fellBack } from './rounds.js';
|
|
2
|
+
import { cmd, kv } from './toon.js';
|
|
3
|
+
export const KEPT_STOP_NAMES = {
|
|
4
|
+
'design-look': 'design look',
|
|
5
|
+
'unmet-need': 'unmet need',
|
|
6
|
+
'trust-grant': 'trust grant',
|
|
7
|
+
};
|
|
8
|
+
// Printed first on `next`, `start`, `gate` and `decide --show` whenever the repo has opted
|
|
9
|
+
// in, so a skill learns the mode from CLI output and never from memory (A1, A8).
|
|
10
|
+
export function autonomyLines(cfg) {
|
|
11
|
+
if (!cfg.autonomy)
|
|
12
|
+
return [];
|
|
13
|
+
return [kv('autonomy', 'on'),
|
|
14
|
+
kv('kept-stops', Object.keys(KEPT_STOP_NAMES).map((k) => KEPT_STOP_NAMES[k]).join(' · '))];
|
|
15
|
+
}
|
|
16
|
+
// `cmd`, not `kv`: a detail can carry a quoted command, and `kv` would quote the whole
|
|
17
|
+
// line into something that no longer pastes (D120).
|
|
18
|
+
export function keptStopLine(stop, detail) {
|
|
19
|
+
return cmd('kept-stop', `${KEPT_STOP_NAMES[stop]} — ${detail}`);
|
|
20
|
+
}
|
|
21
|
+
// The rules whose recommendation the CLI takes as it stands (design §7 A2's table). Each is
|
|
22
|
+
// a fix with a right answer — revise here, revise upstream, approve over nits, re-run a
|
|
23
|
+
// stale or malformed round — so no judgment is owed and none is spent.
|
|
24
|
+
const TAKEN = new Set(['blocking-here', 'blocking-parent', 'bound-recurrence', 'non-blocking-only',
|
|
25
|
+
'stale-below-bound', 'malformed-rerun']);
|
|
26
|
+
// An ordered first-match list, like recommend.ts's rule table, and dispatched by GATE before
|
|
27
|
+
// RULE: the recommender's rules overlap, so a design stop with only non-blocking findings
|
|
28
|
+
// matches `non-blocking-only` before `reserved-stop-clean` (E8), and a rule-keyed policy
|
|
29
|
+
// would approve the one look the user kept for themselves.
|
|
30
|
+
export function policyFor(facts) {
|
|
31
|
+
if (facts.at === 'start')
|
|
32
|
+
return { kind: 'human', stop: 'unmet-need' };
|
|
33
|
+
if (facts.at !== 'gate')
|
|
34
|
+
return { kind: 'take', command: facts.block.options[0].command };
|
|
35
|
+
const { gate, target, entries, run, block, untrusted } = facts;
|
|
36
|
+
const failed = run.checks.filter((c) => !c.ok);
|
|
37
|
+
const blocks = (run.verdicts ?? []).some((rv) => rv.findings.some((f) => f.blocking));
|
|
38
|
+
const clean = failed.length === 0 && !blocks;
|
|
39
|
+
// Option 1 only when it pastes: a placeholder (`<effort>`) means no upstream resolved,
|
|
40
|
+
// and filling an id is exactly what the arbiter may never do either — but it can pick
|
|
41
|
+
// another option, so the stop goes there rather than to a command that would refuse.
|
|
42
|
+
const first = () => {
|
|
43
|
+
const o = block.options[0];
|
|
44
|
+
return o !== undefined && o.runnable ? { kind: 'take', command: o.command } : { kind: 'arbiter' };
|
|
45
|
+
};
|
|
46
|
+
if (untrusted.length > 0)
|
|
47
|
+
return { kind: 'human', stop: 'trust-grant' };
|
|
48
|
+
// A verdict that describes bytes no longer there, or a round that judged nothing, is a free
|
|
49
|
+
// re-run before it is anything else: no human or arbiter can honestly act on it, and the
|
|
50
|
+
// standing and fallback arms below would hand it to one with the re-run filtered away.
|
|
51
|
+
if (block.rule === 'stale-below-bound' || block.rule === 'malformed-rerun')
|
|
52
|
+
return first();
|
|
53
|
+
if (gate === 'design' && clean)
|
|
54
|
+
return { kind: 'human', stop: 'design-look' };
|
|
55
|
+
if ((gate === 'ship' || gate === 'decompose') && clean && run.standing !== undefined)
|
|
56
|
+
return { kind: 'arbiter' };
|
|
57
|
+
if (fellBack(run))
|
|
58
|
+
return { kind: 'arbiter' };
|
|
59
|
+
// A trust failure granted since the stop: the check never ran, so the fix is a re-run,
|
|
60
|
+
// not a revise — sending the author back would have them "fix" a command nobody judged.
|
|
61
|
+
if (failed.some((c) => (c.untrusted?.length ?? 0) > 0) && !boundReached(entries, gate)) {
|
|
62
|
+
return { kind: 'take', command: `witness gate ${gate} ${target}` };
|
|
63
|
+
}
|
|
64
|
+
if (block.rule === 'checks-failed') {
|
|
65
|
+
// amendment-ack is the one check an approve clears, so approving is a judgment about the
|
|
66
|
+
// amendment against the ask — the arbiter's, never the rule's (§11 call 10).
|
|
67
|
+
return failed.every((c) => c.name === 'amendment-ack') ? { kind: 'arbiter' } : first();
|
|
68
|
+
}
|
|
69
|
+
if (TAKEN.has(block.rule) || block.rule.startsWith('anchor-recurrence-'))
|
|
70
|
+
return first();
|
|
71
|
+
// bound · bound-stale · ladder-spent · pin-contradiction · reserved-stop-clean · manual-stop
|
|
72
|
+
return { kind: 'arbiter' };
|
|
73
|
+
}
|
|
74
|
+
// Row 173. Who made a disposition, in one spelling for every surface that says so
|
|
75
|
+
// (`decide --show`, `log`, `status`).
|
|
76
|
+
export function decidedBy(d) {
|
|
77
|
+
if (d.selected === 'policy')
|
|
78
|
+
return 'policy';
|
|
79
|
+
if (d.selected === 'arbiter')
|
|
80
|
+
return `arbiter · ${d.arbiter?.model ?? 'unknown'}`;
|
|
81
|
+
if (d.selected === 'affirmation')
|
|
82
|
+
return 'human · affirmation';
|
|
83
|
+
return 'human';
|
|
84
|
+
}
|
package/dist/battery.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { SESSION_DEFAULT } from './model.js';
|
|
2
|
+
import { ok, refuse } from './refusal.js';
|
|
3
|
+
import { invokeReviewerAsync, parseVerdictText } from './reviewer.js';
|
|
4
|
+
import { parseVerdict, verdictViolations } from './verdict.js';
|
|
5
|
+
// Row 169. Every lens walks the fallback chain on its own, from the pin. One lens that fell
|
|
6
|
+
// back makes the whole round a fallback round: `model` is the highest rung anyone answered
|
|
7
|
+
// on, so `fellBack` holds exactly when the sequential battery would have held it (106/107).
|
|
8
|
+
async function runLens(ctx, harness, chain, lens, opts) {
|
|
9
|
+
let rung = 0;
|
|
10
|
+
let prompt = lens.prompt;
|
|
11
|
+
let rerolled = false;
|
|
12
|
+
const failedOn = [];
|
|
13
|
+
for (let attempt = 0;; attempt++) {
|
|
14
|
+
let answered;
|
|
15
|
+
for (;;) {
|
|
16
|
+
const id = chain[rung];
|
|
17
|
+
const r = await invokeReviewerAsync(ctx, harness, {
|
|
18
|
+
...opts, prompt, model: id === SESSION_DEFAULT ? undefined : id, lens: lens.name,
|
|
19
|
+
});
|
|
20
|
+
if (r.ok) {
|
|
21
|
+
answered = r.value.text;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
if (rung >= chain.length - 1)
|
|
25
|
+
return refuse(r.violations);
|
|
26
|
+
failedOn.push(rung);
|
|
27
|
+
rung += 1;
|
|
28
|
+
}
|
|
29
|
+
const rawR = parseVerdictText(answered);
|
|
30
|
+
const parsedR = rawR.ok ? parseVerdict(rawR.value) : rawR;
|
|
31
|
+
const violations = parsedR.ok ? verdictViolations(parsedR.value, lens.reviewed) : parsedR.violations;
|
|
32
|
+
if (parsedR.ok && violations.length === 0) {
|
|
33
|
+
return ok({
|
|
34
|
+
verdict: { reviewer: lens.name, coverage: parsedR.value.coverage, findings: parsedR.value.findings },
|
|
35
|
+
failedOn, rung, rerolled,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (attempt === 0) {
|
|
39
|
+
// one self-repair reroll per reviewer — a single flaky verdict would
|
|
40
|
+
// otherwise poison the whole round as 'malformed'; the reroll is not
|
|
41
|
+
// part of the gate key, so cached rounds replay the settled result
|
|
42
|
+
rerolled = true;
|
|
43
|
+
prompt += `\n## Previous attempt rejected\n\n${violations.map((x) => `- ${x.field}: ${x.rule} — got ${x.got}; want ${x.want}`).join('\n')}\n\nRe-emit the complete corrected verdict JSON.\n`;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
return ok({ malformed: violations, failedOn, rung, rerolled });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Lenses launch together and are aggregated only once every one has settled, in battery
|
|
50
|
+
// order — the order a lens finishes in must never reach the journal. A lens that exhausts the
|
|
51
|
+
// chain refuses the whole gate, the first such lens in battery order speaking for it.
|
|
52
|
+
export async function runBattery(ctx, harness, chain, lenses, opts) {
|
|
53
|
+
const results = await Promise.all(lenses.map((l) => runLens(ctx, harness, chain, l, opts)));
|
|
54
|
+
const runs = [];
|
|
55
|
+
for (const r of results) {
|
|
56
|
+
if (!r.ok)
|
|
57
|
+
return refuse(r.violations);
|
|
58
|
+
runs.push(r.value);
|
|
59
|
+
}
|
|
60
|
+
const failed = new Set(runs.flatMap((r) => r.failedOn));
|
|
61
|
+
return ok({
|
|
62
|
+
verdicts: runs.flatMap((r) => (r.verdict ? [r.verdict] : [])),
|
|
63
|
+
malformed: runs.flatMap((r, i) => (r.malformed ? [{ reviewer: lenses[i].name, violations: r.malformed }] : [])),
|
|
64
|
+
fallback: [...new Set(chain.filter((_, i) => failed.has(i)))],
|
|
65
|
+
rerolled: lenses.filter((_, i) => runs[i].rerolled).map((l) => l.name),
|
|
66
|
+
model: chain[Math.max(0, ...runs.map((r) => r.rung))],
|
|
67
|
+
});
|
|
68
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -71,7 +71,7 @@ const VERB_USAGE = {
|
|
|
71
71
|
rename: 'witness rename <old-id> <new-id>',
|
|
72
72
|
satisfy: 'witness satisfy <doc-id> --need <text | index>',
|
|
73
73
|
dismiss: 'witness dismiss <artifact> --deferral <id|index> --cause <superseded|lens-retired|judged-wrong> --note "<why>"',
|
|
74
|
-
ship: 'witness ship <plan-id>',
|
|
74
|
+
ship: 'witness ship <plan-id> [--manual]',
|
|
75
75
|
start: 'witness start <plan-id>',
|
|
76
76
|
status: 'witness status — flows · blocked docs · reconcile rows · pending gates (bare `witness` is the same screen)',
|
|
77
77
|
sync: 'witness sync',
|
package/dist/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
3
|
import { isAbsolute, join } from 'node:path';
|
|
3
4
|
import { parse as parseYaml } from 'yaml';
|
|
@@ -137,6 +138,56 @@ export function resolveGates(raw) {
|
|
|
137
138
|
}
|
|
138
139
|
return ok({ reviewerTimeoutMs: val });
|
|
139
140
|
}
|
|
141
|
+
// Rows 171-175. Whether the CLI settles its own stops is a REPO fact — committed, read by
|
|
142
|
+
// every teammate's CLI alike — so it lives here and never in config.local.yaml. Spelled as
|
|
143
|
+
// the strings `on | off` and nothing else: YAML 1.1 reads `yes`/`on` as booleans and 1.2
|
|
144
|
+
// does not, so accepting booleans would make the same file mean two things across parsers.
|
|
145
|
+
export function resolveAutonomy(raw) {
|
|
146
|
+
const val = raw.autonomy;
|
|
147
|
+
if (val === undefined)
|
|
148
|
+
return ok(false);
|
|
149
|
+
if (val === 'on')
|
|
150
|
+
return ok(true);
|
|
151
|
+
if (val === 'off')
|
|
152
|
+
return ok(false);
|
|
153
|
+
return refuse([v('autonomy', 'invalid', String(val), 'on | off')]);
|
|
154
|
+
}
|
|
155
|
+
const MERGE_STYLES = ['merge', 'squash', 'rebase'];
|
|
156
|
+
export const DEFAULT_CI_SETTLE_MS = 60_000;
|
|
157
|
+
export const MAX_CI_SETTLE_MS = 1_800_000;
|
|
158
|
+
// The rest of `ship.*` (test, lint, branch) is still read loosely at its consumers; only
|
|
159
|
+
// the key with a closed value set is resolved here, and only when `ship` is a map.
|
|
160
|
+
export function resolveShip(raw) {
|
|
161
|
+
const conf = raw.ship;
|
|
162
|
+
if (typeof conf !== 'object' || conf === null || Array.isArray(conf))
|
|
163
|
+
return ok({ merge: 'merge', ciSettleMs: DEFAULT_CI_SETTLE_MS });
|
|
164
|
+
const val = conf.merge;
|
|
165
|
+
if (val !== undefined && (typeof val !== 'string' || !MERGE_STYLES.includes(val))) {
|
|
166
|
+
return refuse([v('ship.merge', 'invalid', String(val), 'merge | squash | rebase')]);
|
|
167
|
+
}
|
|
168
|
+
const settle = conf.ciSettleMs;
|
|
169
|
+
// Bounded by the watch window (30 minutes): a longer settle can never be met, and past
|
|
170
|
+
// 2^31-1 ms a Node timer fires at once — the window would silently become zero.
|
|
171
|
+
if (settle !== undefined && (typeof settle !== 'number' || !Number.isInteger(settle) || settle < 0 || settle > MAX_CI_SETTLE_MS)) {
|
|
172
|
+
return refuse([v('ship.ciSettleMs', 'invalid', String(settle), `an integer from 0 to ${MAX_CI_SETTLE_MS} — milliseconds a green check set must hold before witness merges`)]);
|
|
173
|
+
}
|
|
174
|
+
return ok({ merge: (val ?? 'merge'), ciSettleMs: settle ?? DEFAULT_CI_SETTLE_MS });
|
|
175
|
+
}
|
|
176
|
+
// Row 171 (F11). Autonomy is a COMMITTED repo fact: on only when HEAD's witness.config.yaml
|
|
177
|
+
// says so as well. A working-copy edit — the coding agent's, say — grants nothing, because
|
|
178
|
+
// the setting it would grant is merge authority over that agent's own work. `autonomyAt` reads
|
|
179
|
+
// any revision: the merge asks the shipped branch's remote copy (row 174), a fact the agent
|
|
180
|
+
// cannot make true with a local commit.
|
|
181
|
+
export function autonomyAt(root, rev) {
|
|
182
|
+
try {
|
|
183
|
+
const text = execFileSync('git', ['show', `${rev}:witness.config.yaml`], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
184
|
+
return (parseYaml(text) ?? {}).autonomy === 'on';
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const committedAutonomy = (root) => autonomyAt(root, 'HEAD');
|
|
140
191
|
const LOCAL_KEYS = ['reviewerExtensions', 'opener'];
|
|
141
192
|
export const localConfigPath = (root) => join(root, '.witness', 'config.local.yaml');
|
|
142
193
|
export function loadLocalConfig(root) {
|
|
@@ -235,6 +286,13 @@ export function loadConfig(root) {
|
|
|
235
286
|
const drive = resolveDrive(obj);
|
|
236
287
|
if (!drive.ok)
|
|
237
288
|
return refuse(drive.violations);
|
|
289
|
+
const autonomy = resolveAutonomy(obj);
|
|
290
|
+
if (!autonomy.ok)
|
|
291
|
+
return refuse(autonomy.violations);
|
|
292
|
+
const shipCfg = resolveShip(obj);
|
|
293
|
+
if (!shipCfg.ok)
|
|
294
|
+
return refuse(shipCfg.violations);
|
|
295
|
+
const uncommitted = autonomy.value && !committedAutonomy(root);
|
|
238
296
|
return ok({
|
|
239
297
|
schema,
|
|
240
298
|
raw: obj,
|
|
@@ -243,6 +301,10 @@ export function loadConfig(root) {
|
|
|
243
301
|
implement: implement.value,
|
|
244
302
|
gates: gates.value,
|
|
245
303
|
drive: drive.value,
|
|
246
|
-
|
|
304
|
+
autonomy: autonomy.value && !uncommitted,
|
|
305
|
+
ship: shipCfg.value,
|
|
306
|
+
warning: schema < SCHEMA_VERSION ? `schema ${schema} < ${SCHEMA_VERSION} — run witness migrate (reserved)`
|
|
307
|
+
: uncommitted ? 'autonomy: on is not committed — it stays off until witness.config.yaml is committed'
|
|
308
|
+
: undefined,
|
|
247
309
|
});
|
|
248
310
|
}
|
package/dist/criteria.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ensureTrusted } from './allowlist.js';
|
|
|
2
2
|
import { loadConfig } from './config.js';
|
|
3
3
|
import { matchesTag, sourceTags } from './matcher.js';
|
|
4
4
|
import { ok } from './refusal.js';
|
|
5
|
-
import { criteriaExcludes, execCommand, runFiltered, runFullSuite, runnerConfig } from './runner.js';
|
|
5
|
+
import { criteriaExcludes, execCommand, runFiltered, runFullSuite, runnerConfig, untrustedOf } from './runner.js';
|
|
6
6
|
import { canonicalSha } from './sha.js';
|
|
7
7
|
export async function runCriteria(runRoot, ctx, doc, opts = {}) {
|
|
8
8
|
const trustRoot = opts.trustRoot ?? runRoot;
|
|
@@ -21,12 +21,15 @@ export async function runCriteria(runRoot, ctx, doc, opts = {}) {
|
|
|
21
21
|
const list = (Array.isArray(doc.meta.criteria) ? doc.meta.criteria : []);
|
|
22
22
|
let suite = opts.suite;
|
|
23
23
|
let suiteProblem;
|
|
24
|
+
let suiteUntrusted;
|
|
24
25
|
if (rc.mode === 'full-suite' && suite === undefined && list.some((c) => typeof c.test === 'string')) {
|
|
25
26
|
const res = await runFullSuite(runRoot, ctx, rc, trustRoot);
|
|
26
27
|
if (res.ok)
|
|
27
28
|
suite = res.value.tests;
|
|
28
|
-
else
|
|
29
|
+
else {
|
|
29
30
|
suiteProblem = res.violations.map((x) => `${x.rule}: ${x.field}`).join('; ');
|
|
31
|
+
suiteUntrusted = untrustedOf(res.violations);
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
34
|
const src = rc.mode === 'filtered'
|
|
32
35
|
? sourceTags(runRoot, criteriaExcludes(cfg.value))
|
|
@@ -37,7 +40,8 @@ export async function runCriteria(runRoot, ctx, doc, opts = {}) {
|
|
|
37
40
|
if (typeof c.test === 'string') {
|
|
38
41
|
if (rc.mode === 'full-suite') {
|
|
39
42
|
if (!suite) {
|
|
40
|
-
criteria.push({ id: cid, kind: 'test', ok: false, detail: suiteProblem ?? 'suite did not run'
|
|
43
|
+
criteria.push({ id: cid, kind: 'test', ok: false, detail: suiteProblem ?? 'suite did not run',
|
|
44
|
+
...(suiteUntrusted !== undefined ? { untrusted: suiteUntrusted } : {}) });
|
|
41
45
|
continue;
|
|
42
46
|
}
|
|
43
47
|
const mine = suite.filter((t) => matchesTag(t.name, id));
|
|
@@ -52,7 +56,9 @@ export async function runCriteria(runRoot, ctx, doc, opts = {}) {
|
|
|
52
56
|
const run = await runFiltered(runRoot, ctx, rc.template, id, trustRoot);
|
|
53
57
|
const count = src?.counts.get(id) ?? 0;
|
|
54
58
|
if (!run.ok) {
|
|
55
|
-
|
|
59
|
+
const blocked = untrustedOf(run.violations);
|
|
60
|
+
criteria.push({ id: cid, kind: 'test', ok: false, detail: run.violations.map((x) => x.rule).join('; '),
|
|
61
|
+
...(blocked !== undefined ? { untrusted: blocked } : {}) });
|
|
56
62
|
}
|
|
57
63
|
else if (count === 0) {
|
|
58
64
|
criteria.push({ id: cid, kind: 'test', ok: false, detail: 'no tagged test found in source (grep side)' });
|
|
@@ -74,6 +80,7 @@ export async function runCriteria(runRoot, ctx, doc, opts = {}) {
|
|
|
74
80
|
criteria.push({
|
|
75
81
|
id: cid, kind: 'cmd', ok: false,
|
|
76
82
|
detail: `untrusted-${trust} — run: witness trust ${id} (or set WITNESS_TRUST_CMDS=1)`,
|
|
83
|
+
untrusted: c.cmd,
|
|
77
84
|
});
|
|
78
85
|
continue;
|
|
79
86
|
}
|
|
@@ -93,3 +100,19 @@ export async function runCriteria(runRoot, ctx, doc, opts = {}) {
|
|
|
93
100
|
criteria,
|
|
94
101
|
});
|
|
95
102
|
}
|
|
103
|
+
// The drift-lane row both code gates journal — one renderer, so implement and ship cannot
|
|
104
|
+
// disagree about it. `untrusted` (row 171) collects every command trust kept from running,
|
|
105
|
+
// deduplicated in criterion order, so the trust stop reads it from the run's own record.
|
|
106
|
+
export function laneCheck(lane) {
|
|
107
|
+
const untrusted = lane.ok
|
|
108
|
+
? [...new Set(lane.value.criteria.flatMap((c) => (c.untrusted !== undefined ? [c.untrusted] : [])))]
|
|
109
|
+
: [];
|
|
110
|
+
return {
|
|
111
|
+
name: 'drift-lane',
|
|
112
|
+
ok: lane.ok && lane.value.ok,
|
|
113
|
+
detail: lane.ok
|
|
114
|
+
? lane.value.criteria.map((c) => `${c.id}:${c.ok ? 'ok' : 'fail'}`).join(' · ')
|
|
115
|
+
: lane.violations.map((x) => `${x.field}:${x.rule}`).join(' · '),
|
|
116
|
+
...(untrusted.length > 0 ? { untrusted } : {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
package/dist/deferral.js
CHANGED
|
@@ -31,15 +31,28 @@ export function openDeferrals(entries) {
|
|
|
31
31
|
// Deliberately the INVERSE of a pin: a pin tells reviewers not to re-litigate, this tells
|
|
32
32
|
// them to report the thing if it is still there. Pins suppress findings; obligations
|
|
33
33
|
// solicit them — which is what makes the discharge automatic and evidence-shaped.
|
|
34
|
+
//
|
|
35
|
+
// The block states the rule the gate applies, word for word: discharge (gate.ts) reads an
|
|
36
|
+
// obligation the round does not report as fixed. It once said the opposite — "silence is read
|
|
37
|
+
// as still present" — which let a reviewer who still saw a deferred defect stay quiet and
|
|
38
|
+
// close it (row 122, amended 0.15.0). An omission is stored as `omission:<scope>`, which is no
|
|
39
|
+
// anchor a verdict can carry, so it is listed with the anchor object a finding must emit.
|
|
34
40
|
export function deferralsBlock(open) {
|
|
35
41
|
if (open.length === 0)
|
|
36
42
|
return '';
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
const line = (d, i) => {
|
|
44
|
+
const where = `${d.gate} round ${d.round} (${d.id})`;
|
|
45
|
+
if (!d.anchor.startsWith('omission:'))
|
|
46
|
+
return `${i + 1}. ${d.anchor} — ${where}`;
|
|
47
|
+
const scope = d.anchor.slice('omission:'.length);
|
|
48
|
+
return `${i + 1}. omission · scope ${scope} — ${where} — report it with "anchor": { "kind": "omission", "scope": ${JSON.stringify(scope)} }`;
|
|
49
|
+
};
|
|
50
|
+
return '## Open deferrals (approved over findings — report these if they still hold)\n\n' +
|
|
51
|
+
'This artifact was approved over the findings below rather than fixed. They are NOT settled ' +
|
|
52
|
+
'policy and they are NOT pins. If a defect is still present, report it as a finding anchored ' +
|
|
53
|
+
'exactly as listed: that keeps its obligation open. Silence is read as fixed: an obligation ' +
|
|
54
|
+
'this round does not report is discharged.\n\n' +
|
|
55
|
+
open.map(line).join('\n') + '\n\n';
|
|
43
56
|
}
|
|
44
57
|
// D122 + D166. A debt changes homes when the artifact holding it stops being the one the next
|
|
45
58
|
// effort will meet: a plan's merge hands its open obligations to the parent spec (stamp.ts), a
|
package/dist/evidence.js
CHANGED
|
@@ -6,7 +6,7 @@ import { entryLine, appendEntry, journalRel, readStream } from './journal.js';
|
|
|
6
6
|
import { mergeReports, reportFiles } from './junit.js';
|
|
7
7
|
import { extractCanonicalTags, matchesTag } from './matcher.js';
|
|
8
8
|
import { ok, refuse, v } from './refusal.js';
|
|
9
|
-
import { runFiltered, runFullSuite, runnerConfig } from './runner.js';
|
|
9
|
+
import { runFiltered, runFullSuite, runnerConfig, untrustedOf } from './runner.js';
|
|
10
10
|
import { git, stateCommit, tryGit } from './gitio.js';
|
|
11
11
|
import { kv } from './toon.js';
|
|
12
12
|
import { withTxn } from './txn.js';
|
|
@@ -269,7 +269,9 @@ export async function runRegression(runRoot, ctx, trustRoot, specIds, known) {
|
|
|
269
269
|
memo.set(id, run);
|
|
270
270
|
}
|
|
271
271
|
if (!run.ok) {
|
|
272
|
-
|
|
272
|
+
const blocked = untrustedOf(run.violations);
|
|
273
|
+
out.push({ spec: id, state: 'unrunnable', detail: run.violations.map((x) => x.rule).join(' · '),
|
|
274
|
+
...(blocked !== undefined ? { untrusted: blocked } : {}) });
|
|
273
275
|
continue;
|
|
274
276
|
}
|
|
275
277
|
const failed = run.value.tests.filter((t) => !t.ok).length;
|