tickmarkr 2.1.6 → 2.1.7

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.
@@ -1,6 +1,6 @@
1
1
  import { createHash, randomBytes } from "node:crypto";
2
2
  import { shq } from "../adapters/types.js";
3
- import { appendFileSync, closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readlinkSync, readSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import { appendFileSync, closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, readSync, rmSync, statSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
6
6
  import { stringify } from "yaml";
@@ -15,7 +15,7 @@ import { herdrSealShellPrefix, SubprocessDriver } from "../drivers/subprocess.js
15
15
  import { formatOwnedName } from "../drivers/types.js";
16
16
  import { captureBaseline, detectGateCommands, detectVacuousOracles } from "../gates/baseline.js";
17
17
  import { runGates } from "../gates/run-gates.js";
18
- import { addEvidence, attributeBlocked, blockedTasks, getTask, graphDefinitionHash, loadGraph, pendingTasks, readyTasks, saveGraph, setStatus, taskContentDigest } from "../graph/graph.js";
18
+ import { addEvidence, attributeBlocked, blockedTasks, getTask, graphDefinitionHash, loadGraph, pendingTasks, readyTasks, saveGraph, setStatus, taskContentDigest, tickmarkrDir } from "../graph/graph.js";
19
19
  import { GATE_NAMES } from "../graph/schema.js";
20
20
  import { augmentRetryBrief, consult, renderRetryGuidance } from "./consult.js";
21
21
  import { runEnvironment } from "./environment.js";
@@ -23,7 +23,7 @@ import { cleanupRunWorktrees, gitHead, linkNodeModules, npmDependencyInstallComm
23
23
  import { runInteractiveSeed } from "./interactive-seed.js";
24
24
  import { activeRetryBan, classifyTaskFailure, classifyWorkerResultCause, deferredReviewFindings, engagementComparable, formatPriorFindingEvidence, GATE_FINGERPRINT_CAP, GATE_SATISFIED_RELEASE, identicalGateFailures, isDeferredFinding, journaledFailureBrief, Journal, loadRoutingProfile, newRunId, normalizeGateFailure, outstandingReviewFindings, pendingRepairFindings, phaseForGate, readPriorRunEvidence, recordedTaskFailureKind, renderStructuredReviewFinding, repairsSinceApproval, reviewRoundsSinceApproval, runHasEnded, structuredFindings, upheldFeedbackByTask } from "./journal.js";
25
25
  import { isDiffCapPark } from "../gates/review.js";
26
- import { acquireApprovalSerialization, acquireRunLock, releaseRunLock } from "./lock.js";
26
+ import { acquireApprovalSerialization, acquireRunLock, isPidLive, releaseRunLock } from "./lock.js";
27
27
  import { ensureIntegration, integrationBranch, integrationHead, mergeTask, verifyIntegrationTip } from "./merge.js";
28
28
  import { nextChannel, route } from "../route/router.js";
29
29
  import { desiredPanes } from "./reconcile.js";
@@ -764,6 +764,37 @@ function recordFatalRunEnd(journal, runId, branch, err) {
764
764
  console.error(`tickmarkr ${runId}: run crashed — no terminal record written; journal sink unwritable at ${journalPath} (${retryErr instanceof Error ? retryErr.message : String(retryErr)}) — original error: ${original}`);
765
765
  }
766
766
  }
767
+ // OBS-777: the fleet fold cannot distinguish an orphan from another repository's live worker. Give
768
+ // it one repository-scoped snapshot instead: terminal journals are ended, and an open lifecycle is
769
+ // ended only when the shared lock predicate can prove its last recorded daemon pid dead.
770
+ function endedRunIdsForReconcile(repoRoot) {
771
+ const ended = new Set();
772
+ const dir = join(tickmarkrDir(repoRoot), "runs");
773
+ if (!existsSync(dir))
774
+ return ended;
775
+ let runIds;
776
+ try {
777
+ runIds = readdirSync(dir);
778
+ }
779
+ catch {
780
+ return ended;
781
+ }
782
+ for (const runId of runIds) {
783
+ try {
784
+ const events = Journal.open(repoRoot, runId).read();
785
+ if (runHasEnded(events)) {
786
+ ended.add(runId);
787
+ continue;
788
+ }
789
+ const lifecycle = [...events].reverse().find((event) => (event.event === "run-start" || event.event === "run-resume")
790
+ && Number.isInteger(event.data.pid) && event.data.pid > 0);
791
+ if (lifecycle && !isPidLive(lifecycle.data.pid))
792
+ ended.add(runId);
793
+ }
794
+ catch { /* incomplete or foreign run directory — it proves nothing */ }
795
+ }
796
+ return ended;
797
+ }
767
798
  export async function runDaemon(repoRoot, opts = {}) {
768
799
  // v1.51 T2 / OBS-89 (v1.60): retired --quality env seam. Mode resolution owns premium routing;
769
800
  // route() no longer reads the retired env at all, so the old entrypoint scrub is gone with it.
@@ -781,6 +812,7 @@ export async function runDaemon(repoRoot, opts = {}) {
781
812
  // subprocess, so the optional-chain open below is a no-op there). Cosmetic-only: any failure is
782
813
  // swallowed (never affects the run); the operator closes a surviving watch pane.
783
814
  const lock = acquireRunLock(repoRoot, runId);
815
+ const endedRunIds = endedRunIdsForReconcile(repoRoot); // one snapshot for every sweep this caller makes
784
816
  // D10: the lock is this daemon's liveness record and already carries its pid; status prints that
785
817
  // identity beside the supervision row. The `orchestrator` tier belongs exclusively to the seated
786
818
  // supervisor, so a run never beats or stands down that seat's record on the daemon's behalf.
@@ -878,7 +910,7 @@ export async function runDaemon(repoRoot, opts = {}) {
878
910
  // Termination (SIGINT/SIGTERM): record the daemon-controlled exit before closing every live slot,
879
911
  // reconcile owned panes against an EMPTY
880
912
  // desired set (herdr panes not in memory; panesToClose spares foreign names, watch panes, and
881
- // other runs' panes by construction), release the run lock, then exit. There is still no run-end,
913
+ // live/unknown other runs' panes by construction), release the run lock, then exit. There is still no run-end,
882
914
  // so stop-amend-resume keeps resuming; exit-cause distinguishes this deliberate stop from an
883
915
  // observer-classified abrupt death. keepPanes:"forever" (the
884
916
  // keep-everything debug override) preserves panes but still releases the lock and exits.
@@ -907,7 +939,7 @@ export async function runDaemon(repoRoot, opts = {}) {
907
939
  catch { /* cosmetic — reconcile is the backstop */ }
908
940
  }
909
941
  try {
910
- await driver.reconcile?.(new Set(), runId);
942
+ await driver.reconcile?.(new Set(), runId, { endedRunIds });
911
943
  }
912
944
  catch { /* cosmetic — visibility is never a gate */ }
913
945
  }
@@ -1093,7 +1125,7 @@ export async function runDaemon(repoRoot, opts = {}) {
1093
1125
  // herdr's watches bookkeeping lives in close(), and a raw pane-close in the sweep would
1094
1126
  // leave narrator() a stale cache) — the driver always sees it as desired; its lifecycle is
1095
1127
  // decided here from the fold alone.
1096
- await driver.reconcile?.(new Set([...desired, watchName]), runId, opts);
1128
+ await driver.reconcile?.(new Set([...desired, watchName]), runId, { ...opts, endedRunIds });
1097
1129
  // OBS-103: when the fold retires the watch (run-end boundary), close the narrator. The
1098
1130
  // decision keys on the run identity in the pane name — narrator() adopts a prior daemon
1099
1131
  // instance's pane under the same owned name, so a stop→resume cycle's leftover narrator
@@ -1109,7 +1141,10 @@ export async function runDaemon(repoRoot, opts = {}) {
1109
1141
  /* cosmetic — visibility is never a gate */
1110
1142
  }
1111
1143
  };
1112
- await reconcile(); // run start/resume boundary: nothing in flight — full sweep, incl. older runs' leftovers
1144
+ // run start/resume boundary: nothing in flight, so the sweep takes this run's judge/review/consult
1145
+ // panes too. OBS-777: the one startup snapshot lets it reclaim only older runs proven ended, while
1146
+ // every live or unknown run remains spared.
1147
+ await reconcile();
1113
1148
  // v1.4 self-reference guard: a random nonce on the worker trailer AND exit marker. Displayed
1114
1149
  // source/diffs (e.g. a worker editing tickmarkr's own prompt.ts/daemon.ts) can't know it, so an echoed
1115
1150
  // TICKMARKR_RESULT/TICKMARKR_EXIT literal can never premature-harvest the worker. Quote-split keeps the
@@ -7,6 +7,7 @@ import { stateDirName, taskContentDigest, tickmarkrDir } from "../graph/graph.js
7
7
  import { GATE_NAMES, TIERS } from "../graph/schema.js";
8
8
  import { buildProfile, classify } from "../route/profile.js";
9
9
  import { DecisionEventSchema, trackJournalRows, } from "./protocol.js";
10
+ import { normalizeGateOutcome } from "./outcome.js";
10
11
  import { redactSecrets } from "./redact.js";
11
12
  export function phaseForGate(gate) {
12
13
  if (gate === "acceptance")
@@ -15,6 +16,23 @@ export function phaseForGate(gate) {
15
16
  return "review";
16
17
  return `gate:${gate}`;
17
18
  }
19
+ /** The pipe projects the same normalized gate outcome as the TTY rail. The selected-test field only
20
+ * chooses the held outcome's operator noun after the accessor has classified it; it is not a second
21
+ * verdict read. */
22
+ const journalGateDetail = (data) => {
23
+ if (typeof data.gate !== "string")
24
+ return undefined;
25
+ switch (normalizeGateOutcome(data).kind) {
26
+ case "passed":
27
+ return `${data.gate} passed`;
28
+ case "failed":
29
+ return `${data.gate} failed`;
30
+ case "held":
31
+ return Array.isArray(data.selectedTests) ? `${data.gate} selected-test screen` : `${data.gate} held`;
32
+ default:
33
+ return data.gate;
34
+ }
35
+ };
18
36
  export function formatJournalNarration({ event, taskId, data }) {
19
37
  const assignment = data.assignment;
20
38
  const direct = [data.summary, data.reason, data.error, data.step, data.action, data.lint, data.branch, data.from]
@@ -26,7 +44,9 @@ export function formatJournalNarration({ event, taskId, data }) {
26
44
  ? `${data.gate} failed${typeof data.lastMergedTask === "string" ? ` after ${data.lastMergedTask}` : ""}`
27
45
  : event === "tip-verify"
28
46
  ? `${data.gate} passed`
29
- : `${data.gate}${data.pass === true ? " passed" : data.pass === false ? " failed" : ""}`
47
+ : event === "gate-result"
48
+ ? journalGateDetail(data)
49
+ : `${data.gate}`
30
50
  : typeof data.code === "number" ? `exit ${data.code}`
31
51
  : typeof data.pid === "number" ? `pid ${data.pid}`
32
52
  : typeof data.baseRef === "string" ? `base ${data.baseRef.slice(0, 12)}`
@@ -88,7 +88,14 @@ export function normalizeGateOutcome(source) {
88
88
  return { kind: "unavailable", reason: `malformed gate result: expected an object, read ${shape}` };
89
89
  }
90
90
  const row = source;
91
- // `kind` selects the canonical format. It must validate as exactly one canonical arm without any
91
+ // A gate-result data wrapper states its canonical verdict in `outcome`. Consumers may pass either
92
+ // the wrapper or the outcome itself; both must read the same kind even if stale bare fields remain.
93
+ if (hasOwn(row, "outcome")) {
94
+ if (isGateOutcome(row.outcome))
95
+ return row.outcome;
96
+ return { kind: "unavailable", reason: reasonOf(row, "malformed gate result: invalid explicit outcome") };
97
+ }
98
+ // `kind` selects the canonical outcome object. It must validate as exactly one canonical arm without any
92
99
  // legacy truth discriminator; otherwise continuing through the legacy branches could reinterpret a
93
100
  // contradictory dual-write as passed, failed or infra. Mixed and malformed canonical rows stay
94
101
  // explicitly unavailable, retaining any reason/details the producer did manage to state.
@@ -3,6 +3,8 @@ export declare const SUPERVISION_BEAT_MS = 10000;
3
3
  /** Ceiling before a beat reads STALE: SIX beats, lock.ts's ratio — five may be missed before alarm. */
4
4
  export declare const SUPERVISION_STALE_MS: number;
5
5
  export declare const SUPERVISION_FUTURE_GRACE_MS = 1000;
6
+ /** Context watchers act at 75% unless their invocation declares another threshold. */
7
+ export declare const SUPERVISION_DEFAULT_THRESHOLD_PCT = 75;
6
8
  export declare const SUPERVISION_TIERS: readonly ["orchestrator", "orchestrator-context", "overseer", "overseer-context", "watch"];
7
9
  export type SupervisionTier = (typeof SUPERVISION_TIERS)[number];
8
10
  export declare const SUPERVISION_SEAT_TIERS: readonly ["orchestrator", "orchestrator-context", "overseer", "overseer-context"];
@@ -17,16 +19,28 @@ export interface TierLiveness {
17
19
  beatAgeMs?: number;
18
20
  /** The seat the record names, when it names one. Always present on a seat tier that is not ABSENT. */
19
21
  seat?: string;
22
+ /** The alarm's durable duty, orthogonal to whether its watcher is armed, stale or stood down. */
23
+ clearOwedSince?: string;
24
+ /** The latch exists but cannot be decoded; never mistaken for no duty owed. */
25
+ clearOwedUnreadable?: true;
26
+ }
27
+ /** A watcher observation that can raise or discharge the seat's clear obligation. */
28
+ export interface SupervisionBeatObservation {
29
+ armId: string;
30
+ pct: number;
31
+ thresholdPct: number;
20
32
  }
21
33
  export declare const supervisionBeatPath: (repoRoot: string, tier: SupervisionTier) => string;
22
34
  /** Where a watcher records that it STOOD DOWN. Its own file: the beat keeps meaning only "alive". */
23
35
  export declare const supervisionStandDownPath: (repoRoot: string, tier: SupervisionTier) => string;
24
- export declare function beatSupervision(repoRoot: string, tier: SupervisionTier, seat?: string): void;
36
+ export declare function beatSupervision(repoRoot: string, tier: SupervisionTier, seat?: string, observation?: SupervisionBeatObservation): void;
25
37
  /** Handle a watcher holds for as long as it is supervising; disarm stands it down and is idempotent. */
26
38
  export interface ArmedSupervision {
27
39
  disarm: () => void;
28
40
  }
29
41
  export declare function armSupervision(repoRoot: string, tier: SupervisionTier, beatMs?: number, seat?: string): ArmedSupervision;
42
+ /** Arm the live status board's own tier through the normal supervision writer and lifecycle. */
43
+ export declare function armWatchSupervision(repoRoot: string, beatMs?: number): ArmedSupervision;
30
44
  export declare function readTierLiveness(repoRoot: string, tier: SupervisionTier, now?: number): TierLiveness;
31
45
  export declare function supervisionStatus(repoRoot: string, tier: SupervisionTier, now?: number): TierLiveness;
32
46
  /** Every KNOWN tier, always — a tier omitted from this list would read as one that is fine. */
@@ -14,8 +14,8 @@ import { stateDirName, tickmarkrDir } from "../graph/graph.js";
14
14
  //
15
15
  // SUP-02: the beat mtime is the ONLY input. Nothing here reads a process table and nothing matches a
16
16
  // process name — a poll-grep watcher carries `grep` in its own argv, so the filter that removes the
17
- // probing grep removes the watched one. The payload records a pid for an OPERATOR to read off a STALE
18
- // record; the derivation never consults it, so a reused, dead or unreadable pid changes no state.
17
+ // probing grep removes the watched one. The payload's exitedWriterPid identifies the one-shot writer
18
+ // for an OPERATOR reading a STALE record; no derivation consults it, so its value changes no state.
19
19
  // Zero new deps — node:fs stdlib, exactly as lock.ts.
20
20
  /** How often a watcher rewrites its own tier's beat. */
21
21
  export const SUPERVISION_BEAT_MS = 10_000;
@@ -27,6 +27,8 @@ export const SUPERVISION_STALE_MS = 6 * SUPERVISION_BEAT_MS;
27
27
  // millisecond into the future. A second of slack covers even a coarse filesystem. Anything past it
28
28
  // is SKEW, and skew is the one direction this instrument may not fail in: see readTierLiveness.
29
29
  export const SUPERVISION_FUTURE_GRACE_MS = 1_000;
30
+ /** Context watchers act at 75% unless their invocation declares another threshold. */
31
+ export const SUPERVISION_DEFAULT_THRESHOLD_PCT = 75;
30
32
  // The supervision seats this harness has. An unlisted tier is an INVISIBLE tier, which is the failure
31
33
  // mode itself — an auditor read "no watchers were ever armed" off a surface that named none. Adding a
32
34
  // seat means adding it here, and `status` then renders it whether or not it has ever beaten.
@@ -55,6 +57,8 @@ const supervisionDir = (repoRoot) => join(repoRoot, stateDirName(repoRoot), "sup
55
57
  export const supervisionBeatPath = (repoRoot, tier) => join(supervisionDir(repoRoot), `${tier}.beat`);
56
58
  /** Where a watcher records that it STOOD DOWN. Its own file: the beat keeps meaning only "alive". */
57
59
  export const supervisionStandDownPath = (repoRoot, tier) => join(supervisionDir(repoRoot), `${tier}.standdown`);
60
+ /** The independent latch a stand-down cannot overwrite or remove. */
61
+ const supervisionObligationPath = (repoRoot, tier) => join(supervisionDir(repoRoot), `${tier}.clear-owed`);
58
62
  // SUP-06: PRESENCE — one file per ARMED WATCHER, because a tier may legitimately have more than one.
59
63
  // Two boards watch one repo the moment an operator opens a second pane, and the tier is armed while
60
64
  // EITHER of them lives. The stand-down marker speaks for the whole tier, so the first board out
@@ -93,25 +97,102 @@ function stalePeersIfLast(repoRoot, tier, id, now = Date.now()) {
93
97
  }
94
98
  return stale;
95
99
  }
100
+ /** Read the latch without creating, touching or repairing it. */
101
+ function readClearObligation(repoRoot, tier) {
102
+ const p = supervisionObligationPath(repoRoot, tier);
103
+ let st;
104
+ try {
105
+ st = statSync(p);
106
+ }
107
+ catch (e) {
108
+ const code = e.code;
109
+ return code === "ENOENT" || code === "ENOTDIR" ? "NONE" : "UNREADABLE";
110
+ }
111
+ if (!st.isFile())
112
+ return "UNREADABLE";
113
+ try {
114
+ const rec = JSON.parse(readFileSync(p, "utf8"));
115
+ if (rec?.tier !== tier)
116
+ return "UNREADABLE";
117
+ if (typeof rec.clearOwedSince !== "string" || Number.isNaN(Date.parse(rec.clearOwedSince)))
118
+ return "UNREADABLE";
119
+ if (typeof rec.armId !== "string" || !rec.armId.trim())
120
+ return "UNREADABLE";
121
+ if (typeof rec.thresholdPct !== "number" || !Number.isFinite(rec.thresholdPct)
122
+ || rec.thresholdPct < 0 || rec.thresholdPct > 100)
123
+ return "UNREADABLE";
124
+ return { clearOwedSince: rec.clearOwedSince, armId: rec.armId, thresholdPct: rec.thresholdPct };
125
+ }
126
+ catch {
127
+ return "UNREADABLE";
128
+ }
129
+ }
130
+ /** Publish a crossing atomically; a firing replacement inherits the original duty's instant. */
131
+ function raiseClearObligation(repoRoot, tier, armId, thresholdPct) {
132
+ const existing = readClearObligation(repoRoot, tier);
133
+ if (typeof existing === "object" && existing.armId === armId)
134
+ return;
135
+ if (existing === "UNREADABLE") {
136
+ throw new Error(`${tier} clear obligation is unreadable — refusing to overwrite a duty that may still be owed`);
137
+ }
138
+ const p = supervisionObligationPath(repoRoot, tier);
139
+ const tmp = `${p}.${process.pid}.${randomUUID()}.tmp`;
140
+ mkdirSync(dirname(p), { recursive: true });
141
+ writeFileSync(tmp, JSON.stringify({
142
+ tier, armId, thresholdPct,
143
+ clearOwedSince: typeof existing === "object" ? existing.clearOwedSince : new Date().toISOString(),
144
+ }) + "\n");
145
+ renameSync(tmp, p);
146
+ }
147
+ /** Only a different arm observed below the firing threshold proves the old seat was cleared. */
148
+ function dischargeClearObligation(repoRoot, tier, observation) {
149
+ const existing = readClearObligation(repoRoot, tier);
150
+ if (existing === "UNREADABLE") {
151
+ throw new Error(`${tier} clear obligation is unreadable — refusing to erase a duty that may still be owed`);
152
+ }
153
+ if (typeof existing === "object" && existing.armId !== observation.armId
154
+ && observation.pct < existing.thresholdPct) {
155
+ rmSync(supervisionObligationPath(repoRoot, tier), { force: true });
156
+ }
157
+ }
158
+ function validateObservation(observation) {
159
+ if (!observation.armId.trim())
160
+ throw new Error("a supervision observation needs a non-empty arm identity");
161
+ for (const [name, value] of [["pct", observation.pct], ["threshold-pct", observation.thresholdPct]]) {
162
+ if (!Number.isFinite(value) || value < 0 || value > 100) {
163
+ throw new Error(`--${name} must be a number from 0 through 100`);
164
+ }
165
+ }
166
+ }
96
167
  // WRITER — a watcher's own call, on its own tier, every SUPERVISION_BEAT_MS. Never a reader's: the
97
168
  // purity fence (status --watch leaves the state dir byte-identical) is the test that catches a reader
98
169
  // that beats on the watcher's behalf, which would report every dead tier as healthy.
99
- function writeSupervisionBeat(repoRoot, tier, seat, armId) {
170
+ function writeSupervisionBeat(repoRoot, tier, seat, armId, observation) {
100
171
  // A seat tier may not be armed anonymously, and the refusal belongs HERE rather than only in the
101
172
  // verb: any caller that could write a seatless record could arm a tier nobody occupies.
102
173
  if (isSeatTier(tier) && !seat?.trim()) {
103
174
  throw new Error(`${tier} is a per-seat tier — a beat must declare the seat identity it speaks for`);
104
175
  }
176
+ if (observation !== undefined)
177
+ validateObservation(observation);
105
178
  tickmarkrDir(repoRoot); // the write path DOES create — beats land inside the gitignored state dir
106
179
  const p = supervisionBeatPath(repoRoot, tier);
107
180
  mkdirSync(dirname(p), { recursive: true });
181
+ // Raise before the beat so a later beat failure cannot hide a duty; discharge only after the
182
+ // below-threshold observation exists on disk.
183
+ if (observation !== undefined && observation.pct >= observation.thresholdPct) {
184
+ raiseClearObligation(repoRoot, tier, observation.armId, observation.thresholdPct);
185
+ }
108
186
  writeFileSync(p, JSON.stringify({
109
187
  tier, ...(seat ? { seat } : {}), ...(armId ? { armId } : {}),
110
- pid: process.pid, beatAt: new Date().toISOString(),
188
+ ...(observation !== undefined ? { pct: observation.pct, thresholdPct: observation.thresholdPct } : {}),
189
+ exitedWriterPid: process.pid, beatAt: new Date().toISOString(),
111
190
  }) + "\n");
191
+ if (observation !== undefined)
192
+ dischargeClearObligation(repoRoot, tier, observation);
112
193
  }
113
- export function beatSupervision(repoRoot, tier, seat) {
114
- writeSupervisionBeat(repoRoot, tier, seat);
194
+ export function beatSupervision(repoRoot, tier, seat, observation) {
195
+ writeSupervisionBeat(repoRoot, tier, seat, undefined, observation);
115
196
  }
116
197
  // THE WATCHER-FACING ENTRY POINT — the loop SUPERVISION_BEAT_MS actually drives. A supervising seat
117
198
  // calls this once at the top of its watch and holds the handle for the duration; a seat that dies,
@@ -138,7 +219,7 @@ export function armSupervision(repoRoot, tier, beatMs = SUPERVISION_BEAT_MS, sea
138
219
  }
139
220
  catch { /* uncleared: the reader validates the marker and a newer beat outranks it — never masked */ }
140
221
  // This watcher's own identity fences BOTH its presence and its stand-down against every later arm.
141
- // pid alone collides between two boards in one host (and after pid reuse); a UUID never aliases the
222
+ // A process id alone collides between two boards in one host (and after reuse); a UUID never aliases the
142
223
  // stale presence of a killed process that a later last-one-out cleanup may already have observed.
143
224
  const id = `${process.pid}.${randomUUID()}`;
144
225
  const presence = supervisionPresencePath(repoRoot, tier, id);
@@ -146,7 +227,7 @@ export function armSupervision(repoRoot, tier, beatMs = SUPERVISION_BEAT_MS, sea
146
227
  const mark = () => {
147
228
  try {
148
229
  writeSupervisionBeat(repoRoot, tier, seat, id); // creates the directory presence is written into
149
- writeFileSync(presence, JSON.stringify({ tier, pid: process.pid, id }) + "\n");
230
+ writeFileSync(presence, JSON.stringify({ tier, exitedWriterPid: process.pid, id }) + "\n");
150
231
  }
151
232
  catch { /* repo gone / disk full / no seat — the tier ages out rather than crashing its watcher */ }
152
233
  };
@@ -182,7 +263,7 @@ export function armSupervision(repoRoot, tier, beatMs = SUPERVISION_BEAT_MS, sea
182
263
  mkdirSync(dirname(p), { recursive: true });
183
264
  writeFileSync(tmp, JSON.stringify({
184
265
  tier, ...(seat ? { seat } : {}), armId: id,
185
- pid: process.pid, disarmedAt: new Date().toISOString(),
266
+ exitedWriterPid: process.pid, disarmedAt: new Date().toISOString(),
186
267
  }) + "\n");
187
268
  renameSync(tmp, p);
188
269
  }
@@ -198,6 +279,10 @@ export function armSupervision(repoRoot, tier, beatMs = SUPERVISION_BEAT_MS, sea
198
279
  },
199
280
  };
200
281
  }
282
+ /** Arm the live status board's own tier through the normal supervision writer and lifecycle. */
283
+ export function armWatchSupervision(repoRoot, beatMs = SUPERVISION_BEAT_MS) {
284
+ return armSupervision(repoRoot, "watch", beatMs);
285
+ }
201
286
  // BEAT DERIVATION — pure, and the only thing that reads the beat. One statSync: never creates,
202
287
  // touches or reaps the record it reports on, and never creates the directory that holds it. ONLY a
203
288
  // missing path is ABSENT: ENOENT (no beat file) and ENOTDIR (nothing that could hold one) mean no
@@ -206,7 +291,7 @@ export function armSupervision(repoRoot, tier, beatMs = SUPERVISION_BEAT_MS, sea
206
291
  // never silently ARMED. Callers wanting the TIER's state want supervisionStatus below; this answers
207
292
  // the narrower question "does the beat say alive", which is all a beat can ever say.
208
293
  export function readTierLiveness(repoRoot, tier, now = Date.now()) {
209
- return beatLiveness(tier, readBeat(repoRoot, tier), now);
294
+ return withClearObligation(repoRoot, tier, beatLiveness(tier, readBeat(repoRoot, tier), now));
210
295
  }
211
296
  // The beat's inode, or why there is no age to derive from it. Split out so the stand-down ranking below
212
297
  // reads the SAME mtime this derivation does rather than a second, later stat of a moving record.
@@ -266,6 +351,15 @@ function beatLiveness(tier, beat, now) {
266
351
  const beatAgeMs = Math.max(0, age); // inside the grace: the two clocks' resolutions, not skew
267
352
  return { tier, state: beatAgeMs > SUPERVISION_STALE_MS ? "STALE" : "ARMED", beatAgeMs, ...named };
268
353
  }
354
+ /** Add the independent duty without replacing or reinterpreting the watcher's state. */
355
+ function withClearObligation(repoRoot, tier, liveness) {
356
+ const obligation = readClearObligation(repoRoot, tier);
357
+ if (obligation === "NONE")
358
+ return liveness;
359
+ return obligation === "UNREADABLE"
360
+ ? { ...liveness, clearOwedUnreadable: true }
361
+ : { ...liveness, clearOwedSince: obligation.clearOwedSince };
362
+ }
269
363
  // A stand-down is only what a watcher RECORDED, so the record has to READ as one: a regular file whose
270
364
  // payload names this tier and the instant it stood down. Path existence is not proof — a directory, a
271
365
  // torn write or a stray file at that path says nothing about any watcher, and calling one of those a
@@ -317,15 +411,17 @@ export function supervisionStatus(repoRoot, tier, now = Date.now()) {
317
411
  const beat = readBeat(repoRoot, tier);
318
412
  const standDown = readStandDown(repoRoot, tier);
319
413
  if (standDown === "UNREADABLE")
320
- return { tier, state: "UNREADABLE" };
414
+ return withClearObligation(repoRoot, tier, { tier, state: "UNREADABLE" });
321
415
  const beatOutranksStandDown = standDown !== "NONE" && typeof beat === "object" && (beat.mtimeMs > standDown.mtimeMs || (now - beat.mtimeMs <= SUPERVISION_STALE_MS &&
322
416
  beat.armId !== undefined && standDown.armId !== undefined && beat.armId !== standDown.armId));
323
417
  if (standDown !== "NONE" && !beatOutranksStandDown) {
324
418
  // the seat that stood down is named by the marker, falling back to whatever its last beat named
325
419
  const seat = standDown.seat ?? (typeof beat === "object" ? beat.seat : undefined);
326
- return { tier, state: "DISARMED", ...(seat !== undefined ? { seat } : {}) };
420
+ return withClearObligation(repoRoot, tier, {
421
+ tier, state: "DISARMED", ...(seat !== undefined ? { seat } : {}),
422
+ });
327
423
  }
328
- return beatLiveness(tier, beat, now);
424
+ return withClearObligation(repoRoot, tier, beatLiveness(tier, beat, now));
329
425
  }
330
426
  /** Every KNOWN tier, always — a tier omitted from this list would read as one that is fine. */
331
427
  export const readSupervision = (repoRoot, now = Date.now()) => SUPERVISION_TIERS.map((tier) => supervisionStatus(repoRoot, tier, now));
@@ -333,4 +429,6 @@ export const readSupervision = (repoRoot, now = Date.now()) => SUPERVISION_TIERS
333
429
  // The seat is rendered BESIDE the state, never instead of it: `overseer-context ARMED (w3:p2)` says
334
430
  // both that something is beating and who is behind it, which is the pair an operator needs to act. A
335
431
  // row with no seat to name renders exactly as it always did.
336
- export const supervisionText = (tiers, divider = " · ") => `supervision: ${tiers.map((t) => `${t.tier} ${t.state}${t.seat ? ` (${t.seat})` : ""}`).join(divider)}`;
432
+ export const supervisionText = (tiers, divider = " · ") => `supervision: ${tiers.map((t) => `${t.tier} ${t.state}${t.seat ? ` (${t.seat})` : ""}` +
433
+ `${t.clearOwedSince ? ` CLEAR-OWED since ${t.clearOwedSince}` : ""}` +
434
+ `${t.clearOwedUnreadable ? " CLEAR-OWED unreadable" : ""}`).join(divider)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tickmarkr",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "Spec in, verified work out.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -45,7 +45,8 @@ Before `tickmarkr compile` or `tickmarkr run`, compare the installed binary agai
45
45
 
46
46
  1. Run `tickmarkr version` (one line, machine-parseable).
47
47
  2. Read the `version` field from the repository's `package.json`.
48
- 3. If the binary and repository do not **agree on the entire version** (including the patch; e.g. binary `2.1.0` vs repo `2.1.1`), **stop immediately** and tell the operator to update the global install (`npm i -g tickmarkr@latest`) or link the repo binary. Do not compile, plan, or run on hope.
48
+ 3. If the binary and repository do not **agree on the entire version** (including the patch; e.g. binary `2.1.0` vs repo `2.1.1`), **stop immediately** and tell the operator to update the global install (`npm i -g tickmarkr@latest`), or to install this repository's build as a REAL COPY — `npm pack`, then `npm i -g ./<tarball>`. Do not compile, plan, or run on hope.
49
+ > ⚠ **Never `npm i -g .` on the repository directory, and never link it.** npm SYMLINKS a directory install, which makes the working tree itself the machine-wide binary: every later build — including a gate's own `npm run build` — silently hot-swaps the CLI for every repository on the machine, with no version change to notice it by. Measured 2026-08-29: a verify build gate rewrote the shared binary while another repository's daemon was mid-run against it, and a positive control that rebuilds at a pre-fix ref would have installed the very defect it was proving fixed, machine-wide (OBS-771). Verify an install by comparing the global and repo **inodes** — they must DIFFER — never by `tickmarkr version`, which cannot go red when nothing is bumped.
49
50
 
50
51
  A stale binary silently skips daemon gates shipped in newer releases — the v1.38 run exposed this when a global `1.36.0` binary missed the daemon tip-verify gate entirely (OBS-38). Preflight failure is always stop-and-report; never proceed-and-hope.
51
52
 
@@ -40,7 +40,8 @@ Before `tickmarkr compile` or `tickmarkr run`, compare the installed binary agai
40
40
 
41
41
  1. Run `tickmarkr version` (one line, machine-parseable).
42
42
  2. Read the `version` field from the repository's `package.json`.
43
- 3. If the binary and repository do not **agree on the entire version** (including the patch; e.g. binary `2.1.0` vs repo `2.1.1`), **stop immediately** and tell the operator to update the global install (`npm i -g tickmarkr@latest`) or link the repo binary. Do not compile, plan, or run on hope.
43
+ 3. If the binary and repository do not **agree on the entire version** (including the patch; e.g. binary `2.1.0` vs repo `2.1.1`), **stop immediately** and tell the operator to update the global install (`npm i -g tickmarkr@latest`), or to install this repository's build as a REAL COPY — `npm pack`, then `npm i -g ./<tarball>`. Do not compile, plan, or run on hope.
44
+ > ⚠ **Never `npm i -g .` on the repository directory, and never link it.** npm SYMLINKS a directory install, which makes the working tree itself the machine-wide binary: every later build — including a gate's own `npm run build` — silently hot-swaps the CLI for every repository on the machine, with no version change to notice it by. Measured 2026-08-29: a verify build gate rewrote the shared binary while another repository's daemon was mid-run against it, and a positive control that rebuilds at a pre-fix ref would have installed the very defect it was proving fixed, machine-wide (OBS-771). Verify an install by comparing the global and repo **inodes** — they must DIFFER — never by `tickmarkr version`, which cannot go red when nothing is bumped.
44
45
 
45
46
  A stale binary silently skips daemon gates shipped in newer releases — the v1.38 run exposed this when a global `1.36.0` binary missed the daemon tip-verify gate entirely (OBS-38). Preflight failure is always stop-and-report; never proceed-and-hope.
46
47
 
@@ -60,6 +60,11 @@ through brief lineage. **An executor choice nobody made is still an executor cho
60
60
  OPERATOR LAYOUT/CONVENTION rather than a shipped milestone — names like `*-discipline`, `*-drill`,
61
61
  `*-parity`, `*-least-permission`, `context-reset-*`, `consults-*`, `agent-*`, `*-tab-layout`,
62
62
  `*-visible-*`, `*-panes*`, `user-tabs-*`.
63
+ **A standing instruction carries its revocation premise.** Every standing rule you lift from memory,
64
+ handoff or a live correction states the premise that makes it true and the concrete observation that
65
+ would falsify that premise and revoke the rule. If you cannot name the falsifier, you have written a
66
+ preference, not standing supervision law. When the falsifier arrives, retire or amend the rule in the
67
+ shipped skill in the same act; do not leave successors to obey a rule whose reason is already false.
63
68
  **Earned 2026-08-04, expensively.** That directory held `…-falsification-drill-discipline.md`, written
64
69
  three weeks earlier: *"a gate or grep-pin is assumed WRONG until a falsification drill proves it bites…
65
70
  run the drill that should redden it and SEE the red before trusting green."* That is Evidence discipline
@@ -565,6 +570,10 @@ cleared, re-briefed, or replaced keeps beating that tier's file forever. Measure
565
570
  **three-hour window in which no orchestrator was alive**, and it would have silently re-armed a
566
571
  recorded stand-down within 10 seconds. On the same sweep the overseer tier had **three** beat loops,
567
572
  one owned by an unrelated session. So:
573
+ - **Split the liveness reads.** A tier's liveness is read from beat freshness in the repository status
574
+ path; a loop's liveness is read from the live process payload that is emitting that beat (`tickmarkr
575
+ beat <tier> --seat <seat>` in this repo). Neither liveness claim is read from a recorded pid: a pid
576
+ recorded earlier can be stale, reused, or detached from the beat now holding the tier green.
568
577
  - **At every adopt, clear, or re-brief, sweep for pre-existing loops on YOUR tier before arming one**
569
578
  (`pgrep -f "tickmarkr beat <tier>"`), trace each to its parent session, and kill the **loop only**
570
579
  — never the parent — then verify the parent survived.
@@ -20,15 +20,15 @@
20
20
  # than absent. Four rules the shipped version broke, each of which made the tier lie:
21
21
  # 1. BEAT ON THE SUPERVISION CADENCE, NOT ON THE POLL. Beats gap by TICK (below), never by POLL, so a
22
22
  # poll interval above the supervision beat interval cannot leave the tier stale half of every cycle.
23
- # 2. BEAT ONLY AFTER A SUCCESSFUL READ. A watcher that cannot see its seat's percentage is not
24
- # watching it; beating anyway reports coverage it is not providing, and the tier must age out.
23
+ # 2. BEAT AFTER EVERY SUCCESSFUL SCREEN READ. A missing percentage is an explicit UNREADABLE
24
+ # observation: it must keep the live watcher armed but can never reach warn or act. Only a failed
25
+ # screen read withholds the beat, because then the watcher cannot see its seat at all.
25
26
  # 3. WARN DOES NOT EXIT. Warn precedes act, so exiting at warn meant the act was never reached and the
26
27
  # last beat aged into a permanent stale — gradual growth never reached the auto-clear path at all.
27
28
  # 4. EVERY TERMINAL EXIT STANDS THE TIER DOWN, so a watcher that finished reads DISARMED, not dead.
28
29
  # Only a killed watcher reads STALE, which is exactly what STALE means.
29
- # 5. A BLIND READ ALARMS (OBS-739). Ageing the tier is visible only to someone already reading the beat
30
- # table; the seat that armed this watcher must be TOLD its instrument went blind. Silence and health
31
- # must never look alike.
30
+ # 5. AN UNREADABLE FIELD REPORTS ITSELF (OBS-739/780). Silence, health and a trustworthy percentage
31
+ # are three different states. UNREADABLE stays supervised but never authorises a destructive act.
32
32
  #
33
33
  # usage: watch-context.sh <role-slug> <agent|pane> <warn-pct> <act-pct> [handoff-file] [poll-s] [cap-s]
34
34
  # <role-slug> is ANY seat role — orchestrator, overseer, surgeon, consult — and names the tier
@@ -63,8 +63,8 @@ TIER="${ROLE}-context"
63
63
 
64
64
 
65
65
  # The supervision beat interval (SUPERVISION_BEAT_MS = 10s). The loop ticks at the beat cadence or the
66
- # caller's poll, whichever is SHORTER: a beat may only follow a successful read (rule 2), so the read
67
- # cadence is the floor on the beat cadence, and the tier's freshness is never the caller's to widen.
66
+ # caller's poll, whichever is SHORTER. Every successful screen read beats; its result is either a
67
+ # percentage safe to compare or the explicit UNREADABLE state.
68
68
  BEAT_EVERY=5
69
69
  TICK=$(( POLL < BEAT_EVERY ? POLL : BEAT_EVERY ))
70
70
  [ "$TICK" -ge 1 ] 2>/dev/null || TICK=1 # a zero or junk poll would spin, not watch
@@ -100,16 +100,18 @@ stand_down() { tickmarkr beat "$TIER" --stand-down --seat "$SEAT" >/dev/null 2>&
100
100
  # record the hand-off. A killed watcher never runs it, which is the one case that must read STALE.
101
101
  trap stand_down EXIT
102
102
 
103
- # The seat's own rendered truth. Prefer a line carrying a context marker so a percentage elsewhere on
104
- # screen cannot be mistaken for the gauge — but NEVER require one: the ✳ marker the shipped version
105
- # anchored on is rendered by a single vendor, so every other seat read empty, beat anyway and slept to
106
- # its cap while its tier claimed coverage. The last percentage in the statusline window is the fallback.
103
+ # The seat's rendered truth lives on the model banner. Select that line first, then read a percentage
104
+ # only from it: a bare numeric search across the visible window can borrow an old N% from scrollback
105
+ # when a long live-run segment pushes the real field past the pane's visible width (OBS-780).
107
106
  context_pct() {
108
- local screen marked
107
+ local screen banner pct
109
108
  screen=$(herdr agent read "$TARGET" --source visible --lines 8 2>/dev/null) || return 1
110
- marked=$(printf '%s\n' "$screen" | grep -iE '✳|context' | grep -oE '[0-9]+%' | tail -1 | tr -d '%')
111
- [ -n "$marked" ] && { printf '%s\n' "$marked"; return 0; }
112
- printf '%s\n' "$screen" | grep -oE '[0-9]+%' | tail -1 | tr -d '%'
109
+ banner=$(printf '%s\n' "$screen" |
110
+ grep -Ei '(^|[^[:alnum:]])(claude|opus|sonnet|haiku|gpt|gemini|glm|kimi|grok|composer|openai|zai)[[:alnum:]_./-]*([[:space:]]|$)' |
111
+ tail -1)
112
+ [ -n "$banner" ] || { printf 'UNREADABLE\n'; return 0; }
113
+ pct=$(printf '%s\n' "$banner" | grep -oE '[0-9]+%' | tail -1 | tr -d '%')
114
+ [ -n "$pct" ] && printf '%s\n' "$pct" || printf 'UNREADABLE\n'
113
115
  }
114
116
 
115
117
  handoff_fresh() {
@@ -144,35 +146,47 @@ act_on() {
144
146
 
145
147
  warned=0
146
148
  elapsed=0
147
- blind=0 # seconds in the current unreadable spell (OBS-739)
149
+ blind=0 # seconds in the current failed-read spell (OBS-739)
148
150
  blind_alarmed=0
151
+ unreadable_reported=0
149
152
  BLIND_ALARM_S="${TKR_BLIND_ALARM_S:-120}"
150
153
  while [ "$elapsed" -lt "$CAP" ]; do
151
- P=$(context_pct)
154
+ if ! P=$(context_pct); then P=""; fi
152
155
  if [ -z "$P" ]; then
153
- # Rule 2: no reading, no beat. The tier ages to STALE and a supervisor comes looking, which is the
154
- # truth about a watcher that cannot see the seat it was armed on.
155
- #
156
- # Rule 5 (OBS-739): ALARM ON THE BLIND READ. Ageing a tier is not enough — it is only visible to
157
- # someone already reading the beat table, and the measured failure was a watcher ALIVE AND BLIND for
158
- # hours because the run's own status text pushed the percentage off the statusline. An instrument
159
- # that cannot report its own absence is worse than none: the seat believes it has coverage and stops
160
- # looking. So say so on stdout, where the supervising seat is actually woken. Once per blind spell,
161
- # not every tick — a repeating alarm trains the reader to ignore it.
156
+ # The screen read itself failed: no observation, no beat. The tier ages to STALE and the watcher
157
+ # alarms once, because an instrument that cannot see its seat must never look healthy.
158
+ unreadable_reported=0
162
159
  blind=$((blind + TICK))
163
160
  if [ "$blind" -ge "$BLIND_ALARM_S" ] && [ "$blind_alarmed" -eq 0 ]; then
164
161
  blind_alarmed=1
165
- echo "CONTEXT_BLIND $TARGET — no percentage readable for ${blind}s; tier ${TIER} is ALIVE AND BLIND"
166
- echo " this watcher is NOT providing coverage: read the seat by hand and re-arm on a clear statusline"
167
- echo " do NOT substitute the token total — '∑ Nk tok' is cumulative SPEND, not context fill"
162
+ echo "CONTEXT_BLIND $TARGET — screen unreadable for ${blind}s; tier ${TIER} is ALIVE AND BLIND"
163
+ echo " this watcher is NOT providing coverage: read the seat by hand and repair the screen read"
168
164
  fi
169
165
  sleep "$TICK"; elapsed=$((elapsed + TICK)); continue
170
166
  fi
171
- # a successful read closes the blind spell and re-arms the alarm for the next one
167
+
168
+ if [ "$P" = "UNREADABLE" ]; then
169
+ # The screen read succeeded, so keep the watcher armed. The absent field is still not a number:
170
+ # report it once per spell and never let it flow into warn or act.
171
+ if [ "$blind_alarmed" -eq 1 ]; then
172
+ echo "CONTEXT_BLIND_CLEARED $TARGET — screen readable again after ${blind}s blind"
173
+ fi
174
+ blind=0; blind_alarmed=0
175
+ beat
176
+ if [ "$unreadable_reported" -eq 0 ]; then
177
+ unreadable_reported=1
178
+ echo "CONTEXT_UNREADABLE $TARGET — model banner has no visible percentage; no warn or act authorised"
179
+ fi
180
+ sleep "$TICK"; elapsed=$((elapsed + TICK)); continue
181
+ fi
182
+
183
+ if [ "$unreadable_reported" -eq 1 ]; then
184
+ echo "CONTEXT_UNREADABLE_CLEARED $TARGET — percentage readable again at ${P}%"
185
+ fi
172
186
  if [ "$blind_alarmed" -eq 1 ]; then
173
187
  echo "CONTEXT_BLIND_CLEARED $TARGET — percentage readable again at ${P}% after ${blind}s blind"
174
188
  fi
175
- blind=0; blind_alarmed=0
189
+ blind=0; blind_alarmed=0; unreadable_reported=0
176
190
  beat
177
191
 
178
192
  if [ "$P" -ge "$ACT" ] 2>/dev/null; then
@@ -190,4 +204,4 @@ while [ "$elapsed" -lt "$CAP" ]; do
190
204
  sleep "$TICK"; elapsed=$((elapsed + TICK))
191
205
  done
192
206
 
193
- echo "WATCH_CAP_REACHED $TARGET context=$(context_pct)% — no threshold crossed in ${CAP}s"
207
+ echo "WATCH_CAP_REACHED $TARGET — no threshold crossed in ${CAP}s"