@popovych.co/witness 0.28.3 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/dist/act.d.ts +2 -1
- package/dist/act.js +9 -0
- package/dist/busy.d.ts +38 -0
- package/dist/busy.js +274 -0
- package/dist/caps.d.ts +3 -2
- package/dist/caps.js +24 -3
- package/dist/decide-view.d.ts +6 -0
- package/dist/decide-view.js +21 -3
- package/dist/drive-presence.d.ts +3 -0
- package/dist/drive-presence.js +18 -6
- package/dist/drive.d.ts +18 -1
- package/dist/drive.js +264 -48
- package/dist/evidence.d.ts +2 -0
- package/dist/evidence.js +8 -2
- package/dist/gate.js +37 -4
- package/dist/gates/implement.js +11 -3
- package/dist/gates/ship.js +10 -5
- package/dist/gitio.d.ts +5 -0
- package/dist/gitio.js +27 -2
- package/dist/journal.d.ts +1 -1
- package/dist/live.d.ts +6 -1
- package/dist/live.js +15 -3
- package/dist/needs-you.d.ts +18 -2
- package/dist/needs-you.js +55 -17
- package/dist/progress.js +2 -0
- package/dist/reviewed.d.ts +4 -0
- package/dist/reviewed.js +9 -0
- package/dist/rounds.d.ts +6 -2
- package/dist/rounds.js +43 -10
- package/dist/settle.d.ts +25 -2
- package/dist/settle.js +120 -11
- package/dist/ship-outcome.d.ts +24 -0
- package/dist/ship-outcome.js +76 -0
- package/dist/ship.d.ts +12 -1
- package/dist/ship.js +306 -73
- package/dist/stamp.d.ts +6 -0
- package/dist/stamp.js +17 -7
- package/dist/steps.d.ts +1 -0
- package/dist/steps.js +31 -7
- package/dist/verbs/dashboard.js +9 -3
- package/dist/verbs/decide.d.ts +12 -0
- package/dist/verbs/decide.js +77 -23
- package/dist/verbs/evidence.js +40 -3
- package/dist/verbs/next.d.ts +20 -3
- package/dist/verbs/next.js +272 -58
- package/dist/verbs/wait.js +30 -5
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/witness.md +8 -2
- 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 +4 -4
- package/plugin/skills/witness-plan/SKILL.md +2 -2
- package/plugin/skills/witness-ship/SKILL.md +2 -2
package/README.md
CHANGED
|
@@ -244,7 +244,19 @@ own and every `witness turn`, which is how a session runs its tests — because
|
|
|
244
244
|
servers or browsers collide. On Windows each session, test run and gate reviewer runs in a job
|
|
245
245
|
object, so whatever it starts — detached, or orphaned by an installer that exited — ends with it;
|
|
246
246
|
elsewhere a session's process group does. A target that reaches any `drive.caps.*` bound is
|
|
247
|
-
parked.
|
|
247
|
+
parked. Below the round bound a parked gate goes back to work with your own
|
|
248
|
+
`witness decide <gate> <target> --revise --note "<why>"` — it lifts the park without running the
|
|
249
|
+
gate, and `next` routes the owed work, steps first; `witness status` and `decide --show` print it on a
|
|
250
|
+
`revise:` row, beside a `fresh:` row (a re-review of the work as it stands) when no work is owed. It
|
|
251
|
+
also restarts drive's caps for that target.
|
|
252
|
+
|
|
253
|
+
A ship that ends on a hold only you can clear is a stop of yours, remembered in the journal, so it
|
|
254
|
+
survives a drive restart: `waiting: merge` (no CI checks, or none passed) with the merge command
|
|
255
|
+
pinned to the approved commit (`gh pr merge N --<ship.merge> --match-head-commit <sha>`), or
|
|
256
|
+
`waiting: fix` (the PR aims at another branch, was closed, holds commits the worktree lacks, or a
|
|
257
|
+
login was refused) with no merge command at all. Each has a `recheck:` row, `witness ship <plan>`,
|
|
258
|
+
for when you have acted. A hold that clears by itself — CI still running, GitHub not answering — is
|
|
259
|
+
drive's to check again, within its caps.
|
|
248
260
|
|
|
249
261
|
### Upgrading
|
|
250
262
|
|
|
@@ -302,7 +314,7 @@ the wrong file refuses. There are no `WITNESS_*` env vars for configuration.
|
|
|
302
314
|
| `next` | the one next action across every effort |
|
|
303
315
|
| `drive [--flow <plan-id>] [--max-spawns <n>] [--manual] [--detach]` | runs every session itself · under autonomy it needs no terminal and reports when nothing else can move. Up to `drive.parallel` targets at once, one session per target; usage limits are waited out; a target past a cap is parked. `--detach` (autonomy only) runs it in the background into `.witness/drive.log` — each session's start, every command and file its agent touches, every act it journals for its flow, a `still running` line after 5 quiet minutes, and how it ended; drive's pi sessions are kept in pi's session store under `witness-drive/`; `--manual` runs serially and asks you at every stop. One drive per repo. A session drive spawned is refused — agents are what drive spawns, never what spawns drive |
|
|
304
316
|
| `ship <plan-id> [--manual]` | lanes → ship gate → PR → CI watch → under autonomy: merge on green · `--manual` keeps that run's stop and merge for a human |
|
|
305
|
-
| `test-evidence <plan-id> --phase red\|green [--step <id>]` / `verify-red <plan-id> [--base <ref>] [--step <id>]` | journal red/green criteria evidence from a worktree; `--step` names the plan step the cycle closes — required before the plan's first implement gate (on a plan with a criteria step), left off for a fix round
|
|
317
|
+
| `test-evidence <plan-id> --phase red\|green [--step <id>]` / `verify-red <plan-id> [--base <ref>] [--step <id>]` | journal red/green criteria evidence from a worktree; `--step` names the plan step the cycle closes — required before the plan's first implement gate (on a plan with a criteria step), and after it while a criteria step is open (an amendment's step routes first); left off for a fix round, once every step is closed. A green that closes a step prints `context:`, `steps:` and `slice:` |
|
|
306
318
|
| `turn -- <command> [args…]` | run one command in the repo's test turn — it waits while another worktree's test run holds it, unless `drive.parallelSuites: true` — and on Windows inside a job object, so whatever it starts ends with it; exits with the command's code · the implement and ship skills run every test a session runs itself through it |
|
|
307
319
|
| `step-close <plan-id> --step <id>` | close a scaffolding step, which has no red→green to witness; prints `context:`, `steps:` and `slice:` as a closing green does, and closing it again changes nothing |
|
|
308
320
|
| `adopt <path>` | absolve a finished hand-edit into the journal — content only: a hand edit that moves `status`, `drift`, `pr` or `design` is refused, since only witness writes a doc's position |
|
package/dist/act.d.ts
CHANGED
|
@@ -12,5 +12,6 @@ export interface Act {
|
|
|
12
12
|
}
|
|
13
13
|
export declare function actOn(platform: Platform, argv: readonly string[]): Act;
|
|
14
14
|
export declare function cliAct(...argv: string[]): Act;
|
|
15
|
-
export declare function runRow(act: Act, label?: 'run' | 'then', indent?: string): string;
|
|
15
|
+
export declare function runRow(act: Act, label?: 'run' | 'then' | 'revise' | 'fresh' | 'recheck', indent?: string): string;
|
|
16
16
|
export declare function exitsLine(acts: readonly Act[], platform?: Platform): string;
|
|
17
|
+
export declare function reopenRows(reopen: readonly Act[]): string[];
|
package/dist/act.js
CHANGED
|
@@ -59,3 +59,12 @@ export function exitsLine(acts, platform = process.platform) {
|
|
|
59
59
|
return shared ? words(a.argv, platform).slice(3).join(' ') : a.line;
|
|
60
60
|
}).join(' | ');
|
|
61
61
|
}
|
|
62
|
+
// Row 241 (R11). A parked gate's reopen as rows: below the bound a `revise:` row, and a `fresh:` row
|
|
63
|
+
// beside it when no work is owed; at the bound the endgame menu, a set of choices, as `exits:`.
|
|
64
|
+
export function reopenRows(reopen) {
|
|
65
|
+
const labelOf = (a) => a.argv[0] === 'decide' && a.argv.includes('--revise') && !a.argv.includes('--upstream') && !a.argv.includes('--repair') ? 'revise'
|
|
66
|
+
: a.argv[0] === 'gate' && a.argv.includes('--fresh') ? 'fresh' : undefined;
|
|
67
|
+
if (reopen.length > 0 && reopen.every((a) => labelOf(a) !== undefined))
|
|
68
|
+
return reopen.map((a) => runRow(a, labelOf(a)));
|
|
69
|
+
return reopen.length === 1 ? [runRow(reopen[0])] : [` exits: ${exitsLine(reopen)}`];
|
|
70
|
+
}
|
package/dist/busy.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Ctx } from './cli.js';
|
|
2
|
+
import type { Config } from './config.js';
|
|
3
|
+
import { type Violation } from './refusal.js';
|
|
4
|
+
export type BusyKind = 'settle' | 'ship';
|
|
5
|
+
export interface BusyLock {
|
|
6
|
+
pid: number;
|
|
7
|
+
since: number;
|
|
8
|
+
until: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const BUSY_DIR = ".witness/live/busy";
|
|
11
|
+
export declare const BUSY_MAX_MS = 86400000;
|
|
12
|
+
export declare const busyIo: {
|
|
13
|
+
create(p: string, text: string): void;
|
|
14
|
+
unlink(p: string): void;
|
|
15
|
+
};
|
|
16
|
+
export type TakeBusy = {
|
|
17
|
+
taken: true;
|
|
18
|
+
release: () => void;
|
|
19
|
+
} | {
|
|
20
|
+
taken: false;
|
|
21
|
+
holder: BusyLock;
|
|
22
|
+
} | {
|
|
23
|
+
taken: false;
|
|
24
|
+
refused: Violation[];
|
|
25
|
+
};
|
|
26
|
+
export declare function takeBusy(root: string, kind: BusyKind, target: string, until: number, opts?: {
|
|
27
|
+
now?: number;
|
|
28
|
+
pid?: number;
|
|
29
|
+
}): TakeBusy;
|
|
30
|
+
export declare function busyHolder(root: string, kind: BusyKind, target: string, opts?: {
|
|
31
|
+
now?: number;
|
|
32
|
+
pid?: number;
|
|
33
|
+
}): BusyLock | undefined;
|
|
34
|
+
export declare function sweepDeadBusy(root: string, opts?: {
|
|
35
|
+
pid?: number;
|
|
36
|
+
}): number;
|
|
37
|
+
export declare function settleUntil(cfg: Config, env: Ctx['env'], now: number): number;
|
|
38
|
+
export declare function shipUntil(cfg: Config, env: Ctx['env'], now: number): number;
|
package/dist/busy.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { closeSync, constants, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, unlinkSync, writeSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { DRIVE_DEADLINE_ENV } from './drive-presence.js';
|
|
4
|
+
import { isId } from './dsl.js';
|
|
5
|
+
import { LOCK_WAIT_MS, isAlive, pause, takeStale } from './lock.js';
|
|
6
|
+
import { v } from './refusal.js';
|
|
7
|
+
import { ensureExcluded } from './worktree.js';
|
|
8
|
+
export const BUSY_DIR = '.witness/live/busy';
|
|
9
|
+
// A lock whose `until` lies more than this after its `since` is stale, whatever it claims.
|
|
10
|
+
export const BUSY_MAX_MS = 86_400_000;
|
|
11
|
+
// An empty or unparseable file is a write in progress for this long (`lock.ts`'s grace).
|
|
12
|
+
const UNREADABLE_GRACE_MS = 1_000;
|
|
13
|
+
// Windows: a scanner or the indexer can hold a fresh file for a moment (EPERM, EBUSY, EACCES).
|
|
14
|
+
const CREATE_RETRY_MS = 1_000;
|
|
15
|
+
const RETRY_PAUSE_MS = 50;
|
|
16
|
+
const TRANSIENT = new Set(['EPERM', 'EBUSY', 'EACCES']);
|
|
17
|
+
// A `since` this far ahead of now is a tampered lock or a clock set wrong, never a live holder.
|
|
18
|
+
const SINCE_SLACK_MS = 60_000;
|
|
19
|
+
// The one seam for file errors, so a test can stand in for a Windows scanner.
|
|
20
|
+
export const busyIo = {
|
|
21
|
+
create(p, text) {
|
|
22
|
+
const fd = openSync(p, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o644);
|
|
23
|
+
try {
|
|
24
|
+
writeSync(fd, text);
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
closeSync(fd);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
unlink(p) {
|
|
31
|
+
unlinkSync(p);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const unwritable = (why) => v(BUSY_DIR, 'lock-unwritable', why, 'a writable .witness/live/busy folder, not a link — witness writes its busy locks there');
|
|
35
|
+
// The folder, or why it cannot be used. A link anywhere on the way is refused, never followed.
|
|
36
|
+
function busyDir(root, create) {
|
|
37
|
+
const live = join(root, '.witness', 'live');
|
|
38
|
+
const dir = join(root, BUSY_DIR);
|
|
39
|
+
for (const p of [live, dir]) {
|
|
40
|
+
try {
|
|
41
|
+
if (!lstatSync(p).isDirectory())
|
|
42
|
+
return { refused: unwritable(`${p === live ? '.witness/live' : BUSY_DIR} is not a folder`) };
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
if (e.code !== 'ENOENT')
|
|
46
|
+
return { refused: unwritable(e.code ?? String(e)) };
|
|
47
|
+
if (!create)
|
|
48
|
+
return undefined;
|
|
49
|
+
try {
|
|
50
|
+
mkdirSync(p, { recursive: true });
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
return { refused: unwritable(err.code ?? String(err)) };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return dir;
|
|
58
|
+
}
|
|
59
|
+
const lockName = (kind, target) => `${target}.${kind}.json`;
|
|
60
|
+
function parseLock(text) {
|
|
61
|
+
let raw;
|
|
62
|
+
try {
|
|
63
|
+
raw = JSON.parse(text);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return 'unreadable';
|
|
67
|
+
}
|
|
68
|
+
const r = raw;
|
|
69
|
+
const num = (x) => typeof x === 'number' && Number.isFinite(x) && x >= 0;
|
|
70
|
+
if (!(Number.isInteger(r?.pid) && r.pid > 0 && num(r.since) && num(r.until)))
|
|
71
|
+
return 'malformed';
|
|
72
|
+
return { pid: r.pid, since: r.since, until: r.until };
|
|
73
|
+
}
|
|
74
|
+
function readLock(p) {
|
|
75
|
+
try {
|
|
76
|
+
if (lstatSync(p).isSymbolicLink())
|
|
77
|
+
return 'link';
|
|
78
|
+
const text = readFileSync(p, 'utf8');
|
|
79
|
+
const parsed = parseLock(text);
|
|
80
|
+
return typeof parsed === 'string' ? parsed : { lock: parsed };
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
return e.code === 'ENOENT' ? 'absent' : 'unreadable';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Live: its pid is alive, its `until` has not passed, and it claims no more than the cap.
|
|
87
|
+
const live = (l, now) => l.until >= l.since && l.until - l.since <= BUSY_MAX_MS && l.since <= now + SINCE_SLACK_MS && now <= l.until && isAlive(l.pid);
|
|
88
|
+
const olderThanGrace = (p, now) => {
|
|
89
|
+
try {
|
|
90
|
+
return now - lstatSync(p).mtimeMs >= UNREADABLE_GRACE_MS;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
// Stale to `pid`: not live, or its own (no lock nests: a lock naming the reader is never busy to it).
|
|
97
|
+
function stale(p, text, pid, now) {
|
|
98
|
+
if (text === undefined) {
|
|
99
|
+
try {
|
|
100
|
+
if (lstatSync(p).isSymbolicLink())
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return olderThanGrace(p, now);
|
|
107
|
+
}
|
|
108
|
+
const parsed = parseLock(text);
|
|
109
|
+
if (parsed === 'unreadable')
|
|
110
|
+
return olderThanGrace(p, now);
|
|
111
|
+
if (parsed === 'malformed')
|
|
112
|
+
return true;
|
|
113
|
+
return parsed.pid === pid || !live(parsed, now);
|
|
114
|
+
}
|
|
115
|
+
// Takes `kind`'s lock on `target` until `until`, or names the live holder. Never waits on a
|
|
116
|
+
// holder: the only pauses are for a write in progress and a scanner holding a fresh file.
|
|
117
|
+
export function takeBusy(root, kind, target, until, opts = {}) {
|
|
118
|
+
if (!isId(target))
|
|
119
|
+
return { taken: false, refused: [v('target', 'unknown-id', target, 'an artifact id — lowercase letters, digits and dashes')] };
|
|
120
|
+
const pid = opts.pid ?? process.pid;
|
|
121
|
+
const now = () => opts.now ?? Date.now();
|
|
122
|
+
// Spec c2: a repo whose ignore rules predate this folder must never show it. Best effort.
|
|
123
|
+
try {
|
|
124
|
+
ensureExcluded(root);
|
|
125
|
+
}
|
|
126
|
+
catch { /* not a git checkout we can write to */ }
|
|
127
|
+
const dir = busyDir(root, true);
|
|
128
|
+
if (dir === undefined)
|
|
129
|
+
return { taken: false, refused: [unwritable('the folder could not be made')] };
|
|
130
|
+
if (typeof dir !== 'string')
|
|
131
|
+
return { taken: false, refused: [dir.refused] };
|
|
132
|
+
const p = join(dir, lockName(kind, target));
|
|
133
|
+
const since = now();
|
|
134
|
+
const text = JSON.stringify({ pid, since, until });
|
|
135
|
+
const t0 = Date.now();
|
|
136
|
+
for (;;) {
|
|
137
|
+
try {
|
|
138
|
+
busyIo.create(p, text);
|
|
139
|
+
return { taken: true, release: () => releaseIf(p, text) };
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
const code = e.code;
|
|
143
|
+
if (code !== 'EEXIST') {
|
|
144
|
+
if (code !== undefined && TRANSIENT.has(code) && Date.now() - t0 < CREATE_RETRY_MS) {
|
|
145
|
+
pause(RETRY_PAUSE_MS);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
return { taken: false, refused: [unwritable(code ?? String(e))] };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const held = readLock(p);
|
|
152
|
+
if (typeof held === 'object' && held.lock.pid !== pid && live(held.lock, now()))
|
|
153
|
+
return { taken: false, holder: held.lock };
|
|
154
|
+
let took;
|
|
155
|
+
try {
|
|
156
|
+
took = takeStale(p, (t) => stale(p, t, pid, now()));
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
return { taken: false, refused: [unwritable(`the stale lock could not be removed (${e.code ?? String(e)})`)] };
|
|
160
|
+
}
|
|
161
|
+
if (took === 'taken')
|
|
162
|
+
continue;
|
|
163
|
+
// a write in progress, or another stealer at work: re-read shortly, within the same budget
|
|
164
|
+
if (Date.now() - t0 >= CREATE_RETRY_MS + UNREADABLE_GRACE_MS) {
|
|
165
|
+
const again = readLock(p);
|
|
166
|
+
if (typeof again === 'object')
|
|
167
|
+
return { taken: false, holder: again.lock };
|
|
168
|
+
return { taken: false, refused: [unwritable('the lock is being written by another process')] };
|
|
169
|
+
}
|
|
170
|
+
pause(RETRY_PAUSE_MS);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// A lock is released by its taker only, and only while it still holds what the taker wrote.
|
|
174
|
+
// Windows: a scanner holding the file a moment fails the unlink (EBUSY, EPERM); it is retried within
|
|
175
|
+
// a second, as a create is, so a released lock does not read live to others until its `until`.
|
|
176
|
+
function releaseIf(p, text) {
|
|
177
|
+
const t0 = Date.now();
|
|
178
|
+
for (;;) {
|
|
179
|
+
try {
|
|
180
|
+
if (lstatSync(p).isSymbolicLink())
|
|
181
|
+
return;
|
|
182
|
+
if (readFileSync(p, 'utf8') !== text)
|
|
183
|
+
return;
|
|
184
|
+
busyIo.unlink(p);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
const code = e.code;
|
|
189
|
+
// gone already; an unlink that keeps failing is left to the dead-pid rule
|
|
190
|
+
if (code === undefined || !TRANSIENT.has(code) || Date.now() - t0 >= CREATE_RETRY_MS)
|
|
191
|
+
return;
|
|
192
|
+
pause(RETRY_PAUSE_MS);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// The live holder of `kind`'s lock on `target`, when it is a process other than `opts.pid`.
|
|
197
|
+
export function busyHolder(root, kind, target, opts = {}) {
|
|
198
|
+
if (!isId(target))
|
|
199
|
+
return undefined;
|
|
200
|
+
const dir = busyDir(root, false);
|
|
201
|
+
if (typeof dir !== 'string')
|
|
202
|
+
return undefined;
|
|
203
|
+
const held = readLock(join(dir, lockName(kind, target)));
|
|
204
|
+
if (typeof held !== 'object')
|
|
205
|
+
return undefined;
|
|
206
|
+
const pid = opts.pid ?? process.pid;
|
|
207
|
+
return held.lock.pid !== pid && live(held.lock, opts.now ?? Date.now()) ? held.lock : undefined;
|
|
208
|
+
}
|
|
209
|
+
// Drive's cleanup (`releaseDeadTurn`'s pattern, row 218): the locks of dead pids, and the
|
|
210
|
+
// caller's own leftovers, before Windows can hand a dead pid to another process. The count.
|
|
211
|
+
export function sweepDeadBusy(root, opts = {}) {
|
|
212
|
+
const dir = busyDir(root, false);
|
|
213
|
+
if (typeof dir !== 'string')
|
|
214
|
+
return 0;
|
|
215
|
+
const pid = opts.pid ?? process.pid;
|
|
216
|
+
let n = 0;
|
|
217
|
+
let names;
|
|
218
|
+
try {
|
|
219
|
+
names = readdirSync(dir);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
for (const name of names) {
|
|
225
|
+
if (!/\.(settle|ship)\.json$/.test(name))
|
|
226
|
+
continue;
|
|
227
|
+
const p = join(dir, name);
|
|
228
|
+
// Asked again under the steal guard, so a live lock written meanwhile is never removed. A
|
|
229
|
+
// write in progress (an empty file) is not dropped: its taker is mid-create.
|
|
230
|
+
const droppable = (t) => {
|
|
231
|
+
if (t === undefined) {
|
|
232
|
+
try {
|
|
233
|
+
return lstatSync(p).isSymbolicLink();
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const l = parseLock(t);
|
|
240
|
+
return l === 'malformed' || (typeof l === 'object' && (l.pid === pid || !isAlive(l.pid) || !live(l, Date.now())));
|
|
241
|
+
};
|
|
242
|
+
const text = readLock(p) === 'link' ? undefined : (() => { try {
|
|
243
|
+
return readFileSync(p, 'utf8');
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return '';
|
|
247
|
+
} })();
|
|
248
|
+
if (!droppable(text))
|
|
249
|
+
continue;
|
|
250
|
+
try {
|
|
251
|
+
if (takeStale(p, droppable) === 'taken')
|
|
252
|
+
n++;
|
|
253
|
+
}
|
|
254
|
+
catch { /* left to the next sweep */ }
|
|
255
|
+
}
|
|
256
|
+
return n;
|
|
257
|
+
}
|
|
258
|
+
// The bound a taker writes: the estimate, or inside a drive session the session's deadline when
|
|
259
|
+
// later — a reviewer there may wait out a usage limit until then (reviewer.ts) — and never more
|
|
260
|
+
// than the cap after now. The cap goes last (pass 6, P20), so no bound is stale at birth.
|
|
261
|
+
function bound(estimateMs, env, now) {
|
|
262
|
+
const deadline = Number(env[DRIVE_DEADLINE_ENV]) || 0;
|
|
263
|
+
return Math.min(Math.max(now + estimateMs, deadline), now + BUSY_MAX_MS);
|
|
264
|
+
}
|
|
265
|
+
// A self-repair reroll is a second arbitration, each of up to three timed attempts, then the
|
|
266
|
+
// door's lock wait — twice when `parkRefused` follows — and two minutes of slack.
|
|
267
|
+
const settleEstimate = (cfg) => 2 * 3 * cfg.gates.reviewerTimeoutMs + 2 * LOCK_WAIT_MS + 120_000;
|
|
268
|
+
export function settleUntil(cfg, env, now) {
|
|
269
|
+
return bound(settleEstimate(cfg), env, now);
|
|
270
|
+
}
|
|
271
|
+
// The ship gate's battery, the CI watch, both settles, and ten minutes for git and gh.
|
|
272
|
+
export function shipUntil(cfg, env, now) {
|
|
273
|
+
return bound(3 * cfg.gates.reviewerTimeoutMs + cfg.ship.ciSettleMs + 1_800_000 + 2 * settleEstimate(cfg) + 600_000, env, now);
|
|
274
|
+
}
|
package/dist/caps.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Ctx } from './cli.js';
|
|
2
|
-
import type { DriveCaps } from './config.js';
|
|
2
|
+
import type { Config, DriveCaps } from './config.js';
|
|
3
3
|
import type { Entry } from './journal.js';
|
|
4
4
|
export type CapName = 'rounds' | 'upstream' | 'spawns' | 'wall-clock';
|
|
5
5
|
export interface TargetUse {
|
|
@@ -12,9 +12,10 @@ export interface CapHit {
|
|
|
12
12
|
note: string;
|
|
13
13
|
}
|
|
14
14
|
export declare function capHit(entries: Entry[], use: TargetUse, caps: DriveCaps): CapHit | undefined;
|
|
15
|
-
export declare function parkAtCap(ctx: Ctx, root: string, target: string, hit: CapHit): Promise<{
|
|
15
|
+
export declare function parkAtCap(ctx: Ctx, root: string, target: string, hit: CapHit, cfg: Config): Promise<{
|
|
16
16
|
parked: true;
|
|
17
17
|
} | {
|
|
18
18
|
parked: false;
|
|
19
19
|
why: string;
|
|
20
|
+
busy?: true;
|
|
20
21
|
}>;
|
package/dist/caps.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { settleUntil, takeBusy } from './busy.js';
|
|
1
2
|
import { EXIT } from './cli.js';
|
|
2
|
-
import { fellBack, gateRuns, lastGateRun } from './rounds.js';
|
|
3
|
+
import { fellBack, gateRuns, lastGateRun, settledToken, unparkAt } from './rounds.js';
|
|
3
4
|
import { duration } from './usage.js';
|
|
4
5
|
import { gateSettled } from './verbs/next.js';
|
|
5
6
|
const isCapPark = (e) => {
|
|
@@ -17,8 +18,9 @@ function openGates(entries) {
|
|
|
17
18
|
}
|
|
18
19
|
// First hit wins, in this order: rounds · upstream · spawns · wall clock.
|
|
19
20
|
export function capHit(entries, use, caps) {
|
|
21
|
+
// Row 241 (R11): a human un-park restarts the window, as a cap park does.
|
|
20
22
|
let lastPark = -1;
|
|
21
|
-
entries.forEach((e, i) => { if (isCapPark(e))
|
|
23
|
+
entries.forEach((e, i) => { if (isCapPark(e) || unparkAt(entries, i))
|
|
22
24
|
lastPark = i; });
|
|
23
25
|
const since = entries.slice(lastPark + 1);
|
|
24
26
|
// Every budget reset is ignored: this counts the rounds a gate ran, not its window. The
|
|
@@ -50,7 +52,23 @@ export function capHit(entries, use, caps) {
|
|
|
50
52
|
// The park goes through A1's one door with `selected: 'policy'` and the cap as its rule.
|
|
51
53
|
// `park` anchors it on the gate's last run even after the author moved the tree. A target
|
|
52
54
|
// with no open gate has nothing to park on; a refusal from the door is named, not guessed.
|
|
53
|
-
export async function parkAtCap(ctx, root, target, hit) {
|
|
55
|
+
export async function parkAtCap(ctx, root, target, hit, cfg) {
|
|
56
|
+
// Row 240 (design §4.1.2): under the stop's settle lock, taken before the stream is read. Held
|
|
57
|
+
// by another live process, nothing parks and drive tries the target again next round.
|
|
58
|
+
const lock = takeBusy(root, 'settle', target, settleUntil(cfg, ctx.env, Date.now()));
|
|
59
|
+
if (!lock.taken) {
|
|
60
|
+
if ('holder' in lock)
|
|
61
|
+
return { parked: false, busy: true, why: 'busy' };
|
|
62
|
+
return { parked: false, why: `the policy could not park it (${lock.refused[0]?.rule ?? 'lock-unwritable'})` };
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
return await parkUnderLock(ctx, root, target, hit);
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
lock.release();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function parkUnderLock(ctx, root, target, hit) {
|
|
54
72
|
const { readStream } = await import('./journal.js');
|
|
55
73
|
const entries = readStream(root, target);
|
|
56
74
|
if (!entries.some((e) => e.t === 'gate-run'))
|
|
@@ -63,8 +81,11 @@ export async function parkAtCap(ctx, root, target, hit) {
|
|
|
63
81
|
// Loaded on A1's precedent for settle.ts: decide.ts reaches the gate registry.
|
|
64
82
|
const { applyDecision } = await import('./verbs/decide.js');
|
|
65
83
|
const errs = [];
|
|
84
|
+
// Row 240 (R3): the token of this read, so a park read before another decision on the gate —
|
|
85
|
+
// a human's revise-upstream, a settler's — refuses `settled-since` instead of parking on top (P7).
|
|
66
86
|
const code = await applyDecision({ ...ctx, cwd: root, err: (l) => { errs.push(l); ctx.err(l); } }, {
|
|
67
87
|
gate, target, decision: 'stop', note: hit.note, selected: 'policy', rule: `cap-${hit.cap}`, park: true, runId: last.run_id,
|
|
88
|
+
token: settledToken(entries, gate, last.run_id),
|
|
68
89
|
});
|
|
69
90
|
if (code === EXIT.OK)
|
|
70
91
|
return { parked: true };
|
package/dist/decide-view.d.ts
CHANGED
|
@@ -34,6 +34,12 @@ export type DecideView = {
|
|
|
34
34
|
state: 'settled';
|
|
35
35
|
disposition: Disposition;
|
|
36
36
|
last: LastRun;
|
|
37
|
+
} | {
|
|
38
|
+
state: 'parked';
|
|
39
|
+
why: string;
|
|
40
|
+
disposition: Disposition;
|
|
41
|
+
last: LastRun;
|
|
42
|
+
reopen: Act[];
|
|
37
43
|
} | {
|
|
38
44
|
state: 'actionable';
|
|
39
45
|
run: GateRunView;
|
package/dist/decide-view.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cliAct, exitsLine } from './act.js';
|
|
1
|
+
import { cliAct, exitsLine, reopenRows } from './act.js';
|
|
2
2
|
import { untrustedCmdsFor } from './allowlist.js';
|
|
3
3
|
import { autonomyLines, decidedBy } from './autonomy.js';
|
|
4
4
|
import { gateSpec } from './gate.js';
|
|
@@ -9,10 +9,11 @@ import './gates/index.js';
|
|
|
9
9
|
import { policyPins, readStream } from './journal.js';
|
|
10
10
|
import { liftedHolds } from './needs.js';
|
|
11
11
|
import { recommend, renderDecision } from './recommend.js';
|
|
12
|
-
import { exitActs, lastGateRun, openReopen } from './rounds.js';
|
|
12
|
+
import { exitActs, lastGateRun, openReopen, reopenActs } from './rounds.js';
|
|
13
|
+
import { gateParked, parkOwed, parkedBy } from './verbs/next.js';
|
|
13
14
|
import { criteriaOwner } from './scan.js';
|
|
14
15
|
import { short } from './sha.js';
|
|
15
|
-
import { cmd, kv, rows } from './toon.js';
|
|
16
|
+
import { cmd, kv, rows, logSafe } from './toon.js';
|
|
16
17
|
// The record's fields the screen reads, each present only when the record carries it.
|
|
17
18
|
function dispositionOf(d) {
|
|
18
19
|
return {
|
|
@@ -60,6 +61,14 @@ export function decideView(root, cfg, canon, gate, target) {
|
|
|
60
61
|
exits: exitActs(gate, target, entries, stale, upstream),
|
|
61
62
|
};
|
|
62
63
|
}
|
|
64
|
+
if (disposition && gateParked(entries, gate)) {
|
|
65
|
+
const anchor = (last.verdicts ?? []).flatMap((rv) => rv.findings.filter((f) => f.blocking))
|
|
66
|
+
.map((f) => (typeof f.anchor === 'string' ? f.anchor : `omission:${f.anchor.scope}`))[0] ?? last.standing ?? last.outcome;
|
|
67
|
+
return {
|
|
68
|
+
...head, state: 'parked', why: parkedBy(entries, gate, anchor), disposition, last: lastRun,
|
|
69
|
+
reopen: reopenActs(gate, target, entries, upstream, parkOwed(root, cfg, canon, gate, target, entries)),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
63
72
|
if (disposition && disposition.decision !== 'revise' && disposition.decision !== 'revise-upstream') {
|
|
64
73
|
return { ...head, state: 'settled', disposition, last: lastRun };
|
|
65
74
|
}
|
|
@@ -100,6 +109,15 @@ export function decideViewLines(view) {
|
|
|
100
109
|
out.push(cmd('exits', exitsLine(view.exits)));
|
|
101
110
|
return out;
|
|
102
111
|
}
|
|
112
|
+
if (view.state === 'parked') {
|
|
113
|
+
out.push(kv('gate', gate));
|
|
114
|
+
out.push(kv('target', target));
|
|
115
|
+
out.push(`state: parked — ${logSafe(view.why)}`);
|
|
116
|
+
out.push(kv('decided-by', decidedBy(view.disposition)));
|
|
117
|
+
out.push(kv('last-run', `round ${view.last.round} @${view.last.sha} — ${view.last.outcome} · ${cliAct('log', target).line}`));
|
|
118
|
+
out.push(...reopenRows(view.reopen));
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
103
121
|
if (view.state === 'settled') {
|
|
104
122
|
const d = view.disposition;
|
|
105
123
|
out.push(kv('gate', gate));
|
package/dist/drive-presence.d.ts
CHANGED
|
@@ -19,9 +19,12 @@ export declare const DRIVE_LEASE_MS = 120000;
|
|
|
19
19
|
export declare const DRIVE_RENEW_MS = 10000;
|
|
20
20
|
export declare const DRIVE_TAKEOVER_GRACE_MS = 25000;
|
|
21
21
|
export declare function driveHolder(root: string, now?: number): DriveHolder | undefined;
|
|
22
|
+
export declare function olderDrive(root: string, now?: number): DriveHolder | undefined;
|
|
23
|
+
export declare const OLDER_DRIVE_LINE = "wait: older drive \u2014 a witness drive from before 0.29 runs this repo \u00B7 stop it, then say go";
|
|
22
24
|
export declare function renewDriveLock(root: string, pid?: number): boolean;
|
|
23
25
|
export declare function holdLease(root: string, onLost: () => void, everyMs?: number, pid?: number): () => void;
|
|
24
26
|
export declare function acquireDriveLock(root: string, info: {
|
|
25
27
|
log?: string;
|
|
26
28
|
}, pid?: number, graceMs?: number): Result<() => void>;
|
|
27
29
|
export declare function watchLine(h: DriveHolder, platform?: Platform): string;
|
|
30
|
+
export declare function stopCommand(h: DriveHolder, platform?: Platform): string;
|
package/dist/drive-presence.js
CHANGED
|
@@ -70,7 +70,7 @@ function readHolder(root) {
|
|
|
70
70
|
// The lock says only WHETHER a background log exists; its path is always derived. What
|
|
71
71
|
// the file says is never printed: `watch:` is a line the engine acts on, and a path read
|
|
72
72
|
// from a file could carry a newline and a forged `launch:` or `run:` line.
|
|
73
|
-
return { pid: h.pid, renewed, leased: h.lease === 1, ...(h.log !== undefined ? { log: join(root, DRIVE_LOG) } : {}) };
|
|
73
|
+
return { pid: h.pid, renewed, leased: h.lease === 1, busy: h.busy === 1, ...(h.log !== undefined ? { log: join(root, DRIVE_LOG) } : {}) };
|
|
74
74
|
}
|
|
75
75
|
catch {
|
|
76
76
|
return 'unreadable';
|
|
@@ -85,6 +85,15 @@ export function driveHolder(root, now = Date.now()) {
|
|
|
85
85
|
return undefined;
|
|
86
86
|
return { pid: h.pid, ...(h.log !== undefined ? { log: h.log } : {}) };
|
|
87
87
|
}
|
|
88
|
+
// Row 240. A live drive from before 0.29 (its lock has no `busy: 1`), or none.
|
|
89
|
+
export function olderDrive(root, now = Date.now()) {
|
|
90
|
+
const h = readHolder(root);
|
|
91
|
+
if (typeof h !== 'object' || h.busy || !isAlive(h.pid) || !leaseLive(h, now))
|
|
92
|
+
return undefined;
|
|
93
|
+
return { pid: h.pid, ...(h.log !== undefined ? { log: h.log } : {}) };
|
|
94
|
+
}
|
|
95
|
+
// What `next` and `wait` print beside an older drive, above its stop command on a `run:` row.
|
|
96
|
+
export const OLDER_DRIVE_LINE = 'wait: older drive — a witness drive from before 0.29 runs this repo · stop it, then say go';
|
|
88
97
|
// Row 224. The running drive's renewal: the lock's mtime set to now when the lock is this
|
|
89
98
|
// pid's. A link at the lock path is never followed (utimes would touch what it points at).
|
|
90
99
|
// `false` says the lease is no longer this drive's — taken over, or removed — and the drive
|
|
@@ -133,7 +142,7 @@ export function acquireDriveLock(root, info, pid = process.pid, graceMs = DRIVE_
|
|
|
133
142
|
let expired;
|
|
134
143
|
for (;;) {
|
|
135
144
|
try {
|
|
136
|
-
writeFileSync(p, JSON.stringify({ pid, ...(info.log !== undefined ? { log: info.log } : {}), lease: 1 }), { flag: 'wx' });
|
|
145
|
+
writeFileSync(p, JSON.stringify({ pid, ...(info.log !== undefined ? { log: info.log } : {}), lease: 1, busy: 1 }), { flag: 'wx' });
|
|
137
146
|
return ok(release);
|
|
138
147
|
}
|
|
139
148
|
catch (e) {
|
|
@@ -211,9 +220,12 @@ export function acquireDriveLock(root, info, pid = process.pid, graceMs = DRIVE_
|
|
|
211
220
|
export function watchLine(h, platform = process.platform) {
|
|
212
221
|
if (h.log === undefined)
|
|
213
222
|
return `the terminal running witness drive · pid ${h.pid}`;
|
|
214
|
-
const pid = String(h.pid);
|
|
215
223
|
const watch = platform === 'win32' ? ['Get-Content', '-LiteralPath', h.log, '-Wait', '-Tail', '50', '-Encoding', 'UTF8'] : ['tail', '-f', h.log];
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
224
|
+
return `${render(watch, platform)} · stop it: ${stopCommand(h, platform)}`;
|
|
225
|
+
}
|
|
226
|
+
const render = (argv, platform) => argv.map((w) => shellWordExact(w, platform)).join(' ');
|
|
227
|
+
// The command that stops a drive, by its pid: the `watch:` line's stop (rows 180 and 201).
|
|
228
|
+
export function stopCommand(h, platform = process.platform) {
|
|
229
|
+
const pid = String(h.pid);
|
|
230
|
+
return render(platform === 'win32' ? ['taskkill', '/PID', pid, '/T', '/F'] : ['kill', pid], platform);
|
|
219
231
|
}
|
package/dist/drive.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type Result } from './refusal.js';
|
|
|
4
4
|
import { type Canon } from './scan.js';
|
|
5
5
|
import { spawn, type ResolvedSpawn } from './spawn.js';
|
|
6
6
|
import { type NextAction } from './verbs/next.js';
|
|
7
|
+
import { type DecisionAct } from './verbs/decide.js';
|
|
7
8
|
import { type Decision } from './recommend.js';
|
|
8
9
|
import { type KeptStop } from './autonomy.js';
|
|
9
10
|
import { type RunCommand } from './allowlist.js';
|
|
@@ -27,6 +28,9 @@ export type DriveStep = {
|
|
|
27
28
|
} | {
|
|
28
29
|
kind: 'merge';
|
|
29
30
|
line: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'fix';
|
|
33
|
+
line: string;
|
|
30
34
|
} | {
|
|
31
35
|
kind: 'kept';
|
|
32
36
|
stop: 'trust-grant';
|
|
@@ -75,7 +79,7 @@ export declare const AUTONOMY_MAX_SPAWNS = 200;
|
|
|
75
79
|
export declare const PAUSE_POLL_MS = 5000;
|
|
76
80
|
export declare const PAUSE_IDLE_MAX_MS = 43200000;
|
|
77
81
|
export declare function watchSignature(root: string): string;
|
|
78
|
-
export type AsideKind = 'kept' | 'decision' | 'conversation' | 'merge' | 'stuck' | 'capped';
|
|
82
|
+
export type AsideKind = 'kept' | 'decision' | 'conversation' | 'merge' | 'fix' | 'stuck' | 'capped' | 'retry' | 'recheck';
|
|
79
83
|
export interface Aside {
|
|
80
84
|
target: string;
|
|
81
85
|
kind: AsideKind;
|
|
@@ -85,7 +89,20 @@ export interface Aside {
|
|
|
85
89
|
stop?: KeptStop;
|
|
86
90
|
key0?: string;
|
|
87
91
|
trust?: RunCommand[];
|
|
92
|
+
due?: number;
|
|
93
|
+
kept?: DecisionAct;
|
|
94
|
+
tries?: number;
|
|
88
95
|
}
|
|
96
|
+
export declare const RETRY_DUE_MS = 30000;
|
|
97
|
+
export declare const RETRY_MAX = 3;
|
|
98
|
+
export declare const RECHECK_FIRST_MS = 300000;
|
|
99
|
+
export declare const RECHECK_MAX_MS = 3600000;
|
|
100
|
+
export declare function settleAdmitsFor(t: string | undefined, s: {
|
|
101
|
+
lanes: ReadonlyMap<string, unknown>;
|
|
102
|
+
aside: ReadonlyMap<string, unknown>;
|
|
103
|
+
flow?: string;
|
|
104
|
+
busy: (t: string) => boolean;
|
|
105
|
+
}): boolean;
|
|
89
106
|
export declare function flowOf(canon: Canon, t: string): string[];
|
|
90
107
|
export declare function journalWatch(root: string, target: string): (session?: string) => string[];
|
|
91
108
|
export declare function driveLoop(root: string, cfg: Config, ctx: Ctx, flags: DriveFlags, clock?: Clock): Promise<number>;
|