@popovych.co/witness 0.28.2 → 0.29.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.
Files changed (207) hide show
  1. package/README.md +15 -3
  2. package/dist/abandon.d.ts +67 -0
  3. package/dist/act.d.ts +17 -0
  4. package/dist/act.js +70 -0
  5. package/dist/adopt.d.ts +21 -0
  6. package/dist/allowlist.d.ts +48 -0
  7. package/dist/allowlist.js +79 -5
  8. package/dist/arbiter.d.ts +37 -0
  9. package/dist/arbiter.js +7 -5
  10. package/dist/ask.d.ts +29 -0
  11. package/dist/ask.js +11 -5
  12. package/dist/autonomy.d.ts +46 -0
  13. package/dist/autonomy.js +24 -12
  14. package/dist/awake.d.ts +15 -0
  15. package/dist/basis.d.ts +9 -0
  16. package/dist/battery.d.ts +23 -0
  17. package/dist/bin.d.ts +2 -0
  18. package/dist/busy.d.ts +38 -0
  19. package/dist/busy.js +274 -0
  20. package/dist/caps.d.ts +21 -0
  21. package/dist/caps.js +24 -3
  22. package/dist/cli.d.ts +18 -0
  23. package/dist/config-file.d.ts +12 -0
  24. package/dist/config.d.ts +96 -0
  25. package/dist/config.js +2 -1
  26. package/dist/contain.d.ts +16 -0
  27. package/dist/context.d.ts +25 -0
  28. package/dist/criteria.d.ts +27 -0
  29. package/dist/criteria.js +2 -1
  30. package/dist/decide-view.d.ts +52 -0
  31. package/dist/decide-view.js +155 -0
  32. package/dist/decisions.d.ts +23 -0
  33. package/dist/deferral.d.ts +26 -0
  34. package/dist/delta.d.ts +58 -0
  35. package/dist/departure.d.ts +66 -0
  36. package/dist/design.d.ts +34 -0
  37. package/dist/drafts.d.ts +31 -0
  38. package/dist/drafts.js +5 -3
  39. package/dist/drift.d.ts +23 -0
  40. package/dist/drive-presence.d.ts +30 -0
  41. package/dist/drive-presence.js +29 -6
  42. package/dist/drive-report.d.ts +24 -0
  43. package/dist/drive-report.js +4 -4
  44. package/dist/drive.d.ts +114 -0
  45. package/dist/drive.js +328 -115
  46. package/dist/dsl.d.ts +23 -0
  47. package/dist/dsl.js +8 -3
  48. package/dist/evidence.d.ts +67 -0
  49. package/dist/evidence.js +8 -2
  50. package/dist/floor.d.ts +6 -0
  51. package/dist/fm.d.ts +9 -0
  52. package/dist/gate-run-view.d.ts +57 -0
  53. package/dist/gate-run-view.js +100 -0
  54. package/dist/gate.d.ts +91 -0
  55. package/dist/gate.js +51 -71
  56. package/dist/gates/decompose.d.ts +1 -0
  57. package/dist/gates/decompose.js +3 -1
  58. package/dist/gates/design.d.ts +1 -0
  59. package/dist/gates/design.js +6 -2
  60. package/dist/gates/implement.d.ts +1 -0
  61. package/dist/gates/implement.js +20 -5
  62. package/dist/gates/index.d.ts +5 -0
  63. package/dist/gates/plan.d.ts +1 -0
  64. package/dist/gates/plan.js +10 -4
  65. package/dist/gates/ship.d.ts +1 -0
  66. package/dist/gates/ship.js +13 -6
  67. package/dist/gitio.d.ts +35 -0
  68. package/dist/gitio.js +31 -3
  69. package/dist/glob.d.ts +2 -0
  70. package/dist/harness.d.ts +73 -0
  71. package/dist/harness.js +36 -15
  72. package/dist/history.d.ts +10 -0
  73. package/dist/idlists.d.ts +2 -0
  74. package/dist/install.d.ts +29 -0
  75. package/dist/journal.d.ts +74 -0
  76. package/dist/journal.js +5 -1
  77. package/dist/junit.d.ts +9 -0
  78. package/dist/live.d.ts +29 -0
  79. package/dist/live.js +15 -3
  80. package/dist/lock.d.ts +9 -0
  81. package/dist/matcher.d.ts +8 -0
  82. package/dist/migration.d.ts +25 -0
  83. package/dist/model.d.ts +8 -0
  84. package/dist/models.d.ts +9 -0
  85. package/dist/models.js +10 -0
  86. package/dist/needs-you.d.ts +91 -0
  87. package/dist/needs-you.js +153 -51
  88. package/dist/needs.d.ts +44 -0
  89. package/dist/needs.js +37 -7
  90. package/dist/notify.d.ts +12 -0
  91. package/dist/opener.d.ts +15 -0
  92. package/dist/pin.d.ts +12 -0
  93. package/dist/pin.js +9 -2
  94. package/dist/principles.d.ts +3 -0
  95. package/dist/probe.d.ts +1 -0
  96. package/dist/progress.d.ts +3 -0
  97. package/dist/progress.js +2 -0
  98. package/dist/recommend.d.ts +31 -0
  99. package/dist/recommend.js +51 -42
  100. package/dist/refusal.d.ts +20 -0
  101. package/dist/refusal.js +12 -4
  102. package/dist/registry.d.ts +1 -0
  103. package/dist/released-comments.d.ts +1 -0
  104. package/dist/review.d.ts +27 -0
  105. package/dist/reviewed.d.ts +27 -0
  106. package/dist/reviewed.js +9 -0
  107. package/dist/reviewer.d.ts +47 -0
  108. package/dist/rounds.d.ts +139 -0
  109. package/dist/rounds.js +75 -25
  110. package/dist/runner-lock.d.ts +5 -0
  111. package/dist/runner.d.ts +30 -0
  112. package/dist/scan.d.ts +27 -0
  113. package/dist/schemas.d.ts +11 -0
  114. package/dist/schemas.js +7 -3
  115. package/dist/session-clock.d.ts +16 -0
  116. package/dist/settings.d.ts +73 -0
  117. package/dist/settings.js +12 -2
  118. package/dist/settle.d.ts +62 -0
  119. package/dist/settle.js +177 -39
  120. package/dist/sha.d.ts +5 -0
  121. package/dist/ship-outcome.d.ts +24 -0
  122. package/dist/ship-outcome.js +76 -0
  123. package/dist/ship.d.ts +31 -0
  124. package/dist/ship.js +324 -82
  125. package/dist/slice.d.ts +45 -0
  126. package/dist/slice.js +2 -2
  127. package/dist/snapshot.d.ts +10 -0
  128. package/dist/spawn.d.ts +22 -0
  129. package/dist/stamp.d.ts +33 -0
  130. package/dist/stamp.js +20 -8
  131. package/dist/steps.d.ts +31 -0
  132. package/dist/steps.js +39 -10
  133. package/dist/toon.d.ts +17 -0
  134. package/dist/toon.js +150 -14
  135. package/dist/txn.d.ts +28 -0
  136. package/dist/usage.d.ts +25 -0
  137. package/dist/verbs/abandon.d.ts +2 -0
  138. package/dist/verbs/adopt.d.ts +2 -0
  139. package/dist/verbs/adopt.js +9 -4
  140. package/dist/verbs/ask.d.ts +2 -0
  141. package/dist/verbs/check.d.ts +2 -0
  142. package/dist/verbs/check.js +29 -10
  143. package/dist/verbs/clean.d.ts +2 -0
  144. package/dist/verbs/dashboard.d.ts +59 -0
  145. package/dist/verbs/dashboard.js +11 -3
  146. package/dist/verbs/decide.d.ts +46 -0
  147. package/dist/verbs/decide.js +168 -149
  148. package/dist/verbs/design.d.ts +2 -0
  149. package/dist/verbs/design.js +8 -5
  150. package/dist/verbs/diff.d.ts +2 -0
  151. package/dist/verbs/diff.js +4 -2
  152. package/dist/verbs/dismiss.d.ts +2 -0
  153. package/dist/verbs/dispatch.d.ts +2 -0
  154. package/dist/verbs/dispatch.js +2 -2
  155. package/dist/verbs/draft.d.ts +2 -0
  156. package/dist/verbs/draft.js +6 -3
  157. package/dist/verbs/drive.d.ts +2 -0
  158. package/dist/verbs/evidence.d.ts +5 -0
  159. package/dist/verbs/evidence.js +40 -3
  160. package/dist/verbs/floor.d.ts +2 -0
  161. package/dist/verbs/gate.d.ts +3 -0
  162. package/dist/verbs/index-verb.d.ts +2 -0
  163. package/dist/verbs/init.d.ts +2 -0
  164. package/dist/verbs/log.d.ts +9 -0
  165. package/dist/verbs/migrate.d.ts +13 -0
  166. package/dist/verbs/next.d.ts +78 -0
  167. package/dist/verbs/next.js +373 -131
  168. package/dist/verbs/read.d.ts +2 -0
  169. package/dist/verbs/read.js +3 -1
  170. package/dist/verbs/recap.d.ts +28 -0
  171. package/dist/verbs/recap.js +3 -3
  172. package/dist/verbs/recover.d.ts +5 -0
  173. package/dist/verbs/recover.js +14 -9
  174. package/dist/verbs/rename.d.ts +2 -0
  175. package/dist/verbs/rename.js +1 -1
  176. package/dist/verbs/retry.d.ts +2 -0
  177. package/dist/verbs/review.d.ts +2 -0
  178. package/dist/verbs/review.js +1 -1
  179. package/dist/verbs/satisfy.d.ts +2 -0
  180. package/dist/verbs/ship.d.ts +3 -0
  181. package/dist/verbs/start.d.ts +2 -0
  182. package/dist/verbs/start.js +12 -7
  183. package/dist/verbs/step-close.d.ts +2 -0
  184. package/dist/verbs/sync.d.ts +15 -0
  185. package/dist/verbs/trust.d.ts +4 -0
  186. package/dist/verbs/trust.js +34 -32
  187. package/dist/verbs/turn.d.ts +2 -0
  188. package/dist/verbs/wait.d.ts +9 -0
  189. package/dist/verbs/wait.js +33 -8
  190. package/dist/verbs/write.d.ts +18 -0
  191. package/dist/verbs/write.js +11 -5
  192. package/dist/verdict.d.ts +60 -0
  193. package/dist/version.d.ts +4 -0
  194. package/dist/worker-stream.d.ts +22 -0
  195. package/dist/worktree.d.ts +22 -0
  196. package/dist/worktree.js +1 -1
  197. package/package.json +7 -1
  198. package/plugin/.claude-plugin/plugin.json +1 -1
  199. package/plugin/commands/witness.md +17 -11
  200. package/plugin/hooks/canon-guard.mjs +71 -10
  201. package/plugin/hooks/session-dashboard.sh +1 -1
  202. package/plugin/skills/witness-brainstorm/SKILL.md +3 -3
  203. package/plugin/skills/witness-decompose/SKILL.md +3 -3
  204. package/plugin/skills/witness-design/SKILL.md +2 -2
  205. package/plugin/skills/witness-implement/SKILL.md +5 -5
  206. package/plugin/skills/witness-plan/SKILL.md +3 -3
  207. package/plugin/skills/witness-ship/SKILL.md +3 -3
@@ -0,0 +1,52 @@
1
+ import { type Act } from './act.js';
2
+ import type { Config } from './config.js';
3
+ import { type GateRunView } from './gate-run-view.js';
4
+ import './gates/index.js';
5
+ import { type PolicyPin } from './journal.js';
6
+ import { type Decision } from './recommend.js';
7
+ import { type DecisionEntry } from './rounds.js';
8
+ import { type Canon } from './scan.js';
9
+ import type { GateName } from './settings.js';
10
+ export interface LastRun {
11
+ round: number;
12
+ sha: string;
13
+ outcome: string;
14
+ }
15
+ export type Disposition = Pick<DecisionEntry, 'decision' | 'selected' | 'arbiter' | 'reason' | 'note'>;
16
+ export type DecideView = {
17
+ gate: string;
18
+ target: string;
19
+ autonomy: boolean;
20
+ } & ({
21
+ state: 'no-runs';
22
+ } | {
23
+ state: 'reopened';
24
+ by: {
25
+ gate: string;
26
+ artifact: string;
27
+ round: number;
28
+ };
29
+ note?: string;
30
+ last: LastRun;
31
+ disposition?: Disposition;
32
+ exits: Act[];
33
+ } | {
34
+ state: 'settled';
35
+ disposition: Disposition;
36
+ last: LastRun;
37
+ } | {
38
+ state: 'parked';
39
+ why: string;
40
+ disposition: Disposition;
41
+ last: LastRun;
42
+ reopen: Act[];
43
+ } | {
44
+ state: 'actionable';
45
+ run: GateRunView;
46
+ pins: PolicyPin[];
47
+ disposition?: Disposition;
48
+ block?: Decision;
49
+ exits: Act[];
50
+ });
51
+ export declare function decideView(root: string, cfg: Config, canon: Canon, gate: GateName, target: string): DecideView;
52
+ export declare function decideViewLines(view: DecideView): string[];
@@ -0,0 +1,155 @@
1
+ import { cliAct, exitsLine, reopenRows } from './act.js';
2
+ import { untrustedCmdsFor } from './allowlist.js';
3
+ import { autonomyLines, decidedBy } from './autonomy.js';
4
+ import { gateSpec } from './gate.js';
5
+ import { gateRunLines, gateRunView } from './gate-run-view.js';
6
+ // The gate specs `decideView` reads (`currentSha`, `upstreamOf`): registered by loading this
7
+ // module, so a reader with no CLI around it (the UI) gets them as the decide verb does.
8
+ import './gates/index.js';
9
+ import { policyPins, readStream } from './journal.js';
10
+ import { liftedHolds } from './needs.js';
11
+ import { recommend, renderDecision } from './recommend.js';
12
+ import { exitActs, lastGateRun, openReopen, reopenActs } from './rounds.js';
13
+ import { gateParked, parkOwed, parkedBy } from './verbs/next.js';
14
+ import { criteriaOwner } from './scan.js';
15
+ import { short } from './sha.js';
16
+ import { cmd, kv, rows, logSafe } from './toon.js';
17
+ // The record's fields the screen reads, each present only when the record carries it.
18
+ function dispositionOf(d) {
19
+ return {
20
+ decision: d.decision,
21
+ ...(d.selected !== undefined ? { selected: d.selected } : {}),
22
+ ...(d.arbiter !== undefined ? { arbiter: d.arbiter } : {}),
23
+ ...(d.reason !== undefined ? { reason: d.reason } : {}),
24
+ ...(d.note !== undefined ? { note: d.note } : {}),
25
+ };
26
+ }
27
+ export function decideView(root, cfg, canon, gate, target) {
28
+ const spec = gateSpec(gate);
29
+ if (spec === undefined)
30
+ throw new Error(`gate ${gate} is not registered`);
31
+ const entries = readStream(root, target);
32
+ const last = lastGateRun(entries, gate);
33
+ const upstream = spec.upstreamOf?.(root, canon, target);
34
+ const head = { gate, target, autonomy: cfg.autonomy };
35
+ if (!last)
36
+ return { ...head, state: 'no-runs' };
37
+ const reopen = openReopen(entries, gate);
38
+ const decisionsAfter = entries
39
+ .slice(entries.lastIndexOf(last) + 1)
40
+ .filter((e) => e.t === 'human-decision' && e.gate === gate)
41
+ .map((e) => e);
42
+ // A caused_by decision is a REOPEN, not a disposition — it can never settle the run
43
+ // above it, and pairing the two is what presented 15 settled findings as current.
44
+ // The LAST disposition is the state (D94): `find` returned the first, so a
45
+ // revise→approve reported `decision: revise` on a gate that is settled.
46
+ const decided = decisionsAfter.filter((d) => d.caused_by === undefined).at(-1);
47
+ const disposition = decided === undefined ? undefined : dispositionOf(decided);
48
+ // Staleness is a fact about content, not about being reopened. Hardcoding it printed
49
+ // `witness gate …` in the one state where the gate answers changed-nothing. An
50
+ // uncomputable sha is NOT staleness — same doctrine as the approve-time check.
51
+ const shownSha = spec.currentSha?.(root, canon, cfg, target);
52
+ const stale = (shownSha !== undefined && shownSha !== last.reviewed_sha) ||
53
+ liftedHolds(criteriaOwner(canon, target), last).length > 0;
54
+ const lastRun = { round: last.round, sha: short(last.reviewed_sha), outcome: last.outcome };
55
+ if (reopen) {
56
+ const by = reopen.caused_by;
57
+ return {
58
+ ...head, state: 'reopened', by: { gate: by.gate, artifact: by.artifact, round: by.round },
59
+ ...(reopen.note !== undefined ? { note: reopen.note } : {}),
60
+ last: lastRun, ...(disposition ? { disposition } : {}),
61
+ exits: exitActs(gate, target, entries, stale, upstream),
62
+ };
63
+ }
64
+ if (disposition && gateParked(entries, gate)) {
65
+ const anchor = (last.verdicts ?? []).flatMap((rv) => rv.findings.filter((f) => f.blocking))
66
+ .map((f) => (typeof f.anchor === 'string' ? f.anchor : `omission:${f.anchor.scope}`))[0] ?? last.standing ?? last.outcome;
67
+ return {
68
+ ...head, state: 'parked', why: parkedBy(entries, gate, anchor), disposition, last: lastRun,
69
+ reopen: reopenActs(gate, target, entries, upstream, parkOwed(root, cfg, canon, gate, target, entries)),
70
+ };
71
+ }
72
+ if (disposition && disposition.decision !== 'revise' && disposition.decision !== 'revise-upstream') {
73
+ return { ...head, state: 'settled', disposition, last: lastRun };
74
+ }
75
+ // pending (no disposition) or revise (the author's input): the verdict is actionable
76
+ // The surface a human actually reads while deciding, so it is the one that most owes a
77
+ // ranking rather than a menu. `undefined` is stale with no decision pending, where no
78
+ // act but the re-gate is legal and the exits line already says exactly that (D131).
79
+ // D154: the block's trusting twins name the artifact's `cmd:` criteria this repo does not
80
+ // trust yet.
81
+ const block = recommend({
82
+ gate, target, entries, upstream, stale, untrustedCmds: untrustedCmdsFor(root, criteriaOwner(canon, target)),
83
+ });
84
+ return {
85
+ ...head, state: 'actionable', run: gateRunView(last, 'ran', entries), pins: policyPins(entries),
86
+ ...(disposition ? { disposition } : {}), ...(block ? { block } : {}),
87
+ exits: exitActs(gate, target, entries, stale, upstream),
88
+ };
89
+ }
90
+ // Rows 139/203. The screen `decide --show` prints, from its view, in the verb's order: the
91
+ // autonomy setting, then the state. A table is one element, its rows joined, as the verb has
92
+ // always printed it (`gateRunLines`).
93
+ export function decideViewLines(view) {
94
+ const out = [...autonomyLines(view)];
95
+ const { gate, target } = view;
96
+ if (view.state === 'no-runs') {
97
+ out.push(kv('decide', `no gate-runs for ${gate} ${target}`));
98
+ return out;
99
+ }
100
+ if (view.state === 'reopened') {
101
+ out.push(kv('gate', gate));
102
+ out.push(kv('target', target));
103
+ out.push(kv('state', 'reopened — the gate must run again'));
104
+ out.push(kv('reopened-by', `${view.by.gate} ${view.by.artifact} (round ${view.by.round})`));
105
+ if (view.note)
106
+ out.push(kv('note', view.note));
107
+ // Row 239. The log it names is an act's line, here and on the settled screen below.
108
+ out.push(kv('last-run', `round ${view.last.round} @${view.last.sha} — ${view.last.outcome}${view.disposition ? `, ${view.disposition.decision}` : ''} · ${cliAct('log', target).line}`));
109
+ out.push(cmd('exits', exitsLine(view.exits)));
110
+ return out;
111
+ }
112
+ if (view.state === 'parked') {
113
+ out.push(kv('gate', gate));
114
+ out.push(kv('target', target));
115
+ out.push(`state: parked — ${logSafe(view.why)}`);
116
+ out.push(kv('decided-by', decidedBy(view.disposition)));
117
+ out.push(kv('last-run', `round ${view.last.round} @${view.last.sha} — ${view.last.outcome} · ${cliAct('log', target).line}`));
118
+ out.push(...reopenRows(view.reopen));
119
+ return out;
120
+ }
121
+ if (view.state === 'settled') {
122
+ const d = view.disposition;
123
+ out.push(kv('gate', gate));
124
+ out.push(kv('target', target));
125
+ out.push(kv('state', `settled — ${d.decision}`));
126
+ out.push(kv('decided-by', decidedBy(d)));
127
+ if (d.reason)
128
+ out.push(kv('reason', d.reason));
129
+ if (d.note)
130
+ out.push(kv('note', d.note));
131
+ out.push(kv('last-run', `round ${view.last.round} @${view.last.sha} — ${view.last.outcome} · ${cliAct('log', target).line}`));
132
+ // no exits: the gate is genuinely terminal here. Point at the one verb that owns
133
+ // what comes next rather than re-deriving routing in a second place (D101).
134
+ out.push('help: witness next');
135
+ return out;
136
+ }
137
+ out.push(...gateRunLines(view.run));
138
+ if (view.pins.length > 0) {
139
+ out.push(rows('pins', ['ordinal', 'text'], view.pins.map((p) => ({ ordinal: p.ordinal, text: p.text }))).join('\n'));
140
+ }
141
+ if (view.disposition) {
142
+ const d = view.disposition;
143
+ out.push(kv('decision', d.decision));
144
+ out.push(kv('decided-by', decidedBy(d)));
145
+ if (d.reason)
146
+ out.push(kv('reason', d.reason));
147
+ if (d.note)
148
+ out.push(kv('note', d.note));
149
+ }
150
+ if (view.block)
151
+ out.push(...renderDecision(view.block));
152
+ else
153
+ out.push(cmd('exits', exitsLine(view.exits)));
154
+ return out;
155
+ }
@@ -0,0 +1,23 @@
1
+ import { type RecapEntry } from './journal.js';
2
+ import type { CanonDoc } from './scan.js';
3
+ export type RecapDecision = {
4
+ id: string;
5
+ text: string;
6
+ };
7
+ export declare function carriedDecisions(root: string, doc: CanonDoc): {
8
+ effort: string;
9
+ decisions: RecapDecision[];
10
+ } | undefined;
11
+ export declare function canonicalDecisions(decisions: readonly RecapDecision[]): RecapDecision[];
12
+ export declare function decisionsSha(decisions: readonly RecapDecision[]): string | undefined;
13
+ export type DecisionChange = {
14
+ id: string;
15
+ change: 'added' | 'changed' | 'removed';
16
+ text: string;
17
+ };
18
+ export declare function decisionDelta(root: string, base: {
19
+ planId?: string;
20
+ decisions?: string;
21
+ }, spec: CanonDoc): DecisionChange[] | undefined;
22
+ export declare function decisionLines(root: string, doc: CanonDoc): string[];
23
+ export declare function recapLines(recap: RecapEntry): string[];
@@ -0,0 +1,26 @@
1
+ import type { Entry, EntryType } from './journal.js';
2
+ export type DeferralKind = 'artifact-debt' | 'lens-suspicion';
3
+ export type DismissCause = 'superseded' | 'lens-retired' | 'judged-wrong';
4
+ export declare const DISMISS_CAUSES: readonly DismissCause[];
5
+ export interface DeferralEntry {
6
+ v: 1;
7
+ t: 'deferral';
8
+ id: string;
9
+ artifact: string;
10
+ gate: string;
11
+ round: number;
12
+ anchor: string;
13
+ kind: DeferralKind;
14
+ caused_by_run: string;
15
+ moved_from?: string;
16
+ }
17
+ export declare const newDeferralId: () => string;
18
+ export declare function openDeferrals(entries: Entry[]): DeferralEntry[];
19
+ export declare function deferralsBlock(open: DeferralEntry[]): string;
20
+ export declare function deferralMoves(entries: Entry[], from: string, to: string, which?: (d: DeferralEntry) => boolean): Array<{
21
+ stream: string;
22
+ entry: {
23
+ t: EntryType;
24
+ [k: string]: unknown;
25
+ };
26
+ }>;
@@ -0,0 +1,58 @@
1
+ import type { Entry } from './journal.js';
2
+ import { type Lens } from './reviewer.js';
3
+ import { type GateRunEntry, type ReviewerVerdict } from './rounds.js';
4
+ import { type AnchorInput, type Reviewed } from './verdict.js';
5
+ export type UnitState = 'changed' | 'unchanged' | 'context';
6
+ export interface DeltaView {
7
+ state(anchor: AnchorInput): UnitState;
8
+ }
9
+ export declare function deltaView(root: string, reviewed: Reviewed, from: string, to: string): DeltaView;
10
+ export interface PriorFinding {
11
+ reviewer: string;
12
+ anchor: AnchorInput;
13
+ claim: string;
14
+ }
15
+ export declare function reportedBy(prior: readonly AnchorInput[], paths: boolean): (a: AnchorInput) => boolean;
16
+ export interface DeltaPlan {
17
+ base: GateRunEntry;
18
+ baseRound: number;
19
+ prior: PriorFinding[];
20
+ reported: (a: AnchorInput) => boolean;
21
+ view: DeltaView;
22
+ diff: string;
23
+ sections?: string[];
24
+ paths?: string[];
25
+ }
26
+ export declare function planDelta(root: string, entries: Entry[], gate: string, cur: {
27
+ reviewedSha: string;
28
+ snapshot?: {
29
+ tree: string;
30
+ context: string;
31
+ };
32
+ basis: string;
33
+ reviewed: Reviewed;
34
+ inDelta: (lens: string) => boolean;
35
+ }): DeltaPlan | undefined;
36
+ export declare function deltaBlock(d: {
37
+ baseRound: number;
38
+ prior: readonly PriorFinding[];
39
+ diff: string;
40
+ sections?: readonly string[];
41
+ paths?: readonly string[];
42
+ }): string;
43
+ export declare function contextDigest(...parts: string[]): string;
44
+ export declare function basisSha(lenses: readonly Lens[], context: string, pin: string, harness: string): string;
45
+ export declare function demote(verdicts: ReviewerVerdict[], d: {
46
+ baseRound: number;
47
+ reported: (a: AnchorInput) => boolean;
48
+ view: DeltaView;
49
+ }, inDelta: (lens: string) => boolean): ReviewerVerdict[];
50
+ export interface OutstandingDemotion {
51
+ reviewer: string;
52
+ anchor: AnchorInput;
53
+ claim: string;
54
+ round: number;
55
+ since: number;
56
+ }
57
+ export declare function outstandingDemotions(entries: Entry[], gate: string): OutstandingDemotion[];
58
+ export declare function demotionsBlock(gate: string, list: readonly OutstandingDemotion[]): string;
@@ -0,0 +1,66 @@
1
+ import type { CanonPaths } from './config.js';
2
+ import { type RawDoc } from './fm.js';
3
+ import { type Entry, type EntryType, type StatusEntry } from './journal.js';
4
+ import { type Violation } from './refusal.js';
5
+ import { type Canon, type CanonDoc } from './scan.js';
6
+ export declare function canonExit(entries: Entry[]): StatusEntry | undefined;
7
+ export declare function departedStreams(root: string, canon: Canon): string[];
8
+ export interface Departure {
9
+ entry: StatusEntry;
10
+ files: string[];
11
+ remove: () => void;
12
+ }
13
+ export declare function prepareDeparture(root: string, paths: CanonPaths, spec: CanonDoc, entry: StatusEntry): Departure;
14
+ export interface Return {
15
+ entry: StatusEntry;
16
+ files: string[];
17
+ restore: () => void;
18
+ moves: Array<{
19
+ stream: string;
20
+ entry: {
21
+ t: EntryType;
22
+ [k: string]: unknown;
23
+ };
24
+ }>;
25
+ rel: string;
26
+ by: string;
27
+ depends: string[];
28
+ }
29
+ export interface Way {
30
+ returns: Return[];
31
+ unwound: StatusEntry[];
32
+ }
33
+ export interface WriteAct {
34
+ effort: string;
35
+ commit: string;
36
+ created: boolean;
37
+ }
38
+ export type TakenBack = (id: string, sha: string, rel: string, at: string) => WriteAct | undefined;
39
+ export interface At {
40
+ src: string;
41
+ blob: Buffer;
42
+ doc: RawDoc;
43
+ }
44
+ export type Walked = ({
45
+ end: 'content';
46
+ passed: WriteAct[];
47
+ } & At) | {
48
+ end: 'create';
49
+ act: WriteAct;
50
+ passed: WriteAct[];
51
+ } | {
52
+ end: 'lost';
53
+ act: WriteAct;
54
+ passed: WriteAct[];
55
+ at?: At;
56
+ };
57
+ export declare function walkBack(root: string, rel: string, id: string, at: At, takenBack: TakenBack, seen: Set<string>): Walked;
58
+ export declare function takeBack(root: string, rel: string, id: string, act: WriteAct, takenBack: TakenBack): Walked | {
59
+ end: 'unreadable';
60
+ src: string;
61
+ blob: Buffer;
62
+ passed: WriteAct[];
63
+ };
64
+ export declare function prepareReturns(root: string, paths: CanonPaths, commit: string, successor: string, takenBack?: TakenBack): Way;
65
+ export declare function idRetired(root: string, id: string, type: string): Violation | undefined;
66
+ export declare function pathRetired(root: string, canon: Canon, rel: string, id: string): Violation | undefined;
@@ -0,0 +1,34 @@
1
+ import type { CanonPaths } from './config.js';
2
+ import { type Entry } from './journal.js';
3
+ import { type Violation } from './refusal.js';
4
+ import type { CanonDoc } from './scan.js';
5
+ import type { Reviewed } from './verdict.js';
6
+ export declare function elementIds(html: string): string[];
7
+ export type ControlKind = 'select' | 'details' | 'dialog' | 'popover' | 'menu' | 'listbox' | 'tooltip' | 'tabpanel' | 'alertdialog' | 'collapsed' | 'hidden' | 'template';
8
+ export type LookControl = {
9
+ anchor: string;
10
+ line: number;
11
+ kind: ControlKind;
12
+ holds: string;
13
+ };
14
+ export declare const CONTROLS_NOTE = "from markup only \u2014 states a CSS class or a script draws, :hover and :focus styles, and content past a scrolling pane are not listed; read the source for those";
15
+ export declare function lookControls(html: string): LookControl[];
16
+ export declare function controlsBlock(html: string): string[];
17
+ export declare function designReviewed(html: string | undefined, spec: CanonDoc): {
18
+ reviewed: Reviewed;
19
+ promptBody: string;
20
+ };
21
+ export declare function validateDesignArtifact(html: string): Violation[];
22
+ export declare function htmlSha(html: string): string;
23
+ export declare function designPairSha(html: string, spec: CanonDoc): string;
24
+ export declare function designGateSha(html: string | undefined, spec: CanonDoc): string;
25
+ export declare function designCurrentSha(root: string, paths: CanonPaths, spec: CanonDoc): string;
26
+ export declare function designRel(paths: CanonPaths, specId: string): string;
27
+ export declare function designStamp(spec: CanonDoc): {
28
+ sha: string;
29
+ spec: string;
30
+ } | undefined;
31
+ export declare function designPending(root: string, spec: CanonDoc): boolean;
32
+ export declare function designArtifactCurrent(root: string, spec: CanonDoc): boolean;
33
+ export declare function designShown(entries: Entry[], sha: string): boolean;
34
+ export declare function designUnseen(root: string, paths: CanonPaths, specId: string): string | undefined;
@@ -0,0 +1,31 @@
1
+ import { type Result, type Violation } from './refusal.js';
2
+ export declare const DRAFTS_DIR = ".witness/drafts";
3
+ export type DraftKey = {
4
+ kind: 'ask';
5
+ id: string;
6
+ } | {
7
+ kind: 'amend';
8
+ effort: string;
9
+ } | {
10
+ kind: 'design';
11
+ spec: string;
12
+ };
13
+ export interface StoredDraft {
14
+ v: 1;
15
+ key: string;
16
+ session?: string;
17
+ read?: string[];
18
+ draft: Record<string, unknown>;
19
+ }
20
+ export declare function parseKey(key: string): DraftKey | undefined;
21
+ export declare function keyName(k: DraftKey): string;
22
+ export declare const draftRel: (k: DraftKey) => string;
23
+ export declare function readDraft(root: string, k: DraftKey): Result<StoredDraft | undefined>;
24
+ export declare function saveDraft(root: string, k: DraftKey, draft: Record<string, unknown>, session: string | undefined): void;
25
+ export declare function markRead(root: string, k: DraftKey, stored: StoredDraft, session: string): void;
26
+ export declare function dropDraft(root: string, k: DraftKey): void;
27
+ export declare function draftSessions(root: string): string[];
28
+ export declare function validateDraft(k: DraftKey, raw: unknown): Violation[];
29
+ export declare function settledItems(k: DraftKey, draft: Record<string, unknown>): string[];
30
+ export declare function draftSummary(k: DraftKey, draft: Record<string, unknown>): string;
31
+ export declare function draftLine(root: string, k: DraftKey): string | undefined;
package/dist/drafts.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { cliAct } from './act.js';
3
4
  import { ID_RE } from './dsl.js';
4
5
  import { idTextList } from './idlists.js';
5
6
  import { ok, refuse, v } from './refusal.js';
@@ -116,7 +117,7 @@ export function validateDraft(k, raw) {
116
117
  }
117
118
  if (raw.effort !== undefined) {
118
119
  if (typeof raw.effort !== 'string' || !ID_RE.test(raw.effort)) {
119
- out.push(v('effort', 'id-charset', String(raw.effort), '[a-z0-9-]+'));
120
+ out.push(v('effort', 'id-charset', String(raw.effort), '[a-z0-9][a-z0-9-]*'));
120
121
  }
121
122
  else if (k.kind === 'amend' && raw.effort !== k.effort) {
122
123
  out.push(v('effort', 'effort-mismatch', raw.effort, `${k.effort} — the effort this draft amends`));
@@ -159,10 +160,11 @@ export function draftSummary(k, draft) {
159
160
  return `${count(items, 'item')} settled${open > 0 ? ` · ${open} open` : ''}`;
160
161
  }
161
162
  // `next`'s line for a conversation that has a draft. None, or one that does not read, prints
162
- // nothing: an unreadable draft is refused by name where it is read back, never here.
163
+ // nothing: an unreadable draft is refused by name where it is read back, never here. Row 239: the
164
+ // command it names is an act's line.
163
165
  export function draftLine(root, k) {
164
166
  const d = readDraft(root, k);
165
167
  if (!d.ok || d.value === undefined)
166
168
  return undefined;
167
- return `${draftSummary(k, d.value.draft)} · resume with witness draft ${keyName(k)}`;
169
+ return `${draftSummary(k, d.value.draft)} · resume with ${cliAct('draft', keyName(k)).line}`;
168
170
  }
@@ -0,0 +1,23 @@
1
+ import type { Ctx } from './cli.js';
2
+ import { type CriteriaResult } from './criteria.js';
3
+ import { type Entry } from './journal.js';
4
+ import { type Result } from './refusal.js';
5
+ import { type Canon, type CanonDoc } from './scan.js';
6
+ export declare const newRunId: () => string;
7
+ export declare function driftEntry(run: CriteriaResult, runId: string): {
8
+ t: 'drift-check';
9
+ [k: string]: unknown;
10
+ };
11
+ export declare function trailingFails(entries: Entry[]): number;
12
+ export declare const liveSpecs: (canon: Canon) => CanonDoc[];
13
+ export declare function stampDrift(root: string, doc: CanonDoc, sha: string): void;
14
+ export declare function clearDrift(root: string, doc: CanonDoc): void;
15
+ export declare function flapScore(entries: Entry[]): number;
16
+ export declare function reconcileRows(root: string, canon: Canon): Array<{
17
+ spec: string;
18
+ why: string;
19
+ detail: string;
20
+ }>;
21
+ export declare function driftSweep(root: string, ctx: Ctx, canon: Canon): Promise<Result<CriteriaResult[]>>;
22
+ export declare function deepDrift(root: string, ctx: Ctx, canon: Canon, specId: string): Promise<number>;
23
+ export declare function runDrift(ctx: Ctx, argv: string[]): Promise<number>;
@@ -0,0 +1,30 @@
1
+ import { type Result } from './refusal.js';
2
+ import { type Platform } from './toon.js';
3
+ export declare const DRIVE_ENV = "WITNESS_DRIVE";
4
+ export declare const TARGETLESS = "-";
5
+ export declare const DRIVE_DEADLINE_ENV = "WITNESS_DRIVE_DEADLINE";
6
+ export declare function driveChild(env: Record<string, string | undefined>): {
7
+ target: string | undefined;
8
+ } | undefined;
9
+ export declare function isReviewer(env: Record<string, string | undefined>): boolean;
10
+ export declare function sessionMarker(env: Record<string, string | undefined>): 'WITNESS_DRIVE' | 'WITNESS_REVIEWER' | undefined;
11
+ export declare const DRIVE_LOCK = ".witness/drive.lock";
12
+ export declare const DRIVE_LOG = ".witness/drive.log";
13
+ export declare const DRIVE_LOG_ENV = "WITNESS_DRIVE_LOG";
14
+ export interface DriveHolder {
15
+ pid: number;
16
+ log?: string;
17
+ }
18
+ export declare const DRIVE_LEASE_MS = 120000;
19
+ export declare const DRIVE_RENEW_MS = 10000;
20
+ export declare const DRIVE_TAKEOVER_GRACE_MS = 25000;
21
+ export declare function driveHolder(root: string, now?: number): DriveHolder | undefined;
22
+ export declare function olderDrive(root: string, now?: number): DriveHolder | undefined;
23
+ export declare const OLDER_DRIVE_LINE = "wait: older drive \u2014 a witness drive from before 0.29 runs this repo \u00B7 stop it, then say go";
24
+ export declare function renewDriveLock(root: string, pid?: number): boolean;
25
+ export declare function holdLease(root: string, onLost: () => void, everyMs?: number, pid?: number): () => void;
26
+ export declare function acquireDriveLock(root: string, info: {
27
+ log?: string;
28
+ }, pid?: number, graceMs?: number): Result<() => void>;
29
+ export declare function watchLine(h: DriveHolder, platform?: Platform): string;
30
+ export declare function stopCommand(h: DriveHolder, platform?: Platform): string;
@@ -2,7 +2,7 @@ import { lstatSync, mkdirSync, readFileSync, utimesSync, writeFileSync } from 'n
2
2
  import { join } from 'node:path';
3
3
  import { isAlive, pause, pidOf, releaseIfMine, takeStale } from './lock.js';
4
4
  import { ok, refuse, v } from './refusal.js';
5
- import { psArg, shellArg } from './toon.js';
5
+ import { shellWordExact } from './toon.js';
6
6
  // Row 180. What a process knows about the drive it runs under. Drive marks every child
7
7
  // session with WITNESS_DRIVE=<target>: the marker is the recursion guard (a marked session's
8
8
  // `witness drive` refuses) and the child's scope (its `next` answers for that target alone).
@@ -70,7 +70,7 @@ function readHolder(root) {
70
70
  // The lock says only WHETHER a background log exists; its path is always derived. What
71
71
  // the file says is never printed: `watch:` is a line the engine acts on, and a path read
72
72
  // from a file could carry a newline and a forged `launch:` or `run:` line.
73
- return { pid: h.pid, renewed, leased: h.lease === 1, ...(h.log !== undefined ? { log: join(root, DRIVE_LOG) } : {}) };
73
+ return { pid: h.pid, renewed, leased: h.lease === 1, busy: h.busy === 1, ...(h.log !== undefined ? { log: join(root, DRIVE_LOG) } : {}) };
74
74
  }
75
75
  catch {
76
76
  return 'unreadable';
@@ -85,6 +85,15 @@ export function driveHolder(root, now = Date.now()) {
85
85
  return undefined;
86
86
  return { pid: h.pid, ...(h.log !== undefined ? { log: h.log } : {}) };
87
87
  }
88
+ // Row 240. A live drive from before 0.29 (its lock has no `busy: 1`), or none.
89
+ export function olderDrive(root, now = Date.now()) {
90
+ const h = readHolder(root);
91
+ if (typeof h !== 'object' || h.busy || !isAlive(h.pid) || !leaseLive(h, now))
92
+ return undefined;
93
+ return { pid: h.pid, ...(h.log !== undefined ? { log: h.log } : {}) };
94
+ }
95
+ // What `next` and `wait` print beside an older drive, above its stop command on a `run:` row.
96
+ export const OLDER_DRIVE_LINE = 'wait: older drive — a witness drive from before 0.29 runs this repo · stop it, then say go';
88
97
  // Row 224. The running drive's renewal: the lock's mtime set to now when the lock is this
89
98
  // pid's. A link at the lock path is never followed (utimes would touch what it points at).
90
99
  // `false` says the lease is no longer this drive's — taken over, or removed — and the drive
@@ -133,7 +142,7 @@ export function acquireDriveLock(root, info, pid = process.pid, graceMs = DRIVE_
133
142
  let expired;
134
143
  for (;;) {
135
144
  try {
136
- writeFileSync(p, JSON.stringify({ pid, ...(info.log !== undefined ? { log: info.log } : {}), lease: 1 }), { flag: 'wx' });
145
+ writeFileSync(p, JSON.stringify({ pid, ...(info.log !== undefined ? { log: info.log } : {}), lease: 1, busy: 1 }), { flag: 'wx' });
137
146
  return ok(release);
138
147
  }
139
148
  catch (e) {
@@ -199,10 +208,24 @@ export function acquireDriveLock(root, info, pid = process.pid, graceMs = DRIVE_
199
208
  // because `-Path` reads `[ ]` in a path as a wildcard, `-Tail 50` so it starts at the end rather
200
209
  // than replaying the whole log, and `-Encoding UTF8` because Windows PowerShell 5.1 reads a
201
210
  // BOM-less file as ANSI and would garble drive's `·` and `—`.
211
+ //
212
+ // Row 239. Each command is argv through the quoter, word by word, which prints the bytes this line
213
+ // always had: `Get-Content`, `taskkill` and their words are bare in PowerShell, the cmdlet's flags
214
+ // stay bare as the plan's B2 keeps a flag, and the log, an absolute path and so never shaped like a
215
+ // flag, prints as `shellArg` or `psArg` printed it — but for a Windows path, whose `\` now prints it
216
+ // single-quoted (ruling R22), which PowerShell reads as the same path. Ruling R27: the one word that
217
+ // can hold a character outside printable ASCII is the log path, a local path no attacker text
218
+ // reaches and that this line never offers to run (it has no `$(…)`), so `shellWordExact` keeps its
219
+ // bytes rather than spelling them, as the human needs the real path to read.
202
220
  export function watchLine(h, platform = process.platform) {
203
221
  if (h.log === undefined)
204
222
  return `the terminal running witness drive · pid ${h.pid}`;
205
- return platform === 'win32'
206
- ? `Get-Content -LiteralPath ${psArg(h.log)} -Wait -Tail 50 -Encoding UTF8 · stop it: taskkill /PID ${h.pid} /T /F`
207
- : `tail -f ${shellArg(h.log)} · stop it: kill ${h.pid}`;
223
+ const watch = platform === 'win32' ? ['Get-Content', '-LiteralPath', h.log, '-Wait', '-Tail', '50', '-Encoding', 'UTF8'] : ['tail', '-f', h.log];
224
+ return `${render(watch, platform)} · stop it: ${stopCommand(h, platform)}`;
225
+ }
226
+ const render = (argv, platform) => argv.map((w) => shellWordExact(w, platform)).join(' ');
227
+ // The command that stops a drive, by its pid: the `watch:` line's stop (rows 180 and 201).
228
+ export function stopCommand(h, platform = process.platform) {
229
+ const pid = String(h.pid);
230
+ return render(platform === 'win32' ? ['taskkill', '/PID', pid, '/T', '/F'] : ['kill', pid], platform);
208
231
  }
@@ -0,0 +1,24 @@
1
+ import type { Ctx } from './cli.js';
2
+ import type { Config } from './config.js';
3
+ import type { Aside } from './drive.js';
4
+ import { type Entry } from './journal.js';
5
+ export interface RunStart {
6
+ lines: Map<string, number>;
7
+ }
8
+ export declare function runStart(root: string): RunStart;
9
+ export declare function entriesSince(root: string, start: RunStart): Array<{
10
+ stream: string;
11
+ entry: Entry;
12
+ }>;
13
+ export interface Report {
14
+ lines: string[];
15
+ summary: string;
16
+ merged: number;
17
+ waiting: number;
18
+ parked: number;
19
+ stuck: number;
20
+ }
21
+ export declare function driveReport(root: string, ctx: Ctx, cfg: Config, start: RunStart, aside: readonly Aside[], run: {
22
+ autonomous: boolean;
23
+ stopped?: string;
24
+ }): Report;
@@ -1,6 +1,6 @@
1
1
  import { basename } from 'node:path';
2
2
  import { readStream, streamIds } from './journal.js';
3
- import { needsYou, WAIT_KINDS } from './needs-you.js';
3
+ import { needsYou, needYouRows, WAIT_KINDS } from './needs-you.js';
4
4
  import { loadCanon } from './scan.js';
5
5
  export function runStart(root) {
6
6
  return { lines: new Map(streamIds(root).map((s) => [s, readStream(root, s).length])) };
@@ -18,10 +18,10 @@ export function driveReport(root, ctx, cfg, start, aside, run) {
18
18
  // gates and the stuck targets: one derivation, read by the notifier and `witness wait` too.
19
19
  const items = needsYou(root, ctx, cfg, canon, aside);
20
20
  const waiting = items.filter((i) => WAIT_KINDS.has(i.kind));
21
- const waits = waiting.flatMap((i) => i.rows);
22
- const parked = items.filter((i) => i.kind === 'parked').flatMap((i) => i.rows);
21
+ const waits = waiting.flatMap((i) => needYouRows(i));
22
+ const parked = items.filter((i) => i.kind === 'parked').flatMap((i) => needYouRows(i));
23
23
  const stuckItems = items.filter((i) => i.kind === 'stuck' || i.kind === 'capped');
24
- const stuck = stuckItems.flatMap((i) => i.rows);
24
+ const stuck = stuckItems.flatMap((i) => needYouRows(i));
25
25
  const obligations = since.filter(({ entry }) => entry.t === 'deferral').map(({ entry }) => {
26
26
  const d = entry;
27
27
  return `obligation: ${d.id} · ${d.artifact} · ${d.anchor} — ${d.kind}`;