@popovych.co/witness 0.30.0 → 0.32.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 +289 -7
- package/dist/abandon.js +19 -0
- package/dist/act.d.ts +1 -1
- package/dist/allowlist.d.ts +15 -0
- package/dist/allowlist.js +223 -28
- package/dist/always.d.ts +22 -0
- package/dist/always.js +108 -0
- package/dist/arbiter.d.ts +12 -5
- package/dist/arbiter.js +170 -13
- package/dist/ask.d.ts +6 -1
- package/dist/ask.js +35 -16
- package/dist/autonomy.d.ts +5 -2
- package/dist/autonomy.js +23 -2
- package/dist/base-lint.d.ts +31 -0
- package/dist/base-lint.js +213 -0
- package/dist/base-tests.d.ts +19 -0
- package/dist/base-tests.js +142 -0
- package/dist/behavior-map.d.ts +44 -0
- package/dist/behavior-map.js +408 -0
- package/dist/births.d.ts +35 -0
- package/dist/births.js +273 -0
- package/dist/breadth.d.ts +10 -0
- package/dist/breadth.js +423 -0
- package/dist/busy.js +4 -3
- package/dist/caps.js +3 -1
- package/dist/carry.d.ts +1 -1
- package/dist/carry.js +8 -11
- package/dist/cf-tree.d.ts +28 -0
- package/dist/cf-tree.js +157 -0
- package/dist/change-set.d.ts +9 -0
- package/dist/change-set.js +135 -0
- package/dist/checks.d.ts +20 -0
- package/dist/checks.js +114 -0
- package/dist/clash.d.ts +1 -0
- package/dist/clash.js +3 -2
- package/dist/cli.js +17 -5
- package/dist/config.d.ts +27 -3
- package/dist/config.js +115 -3
- package/dist/content-sha.js +9 -1
- package/dist/criteria.d.ts +12 -1
- package/dist/criteria.js +72 -2
- package/dist/deadline.d.ts +13 -0
- package/dist/deadline.js +205 -0
- package/dist/decide-view.d.ts +10 -0
- package/dist/decide-view.js +30 -3
- package/dist/definitions.d.ts +21 -0
- package/dist/definitions.js +388 -0
- package/dist/delta.js +5 -5
- package/dist/design.d.ts +3 -2
- package/dist/design.js +25 -10
- package/dist/diagnostics.d.ts +27 -0
- package/dist/diagnostics.js +212 -0
- package/dist/drafts.js +5 -1
- package/dist/drift.js +17 -5
- package/dist/drive-jobs.d.ts +43 -0
- package/dist/drive-jobs.js +210 -0
- package/dist/drive-presence.d.ts +3 -1
- package/dist/drive-presence.js +9 -3
- package/dist/drive-report.d.ts +1 -0
- package/dist/drive-report.js +43 -3
- package/dist/drive.d.ts +12 -4
- package/dist/drive.js +365 -103
- package/dist/dsl.d.ts +7 -0
- package/dist/dsl.js +22 -2
- package/dist/evidence.d.ts +4 -3
- package/dist/evidence.js +134 -312
- package/dist/explore-bridge.d.ts +33 -0
- package/dist/explore-bridge.js +332 -0
- package/dist/explore-claims.d.ts +43 -0
- package/dist/explore-claims.js +175 -0
- package/dist/explore-config.d.ts +21 -0
- package/dist/explore-config.js +67 -0
- package/dist/explore-env.d.ts +3 -0
- package/dist/explore-env.js +5 -0
- package/dist/explore-host.d.ts +53 -0
- package/dist/explore-host.js +212 -0
- package/dist/explore-job.d.ts +7 -0
- package/dist/explore-job.js +120 -0
- package/dist/explore-maps.d.ts +17 -0
- package/dist/explore-maps.js +107 -0
- package/dist/explore-marker.d.ts +8 -0
- package/dist/explore-marker.js +38 -0
- package/dist/explore-pi.d.ts +19 -0
- package/dist/explore-pi.js +99 -0
- package/dist/explore-relay.d.ts +1 -0
- package/dist/explore-relay.js +28 -0
- package/dist/explore-run.d.ts +49 -0
- package/dist/explore-run.js +251 -0
- package/dist/explore-verbs.d.ts +39 -0
- package/dist/explore-verbs.js +200 -0
- package/dist/explore-when.d.ts +25 -0
- package/dist/explore-when.js +141 -0
- package/dist/explorer-prompt.d.ts +9 -0
- package/dist/explorer-prompt.js +20 -0
- package/dist/explorer-session.d.ts +31 -0
- package/dist/explorer-session.js +229 -0
- package/dist/features-off.d.ts +7 -0
- package/dist/features-off.js +36 -0
- package/dist/findings.d.ts +22 -0
- package/dist/findings.js +120 -0
- package/dist/fm.js +2 -2
- package/dist/gate-run-view.d.ts +7 -2
- package/dist/gate-run-view.js +23 -9
- package/dist/gate.d.ts +10 -1
- package/dist/gate.js +159 -23
- package/dist/gates/decompose.js +38 -26
- package/dist/gates/design.js +16 -8
- package/dist/gates/implement.js +115 -41
- package/dist/gates/index.d.ts +1 -0
- package/dist/gates/index.js +1 -0
- package/dist/gates/map.d.ts +1 -0
- package/dist/gates/map.js +93 -0
- package/dist/gates/plan.js +20 -16
- package/dist/gates/ship.js +180 -42
- package/dist/gh-repo.d.ts +13 -0
- package/dist/gh-repo.js +100 -0
- package/dist/gitio.d.ts +2 -0
- package/dist/gitio.js +17 -3
- package/dist/glob.js +6 -0
- package/dist/guard.d.ts +108 -0
- package/dist/guard.js +567 -0
- package/dist/harness.d.ts +24 -0
- package/dist/harness.js +96 -3
- package/dist/held.d.ts +41 -0
- package/dist/held.js +411 -0
- package/dist/history.d.ts +5 -0
- package/dist/history.js +22 -0
- package/dist/install.d.ts +9 -2
- package/dist/install.js +152 -11
- package/dist/jobs.d.ts +103 -0
- package/dist/jobs.js +370 -0
- package/dist/journal.d.ts +13 -1
- package/dist/journal.js +11 -0
- package/dist/json-format.d.ts +7 -0
- package/dist/json-format.js +49 -0
- package/dist/junit.d.ts +18 -0
- package/dist/junit.js +48 -2
- package/dist/ledger.d.ts +332 -0
- package/dist/ledger.js +815 -0
- package/dist/lint-config.d.ts +17 -0
- package/dist/lint-config.js +241 -0
- package/dist/lint-effect.d.ts +71 -0
- package/dist/lint-effect.js +406 -0
- package/dist/lint-lane.d.ts +13 -0
- package/dist/lint-lane.js +229 -0
- package/dist/lint-parts.d.ts +12 -0
- package/dist/lint-parts.js +58 -0
- package/dist/lint-readers.d.ts +13 -0
- package/dist/lint-readers.js +172 -0
- package/dist/live-page.d.ts +3 -0
- package/dist/live-page.js +31 -0
- package/dist/live.js +3 -1
- package/dist/map-act.d.ts +15 -0
- package/dist/map-act.js +165 -0
- package/dist/map-page.d.ts +36 -0
- package/dist/map-page.js +233 -0
- package/dist/markers.d.ts +2 -0
- package/dist/markers.js +73 -0
- package/dist/matcher.d.ts +6 -0
- package/dist/matcher.js +25 -2
- package/dist/mcp-client.d.ts +14 -0
- package/dist/mcp-client.js +269 -0
- package/dist/merge-clock.d.ts +9 -0
- package/dist/merge-clock.js +43 -0
- package/dist/migration.d.ts +1 -0
- package/dist/migration.js +9 -3
- package/dist/models.d.ts +2 -0
- package/dist/models.js +4 -0
- package/dist/mutation-reports.d.ts +28 -0
- package/dist/mutation-reports.js +171 -0
- package/dist/mutation-scope.d.ts +20 -0
- package/dist/mutation-scope.js +171 -0
- package/dist/mutation.d.ts +65 -0
- package/dist/mutation.js +506 -0
- package/dist/needs-you.d.ts +11 -0
- package/dist/needs-you.js +47 -12
- package/dist/owed.d.ts +26 -0
- package/dist/owed.js +66 -0
- package/dist/parent-approvals.d.ts +3 -0
- package/dist/parent-approvals.js +26 -0
- package/dist/prepare.d.ts +13 -0
- package/dist/prepare.js +107 -0
- package/dist/progress.js +15 -1
- package/dist/proof-markdown.d.ts +16 -0
- package/dist/proof-markdown.js +241 -0
- package/dist/proof-text.d.ts +18 -0
- package/dist/proof-text.js +172 -0
- package/dist/proof.d.ts +175 -0
- package/dist/proof.js +435 -0
- package/dist/recommend.d.ts +5 -1
- package/dist/recommend.js +164 -7
- package/dist/record.d.ts +117 -0
- package/dist/record.js +354 -0
- package/dist/referral.d.ts +17 -0
- package/dist/referral.js +58 -0
- package/dist/released-comments.js +19 -0
- package/dist/repair-check-run.d.ts +20 -0
- package/dist/repair-check-run.js +119 -0
- package/dist/repair-check.d.ts +12 -0
- package/dist/repair-check.js +87 -0
- package/dist/replay-job.d.ts +24 -0
- package/dist/replay-job.js +90 -0
- package/dist/replay-points.d.ts +34 -0
- package/dist/replay-points.js +127 -0
- package/dist/replay-read.d.ts +41 -0
- package/dist/replay-read.js +87 -0
- package/dist/replay-run.d.ts +50 -0
- package/dist/replay-run.js +216 -0
- package/dist/replay-search.d.ts +11 -0
- package/dist/replay-search.js +58 -0
- package/dist/resource-lock.d.ts +23 -0
- package/dist/resource-lock.js +520 -0
- package/dist/retired-payload.d.ts +1 -0
- package/dist/retired-payload.js +98 -0
- package/dist/reviewed.js +6 -5
- package/dist/reviewer.d.ts +1 -1
- package/dist/reviewer.js +7 -5
- package/dist/rounds.d.ts +169 -4
- package/dist/rounds.js +142 -14
- package/dist/runner-lock.d.ts +26 -1
- package/dist/runner-lock.js +377 -29
- package/dist/runner.d.ts +26 -2
- package/dist/runner.js +84 -36
- package/dist/schemas.js +25 -0
- package/dist/scratch-checkout.d.ts +40 -0
- package/dist/scratch-checkout.js +262 -0
- package/dist/scratch-lock.d.ts +22 -0
- package/dist/scratch-lock.js +348 -0
- package/dist/scratch.d.ts +4 -0
- package/dist/scratch.js +34 -0
- package/dist/screens.d.ts +26 -0
- package/dist/screens.js +156 -0
- package/dist/self.d.ts +9 -0
- package/dist/self.js +88 -0
- package/dist/session-clock.d.ts +2 -0
- package/dist/session-clock.js +28 -8
- package/dist/settings.d.ts +34 -1
- package/dist/settings.js +151 -9
- package/dist/settle.d.ts +4 -0
- package/dist/settle.js +83 -4
- package/dist/sha.d.ts +1 -1
- package/dist/sha.js +1 -1
- package/dist/ship.d.ts +7 -3
- package/dist/ship.js +179 -36
- package/dist/slice.js +2 -0
- package/dist/snapshot.d.ts +1 -0
- package/dist/snapshot.js +39 -16
- package/dist/stamp.js +22 -2
- package/dist/steps.d.ts +5 -0
- package/dist/steps.js +15 -0
- package/dist/streams.d.ts +3 -0
- package/dist/streams.js +6 -0
- package/dist/switch-offs.d.ts +42 -0
- package/dist/switch-offs.js +511 -0
- package/dist/tests-effect.d.ts +48 -0
- package/dist/tests-effect.js +132 -0
- package/dist/tolerated-lists.d.ts +33 -0
- package/dist/tolerated-lists.js +247 -0
- package/dist/tolerated.d.ts +35 -0
- package/dist/tolerated.js +335 -0
- package/dist/verbs/abandon.js +31 -1
- package/dist/verbs/adopt.js +8 -1
- package/dist/verbs/check.js +108 -7
- package/dist/verbs/dashboard.d.ts +2 -1
- package/dist/verbs/dashboard.js +97 -5
- package/dist/verbs/decide.d.ts +3 -1
- package/dist/verbs/decide.js +306 -33
- package/dist/verbs/design.js +53 -5
- package/dist/verbs/diff.js +31 -7
- package/dist/verbs/dismiss.js +122 -4
- package/dist/verbs/draft.js +6 -2
- package/dist/verbs/drive.js +1 -1
- package/dist/verbs/evidence.js +11 -1
- package/dist/verbs/finding.d.ts +7 -0
- package/dist/verbs/finding.js +248 -0
- package/dist/verbs/gate.js +1 -1
- package/dist/verbs/guard.d.ts +2 -0
- package/dist/verbs/guard.js +244 -0
- package/dist/verbs/init.js +42 -4
- package/dist/verbs/job.d.ts +2 -0
- package/dist/verbs/job.js +123 -0
- package/dist/verbs/log.js +73 -3
- package/dist/verbs/map.d.ts +2 -0
- package/dist/verbs/map.js +159 -0
- package/dist/verbs/migrate.d.ts +3 -0
- package/dist/verbs/migrate.js +94 -18
- package/dist/verbs/next.d.ts +4 -2
- package/dist/verbs/next.js +256 -84
- package/dist/verbs/recap.d.ts +2 -0
- package/dist/verbs/recap.js +473 -7
- package/dist/verbs/recover.js +68 -3
- package/dist/verbs/rename.js +8 -2
- package/dist/verbs/review.js +1 -1
- package/dist/verbs/start.js +11 -0
- package/dist/verbs/trust.d.ts +22 -1
- package/dist/verbs/trust.js +149 -8
- package/dist/verbs/turn.js +5 -0
- package/dist/verbs/write.d.ts +1 -0
- package/dist/verbs/write.js +49 -10
- package/dist/verdict.d.ts +8 -0
- package/dist/verdict.js +17 -0
- package/dist/worktree.d.ts +4 -1
- package/dist/worktree.js +76 -22
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/witness.md +6 -5
- package/plugin/hooks/session-dashboard.sh +1 -1
- package/plugin/skills/witness-brainstorm/SKILL.md +7 -3
- package/plugin/skills/witness-decompose/SKILL.md +26 -6
- package/plugin/skills/witness-design/SKILL.md +4 -2
- package/plugin/skills/witness-implement/SKILL.md +10 -8
- package/plugin/skills/witness-plan/SKILL.md +7 -1
- package/plugin/skills/witness-ship/SKILL.md +5 -5
- package/prompts/arbiter.md +4 -0
- package/prompts/code-reviewer.md +2 -0
- package/prompts/explorer.md +23 -0
- package/prompts/map-reviewer.md +38 -0
- package/prompts/pr-test.md +5 -1
- package/prompts/silent-failure-hunter.md +2 -0
- package/prompts/slicing-critic.md +1 -1
- package/prompts/type-design.md +2 -0
package/dist/allowlist.js
CHANGED
|
@@ -1,22 +1,48 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { actOn, runRow } from './act.js';
|
|
4
|
+
import { lintCommands } from './lint-parts.js';
|
|
5
|
+
import { MUTATION_TOOLS, READER_TOOLS } from './settings.js';
|
|
6
|
+
import { pinnedCommands } from './explore-config.js';
|
|
7
|
+
import { globToRegExp } from './glob.js';
|
|
8
|
+
import { execFileSync } from './spawn.js';
|
|
4
9
|
import { heldCriteria } from './needs.js';
|
|
5
10
|
import { ok, refuse, v } from './refusal.js';
|
|
6
11
|
import { criteriaOwner, findById } from './scan.js';
|
|
7
12
|
import { hasControl, visible } from './toon.js';
|
|
8
13
|
const allowPath = (root) => join(root, '.witness', 'allow.json');
|
|
9
|
-
|
|
14
|
+
const BLOB_RE = /^[0-9a-f]{40}$/;
|
|
15
|
+
const isPinEntry = (x) => {
|
|
16
|
+
if (typeof x !== 'object' || x === null)
|
|
17
|
+
return false;
|
|
18
|
+
const { cmd, globs, files } = x;
|
|
19
|
+
return typeof cmd === 'string' && cmd !== ''
|
|
20
|
+
&& Array.isArray(globs) && globs.length > 0 && globs.every((g) => typeof g === 'string' && g !== '')
|
|
21
|
+
&& typeof files === 'object' && files !== null && !Array.isArray(files)
|
|
22
|
+
&& Object.keys(files).length > 0 && Object.values(files).every((b) => typeof b === 'string' && BLOB_RE.test(b));
|
|
23
|
+
};
|
|
24
|
+
function loadAllow(root) {
|
|
10
25
|
if (!existsSync(allowPath(root)))
|
|
11
|
-
return [];
|
|
26
|
+
return { commands: [], pins: [] };
|
|
12
27
|
try {
|
|
13
28
|
const parsed = JSON.parse(readFileSync(allowPath(root), 'utf8'));
|
|
14
|
-
return
|
|
29
|
+
return {
|
|
30
|
+
commands: Array.isArray(parsed.commands) ? parsed.commands.filter((c) => typeof c === 'string') : [],
|
|
31
|
+
pins: Array.isArray(parsed.pins) ? parsed.pins.filter(isPinEntry) : [],
|
|
32
|
+
};
|
|
15
33
|
}
|
|
16
34
|
catch {
|
|
17
|
-
return [];
|
|
35
|
+
return { commands: [], pins: [] };
|
|
18
36
|
}
|
|
19
37
|
}
|
|
38
|
+
const load = (root) => loadAllow(root).commands;
|
|
39
|
+
// Each writer keeps what it does not own: a command grant keeps the pins, a pin grant the commands.
|
|
40
|
+
function writeAllow(root, a) {
|
|
41
|
+
mkdirSync(join(root, '.witness'), { recursive: true });
|
|
42
|
+
writeFileSync(allowPath(root), JSON.stringify(a.pins.length ? { commands: a.commands, pins: a.pins } : { commands: a.commands }, null, 2));
|
|
43
|
+
}
|
|
44
|
+
// Row 320. Every set ever granted, malformed entries skipped.
|
|
45
|
+
export const loadPins = (root) => loadAllow(root).pins;
|
|
20
46
|
// D154. The trust list, read. One home for the fact "is this command trusted here", so the
|
|
21
47
|
// headless block, the decision surface and the `trust` verb cannot disagree about it.
|
|
22
48
|
export function trustedCommands(root) {
|
|
@@ -26,15 +52,137 @@ export function trustedCommands(root) {
|
|
|
26
52
|
// `--approve --trust-cmds`, or by the `trust` verb where no stop exists — and both routes
|
|
27
53
|
// land here rather than each writing the file their own way.
|
|
28
54
|
export function grantCommands(root, cmds) {
|
|
29
|
-
const have =
|
|
30
|
-
const merged = [...have];
|
|
55
|
+
const have = loadAllow(root);
|
|
56
|
+
const merged = [...have.commands];
|
|
31
57
|
for (const c of cmds)
|
|
32
58
|
if (!merged.includes(c))
|
|
33
59
|
merged.push(c);
|
|
34
|
-
if (merged.length === have.length)
|
|
60
|
+
if (merged.length === have.commands.length)
|
|
35
61
|
return;
|
|
36
|
-
|
|
37
|
-
|
|
62
|
+
writeAllow(root, { ...have, commands: merged });
|
|
63
|
+
}
|
|
64
|
+
const sameFiles = (a, b) => {
|
|
65
|
+
const ka = Object.keys(a);
|
|
66
|
+
return ka.length === Object.keys(b).length && ka.every((k) => b[k] === a[k]);
|
|
67
|
+
};
|
|
68
|
+
const sameGlobs = (a, b) => {
|
|
69
|
+
const sa = [...new Set(a)].sort();
|
|
70
|
+
const sb = [...new Set(b)].sort();
|
|
71
|
+
return sa.length === sb.length && sa.every((g, i) => g === sb[i]);
|
|
72
|
+
};
|
|
73
|
+
// Row 320. Append-dedupe, as `grantCommands`: a set already granted for the command is not added
|
|
74
|
+
// twice. Earlier sets stay, so an older merge (and T8c's bisect) runs the scripts read then.
|
|
75
|
+
export function grantPin(root, e) {
|
|
76
|
+
const have = loadAllow(root);
|
|
77
|
+
if (have.pins.some((p) => p.cmd === e.cmd && sameGlobs(p.globs, e.globs) && sameFiles(p.files, e.files)))
|
|
78
|
+
return;
|
|
79
|
+
writeAllow(root, { ...have, pins: [...have.pins, { cmd: e.cmd, globs: [...e.globs], files: { ...e.files } }] });
|
|
80
|
+
}
|
|
81
|
+
// How a case- and normalization-insensitive filesystem compares two names (APFS, NTFS, near enough;
|
|
82
|
+
// the run's check of the checkout catches what this misses).
|
|
83
|
+
const foldPath = (p) => p.normalize('NFC').toLowerCase();
|
|
84
|
+
// Row 320 (C107). The tracked files a pinned command's globs match at `commit`, each with its blob:
|
|
85
|
+
// one `ls-tree` of the whole commit, every glob tested on the full path. A link is refused (a pin
|
|
86
|
+
// of it pins its target's name, not the text that runs), and so is any other entry that is not a
|
|
87
|
+
// regular file — a submodule's gitlink pins no text at all (security review) — as is a glob that
|
|
88
|
+
// matches nothing (the human would grant a set that lacks what they declared) and a set past 200.
|
|
89
|
+
export function pinSet(root, globs, commit) {
|
|
90
|
+
const at12 = commit.slice(0, 12);
|
|
91
|
+
let out;
|
|
92
|
+
try {
|
|
93
|
+
out = execFileSync('git', ['ls-tree', '-r', '-z', '--full-tree', commit], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], maxBuffer: 256 * 1024 * 1024 });
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return refuse([v('--at', 'unknown-commit', at12, 'a commit this repository holds')]);
|
|
97
|
+
}
|
|
98
|
+
const res = globs.map(globToRegExp);
|
|
99
|
+
const hits = new Set();
|
|
100
|
+
const files = [];
|
|
101
|
+
// Slice 1 review C1: every spelling of each path and folder, by its folded form. A checkout on a
|
|
102
|
+
// case- or normalization-folding filesystem (macOS, Windows) writes two spellings to one file, so
|
|
103
|
+
// a tracked twin of a pinned path would run in its place while the pinned blob stays as granted.
|
|
104
|
+
const spellings = new Map();
|
|
105
|
+
const prefixes = (path) => path.split('/').map((_, i, segs) => segs.slice(0, i + 1).join('/'));
|
|
106
|
+
const records = [];
|
|
107
|
+
for (const rec of out.split('\0')) {
|
|
108
|
+
const tab = rec.indexOf('\t');
|
|
109
|
+
if (tab < 0)
|
|
110
|
+
continue;
|
|
111
|
+
const [mode, type, sha] = rec.slice(0, tab).split(' ');
|
|
112
|
+
const path = rec.slice(tab + 1);
|
|
113
|
+
records.push({ mode: mode, type: type, sha: sha, path });
|
|
114
|
+
for (const x of prefixes(path)) {
|
|
115
|
+
const key = foldPath(x);
|
|
116
|
+
const set = spellings.get(key) ?? new Set();
|
|
117
|
+
set.add(x);
|
|
118
|
+
spellings.set(key, set);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (const { mode, type, sha, path } of records) {
|
|
122
|
+
const matched = res.flatMap((re, i) => (re.test(path) ? [i] : []));
|
|
123
|
+
if (matched.length === 0)
|
|
124
|
+
continue;
|
|
125
|
+
matched.forEach((i) => hits.add(i));
|
|
126
|
+
if (mode === '120000') {
|
|
127
|
+
return refuse([v('files', 'pin-file-link', `${path} is a link`, "a regular file — a pin of a link pins its target's name, not its text")]);
|
|
128
|
+
}
|
|
129
|
+
if (type !== 'blob' || (mode !== '100644' && mode !== '100755')) {
|
|
130
|
+
return refuse([v('files', 'pin-file-not-regular', `${path} is a ${mode === '160000' ? 'submodule' : `${type} (${mode})`}`, 'regular files — a pin holds the text that runs, which a submodule or a tree is not')]);
|
|
131
|
+
}
|
|
132
|
+
files.push([path, sha]);
|
|
133
|
+
for (const x of prefixes(path)) {
|
|
134
|
+
const twin = [...spellings.get(foldPath(x))].find((y) => y !== x);
|
|
135
|
+
if (twin !== undefined) {
|
|
136
|
+
const entry = records.find((r) => r.path === twin || r.path.startsWith(`${twin}/`))?.path ?? twin;
|
|
137
|
+
return refuse([v('files', 'pin-path-collides', `${entry} folds onto ${path} at ${at12}`, 'one spelling per path — a case- or normalization-folding checkout writes one over the other')]);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const missing = globs.find((_, i) => !hits.has(i));
|
|
142
|
+
if (missing !== undefined) {
|
|
143
|
+
return refuse([v('files', 'pin-files-missing', `${missing} matches no tracked file at ${at12}`, 'globs that each match a file the commit tracks')]);
|
|
144
|
+
}
|
|
145
|
+
if (files.length > 200) {
|
|
146
|
+
return refuse([v('files', 'pin-too-many', `${files.length} files at ${at12}`, 'at most 200 files — declare the scripts that run, not the tree')]);
|
|
147
|
+
}
|
|
148
|
+
files.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
149
|
+
return ok(Object.fromEntries(files));
|
|
150
|
+
}
|
|
151
|
+
// Final review I4. What a grant at `commit` would pin that the command's newest granted set does not:
|
|
152
|
+
// the globs, when they differ, then the files changed, new and gone (five named each, then a count).
|
|
153
|
+
// 'never granted' for a command with no set; undefined when nothing differs or the files cannot be
|
|
154
|
+
// pinned. The human reads this before re-granting, so a narrowed declaration never looks routine.
|
|
155
|
+
export function pinNote(root, c, commit) {
|
|
156
|
+
const last = loadPins(root).filter((p) => p.cmd === c.cmd).at(-1);
|
|
157
|
+
if (last === undefined)
|
|
158
|
+
return 'never granted';
|
|
159
|
+
const set = pinSet(root, c.files ?? [], commit);
|
|
160
|
+
if (!set.ok)
|
|
161
|
+
return undefined;
|
|
162
|
+
// Paths and globs are the repo's text: each is escaped here, so the note prints as written.
|
|
163
|
+
const named = (xs) => (xs.length <= 5 ? xs.map(visible).join(', ') : `${xs.slice(0, 5).map(visible).join(', ')} and ${xs.length - 5} more`);
|
|
164
|
+
const changed = Object.keys(set.value).filter((k) => last.files[k] !== undefined && last.files[k] !== set.value[k]);
|
|
165
|
+
const added = Object.keys(set.value).filter((k) => last.files[k] === undefined);
|
|
166
|
+
const gone = Object.keys(last.files).filter((k) => set.value[k] === undefined);
|
|
167
|
+
const globs = !sameGlobs(last.globs, c.files ?? []);
|
|
168
|
+
const parts = [
|
|
169
|
+
...(globs ? [`globs changed since the last grant: ${last.globs.map(visible).join(', ')} → ${(c.files ?? []).map(visible).join(', ')}`] : []),
|
|
170
|
+
...(changed.length ? [`${globs ? 'changed' : 'changed since the last grant'}: ${named(changed)}`] : []),
|
|
171
|
+
...(added.length ? [`new: ${named(added)}`] : []),
|
|
172
|
+
...(gone.length ? [`gone: ${named(gone)}`] : []),
|
|
173
|
+
];
|
|
174
|
+
return parts.length ? parts.join(' · ') : undefined;
|
|
175
|
+
}
|
|
176
|
+
// Row 320 (C107). A pinned command runs at `commit` only when that commit's files equal a set the
|
|
177
|
+
// human granted for its exact command and its exact globs — or under the automation switch. Never
|
|
178
|
+
// prompts.
|
|
179
|
+
export function pinnedTrusted(root, env, c, commit) {
|
|
180
|
+
if (env.WITNESS_TRUST_CMDS === '1')
|
|
181
|
+
return true;
|
|
182
|
+
const set = pinSet(root, c.files ?? [], commit);
|
|
183
|
+
if (!set.ok)
|
|
184
|
+
return false;
|
|
185
|
+
return loadPins(root).some((p) => p.cmd === c.cmd && sameGlobs(p.globs, c.files ?? []) && sameFiles(p.files, set.value));
|
|
38
186
|
}
|
|
39
187
|
// D154. The `cmd:` criteria an artifact carries that this repo does not trust yet. The
|
|
40
188
|
// artifact is the SPEC that owns the criteria: a plan gate judges a plan, but criteria live
|
|
@@ -55,7 +203,7 @@ export function untrustedCmdsFor(root, doc) {
|
|
|
55
203
|
// Security review. Every surface that asks the human to trust a command — `next`'s kept stop,
|
|
56
204
|
// drive's report, the chat — renders it here: escaped, beside its source, and with the grant
|
|
57
205
|
// that names it only when the verb would take it (printable ASCII, `witness trust`).
|
|
58
|
-
export const shownCmd = (c) => `${visible(c.cmd)} (${visible(c.source)})`;
|
|
206
|
+
export const shownCmd = (c) => `${visible(c.cmd)} (${visible(c.source)}${c.at !== undefined ? ` · its files at ${c.at.slice(0, 12)}` : ''}${c.note !== undefined ? ` · ${c.note}` : ''})`;
|
|
59
207
|
export const UNGRANTABLE = 'never granted here — rewrite it in printable ASCII where it is written';
|
|
60
208
|
// Row 205. The commands a grant leaves blocked for that reason, counted: the trust verb's summary
|
|
61
209
|
// and `decide --approve --trust-cmds` say it in these words.
|
|
@@ -65,6 +213,12 @@ export const unsafeLeft = (n) => `${n} carry characters outside printable ASCII
|
|
|
65
213
|
export function grantAct(target, c, platform = process.platform) {
|
|
66
214
|
return hasControl(c.cmd) ? undefined : actOn(platform, ['trust', target, '--cmd', c.cmd]);
|
|
67
215
|
}
|
|
216
|
+
// Row 259. A repo command's grant: no target, since a job or a scratch prepare serves no artifact.
|
|
217
|
+
// The same rule as `grantAct`: none for a command the verb would not take.
|
|
218
|
+
// Row 320: a pinned command's grant names the commit whose files it pins.
|
|
219
|
+
export function repoGrantAct(c, platform = process.platform) {
|
|
220
|
+
return hasControl(c.cmd) ? undefined : actOn(platform, ['trust', '--cmd', c.cmd, ...(c.at !== undefined ? ['--at', c.at] : [])]);
|
|
221
|
+
}
|
|
68
222
|
// The grant's line, or why there is none. Row 239: a grant Windows withholds (`Act.withheld`) is
|
|
69
223
|
// never offered to be pasted, so the line names the listing instead, which grants nothing by
|
|
70
224
|
// itself: the command stays pending, and at a terminal the listing asks for each one.
|
|
@@ -92,8 +246,11 @@ export function grantRowsOf(grant, list) {
|
|
|
92
246
|
return [` note: ${UNGRANTABLE}`];
|
|
93
247
|
return grant.withheld === undefined ? [runRow(grant)] : [` note: ${grant.withheld}`, runRow(list)];
|
|
94
248
|
}
|
|
95
|
-
// The filtered runner template, `ship.test`, `ship.lint
|
|
96
|
-
//
|
|
249
|
+
// The filtered runner template, `ship.test`, every `ship.lint` part and its bound reader (rows 261–262),
|
|
250
|
+
// every other set reader, `scratch.prepare`, each when set. Full-suite mode's runner IS `ship.test`,
|
|
251
|
+
// and a command listed twice is listed once, under its first source. A reader no part bears the name
|
|
252
|
+
// of is declared all the same (slice 1 review I1): migrate proposes and grants it, so the targetless
|
|
253
|
+
// grant takes it, but nothing owes it until a part bears its name (`trustOwed`).
|
|
97
254
|
export function configCommands(cfg) {
|
|
98
255
|
const out = [];
|
|
99
256
|
const add = (cmd, source) => {
|
|
@@ -103,7 +260,18 @@ export function configCommands(cfg) {
|
|
|
103
260
|
if (cfg.criteria.runner !== 'full-suite')
|
|
104
261
|
add(cfg.criteria.runner, 'criteria.runner');
|
|
105
262
|
add(cfg.ship.test, 'ship.test');
|
|
106
|
-
|
|
263
|
+
// Row 280. A test guard's command, its `{files}` template granted whole (as the runner's `{id}`).
|
|
264
|
+
add(cfg.criteria.byFile, 'criteria.byFile');
|
|
265
|
+
for (const c of lintCommands(cfg))
|
|
266
|
+
add(c.cmd, c.source);
|
|
267
|
+
for (const tool of READER_TOOLS)
|
|
268
|
+
add(cfg.readers[tool], `readers.${tool}`);
|
|
269
|
+
// Row 292. Each mutation tool's command, granted once with the targetless grant.
|
|
270
|
+
for (const tool of MUTATION_TOOLS)
|
|
271
|
+
add(cfg.mutation[tool], `mutation.${tool}`);
|
|
272
|
+
// Row 259. The scratch's setup command, when there is one to run.
|
|
273
|
+
if (cfg.scratch.prepare !== 'none')
|
|
274
|
+
add(cfg.scratch.prepare, 'scratch.prepare');
|
|
107
275
|
return out;
|
|
108
276
|
}
|
|
109
277
|
const cmdCriteria = (doc) => (Array.isArray(doc.meta.criteria) ? doc.meta.criteria : [])
|
|
@@ -131,6 +299,8 @@ export function sourced(cfg, canon, target, cmds) {
|
|
|
131
299
|
export function repoCommands(cfg, canon) {
|
|
132
300
|
return [
|
|
133
301
|
...configCommands(cfg).map((c) => ({ ...c, doc: '-' })),
|
|
302
|
+
// Row 320. Each pinned command (explore's host and login), its status read from its file sets.
|
|
303
|
+
...pinnedCommands(cfg).map((c) => ({ ...c, doc: '-' })),
|
|
134
304
|
...canon.docs.flatMap((d) => [...cmdCriteria(d), ...cmdNeeds(d)].map((c) => ({ ...c, doc: String(d.meta.id) }))),
|
|
135
305
|
];
|
|
136
306
|
}
|
|
@@ -152,7 +322,7 @@ export function pendingRows(listing, platform = process.platform) {
|
|
|
152
322
|
// pending, so the verb's terminal prompt and `--yes` still reach it.
|
|
153
323
|
export function trustListing(root, cfg, canon, target, platform = process.platform) {
|
|
154
324
|
if (target === undefined)
|
|
155
|
-
return ok(listingOf(root, repoCommands(cfg, canon)));
|
|
325
|
+
return ok(listingOf(root, repoCommands(cfg, canon), undefined, platform, pinnedStatus(root, cfg)));
|
|
156
326
|
const doc = findById(canon, target);
|
|
157
327
|
if (!doc)
|
|
158
328
|
return refuse([v('artifact', 'unknown-artifact', target, 'an existing canon doc id', 'witness index')]);
|
|
@@ -160,29 +330,43 @@ export function trustListing(root, cfg, canon, target, platform = process.platfo
|
|
|
160
330
|
}
|
|
161
331
|
// The counts are of the raw commands, never of their escaped rows: two commands can escape to
|
|
162
332
|
// the same text.
|
|
163
|
-
function listingOf(root, listed, target, platform = process.platform) {
|
|
333
|
+
function listingOf(root, listed, target, platform = process.platform, pinned) {
|
|
164
334
|
const trusted = new Set(load(root));
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
const
|
|
335
|
+
// Row 320. A pinned row's status is its file sets', never allow.json's `commands`.
|
|
336
|
+
const statusOf = (c) => (c.files !== undefined && pinned !== undefined ? pinned(c) : trustStatus(trusted, c.cmd));
|
|
337
|
+
const once = [...new Map(listed.map((c) => [`${c.files !== undefined ? 'pin' : 'cmd'}\0${c.cmd}`, c])).values()];
|
|
338
|
+
const untrusted = once.filter((c) => statusOf(c) === 'untrusted');
|
|
168
339
|
return {
|
|
169
340
|
...(target !== undefined ? { target } : {}),
|
|
170
341
|
rows: listed.map((c) => ({
|
|
171
|
-
cmd: visible(c.cmd), source: visible(c.source), ...(c.doc !== undefined ? { doc: visible(c.doc) } : {}), status:
|
|
342
|
+
cmd: visible(c.cmd), source: visible(c.source), ...(c.doc !== undefined ? { doc: visible(c.doc) } : {}), status: statusOf(c),
|
|
172
343
|
})),
|
|
173
|
-
pending: target === undefined ? [] : untrusted.flatMap((
|
|
344
|
+
pending: target === undefined ? [] : untrusted.flatMap((c) => grantAct(target, c, platform) ?? []),
|
|
174
345
|
untrusted: untrusted.length,
|
|
175
346
|
// A residual kept byte for byte: the repo listing counts rows, so a command two docs run
|
|
176
347
|
// counts twice.
|
|
177
|
-
unsafe: (target === undefined ? listed
|
|
348
|
+
unsafe: (target === undefined ? listed : once).filter((c) => statusOf(c) === 'unsafe').length,
|
|
178
349
|
};
|
|
179
350
|
}
|
|
351
|
+
// Row 320. A pinned command's status at the ship branch's tip: trusted when the tip's files are a
|
|
352
|
+
// granted set; a tip that does not resolve reads untrusted. A command outside printable ASCII is
|
|
353
|
+
// unsafe, as every other row.
|
|
354
|
+
function pinnedStatus(root, cfg) {
|
|
355
|
+
let tip;
|
|
356
|
+
try {
|
|
357
|
+
tip = execFileSync('git', ['rev-parse', '--verify', '--quiet', `refs/heads/${cfg.ship.branch}^{commit}`], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
tip = undefined;
|
|
361
|
+
}
|
|
362
|
+
return (c) => (hasControl(c.cmd) ? 'unsafe' : tip !== undefined && pinnedTrusted(root, {}, c, tip) ? 'trusted' : 'untrusted');
|
|
363
|
+
}
|
|
180
364
|
// Row 205 (issue #56, P5). The commands the routed action's verb runs that this machine does
|
|
181
365
|
// not trust yet, checked before any work: found only inside the session, a refusal journaled
|
|
182
366
|
// nothing, `next` routed the same line again and drive respawned it to the cap. Only the
|
|
183
367
|
// commands with no "no" path — the runner (the template, or ship.test in full-suite) for the
|
|
184
|
-
// evidence verbs
|
|
185
|
-
// own cmd: needs. Never cmd: criteria (row 154): a plain approve leaves them blocked at a
|
|
368
|
+
// evidence verbs; that plus every ship.lint part and bound reader for the implement gate (row
|
|
369
|
+
// 265); those plus ship.test for ship; a start's own cmd: needs. Never cmd: criteria (row 154): a plain approve leaves them blocked at a
|
|
186
370
|
// headless gate, so trust is never the toll, and a gate whose check failed on one reaches the
|
|
187
371
|
// settle pass's trust-grant stop instead.
|
|
188
372
|
export function trustOwed(root, env, cfg, canon, action) {
|
|
@@ -190,12 +374,18 @@ export function trustOwed(root, env, cfg, canon, action) {
|
|
|
190
374
|
return [];
|
|
191
375
|
const config = configCommands(cfg);
|
|
192
376
|
const runner = config.filter((c) => c.source === (cfg.criteria.runner === 'full-suite' ? 'ship.test' : 'criteria.runner'));
|
|
377
|
+
// Rows 261–262. Ship runs its suite, every lint part and every bound reader — never a reader no
|
|
378
|
+
// part bears the name of (slice 1 review I1). Row 265: the implement gate runs the lint parts and
|
|
379
|
+
// their readers too, never ship.test.
|
|
380
|
+
const lints = lintCommands(cfg);
|
|
381
|
+
const shipRuns = new Set([cfg.ship.test, ...lints.map((c) => c.cmd)]);
|
|
193
382
|
const line = `${action.line} `;
|
|
194
|
-
const run = /^witness (test-evidence|verify-red|
|
|
195
|
-
: /^witness
|
|
196
|
-
: /^witness
|
|
197
|
-
|
|
198
|
-
|
|
383
|
+
const run = /^witness (test-evidence|verify-red|check --drift) /.test(line) ? runner
|
|
384
|
+
: /^witness gate implement /.test(line) ? [...runner, ...lints]
|
|
385
|
+
: /^witness (ship|gate ship) /.test(line) ? [...runner, ...config.filter((c) => shipRuns.has(c.cmd))]
|
|
386
|
+
: /^witness start /.test(line) && action.target !== undefined
|
|
387
|
+
? (() => { const doc = canon.docs.find((d) => d.meta.id === action.target); return doc ? cmdNeeds(doc) : []; })()
|
|
388
|
+
: [];
|
|
199
389
|
const trusted = new Set(load(root));
|
|
200
390
|
const out = [];
|
|
201
391
|
for (const c of run)
|
|
@@ -203,6 +393,11 @@ export function trustOwed(root, env, cfg, canon, action) {
|
|
|
203
393
|
out.push(c);
|
|
204
394
|
return out;
|
|
205
395
|
}
|
|
396
|
+
// Row 259. Trusted right now, by the human's list or the automation switch. Never prompts: the
|
|
397
|
+
// headless paths (a scratch prepare, a job's commands) ask nothing, they wait for the human's grant.
|
|
398
|
+
export function trustedNow(root, env, cmd) {
|
|
399
|
+
return env.WITNESS_TRUST_CMDS === '1' || load(root).includes(cmd);
|
|
400
|
+
}
|
|
206
401
|
export async function ensureTrusted(root, ctx, cmd) {
|
|
207
402
|
if (ctx.env.WITNESS_TRUST_CMDS === '1')
|
|
208
403
|
return 'trusted';
|
package/dist/always.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Violation } from './refusal.js';
|
|
2
|
+
export interface AlwaysRule {
|
|
3
|
+
id: string;
|
|
4
|
+
tag: string;
|
|
5
|
+
statement: string;
|
|
6
|
+
}
|
|
7
|
+
type DocLike = {
|
|
8
|
+
meta: Record<string, unknown>;
|
|
9
|
+
body: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function alwaysRules(doc: DocLike): AlwaysRule[];
|
|
12
|
+
export declare function validateAlways(meta: Record<string, unknown>, body: string): Violation[];
|
|
13
|
+
export declare function alwaysWithoutReport(meta: Record<string, unknown>, report: string | undefined): Violation[];
|
|
14
|
+
export declare function alwaysBuilt(plan: {
|
|
15
|
+
meta: Record<string, unknown>;
|
|
16
|
+
}, parent: DocLike): string[];
|
|
17
|
+
export declare function alwaysAdded(built: readonly string[]): Array<{
|
|
18
|
+
lens: string;
|
|
19
|
+
why: string;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function alwaysNotes(doc: DocLike, built: readonly string[]): string;
|
|
22
|
+
export {};
|
package/dist/always.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { alwaysOf, alwaysTag } from './dsl.js';
|
|
2
|
+
import { v } from './refusal.js';
|
|
3
|
+
import { headingLines, sectionText } from './verdict.js';
|
|
4
|
+
// The rule ids a doc's criteria name, once each, in criteria order.
|
|
5
|
+
function ruleIds(meta) {
|
|
6
|
+
const specId = meta.id;
|
|
7
|
+
if (typeof specId !== 'string' || !Array.isArray(meta.criteria))
|
|
8
|
+
return [];
|
|
9
|
+
const ids = meta.criteria
|
|
10
|
+
.filter((c) => typeof c === 'object' && c !== null)
|
|
11
|
+
.flatMap((c) => { const r = alwaysOf(c, specId); return r !== undefined ? [r] : []; });
|
|
12
|
+
return [...new Set(ids)];
|
|
13
|
+
}
|
|
14
|
+
// `## Behavior`'s own section, never the whole body: a later section may hold the same heading.
|
|
15
|
+
const behaviorOf = (body) => sectionText(body, ['## Behavior']) ?? '';
|
|
16
|
+
const headingOf = (id) => `### Always: ${id}`;
|
|
17
|
+
// The section under the rule's first heading (the anchor model: up to the next heading at its level or
|
|
18
|
+
// above), its heading line dropped, trimmed; '' when there is none.
|
|
19
|
+
function statementOf(behavior, id) {
|
|
20
|
+
const section = sectionText(behavior, [headingOf(id)]);
|
|
21
|
+
return section === undefined ? '' : section.split('\n').slice(1).join('\n').trim();
|
|
22
|
+
}
|
|
23
|
+
export function alwaysRules(doc) {
|
|
24
|
+
const specId = String(doc.meta.id);
|
|
25
|
+
const behavior = behaviorOf(doc.body);
|
|
26
|
+
return ruleIds(doc.meta).map((id) => ({ id, tag: alwaysTag(specId, id), statement: statementOf(behavior, id) }));
|
|
27
|
+
}
|
|
28
|
+
// Row 303. A spec's statements, judged with the doc (write, adopt, check): the missing (criteria order),
|
|
29
|
+
// the orphans (heading order — a `### Always:` heading under ## Behavior that names no rule of this spec,
|
|
30
|
+
// malformed ones included), the duplicates, the empty.
|
|
31
|
+
export function validateAlways(meta, body) {
|
|
32
|
+
if (meta.type !== 'spec')
|
|
33
|
+
return [];
|
|
34
|
+
const ids = ruleIds(meta);
|
|
35
|
+
const behavior = behaviorOf(body);
|
|
36
|
+
const counts = new Map();
|
|
37
|
+
const orphans = [];
|
|
38
|
+
for (const h of headingLines(behavior).filter((l) => l.startsWith('### Always:'))) {
|
|
39
|
+
const id = ids.find((x) => h === headingOf(x));
|
|
40
|
+
if (id === undefined)
|
|
41
|
+
orphans.push(h);
|
|
42
|
+
else
|
|
43
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
44
|
+
}
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const id of ids) {
|
|
47
|
+
if (!counts.has(id))
|
|
48
|
+
out.push(v('body', 'always-statement-missing', id, `'${headingOf(id)}' under ## Behavior, then the rule in plain sentences`));
|
|
49
|
+
}
|
|
50
|
+
for (const h of orphans) {
|
|
51
|
+
out.push(v('body', 'always-statement-orphan', h, `every ### Always: heading under ## Behavior names one of this spec's always-rules: ${ids.join(' · ') || '(none)'}`));
|
|
52
|
+
}
|
|
53
|
+
for (const id of ids) {
|
|
54
|
+
if ((counts.get(id) ?? 0) > 1)
|
|
55
|
+
out.push(v('body', 'always-statement-duplicate', id, `one '${headingOf(id)}' heading per always-rule`));
|
|
56
|
+
}
|
|
57
|
+
for (const id of ids) {
|
|
58
|
+
if (counts.has(id) && statementOf(behavior, id) === '')
|
|
59
|
+
out.push(v('body', 'always-statement-empty', id, 'the rule in plain sentences under its heading'));
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
const NEEDS_REPORT_WANT = "criteria.report: junit:<glob> — an always-rule is judged by its own tests' names, which only a junit report holds · or the plain @spec:<id> tag";
|
|
64
|
+
// Row 304. An always-rule is judged by its own cases, which only a junit report names: write and adopt
|
|
65
|
+
// refuse one while `criteria.report` is none. `report` is the typed config's (undefined = none).
|
|
66
|
+
export function alwaysWithoutReport(meta, report) {
|
|
67
|
+
const specId = meta.id;
|
|
68
|
+
if (report !== undefined || typeof specId !== 'string' || !Array.isArray(meta.criteria))
|
|
69
|
+
return [];
|
|
70
|
+
return meta.criteria.flatMap((c, i) => typeof c === 'object' && c !== null && alwaysOf(c, specId) !== undefined
|
|
71
|
+
? [v(`criteria[${i}].test`, 'always-needs-report', String(c.test), NEEDS_REPORT_WANT)]
|
|
72
|
+
: []);
|
|
73
|
+
}
|
|
74
|
+
// Row 306. The parent's always-rules a plan's steps list, in the parent's criteria order: the rules the plan
|
|
75
|
+
// builds. Implement adds pr-test for them, and both code gates mark them in the reviewers' notes.
|
|
76
|
+
export function alwaysBuilt(plan, parent) {
|
|
77
|
+
const steps = Array.isArray(plan.meta.steps) ? plan.meta.steps : [];
|
|
78
|
+
const listed = new Set(steps.flatMap((st) => {
|
|
79
|
+
const criteria = typeof st === 'object' && st !== null ? st.criteria : undefined;
|
|
80
|
+
return Array.isArray(criteria) ? criteria : [];
|
|
81
|
+
}));
|
|
82
|
+
return alwaysRules(parent).map((r) => r.id).filter((id) => listed.has(id));
|
|
83
|
+
}
|
|
84
|
+
// Row 306 (C84). The lens a plan that builds a rule brings, with its cause for the round's `added:` line —
|
|
85
|
+
// the ids joined by ` + `, never a comma, which would quote the line.
|
|
86
|
+
export function alwaysAdded(built) {
|
|
87
|
+
return built.length === 0 ? [] : [{ lens: 'pr-test', why: `the plan builds always-rule${built.length > 1 ? 's' : ''} ${built.join(' + ')}` }];
|
|
88
|
+
}
|
|
89
|
+
// Row 305 (C83). At implement the reviewers see the plan, not the spec: both code gates append the parent's
|
|
90
|
+
// rules to the reviewed content, each statement on one line, so pr-test can judge whether their tests
|
|
91
|
+
// explore many orders or inputs. A statement is canon text, as the spec itself is at ship. Slice 2 review:
|
|
92
|
+
// the rules the plan builds are marked, the rest are context — an old rule outside the plan is no gap of its.
|
|
93
|
+
export function alwaysNotes(doc, built) {
|
|
94
|
+
const rules = alwaysRules(doc);
|
|
95
|
+
if (rules.length === 0)
|
|
96
|
+
return '';
|
|
97
|
+
const marked = rules.some((r) => built.includes(r.id));
|
|
98
|
+
return [
|
|
99
|
+
`### Always-rules of ${String(doc.meta.id)}`,
|
|
100
|
+
'',
|
|
101
|
+
'Each holds whatever the order or input; its tests carry its tag in their names (a Rust test, in its path: spec_<spec>::<rule>). ' +
|
|
102
|
+
(marked
|
|
103
|
+
? 'The rules marked (built by this plan) are the ones its steps build; the others are context.'
|
|
104
|
+
: "This plan's steps build none of them: they are context."),
|
|
105
|
+
'',
|
|
106
|
+
...rules.map((r) => `- ${r.id}${built.includes(r.id) ? ' (built by this plan)' : ''} — tests named ${r.tag}: ${r.statement.replace(/\s+/g, ' ').trim()}`),
|
|
107
|
+
].join('\n');
|
|
108
|
+
}
|
package/dist/arbiter.d.ts
CHANGED
|
@@ -4,16 +4,23 @@ import { type Config } from './config.js';
|
|
|
4
4
|
import { type Entry } from './journal.js';
|
|
5
5
|
import type { Decision, Option } from './recommend.js';
|
|
6
6
|
import { type Result } from './refusal.js';
|
|
7
|
-
import { type GateRunEntry } from './rounds.js';
|
|
7
|
+
import { type GateCheck, type GateRunEntry } from './rounds.js';
|
|
8
8
|
import { type Canon } from './scan.js';
|
|
9
9
|
export type ArbiterMode = 'decision';
|
|
10
10
|
export interface ArbiterSection {
|
|
11
11
|
title: string;
|
|
12
12
|
body: string;
|
|
13
13
|
}
|
|
14
|
+
export type ArbiterOption = (Option & {
|
|
15
|
+
act: Act;
|
|
16
|
+
refer?: undefined;
|
|
17
|
+
}) | (Option & {
|
|
18
|
+
refer: true;
|
|
19
|
+
act?: undefined;
|
|
20
|
+
});
|
|
14
21
|
export interface ArbiterRequest {
|
|
15
22
|
mode: ArbiterMode;
|
|
16
|
-
menu: readonly
|
|
23
|
+
menu: readonly ArbiterOption[];
|
|
17
24
|
evidence: readonly ArbiterSection[];
|
|
18
25
|
}
|
|
19
26
|
export interface ArbiterRuling {
|
|
@@ -25,10 +32,10 @@ export interface ArbiterRuling {
|
|
|
25
32
|
}
|
|
26
33
|
export declare const PROMPT_OF: Record<ArbiterMode, string>;
|
|
27
34
|
export declare function arbitrate(ctx: Ctx, root: string, cfg: Config, req: ArbiterRequest): Promise<Result<ArbiterRuling>>;
|
|
28
|
-
export declare
|
|
29
|
-
|
|
30
|
-
}>;
|
|
35
|
+
export declare const REFER_OPTION: ArbiterOption;
|
|
36
|
+
export declare function menuFor(block: Decision, run: GateRunEntry): ArbiterOption[];
|
|
31
37
|
export declare const HANDED_BACK_FACT = "the author handed this revise back with the content unchanged";
|
|
38
|
+
export declare function checkFacts(c: GateCheck): string;
|
|
32
39
|
export declare function decisionEvidence(root: string, canon: Canon, stop: {
|
|
33
40
|
gate: string;
|
|
34
41
|
target: string;
|