tickmarkr 1.63.0 → 1.64.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.
@@ -8,6 +8,7 @@ export interface JudgeVerdict {
8
8
  criterion: string;
9
9
  met: boolean;
10
10
  reason: string;
11
+ evidence: string;
11
12
  }>;
12
13
  }
13
14
  export declare function judgeCriterionId(index: number): string;
@@ -4,13 +4,16 @@ import { DEFAULT_DIFF_CAP } from "../config/config.js";
4
4
  import { renderAcceptanceItem } from "../graph/schema.js";
5
5
  import { sh } from "../run/git.js";
6
6
  import { checkDiffCap, fetchTaskDiff } from "./review.js";
7
- import { extractVerdictJson, generateVerdictNonce, runLlm, verdictNonceLine } from "./llm.js";
7
+ import { COMPLETION_FAKING_CHECKLIST, extractVerdictJson, generateVerdictNonce, runLlm, verdictNonceLine } from "./llm.js";
8
8
  // Fable F4: acceptance judge shares review's 900s timeout — 300s default killed frontier judges on cap-sized diffs.
9
9
  const JUDGE_TIMEOUT_MS = 900_000;
10
10
  const JudgeVerdictRowSchema = z.object({
11
11
  criterion: z.string(),
12
12
  met: z.boolean(),
13
13
  reason: z.string(),
14
+ // v1.64: a verbatim quote from the judged diff grounding the ruling — required; a verdict
15
+ // omitting it is malformed and fails closed like any other shape violation.
16
+ evidence: z.string(),
14
17
  });
15
18
  const JudgeVerdictSchema = z.object({
16
19
  pass: z.boolean(),
@@ -157,6 +160,8 @@ You are a strict acceptance judge. Decide whether the diff satisfies EVERY accep
157
160
  Judge only what the diff proves — plausible-but-wrong must fail. Do not award partial credit.
158
161
  Deterministic command/test oracles have already passed mechanically; judge ONLY the rubric items below.
159
162
 
163
+ ${COMPLETION_FAKING_CHECKLIST}
164
+
160
165
  ## Task ${task.id}: ${task.title}
161
166
  Goal: ${task.goal}
162
167
 
@@ -171,8 +176,9 @@ ${diff}
171
176
  ${verdictNonceLine(nonce)}
172
177
 
173
178
  Respond with ONLY this JSON (no prose before or after):
174
- {"nonce": "${nonce}", "pass": true|false, "criteria": [{"criterion": "c1", "met": true|false, "reason": "..."}]}
179
+ {"nonce": "${nonce}", "pass": true|false, "criteria": [{"criterion": "c1", "met": true|false, "reason": "...", "evidence": "..."}]}
175
180
  Each criteria[].criterion MUST be the stable id from the rubric (c1, c2, ...) exactly once.
181
+ Each criteria[].evidence MUST be a short verbatim quote copied from the diff above that grounds the ruling; a quote not found in the diff voids the whole verdict.
176
182
  `;
177
183
  const raw = await runLlm(judge.adapter, judge.model, prompt, worktree, via, JUDGE_TIMEOUT_MS);
178
184
  const extracted = extractVerdictJson(raw, nonce);
@@ -185,6 +191,15 @@ Each criteria[].criterion MUST be the stable id from the rubric (c1, c2, ...) ex
185
191
  meta: { unparseable: true, judge: channelKey({ adapter: judge.adapter.id, model: judge.model }) } };
186
192
  }
187
193
  const { verdict: v, inconsistencies } = checkJudgeVerdict(extracted, expectedIds);
194
+ // v1.64: quoted evidence must appear verbatim in `diff` — the exact string embedded in the prompt
195
+ // above, never the worktree or any other artifact. A quote the diff doesn't contain is a
196
+ // hallucinated verdict: treated as unparseable so GATE-09 retries the judge on a failover channel.
197
+ const fabricated = v.criteria.filter((row) => !row.evidence.trim() || !diff.includes(row.evidence));
198
+ if (fabricated.length) {
199
+ return { gate: "acceptance", pass: false,
200
+ details: warn + detBlock + `judge verdict quotes evidence absent from the judged diff (${fabricated.map((row) => row.criterion).join(", ")}) — treating as unparseable, failing closed`,
201
+ meta: { unparseable: true, judge: channelKey({ adapter: judge.adapter.id, model: judge.model }) } };
202
+ }
188
203
  const pass = v.pass === true && inconsistencies.length === 0 && v.criteria.every((row) => row.met);
189
204
  const lines = v.criteria.map((row) => `${row.met ? "✓" : "✗"} ${row.criterion}: ${row.reason}`);
190
205
  if (!v.pass)
@@ -1,4 +1,5 @@
1
1
  import type { TickmarkrConfig } from "../config/config.js";
2
+ import type { AcceptanceItem } from "../graph/schema.js";
2
3
  import type { GateResult } from "./types.js";
3
4
  export interface Baseline {
4
5
  commands: Record<string, {
@@ -16,4 +17,14 @@ export interface BaselineWarning {
16
17
  export declare function fingerprint(output: string): string[];
17
18
  export declare function detectGateCommands(repoRoot: string, cfg: TickmarkrConfig): Record<string, string>;
18
19
  export declare function captureBaseline(cwd: string, commands: Record<string, string>): Promise<Baseline>;
20
+ export interface VacuousOracleWarning {
21
+ kind: "vacuous-oracle";
22
+ taskId: string;
23
+ oracles: string[];
24
+ reason: string;
25
+ }
26
+ export declare function detectVacuousOracles(cwd: string, tasks: ReadonlyArray<{
27
+ id: string;
28
+ acceptance: AcceptanceItem[];
29
+ }>): Promise<VacuousOracleWarning[]>;
19
30
  export declare function compareToBaseline(cwd: string, commands: Record<string, string>, baseline: Baseline, enabled: string[]): Promise<GateResult[]>;
@@ -83,6 +83,32 @@ export async function captureBaseline(cwd, commands) {
83
83
  }
84
84
  return base;
85
85
  }
86
+ // Tier A #3 (2026-07-21 repo-scan reconciliation): a command oracle that already exits 0 before any
87
+ // work exists cannot falsify the work — surface it at baseline capture. Observational only: journaled
88
+ // warning, never a gate input, and an oracle that fails at baseline changes nothing. Judge oracles
89
+ // (including plain-string compat judges) are never executed; test oracles stay gate-only (they need
90
+ // the detected runner and the worker's diff to mean anything).
91
+ export async function detectVacuousOracles(cwd, tasks) {
92
+ const out = [];
93
+ for (const t of tasks) {
94
+ const vacuous = [];
95
+ for (const a of t.acceptance) {
96
+ if (typeof a !== "object" || a.oracle !== "command")
97
+ continue;
98
+ if ((await sh(a.command, cwd)).code === 0)
99
+ vacuous.push(a.command);
100
+ }
101
+ if (vacuous.length) {
102
+ out.push({
103
+ kind: "vacuous-oracle",
104
+ taskId: t.id,
105
+ oracles: vacuous,
106
+ reason: `vacuous acceptance oracle on ${t.id}: already passes before any work exists — ${vacuous.map((c) => `$ ${c}`).join("; ")}`,
107
+ });
108
+ }
109
+ }
110
+ return out;
111
+ }
86
112
  // HYG-08 (D-01): headline the runner's own failure naming; demote the fingerprint diff to a secondary
87
113
  // section. Extracts from `raw` — the SAME cwd-stripped, per-line ANSI_RE-stripped string that was
88
114
  // fingerprinted, digits UN-normalized (Pitfall 2: normalization mangles test names, and the diff set could
@@ -1,12 +1,13 @@
1
1
  import type { WorkerAdapter } from "../adapters/types.js";
2
2
  import { type ExecutorDriver, type Slot } from "../drivers/types.js";
3
3
  export declare const GATE_PANE_SEP = " \u00B7 ";
4
+ export declare const COMPLETION_FAKING_CHECKLIST = "## Completion-faking checklist\nHunt for these concrete completion-faking shortcuts before ruling on any criterion:\n- hardcoded-result: output or fixture hardcoded to satisfy the stated criterion instead of real logic\n- test-weakening: tests skipped, deleted, or assertions loosened until failing behavior looks green\n- vacuous-assertion: a test that cannot fail (asserts a constant, asserts its own setup, no assertion)\n- fixture-overfit: implementation narrowed to the exact test inputs rather than the described behavior\n- echo-not-implement: criterion text echoed in names, comments, or strings without the behavior itself\n- stub-left-behind: TODO, throw, or no-op stub where the real implementation should be\n- error-swallowing: catch or fallback that hides failures instead of handling them\n- self-mocking: the code under test mocked or faked so the test exercises the mock\n- check-bypass: lint, type, or CI checks disabled, relaxed, or excluded to get green\n- rename-as-work: code moved or renamed and presented as the requested change\n- scope-padding: unrelated edits padding the diff while the criterion's behavior is untouched\nWhen a criterion fails, the verdict MUST name which shortcut above it matches, or state that none does.";
4
5
  /** Fable F3: per-call nonce echoed in verdict JSON and gate exit markers. */
5
6
  export declare function generateVerdictNonce(): string;
6
7
  export declare function verdictNonceLine(nonce: string): string;
7
8
  export declare function extractPromptNonce(prompt: string): string | null;
8
9
  export declare function gateExitTrailer(nonce: string): string;
9
- export declare function augmentFakeVerdictOutput(adapter: WorkerAdapter, out: string, nonce: string): string;
10
+ export declare function augmentFakeVerdictOutput(adapter: WorkerAdapter, out: string, nonce: string, prompt?: string): string;
10
11
  export type GatePaneRole = "judge" | "review" | "consult";
11
12
  /** T8: role-first pane name for fleet visibility — judge · T4, review · T3, consult · T2. */
12
13
  export declare function gatePaneName(role: GatePaneRole, taskId: string, suffix?: string): string;
package/dist/gates/llm.js CHANGED
@@ -6,6 +6,22 @@ import { formatOwnedName, parseOwnedName } from "../drivers/types.js";
6
6
  import { bannerShell, paneDispatchCommand } from "../brand.js";
7
7
  import { sh } from "../run/git.js";
8
8
  export const GATE_PANE_SEP = " · ";
9
+ // v1.64 gate-integrity (repo-scan Tier A·1): the concrete completion-faking shortcuts every
10
+ // judge/review verdict must hunt for. Shared verbatim by the acceptance judge and review prompts.
11
+ export const COMPLETION_FAKING_CHECKLIST = `## Completion-faking checklist
12
+ Hunt for these concrete completion-faking shortcuts before ruling on any criterion:
13
+ - hardcoded-result: output or fixture hardcoded to satisfy the stated criterion instead of real logic
14
+ - test-weakening: tests skipped, deleted, or assertions loosened until failing behavior looks green
15
+ - vacuous-assertion: a test that cannot fail (asserts a constant, asserts its own setup, no assertion)
16
+ - fixture-overfit: implementation narrowed to the exact test inputs rather than the described behavior
17
+ - echo-not-implement: criterion text echoed in names, comments, or strings without the behavior itself
18
+ - stub-left-behind: TODO, throw, or no-op stub where the real implementation should be
19
+ - error-swallowing: catch or fallback that hides failures instead of handling them
20
+ - self-mocking: the code under test mocked or faked so the test exercises the mock
21
+ - check-bypass: lint, type, or CI checks disabled, relaxed, or excluded to get green
22
+ - rename-as-work: code moved or renamed and presented as the requested change
23
+ - scope-padding: unrelated edits padding the diff while the criterion's behavior is untouched
24
+ When a criterion fails, the verdict MUST name which shortcut above it matches, or state that none does.`;
9
25
  /** Fable F3: per-call nonce echoed in verdict JSON and gate exit markers. */
10
26
  export function generateVerdictNonce() {
11
27
  return randomBytes(4).toString("hex");
@@ -19,8 +35,20 @@ export function extractPromptNonce(prompt) {
19
35
  export function gateExitTrailer(nonce) {
20
36
  return `printf '\\nTICKMARKR_''EXIT_${nonce}:%s\\n' $?`;
21
37
  }
38
+ // v1.64: scripted fake judge verdicts predate the required per-criterion evidence field — quote the
39
+ // first line of the prompt's own diff block into rows lacking one so zero-token fixtures keep their
40
+ // outcomes. Rows scripting an explicit evidence value pass through verbatim (tests exercise both paths).
41
+ function injectFakeEvidence(obj, prompt) {
42
+ if (!prompt.startsWith("TICKMARKR-JUDGE") || !Array.isArray(obj.criteria))
43
+ return obj;
44
+ const line = /```diff\n([\s\S]*?)```/.exec(prompt)?.[1].split("\n").find((l) => l.trim());
45
+ if (!line)
46
+ return obj;
47
+ const criteria = obj.criteria.map((row) => row && typeof row === "object" && !("evidence" in row) ? { ...row, evidence: line } : row);
48
+ return { ...obj, criteria };
49
+ }
22
50
  // ponytail: fake adapter serves static verdict JSON without nonce; append a bound copy for zero-token tests.
23
- export function augmentFakeVerdictOutput(adapter, out, nonce) {
51
+ export function augmentFakeVerdictOutput(adapter, out, nonce, prompt = "") {
24
52
  if (adapter.id !== "fake")
25
53
  return out;
26
54
  const obj = extractJson(out);
@@ -28,7 +56,7 @@ export function augmentFakeVerdictOutput(adapter, out, nonce) {
28
56
  return out;
29
57
  if (typeof obj.nonce === "string")
30
58
  return out;
31
- return `${out}\n${JSON.stringify({ ...obj, nonce })}`;
59
+ return `${out}\n${JSON.stringify(injectFakeEvidence({ ...obj, nonce }, prompt))}`;
32
60
  }
33
61
  /** T8: role-first pane name for fleet visibility — judge · T4, review · T3, consult · T2. */
34
62
  export function gatePaneName(role, taskId, suffix = "") {
@@ -61,7 +89,7 @@ export async function runHeadless(adapter, model, prompt, cwd, timeoutMs = 30000
61
89
  const nonce = extractPromptNonce(prompt);
62
90
  let out = r.stdout + "\n" + r.stderr;
63
91
  if (nonce)
64
- out = augmentFakeVerdictOutput(adapter, out, nonce);
92
+ out = augmentFakeVerdictOutput(adapter, out, nonce, prompt);
65
93
  return out;
66
94
  }
67
95
  // v1.1 default path: the same headless CLI call, but dispatched through the driver
@@ -88,7 +116,7 @@ export async function runViaDriver(adapter, model, prompt, cwd, via, timeoutMs =
88
116
  let out = await via.driver.read(slot, 400);
89
117
  if (!via.keep)
90
118
  await via.driver.close(slot);
91
- out = augmentFakeVerdictOutput(adapter, out, nonce);
119
+ out = augmentFakeVerdictOutput(adapter, out, nonce, prompt);
92
120
  return out;
93
121
  }
94
122
  export function runLlm(adapter, model, prompt, cwd, via, timeoutMs = 300000) {
@@ -4,7 +4,7 @@ import { renderAcceptanceItem } from "../graph/schema.js";
4
4
  import { getAdapter } from "../adapters/registry.js";
5
5
  import { shOk } from "../run/git.js";
6
6
  import { marginalCostRank } from "../route/router.js";
7
- import { extractVerdictJson, generateVerdictNonce, runLlm, verdictNonceLine } from "./llm.js";
7
+ import { COMPLETION_FAKING_CHECKLIST, extractVerdictJson, generateVerdictNonce, runLlm, verdictNonceLine } from "./llm.js";
8
8
  // OBS-48: cap on zero-context diff bytes (git diff -U0), not context-padded full diff — scattered
9
9
  // one-line hunks no longer trip at ~370 diff-bytes per changed line. Full diff still goes to the judge.
10
10
  const DIFF_CAP_REMEDY = "split the task, or raise gates.diffCap";
@@ -82,6 +82,8 @@ export async function reviewGate(task, worktree, baseRef, author, channels, adap
82
82
  You are a skeptical cross-vendor code reviewer. Another agent (vendor: ${author.adapter}) authored this diff.
83
83
  Look for correctness bugs, security issues, and acceptance-criteria gaps. Approve only if you would merge it.
84
84
 
85
+ ${COMPLETION_FAKING_CHECKLIST}
86
+
85
87
  ## Task ${task.id}: ${task.title} (complexity ${task.complexity})
86
88
  ## Acceptance criteria
87
89
  ${task.acceptance.map((a) => `- ${renderAcceptanceItem(a)}`).join("\n")}
@@ -4,6 +4,7 @@ import { getAdapter } from "../adapters/registry.js";
4
4
  import { bannerShell, paneDispatchCommand } from "../brand.js";
5
5
  import { augmentFakeVerdictOutput, extractVerdictJson, gateExitTrailer, gatePaneName, generateVerdictNonce, verdictNonceLine } from "../gates/llm.js";
6
6
  import { sh } from "./git.js";
7
+ import { redactSecrets } from "./redact.js";
7
8
  const MAX_RETRY_GUIDANCE_LINES = 10;
8
9
  function guidanceParts(text) {
9
10
  return text.split(/\n+/).flatMap((line) => line.split(/(?<=[.!?])\s+/)).map((s) => s.trim()).filter(Boolean);
@@ -100,7 +101,9 @@ opts = {}) {
100
101
  const dir = join(runDir, "consults");
101
102
  mkdirSync(dir, { recursive: true });
102
103
  const promptFile = join(dir, `${d.taskId}-${n}.md`);
103
- writeFileSync(promptFile, buildDossierPrompt(d, nonce));
104
+ // T3 secret redaction: the persisted dossier artifact (transcript/diff/journal tail — also what the
105
+ // consult model reads) is masked at this seam; the in-memory Dossier stays untouched.
106
+ writeFileSync(promptFile, redactSecrets(buildDossierPrompt(d, nonce)));
104
107
  // One seat = the WHOLE invoke-and-parse unit, both visibility branches (OBS-69 class: a headless-only
105
108
  // failover would leave the production pane path hard-failing on seat one). null = no parseable verdict.
106
109
  const invokeSeat = async (seatAdapter, seatModel, seatIdx) => {
@@ -11,7 +11,7 @@ import { bannerShell, paneDispatchCommand } from "../brand.js";
11
11
  import { globalConfigDir, loadConfigWithMode, readOverlayFile, repoOverlayPath, } from "../config/config.js";
12
12
  import { herdrSealShellPrefix, SubprocessDriver } from "../drivers/subprocess.js";
13
13
  import { formatOwnedName } from "../drivers/types.js";
14
- import { captureBaseline, detectGateCommands } from "../gates/baseline.js";
14
+ import { captureBaseline, detectGateCommands, detectVacuousOracles } from "../gates/baseline.js";
15
15
  import { runGates } from "../gates/run-gates.js";
16
16
  import { addEvidence, attributeBlocked, blockedTasks, getTask, graphDefinitionHash, loadGraph, pendingTasks, readyTasks, saveGraph, setStatus } from "../graph/graph.js";
17
17
  import { augmentRetryBrief, consult, renderRetryGuidance } from "./consult.js";
@@ -259,12 +259,21 @@ export async function runDaemon(repoRoot, opts = {}) {
259
259
  prior?.append("superseded", undefined, { by: runId });
260
260
  for (const warning of baseline.warnings ?? [])
261
261
  journal.append("baseline-warning", undefined, { ...warning });
262
+ // Tier A #3: run each task's command-typed acceptance oracles against the pristine baseline —
263
+ // one that already exits 0 verifies nothing. Warning only, taskId-stamped; never a gate input.
264
+ for (const w of await detectVacuousOracles(repoRoot, graph.tasks))
265
+ journal.append("baseline-warning", w.taskId, { ...w });
262
266
  }
263
267
  // T6: open the narrator AFTER run-start/run-resume is journaled so the watch surface has a run to
264
268
  // show. driver.narrator is undefined on subprocess → no-op (subprocess spawns nothing). Swallowed:
265
269
  // a failed-to-open or later-dead watch pane never affects the run.
270
+ // OBS-103: hold the returned slot — narrator() adopts an already-open watch by its owned name
271
+ // (a prior daemon instance's, after a stop→resume cycle), so the run-end sweep below can retire
272
+ // it regardless of which instance split the pane.
273
+ const watchName = formatOwnedName({ role: "watch", taskId: "run", attempt: 0, runId });
274
+ let watchSlot;
266
275
  try {
267
- await driver.narrator?.(repoRoot, "tickmarkr status --watch", runId);
276
+ watchSlot = await driver.narrator?.(repoRoot, "tickmarkr status --watch", runId);
268
277
  }
269
278
  catch {
270
279
  /* cosmetic-only — the run proceeds without a live surface */
@@ -293,7 +302,22 @@ export async function runDaemon(repoRoot, opts = {}) {
293
302
  if (keepForever)
294
303
  return;
295
304
  try {
296
- await driver.reconcile?.(desiredPanes(journal.read(), runId), runId, opts);
305
+ const desired = desiredPanes(journal.read(), runId);
306
+ // The watch pane is never the DRIVER sweep's candidate (panesToClose spares role "watch":
307
+ // herdr's watches bookkeeping lives in close(), and a raw pane-close in the sweep would
308
+ // leave narrator() a stale cache) — the driver always sees it as desired; its lifecycle is
309
+ // decided here from the fold alone.
310
+ await driver.reconcile?.(new Set([...desired, watchName]), runId, opts);
311
+ // OBS-103: when the fold retires the watch (run-end boundary), close the narrator. The
312
+ // decision keys on the run identity in the pane name — narrator() adopts a prior daemon
313
+ // instance's pane under the same owned name, so a stop→resume cycle's leftover narrator
314
+ // closes exactly like one this instance opened. A narrator carrying a non-canonical name
315
+ // (no run identity) is never this run's to sweep.
316
+ if (watchSlot && watchSlot.name === watchName && !desired.has(watchName)) {
317
+ const w = watchSlot;
318
+ watchSlot = undefined;
319
+ await driver.close(w);
320
+ }
297
321
  }
298
322
  catch {
299
323
  /* cosmetic — visibility is never a gate */
@@ -5,6 +5,7 @@ import { channelKey, TokenUsageSchema } from "../adapters/types.js";
5
5
  import { stateDirName, tickmarkrDir } from "../graph/graph.js";
6
6
  import { TIERS } from "../graph/schema.js";
7
7
  import { buildProfile } from "../route/profile.js";
8
+ import { redactSecrets } from "./redact.js";
8
9
  export function formatJournalNarration({ event, taskId, data }) {
9
10
  const assignment = data.assignment;
10
11
  const direct = [data.summary, data.reason, data.error, data.step, data.action, data.lint, data.branch, data.from]
@@ -311,9 +312,12 @@ export class Journal {
311
312
  }
312
313
  append(event, taskId, data = {}) {
313
314
  const row = { ts: new Date().toISOString(), event, ...(taskId ? { taskId } : {}), data };
314
- appendFileSync(this.journalPath, JSON.stringify(row) + "\n");
315
+ // T3 secret redaction: only the persisted bytes are masked — the caller's data stays untouched in
316
+ // memory. The narrator receives the persisted (masked) row so a pane sink never shows a credential.
317
+ const line = redactSecrets(JSON.stringify(row));
318
+ appendFileSync(this.journalPath, line + "\n");
315
319
  try {
316
- this.narrate?.(row);
320
+ this.narrate?.(JSON.parse(line));
317
321
  }
318
322
  catch {
319
323
  // narration is observational; a broken sink must not affect the journal or run
@@ -421,7 +425,8 @@ export class Journal {
421
425
  return m;
422
426
  }
423
427
  telemetry(row) {
424
- appendFileSync(join(this.dir, "telemetry.jsonl"), JSON.stringify(row) + "\n");
428
+ // T3 secret redaction: same persistence seam as append — credential-free rows are byte-identical.
429
+ appendFileSync(join(this.dir, "telemetry.jsonl"), redactSecrets(JSON.stringify(row)) + "\n");
425
430
  }
426
431
  // Per-run, raw (NOT schema-validated) — report.ts reads v1.5 core fields; stays byte-compatible.
427
432
  readTelemetry() {
@@ -87,8 +87,10 @@ export function desiredPanes(rows, runId) {
87
87
  clearTask(row.taskId);
88
88
  break;
89
89
  case "run-end":
90
+ // OBS-103: run-end retires EVERY run-tagged pane, the watch narrator included. The fold
91
+ // keys on the run identity in the pane name, so a narrator a prior daemon instance opened
92
+ // (stop→resume cycle) retires all the same; a later run-resume re-desires it above.
90
93
  desired.clear();
91
- desired.add(formatOwnedName({ role: "watch", taskId: "run", attempt: 0, runId }));
92
94
  break;
93
95
  }
94
96
  }
@@ -0,0 +1,2 @@
1
+ export declare const MASK = "[REDACTED]";
2
+ export declare function redactSecrets(text: string): string;
@@ -0,0 +1,53 @@
1
+ // T3 (repo-scan Tier A #2): the shared secret-redaction pass for captured agent text at the
2
+ // persistence seams. Every seam that persists captured agent text routes its bytes through
3
+ // redactSecrets before hitting disk — journal event payloads and telemetry rows (journal.ts) and
4
+ // consult dossier artifacts (consult.ts). In-memory originals are never touched: redaction applies
5
+ // to the serialized bytes only, at the write site.
6
+ //
7
+ // Two shape families:
8
+ // - vendor keys: recognizable prefix + high-entropy body. The prefix survives masking so the
9
+ // credential class stays identifiable; the body never persists.
10
+ // - secret assignments: KEY=value / "key": "value" where the key NAME announces a secret. The key
11
+ // survives; the value is masked.
12
+ // Text with no credential shapes passes through byte-identical. Masks contain no quote or backslash
13
+ // and value charsets never cross a JSON string boundary, so redacting a serialized JSON line always
14
+ // yields a line that still parses.
15
+ export const MASK = "[REDACTED]";
16
+ // Order matters: more specific prefixes (sk-ant-, sk-proj-) before the generic sk- form.
17
+ const VENDOR_KEY_RES = [
18
+ /\b(sk-ant-)[A-Za-z0-9_-]{8,}/g, // Anthropic
19
+ /\b(sk-proj-)[A-Za-z0-9_-]{8,}/g, // OpenAI project key
20
+ /\b(sk-)[A-Za-z0-9_-]{16,}/g, // OpenAI classic / sk-prefixed secret keys
21
+ /\b(github_pat_)[A-Za-z0-9_]{8,}/g, // GitHub fine-grained PAT
22
+ /\b(gh[pousr]_)[A-Za-z0-9]{16,}/g, // GitHub token family (ghp_/gho_/ghu_/ghs_/ghr_)
23
+ /\b(glpat-)[A-Za-z0-9_-]{8,}/g, // GitLab PAT
24
+ /\b(xox[baprs]-)[A-Za-z0-9-]{8,}/g, // Slack token family
25
+ /\b(npm_)[A-Za-z0-9]{16,}/g, // npm token
26
+ /\b(AKIA)[0-9A-Z]{16}\b/g, // AWS access key id
27
+ /\b(AIza)[0-9A-Za-z_-]{35}\b/g, // Google API key
28
+ ];
29
+ // Key names that announce a secret. The optional quote after the key closes a JSON key ("apiKey": "…").
30
+ // The match starts AT the keyword — chars before it (MY_ in MY_API_KEY=) are simply left in place by
31
+ // replace, so anchoring on the keyword yields identical output while keeping the scan linear (a
32
+ // leading [A-Za-z0-9_.-]* here backtracks quadratically on long tokens — seconds on a 50K blob, and
33
+ // journal payloads carry parked diffs up to the diff cap).
34
+ // The value charset excludes quotes/backslash (never crosses a JSON string boundary) and square
35
+ // brackets (an already-masked value never re-matches ⇒ idempotent, and a vendor prefix kept by the
36
+ // pass above survives). The letter lookahead skips purely numeric values ("maxTokens":30000000 is a
37
+ // count, not a credential — and masking a bare JSON number would break the line's parse).
38
+ // Quotes may arrive backslash-escaped (a transcript already serialized inside a JSON string), so the
39
+ // optional opening/closing quote around key and value accepts \" as well as ".
40
+ const ASSIGNMENT_RE = /((?:api[_-]?key|apikey|secret|token|passwd|password|credential|access[_-]?key)[A-Za-z0-9_.-]*(?:\\?["'])?\s*[=:]\s*(?:\\?["'])?)(?=[^\s"'`\\,;[\]]*[A-Za-z])([^\s"'`\\,;[\]]{8,})/gi;
41
+ // Authorization headers are the most common credential shape in captured transcripts.
42
+ const BEARER_RE = /\b(Bearer\s+)[A-Za-z0-9._~+/=-]{16,}/g;
43
+ // Cheap literal prescan: every pattern above needs one of these substrings, and most persisted text
44
+ // (diffs, prose, telemetry) has none — those payloads skip all 12 regex passes in one linear scan.
45
+ const HINT_RE = /sk-|github_pat_|gh[pousr]_|glpat-|xox[baprs]-|npm_|AKIA|AIza|Bearer|api[_-]?key|apikey|secret|token|passwd|password|credential|access[_-]?key/i;
46
+ export function redactSecrets(text) {
47
+ if (!HINT_RE.test(text))
48
+ return text;
49
+ let out = text;
50
+ for (const re of VENDOR_KEY_RES)
51
+ out = out.replace(re, `$1${MASK}`);
52
+ return out.replace(ASSIGNMENT_RE, `$1${MASK}`).replace(BEARER_RE, `$1${MASK}`);
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tickmarkr",
3
- "version": "1.63.0",
3
+ "version": "1.64.0",
4
4
  "description": "Spec in, verified work out.",
5
5
  "type": "module",
6
6
  "license": "MIT",