@popovych.co/witness 0.28.0 → 0.28.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 +6 -3
- package/dist/adopt.js +92 -6
- package/dist/allowlist.js +10 -1
- package/dist/arbiter.js +5 -3
- package/dist/drive-presence.js +96 -13
- package/dist/drive.js +37 -8
- package/dist/gates/decompose.js +25 -7
- package/dist/needs.js +6 -2
- package/dist/principles.js +18 -0
- package/dist/recommend.js +13 -5
- package/dist/reviewed.js +30 -1
- package/dist/runner.js +7 -3
- package/dist/verbs/adopt.js +20 -3
- package/dist/verbs/check.js +17 -4
- package/dist/verbs/decide.js +25 -9
- package/dist/verbs/drive.js +9 -1
- package/dist/verbs/floor.js +34 -4
- package/dist/verbs/init.js +5 -7
- package/dist/verbs/migrate.js +43 -11
- package/dist/verbs/next.js +64 -16
- package/dist/verbs/satisfy.js +8 -0
- package/dist/verbs/trust.js +37 -19
- package/dist/verbs/write.js +6 -1
- package/package.json +1 -1
- 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/reviewed.js
CHANGED
|
@@ -93,6 +93,35 @@ export function effortSpecs(root, canon, effort) {
|
|
|
93
93
|
}
|
|
94
94
|
return docs.sort((a, b) => String(a.meta.id).localeCompare(String(b.meta.id)));
|
|
95
95
|
}
|
|
96
|
+
// Row 221. Principles are canon like a spec: the effort that changes them has them reviewed.
|
|
97
|
+
// What an effort's decompose gate resolves, reviews and stamps — its written specs, and the
|
|
98
|
+
// principles while its write is their current content. Every effort amends the one shared doc,
|
|
99
|
+
// so a later effort's amendment is that effort's to have reviewed, and an earlier writer is not
|
|
100
|
+
// reopened by it. `effortSpecs` stays for the callers that need specs only.
|
|
101
|
+
export function effortCanon(root, canon, effort) {
|
|
102
|
+
const docs = [];
|
|
103
|
+
for (const [id, w] of effortWrites(root, effort)) {
|
|
104
|
+
const doc = findById(canon, id);
|
|
105
|
+
if (!doc)
|
|
106
|
+
continue;
|
|
107
|
+
if (doc.meta.type === 'spec' || (doc.meta.type === 'principles' && w.sha === canonicalSha(doc.meta, doc.body)))
|
|
108
|
+
docs.push(doc);
|
|
109
|
+
}
|
|
110
|
+
return docs.sort((a, b) => String(a.meta.id).localeCompare(String(b.meta.id)));
|
|
111
|
+
}
|
|
112
|
+
// Row 221. The effort that owns the principles as they stand: the live one whose latest write
|
|
113
|
+
// of them is the current content — its decompose gate approves them; by slug when several. None
|
|
114
|
+
// when no live effort wrote this content (a hand edit adopted, an older init's template, or an
|
|
115
|
+
// effort since abandoned, whose gate approves nothing): then a feature or fix effort amends them.
|
|
116
|
+
export function principlesOwner(root, canon) {
|
|
117
|
+
const doc = findById(canon, 'principles');
|
|
118
|
+
if (!doc)
|
|
119
|
+
return undefined;
|
|
120
|
+
const current = canonicalSha(doc.meta, doc.body);
|
|
121
|
+
return effortStreams(root)
|
|
122
|
+
.filter((e) => effortWrites(root, e).get('principles')?.sha === current && !effortAbandoned(readStream(root, e)))
|
|
123
|
+
.sort((a, b) => a.localeCompare(b))[0];
|
|
124
|
+
}
|
|
96
125
|
export function effortOf(root, artifactId) {
|
|
97
126
|
const hits = [];
|
|
98
127
|
for (const effort of effortStreams(root)) {
|
|
@@ -112,7 +141,7 @@ function sha256(parts) {
|
|
|
112
141
|
}
|
|
113
142
|
export function effortReviewedSha(root, canon, effort) {
|
|
114
143
|
const recap = latestRecap(root, effort);
|
|
115
|
-
const docs =
|
|
144
|
+
const docs = effortCanon(root, canon, effort); // row 221: principles an effort wrote are judged content too
|
|
116
145
|
const writes = effortWrites(root, effort);
|
|
117
146
|
// Row 198 (Builder's call 7). The decision mapping is judged content, so a carries-only
|
|
118
147
|
// rewrite moves the identity rather than resuming into row 112's `cached` replay — a spec
|
package/dist/runner.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { ensureTrusted } from './allowlist.js';
|
|
3
|
+
import { ensureTrusted, UNGRANTABLE } from './allowlist.js';
|
|
4
4
|
import { mergeReports, reportFiles } from './junit.js';
|
|
5
5
|
import { ok, refuse, v } from './refusal.js';
|
|
6
6
|
import { contained, JOB_HOST_ENV, jobHost } from './contain.js';
|
|
7
7
|
import { withRunnerTurn } from './runner-lock.js';
|
|
8
8
|
import { execFileSync, execSync, system32 } from './spawn.js';
|
|
9
|
+
import { hasControl } from './toon.js';
|
|
9
10
|
// The values' own shapes (a runner with {id}, a junit: report) are refused when the file loads
|
|
10
11
|
// (row 193); what is left is what only a combination says, and what an older file never set.
|
|
11
12
|
export function runnerConfig(cfg) {
|
|
@@ -87,17 +88,20 @@ export function untrustedOf(violations) {
|
|
|
87
88
|
// Row 205. The runner knows no target, so it names the verb that does: `next` prints the grant
|
|
88
89
|
// to make, and the human names the command in the chat. The env var is the automation route.
|
|
89
90
|
const UNTRUSTED_WANT = 'a trusted command — witness next names the grant to make, or set WITNESS_TRUST_CMDS=1 for automation';
|
|
91
|
+
// Row 237. No grant exists for a command outside printable ASCII, so its refusal says so rather
|
|
92
|
+
// than send the human to `witness next` for one.
|
|
93
|
+
const blockedWant = (cmd) => hasControl(cmd) ? UNGRANTABLE : UNTRUSTED_WANT;
|
|
90
94
|
export async function runFiltered(runRoot, ctx, template, specId, trustRoot = runRoot) {
|
|
91
95
|
const trust = await ensureTrusted(trustRoot, ctx, template);
|
|
92
96
|
if (trust !== 'trusted') {
|
|
93
|
-
return refuse([v('criteria.runner', `untrusted-${trust}`, template, trust === 'blocked' ?
|
|
97
|
+
return refuse([v('criteria.runner', `untrusted-${trust}`, template, trust === 'blocked' ? blockedWant(template) : 'trust was declined')]);
|
|
94
98
|
}
|
|
95
99
|
return ok(execCommand(runRoot, ctx, template.replaceAll('{id}', specId)));
|
|
96
100
|
}
|
|
97
101
|
export async function runFullSuite(runRoot, ctx, rc, trustRoot = runRoot) {
|
|
98
102
|
const trust = await ensureTrusted(trustRoot, ctx, rc.suiteCmd);
|
|
99
103
|
if (trust !== 'trusted') {
|
|
100
|
-
return refuse([v('ship.test', `untrusted-${trust}`, rc.suiteCmd, trust === 'blocked' ?
|
|
104
|
+
return refuse([v('ship.test', `untrusted-${trust}`, rc.suiteCmd, trust === 'blocked' ? blockedWant(rc.suiteCmd) : 'trust was declined')]);
|
|
101
105
|
}
|
|
102
106
|
for (const f of reportFiles(runRoot, rc.reportGlob))
|
|
103
107
|
rmSync(join(runRoot, f));
|
package/dist/verbs/adopt.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { adoptedCommitsFor, lastWitnessed, positionOf, untrailedCommitsFor } from '../adopt.js';
|
|
3
3
|
import { EXIT } from '../cli.js';
|
|
4
4
|
import { canonPaths } from '../config.js';
|
|
5
5
|
import { runCriteria } from '../criteria.js';
|
|
@@ -12,7 +12,7 @@ import { renderRefusal, v } from '../refusal.js';
|
|
|
12
12
|
import { idRetired, pathRetired } from '../departure.js';
|
|
13
13
|
import { findById, findCycle, loadCanon } from '../scan.js';
|
|
14
14
|
import { validateDoc } from '../schemas.js';
|
|
15
|
-
import { canonicalSha, short } from '../sha.js';
|
|
15
|
+
import { canonicalJson, canonicalSha, short, VOLATILE_FIELDS } from '../sha.js';
|
|
16
16
|
import { kv } from '../toon.js';
|
|
17
17
|
import { crashPoint, guardTxn, withTxn } from '../txn.js';
|
|
18
18
|
export async function run(ctx, argv) {
|
|
@@ -59,6 +59,7 @@ export async function run(ctx, argv) {
|
|
|
59
59
|
const cycle = findCycle(canon);
|
|
60
60
|
if (cycle)
|
|
61
61
|
violations.push(v('depends', 'cycle', cycle.join(' -> '), 'an acyclic graph'));
|
|
62
|
+
violations.push(...positionMoves(root, rel, id, meta));
|
|
62
63
|
if (violations.length) {
|
|
63
64
|
renderRefusal(violations).forEach(ctx.err);
|
|
64
65
|
ctx.err(`help: fix the file and re-run, or revert instead: git checkout HEAD -- ${rel}`);
|
|
@@ -68,7 +69,8 @@ export async function run(ctx, argv) {
|
|
|
68
69
|
const currentSha = canonicalSha(meta, body);
|
|
69
70
|
const changed = witnessed?.sha !== currentSha;
|
|
70
71
|
const criteriaChanged = JSON.stringify(meta.criteria ?? null) !== JSON.stringify(witnessed?.criteria ?? null);
|
|
71
|
-
const
|
|
72
|
+
const absolved = adoptedCommitsFor(root, id); // final review F1: absolved for this doc, not any
|
|
73
|
+
const commits = untrailedCommitsFor(root, rel).filter((sha) => !absolved.has(sha));
|
|
72
74
|
const dirty = dirtyStatePaths(root).includes(rel);
|
|
73
75
|
if (!changed && !dirty && commits.length === 0) {
|
|
74
76
|
ctx.out(kv('adopt', `${id}: nothing to adopt — content matches the last witnessed state`));
|
|
@@ -127,3 +129,18 @@ export async function run(ctx, argv) {
|
|
|
127
129
|
ctx.out('help: history: witness log ' + id);
|
|
128
130
|
return reverify && !reverify.ok ? EXIT.FINDINGS : EXIT.OK;
|
|
129
131
|
}
|
|
132
|
+
// Row 220 (#65). Position — status, drift, pr, design — is written by the CLI's own transitions
|
|
133
|
+
// alone, and the content sha leaves it out, so a hand edit of position alone read as unchanged
|
|
134
|
+
// and adopt absolved it. Measured against the doc's last witnessed state (a trailered commit, or
|
|
135
|
+
// one an earlier adopt absolved), followed through a hand move, when that state is this id's; a doc adopt
|
|
136
|
+
// has never seen is born draft, with no stamps. Every moved field is named in the one refusal.
|
|
137
|
+
function positionMoves(root, rel, id, meta) {
|
|
138
|
+
const base = lastWitnessed(root, rel, adoptedCommitsFor(root, id), { follow: true });
|
|
139
|
+
const seen = base !== undefined && base.id === id ? base : undefined;
|
|
140
|
+
const was = seen?.position ?? positionOf({ status: 'draft' });
|
|
141
|
+
const now = positionOf(meta);
|
|
142
|
+
const shown = (x) => (x === undefined ? '(none)' : typeof x === 'string' ? x : canonicalJson(x));
|
|
143
|
+
return VOLATILE_FIELDS.filter((f) => canonicalJson(was[f]) !== canonicalJson(now[f])).map((f) => v(f, 'position-moved', `${shown(was[f])} → ${shown(now[f])}`, seen !== undefined
|
|
144
|
+
? `position is written by the CLI — set ${f} back to ${shown(was[f])}, or revert the file: git checkout ${short(seen.commit)} -- ${rel}`
|
|
145
|
+
: `position is written by the CLI — a doc adopt has never seen is born ${f === 'status' ? 'status: draft' : `draft, with no ${f}`}`));
|
|
146
|
+
}
|
package/dist/verbs/check.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readdirSync, existsSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { absolutions, unabsolvedPaths } from '../adopt.js';
|
|
4
4
|
import { EXIT, version } from '../cli.js';
|
|
5
5
|
import { pctOf, readFill, windowLabel } from '../context.js';
|
|
6
6
|
import { HARNESSES, judgeLine, loadHarness, resolveDriver, resolveJudge, resolveSkills, skillPins, } from '../harness.js';
|
|
@@ -8,7 +8,7 @@ import { CONTEXT_INSTALL, payloadStale } from '../install.js';
|
|
|
8
8
|
import { latestPublished } from '../registry.js';
|
|
9
9
|
import { NPX_LATEST, compareTriple } from '../version.js';
|
|
10
10
|
import { probe } from '../probe.js';
|
|
11
|
-
import { loadConfig, loadLocalConfig, localConfigPath } from '../config.js';
|
|
11
|
+
import { canonPaths, loadConfig, loadLocalConfig, localConfigPath } from '../config.js';
|
|
12
12
|
import { openDeferrals } from '../deferral.js';
|
|
13
13
|
import { canonExit } from '../departure.js';
|
|
14
14
|
import { designPending } from '../design.js';
|
|
@@ -254,10 +254,23 @@ export async function run(ctx, argv = []) {
|
|
|
254
254
|
findings.push(f('warn', 'needs', `${doc.rel}: ${r.label}`, rule, r.detail));
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
-
|
|
257
|
+
// Final review F1 and the security review. An untrailered commit is absolved only when every
|
|
258
|
+
// state path it changed is a doc an adopt took in: one that also changed another doc, deleted
|
|
259
|
+
// one, or touched the journal or a design by hand is still a hand edit to report, by path.
|
|
260
|
+
const absolved = absolutions(root);
|
|
261
|
+
const paths = canonPaths(root);
|
|
262
|
+
const dirs = { docs: [paths.specs, paths.plans], other: [paths.designs, '.witness/journal'] };
|
|
258
263
|
auditStateCommits(root).forEach((c) => {
|
|
259
|
-
if (
|
|
264
|
+
if (c.trailered)
|
|
265
|
+
return;
|
|
266
|
+
const ids = absolved.get(c.sha);
|
|
267
|
+
if (ids === undefined) {
|
|
260
268
|
findings.push(f('error', 'audit', c.sha.slice(0, 7), 'untrailered-commit', `${c.subject} — adopt: witness adopt <path> · or revert`));
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const left = unabsolvedPaths(root, c.sha, ids, dirs);
|
|
272
|
+
if (left.length > 0) {
|
|
273
|
+
findings.push(f('error', 'audit', c.sha.slice(0, 7), 'untrailered-commit', `${c.subject} — not absolved: ${left.join(' ')} · adopt each doc left (witness adopt <path>) · revert a journal or design edit`));
|
|
261
274
|
}
|
|
262
275
|
});
|
|
263
276
|
if (pendingTxn(root)) {
|
package/dist/verbs/decide.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { EXIT } from '../cli.js';
|
|
3
|
-
import {
|
|
3
|
+
import { unsafeLeft, untrustedCmdsFor } from '../allowlist.js';
|
|
4
4
|
import { loadConfig } from '../config.js';
|
|
5
5
|
import { designUnseen } from '../design.js';
|
|
6
6
|
import { dropDraft } from '../drafts.js';
|
|
@@ -18,10 +18,10 @@ import { effortOf } from '../reviewed.js';
|
|
|
18
18
|
import { liftedHolds } from '../needs.js';
|
|
19
19
|
import { criteriaOwner, findById, loadCanon } from '../scan.js';
|
|
20
20
|
import { newRunId } from '../drift.js';
|
|
21
|
-
import {
|
|
21
|
+
import { grantTrust } from './trust.js';
|
|
22
22
|
import { ok, refuse, renderRefusal, v } from '../refusal.js';
|
|
23
23
|
import { short } from '../sha.js';
|
|
24
|
-
import { cmd, kv, rows } from '../toon.js';
|
|
24
|
+
import { cmd, hasControl, kv, rows } from '../toon.js';
|
|
25
25
|
import { ROUND_BOUND, anchorRecurrence, boundReached, lastGateRun, openReopen, pendingDecision, repairGranted, roundsSinceApprove, } from '../rounds.js';
|
|
26
26
|
import { prepareStamp, writeStamp } from '../stamp.js';
|
|
27
27
|
import { handOverIfDue } from '../slice.js';
|
|
@@ -651,16 +651,32 @@ export async function applyDecision(ctx, act) {
|
|
|
651
651
|
dropDraft(root, { kind: 'design', spec: target });
|
|
652
652
|
// D154. After the decision is durable, never before: a refused or crashed decide must
|
|
653
653
|
// not leave a grant behind that nobody chose.
|
|
654
|
+
// Row 222. Through the one locked grant, after decide's own lock is released above (the
|
|
655
|
+
// lock is not re-entrant across a release): the decision stands whatever the grant meets,
|
|
656
|
+
// and a grant it could not land is refused with its rows and the exit says so.
|
|
657
|
+
let grantExit = EXIT.OK;
|
|
654
658
|
if (trustCmds) {
|
|
655
|
-
|
|
659
|
+
// Row 205. The grant takes what `witness trust` would and nothing else: a command holding a
|
|
660
|
+
// character outside printable ASCII is never granted, so it stays blocked and is counted, and
|
|
661
|
+
// "nothing to grant" claims every criterion trusted only when none is left that way.
|
|
662
|
+
const untrusted = untrustedCmdsFor(root, criteriaOwner(canon, target));
|
|
663
|
+
const granted = untrusted.filter((c) => !hasControl(c));
|
|
664
|
+
const unsafe = untrusted.length - granted.length;
|
|
656
665
|
if (granted.length > 0) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
666
|
+
const res = grantTrust(ctx, root, target, granted, 'decide');
|
|
667
|
+
if (res.ok)
|
|
668
|
+
ctx.out(kv('trusted', granted.join(' · ')));
|
|
669
|
+
else {
|
|
670
|
+
renderRefusal(res.violations).forEach((l) => ctx.err(l));
|
|
671
|
+
ctx.err(`help: the decision landed; grant again once the repo is free — witness trust ${target}`);
|
|
672
|
+
grantExit = res.violations.some((x) => x.rule === 'locked') ? EXIT.BLOCKED : EXIT.REFUSED;
|
|
673
|
+
}
|
|
660
674
|
}
|
|
661
675
|
else {
|
|
662
|
-
ctx.out(kv('trusted', 'nothing to grant — every cmd: criterion was already trusted'));
|
|
676
|
+
ctx.out(kv('trusted', unsafe === 0 ? 'nothing to grant — every cmd: criterion was already trusted' : 'nothing to grant'));
|
|
663
677
|
}
|
|
678
|
+
if (unsafe > 0)
|
|
679
|
+
ctx.out(kv('trust', unsafeLeft(unsafe)));
|
|
664
680
|
}
|
|
665
681
|
// Row 173: a decision nobody typed says so, with the rule it acted on.
|
|
666
682
|
const by = act.selected === 'policy' || act.selected === 'arbiter'
|
|
@@ -697,5 +713,5 @@ export async function applyDecision(ctx, act) {
|
|
|
697
713
|
else if (entry.upstream)
|
|
698
714
|
ctx.out(`help: reopened ${entry.upstream.artifact} (${entry.upstream.gate} stage) — linked via caused_by`);
|
|
699
715
|
}
|
|
700
|
-
return
|
|
716
|
+
return grantExit;
|
|
701
717
|
}
|
package/dist/verbs/drive.js
CHANGED
|
@@ -3,7 +3,7 @@ import { EXIT } from '../cli.js';
|
|
|
3
3
|
import { loadConfig } from '../config.js';
|
|
4
4
|
import { withoutSession } from '../context.js';
|
|
5
5
|
import { detachDrive, driveLoop } from '../drive.js';
|
|
6
|
-
import { acquireDriveLock, DRIVE_ENV, DRIVE_LOG_ENV, driveChild, driveHolder, watchLine } from '../drive-presence.js';
|
|
6
|
+
import { acquireDriveLock, DRIVE_ENV, DRIVE_LOCK, DRIVE_LOG_ENV, driveChild, driveHolder, holdLease, watchLine } from '../drive-presence.js';
|
|
7
7
|
import { primaryRoot } from '../gitio.js';
|
|
8
8
|
import { withJournalCtx } from '../journal.js';
|
|
9
9
|
import { renderRefusal, v } from '../refusal.js';
|
|
@@ -100,14 +100,22 @@ async function drive(ctx, argv) {
|
|
|
100
100
|
renderRefusal(lock.violations).forEach((l) => ctx.err(l));
|
|
101
101
|
return EXIT.REFUSED;
|
|
102
102
|
}
|
|
103
|
+
// Row 224. The lock is a lease this drive renews for as long as it holds it; lost, the run stops.
|
|
104
|
+
const lost = new AbortController();
|
|
105
|
+
const stopLease = holdLease(root, () => {
|
|
106
|
+
ctx.err(`drive: lease lost — ${DRIVE_LOCK} is no longer this drive's · this drive stops`);
|
|
107
|
+
lost.abort();
|
|
108
|
+
});
|
|
103
109
|
try {
|
|
104
110
|
return await driveLoop(root, cfgR.value, ctx, {
|
|
105
111
|
...(values.flow !== undefined ? { flow: values.flow } : {}),
|
|
106
112
|
...(maxSpawns !== undefined ? { maxSpawns } : {}),
|
|
107
113
|
...(manual ? { manual } : {}),
|
|
114
|
+
signal: lost.signal,
|
|
108
115
|
});
|
|
109
116
|
}
|
|
110
117
|
finally {
|
|
118
|
+
stopLease();
|
|
111
119
|
lock.value();
|
|
112
120
|
}
|
|
113
121
|
}
|
package/dist/verbs/floor.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
2
|
import { EXIT } from '../cli.js';
|
|
3
3
|
import { FLOOR_KEY, FLOOR_STREAM, stateFloor } from '../floor.js';
|
|
4
|
-
import { primaryRoot } from '../gitio.js';
|
|
5
|
-
import { appendEntry } from '../journal.js';
|
|
4
|
+
import { primaryRoot, stateCommit } from '../gitio.js';
|
|
5
|
+
import { appendEntry, entryLine, journalRel } from '../journal.js';
|
|
6
|
+
import { acquireLock } from '../lock.js';
|
|
6
7
|
import { renderRefusal, v } from '../refusal.js';
|
|
7
8
|
import { kv } from '../toon.js';
|
|
9
|
+
import { crashPoint, guardTxn, withTxn } from '../txn.js';
|
|
8
10
|
import { compareTriple, version } from '../version.js';
|
|
9
11
|
// Row 116's safety valve. The floor is derived from what the state has seen, which is
|
|
10
12
|
// correct until a published version turns out to be broken: then every repository that ran
|
|
@@ -37,8 +39,36 @@ export async function run(ctx, argv) {
|
|
|
37
39
|
renderRefusal(violations).forEach((l) => ctx.err(l));
|
|
38
40
|
return EXIT.REFUSED;
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
// Row 226 (#71). Committed state like every other decision: under the repo lock, one
|
|
43
|
+
// transaction appends the pin and lands its trailer commit, so the tree is clean after.
|
|
44
|
+
// A pending transaction refuses it as it refuses every writer.
|
|
45
|
+
const blocked = guardTxn(ctx, root);
|
|
46
|
+
if (blocked !== undefined)
|
|
47
|
+
return blocked;
|
|
48
|
+
const pin = values.set;
|
|
49
|
+
const note = values.note ?? '';
|
|
50
|
+
const lock = acquireLock(root);
|
|
51
|
+
if (!lock.ok) {
|
|
52
|
+
renderRefusal(lock.violations).forEach((l) => ctx.err(l));
|
|
53
|
+
return EXIT.BLOCKED;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const entry = { t: 'policy-pin', key: FLOOR_KEY, pin, note };
|
|
57
|
+
const rel = journalRel(FLOOR_STREAM);
|
|
58
|
+
const res = withTxn(root, { op: `floor(${pin})`, files: [rel], journal: { stream: FLOOR_STREAM, line: entryLine(entry) } }, () => {
|
|
59
|
+
appendEntry(root, FLOOR_STREAM, entry);
|
|
60
|
+
crashPoint(ctx.env, 'journal-append');
|
|
61
|
+
return stateCommit(root, [rel], `floor(${pin}): ${note.slice(0, 60)}`);
|
|
62
|
+
});
|
|
63
|
+
if (!res.ok) {
|
|
64
|
+
renderRefusal(res.violations).forEach((l) => ctx.err(l));
|
|
65
|
+
return EXIT.REFUSED;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
lock.value();
|
|
70
|
+
}
|
|
71
|
+
ctx.out(kv('floor', `${pin} — set by hand: ${note}`));
|
|
42
72
|
return EXIT.OK;
|
|
43
73
|
}
|
|
44
74
|
const floor = stateFloor(root);
|
package/dist/verbs/init.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { parseArgs } from 'node:util';
|
|
4
4
|
import { EXIT, version } from '../cli.js';
|
|
5
|
+
import { PRINCIPLES_BODY } from '../principles.js';
|
|
5
6
|
import { configPath, loadConfig } from '../config.js';
|
|
6
7
|
import { renderConfig } from '../config-file.js';
|
|
7
8
|
import { writeDoc } from '../fm.js';
|
|
@@ -25,11 +26,6 @@ const GITIGNORE_BLOCK = `# witness local (never committed)
|
|
|
25
26
|
.witness/drafts/
|
|
26
27
|
.witness/live/
|
|
27
28
|
`;
|
|
28
|
-
const PRINCIPLES_BODY = `# Principles
|
|
29
|
-
|
|
30
|
-
Repo-wide rules and trade-offs. Amend via \`witness write\`; chores may name
|
|
31
|
-
this doc as their plan's parent.
|
|
32
|
-
`;
|
|
33
29
|
const USAGE = 'usage: witness init [--agent claude-code|pi|auto]';
|
|
34
30
|
// `--agent` is what makes a second run legal. A bare `witness init` keeps its tested
|
|
35
31
|
// contract — it refuses `already-initialized` — because scaffolding twice is a mistake.
|
|
@@ -107,8 +103,10 @@ export async function run(ctx, argv = []) {
|
|
|
107
103
|
if (!existing.includes('.witness/lock')) {
|
|
108
104
|
writeFileSync(gi, existing + (existing && !existing.endsWith('\n') ? '\n' : '') + GITIGNORE_BLOCK);
|
|
109
105
|
}
|
|
106
|
+
// Row 221. Born approved: the empty template has nothing to judge, and a chore's plan
|
|
107
|
+
// names it as its parent from the first day. An effort that amends it has it reviewed.
|
|
110
108
|
writeDoc(join(root, 'specs', 'principles.md'), {
|
|
111
|
-
meta: { id: 'principles', type: 'principles', status: '
|
|
109
|
+
meta: { id: 'principles', type: 'principles', status: 'approved', depends: [], needs: [] },
|
|
112
110
|
body: PRINCIPLES_BODY,
|
|
113
111
|
});
|
|
114
112
|
files.push('witness.config.yaml', '.gitignore', 'specs/principles.md', 'plans/.gitkeep', '.witness/journal/.gitkeep');
|
|
@@ -182,7 +180,7 @@ export async function run(ctx, argv = []) {
|
|
|
182
180
|
}
|
|
183
181
|
if (!scaffolded) {
|
|
184
182
|
ctx.out(kv('initialized', root));
|
|
185
|
-
ctx.out(kv('canon', 'specs/principles.md (
|
|
183
|
+
ctx.out(kv('canon', 'specs/principles.md (approved)'));
|
|
186
184
|
if (judge !== undefined)
|
|
187
185
|
ctx.out(kv('harness', `${judge.name} · ${judge.from}`));
|
|
188
186
|
}
|
package/dist/verbs/migrate.js
CHANGED
|
@@ -14,9 +14,21 @@ import { renderRefusal, v } from '../refusal.js';
|
|
|
14
14
|
import { GATE_NAMES, SETTINGS, getIn, settingAt } from '../settings.js';
|
|
15
15
|
import { execFileSync } from '../spawn.js';
|
|
16
16
|
import { kv } from '../toon.js';
|
|
17
|
+
import { journalRel } from '../journal.js';
|
|
18
|
+
import { findById, loadCanon } from '../scan.js';
|
|
19
|
+
import { prepareStamp, writeStamp } from '../stamp.js';
|
|
20
|
+
import { crashPoint, withTxn } from '../txn.js';
|
|
21
|
+
import { templateDraft } from '../principles.js';
|
|
17
22
|
// Row 193 §4.6, the verb row 23 reserved: bring witness.config.yaml to this CLI's schema and
|
|
18
23
|
// make it complete — every setting with its comment, every value that is a choice kept, every
|
|
19
|
-
// comment a human wrote kept — and name each change. Config only
|
|
24
|
+
// comment a human wrote kept — and name each change. Config only (row 23), with one exception
|
|
25
|
+
// row 221 made: the untouched principles template an older init wrote draft is stamped approved,
|
|
26
|
+
// journaled as the template, in the same trailer commit.
|
|
27
|
+
// Row 221. The untouched template an older init left draft, stamped approved as the template.
|
|
28
|
+
function templateStamp(root) {
|
|
29
|
+
const doc = findById(loadCanon(root), 'principles');
|
|
30
|
+
return templateDraft(root, doc) ? prepareStamp(doc, 'approved', 'template') : undefined;
|
|
31
|
+
}
|
|
20
32
|
const shown = (val) => (val === undefined ? 'absent' : inlineValue(val));
|
|
21
33
|
// What an ambient setting meant while it was absent, so a `filled:` line says what it replaces.
|
|
22
34
|
function filledWhy(path) {
|
|
@@ -170,27 +182,47 @@ export async function run(ctx, argv) {
|
|
|
170
182
|
return refused(guard);
|
|
171
183
|
// Line ends and a BOM are the checkout's, not the file's: with core.autocrlf a Windows working
|
|
172
184
|
// copy of an up-to-date file reads CRLF, and is still up to date.
|
|
173
|
-
|
|
185
|
+
const current = newText === oldText.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n');
|
|
186
|
+
const stamp = templateStamp(root);
|
|
187
|
+
if (current)
|
|
174
188
|
ctx.out(kv('config', `schema ${schema} · up to date`));
|
|
189
|
+
else {
|
|
190
|
+
changeLines(changes, schema).forEach((l) => ctx.out(l));
|
|
191
|
+
const kept = humanLines(comments.human).length - comments.moved;
|
|
192
|
+
ctx.out(kv('comments', `kept ${kept} · moved ${comments.moved} · dropped ${comments.legacy} old template lines`));
|
|
193
|
+
ctx.out(kv('config', `schema ${schema} → ${SCHEMA_VERSION}`));
|
|
194
|
+
}
|
|
195
|
+
if (stamp !== undefined)
|
|
196
|
+
ctx.out(kv('principles', 'draft → approved — the untouched template an older init wrote draft'));
|
|
197
|
+
if (current && stamp === undefined)
|
|
175
198
|
return EXIT.OK;
|
|
176
|
-
}
|
|
177
|
-
changeLines(changes, schema).forEach((l) => ctx.out(l));
|
|
178
|
-
const kept = humanLines(comments.human).length - comments.moved;
|
|
179
|
-
ctx.out(kv('comments', `kept ${kept} · moved ${comments.moved} · dropped ${comments.legacy} old template lines`));
|
|
180
|
-
ctx.out(kv('config', `schema ${schema} → ${SCHEMA_VERSION}`));
|
|
181
199
|
if (dryRun) {
|
|
182
|
-
|
|
183
|
-
|
|
200
|
+
if (!current) {
|
|
201
|
+
ctx.out('diff:');
|
|
202
|
+
diffOf(oldText, newText).forEach((l) => ctx.out(l));
|
|
203
|
+
}
|
|
184
204
|
return EXIT.OK;
|
|
185
205
|
}
|
|
206
|
+
const files = [...(current ? [] : ['witness.config.yaml']), ...(stamp !== undefined ? [stamp.rel, journalRel(stamp.stream)] : [])];
|
|
207
|
+
const subject = [
|
|
208
|
+
...(current ? [] : [`config schema ${schema} → ${SCHEMA_VERSION}`]),
|
|
209
|
+
...(stamp !== undefined ? ['principles approved (the untouched template)'] : []),
|
|
210
|
+
].join(' · ');
|
|
186
211
|
const lock = acquireLock(root);
|
|
187
212
|
if (!lock.ok) {
|
|
188
213
|
renderRefusal(lock.violations).forEach((l) => ctx.err(l));
|
|
189
214
|
return EXIT.BLOCKED;
|
|
190
215
|
}
|
|
191
216
|
try {
|
|
192
|
-
|
|
193
|
-
const commit =
|
|
217
|
+
const marker = { op: 'migrate', files, ...(stamp !== undefined ? { journal: { stream: stamp.stream, line: stamp.line } } : {}) };
|
|
218
|
+
const commit = withTxn(root, marker, () => {
|
|
219
|
+
if (!current)
|
|
220
|
+
writeFileSync(p, newText);
|
|
221
|
+
if (stamp !== undefined)
|
|
222
|
+
writeStamp(root, stamp);
|
|
223
|
+
crashPoint(ctx.env, 'migrate-write');
|
|
224
|
+
return commitWithTrailer(root, files, `migrate: ${subject}`);
|
|
225
|
+
});
|
|
194
226
|
if (!commit.ok)
|
|
195
227
|
return refused(commit.violations);
|
|
196
228
|
}
|
package/dist/verbs/next.js
CHANGED
|
@@ -8,9 +8,10 @@ import { loadConfig } from '../config.js';
|
|
|
8
8
|
import { pendingTxn } from '../txn.js';
|
|
9
9
|
import { primaryRoot } from '../gitio.js';
|
|
10
10
|
import { findById, loadCanon, planFinished, plannableParent } from '../scan.js';
|
|
11
|
+
import { templateDraft } from '../principles.js';
|
|
11
12
|
import { designArtifactCurrent, designCurrentSha, designPending, designUnseen } from '../design.js';
|
|
12
13
|
import { effortAbandoned, effortStreams, latestRecap, readStream } from '../journal.js';
|
|
13
|
-
import { diffReviewedSha, effortOf, effortReviewedSha,
|
|
14
|
+
import { diffReviewedSha, effortCanon, effortOf, effortReviewedSha, effortWrites, implementReviewedSha, planPairSha, principlesOwner } from '../reviewed.js';
|
|
14
15
|
import { baseForSpec } from '../history.js';
|
|
15
16
|
import { basisMoved, planDecisionsTerm, specBasis } from '../basis.js';
|
|
16
17
|
import { changedFiles, diffBase, evidenceForDiff, isTestPath } from '../evidence.js';
|
|
@@ -266,7 +267,8 @@ function amendedSinceSettled(entries) {
|
|
|
266
267
|
// live specs (c2). A finished effort's change is a new effort.
|
|
267
268
|
function effortFinished(specs, plans) {
|
|
268
269
|
const ids = new Set(specs.map((d) => String(d.meta.id)));
|
|
269
|
-
|
|
270
|
+
// Row 221. Principles an effort wrote finish at approved: they never go live.
|
|
271
|
+
return specs.every((d) => String(d.meta.status) === (d.meta.type === 'principles' ? 'approved' : 'live')) &&
|
|
270
272
|
!plans.some((p) => ids.has(String(p.meta.parent)) && !planFinished(p));
|
|
271
273
|
}
|
|
272
274
|
// Whether an effort's decompose is owed. Settled either by a real gate-run+approve, or
|
|
@@ -283,6 +285,53 @@ function decomposeOwed(root, canon, e, specs, plans) {
|
|
|
283
285
|
return !specsApproved && !gateSettled(e.entries, 'decompose', effortReviewedSha(root, canon, e.slug).sha) &&
|
|
284
286
|
!gateParked(e.entries, 'decompose');
|
|
285
287
|
}
|
|
288
|
+
// The step an effort's owed decompose takes: re-authoring when a revise is owed — the gate would
|
|
289
|
+
// only say it changed nothing — else the gate. One derivation for the effort's own rung and for a
|
|
290
|
+
// chore routed to the effort that owns its draft principles (row 221).
|
|
291
|
+
function decomposeStep(root, canon, e, judge) {
|
|
292
|
+
return authoringOwed(e.entries, 'decompose', effortReviewedSha(root, canon, e.slug).sha)
|
|
293
|
+
? {
|
|
294
|
+
line: `witness write <spec-id> --effort ${e.slug} --meta m.json --body b.md`,
|
|
295
|
+
stage: 'decompose', target: e.slug,
|
|
296
|
+
note: 'revise owed — re-author, then the gate has something new to judge',
|
|
297
|
+
}
|
|
298
|
+
: { line: `witness gate decompose --effort ${e.slug}`, target: e.slug, ...noteOf(judgeNote(e.entries, 'decompose', judge)) };
|
|
299
|
+
}
|
|
300
|
+
// Row 221. What approves draft principles — one derivation for `next`'s chore rung and for
|
|
301
|
+
// `write`'s `parent-not-approved` remedy, so neither routes back to an act that is refused or
|
|
302
|
+
// loops: an older init's untouched template → `witness migrate`; a live owner whose decompose is
|
|
303
|
+
// owed → its step (`decomposeStep`); parked → its reopen; otherwise where its gate stands; no
|
|
304
|
+
// live owner → a new feature or fix effort amends them. `undefined` when principles are not draft.
|
|
305
|
+
export function principlesApproval(root, canon, judge) {
|
|
306
|
+
const doc = findById(canon, 'principles');
|
|
307
|
+
if (doc === undefined || String(doc.meta.status) !== 'draft')
|
|
308
|
+
return undefined;
|
|
309
|
+
if (templateDraft(root, doc)) {
|
|
310
|
+
const note = 'principles.md is the untouched template an older witness init left draft — witness migrate stamps it approved';
|
|
311
|
+
return { action: { line: 'witness migrate', note }, remedy: `${note} — run: witness migrate` };
|
|
312
|
+
}
|
|
313
|
+
const owner = principlesOwner(root, canon);
|
|
314
|
+
if (owner === undefined) {
|
|
315
|
+
const note = 'principles.md is draft and no effort owns it — amend principles through a feature or fix effort: its decompose gate approves them';
|
|
316
|
+
return { action: { line: 'witness check', note }, remedy: note };
|
|
317
|
+
}
|
|
318
|
+
const e = { slug: owner, entries: readStream(root, owner) };
|
|
319
|
+
const plans = canon.docs.filter((d) => d.meta.type === 'plan');
|
|
320
|
+
const amended = `principles.md is draft — ${owner} amended it and its decompose gate approves it`;
|
|
321
|
+
if (gateParked(e.entries, 'decompose')) {
|
|
322
|
+
const reopen = reopenCommand('decompose', owner, e.entries, upstreamFor(root, 'decompose', owner));
|
|
323
|
+
return {
|
|
324
|
+
action: { line: 'witness check', note: `${amended} · its decompose is parked — witness status names its reopen` },
|
|
325
|
+
remedy: `${amended} · its decompose is parked — reopen it: ${reopen}`,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (decomposeOwed(root, canon, e, effortCanon(root, canon, owner), plans)) {
|
|
329
|
+
const step = decomposeStep(root, canon, e, judge);
|
|
330
|
+
return { action: { ...step, note: [amended, step.note].filter(Boolean).join(' · ') }, remedy: `${amended} — run: ${step.line}` };
|
|
331
|
+
}
|
|
332
|
+
const note = `principles.md is draft and ${owner}'s decompose is not owed now — witness log ${owner} shows where its gate stands`;
|
|
333
|
+
return { action: { line: 'witness check', note }, remedy: note };
|
|
334
|
+
}
|
|
286
335
|
// Row 205. The trust act: the human names, in the chat, each command to trust. The listing
|
|
287
336
|
// form of the verb, which grants nothing, so a routed line run verbatim cannot over-grant.
|
|
288
337
|
export function trustAction(target, owed) {
|
|
@@ -478,9 +527,12 @@ function lastDisposition(entries, gate, from) {
|
|
|
478
527
|
// the human parked something specific, and "parked" without "on what" is not a report.
|
|
479
528
|
export function parkedGates(root, canon) {
|
|
480
529
|
const out = [];
|
|
530
|
+
// Row 227. A parked gate on terminal work is owed to no one: a plan done or abandoned, an
|
|
531
|
+
// effort abandoned, offers nothing to reopen or approve.
|
|
481
532
|
const seen = [
|
|
482
|
-
...effortStreams(root).
|
|
483
|
-
|
|
533
|
+
...effortStreams(root).filter((slug) => !effortAbandoned(readStream(root, slug)))
|
|
534
|
+
.map((slug) => ({ id: slug, gates: ['decompose'] })),
|
|
535
|
+
...canon.docs.filter((d) => d.meta.type === 'plan' && !planFinished(d))
|
|
484
536
|
.map((d) => ({ id: String(d.meta.id), parent: String(d.meta.parent), gates: ['plan', 'implement', 'ship'] })),
|
|
485
537
|
...canon.docs.filter((d) => d.meta.type === 'spec')
|
|
486
538
|
.map((d) => ({ id: String(d.meta.id), gates: ['design'] })),
|
|
@@ -777,6 +829,11 @@ export function computeNext(root, ctx, canon, cfg, opts = {}) {
|
|
|
777
829
|
// gateable work, and they carry its goals — decompose is simply not owed here.
|
|
778
830
|
if (latestRecap(root, e.slug)?.class === 'chore') {
|
|
779
831
|
if (writes.size === 0) {
|
|
832
|
+
// Row 221. A chore's plan names the principles as its parent, which must be approved:
|
|
833
|
+
// a draft one is the owner's decompose to approve, never the write `write` would refuse.
|
|
834
|
+
const approval = principlesApproval(root, canon, judge);
|
|
835
|
+
if (approval !== undefined)
|
|
836
|
+
return approval.action;
|
|
780
837
|
return {
|
|
781
838
|
line: `witness write <plan-id> --effort ${e.slug} --meta m.json --body b.md`,
|
|
782
839
|
stage: 'plan', target: e.slug,
|
|
@@ -791,17 +848,8 @@ export function computeNext(root, ctx, canon, cfg, opts = {}) {
|
|
|
791
848
|
stage: 'decompose', target: e.slug,
|
|
792
849
|
};
|
|
793
850
|
}
|
|
794
|
-
if (decomposeOwed(root, canon, e,
|
|
795
|
-
|
|
796
|
-
return authoringOwed(e.entries, 'decompose', effortSha)
|
|
797
|
-
? {
|
|
798
|
-
line: `witness write <spec-id> --effort ${e.slug} --meta m.json --body b.md`,
|
|
799
|
-
stage: 'decompose', target: e.slug,
|
|
800
|
-
note: 'revise owed — re-author, then the gate has something new to judge',
|
|
801
|
-
}
|
|
802
|
-
: { line: `witness gate decompose --effort ${e.slug}`, target: e.slug,
|
|
803
|
-
...noteOf(judgeNote(e.entries, 'decompose', judge)) };
|
|
804
|
-
}
|
|
851
|
+
if (decomposeOwed(root, canon, e, effortCanon(root, canon, e.slug), plans))
|
|
852
|
+
return decomposeStep(root, canon, e, judge);
|
|
805
853
|
}
|
|
806
854
|
// Row 52 (Builder's call 8). While an effort owes the re-slice an amendment re-armed, the specs
|
|
807
855
|
// it wrote wait for it: a walk scoped to a spec never meets its effort's rung (`admits(e.slug)`
|
|
@@ -812,7 +860,7 @@ export function computeNext(root, ctx, canon, cfg, opts = {}) {
|
|
|
812
860
|
// admit can still owe it here. Flows, draft-plan gates and starts keep row 18's soft lock.
|
|
813
861
|
const reslicing = efforts
|
|
814
862
|
.filter((e) => !admits(e.slug) && latestRecap(root, e.slug)?.class !== 'chore' && effortWrites(root, e.slug).size > 0)
|
|
815
|
-
.filter((e) => amendedSinceSettled(e.entries) && decomposeOwed(root, canon, e,
|
|
863
|
+
.filter((e) => amendedSinceSettled(e.entries) && decomposeOwed(root, canon, e, effortCanon(root, canon, e.slug), plans));
|
|
816
864
|
const resliced = new Set(reslicing.flatMap((e) => [...effortWrites(root, e.slug).keys()]));
|
|
817
865
|
for (const spec of specs) {
|
|
818
866
|
if (String(spec.meta.status) !== 'approved')
|
package/dist/verbs/satisfy.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
2
|
import { EXIT } from '../cli.js';
|
|
3
|
+
import { sessionMarker } from '../drive-presence.js';
|
|
3
4
|
import { appendEntry, entryLine, journalRel } from '../journal.js';
|
|
4
5
|
import { primaryRoot, stateCommit } from '../gitio.js';
|
|
5
6
|
import { acquireLock } from '../lock.js';
|
|
@@ -19,6 +20,13 @@ export async function run(ctx, argv) {
|
|
|
19
20
|
renderRefusal([v('usage', 'required', 'missing id or --need', 'witness satisfy <doc-id> --need <id | index | text>')]).forEach(ctx.err);
|
|
20
21
|
return EXIT.REFUSED;
|
|
21
22
|
}
|
|
23
|
+
// Row 225. An unmet need is a kept stop for the human: a session drive spawned, or a
|
|
24
|
+
// reviewer, never marks one met — the human does, from their own chat or terminal.
|
|
25
|
+
const marker = sessionMarker(ctx.env);
|
|
26
|
+
if (marker !== undefined) {
|
|
27
|
+
renderRefusal([v('satisfy', 'satisfy-in-session', marker, 'the human marks a need met from their own chat or terminal')]).forEach(ctx.err);
|
|
28
|
+
return EXIT.REFUSED;
|
|
29
|
+
}
|
|
22
30
|
const rootRes = primaryRoot(ctx.cwd);
|
|
23
31
|
if (!rootRes.ok) {
|
|
24
32
|
renderRefusal(rootRes.violations).forEach(ctx.err);
|