@popovych.co/witness 0.28.2 → 0.28.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/abandon.d.ts +67 -0
- package/dist/act.d.ts +16 -0
- package/dist/act.js +61 -0
- package/dist/adopt.d.ts +21 -0
- package/dist/allowlist.d.ts +48 -0
- package/dist/allowlist.js +79 -5
- package/dist/arbiter.d.ts +37 -0
- package/dist/arbiter.js +7 -5
- package/dist/ask.d.ts +29 -0
- package/dist/ask.js +11 -5
- package/dist/autonomy.d.ts +46 -0
- package/dist/autonomy.js +24 -12
- package/dist/awake.d.ts +15 -0
- package/dist/basis.d.ts +9 -0
- package/dist/battery.d.ts +23 -0
- package/dist/bin.d.ts +2 -0
- package/dist/caps.d.ts +20 -0
- package/dist/cli.d.ts +18 -0
- package/dist/config-file.d.ts +12 -0
- package/dist/config.d.ts +96 -0
- package/dist/config.js +2 -1
- package/dist/contain.d.ts +16 -0
- package/dist/context.d.ts +25 -0
- package/dist/criteria.d.ts +27 -0
- package/dist/criteria.js +2 -1
- package/dist/decide-view.d.ts +46 -0
- package/dist/decide-view.js +137 -0
- package/dist/decisions.d.ts +23 -0
- package/dist/deferral.d.ts +26 -0
- package/dist/delta.d.ts +58 -0
- package/dist/departure.d.ts +66 -0
- package/dist/design.d.ts +34 -0
- package/dist/drafts.d.ts +31 -0
- package/dist/drafts.js +5 -3
- package/dist/drift.d.ts +23 -0
- package/dist/drive-presence.d.ts +27 -0
- package/dist/drive-presence.js +15 -4
- package/dist/drive-report.d.ts +24 -0
- package/dist/drive-report.js +4 -4
- package/dist/drive.d.ts +97 -0
- package/dist/drive.js +68 -71
- package/dist/dsl.d.ts +23 -0
- package/dist/dsl.js +8 -3
- package/dist/evidence.d.ts +65 -0
- package/dist/floor.d.ts +6 -0
- package/dist/fm.d.ts +9 -0
- package/dist/gate-run-view.d.ts +57 -0
- package/dist/gate-run-view.js +100 -0
- package/dist/gate.d.ts +91 -0
- package/dist/gate.js +14 -67
- package/dist/gates/decompose.d.ts +1 -0
- package/dist/gates/decompose.js +3 -1
- package/dist/gates/design.d.ts +1 -0
- package/dist/gates/design.js +6 -2
- package/dist/gates/implement.d.ts +1 -0
- package/dist/gates/implement.js +9 -2
- package/dist/gates/index.d.ts +5 -0
- package/dist/gates/plan.d.ts +1 -0
- package/dist/gates/plan.js +10 -4
- package/dist/gates/ship.d.ts +1 -0
- package/dist/gates/ship.js +4 -2
- package/dist/gitio.d.ts +30 -0
- package/dist/gitio.js +4 -1
- package/dist/glob.d.ts +2 -0
- package/dist/harness.d.ts +73 -0
- package/dist/harness.js +36 -15
- package/dist/history.d.ts +10 -0
- package/dist/idlists.d.ts +2 -0
- package/dist/install.d.ts +29 -0
- package/dist/journal.d.ts +74 -0
- package/dist/journal.js +5 -1
- package/dist/junit.d.ts +9 -0
- package/dist/live.d.ts +24 -0
- package/dist/lock.d.ts +9 -0
- package/dist/matcher.d.ts +8 -0
- package/dist/migration.d.ts +25 -0
- package/dist/model.d.ts +8 -0
- package/dist/models.d.ts +9 -0
- package/dist/models.js +10 -0
- package/dist/needs-you.d.ts +75 -0
- package/dist/needs-you.js +104 -40
- package/dist/needs.d.ts +44 -0
- package/dist/needs.js +37 -7
- package/dist/notify.d.ts +12 -0
- package/dist/opener.d.ts +15 -0
- package/dist/pin.d.ts +12 -0
- package/dist/pin.js +9 -2
- package/dist/principles.d.ts +3 -0
- package/dist/probe.d.ts +1 -0
- package/dist/progress.d.ts +3 -0
- package/dist/recommend.d.ts +31 -0
- package/dist/recommend.js +51 -42
- package/dist/refusal.d.ts +20 -0
- package/dist/refusal.js +12 -4
- package/dist/registry.d.ts +1 -0
- package/dist/released-comments.d.ts +1 -0
- package/dist/review.d.ts +27 -0
- package/dist/reviewed.d.ts +23 -0
- package/dist/reviewer.d.ts +47 -0
- package/dist/rounds.d.ts +135 -0
- package/dist/rounds.js +38 -21
- package/dist/runner-lock.d.ts +5 -0
- package/dist/runner.d.ts +30 -0
- package/dist/scan.d.ts +27 -0
- package/dist/schemas.d.ts +11 -0
- package/dist/schemas.js +7 -3
- package/dist/session-clock.d.ts +16 -0
- package/dist/settings.d.ts +73 -0
- package/dist/settings.js +12 -2
- package/dist/settle.d.ts +39 -0
- package/dist/settle.js +59 -30
- package/dist/sha.d.ts +5 -0
- package/dist/ship.d.ts +20 -0
- package/dist/ship.js +21 -12
- package/dist/slice.d.ts +45 -0
- package/dist/slice.js +2 -2
- package/dist/snapshot.d.ts +10 -0
- package/dist/spawn.d.ts +22 -0
- package/dist/stamp.d.ts +27 -0
- package/dist/stamp.js +3 -1
- package/dist/steps.d.ts +30 -0
- package/dist/steps.js +8 -3
- package/dist/toon.d.ts +17 -0
- package/dist/toon.js +150 -14
- package/dist/txn.d.ts +28 -0
- package/dist/usage.d.ts +25 -0
- package/dist/verbs/abandon.d.ts +2 -0
- package/dist/verbs/adopt.d.ts +2 -0
- package/dist/verbs/adopt.js +9 -4
- package/dist/verbs/ask.d.ts +2 -0
- package/dist/verbs/check.d.ts +2 -0
- package/dist/verbs/check.js +29 -10
- package/dist/verbs/clean.d.ts +2 -0
- package/dist/verbs/dashboard.d.ts +59 -0
- package/dist/verbs/dashboard.js +4 -2
- package/dist/verbs/decide.d.ts +34 -0
- package/dist/verbs/decide.js +95 -130
- package/dist/verbs/design.d.ts +2 -0
- package/dist/verbs/design.js +8 -5
- package/dist/verbs/diff.d.ts +2 -0
- package/dist/verbs/diff.js +4 -2
- package/dist/verbs/dismiss.d.ts +2 -0
- package/dist/verbs/dispatch.d.ts +2 -0
- package/dist/verbs/dispatch.js +2 -2
- package/dist/verbs/draft.d.ts +2 -0
- package/dist/verbs/draft.js +6 -3
- package/dist/verbs/drive.d.ts +2 -0
- package/dist/verbs/evidence.d.ts +5 -0
- package/dist/verbs/floor.d.ts +2 -0
- package/dist/verbs/gate.d.ts +3 -0
- package/dist/verbs/index-verb.d.ts +2 -0
- package/dist/verbs/init.d.ts +2 -0
- package/dist/verbs/log.d.ts +9 -0
- package/dist/verbs/migrate.d.ts +13 -0
- package/dist/verbs/next.d.ts +61 -0
- package/dist/verbs/next.js +112 -84
- package/dist/verbs/read.d.ts +2 -0
- package/dist/verbs/read.js +3 -1
- package/dist/verbs/recap.d.ts +28 -0
- package/dist/verbs/recap.js +3 -3
- package/dist/verbs/recover.d.ts +5 -0
- package/dist/verbs/recover.js +14 -9
- package/dist/verbs/rename.d.ts +2 -0
- package/dist/verbs/rename.js +1 -1
- package/dist/verbs/retry.d.ts +2 -0
- package/dist/verbs/review.d.ts +2 -0
- package/dist/verbs/review.js +1 -1
- package/dist/verbs/satisfy.d.ts +2 -0
- package/dist/verbs/ship.d.ts +3 -0
- package/dist/verbs/start.d.ts +2 -0
- package/dist/verbs/start.js +12 -7
- package/dist/verbs/step-close.d.ts +2 -0
- package/dist/verbs/sync.d.ts +15 -0
- package/dist/verbs/trust.d.ts +4 -0
- package/dist/verbs/trust.js +34 -32
- package/dist/verbs/turn.d.ts +2 -0
- package/dist/verbs/wait.d.ts +9 -0
- package/dist/verbs/wait.js +3 -3
- package/dist/verbs/write.d.ts +18 -0
- package/dist/verbs/write.js +11 -5
- package/dist/verdict.d.ts +60 -0
- package/dist/version.d.ts +4 -0
- package/dist/worker-stream.d.ts +22 -0
- package/dist/worktree.d.ts +22 -0
- package/dist/worktree.js +1 -1
- package/package.json +7 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/witness.md +10 -10
- package/plugin/hooks/canon-guard.mjs +71 -10
- package/plugin/hooks/session-dashboard.sh +1 -1
- package/plugin/skills/witness-brainstorm/SKILL.md +3 -3
- package/plugin/skills/witness-decompose/SKILL.md +3 -3
- package/plugin/skills/witness-design/SKILL.md +2 -2
- package/plugin/skills/witness-implement/SKILL.md +2 -2
- package/plugin/skills/witness-plan/SKILL.md +2 -2
- package/plugin/skills/witness-ship/SKILL.md +2 -2
package/dist/drafts.d.ts
ADDED
|
@@ -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
|
|
169
|
+
return `${draftSummary(k, d.value.draft)} · resume with ${cliAct('draft', keyName(k)).line}`;
|
|
168
170
|
}
|
package/dist/drift.d.ts
ADDED
|
@@ -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,27 @@
|
|
|
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 renewDriveLock(root: string, pid?: number): boolean;
|
|
23
|
+
export declare function holdLease(root: string, onLost: () => void, everyMs?: number, pid?: number): () => void;
|
|
24
|
+
export declare function acquireDriveLock(root: string, info: {
|
|
25
|
+
log?: string;
|
|
26
|
+
}, pid?: number, graceMs?: number): Result<() => void>;
|
|
27
|
+
export declare function watchLine(h: DriveHolder, platform?: Platform): string;
|
package/dist/drive-presence.js
CHANGED
|
@@ -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 {
|
|
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).
|
|
@@ -199,10 +199,21 @@ export function acquireDriveLock(root, info, pid = process.pid, graceMs = DRIVE_
|
|
|
199
199
|
// because `-Path` reads `[ ]` in a path as a wildcard, `-Tail 50` so it starts at the end rather
|
|
200
200
|
// than replaying the whole log, and `-Encoding UTF8` because Windows PowerShell 5.1 reads a
|
|
201
201
|
// BOM-less file as ANSI and would garble drive's `·` and `—`.
|
|
202
|
+
//
|
|
203
|
+
// Row 239. Each command is argv through the quoter, word by word, which prints the bytes this line
|
|
204
|
+
// always had: `Get-Content`, `taskkill` and their words are bare in PowerShell, the cmdlet's flags
|
|
205
|
+
// stay bare as the plan's B2 keeps a flag, and the log, an absolute path and so never shaped like a
|
|
206
|
+
// flag, prints as `shellArg` or `psArg` printed it — but for a Windows path, whose `\` now prints it
|
|
207
|
+
// single-quoted (ruling R22), which PowerShell reads as the same path. Ruling R27: the one word that
|
|
208
|
+
// can hold a character outside printable ASCII is the log path, a local path no attacker text
|
|
209
|
+
// reaches and that this line never offers to run (it has no `$(…)`), so `shellWordExact` keeps its
|
|
210
|
+
// bytes rather than spelling them, as the human needs the real path to read.
|
|
202
211
|
export function watchLine(h, platform = process.platform) {
|
|
203
212
|
if (h.log === undefined)
|
|
204
213
|
return `the terminal running witness drive · pid ${h.pid}`;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
214
|
+
const pid = String(h.pid);
|
|
215
|
+
const watch = platform === 'win32' ? ['Get-Content', '-LiteralPath', h.log, '-Wait', '-Tail', '50', '-Encoding', 'UTF8'] : ['tail', '-f', h.log];
|
|
216
|
+
const stop = platform === 'win32' ? ['taskkill', '/PID', pid, '/T', '/F'] : ['kill', pid];
|
|
217
|
+
const render = (argv) => argv.map((w) => shellWordExact(w, platform)).join(' ');
|
|
218
|
+
return `${render(watch)} · stop it: ${render(stop)}`;
|
|
208
219
|
}
|
|
@@ -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;
|
package/dist/drive-report.js
CHANGED
|
@@ -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
|
|
22
|
-
const parked = items.filter((i) => i.kind === 'parked').flatMap((i) => i
|
|
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
|
|
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}`;
|
package/dist/drive.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type Ctx } from './cli.js';
|
|
2
|
+
import { type Config } from './config.js';
|
|
3
|
+
import { type Result } from './refusal.js';
|
|
4
|
+
import { type Canon } from './scan.js';
|
|
5
|
+
import { spawn, type ResolvedSpawn } from './spawn.js';
|
|
6
|
+
import { type NextAction } from './verbs/next.js';
|
|
7
|
+
import { type Decision } from './recommend.js';
|
|
8
|
+
import { type KeptStop } from './autonomy.js';
|
|
9
|
+
import { type RunCommand } from './allowlist.js';
|
|
10
|
+
import { type WorkerStream } from './worker-stream.js';
|
|
11
|
+
import { type Clock } from './usage.js';
|
|
12
|
+
import { type Ticker } from './session-clock.js';
|
|
13
|
+
export type DriveStep = {
|
|
14
|
+
kind: 'spawn';
|
|
15
|
+
home: string;
|
|
16
|
+
stage?: string;
|
|
17
|
+
target?: string;
|
|
18
|
+
model?: string;
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'decision';
|
|
21
|
+
gate?: string;
|
|
22
|
+
target?: string;
|
|
23
|
+
block?: Decision;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'conversation';
|
|
26
|
+
line: string;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'merge';
|
|
29
|
+
line: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'kept';
|
|
32
|
+
stop: 'trust-grant';
|
|
33
|
+
line: string;
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'idle';
|
|
36
|
+
};
|
|
37
|
+
export declare function classifyAction(action: NextAction, root: string, opts?: {
|
|
38
|
+
autonomy?: boolean;
|
|
39
|
+
}): DriveStep;
|
|
40
|
+
export type SpawnStep = Extract<DriveStep, {
|
|
41
|
+
kind: 'spawn';
|
|
42
|
+
}>;
|
|
43
|
+
export type SpawnOutcome = 'exited' | 'timeout' | 'spawn-failed' | 'stopped';
|
|
44
|
+
export interface SessionEnd {
|
|
45
|
+
outcome: SpawnOutcome;
|
|
46
|
+
code: number | null;
|
|
47
|
+
tail: string[];
|
|
48
|
+
ms: number;
|
|
49
|
+
failed: boolean;
|
|
50
|
+
}
|
|
51
|
+
export declare const SESSION_QUIET_MS = 300000;
|
|
52
|
+
export declare function lineSink(emit: (record: string) => void): {
|
|
53
|
+
push(chunk: string): void;
|
|
54
|
+
flush(): void;
|
|
55
|
+
};
|
|
56
|
+
export declare function signalSession(child: ReturnType<typeof spawn>, grouped: boolean, env: Record<string, string | undefined>, sig: NodeJS.Signals): void;
|
|
57
|
+
export declare function spawnSession(step: SpawnStep, cfg: Config, ctx: Ctx, spawnN: number, opts?: {
|
|
58
|
+
manual?: boolean;
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
ticker?: Ticker;
|
|
61
|
+
hear?: (line: string) => void;
|
|
62
|
+
root?: string;
|
|
63
|
+
stream?: WorkerStream;
|
|
64
|
+
next?: string;
|
|
65
|
+
progress?: (session?: string) => string[];
|
|
66
|
+
}): Promise<SessionEnd>;
|
|
67
|
+
export interface DriveFlags {
|
|
68
|
+
flow?: string;
|
|
69
|
+
maxSpawns?: number;
|
|
70
|
+
manual?: boolean;
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
}
|
|
73
|
+
export declare const DEFAULT_MAX_SPAWNS = 20;
|
|
74
|
+
export declare const AUTONOMY_MAX_SPAWNS = 200;
|
|
75
|
+
export declare const PAUSE_POLL_MS = 5000;
|
|
76
|
+
export declare const PAUSE_IDLE_MAX_MS = 43200000;
|
|
77
|
+
export declare function watchSignature(root: string): string;
|
|
78
|
+
export type AsideKind = 'kept' | 'decision' | 'conversation' | 'merge' | 'stuck' | 'capped';
|
|
79
|
+
export interface Aside {
|
|
80
|
+
target: string;
|
|
81
|
+
kind: AsideKind;
|
|
82
|
+
line: string;
|
|
83
|
+
why: string;
|
|
84
|
+
gate?: string;
|
|
85
|
+
stop?: KeptStop;
|
|
86
|
+
key0?: string;
|
|
87
|
+
trust?: RunCommand[];
|
|
88
|
+
}
|
|
89
|
+
export declare function flowOf(canon: Canon, t: string): string[];
|
|
90
|
+
export declare function journalWatch(root: string, target: string): (session?: string) => string[];
|
|
91
|
+
export declare function driveLoop(root: string, cfg: Config, ctx: Ctx, flags: DriveFlags, clock?: Clock): Promise<number>;
|
|
92
|
+
export declare function detachArgv(bin: string | undefined, args: readonly string[], env: Record<string, string | undefined>, platform?: NodeJS.Platform): Result<ResolvedSpawn>;
|
|
93
|
+
export declare function detachDrive(root: string, ctx: Ctx, args: readonly string[]): Result<{
|
|
94
|
+
pid: number;
|
|
95
|
+
log: string;
|
|
96
|
+
}>;
|
|
97
|
+
export declare function splitArgv(command: string): string[];
|
package/dist/drive.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { closeSync, constants, fstatSync, mkdirSync, openSync, readdirSync, statSync, writeSync } from 'node:fs';
|
|
3
3
|
import { basename, dirname, join } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { cliAct } from './act.js';
|
|
5
6
|
import { EXIT, main } from './cli.js';
|
|
6
7
|
import { canonPaths, loadConfig, loadLocalConfig } from './config.js';
|
|
7
8
|
import { sessionHash, withoutSession } from './context.js';
|
|
@@ -12,6 +13,9 @@ import { NO_CONSOLE_ENV, resolveSpawn, spawn, treeStop } from './spawn.js';
|
|
|
12
13
|
import { contained, containmentLine, JOB_HOST_ENV, jobHost } from './contain.js';
|
|
13
14
|
import { releaseDeadTurn } from './runner-lock.js';
|
|
14
15
|
import { computeNext, conversationStage } from './verbs/next.js';
|
|
16
|
+
import { shownView } from './verbs/decide.js';
|
|
17
|
+
import { decideViewLines } from './decide-view.js';
|
|
18
|
+
import { renderDecision } from './recommend.js';
|
|
15
19
|
import { entryDetail } from './verbs/log.js';
|
|
16
20
|
import { DRIVE_DEADLINE_ENV, DRIVE_ENV, DRIVE_LOG, DRIVE_LOG_ENV, TARGETLESS, driveHolder } from './drive-presence.js';
|
|
17
21
|
import { isAlive, pause } from './lock.js';
|
|
@@ -24,7 +28,7 @@ import { movesFlow } from './progress.js';
|
|
|
24
28
|
import { sourced } from './allowlist.js';
|
|
25
29
|
import { effortOf } from './reviewed.js';
|
|
26
30
|
import { pendingTxn } from './txn.js';
|
|
27
|
-
import { logSafe } from './toon.js';
|
|
31
|
+
import { logSafe, shellWords } from './toon.js';
|
|
28
32
|
import { passthrough } from './worker-stream.js';
|
|
29
33
|
import { duration, limitIn, realClock, sessionLimit, SINGLE_WAIT_MAX_MS, TOTAL_WAIT_MAX_MS, waitFor, } from './usage.js';
|
|
30
34
|
import { keepAwake } from './awake.js';
|
|
@@ -32,7 +36,7 @@ import { monotonicTicker, sessionClock } from './session-clock.js';
|
|
|
32
36
|
import { driveReport, runStart } from './drive-report.js';
|
|
33
37
|
import { notify } from './notify.js';
|
|
34
38
|
import { writeLive } from './live.js';
|
|
35
|
-
import { needsYou, needsYouToken, WAIT_LABEL } from './needs-you.js';
|
|
39
|
+
import { needsYou, needsYouToken, needYouRows, WAIT_LABEL } from './needs-you.js';
|
|
36
40
|
// The rule table is an ORDERED FIRST-MATCH list, on `recommend.ts`'s precedent: a
|
|
37
41
|
// misrouted action is attributable to one line here rather than to a weighting. Pure over
|
|
38
42
|
// the NextAction shape — no I/O — so every branch is one `expect` away.
|
|
@@ -46,13 +50,11 @@ import { needsYou, needsYouToken, WAIT_LABEL } from './needs-you.js';
|
|
|
46
50
|
// in both modes.
|
|
47
51
|
export function classifyAction(action, root, opts = {}) {
|
|
48
52
|
const { line } = action;
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const [, , gate, target] = line.split(' ');
|
|
55
|
-
return { kind: 'decision', gate, target: target ?? action.target };
|
|
53
|
+
// Row 239. A decision is a `decide` act: tier 2's pending decision and the bound endgame both
|
|
54
|
+
// name `witness decide <gate> <target> --show` (the plan's B8), and the gate and the target are
|
|
55
|
+
// the act's first two words after the verb, as `decide`'s own positional parser reads them.
|
|
56
|
+
if (action.act?.argv[0] === 'decide') {
|
|
57
|
+
return { kind: 'decision', gate: action.act.argv[1], target: action.act.argv[2] ?? action.target };
|
|
56
58
|
}
|
|
57
59
|
// Row 205 (issue #56). A step whose runner, ship lanes or cmd: need this machine does not
|
|
58
60
|
// trust would only be refused inside the session — the refusal journaled nothing, so drive
|
|
@@ -746,7 +748,7 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
|
|
|
746
748
|
const stuck = (key, action) => {
|
|
747
749
|
ctx.out(`drive: no progress — ${action.line}`);
|
|
748
750
|
ctx.out(action.target !== undefined
|
|
749
|
-
? `help: ${action.target} is set aside until its record moves — read its stream above · after a fix witness cannot see:
|
|
751
|
+
? `help: ${action.target} is set aside until its record moves — read its stream above · after a fix witness cannot see: ${cliAct('retry', action.target).line}`
|
|
750
752
|
: 'help: untargeted work is set aside until its record moves — read its stream above');
|
|
751
753
|
setAside(key, { kind: 'stuck', line: action.line, why: `no progress on ${action.line}`, key0: keyOf(action) });
|
|
752
754
|
};
|
|
@@ -888,7 +890,7 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
|
|
|
888
890
|
// the pass leaves for a human, drive sets aside. The pass never waits inside a reviewer
|
|
889
891
|
// (F6: that wait was silent, uncounted and deaf to a signal): an arbiter refused by a usage
|
|
890
892
|
// limit becomes drive's own pause, and the stop is judged again after it.
|
|
891
|
-
const routed = new Map(); // target → the re-run its settle routed
|
|
893
|
+
const routed = new Map(); // target → the re-run its settle routed (row 239: its act)
|
|
892
894
|
const settlePass = async () => {
|
|
893
895
|
const { settleOwed, settledLine } = await import('./settle.js');
|
|
894
896
|
for (const r of await settleOwed(ctx, root, cfg, { scope: admits })) {
|
|
@@ -910,10 +912,10 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
|
|
|
910
912
|
}
|
|
911
913
|
else if (s.kind === 'left') {
|
|
912
914
|
ctx.out(`drive: waits on you — ${r.target} · decision · ${s.why}`);
|
|
913
|
-
setAside(r.target, { kind: 'decision', line:
|
|
915
|
+
setAside(r.target, { kind: 'decision', line: cliAct('decide', r.gate, r.target, '--show').line, why: s.why, gate: r.gate, key0: keyOf(ownNext(r.target)) });
|
|
914
916
|
}
|
|
915
917
|
else if (s.kind === 'routed') {
|
|
916
|
-
routed.set(r.target, s.
|
|
918
|
+
routed.set(r.target, s.act);
|
|
917
919
|
}
|
|
918
920
|
}
|
|
919
921
|
};
|
|
@@ -1023,7 +1025,7 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
|
|
|
1023
1025
|
const token = needsYouToken(items);
|
|
1024
1026
|
if (token !== pausePrinted) {
|
|
1025
1027
|
ctx.out(`drive: waiting on you — ${items.length} item(s)`);
|
|
1026
|
-
items.flatMap((i) => i
|
|
1028
|
+
items.flatMap((i) => needYouRows(i)).forEach((l) => ctx.out(l));
|
|
1027
1029
|
pausePrinted = token;
|
|
1028
1030
|
}
|
|
1029
1031
|
notifyNew(items);
|
|
@@ -1095,8 +1097,8 @@ export async function driveLoop(root, cfg, ctx, flags, clock = realClock) {
|
|
|
1095
1097
|
// Only then: `routed` keeps a target's re-run for the whole run.
|
|
1096
1098
|
let next = action.line;
|
|
1097
1099
|
if (step.kind === 'decision' && autonomous && rerun !== undefined) {
|
|
1098
|
-
step = conversationStage({ line: rerun }) ? { kind: 'conversation', line: rerun } : { kind: 'spawn', home: root, target: action.target };
|
|
1099
|
-
next = rerun;
|
|
1100
|
+
step = conversationStage({ line: rerun.line }) ? { kind: 'conversation', line: rerun.line } : { kind: 'spawn', home: root, target: action.target };
|
|
1101
|
+
next = rerun.line;
|
|
1100
1102
|
}
|
|
1101
1103
|
if (step.kind !== 'spawn') {
|
|
1102
1104
|
await standAside(step, action, key);
|
|
@@ -1236,76 +1238,70 @@ export function detachDrive(root, ctx, args) {
|
|
|
1236
1238
|
closeSync(fd);
|
|
1237
1239
|
}
|
|
1238
1240
|
}
|
|
1239
|
-
// Read back what `renderDecision` printed (recommend.ts:33): a `<n> · [recommended ·]
|
|
1240
|
-
// <depth>[ · not runnable]` tag line, then the command indented under it. Parsed rather
|
|
1241
|
-
// than recomputed on purpose — the human decides against the bytes on their screen, so
|
|
1242
|
-
// the option drive runs must be the option they read, not a second derivation of it.
|
|
1243
|
-
export function parseBlock(lines) {
|
|
1244
|
-
const out = [];
|
|
1245
|
-
lines.forEach((line, i) => {
|
|
1246
|
-
const m = /^(\d+) · (.+)$/.exec(line);
|
|
1247
|
-
if (!m)
|
|
1248
|
-
return;
|
|
1249
|
-
const command = (lines[i + 1] ?? '').trim();
|
|
1250
|
-
if (!command.startsWith('witness '))
|
|
1251
|
-
return;
|
|
1252
|
-
const tags = m[2].split(' · ');
|
|
1253
|
-
out.push({
|
|
1254
|
-
n: Number(m[1]), command,
|
|
1255
|
-
recommended: tags.includes('recommended'), runnable: !tags.includes('not runnable'),
|
|
1256
|
-
});
|
|
1257
|
-
});
|
|
1258
|
-
return out;
|
|
1259
|
-
}
|
|
1260
1241
|
// D143's exclusions, verbatim: an obligation-minting override (D122's ledger must not
|
|
1261
1242
|
// open on an "ok"), terminal acts, and trust grants (D154). `decide` refuses these with
|
|
1262
|
-
// `nod-cannot` anyway — drive names the act instead of burning the round-trip.
|
|
1263
|
-
|
|
1264
|
-
|
|
1243
|
+
// `nod-cannot` anyway — drive names the act instead of burning the round-trip. Row 239: read
|
|
1244
|
+
// off the act's words, so a flag is one only where the act holds it as one.
|
|
1245
|
+
function nodExcluded(act) {
|
|
1246
|
+
if (act.argv[0] === 'abandon')
|
|
1265
1247
|
return 'witness abandon';
|
|
1266
|
-
return ['--override', '--stop', '--trust-cmds'].find((f) =>
|
|
1248
|
+
return ['--override', '--stop', '--trust-cmds'].find((f) => act.argv.includes(f));
|
|
1267
1249
|
}
|
|
1268
1250
|
const AFFIRMATIONS = new Set(['y', 'yes', 'ok', 'okay', 'go']);
|
|
1251
|
+
const selectable = (options) => options.flatMap((o, i) => o.act ? [{ n: i + 1, act: o.act, recommended: i === 0, runnable: o.act.inputs.length === 0 }] : []);
|
|
1269
1252
|
// The option verbs a human can name instead of a number — `approve`, `revise`, `stop`,
|
|
1270
1253
|
// `abandon`, `override`, `repair`. Ambiguity is reported, never guessed: two options can
|
|
1271
1254
|
// share a verb (a plain approve beside an approve --trust-cmds), and picking one for the
|
|
1272
1255
|
// human is authoring their decision.
|
|
1273
1256
|
function byVerb(word, options) {
|
|
1274
|
-
return options.filter((o) => o.
|
|
1257
|
+
return options.filter((o) => o.act.argv.includes(`--${word}`) || o.act.argv[0] === word);
|
|
1258
|
+
}
|
|
1259
|
+
// An option with an input is the human's to fill: picked by a nod, a number or its verb, it is
|
|
1260
|
+
// refused, never run with the placeholder for its word.
|
|
1261
|
+
function taken(o) {
|
|
1262
|
+
return o.runnable ? { argv: o.act.argv, line: o.act.line } : { refuse: `option ${o.n} needs an id you must fill in — type it out` };
|
|
1275
1263
|
}
|
|
1276
1264
|
function selectOption(answer, options) {
|
|
1277
|
-
|
|
1278
|
-
|
|
1265
|
+
// Typed out, and read by the grammar its words are quoted for (`shellWords`), so a note typed
|
|
1266
|
+
// as `'it'\''s'` or `"don't ship"` is the one word it says. POSIX quoting alone, by design: on
|
|
1267
|
+
// Windows a word PowerShell's quoting wrote (`'o''b'`) reads back lossily (`ob`), and the
|
|
1268
|
+
// measured Windows pass owns that (residual R1).
|
|
1269
|
+
if (answer.startsWith('witness ')) {
|
|
1270
|
+
const words = shellWords(answer);
|
|
1271
|
+
return words === undefined ? { refuse: 'its quotes do not close — type the command again' } : { argv: words.slice(1), line: answer };
|
|
1272
|
+
}
|
|
1279
1273
|
if (AFFIRMATIONS.has(answer.toLowerCase())) {
|
|
1280
1274
|
const rec = options.find((o) => o.recommended);
|
|
1281
1275
|
if (!rec)
|
|
1282
1276
|
return { refuse: 'this block carries no recommendation — name the option (D143)' };
|
|
1283
1277
|
if (!rec.runnable)
|
|
1284
1278
|
return { refuse: 'the recommended option needs an id you must fill in — type it out' };
|
|
1285
|
-
const excluded = nodExcluded(rec.
|
|
1279
|
+
const excluded = nodExcluded(rec.act);
|
|
1286
1280
|
if (excluded !== undefined) {
|
|
1287
1281
|
return { refuse: `nod-cannot: ${excluded} is never taken on an affirmation — name the option (D143)` };
|
|
1288
1282
|
}
|
|
1289
|
-
|
|
1283
|
+
// Row 239. `--via affirmation` is decide's record that a nod chose, so only a decide act
|
|
1284
|
+
// carries it; any other recommended act (the recovery fork's) runs exactly as named.
|
|
1285
|
+
if (rec.act.argv[0] !== 'decide')
|
|
1286
|
+
return { argv: rec.act.argv, line: rec.act.line };
|
|
1287
|
+
return { argv: [...rec.act.argv, '--via', 'affirmation'], line: `${rec.act.line} --via affirmation` };
|
|
1290
1288
|
}
|
|
1291
1289
|
if (/^\d+$/.test(answer)) {
|
|
1292
1290
|
const picked = options.find((o) => o.n === Number(answer));
|
|
1293
|
-
|
|
1294
|
-
return { refuse: `no option ${answer} in this block` };
|
|
1295
|
-
if (!picked.runnable)
|
|
1296
|
-
return { refuse: `option ${answer} needs an id you must fill in — type it out` };
|
|
1297
|
-
return { command: picked.command };
|
|
1291
|
+
return picked === undefined ? { refuse: `no option ${answer} in this block` } : taken(picked);
|
|
1298
1292
|
}
|
|
1299
1293
|
const matches = byVerb(answer.toLowerCase(), options);
|
|
1300
1294
|
if (matches.length === 1)
|
|
1301
|
-
return
|
|
1295
|
+
return taken(matches[0]);
|
|
1302
1296
|
if (matches.length > 1) {
|
|
1303
1297
|
return { refuse: `${answer} matches options ${matches.map((o) => o.n).join(', ')} — name the number` };
|
|
1304
1298
|
}
|
|
1305
1299
|
return { refuse: `not an option: ${answer} — answer with a number, an option verb, or the command itself` };
|
|
1306
1300
|
}
|
|
1307
|
-
// Split a
|
|
1308
|
-
//
|
|
1301
|
+
// Split a WITNESS_BIN command line into argv, honoring double quotes: on Windows `detachArgv`
|
|
1302
|
+
// starts the bin it names with no shell, and a first word quoted for its spaces (an install
|
|
1303
|
+
// under Program Files) is one word. Row 239: its one use. A printed decision is never read back
|
|
1304
|
+
// through it, and a typed answer at `decide>` reads by `shellWords`.
|
|
1309
1305
|
export function splitArgv(command) {
|
|
1310
1306
|
const argv = [];
|
|
1311
1307
|
let cur = '';
|
|
@@ -1336,31 +1332,32 @@ export function splitArgv(command) {
|
|
|
1336
1332
|
// an option in three tries is being asked the wrong question, and a prompt that never
|
|
1337
1333
|
// gives up is a worse treadmill than the one drive exists to end.
|
|
1338
1334
|
const ASK_LIMIT = 3;
|
|
1339
|
-
// The judgment stop, in the driver's own terminal.
|
|
1340
|
-
//
|
|
1341
|
-
// read in a chat session — D143 is one rule across
|
|
1335
|
+
// The judgment stop, in the driver's own terminal. The screen is the one `decide --show`
|
|
1336
|
+
// prints, from the view it prints (`shownView`), so the block a human reads here is
|
|
1337
|
+
// byte-identical to the one they would read in a chat session — D143 is one rule across
|
|
1338
|
+
// surfaces, not two implementations. Row 239: an answer runs the chosen option's act as argv,
|
|
1339
|
+
// from the same view, so no printed line is parsed back to learn what to run.
|
|
1342
1340
|
//
|
|
1343
1341
|
// `executed` when the decision ran (the loop derives again), `stands` when the human left it
|
|
1344
1342
|
// standing, `refused` when the render or the chosen command refused.
|
|
1345
1343
|
async function resolveDecision(step, action, ctx) {
|
|
1346
|
-
|
|
1347
|
-
const echo = {
|
|
1348
|
-
...ctx,
|
|
1349
|
-
out: (l) => { rendered.push(l); ctx.out(l); },
|
|
1350
|
-
err: (l) => { rendered.push(l); ctx.err(l); },
|
|
1351
|
-
};
|
|
1344
|
+
let options = [];
|
|
1352
1345
|
if (step.block !== undefined) {
|
|
1353
|
-
step.block.forEach((l) =>
|
|
1346
|
+
renderDecision(step.block).forEach((l) => ctx.out(l));
|
|
1347
|
+
options = step.block.options;
|
|
1354
1348
|
}
|
|
1355
1349
|
else if (step.gate !== undefined && step.target !== undefined) {
|
|
1356
|
-
const
|
|
1357
|
-
if (
|
|
1350
|
+
const view = shownView(ctx, step.gate, step.target);
|
|
1351
|
+
if (view === undefined)
|
|
1358
1352
|
return 'refused';
|
|
1353
|
+
decideViewLines(view).forEach((l) => ctx.out(l));
|
|
1354
|
+
if (view.state === 'actionable')
|
|
1355
|
+
options = view.block?.options ?? [];
|
|
1359
1356
|
}
|
|
1360
1357
|
else {
|
|
1361
1358
|
ctx.out(`drive: decision — ${action.line}`);
|
|
1362
1359
|
}
|
|
1363
|
-
const
|
|
1360
|
+
const picks = selectable(options);
|
|
1364
1361
|
for (let asked = 0; asked < ASK_LIMIT; asked++) {
|
|
1365
1362
|
const answer = (await ctx.ask('decide>')).trim();
|
|
1366
1363
|
// Empty is a human declining to decide now. One re-ask (the prompt may have scrolled
|
|
@@ -1371,15 +1368,15 @@ async function resolveDecision(step, action, ctx) {
|
|
|
1371
1368
|
ctx.out('help: answer with an option number, an option verb, or a bare y to take the recommendation — empty leaves the stop standing');
|
|
1372
1369
|
continue;
|
|
1373
1370
|
}
|
|
1374
|
-
const pick = selectOption(answer,
|
|
1371
|
+
const pick = selectOption(answer, picks);
|
|
1375
1372
|
if ('refuse' in pick) {
|
|
1376
1373
|
ctx.out(`help: ${pick.refuse}`);
|
|
1377
1374
|
continue;
|
|
1378
1375
|
}
|
|
1379
|
-
ctx.out(`drive: running — ${pick.
|
|
1380
|
-
const code = await main(ctx,
|
|
1376
|
+
ctx.out(`drive: running — ${pick.line}`);
|
|
1377
|
+
const code = await main(ctx, [...pick.argv]);
|
|
1381
1378
|
if (code !== EXIT.OK) {
|
|
1382
|
-
ctx.out(`drive: decision refused — ${pick.
|
|
1379
|
+
ctx.out(`drive: decision refused — ${pick.line}`);
|
|
1383
1380
|
return 'refused';
|
|
1384
1381
|
}
|
|
1385
1382
|
return 'executed';
|
package/dist/dsl.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Violation } from './refusal.js';
|
|
2
|
+
export declare const ID_RE: RegExp;
|
|
3
|
+
export declare const isId: (s: unknown) => s is string;
|
|
4
|
+
export interface Criterion {
|
|
5
|
+
id: string;
|
|
6
|
+
test?: string;
|
|
7
|
+
cmd?: string;
|
|
8
|
+
}
|
|
9
|
+
export type Need = {
|
|
10
|
+
env: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
} | {
|
|
13
|
+
cmd: string;
|
|
14
|
+
id?: string;
|
|
15
|
+
} | {
|
|
16
|
+
manual: string;
|
|
17
|
+
satisfied: boolean;
|
|
18
|
+
id?: string;
|
|
19
|
+
holds?: string[];
|
|
20
|
+
};
|
|
21
|
+
export declare function validateCriteria(raw: unknown, specId: string): Violation[];
|
|
22
|
+
export declare function validateNeeds(raw: unknown): Violation[];
|
|
23
|
+
export declare function validateHolds(meta: Record<string, unknown>): Violation[];
|
package/dist/dsl.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { v } from './refusal.js';
|
|
2
|
-
|
|
2
|
+
// Row 239 (the plan's B14). An id is printed into the commands witness offers, where a word that
|
|
3
|
+
// starts with `-` is read as a flag: it starts with a letter or a digit.
|
|
4
|
+
export const ID_RE = /^[a-z0-9][a-z0-9-]*$/;
|
|
5
|
+
// Row 239 (the plan's B15). A value a reader can print as an id: canon and the journal are parsed
|
|
6
|
+
// text, so an id read there may be any value.
|
|
7
|
+
export const isId = (s) => typeof s === 'string' && ID_RE.test(s);
|
|
3
8
|
export function validateCriteria(raw, specId) {
|
|
4
9
|
if (!Array.isArray(raw) || raw.length === 0) {
|
|
5
10
|
return [v('criteria', 'required', Array.isArray(raw) ? 'empty list' : String(raw ?? 'absent'), '>=1 machine-checkable criterion')];
|
|
@@ -14,7 +19,7 @@ export function validateCriteria(raw, specId) {
|
|
|
14
19
|
}
|
|
15
20
|
const e = c;
|
|
16
21
|
if (typeof e.id !== 'string' || !ID_RE.test(e.id)) {
|
|
17
|
-
out.push(v(`${at}.id`, 'id-charset', String(e.id ?? 'absent'), '[a-z0-9-]
|
|
22
|
+
out.push(v(`${at}.id`, 'id-charset', String(e.id ?? 'absent'), '[a-z0-9][a-z0-9-]*'));
|
|
18
23
|
}
|
|
19
24
|
else if (seen.has(e.id)) {
|
|
20
25
|
out.push(v(`${at}.id`, 'id-unique', e.id, 'unique per spec'));
|
|
@@ -66,7 +71,7 @@ export function validateNeeds(raw) {
|
|
|
66
71
|
}
|
|
67
72
|
if (e.id !== undefined) {
|
|
68
73
|
if (typeof e.id !== 'string' || !ID_RE.test(e.id))
|
|
69
|
-
out.push(v(`${at}.id`, 'id-charset', String(e.id), '[a-z0-9-]
|
|
74
|
+
out.push(v(`${at}.id`, 'id-charset', String(e.id), '[a-z0-9][a-z0-9-]*'));
|
|
70
75
|
else if (ids.has(e.id))
|
|
71
76
|
out.push(v(`${at}.id`, 'id-unique', e.id, 'unique per doc'));
|
|
72
77
|
else
|