tickmarkr 2.5.7 → 2.5.9
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/dist/adapters/qwen.js +30 -3
- package/dist/cli/commands/approve.js +23 -4
- package/dist/cli/commands/beat.d.ts +2 -0
- package/dist/cli/commands/beat.js +28 -29
- package/dist/cli/commands/compile.js +18 -0
- package/dist/cli/commands/fleet.js +61 -53
- package/dist/cli/commands/plan.d.ts +5 -0
- package/dist/cli/commands/plan.js +28 -23
- package/dist/cli/commands/resume.js +1 -1
- package/dist/cli/commands/run.js +1 -1
- package/dist/cli/commands/verify.d.ts +4 -1
- package/dist/cli/commands/verify.js +16 -5
- package/dist/cli/help.d.ts +2 -0
- package/dist/cli/help.js +6 -4
- package/dist/compile/native.js +68 -7
- package/dist/compile/retired-literals.d.ts +22 -0
- package/dist/compile/retired-literals.js +271 -0
- package/dist/config/config.d.ts +41 -3
- package/dist/config/config.js +48 -17
- package/dist/config/fleet-overlay.js +47 -62
- package/dist/drivers/index.d.ts +4 -2
- package/dist/drivers/index.js +54 -6
- package/dist/gates/baseline.d.ts +65 -0
- package/dist/gates/baseline.js +163 -9
- package/dist/gates/review.d.ts +6 -4
- package/dist/gates/review.js +62 -21
- package/dist/gates/run-gates.d.ts +6 -1
- package/dist/gates/run-gates.js +25 -13
- package/dist/gates/test-manifest.d.ts +20 -1
- package/dist/gates/test-manifest.js +50 -22
- package/dist/gates/test-reporter.js +22 -1
- package/dist/graph/schema.d.ts +28 -0
- package/dist/graph/schema.js +13 -1
- package/dist/run/daemon.d.ts +19 -0
- package/dist/run/daemon.js +363 -118
- package/dist/run/journal.d.ts +54 -3
- package/dist/run/journal.js +142 -11
- package/dist/run/merge.d.ts +15 -2
- package/dist/run/merge.js +74 -11
- package/dist/run/protocol.d.ts +82 -0
- package/dist/run/protocol.js +35 -0
- package/dist/run/receipt-resolver.d.ts +18 -0
- package/dist/run/receipt-resolver.js +132 -0
- package/dist/run/repair-disposition.d.ts +41 -0
- package/dist/run/repair-disposition.js +77 -0
- package/dist/run/supervision.d.ts +14 -1
- package/dist/run/supervision.js +122 -24
- package/dist/tui/cockpit/evidence-view.d.ts +10 -1
- package/dist/tui/cockpit/evidence-view.js +37 -5
- package/dist/tui/cockpit/home-view.js +45 -30
- package/dist/tui/cockpit/live-store.d.ts +18 -0
- package/dist/tui/ink/fleet-app.d.ts +12 -22
- package/dist/tui/ink/fleet-app.js +520 -131
- package/package.json +1 -1
- package/schema/rungraph.schema.json +54 -0
- package/skills/tickmarkr-overseer/SKILL.md +168 -36
- package/skills/tickmarkr-overseer/scripts/watch-context.sh +14 -2
package/dist/run/protocol.js
CHANGED
|
@@ -33,6 +33,41 @@ export const ShellReceiptSchema = z.object({
|
|
|
33
33
|
error: z.string().optional(),
|
|
34
34
|
durationMs: z.number().nonnegative().optional(),
|
|
35
35
|
}).strict();
|
|
36
|
+
export const EVIDENCE_AVAILABILITIES = ["available", "not-started", "capture-failed", "killed", "expired", "missing"];
|
|
37
|
+
export const EvidenceArtifactSchema = z.object({
|
|
38
|
+
path: z.string().refine(p => p.length > 0 && !p.startsWith("/") && !p.includes("\\") && !p.split("/").includes("..")),
|
|
39
|
+
availability: z.enum(EVIDENCE_AVAILABILITIES),
|
|
40
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/).nullable(),
|
|
41
|
+
retainedBytes: z.number().int().min(0).max(16 * 1024),
|
|
42
|
+
droppedBytes: z.number().int().nonnegative(),
|
|
43
|
+
truncated: z.boolean(),
|
|
44
|
+
}).strict().superRefine((ref, ctx) => {
|
|
45
|
+
if (ref.truncated !== (ref.droppedBytes > 0))
|
|
46
|
+
ctx.addIssue({ code: "custom", message: "truncation must agree with dropped bytes" });
|
|
47
|
+
if (ref.availability === "available" && ref.sha256 === null)
|
|
48
|
+
ctx.addIssue({ code: "custom", message: "available bytes require a hash" });
|
|
49
|
+
});
|
|
50
|
+
export const GateEvidenceReceiptSchema = z.object({
|
|
51
|
+
invocationId: NonEmptyStringSchema,
|
|
52
|
+
nonce: NonEmptyStringSchema.optional(),
|
|
53
|
+
subject: z.object({
|
|
54
|
+
runId: NonEmptyStringSchema,
|
|
55
|
+
taskId: NonEmptyStringSchema.nullable(),
|
|
56
|
+
attempt: AttemptSchema.nullable(),
|
|
57
|
+
gate: NonEmptyStringSchema,
|
|
58
|
+
subjectCommit: NonEmptyStringSchema.nullable(),
|
|
59
|
+
}).strict(),
|
|
60
|
+
termination: z.object({
|
|
61
|
+
kind: z.enum(["exit", "signal", "timeout", "not-started", "unknown"]),
|
|
62
|
+
exitCode: z.number().int().nullable(),
|
|
63
|
+
signal: NonEmptyStringSchema.nullable(),
|
|
64
|
+
timedOut: z.boolean().nullable(),
|
|
65
|
+
}).strict(),
|
|
66
|
+
availability: z.enum(EVIDENCE_AVAILABILITIES),
|
|
67
|
+
redaction: z.object({ material: z.boolean() }).strict(),
|
|
68
|
+
stdout: EvidenceArtifactSchema,
|
|
69
|
+
stderr: EvidenceArtifactSchema,
|
|
70
|
+
}).strict();
|
|
36
71
|
/** A task-build row must carry the entire caller-owned correlation, even before spawn. */
|
|
37
72
|
export const CommandReceiptSchema = ShellReceiptSchema.extend({
|
|
38
73
|
attribution: CommandReceiptAttributionSchema,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type GateEvidenceReceipt } from "./protocol.js";
|
|
2
|
+
export declare const RECEIPT_UNAVAILABLE_REASONS: readonly ["outside-root", "symlink", "hash-mismatch", "expired", "missing"];
|
|
3
|
+
export type ReceiptUnavailableReason = (typeof RECEIPT_UNAVAILABLE_REASONS)[number];
|
|
4
|
+
export type ReceiptResolution = {
|
|
5
|
+
readonly ok: true;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly sha256: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly ok: false;
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly reason: ReceiptUnavailableReason;
|
|
12
|
+
};
|
|
13
|
+
/** Resolve one artifact reference against the run root it was recorded under. Fails closed. */
|
|
14
|
+
export declare function resolveReceipt(reference: unknown, runRoot: string): ReceiptResolution;
|
|
15
|
+
/** Both artifacts of a receipt, stdout first, each resolved independently. */
|
|
16
|
+
export declare function resolveReceiptArtifacts(receipt: GateEvidenceReceipt, runRoot: string): ReceiptResolution[];
|
|
17
|
+
/** One line per artifact for a human surface: the reference, then its verified availability. */
|
|
18
|
+
export declare function formatReceiptResolution(r: ReceiptResolution): string;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { EvidenceArtifactSchema } from "./protocol.js";
|
|
5
|
+
// OBS-1101 retrieval (D-174): the one production reader of an execution-evidence receipt. It answers
|
|
6
|
+
// from the bytes on disk under the run root the receipt was minted in and nothing else — no
|
|
7
|
+
// re-execution, no substitute chosen by name or timestamp, no symlink followed anywhere: not in the
|
|
8
|
+
// reference, not at the root, not above it. The caller hands a canonical root (its own trust anchor);
|
|
9
|
+
// a root reached through any link is refused outright.
|
|
10
|
+
export const RECEIPT_UNAVAILABLE_REASONS = ["outside-root", "symlink", "hash-mismatch", "expired", "missing"];
|
|
11
|
+
/** Resolve one artifact reference against the run root it was recorded under. Fails closed. */
|
|
12
|
+
export function resolveReceipt(reference, runRoot) {
|
|
13
|
+
const parsed = EvidenceArtifactSchema.safeParse(reference);
|
|
14
|
+
const path = typeof reference?.path === "string" ? reference.path : "";
|
|
15
|
+
if (!parsed.success) {
|
|
16
|
+
const escapes = path && (isAbsolute(path) || path.includes("\\") || path.split("/").includes(".."));
|
|
17
|
+
return { ok: false, path, reason: escapes ? "outside-root" : "missing" };
|
|
18
|
+
}
|
|
19
|
+
const ref = parsed.data;
|
|
20
|
+
if (ref.availability === "expired")
|
|
21
|
+
return { ok: false, path: ref.path, reason: "expired" };
|
|
22
|
+
if (ref.availability !== "available" || ref.sha256 === null)
|
|
23
|
+
return { ok: false, path: ref.path, reason: "missing" };
|
|
24
|
+
const root = resolve(runRoot);
|
|
25
|
+
const full = resolve(root, ref.path);
|
|
26
|
+
const rel = relative(root, full);
|
|
27
|
+
if (!rel || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel))
|
|
28
|
+
return { ok: false, path: ref.path, reason: "outside-root" };
|
|
29
|
+
const read = readUnderRoot(root, rel.split(sep));
|
|
30
|
+
if (typeof read === "string")
|
|
31
|
+
return { ok: false, path: ref.path, reason: read };
|
|
32
|
+
const sha256 = createHash("sha256").update(read).digest("hex");
|
|
33
|
+
if (sha256 !== ref.sha256 || read.length !== ref.retainedBytes)
|
|
34
|
+
return { ok: false, path: ref.path, reason: "hash-mismatch" };
|
|
35
|
+
return { ok: true, path: ref.path, sha256 };
|
|
36
|
+
}
|
|
37
|
+
const same = (a, b) => a.dev === b.dev && a.ino === b.ino;
|
|
38
|
+
/** Every ancestor of the root, root first excluded — "/" itself cannot be a link. */
|
|
39
|
+
function ancestors(root) {
|
|
40
|
+
const out = [];
|
|
41
|
+
for (let p = dirname(root); p !== dirname(p); p = dirname(p))
|
|
42
|
+
out.push(p);
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Walk `parts` below `root` one descriptor at a time and return the leaf's bytes. Every component —
|
|
47
|
+
* the root's ancestors, the root, each directory, the leaf — is opened O_NOFOLLOW and must be the
|
|
48
|
+
* same inode lstat reports for that name before AND after the open, so a component swapped for a
|
|
49
|
+
* link mid-walk is refused rather than followed. Every platform takes the same pathname open: an
|
|
50
|
+
* ancestor swap by a same-privilege writer can only ever yield hash-identical bytes (D-269), so no
|
|
51
|
+
* descriptor-anchored traversal is layered on top (D-279: the boundary is the run root).
|
|
52
|
+
*/
|
|
53
|
+
function readUnderRoot(root, parts) {
|
|
54
|
+
for (const p of ancestors(root)) {
|
|
55
|
+
let st;
|
|
56
|
+
try {
|
|
57
|
+
st = lstatSync(p);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return "missing";
|
|
61
|
+
}
|
|
62
|
+
if (st.isSymbolicLink())
|
|
63
|
+
return "symlink";
|
|
64
|
+
}
|
|
65
|
+
const fds = [];
|
|
66
|
+
try {
|
|
67
|
+
let parent = openComponent(root, true);
|
|
68
|
+
if (typeof parent === "string")
|
|
69
|
+
return parent;
|
|
70
|
+
fds.push(parent);
|
|
71
|
+
let at = root;
|
|
72
|
+
for (let i = 0; i < parts.length; i++) {
|
|
73
|
+
at = resolve(at, parts[i]);
|
|
74
|
+
const fd = openComponent(at, i < parts.length - 1);
|
|
75
|
+
if (typeof fd === "string")
|
|
76
|
+
return fd;
|
|
77
|
+
fds.push(fd);
|
|
78
|
+
parent = fd;
|
|
79
|
+
}
|
|
80
|
+
return readFileSync(parent);
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
return e.code === "ELOOP" ? "symlink" : "missing";
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
for (const fd of fds)
|
|
87
|
+
closeSync(fd);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function openComponent(path, dir) {
|
|
91
|
+
let before;
|
|
92
|
+
try {
|
|
93
|
+
before = lstatSync(path);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return "missing";
|
|
97
|
+
}
|
|
98
|
+
if (before.isSymbolicLink())
|
|
99
|
+
return "symlink";
|
|
100
|
+
if (dir ? !before.isDirectory() : !before.isFile())
|
|
101
|
+
return "missing";
|
|
102
|
+
const flags = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK | (dir ? constants.O_DIRECTORY : 0);
|
|
103
|
+
const fd = openSync(path, flags);
|
|
104
|
+
let after;
|
|
105
|
+
try {
|
|
106
|
+
after = lstatSync(path);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
closeSync(fd);
|
|
110
|
+
return "missing";
|
|
111
|
+
}
|
|
112
|
+
const opened = fstatSync(fd);
|
|
113
|
+
if (after.isSymbolicLink() || !same(before, opened) || !same(after, opened)) {
|
|
114
|
+
closeSync(fd);
|
|
115
|
+
return "symlink";
|
|
116
|
+
}
|
|
117
|
+
// A leaf reachable under a second name (a hard link) is an alias the inode check cannot see through;
|
|
118
|
+
// evidence is written once under one name, so any aliased leaf is refused.
|
|
119
|
+
if (!dir && opened.nlink !== 1) {
|
|
120
|
+
closeSync(fd);
|
|
121
|
+
return "symlink";
|
|
122
|
+
}
|
|
123
|
+
return fd;
|
|
124
|
+
}
|
|
125
|
+
/** Both artifacts of a receipt, stdout first, each resolved independently. */
|
|
126
|
+
export function resolveReceiptArtifacts(receipt, runRoot) {
|
|
127
|
+
return [receipt.stdout, receipt.stderr].map(ref => resolveReceipt(ref, runRoot));
|
|
128
|
+
}
|
|
129
|
+
/** One line per artifact for a human surface: the reference, then its verified availability. */
|
|
130
|
+
export function formatReceiptResolution(r) {
|
|
131
|
+
return r.ok ? `${r.path} available sha256=${r.sha256}` : `${r.path} unavailable (${r.reason})`;
|
|
132
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { GateResult } from "../gates/types.js";
|
|
2
|
+
/** Pure decision table of the scope-red disposition (OBS-1077, OBS-1074 residual): no filesystem,
|
|
3
|
+
* process, clock or journal. The caller supplies the inventory and performs every side effect. */
|
|
4
|
+
export type RepairDispositionKind = "fund-repair" | "scope-request" | "authoring" | "none";
|
|
5
|
+
export interface RepairDisposition {
|
|
6
|
+
kind: RepairDispositionKind;
|
|
7
|
+
/** validated inventory paths only — the sole paths a caller may put in an executable command */
|
|
8
|
+
paths: string[];
|
|
9
|
+
reason: string;
|
|
10
|
+
/** which evidence decided: a gate name, "worker" for a refusal, absent for the ordinary disposition */
|
|
11
|
+
source?: string;
|
|
12
|
+
/** an independent classification that kept priority over path prose */
|
|
13
|
+
blocker?: "infra" | "scope-collateral";
|
|
14
|
+
/** candidates that bound to nothing, or to more than one path; evidence, never approval advice */
|
|
15
|
+
diagnostics: ScopeHintDiagnostic[];
|
|
16
|
+
}
|
|
17
|
+
export interface ScopeHintDiagnostic {
|
|
18
|
+
candidate: string;
|
|
19
|
+
kind: "unresolved" | "ambiguous";
|
|
20
|
+
matches: string[];
|
|
21
|
+
reason: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ScopeHintResolution {
|
|
24
|
+
resolved: string[];
|
|
25
|
+
diagnostics: ScopeHintDiagnostic[];
|
|
26
|
+
}
|
|
27
|
+
export interface RepairDispositionInput {
|
|
28
|
+
/** the failing gate results (passing rows are ignored) */
|
|
29
|
+
results: readonly GateResult[];
|
|
30
|
+
files: readonly string[];
|
|
31
|
+
/** the worker's refusal summary — present only when the worker reported ok:false */
|
|
32
|
+
refusalSummary?: string;
|
|
33
|
+
/** task tree plus diff, deleted tracked paths included */
|
|
34
|
+
inventory: Iterable<string>;
|
|
35
|
+
}
|
|
36
|
+
/** Lexing never starts in the middle of a word (same lexer as the daemon's scope-red disposition). */
|
|
37
|
+
export declare const namedPaths: (text: string) => string[];
|
|
38
|
+
/** Binds candidates to the SUPPLIED inventory and nothing else: an exact path, else a unique
|
|
39
|
+
* path-suffix. Anything unbound or bound twice comes back as a non-executable diagnostic. */
|
|
40
|
+
export declare function resolveScopeHints(candidates: Iterable<string>, inventory: Iterable<string>): ScopeHintResolution;
|
|
41
|
+
export declare function classifyRepairDisposition(input: RepairDispositionInput): RepairDisposition;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { filesGlob } from "../graph/files-glob.js";
|
|
2
|
+
const failed = (g) => !(g.pass || g.meta?.skipped === true) || g.meta?.infra === true;
|
|
3
|
+
const REFUSAL_RE = /outside|out.of.scope|allowlist|scope expansion|not (?:in|own)|unowned/i;
|
|
4
|
+
/** Lexing never starts in the middle of a word (same lexer as the daemon's scope-red disposition). */
|
|
5
|
+
export const namedPaths = (text) => [...text.matchAll(/(?:^|[\s`'"])((?:[A-Za-z0-9_@.()[\]-]+\/)+[A-Za-z0-9_@.[\]-]+|[A-Za-z0-9_@-]+(?:\.[A-Za-z0-9_-]+)+)(?=$|[\s`'"),:;.!?])/g)]
|
|
6
|
+
.map((match) => match[1].replace(/^\.\//, "").replace(/\.$/, ""))
|
|
7
|
+
.filter((path) => !path.split("/").includes(".."));
|
|
8
|
+
/** Binds candidates to the SUPPLIED inventory and nothing else: an exact path, else a unique
|
|
9
|
+
* path-suffix. Anything unbound or bound twice comes back as a non-executable diagnostic. */
|
|
10
|
+
export function resolveScopeHints(candidates, inventory) {
|
|
11
|
+
const known = new Set(inventory);
|
|
12
|
+
const resolved = new Set();
|
|
13
|
+
const diagnostics = [];
|
|
14
|
+
for (const candidate of new Set(candidates)) {
|
|
15
|
+
if (known.has(candidate)) {
|
|
16
|
+
resolved.add(candidate);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const matches = [...known].filter((path) => path.endsWith(`/${candidate}`)).sort();
|
|
20
|
+
if (matches.length === 1)
|
|
21
|
+
resolved.add(matches[0]);
|
|
22
|
+
else
|
|
23
|
+
diagnostics.push(matches.length === 0
|
|
24
|
+
? { candidate, kind: "unresolved", matches, reason: `scope hint resolves to nothing in the task tree: ${candidate}` }
|
|
25
|
+
: { candidate, kind: "ambiguous", matches, reason: `scope hint ${candidate} matches ${matches.length} paths: ${matches.join(", ")}` });
|
|
26
|
+
}
|
|
27
|
+
return { resolved: [...resolved].sort(), diagnostics };
|
|
28
|
+
}
|
|
29
|
+
export function classifyRepairDisposition(input) {
|
|
30
|
+
const reds = input.results.filter(failed);
|
|
31
|
+
const none = (reason, extra = {}) => ({ kind: "none", paths: [], reason, diagnostics: [], ...extra });
|
|
32
|
+
// Independent classifications first: prose naming a path never erases them.
|
|
33
|
+
const infra = reds.find((g) => g.meta?.infra === true);
|
|
34
|
+
if (infra)
|
|
35
|
+
return none(`${infra.gate}: infra red keeps its own classification`, { source: infra.gate, blocker: "infra" });
|
|
36
|
+
const verdict = reds.find((g) => g.gate === "scope")?.meta?.collateral;
|
|
37
|
+
if (verdict) {
|
|
38
|
+
return verdict.authoring
|
|
39
|
+
? { kind: "authoring", paths: [...verdict.predicted], reason: verdict.repair, source: "scope", blocker: "scope-collateral", diagnostics: [] }
|
|
40
|
+
: none("scope: collateral verdict has unpredicted offenders — ordinary chargeable disposition", { source: "scope", blocker: "scope-collateral" });
|
|
41
|
+
}
|
|
42
|
+
if (input.files.length === 0)
|
|
43
|
+
return none("task declares no files[]");
|
|
44
|
+
const allowed = filesGlob([...input.files]);
|
|
45
|
+
const inventory = [...input.inventory];
|
|
46
|
+
const unowned = (text) => {
|
|
47
|
+
const r = resolveScopeHints(namedPaths(text).filter((path) => !allowed(path)), inventory);
|
|
48
|
+
return { paths: r.resolved.filter((path) => !allowed(path)), diagnostics: r.diagnostics };
|
|
49
|
+
};
|
|
50
|
+
const owned = (text) => resolveScopeHints(namedPaths(text), inventory).resolved.some(allowed);
|
|
51
|
+
const refusal = input.refusalSummary !== undefined && REFUSAL_RE.test(input.refusalSummary)
|
|
52
|
+
? unowned(input.refusalSummary) : { paths: [], diagnostics: [] };
|
|
53
|
+
// A test gate names where the ASSERTION lives — a detection site, not the code that needs fixing.
|
|
54
|
+
const sites = reds.filter((g) => g.gate === "test").map((g) => unowned(g.details));
|
|
55
|
+
const others = reds.filter((g) => g.gate !== "test");
|
|
56
|
+
const hints = others.map((g) => unowned(g.details));
|
|
57
|
+
const diagnostics = [refusal, ...sites, ...hints].flatMap((r) => r.diagnostics)
|
|
58
|
+
.filter((d, i, all) => all.findIndex((o) => o.candidate === d.candidate) === i);
|
|
59
|
+
const uniq = (rs) => [...new Set(rs.flatMap((r) => r.paths))].sort();
|
|
60
|
+
if (refusal.paths.length) {
|
|
61
|
+
return { kind: "scope-request", paths: refusal.paths, source: "worker", diagnostics,
|
|
62
|
+
reason: `worker refusal names unowned paths: ${refusal.paths.join(", ")}` };
|
|
63
|
+
}
|
|
64
|
+
const repair = uniq(hints);
|
|
65
|
+
if (repair.length && !others.some((g) => owned(g.details))) {
|
|
66
|
+
const review = others.some((g) => g.gate === "review");
|
|
67
|
+
return { kind: review ? "scope-request" : "authoring", paths: repair, source: others[0].gate, diagnostics,
|
|
68
|
+
reason: `files[] repair hint: ${repair.join(", ")}` };
|
|
69
|
+
}
|
|
70
|
+
const detection = uniq(sites);
|
|
71
|
+
if (detection.length) {
|
|
72
|
+
return { kind: "fund-repair", paths: detection, source: "test", diagnostics,
|
|
73
|
+
reason: `test gate names a detection site, not an out-of-scope repair: ${detection.join(", ")}` };
|
|
74
|
+
}
|
|
75
|
+
// Unknown attribution never blocks funding: the ordinary chargeable disposition applies.
|
|
76
|
+
return none("no attributable out-of-scope repair — ordinary chargeable disposition", { diagnostics });
|
|
77
|
+
}
|
|
@@ -39,7 +39,20 @@ export interface SupervisionBeatObservation {
|
|
|
39
39
|
export declare const supervisionBeatPath: (repoRoot: string, tier: SupervisionTier) => string;
|
|
40
40
|
/** Where a watcher records that it STOOD DOWN. Its own file: the beat keeps meaning only "alive". */
|
|
41
41
|
export declare const supervisionStandDownPath: (repoRoot: string, tier: SupervisionTier) => string;
|
|
42
|
-
|
|
42
|
+
/** Durable CLI arm; ticks never advance its epoch or its stand-down fence. */
|
|
43
|
+
export interface SupervisionArm {
|
|
44
|
+
armId: string;
|
|
45
|
+
armEpoch: string;
|
|
46
|
+
markerFence: string;
|
|
47
|
+
}
|
|
48
|
+
export declare const supervisionArmPath: (repoRoot: string, tier: SupervisionTier) => string;
|
|
49
|
+
/** Explicit arming acknowledges the current marker without deleting it. */
|
|
50
|
+
export declare function newSupervisionArm(repoRoot: string, tier: SupervisionTier, armId?: string, initial?: boolean): SupervisionArm;
|
|
51
|
+
export declare function beatSupervision(repoRoot: string, tier: SupervisionTier, seat?: string, observation?: SupervisionBeatObservation, options?: {
|
|
52
|
+
arm?: SupervisionArm;
|
|
53
|
+
armId?: string;
|
|
54
|
+
loop?: boolean;
|
|
55
|
+
}): boolean;
|
|
43
56
|
/** Handle a watcher holds for as long as it is supervising; disarm stands it down and is idempotent. */
|
|
44
57
|
export interface ArmedSupervision {
|
|
45
58
|
disarm: () => void;
|
package/dist/run/supervision.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
1
|
+
import { existsSync, linkSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { parseRunId } from "./journal.js";
|
|
5
5
|
import { stateDirName, tickmarkrDir } from "../graph/graph.js";
|
|
@@ -86,6 +86,63 @@ const supervisionDir = (repoRoot) => join(repoRoot, stateDirName(repoRoot), "sup
|
|
|
86
86
|
export const supervisionBeatPath = (repoRoot, tier) => join(supervisionDir(repoRoot), `${tier}.beat`);
|
|
87
87
|
/** Where a watcher records that it STOOD DOWN. Its own file: the beat keeps meaning only "alive". */
|
|
88
88
|
export const supervisionStandDownPath = (repoRoot, tier) => join(supervisionDir(repoRoot), `${tier}.standdown`);
|
|
89
|
+
export const supervisionArmPath = (repoRoot, tier) => join(supervisionDir(repoRoot), `${tier}.arm`);
|
|
90
|
+
function readArm(repoRoot, tier) {
|
|
91
|
+
try {
|
|
92
|
+
const arm = JSON.parse(readFileSync(supervisionArmPath(repoRoot, tier), "utf8"));
|
|
93
|
+
if (typeof arm.armId !== "string" || !arm.armId.trim() ||
|
|
94
|
+
typeof arm.armEpoch !== "string" || Number.isNaN(Date.parse(arm.armEpoch)) ||
|
|
95
|
+
typeof arm.markerFence !== "string")
|
|
96
|
+
throw new Error("invalid arm");
|
|
97
|
+
return arm;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error.code === "ENOENT")
|
|
101
|
+
return undefined;
|
|
102
|
+
throw new Error(`${tier} arm is unreadable`, { cause: error });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function markerFence(repoRoot, tier) {
|
|
106
|
+
const marker = readStandDown(repoRoot, tier);
|
|
107
|
+
if (marker === "UNREADABLE")
|
|
108
|
+
throw new Error(`${tier} stand-down is unreadable`);
|
|
109
|
+
return marker === "NONE" ? "NONE" : marker.fence;
|
|
110
|
+
}
|
|
111
|
+
/** Explicit arming acknowledges the current marker without deleting it. */
|
|
112
|
+
export function newSupervisionArm(repoRoot, tier, armId = randomUUID(), initial = false) {
|
|
113
|
+
// Acknowledge only the marker observed when arming begins. In particular, do not
|
|
114
|
+
// sample it after stamping the epoch: a stand-down published in that gap is a
|
|
115
|
+
// later act, and must fence this arm rather than be silently acknowledged by it.
|
|
116
|
+
const fence = initial ? "NONE" : markerFence(repoRoot, tier);
|
|
117
|
+
const previous = readArm(repoRoot, tier);
|
|
118
|
+
const arm = {
|
|
119
|
+
armId, armEpoch: new Date(Math.max(Date.now(), previous ? Date.parse(previous.armEpoch) + 1 : 0)).toISOString(),
|
|
120
|
+
markerFence: fence,
|
|
121
|
+
};
|
|
122
|
+
tickmarkrDir(repoRoot);
|
|
123
|
+
const path = supervisionArmPath(repoRoot, tier);
|
|
124
|
+
if (!initial) {
|
|
125
|
+
atomicRecord(path, arm);
|
|
126
|
+
return arm;
|
|
127
|
+
}
|
|
128
|
+
// Only one legacy first tick may install the initial arm. A losing process reuses the winner.
|
|
129
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
130
|
+
const tmp = `${path}.${randomUUID()}.tmp`;
|
|
131
|
+
try {
|
|
132
|
+
writeFileSync(tmp, JSON.stringify(arm) + "\n");
|
|
133
|
+
try {
|
|
134
|
+
linkSync(tmp, path);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (error.code !== "EEXIST")
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
rmSync(tmp, { force: true });
|
|
143
|
+
}
|
|
144
|
+
return readArm(repoRoot, tier);
|
|
145
|
+
}
|
|
89
146
|
/** The independent latch a stand-down cannot overwrite or remove. */
|
|
90
147
|
const supervisionObligationPath = (repoRoot, tier) => join(supervisionDir(repoRoot), `${tier}.clear-owed`);
|
|
91
148
|
// SUP-06: PRESENCE — one file per ARMED WATCHER, because a tier may legitimately have more than one.
|
|
@@ -190,6 +247,22 @@ function dischargeClearObligation(repoRoot, tier, observation) {
|
|
|
190
247
|
rmSync(supervisionObligationPath(repoRoot, tier), { force: true });
|
|
191
248
|
}
|
|
192
249
|
}
|
|
250
|
+
function raiseIfCrossed(repoRoot, tier, observation) {
|
|
251
|
+
if (observation.pct >= observation.thresholdPct) {
|
|
252
|
+
raiseClearObligation(repoRoot, tier, observation.armId, observation.thresholdPct);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// The latch is orthogonal to liveness: a stood-down tier still raises a crossing and still lets a
|
|
256
|
+
// different arm below threshold discharge it. Otherwise the context instrument goes silent after the
|
|
257
|
+
// first hand-off — the watcher script stands its tier down on every exit.
|
|
258
|
+
function observeWithoutBeat(repoRoot, tier, observation) {
|
|
259
|
+
if (observation !== undefined) {
|
|
260
|
+
tickmarkrDir(repoRoot);
|
|
261
|
+
raiseIfCrossed(repoRoot, tier, observation);
|
|
262
|
+
dischargeClearObligation(repoRoot, tier, observation);
|
|
263
|
+
}
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
193
266
|
function validateObservation(observation) {
|
|
194
267
|
if (!observation.armId.trim())
|
|
195
268
|
throw new Error("a supervision observation needs a non-empty arm identity");
|
|
@@ -202,7 +275,7 @@ function validateObservation(observation) {
|
|
|
202
275
|
// WRITER — a watcher's own call, on its own tier, every SUPERVISION_BEAT_MS. Never a reader's: the
|
|
203
276
|
// purity fence (status --watch leaves the state dir byte-identical) is the test that catches a reader
|
|
204
277
|
// that beats on the watcher's behalf, which would report every dead tier as healthy.
|
|
205
|
-
function writeSupervisionBeat(repoRoot, tier, seat, armId, observation) {
|
|
278
|
+
function writeSupervisionBeat(repoRoot, tier, seat, armId, observation, arm, loop = false) {
|
|
206
279
|
// A seat tier may not be armed anonymously, and the refusal belongs HERE rather than only in the
|
|
207
280
|
// verb: any caller that could write a seatless record could arm a tier nobody occupies.
|
|
208
281
|
if (isSeatTier(tier) && !seat?.trim()) {
|
|
@@ -215,19 +288,42 @@ function writeSupervisionBeat(repoRoot, tier, seat, armId, observation) {
|
|
|
215
288
|
mkdirSync(dirname(p), { recursive: true });
|
|
216
289
|
// Raise before the beat so a later beat failure cannot hide a duty; discharge only after the
|
|
217
290
|
// below-threshold observation exists on disk.
|
|
218
|
-
if (observation !== undefined
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
writeFileSync(p, JSON.stringify({
|
|
291
|
+
if (observation !== undefined)
|
|
292
|
+
raiseIfCrossed(repoRoot, tier, observation);
|
|
293
|
+
atomicRecord(p, {
|
|
222
294
|
tier, ...(seat ? { seat } : {}), ...(armId ? { armId } : {}),
|
|
223
295
|
...(observation !== undefined ? { pct: observation.pct, thresholdPct: observation.thresholdPct } : {}),
|
|
224
|
-
|
|
225
|
-
|
|
296
|
+
...arm,
|
|
297
|
+
...(loop ? { pid: process.pid } : { exitedWriterPid: process.pid }),
|
|
298
|
+
beatAt: new Date().toISOString(),
|
|
299
|
+
});
|
|
226
300
|
if (observation !== undefined)
|
|
227
301
|
dischargeClearObligation(repoRoot, tier, observation);
|
|
228
302
|
}
|
|
229
|
-
export function beatSupervision(repoRoot, tier, seat, observation) {
|
|
230
|
-
|
|
303
|
+
export function beatSupervision(repoRoot, tier, seat, observation, options = {}) {
|
|
304
|
+
// `armId` only NAMES a first legacy arm; an existing arm is never refused for a name mismatch —
|
|
305
|
+
// the recorded id is a UUID no operator can know, and a mismatch is not a stand-down.
|
|
306
|
+
if (isSeatTier(tier) && !seat?.trim()) {
|
|
307
|
+
throw new Error(`${tier} is a per-seat tier — a beat must declare the seat identity it speaks for`);
|
|
308
|
+
}
|
|
309
|
+
if (observation !== undefined)
|
|
310
|
+
validateObservation(observation);
|
|
311
|
+
let arm = options.arm ?? readArm(repoRoot, tier);
|
|
312
|
+
if (!arm) {
|
|
313
|
+
if (markerFence(repoRoot, tier) !== "NONE")
|
|
314
|
+
return observeWithoutBeat(repoRoot, tier, observation);
|
|
315
|
+
arm = newSupervisionArm(repoRoot, tier, options.armId ?? observation?.armId, true);
|
|
316
|
+
// A marker published during initial creation must not be acknowledged implicitly.
|
|
317
|
+
if (arm.markerFence !== "NONE")
|
|
318
|
+
return observeWithoutBeat(repoRoot, tier, observation);
|
|
319
|
+
}
|
|
320
|
+
const current = readArm(repoRoot, tier);
|
|
321
|
+
if (current?.armId !== arm.armId || current.armEpoch !== arm.armEpoch ||
|
|
322
|
+
markerFence(repoRoot, tier) !== arm.markerFence)
|
|
323
|
+
return observeWithoutBeat(repoRoot, tier, observation);
|
|
324
|
+
writeSupervisionBeat(repoRoot, tier, seat, arm.armId, observation, arm, options.loop);
|
|
325
|
+
// The immutable fence travels WITH the beat, so a rename racing stand-down cannot outrank it.
|
|
326
|
+
return markerFence(repoRoot, tier) === arm.markerFence;
|
|
231
327
|
}
|
|
232
328
|
// THE WATCHER-FACING ENTRY POINT — the loop SUPERVISION_BEAT_MS actually drives. A supervising seat
|
|
233
329
|
// calls this once at the top of its watch and holds the handle for the duration; a seat that dies,
|
|
@@ -348,11 +444,12 @@ function readBeat(repoRoot, tier) {
|
|
|
348
444
|
// is not evidence that nobody armed the tier). On a SEAT tier it is the opposite: a record naming no
|
|
349
445
|
// seat leaves the tier armed and unattributable, which reads as coverage no seat is providing, so
|
|
350
446
|
// it is UNREADABLE — something is there and no beat any reader can attribute comes out of it.
|
|
351
|
-
const { seat, armId } = beatMetadata(p);
|
|
447
|
+
const { seat, armId, markerFence } = beatMetadata(p);
|
|
352
448
|
if (isSeatTier(tier) && seat === undefined)
|
|
353
449
|
return "UNREADABLE";
|
|
354
450
|
return {
|
|
355
451
|
mtimeMs: st.mtimeMs,
|
|
452
|
+
...(markerFence !== undefined ? { markerFence } : {}),
|
|
356
453
|
...(seat !== undefined ? { seat } : {}),
|
|
357
454
|
...(armId !== undefined ? { armId } : {}),
|
|
358
455
|
};
|
|
@@ -363,7 +460,8 @@ function beatMetadata(path) {
|
|
|
363
460
|
const rec = JSON.parse(readFileSync(path, "utf8"));
|
|
364
461
|
const seat = typeof rec?.seat === "string" && rec.seat.trim() ? rec.seat : undefined;
|
|
365
462
|
const armId = typeof rec?.armId === "string" && rec.armId.trim() ? rec.armId : undefined;
|
|
366
|
-
|
|
463
|
+
const markerFence = typeof rec?.markerFence === "string" ? rec.markerFence : undefined;
|
|
464
|
+
return { ...(markerFence !== undefined ? { markerFence } : {}), ...(seat !== undefined ? { seat } : {}), ...(armId !== undefined ? { armId } : {}) };
|
|
367
465
|
}
|
|
368
466
|
catch {
|
|
369
467
|
return {};
|
|
@@ -414,8 +512,11 @@ function readStandDown(repoRoot, tier) {
|
|
|
414
512
|
return "UNREADABLE";
|
|
415
513
|
let seat;
|
|
416
514
|
let armId;
|
|
515
|
+
let fence;
|
|
417
516
|
try {
|
|
418
|
-
const
|
|
517
|
+
const bytes = readFileSync(p, "utf8");
|
|
518
|
+
fence = createHash("sha256").update(bytes).digest("hex");
|
|
519
|
+
const rec = JSON.parse(bytes);
|
|
419
520
|
if (rec?.tier !== tier)
|
|
420
521
|
return "UNREADABLE";
|
|
421
522
|
if (typeof rec.disarmedAt !== "string" || Number.isNaN(Date.parse(rec.disarmedAt)))
|
|
@@ -431,25 +532,22 @@ function readStandDown(repoRoot, tier) {
|
|
|
431
532
|
return "UNREADABLE";
|
|
432
533
|
} // unparseable or unreadable bytes — not a stand-down anyone can read
|
|
433
534
|
return {
|
|
434
|
-
mtimeMs: st.mtimeMs,
|
|
535
|
+
mtimeMs: st.mtimeMs, fence,
|
|
435
536
|
...(seat !== undefined ? { seat } : {}),
|
|
436
537
|
...(armId !== undefined ? { armId } : {}),
|
|
437
538
|
};
|
|
438
539
|
}
|
|
439
|
-
//
|
|
440
|
-
//
|
|
441
|
-
//
|
|
442
|
-
// armed-watcher identity is another arm, so a marker whose rename lost that race cannot mask a live
|
|
443
|
-
// watcher. Once that foreign beat is stale, a newer clean hand-off must win: otherwise overlapping
|
|
444
|
-
// boards closed in last-beater-first order would leave the tier reporting a death forever.
|
|
540
|
+
// CLI beats carry the marker generation acknowledged at arm time, never at tick time. A new
|
|
541
|
+
// marker dominates every tick of that arm regardless of rename order or beat mtime. The separate
|
|
542
|
+
// presence-based lifecycle retains overlapping watch owners and their last-owner stand-down.
|
|
445
543
|
export function supervisionStatus(repoRoot, tier, now = Date.now()) {
|
|
446
544
|
const beat = readBeat(repoRoot, tier);
|
|
447
545
|
const standDown = readStandDown(repoRoot, tier);
|
|
448
546
|
if (standDown === "UNREADABLE")
|
|
449
547
|
return withClearObligation(repoRoot, tier, { tier, state: "UNREADABLE" });
|
|
450
|
-
const beatOutranksStandDown = standDown !== "NONE" && typeof beat === "object" && (beat.
|
|
451
|
-
beat.armId !== undefined &&
|
|
452
|
-
|
|
548
|
+
const beatOutranksStandDown = standDown !== "NONE" && typeof beat === "object" && (beat.markerFence !== undefined ? beat.markerFence === standDown.fence :
|
|
549
|
+
beat.armId !== undefined && existsSync(supervisionPresencePath(repoRoot, tier, beat.armId)) && (beat.mtimeMs > standDown.mtimeMs || (now - beat.mtimeMs <= SUPERVISION_STALE_MS &&
|
|
550
|
+
standDown.armId !== undefined && beat.armId !== standDown.armId)));
|
|
453
551
|
if (standDown !== "NONE" && !beatOutranksStandDown) {
|
|
454
552
|
// the seat that stood down is named by the marker, falling back to whatever its last beat named
|
|
455
553
|
const seat = standDown.seat ?? (typeof beat === "object" ? beat.seat : undefined);
|
|
@@ -27,6 +27,10 @@ export interface EvidenceRow {
|
|
|
27
27
|
/** Durable artifact locations this row's detail names (e.g. a saved raw-review capture); empty
|
|
28
28
|
* when none were recorded — rendered as "missing", never silently omitted. */
|
|
29
29
|
readonly artifacts: readonly string[];
|
|
30
|
+
/** The row's execution-evidence receipt, each artifact resolved through the shared resolver against
|
|
31
|
+
* the run root it was minted in (`originRunRoot` for a reused verdict) — reference then verified
|
|
32
|
+
* availability; empty when the row carries no receipt. */
|
|
33
|
+
readonly receipts: readonly string[];
|
|
30
34
|
readonly taskId?: string;
|
|
31
35
|
readonly gate?: string;
|
|
32
36
|
}
|
|
@@ -34,7 +38,10 @@ export interface EvidenceRow {
|
|
|
34
38
|
export declare function parseArtifactLocations(details: string): string[];
|
|
35
39
|
/** Pure C2-journal-to-Evidence-rows mapping: the original journal position IS the evidence identity
|
|
36
40
|
* — assigned once here, from the full unfiltered event list, never recomputed from a display slice. */
|
|
37
|
-
export declare function deriveEvidenceJournal(eventsOrRows: readonly (JournalEvent | TrackedJournalRow)[], source?: string): EvidenceRow[];
|
|
41
|
+
export declare function deriveEvidenceJournal(eventsOrRows: readonly (JournalEvent | TrackedJournalRow)[], source?: string, runRoot?: string): EvidenceRow[];
|
|
42
|
+
/** The live cockpit names its journal by absolute path (`<state>/runs/<runId>/journal.jsonl`); that
|
|
43
|
+
* directory IS the run root. A relative or foreign source names no root — nothing is guessed. */
|
|
44
|
+
export declare function runRootOf(source: string | undefined): string | undefined;
|
|
38
45
|
/** The most recent review verdict recorded for a task — by original journal position, so a merged
|
|
39
46
|
* task's review opens the row it actually happened on rather than any on-screen index. */
|
|
40
47
|
export declare function selectTaskReview(journal: readonly EvidenceRow[], taskId: string): EvidenceRow | undefined;
|
|
@@ -42,6 +49,8 @@ export interface EvidenceViewInput {
|
|
|
42
49
|
readonly events?: readonly JournalEvent[];
|
|
43
50
|
readonly rows?: readonly TrackedJournalRow[];
|
|
44
51
|
readonly source?: string;
|
|
52
|
+
/** The displayed run's root (its journal directory); receipts minted by this run resolve under it. */
|
|
53
|
+
readonly runRoot?: string;
|
|
45
54
|
readonly costs?: readonly ChannelCost[];
|
|
46
55
|
/** Caller-supplied Report-tab text (e.g. from `renderMarkdownRecord`/`textReport`) — kept as a pure
|
|
47
56
|
* input so this leaf never reads config/telemetry itself. */
|