@tokenfactory/acc-runner 0.29.4 → 0.33.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.
Files changed (71) hide show
  1. package/dist/cli.js +3 -2
  2. package/dist/cli.js.map +1 -1
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +9 -2
  5. package/dist/config.js.map +1 -1
  6. package/dist/doctor.d.ts +19 -0
  7. package/dist/doctor.d.ts.map +1 -1
  8. package/dist/doctor.js +169 -8
  9. package/dist/doctor.js.map +1 -1
  10. package/dist/engines/claude-code.d.ts +9 -0
  11. package/dist/engines/claude-code.d.ts.map +1 -0
  12. package/dist/engines/claude-code.js +95 -0
  13. package/dist/engines/claude-code.js.map +1 -0
  14. package/dist/engines/codex.d.ts +27 -0
  15. package/dist/engines/codex.d.ts.map +1 -0
  16. package/dist/engines/codex.js +178 -0
  17. package/dist/engines/codex.js.map +1 -0
  18. package/dist/engines/registry.d.ts +18 -0
  19. package/dist/engines/registry.d.ts.map +1 -0
  20. package/dist/engines/registry.js +26 -0
  21. package/dist/engines/registry.js.map +1 -0
  22. package/dist/engines/types.d.ts +73 -0
  23. package/dist/engines/types.d.ts.map +1 -0
  24. package/dist/engines/types.js +2 -0
  25. package/dist/engines/types.js.map +1 -0
  26. package/dist/failure-classifier.d.ts +32 -1
  27. package/dist/failure-classifier.d.ts.map +1 -1
  28. package/dist/failure-classifier.js +193 -1
  29. package/dist/failure-classifier.js.map +1 -1
  30. package/dist/git.d.ts +10 -0
  31. package/dist/git.d.ts.map +1 -1
  32. package/dist/git.js +6 -0
  33. package/dist/git.js.map +1 -1
  34. package/dist/login.d.ts +17 -0
  35. package/dist/login.d.ts.map +1 -1
  36. package/dist/login.js +22 -1
  37. package/dist/login.js.map +1 -1
  38. package/dist/pr-body.d.ts +53 -0
  39. package/dist/pr-body.d.ts.map +1 -0
  40. package/dist/pr-body.js +154 -0
  41. package/dist/pr-body.js.map +1 -0
  42. package/dist/prepr-gate.d.ts +132 -2
  43. package/dist/prepr-gate.d.ts.map +1 -1
  44. package/dist/prepr-gate.js +260 -9
  45. package/dist/prepr-gate.js.map +1 -1
  46. package/dist/provider-auth.d.ts +120 -0
  47. package/dist/provider-auth.d.ts.map +1 -0
  48. package/dist/provider-auth.js +184 -0
  49. package/dist/provider-auth.js.map +1 -0
  50. package/dist/review-diff-guard.d.ts +12 -0
  51. package/dist/review-diff-guard.d.ts.map +1 -0
  52. package/dist/review-diff-guard.js +52 -0
  53. package/dist/review-diff-guard.js.map +1 -0
  54. package/dist/review-worktree-cleanup.d.ts +73 -0
  55. package/dist/review-worktree-cleanup.d.ts.map +1 -0
  56. package/dist/review-worktree-cleanup.js +103 -0
  57. package/dist/review-worktree-cleanup.js.map +1 -0
  58. package/dist/runtime/reviewer.d.ts.map +1 -1
  59. package/dist/runtime/reviewer.js +72 -29
  60. package/dist/runtime/reviewer.js.map +1 -1
  61. package/dist/runtime/worktree.d.ts.map +1 -1
  62. package/dist/runtime/worktree.js +8 -3
  63. package/dist/runtime/worktree.js.map +1 -1
  64. package/dist/task-runner.d.ts +1 -8
  65. package/dist/task-runner.d.ts.map +1 -1
  66. package/dist/task-runner.js +65 -66
  67. package/dist/task-runner.js.map +1 -1
  68. package/dist/watch.d.ts.map +1 -1
  69. package/dist/watch.js +30 -3
  70. package/dist/watch.js.map +1 -1
  71. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- export type PreprGateName = "typecheck" | "lint" | "build" | "test" | "migration-lint";
1
+ export type PreprGateName = "nul-check" | "scope" | "typecheck" | "lint" | "build" | "test" | "migration-lint";
2
2
  /**
3
3
  * Run order. typecheck → lint → build → test mirrors the CLAUDE.md quality-gate
4
4
  * order (cheapest / most-likely-to-fail first) so a broken worktree fails on
@@ -25,6 +25,28 @@ export interface PreprGateResult {
25
25
  absent: PreprGateName[];
26
26
  /** Set iff `ok === false`: the first gate that failed + its output tail. */
27
27
  failure?: PreprGateFailure;
28
+ /**
29
+ * SHADOW MODE: set when the migration linter reported findings but the
30
+ * `migration_lint_blocking` knob is OFF — the PR was NOT blocked, but the
31
+ * output is surfaced so the caller can log it (advisory). `ok` stays `true`.
32
+ * Never set in blocking mode (there a finding lands in `failure` instead).
33
+ */
34
+ migrationLintShadow?: {
35
+ exitCode: number | null;
36
+ /** Tail of the linter's findings output — log-safe. */
37
+ outputTail: string;
38
+ };
39
+ /**
40
+ * V96 (R5) SHADOW MODE: set when staged files fell outside the task's
41
+ * `allowed` globs but the scope-enforce knob was OFF — the PR was NOT blocked
42
+ * (advisory only). `ok` stays `true`. In enforce mode the violation lands in
43
+ * `failure` (gate `scope`) instead and this is unset.
44
+ */
45
+ scopeShadow?: {
46
+ /** Repo-relative staged paths that matched none of the allowed globs. */
47
+ offending: string[];
48
+ outputTail: string;
49
+ };
28
50
  }
29
51
  export interface PreprGateDeps {
30
52
  /**
@@ -65,9 +87,117 @@ export interface PreprGateDeps {
65
87
  exitCode: number | null;
66
88
  output: string;
67
89
  }>;
90
+ /**
91
+ * SHADOW-WEEK knob. When the migration linter reports a lint ERROR (exit ≠ 0):
92
+ * • `true` → block the PR (fail the gate) — the linter's output lands in
93
+ * the runner log via `failure.outputTail`.
94
+ * • `false` → advisory: log the findings (`migrationLintShadow`) but open
95
+ * the PR anyway.
96
+ * This mirrors the org `acc.org_settings.migration_lint_blocking` knob, which
97
+ * defaults to `false` (shadow). The task-runner resolves that org setting and
98
+ * passes it here; when unset (dep + `ACC_MIGRATION_LINT_BLOCKING` env both
99
+ * absent) this defaults to `false` (shadow) — defaults ship OFF; blocking is
100
+ * an explicit opt-in via the org knob or the env.
101
+ */
102
+ migrationLintBlocking?: boolean;
103
+ /**
104
+ * V96 (R5): the task's `allowed` file globs. When non-empty, the scope check
105
+ * flags every staged file that matches NONE of these globs. Empty/undefined
106
+ * disables the scope check entirely (a task with no declared scope is not
107
+ * scope-checked). Never enforced-by-default — see `scopeEnforce`.
108
+ */
109
+ allowedGlobs?: string[];
110
+ /**
111
+ * V96 (R5) knob (DEFAULT OFF). When true a scope violation FAILS the gate
112
+ * (HALT — no PR opened). When false/unset the violation is advisory
113
+ * (`scopeShadow`, PR still opens). Precedence mirrors migrationLintBlocking:
114
+ * explicit dep, else `ACC_PREPR_SCOPE_ENFORCE` env, else `false`.
115
+ */
116
+ scopeEnforce?: boolean;
117
+ /**
118
+ * V96 (R4/R5): the staged files (repo-relative) this branch added/changed vs
119
+ * `baseRef`. Default: `git diff --name-only --diff-filter=ACMR <base>...HEAD`.
120
+ * Drives BOTH the NUL/binary check and the scope check. Omitted + no `baseRef`
121
+ * → both checks are skipped (unit suite never shells out to git).
122
+ */
123
+ listStagedFiles?: (workdir: string, baseRef?: string) => Promise<string[]>;
124
+ /**
125
+ * V96 (R4): read a staged file's raw bytes (for the NUL/binary scan). Default:
126
+ * `fs.readFile(join(workdir, file))`. Injectable so the unit suite can feed a
127
+ * NUL fixture without a real file.
128
+ */
129
+ readFileBytes?: (workdir: string, file: string) => Promise<Buffer>;
130
+ }
131
+ /**
132
+ * Text-source extensions the NUL/binary check scans. An allowlist (never a
133
+ * binary denylist) so genuine binary assets — images, fonts, the design export —
134
+ * are never false-positives. Kept in sync with scripts/ci/check-no-binary-source.mjs
135
+ * (the CI backstop for the SAME defect class); the runner package cannot import
136
+ * that .mjs, so the list is duplicated per the standing cross-package convention.
137
+ */
138
+ export declare const TEXT_EXTENSIONS: Set<string>;
139
+ /** True when `p` has a text-source extension the NUL check scans. */
140
+ export declare function isTextSourcePath(p: string): boolean;
141
+ export interface NulHit {
142
+ path: string;
143
+ /** Byte offset of the first NUL. */
144
+ offset: number;
145
+ /** 1-based line of the NUL byte. */
146
+ line: number;
147
+ /** 1-based byte column within the line. */
148
+ col: number;
68
149
  }
69
- /** Escape-hatch flag. Matches the truthy convention in anthropic-auth.ts. */
150
+ /** Offset of the first NUL byte in `buf`, or -1 if there is none. */
151
+ export declare function firstNulOffset(buf: Buffer): number;
152
+ /** 1-based {line, col} of byte `offset` within `buf` (col counts bytes). */
153
+ export declare function lineColOf(buf: Buffer, offset: number): {
154
+ line: number;
155
+ col: number;
156
+ };
157
+ /**
158
+ * Build the log-safe failure message for a NUL hit. Names the file, the byte
159
+ * offset, and the 1-based line:col — the exact pointer the reviewer needed for
160
+ * PR #1059 (a single NUL byte burned two review cycles).
161
+ */
162
+ export declare function formatNulFailure(hit: NulHit): string;
163
+ /**
164
+ * Convert one `allowed`-list glob into a RegExp anchored to a full repo-relative
165
+ * path. Semantics:
166
+ * - `**` matches any run of chars INCLUDING `/`;
167
+ * - `*` matches any run of chars EXCLUDING `/` (within one path segment);
168
+ * - `?` matches a single non-`/` char;
169
+ * - a pattern ending in `/` (or a bare directory with no wildcard) matches
170
+ * everything beneath that directory prefix;
171
+ * - every other char is matched literally.
172
+ */
173
+ export declare function globToRegExp(glob: string): RegExp;
174
+ /**
175
+ * True when `file` (repo-relative) matches ANY of `globs`, OR when a wildcard-free
176
+ * glob names a directory that `file` sits beneath (`api/_lib` matches
177
+ * `api/_lib/x.ts`). Fail-open on an empty glob list — a task that declares no
178
+ * scope is treated as "everything allowed" (the caller gates on non-empty).
179
+ */
180
+ export declare function matchesAllowedGlobs(file: string, globs: string[]): boolean;
181
+ /** Repo-relative staged paths that match NONE of the allowed globs. */
182
+ export declare function scopeViolations(files: string[], globs: string[]): string[];
183
+ /**
184
+ * Resolve whether a scope violation BLOCKS the PR. Precedence:
185
+ * 1. explicit `deps.scopeEnforce`, else
186
+ * 2. the `ACC_PREPR_SCOPE_ENFORCE` env (`1/true/yes/on` → enforce), else
187
+ * 3. `false` — advisory/shadow (defaults ship OFF; enforcement is opt-in).
188
+ */
189
+ export declare function scopeEnforceResolved(explicit: boolean | undefined, env: NodeJS.ProcessEnv): boolean;
190
+ /** Escape-hatch flag. Matches the truthy convention in provider-auth.ts. */
70
191
  export declare function preprSkipRequested(env: NodeJS.ProcessEnv): boolean;
192
+ /**
193
+ * Resolve whether a migration-lint ERROR blocks the PR. Precedence:
194
+ * 1. explicit `deps.migrationLintBlocking` (the resolved org knob), else
195
+ * 2. the `ACC_MIGRATION_LINT_BLOCKING` env (`1/true/yes/on` → blocking), else
196
+ * 3. `false` — shadow (defaults ship OFF; blocking is an explicit opt-in).
197
+ * Matches the org `migration_lint_blocking` default of `false` (shadow), so
198
+ * un-wired callers get the same effective default as wired ones.
199
+ */
200
+ export declare function migrationLintBlockingResolved(explicit: boolean | undefined, env: NodeJS.ProcessEnv): boolean;
71
201
  /**
72
202
  * Run the repo's own quality gates in `workdir` before a PR is opened.
73
203
  * `ok === false` means the caller MUST NOT open a PR — fail the task with
@@ -1 +1 @@
1
- {"version":3,"file":"prepr-gate.d.ts","sourceRoot":"","sources":["../src/prepr-gate.ts"],"names":[],"mappings":"AA+BA,MAAM,MAAM,aAAa,GACrB,WAAW,GACX,MAAM,GACN,OAAO,GACP,MAAM,GACN,gBAAgB,CAAC;AAErB;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,aAAa,EAA2C,CAAC;AAEnF,MAAM,WAAW,gBAAgB;IAC/B,yBAAyB;IACzB,IAAI,EAAE,aAAa,CAAC;IACpB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,EAAE,EAAE,OAAO,CAAC;IACZ,uEAAuE;IACvE,OAAO,EAAE,OAAO,CAAC;IACjB,6CAA6C;IAC7C,GAAG,EAAE,aAAa,EAAE,CAAC;IACrB,2EAA2E;IAC3E,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnE;;;;OAIG;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AG,EAAE,MAAM,GAAG,MAAM,CASpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAuBjD;AAMD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAW1E;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAG1E;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAC7B,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,OAAO,CAKT;AAQD,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAGlE;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,OAAO,GAAG,SAAS,EAC7B,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,OAAO,CAKT;AA0GD;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,eAAe,CAAC,CAkJ1B"}
@@ -32,14 +32,167 @@ import { buildEnv } from "./bin-resolve.js";
32
32
  */
33
33
  export const PREPR_GATES = ["typecheck", "lint", "build", "test"];
34
34
  // ─────────────────────────────────────────────────────────────────────────────
35
+ // V96 (R4/R5): scope + binary/NUL pure helpers
36
+ // ─────────────────────────────────────────────────────────────────────────────
37
+ /**
38
+ * Text-source extensions the NUL/binary check scans. An allowlist (never a
39
+ * binary denylist) so genuine binary assets — images, fonts, the design export —
40
+ * are never false-positives. Kept in sync with scripts/ci/check-no-binary-source.mjs
41
+ * (the CI backstop for the SAME defect class); the runner package cannot import
42
+ * that .mjs, so the list is duplicated per the standing cross-package convention.
43
+ */
44
+ export const TEXT_EXTENSIONS = new Set([
45
+ ".ts", ".tsx", ".mts", ".cts",
46
+ ".js", ".jsx", ".mjs", ".cjs",
47
+ ".json", ".jsonc",
48
+ ".sql",
49
+ ".md", ".mdx", ".txt",
50
+ ".css", ".scss", ".html",
51
+ ".yml", ".yaml", ".toml",
52
+ ".sh", ".env",
53
+ ]);
54
+ /** True when `p` has a text-source extension the NUL check scans. */
55
+ export function isTextSourcePath(p) {
56
+ return TEXT_EXTENSIONS.has(path.extname(p).toLowerCase());
57
+ }
58
+ /** Offset of the first NUL byte in `buf`, or -1 if there is none. */
59
+ export function firstNulOffset(buf) {
60
+ return buf.indexOf(0);
61
+ }
62
+ /** 1-based {line, col} of byte `offset` within `buf` (col counts bytes). */
63
+ export function lineColOf(buf, offset) {
64
+ let line = 1;
65
+ let lineStart = 0;
66
+ for (let i = 0; i < offset && i < buf.length; i++) {
67
+ if (buf[i] === 0x0a) {
68
+ line++;
69
+ lineStart = i + 1;
70
+ }
71
+ }
72
+ return { line, col: offset - lineStart + 1 };
73
+ }
74
+ /**
75
+ * Build the log-safe failure message for a NUL hit. Names the file, the byte
76
+ * offset, and the 1-based line:col — the exact pointer the reviewer needed for
77
+ * PR #1059 (a single NUL byte burned two review cycles).
78
+ */
79
+ export function formatNulFailure(hit) {
80
+ return [
81
+ `raw NUL byte in staged text source: ${hit.path}:${hit.line}:${hit.col} (byte offset ${hit.offset})`,
82
+ "git treats a file with a NUL byte as BINARY, so the diff renders as an opaque",
83
+ "blob and the reviewer cannot review it (this blocked V82 / PR #1059). tsc +",
84
+ "eslint accept a NUL inside a string, so typecheck/lint/build will NOT catch it.",
85
+ "Fix: replace the raw NUL byte with the \\u0000 escape sequence (or a non-control",
86
+ "delimiter). UTF-16-encoded files trip this too — re-save as UTF-8.",
87
+ ].join("\n");
88
+ }
89
+ /**
90
+ * Convert one `allowed`-list glob into a RegExp anchored to a full repo-relative
91
+ * path. Semantics:
92
+ * - `**` matches any run of chars INCLUDING `/`;
93
+ * - `*` matches any run of chars EXCLUDING `/` (within one path segment);
94
+ * - `?` matches a single non-`/` char;
95
+ * - a pattern ending in `/` (or a bare directory with no wildcard) matches
96
+ * everything beneath that directory prefix;
97
+ * - every other char is matched literally.
98
+ */
99
+ export function globToRegExp(glob) {
100
+ const g = glob.trim();
101
+ // Directory-prefix form: `foo/bar/` → everything under it.
102
+ if (g.endsWith("/")) {
103
+ return new RegExp("^" + escapeRegexLiteral(g) + ".*$");
104
+ }
105
+ let re = "";
106
+ for (let i = 0; i < g.length; i++) {
107
+ const c = g[i];
108
+ if (c === "*") {
109
+ if (g[i + 1] === "*") {
110
+ re += ".*";
111
+ i++;
112
+ }
113
+ else {
114
+ re += "[^/]*";
115
+ }
116
+ }
117
+ else if (c === "?") {
118
+ re += "[^/]";
119
+ }
120
+ else {
121
+ re += escapeRegexLiteral(c);
122
+ }
123
+ }
124
+ return new RegExp("^" + re + "$");
125
+ }
126
+ function escapeRegexLiteral(s) {
127
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
128
+ }
129
+ /**
130
+ * True when `file` (repo-relative) matches ANY of `globs`, OR when a wildcard-free
131
+ * glob names a directory that `file` sits beneath (`api/_lib` matches
132
+ * `api/_lib/x.ts`). Fail-open on an empty glob list — a task that declares no
133
+ * scope is treated as "everything allowed" (the caller gates on non-empty).
134
+ */
135
+ export function matchesAllowedGlobs(file, globs) {
136
+ const f = file.trim();
137
+ if (globs.length === 0)
138
+ return true;
139
+ for (const raw of globs) {
140
+ const g = raw.trim();
141
+ if (!g)
142
+ continue;
143
+ if (globToRegExp(g).test(f))
144
+ return true;
145
+ // Wildcard-free directory prefix: `api/_lib` allows `api/_lib/**`.
146
+ if (!/[*?]/.test(g) && f.startsWith(g.endsWith("/") ? g : `${g}/`))
147
+ return true;
148
+ }
149
+ return false;
150
+ }
151
+ /** Repo-relative staged paths that match NONE of the allowed globs. */
152
+ export function scopeViolations(files, globs) {
153
+ if (globs.length === 0)
154
+ return [];
155
+ return files.filter((f) => f && !matchesAllowedGlobs(f, globs));
156
+ }
157
+ /**
158
+ * Resolve whether a scope violation BLOCKS the PR. Precedence:
159
+ * 1. explicit `deps.scopeEnforce`, else
160
+ * 2. the `ACC_PREPR_SCOPE_ENFORCE` env (`1/true/yes/on` → enforce), else
161
+ * 3. `false` — advisory/shadow (defaults ship OFF; enforcement is opt-in).
162
+ */
163
+ export function scopeEnforceResolved(explicit, env) {
164
+ if (typeof explicit === "boolean")
165
+ return explicit;
166
+ const v = env.ACC_PREPR_SCOPE_ENFORCE?.trim().toLowerCase();
167
+ if (v === undefined || v === "")
168
+ return false;
169
+ return !(v === "0" || v === "false" || v === "no" || v === "off");
170
+ }
171
+ // ─────────────────────────────────────────────────────────────────────────────
35
172
  // Pure helpers
36
173
  // ─────────────────────────────────────────────────────────────────────────────
37
174
  const OUTPUT_TAIL = 4000;
38
- /** Escape-hatch flag. Matches the truthy convention in anthropic-auth.ts. */
175
+ /** Escape-hatch flag. Matches the truthy convention in provider-auth.ts. */
39
176
  export function preprSkipRequested(env) {
40
177
  const v = env.ACC_RUNNER_SKIP_PREPR?.trim().toLowerCase();
41
178
  return v === "1" || v === "true" || v === "yes" || v === "on";
42
179
  }
180
+ /**
181
+ * Resolve whether a migration-lint ERROR blocks the PR. Precedence:
182
+ * 1. explicit `deps.migrationLintBlocking` (the resolved org knob), else
183
+ * 2. the `ACC_MIGRATION_LINT_BLOCKING` env (`1/true/yes/on` → blocking), else
184
+ * 3. `false` — shadow (defaults ship OFF; blocking is an explicit opt-in).
185
+ * Matches the org `migration_lint_blocking` default of `false` (shadow), so
186
+ * un-wired callers get the same effective default as wired ones.
187
+ */
188
+ export function migrationLintBlockingResolved(explicit, env) {
189
+ if (typeof explicit === "boolean")
190
+ return explicit;
191
+ const v = env.ACC_MIGRATION_LINT_BLOCKING?.trim().toLowerCase();
192
+ if (v === undefined || v === "")
193
+ return false;
194
+ return !(v === "0" || v === "false" || v === "no" || v === "off");
195
+ }
43
196
  // ─────────────────────────────────────────────────────────────────────────────
44
197
  // Default I/O implementations
45
198
  // ─────────────────────────────────────────────────────────────────────────────
@@ -91,6 +244,23 @@ async function defaultListChangedMigrations(workdir, baseRef) {
91
244
  .map((s) => s.trim())
92
245
  .filter((s) => s.endsWith(".sql"));
93
246
  }
247
+ async function defaultListStagedFiles(workdir, baseRef) {
248
+ if (!baseRef)
249
+ return [];
250
+ // `<base>...HEAD` (merge-base range) so only files THIS branch added/changed
251
+ // are checked — never files the base already carried. reject:false + exitCode
252
+ // guard: a missing base ref yields no files rather than throwing.
253
+ const result = await execa("git", ["diff", "--name-only", "--diff-filter=ACMR", `${baseRef}...HEAD`], { cwd: workdir, env: buildEnv(), reject: false });
254
+ if (result.exitCode !== 0)
255
+ return [];
256
+ return (result.stdout ?? "")
257
+ .split("\n")
258
+ .map((s) => s.trim())
259
+ .filter((s) => s.length > 0);
260
+ }
261
+ async function defaultReadFileBytes(workdir, file) {
262
+ return fs.readFile(path.join(workdir, file));
263
+ }
94
264
  async function defaultRunMigrationLint(workdir, files) {
95
265
  const script = path.join(workdir, "scripts", "ci", "migration-lint.mjs");
96
266
  const result = await execa("node", [script, ...files], {
@@ -120,9 +290,74 @@ export async function runPreprGate(workdir, deps = {}) {
120
290
  }
121
291
  const readScripts = deps.readScripts ?? defaultReadScripts;
122
292
  const runGate = deps.runGate ?? defaultRunGate;
123
- const scripts = await readScripts(workdir);
124
293
  const ran = [];
125
294
  const absent = [];
295
+ let scopeShadow;
296
+ // V96 (R4/R5): staged-file checks run FIRST — they are cheap and catch the
297
+ // exact classes typecheck/lint/build cannot (a NUL byte tsc accepts inside a
298
+ // string; an out-of-scope edit). Gated on baseRef / injected dep so the unit
299
+ // suite (which provides neither) never shells out to git.
300
+ if (deps.listStagedFiles || deps.baseRef) {
301
+ const listStagedFiles = deps.listStagedFiles ?? defaultListStagedFiles;
302
+ const readFileBytes = deps.readFileBytes ?? defaultReadFileBytes;
303
+ const staged = await listStagedFiles(workdir, deps.baseRef);
304
+ // (a) BINARY/NUL check — always-on structural guard (not a knob). Any staged
305
+ // text-extension file that git will treat as binary (a raw NUL byte, or
306
+ // UTF-16 which is riddled with NULs) FAILS the gate with file + byte offset.
307
+ ran.push("nul-check");
308
+ for (const file of staged) {
309
+ if (!isTextSourcePath(file))
310
+ continue;
311
+ let buf;
312
+ try {
313
+ buf = await readFileBytes(workdir, file);
314
+ }
315
+ catch {
316
+ continue; // unreadable (e.g. deleted after diff) — not our failure to raise
317
+ }
318
+ const offset = firstNulOffset(buf);
319
+ if (offset >= 0) {
320
+ const { line, col } = lineColOf(buf, offset);
321
+ const hit = { path: file, offset, line, col };
322
+ return {
323
+ ok: false,
324
+ skipped: false,
325
+ ran,
326
+ absent,
327
+ failure: {
328
+ gate: "nul-check",
329
+ exitCode: 1,
330
+ outputTail: formatNulFailure(hit),
331
+ },
332
+ };
333
+ }
334
+ }
335
+ // (b) SCOPE check — staged files vs the task's `allowed` globs. Only when the
336
+ // task declares a scope (non-empty globs). Enforcement is a DEFAULT-OFF knob:
337
+ // ON → HALT (fail gate); OFF → advisory (scopeShadow, PR still opens).
338
+ const globs = (deps.allowedGlobs ?? []).filter((g) => g && g.trim().length > 0);
339
+ if (globs.length > 0) {
340
+ const offending = scopeViolations(staged, globs);
341
+ if (offending.length > 0) {
342
+ ran.push("scope");
343
+ const detail = `staged file(s) outside the task's allowed scope:\n` +
344
+ offending.map((f) => ` - ${f}`).join("\n") +
345
+ `\nallowed globs:\n` +
346
+ globs.map((g) => ` - ${g}`).join("\n");
347
+ if (scopeEnforceResolved(deps.scopeEnforce, env)) {
348
+ return {
349
+ ok: false,
350
+ skipped: false,
351
+ ran,
352
+ absent,
353
+ failure: { gate: "scope", exitCode: 1, outputTail: detail.slice(-OUTPUT_TAIL) },
354
+ };
355
+ }
356
+ scopeShadow = { offending, outputTail: detail.slice(-OUTPUT_TAIL) };
357
+ }
358
+ }
359
+ }
360
+ const scripts = await readScripts(workdir);
126
361
  for (const gate of PREPR_GATES) {
127
362
  if (!scripts[gate]) {
128
363
  absent.push(gate);
@@ -154,20 +389,36 @@ export async function runPreprGate(workdir, deps = {}) {
154
389
  ran.push("migration-lint");
155
390
  const { exitCode, output } = await runMigrationLint(workdir, migrations);
156
391
  if (exitCode !== 0) {
392
+ const blocking = migrationLintBlockingResolved(deps.migrationLintBlocking, env);
393
+ if (blocking) {
394
+ // Blocking mode: a lint ERROR fails the gate — no PR is opened and the
395
+ // linter output lands in the runner log via failure.outputTail.
396
+ return {
397
+ ok: false,
398
+ skipped: false,
399
+ ran,
400
+ absent,
401
+ failure: {
402
+ gate: "migration-lint",
403
+ exitCode,
404
+ outputTail: output.slice(-OUTPUT_TAIL),
405
+ },
406
+ };
407
+ }
408
+ // Shadow mode: advisory only — surface the findings for logging but do
409
+ // NOT block the PR. (The linter itself exits 0 on warning-only findings,
410
+ // so reaching here means a genuine lint ERROR that shadow week tolerates.)
157
411
  return {
158
- ok: false,
412
+ ok: true,
159
413
  skipped: false,
160
414
  ran,
161
415
  absent,
162
- failure: {
163
- gate: "migration-lint",
164
- exitCode,
165
- outputTail: output.slice(-OUTPUT_TAIL),
166
- },
416
+ migrationLintShadow: { exitCode, outputTail: output.slice(-OUTPUT_TAIL) },
417
+ scopeShadow,
167
418
  };
168
419
  }
169
420
  }
170
421
  }
171
- return { ok: true, skipped: false, ran, absent };
422
+ return { ok: true, skipped: false, ran, absent, scopeShadow };
172
423
  }
173
424
  //# sourceMappingURL=prepr-gate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepr-gate.js","sourceRoot":"","sources":["../src/prepr-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAa5C;;;;;GAK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,EAAE,KAAK;wBACT,OAAO,EAAE,KAAK;wBACd,GAAG;wBACH,MAAM;wBACN,OAAO,EAAE;4BACP,IAAI,EAAE,gBAAgB;4BACtB,QAAQ;4BACR,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC;yBACvC;qBACF,CAAC;gBACJ,CAAC;gBACD,uEAAuE;gBACvE,yEAAyE;gBACzE,2EAA2E;gBAC3E,OAAO;oBACL,EAAE,EAAE,IAAI;oBACR,OAAO,EAAE,KAAK;oBACd,GAAG;oBACH,MAAM;oBACN,mBAAmB,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,EAAE;oBACzE,WAAW;iBACZ,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AAChE,CAAC"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Centralised resolution of how the spawned
3
+ * `claude` CLI authenticates with Anthropic.
4
+ *
5
+ * Claude Code authenticates *strictly* via the `ANTHROPIC_API_KEY`
6
+ * environment variable (or an apiKeyHelper) — it has no `--api-key` flag;
7
+ * passing one fails with `error: unknown option '--api-key'`. So "passing
8
+ * the API key to claude" means making sure the variable is present in the
9
+ * spawned subprocess's environment.
10
+ *
11
+ * When ANTHROPIC_API_KEY is set the CLI bills against the API account, which
12
+ * has no per-session usage cap. When it is absent the CLI falls back to the
13
+ * operator's interactive OAuth session, which is subject to the 429 session
14
+ * caps this change exists to avoid.
15
+ *
16
+ * M4 (ENGINE-CODEX): this module was renamed anthropic-auth.ts →
17
+ * provider-auth.ts and extended to cover the OpenAI Codex CLI as well, which
18
+ * has TWO auth channels (see §0.1.5 of the multi-model plan): an `api-key`
19
+ * mode driven by `OPENAI_API_KEY` (keychain/env) and a `subscription` mode
20
+ * driven by a stored ChatGPT login session. The Anthropic helpers are
21
+ * unchanged (byte-identical) so existing call sites keep their behaviour.
22
+ */
23
+ export type AnthropicAuthMode = "api-key" | "interactive-session";
24
+ /** Trimmed ANTHROPIC_API_KEY from `env`, or "" when unset/blank. */
25
+ export declare function anthropicApiKey(env?: NodeJS.ProcessEnv): string;
26
+ /**
27
+ * Opt-in claude-config isolation. Even with ANTHROPIC_API_KEY
28
+ * set, the Claude CLI prefers a stored claude.ai OAuth login when one exists —
29
+ * the observed cause of 429 session caps on a key-configured runner. Pointing
30
+ * the spawned claude at an isolated CLAUDE_CONFIG_DIR (no stored login) leaves
31
+ * the env key as the only credential, forcing API-key auth. Opt-in via
32
+ * ACC_RUNNER_ISOLATE_CLAUDE_CONFIG because the behaviour needs live-runner
33
+ * validation before becoming default.
34
+ */
35
+ export declare function claudeConfigIsolationEnabled(env?: NodeJS.ProcessEnv): boolean;
36
+ /** Runner-owned claude config dir used when isolation is enabled. */
37
+ export declare function isolatedClaudeConfigDir(env?: NodeJS.ProcessEnv): string;
38
+ /**
39
+ * `"api-key"` when ANTHROPIC_API_KEY is set (non-blank), else
40
+ * `"interactive-session"`.
41
+ */
42
+ export declare function resolveAuthMode(env?: NodeJS.ProcessEnv): AnthropicAuthMode;
43
+ /**
44
+ * Returns `base` with ANTHROPIC_API_KEY explicitly forwarded (trimmed) when
45
+ * set, so every claude spawn site authenticates identically regardless of how
46
+ * `base` was assembled. A passthrough of `base` when the key is absent — the
47
+ * CLI then uses the operator's interactive OAuth session.
48
+ */
49
+ export declare function withAnthropicAuth(base?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
50
+ /** One-line, human-readable description of an auth mode for banners/checks. */
51
+ export declare function describeAuthMode(mode: AnthropicAuthMode): string;
52
+ /**
53
+ * Precedence hint for the banner / doctor. Returns null when
54
+ * there's nothing to add (interactive-session mode is already self-explanatory
55
+ * via describeAuthMode). In api-key mode it tells the operator either that
56
+ * isolation is forcing the key, or — if not isolated — how to stop a claude.ai
57
+ * login from shadowing the key and causing 429s.
58
+ */
59
+ export declare function authPrecedenceHint(env?: NodeJS.ProcessEnv): string | null;
60
+ /** How the codex CLI authenticates for a given spawn. */
61
+ export type CodexAuthMode = "api-key" | "subscription";
62
+ /**
63
+ * Preference resolved from `auth_preference` (plan §0.1.5). `subscription_first`
64
+ * starts on the subscription session and spills to the api-key on a cap-hit;
65
+ * `api_key_first` starts on the key. Defaults to `subscription_first` — the
66
+ * program's cost-saving default — so an unset preference behaves as the plan
67
+ * specifies.
68
+ */
69
+ export type CodexAuthPreference = "subscription_first" | "api_key_first";
70
+ /**
71
+ * The per-provider keychain account under the frozen `acc-runner` service.
72
+ * FROZEN-CONTRACT EXTENSION (Track-A note): this ADDS a namespaced account
73
+ * (`provider:openai`) alongside the existing `default` session entry — the
74
+ * session schema in keychain.ts is untouched, so a Track-A review only needs
75
+ * to bless the new account name, not a shape change. The value is the raw
76
+ * OPENAI_API_KEY string (never a JSON blob), so it round-trips through keytar
77
+ * without colliding with the StoredSession JSON at `default`.
78
+ */
79
+ export declare const OPENAI_KEYCHAIN_ACCOUNT: "provider:openai";
80
+ /** Trimmed OPENAI_API_KEY from `env`, or "" when unset/blank. */
81
+ export declare function openaiApiKey(env?: NodeJS.ProcessEnv): string;
82
+ /**
83
+ * Read the OPENAI_API_KEY from the OS keychain (per-provider account). Returns
84
+ * "" when absent, keytar is unavailable (headless Linux without libsecret), or
85
+ * the entry is empty. Async because keychain access is — the sync spawn path
86
+ * (`withOpenAiAuth`) only ever reads the env-present key, exactly like the
87
+ * Anthropic path; the keychain is consulted by startup/doctor which can await.
88
+ */
89
+ export declare function openaiApiKeyFromKeychain(): Promise<string>;
90
+ /**
91
+ * Resolve the `auth_preference` string into a typed preference. Accepts the
92
+ * env-string forms and the DB spelling; anything unknown/blank falls back to
93
+ * the `subscription_first` default.
94
+ */
95
+ export declare function resolveCodexAuthPreference(raw: string | null | undefined): CodexAuthPreference;
96
+ /**
97
+ * The auth mode a codex spawn should START in, given the preference and whether
98
+ * an api key is present. `subscription_first` uses subscription; `api_key_first`
99
+ * uses the key when one is available (else subscription). This is the FIRST
100
+ * attempt only — the spill to api-key on a `subscription_exhausted` cap-hit is
101
+ * driven by the (future, M5) task-runner orchestration, which re-invokes with
102
+ * mode "api-key" explicitly.
103
+ */
104
+ export declare function initialCodexAuthMode(preference: CodexAuthPreference, hasApiKey: boolean): CodexAuthMode;
105
+ /** One-line, human-readable description of a codex auth mode for banners/checks. */
106
+ export declare function describeCodexAuthMode(mode: CodexAuthMode): string;
107
+ /**
108
+ * Augment `base` for a codex spawn in the given auth mode:
109
+ * - "api-key": OPENAI_API_KEY is forwarded (trimmed) so codex bills the
110
+ * key. A passthrough when the key is absent — codex then
111
+ * errors on missing auth, surfaced as `auth_expired`.
112
+ * - "subscription": OPENAI_API_KEY is REMOVED from the environment so codex
113
+ * cannot silently bill the key and instead uses the stored
114
+ * ChatGPT login (the mirror of the claude config-isolation
115
+ * concern: a stray key must not shadow the subscription we
116
+ * deliberately chose to try first).
117
+ * Never mutates `base`; returns a shallow copy.
118
+ */
119
+ export declare function withOpenAiAuth(mode: CodexAuthMode, base?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
120
+ //# sourceMappingURL=provider-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-auth.d.ts","sourceRoot":"","sources":["../src/provider-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,qBAAqB,CAAC;AAElE,oEAAoE;AACpE,wBAAgB,eAAe,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAE5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAGT;AAED,qEAAqE;AACrE,wBAAgB,uBAAuB,CACrC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,C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