@vaultcompass/conductor 0.8.0 → 0.9.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 (44) hide show
  1. package/README.md +263 -77
  2. package/dist/cli.js +152 -30
  3. package/dist/envelope.d.ts +8 -0
  4. package/dist/exit-codes.d.ts +52 -2
  5. package/dist/exit-codes.js +64 -14
  6. package/dist/external-config.d.ts +2 -1
  7. package/dist/external-config.js +33 -18
  8. package/dist/gate-runner.d.ts +141 -17
  9. package/dist/gate-runner.js +537 -83
  10. package/dist/git.d.ts +95 -0
  11. package/dist/git.js +244 -0
  12. package/dist/init-policy.js +38 -2
  13. package/dist/init.js +40 -3
  14. package/dist/intent-base.d.ts +35 -1
  15. package/dist/intent-base.js +124 -64
  16. package/dist/intent-prepare.d.ts +33 -2
  17. package/dist/intent-prepare.js +443 -34
  18. package/dist/intent-spec.d.ts +28 -0
  19. package/dist/intent-spec.js +22 -5
  20. package/dist/normalize.d.ts +11 -0
  21. package/dist/normalize.js +60 -6
  22. package/dist/osv-baseline.d.ts +84 -0
  23. package/dist/osv-baseline.js +325 -0
  24. package/dist/osv-coverage.d.ts +80 -0
  25. package/dist/osv-coverage.js +223 -0
  26. package/dist/output-sarif.js +55 -15
  27. package/dist/output-text.d.ts +53 -2
  28. package/dist/output-text.js +287 -27
  29. package/dist/policy.d.ts +10 -0
  30. package/dist/policy.js +21 -7
  31. package/dist/products.d.ts +32 -10
  32. package/dist/products.js +73 -9
  33. package/dist/requirements-pin.d.ts +47 -0
  34. package/dist/requirements-pin.js +256 -0
  35. package/dist/resolve.d.ts +1 -0
  36. package/dist/resolve.js +1 -1
  37. package/dist/run.d.ts +21 -0
  38. package/dist/run.js +74 -15
  39. package/dist/trust-base.d.ts +101 -20
  40. package/dist/trust-base.js +219 -73
  41. package/dist/unread-manifests.d.ts +14 -0
  42. package/dist/unread-manifests.js +69 -0
  43. package/package.json +1 -1
  44. package/schema/guardrails.schema.json +4 -0
package/dist/git.d.ts ADDED
@@ -0,0 +1,95 @@
1
+ export interface GitResult {
2
+ status: number | null;
3
+ stdout: string;
4
+ stderr: string;
5
+ /** Set when git could not be started at all. */
6
+ error: Error | undefined;
7
+ }
8
+ /** The program every git call in this process runs. */
9
+ export declare function currentGitProgram(): string;
10
+ /**
11
+ * Pins the git program for the rest of this process. The CLI calls it once
12
+ * on a pull-request run, with an absolute path; tests call it to reset.
13
+ */
14
+ export declare function useGitProgram(program: string): void;
15
+ /** Runs one git command in `cwd`, reading stdout as UTF-8. Never throws. */
16
+ export declare function runGit(cwd: string, args: readonly string[], options?: {
17
+ maxBuffer?: number;
18
+ input?: string;
19
+ }): GitResult;
20
+ /**
21
+ * Runs one git command in `cwd` and keeps stdout as BYTES. For a blob that is
22
+ * copied out byte for byte (the osv gate's base copies): decoding it as UTF-8
23
+ * would rewrite a file with invalid bytes before anything read it. Same
24
+ * program, same environment and same never-throws contract as runGit.
25
+ */
26
+ export declare function runGitBytes(cwd: string, args: readonly string[], options?: {
27
+ maxBuffer?: number;
28
+ }): {
29
+ status: number | null;
30
+ stdout: Buffer;
31
+ stderr: string;
32
+ error: Error | undefined;
33
+ };
34
+ /**
35
+ * A PATH with every entry that would resolve against the working directory
36
+ * removed: an empty entry (which means the current directory) and a relative
37
+ * one. Returns the cleaned value and what was removed, in order.
38
+ *
39
+ * Used on a run with a trust base, where the working directory of nearly
40
+ * every child is the tree under judgment, so that every PATH lookup, for
41
+ * git, for node in a gate's "#!/usr/bin/env node" line, or for a gate,
42
+ * resolves against an absolute directory.
43
+ */
44
+ export declare function absolutePathEntries(pathValue: string): {
45
+ value: string;
46
+ removed: string[];
47
+ };
48
+ /**
49
+ * The nearest directory at or above `start` holding a `.git` entry (the
50
+ * work tree a git run from `start` would find), resolved, or null. Found
51
+ * without running git, because it decides which git may be run.
52
+ */
53
+ export declare function workTreeAbove(start: string): string | null;
54
+ /**
55
+ * The first git on `pathValue` whose real path (symlinks resolved) is
56
+ * outside every root in `excluded`, as that real path, or null when there
57
+ * is none. Only absolute PATH entries are considered.
58
+ */
59
+ export declare function gitOutside(pathValue: string, excluded: readonly string[]): string | null;
60
+ /**
61
+ * Pins every git call in this process to the first git on `pathValue` that
62
+ * is outside the given work trees, and returns it; null, with nothing
63
+ * pinned, when there is none. Called once on a pull-request run.
64
+ */
65
+ export declare function pinGitOutside(pathValue: string, excluded: readonly string[]): string | null;
66
+ /** Whether the pinned git program's real path is inside `root`. */
67
+ export declare function pinnedGitInside(root: string): boolean;
68
+ /** Whether `candidate`'s real path is `root`'s real path or under it. */
69
+ export declare function realPathInside(root: string, candidate: string): boolean;
70
+ /** The name every private git directory starts with, under the temp directory. */
71
+ export declare const GIT_SHIM_PREFIX = "conductor-git-";
72
+ /**
73
+ * On a run with a trust base: creates the private directory that goes first
74
+ * on PATH for every child the run starts, so that a gate, or anything a gate
75
+ * starts, that looks git up by name runs the pinned `program` and never a git
76
+ * found in a PATH entry inside the tree being judged.
77
+ *
78
+ * The directory is a fresh mkdtemp directory under `tempRoot`, mode 0700,
79
+ * holding exactly one entry, `git`, a symbolic link to `program`, so no other
80
+ * lookup is shadowed. git finds its helpers through its own exec path, not
81
+ * through PATH, so a link is enough. Throws, with a sentence saying why and
82
+ * what to set, when `tempRoot` is inside one of `excluded` or the directory
83
+ * cannot be made; it never returns an unprotected result silently.
84
+ *
85
+ * On Windows it creates nothing and returns null: a symbolic link needs a
86
+ * privilege there, and a git.cmd wrapper is not found by a child that starts
87
+ * git without a shell. There the gates look git up through the cleaned PATH.
88
+ */
89
+ export declare function createGitShim(program: string, tempRoot: string, excluded: readonly string[], platform?: NodeJS.Platform): string | null;
90
+ /** Why a run cannot go ahead when the temp directory is inside the tree. */
91
+ export declare function tempInsideTreeMessage(tempRoot: string): string;
92
+ /** Removes a directory createGitShim made. Never throws. */
93
+ export declare function removeGitShim(dir: string): void;
94
+ /** git's first line of complaint, without a trailing full stop. */
95
+ export declare function gitComplaint(result: GitResult): string;
package/dist/git.js ADDED
@@ -0,0 +1,244 @@
1
+ // Every git command the umbrella runs itself, through one door.
2
+ //
3
+ // Three properties hold for each of them, and keeping the calls in one place
4
+ // is what lets that be said once rather than checked at a dozen call sites:
5
+ //
6
+ // - THE PROGRAM. On a pull-request run the caller pins git to one absolute
7
+ // path, outside the repository's work tree, before anything else runs
8
+ // (`pinGitOutside`), so every git call here runs that program and no
9
+ // other. Outside pull-request mode this is plain `git`, found the way a
10
+ // shell finds it.
11
+ //
12
+ // - REPLACE OBJECTS ARE IGNORED. GIT_NO_REPLACE_OBJECTS is set on every
13
+ // call, so every read here sees the commit's own objects.
14
+ //
15
+ // - NOTHING HERE DECIDES WHAT A FAILURE MEANS. The result carries the exit
16
+ // status and the error, and each caller keeps "git said there is nothing
17
+ // there" apart from "git could not answer", because the second is never
18
+ // a reason to treat a trusted file as absent.
19
+ import { spawnSync } from 'node:child_process';
20
+ import { accessSync, chmodSync, constants, existsSync, mkdtempSync, realpathSync, rmSync, statSync, symlinkSync, } from 'node:fs';
21
+ import path from 'node:path';
22
+ let gitProgram = 'git';
23
+ /** The program every git call in this process runs. */
24
+ export function currentGitProgram() {
25
+ return gitProgram;
26
+ }
27
+ /**
28
+ * Pins the git program for the rest of this process. The CLI calls it once
29
+ * on a pull-request run, with an absolute path; tests call it to reset.
30
+ */
31
+ export function useGitProgram(program) {
32
+ gitProgram = program;
33
+ }
34
+ /** Runs one git command in `cwd`, reading stdout as UTF-8. Never throws. */
35
+ export function runGit(cwd, args, options = {}) {
36
+ const child = spawnSync(gitProgram, [...args], {
37
+ cwd,
38
+ encoding: 'utf8',
39
+ maxBuffer: options.maxBuffer ?? 32 * 1024 * 1024,
40
+ env: { ...process.env, GIT_NO_REPLACE_OBJECTS: '1' },
41
+ ...(options.input === undefined ? {} : { input: options.input }),
42
+ });
43
+ return {
44
+ status: child.status,
45
+ stdout: typeof child.stdout === 'string' ? child.stdout : '',
46
+ stderr: typeof child.stderr === 'string' ? child.stderr : '',
47
+ error: child.error,
48
+ };
49
+ }
50
+ /**
51
+ * Runs one git command in `cwd` and keeps stdout as BYTES. For a blob that is
52
+ * copied out byte for byte (the osv gate's base copies): decoding it as UTF-8
53
+ * would rewrite a file with invalid bytes before anything read it. Same
54
+ * program, same environment and same never-throws contract as runGit.
55
+ */
56
+ export function runGitBytes(cwd, args, options = {}) {
57
+ const child = spawnSync(gitProgram, [...args], {
58
+ cwd,
59
+ maxBuffer: options.maxBuffer ?? 64 * 1024 * 1024,
60
+ env: { ...process.env, GIT_NO_REPLACE_OBJECTS: '1' },
61
+ });
62
+ return {
63
+ status: child.status,
64
+ stdout: Buffer.isBuffer(child.stdout) ? child.stdout : Buffer.alloc(0),
65
+ stderr: Buffer.isBuffer(child.stderr) ? child.stderr.toString('utf8') : '',
66
+ error: child.error,
67
+ };
68
+ }
69
+ /**
70
+ * A PATH with every entry that would resolve against the working directory
71
+ * removed: an empty entry (which means the current directory) and a relative
72
+ * one. Returns the cleaned value and what was removed, in order.
73
+ *
74
+ * Used on a run with a trust base, where the working directory of nearly
75
+ * every child is the tree under judgment, so that every PATH lookup, for
76
+ * git, for node in a gate's "#!/usr/bin/env node" line, or for a gate,
77
+ * resolves against an absolute directory.
78
+ */
79
+ export function absolutePathEntries(pathValue) {
80
+ const kept = [];
81
+ const removed = [];
82
+ for (const entry of pathValue.split(path.delimiter)) {
83
+ if (entry !== '' && path.isAbsolute(entry)) {
84
+ kept.push(entry);
85
+ }
86
+ else {
87
+ removed.push(entry);
88
+ }
89
+ }
90
+ return { value: kept.join(path.delimiter), removed };
91
+ }
92
+ /** Whether `candidate` (already resolved) is `root` or under it. */
93
+ function isInside(root, candidate) {
94
+ const relative = path.relative(root, candidate);
95
+ return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
96
+ }
97
+ function realOrNull(candidate) {
98
+ try {
99
+ return realpathSync(candidate);
100
+ }
101
+ catch {
102
+ return null;
103
+ }
104
+ }
105
+ /**
106
+ * The nearest directory at or above `start` holding a `.git` entry (the
107
+ * work tree a git run from `start` would find), resolved, or null. Found
108
+ * without running git, because it decides which git may be run.
109
+ */
110
+ export function workTreeAbove(start) {
111
+ let current = realOrNull(start);
112
+ while (current !== null) {
113
+ if (existsSync(path.join(current, '.git'))) {
114
+ return current;
115
+ }
116
+ const parent = path.dirname(current);
117
+ if (parent === current) {
118
+ return null;
119
+ }
120
+ current = parent;
121
+ }
122
+ return null;
123
+ }
124
+ /**
125
+ * The first git on `pathValue` whose real path (symlinks resolved) is
126
+ * outside every root in `excluded`, as that real path, or null when there
127
+ * is none. Only absolute PATH entries are considered.
128
+ */
129
+ export function gitOutside(pathValue, excluded) {
130
+ const roots = excluded.map((root) => realOrNull(root) ?? root);
131
+ for (const dir of pathValue.split(path.delimiter)) {
132
+ if (dir === '' || !path.isAbsolute(dir)) {
133
+ continue;
134
+ }
135
+ const real = realOrNull(path.join(dir, 'git'));
136
+ if (real === null) {
137
+ continue;
138
+ }
139
+ try {
140
+ if (!statSync(real).isFile()) {
141
+ continue;
142
+ }
143
+ accessSync(real, constants.X_OK);
144
+ }
145
+ catch {
146
+ continue;
147
+ }
148
+ if (roots.some((root) => isInside(root, real))) {
149
+ continue;
150
+ }
151
+ return real;
152
+ }
153
+ return null;
154
+ }
155
+ /**
156
+ * Pins every git call in this process to the first git on `pathValue` that
157
+ * is outside the given work trees, and returns it; null, with nothing
158
+ * pinned, when there is none. Called once on a pull-request run.
159
+ */
160
+ export function pinGitOutside(pathValue, excluded) {
161
+ const chosen = gitOutside(pathValue, excluded);
162
+ if (chosen !== null) {
163
+ useGitProgram(chosen);
164
+ }
165
+ return chosen;
166
+ }
167
+ /** Whether the pinned git program's real path is inside `root`. */
168
+ export function pinnedGitInside(root) {
169
+ const real = realOrNull(gitProgram);
170
+ const resolvedRoot = realOrNull(root) ?? root;
171
+ return real !== null && path.isAbsolute(gitProgram) && isInside(resolvedRoot, real);
172
+ }
173
+ /** Whether `candidate`'s real path is `root`'s real path or under it. */
174
+ export function realPathInside(root, candidate) {
175
+ const real = realOrNull(candidate) ?? candidate;
176
+ return isInside(realOrNull(root) ?? root, real);
177
+ }
178
+ /** The name every private git directory starts with, under the temp directory. */
179
+ export const GIT_SHIM_PREFIX = 'conductor-git-';
180
+ /**
181
+ * On a run with a trust base: creates the private directory that goes first
182
+ * on PATH for every child the run starts, so that a gate, or anything a gate
183
+ * starts, that looks git up by name runs the pinned `program` and never a git
184
+ * found in a PATH entry inside the tree being judged.
185
+ *
186
+ * The directory is a fresh mkdtemp directory under `tempRoot`, mode 0700,
187
+ * holding exactly one entry, `git`, a symbolic link to `program`, so no other
188
+ * lookup is shadowed. git finds its helpers through its own exec path, not
189
+ * through PATH, so a link is enough. Throws, with a sentence saying why and
190
+ * what to set, when `tempRoot` is inside one of `excluded` or the directory
191
+ * cannot be made; it never returns an unprotected result silently.
192
+ *
193
+ * On Windows it creates nothing and returns null: a symbolic link needs a
194
+ * privilege there, and a git.cmd wrapper is not found by a child that starts
195
+ * git without a shell. There the gates look git up through the cleaned PATH.
196
+ */
197
+ export function createGitShim(program, tempRoot, excluded, platform = process.platform) {
198
+ if (platform === 'win32') {
199
+ return null;
200
+ }
201
+ const realTemp = realOrNull(tempRoot) ?? tempRoot;
202
+ if (excluded.some((root) => realPathInside(root, realTemp))) {
203
+ throw new Error(tempInsideTreeMessage(tempRoot));
204
+ }
205
+ let dir;
206
+ try {
207
+ dir = mkdtempSync(path.join(realTemp, GIT_SHIM_PREFIX));
208
+ chmodSync(dir, 0o700);
209
+ symlinkSync(program, path.join(dir, 'git'));
210
+ return dir;
211
+ }
212
+ catch (err) {
213
+ if (dir !== undefined) {
214
+ removeGitShim(dir);
215
+ }
216
+ throw new Error('conductor could not create the private git directory it puts first on PATH for the ' +
217
+ `gates under the system temporary directory (${tempRoot}): ` +
218
+ `${err instanceof Error ? err.message : String(err)}. ${SHIM_REMEDY}`);
219
+ }
220
+ }
221
+ const SHIM_REMEDY = 'Set TMPDIR to a writable directory outside the repository. Nothing was checked.';
222
+ /** Why a run cannot go ahead when the temp directory is inside the tree. */
223
+ export function tempInsideTreeMessage(tempRoot) {
224
+ return (`the system temporary directory (${tempRoot}) is inside the repository being judged, ` +
225
+ 'and on a pull-request run conductor keeps the directory it puts first on PATH for ' +
226
+ `the gates outside that tree. ${SHIM_REMEDY}`);
227
+ }
228
+ /** Removes a directory createGitShim made. Never throws. */
229
+ export function removeGitShim(dir) {
230
+ try {
231
+ rmSync(dir, { recursive: true, force: true });
232
+ }
233
+ catch {
234
+ // Nothing left to remove, or not removable; the run's outcome stands.
235
+ }
236
+ }
237
+ /** git's first line of complaint, without a trailing full stop. */
238
+ export function gitComplaint(result) {
239
+ if (result.error !== undefined) {
240
+ return `git could not be run: ${result.error.message}`;
241
+ }
242
+ const line = (result.stderr.trim().split('\n')[0] ?? '').replace(/\.+$/, '');
243
+ return line === '' ? `git exited ${result.status ?? -1}` : line;
244
+ }
@@ -112,6 +112,7 @@ export function renderPolicy(detected, frozenContractPath) {
112
112
  // ramp is already climbed and enforcing from the start is what stops a
113
113
  // frozen contract's protected paths from producing findings that never
114
114
  // fail the check (issue #57).
115
+ let unfrozenIntent = false;
115
116
  if (role === 'intent') {
116
117
  if (frozenContractPath !== null) {
117
118
  lines.push(` # A frozen contract already exists at ${frozenContractPath}, so this gate`);
@@ -119,6 +120,7 @@ export function renderPolicy(detected, frozenContractPath) {
119
120
  lines.push(' enforce: true');
120
121
  }
121
122
  else {
123
+ unfrozenIntent = true;
122
124
  lines.push(` # No frozen contract yet (${NATIVE_CONTRACT_PATH}), so this gate runs`);
123
125
  lines.push(' # and reports without failing the run. Once a contract is frozen,');
124
126
  lines.push(' # set this to true by hand: conductor init never rewrites this file');
@@ -129,9 +131,43 @@ export function renderPolicy(detected, frozenContractPath) {
129
131
  else {
130
132
  lines.push(' enforce: true');
131
133
  }
134
+ // Only the vulnerabilities gate compares a pull request with its base.
135
+ // Written as report for a fresh repository, so an existing backlog does
136
+ // not block every pull request from the first one; a parser default of
137
+ // block keeps every policy written before the key existed as strict as
138
+ // it was.
139
+ if (role === 'vulnerabilities') {
140
+ lines.push(' # On a pull request, findings already on the base branch are reported');
141
+ lines.push(' # and do not block; only advisories the pull request introduces do.');
142
+ lines.push(' # Set present-on-base: block to block on every known vulnerability.');
143
+ lines.push(' present-on-base: report');
144
+ }
132
145
  lines.push(' # Handed to this gate unchanged. Keys are its own long flags,');
133
- lines.push(' # without the leading dashes. Example: fail-on: high');
134
- lines.push(' options: {}');
146
+ lines.push(' # without the leading dashes.');
147
+ if (role === 'secrets-history') {
148
+ lines.push(' # gitleaks has no severity floor. Tune its rules in .gitleaks.toml and');
149
+ lines.push(' # accept an old finding in .gitleaksignore, not here.');
150
+ }
151
+ else if (role === 'vulnerabilities') {
152
+ lines.push(' # osv-scanner has no severity floor. Tune what it reports in');
153
+ lines.push(' # osv-scanner.toml, not here.');
154
+ }
155
+ else if (role === 'intent') {
156
+ lines.push(' # require-frozen: false lets the gate run and not block when no contract exists.');
157
+ }
158
+ else {
159
+ lines.push(' # Example: fail-on: high');
160
+ }
161
+ if (unfrozenIntent) {
162
+ // intent-guard blocks on a missing contract when require-frozen is true,
163
+ // its default. Without this key a full run prints a BLOCKING critical
164
+ // finding for the very state the unenforced ramp above exists for.
165
+ lines.push(' options:');
166
+ lines.push(' require-frozen: false');
167
+ }
168
+ else {
169
+ lines.push(' options: {}');
170
+ }
135
171
  }
136
172
  lines.push('', 'report:', ' format: text', '');
137
173
  return lines.join('\n');
package/dist/init.js CHANGED
@@ -65,7 +65,7 @@
65
65
  // and lost it at the next install, with the manifest still recording it
66
66
  // as installed. See detectManagedHook and declaredManagedHooks.
67
67
  import { execFileSync } from 'node:child_process';
68
- import { chmodSync, existsSync, mkdirSync, readdirSync, realpathSync, rmSync, rmdirSync, statSync, writeFileSync, } from 'node:fs';
68
+ import { chmodSync, closeSync, constants as fsConstants, existsSync, mkdirSync, openSync, readdirSync, realpathSync, rmSync, rmdirSync, statSync, writeFileSync, writeSync, } from 'node:fs';
69
69
  import path from 'node:path';
70
70
  import { DEP_GUARD_HOOK_MARKER, INTENT_GUARD_HOOK_MARKER, MANAGED_HOOK_MARKER, declaredManagedHooks, detectGateHook, detectGeneratedHook, detectManagedHook, editedManagedGuidance, foreignGuidance, gateHookGuidance, generatedHookGuidance, huskyDirectoryFor, huskyShimPresent, managedHooksGuidance, } from './init-hook-detect.js';
71
71
  import { MANIFEST_RELATIVE_PATH, manifestPathInsideRepo, readIfExists, readManifest, recordedHookSha, sha256, } from './init-manifest.js';
@@ -546,6 +546,31 @@ function finishPlanWithoutHook(options, root, policyPath, base, actions, writes,
546
546
  adoptedFrom: null,
547
547
  });
548
548
  }
549
+ /** The conflict for a manifest path that resolves outside the repository. */
550
+ function manifestOutsideConflict() {
551
+ return {
552
+ path: MANIFEST_RELATIVE_PATH,
553
+ reason: 'manifest-path-outside-repository',
554
+ guidance: `${MANIFEST_RELATIVE_PATH} resolves outside this repository (it, or .guardrails, is a ` +
555
+ 'symbolic link pointing out of the checkout), so nothing was written. Replace the link ' +
556
+ 'with a real directory or file inside the repository and re-run.',
557
+ };
558
+ }
559
+ /**
560
+ * Writes the manifest without following a symbolic link at its own path:
561
+ * O_NOFOLLOW where the platform has it, so a link swapped in after the
562
+ * containment check is refused by the kernel rather than followed.
563
+ */
564
+ function writeManifestFile(target, body) {
565
+ const noFollow = fsConstants.O_NOFOLLOW ?? 0;
566
+ const fd = openSync(target, fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_TRUNC | noFollow, 0o666);
567
+ try {
568
+ writeSync(fd, body);
569
+ }
570
+ finally {
571
+ closeSync(fd);
572
+ }
573
+ }
549
574
  export function applyInit(plan, options) {
550
575
  if (!plan.ok || plan.dryRun || plan.alreadyInstalled) {
551
576
  return plan;
@@ -572,6 +597,11 @@ export function applyInit(plan, options) {
572
597
  // but the adopted record is carried forward from the committed manifest, and
573
598
  // a write that lands outside the repository is a write apply should refuse
574
599
  // whatever produced the path.
600
+ // The manifest's own path first, and before any write at all, so the
601
+ // manifest is written inside the repository or nothing is written.
602
+ if (!manifestPathInsideRepo(plan.repoRoot, path.join(plan.repoRoot, MANIFEST_RELATIVE_PATH))) {
603
+ return { ...plan, ok: false, conflicts: [...plan.conflicts, manifestOutsideConflict()] };
604
+ }
575
605
  const escaping = [
576
606
  ...plan.writes.map((write) => write.path),
577
607
  ...(manifest.adopted === null ? [] : [manifest.adopted.path]),
@@ -627,7 +657,7 @@ export function applyInit(plan, options) {
627
657
  }
628
658
  const manifestPath = path.join(plan.repoRoot, MANIFEST_RELATIVE_PATH);
629
659
  mkdirSync(path.dirname(manifestPath), { recursive: true });
630
- writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
660
+ writeManifestFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
631
661
  }
632
662
  catch (err) {
633
663
  return {
@@ -693,6 +723,13 @@ export function revertInit(options) {
693
723
  return { ok: false, actions, conflicts, dryRun };
694
724
  }
695
725
  const manifestPath = path.join(root, MANIFEST_RELATIVE_PATH);
726
+ // The manifest itself is contained like every path it names: revert
727
+ // rewrites or removes it, and a symlinked .guardrails (or manifest) would
728
+ // land that write outside the repository.
729
+ if (!manifestPathInsideRepo(root, manifestPath)) {
730
+ conflicts.push(manifestOutsideConflict());
731
+ return { ok: false, actions, conflicts, dryRun };
732
+ }
696
733
  const raw = readIfExists(manifestPath);
697
734
  if (raw === undefined) {
698
735
  conflicts.push({
@@ -883,7 +920,7 @@ export function revertInit(options) {
883
920
  }
884
921
  // Something is left, so the manifest stays and keeps describing it.
885
922
  if (!dryRun) {
886
- writeFileSync(manifestPath, `${JSON.stringify({ ...manifest, files: remaining, adopted }, null, 2)}\n`, 'utf8');
923
+ writeManifestFile(manifestPath, `${JSON.stringify({ ...manifest, files: remaining, adopted }, null, 2)}\n`);
887
924
  }
888
925
  actions.push({
889
926
  kind: 'skip',
@@ -1,7 +1,7 @@
1
1
  export interface BaseResolution {
2
2
  ref: string;
3
3
  /** Which input named it, so the report can say. */
4
- source: 'flag' | 'github';
4
+ source: 'flag' | 'github' | 'trust-base';
5
5
  }
6
6
  export type ChangedPaths = {
7
7
  ok: true;
@@ -43,6 +43,8 @@ export type ResolvedBase = {
43
43
  * both in full. The private ref wins and is not compared against the
44
44
  * remote-tracking ref. If neither exists the spelled remote ref is returned and the
45
45
  * diff fails closed, naming fetch-depth: 0.
46
+ * - Otherwise, on a run with a trust base: the commit the trust base
47
+ * resolves to.
46
48
  * - Null outside a pull request.
47
49
  *
48
50
  * Nothing is deepened here: a depth-1 private ref has no merge base and the
@@ -50,6 +52,7 @@ export type ResolvedBase = {
50
52
  */
51
53
  export declare function resolveBaseRefInRepo(repoRoot: string, options: {
52
54
  base?: string;
55
+ trustBase?: string;
53
56
  env: NodeJS.ProcessEnv;
54
57
  }): ResolvedBase;
55
58
  /**
@@ -81,3 +84,34 @@ export declare function currentBranch(repoRoot: string, env: NodeJS.ProcessEnv):
81
84
  * git error, because an empty path set is indistinguishable from a clean run.
82
85
  */
83
86
  export declare function changedPathsSince(repoRoot: string, base: string): ChangedPaths;
87
+ /**
88
+ * Why this change set cannot be handed to intent-guard as one `--paths`
89
+ * value, or null when it can.
90
+ *
91
+ * Asked only where `--paths` is the channel: a contract imported from a spec
92
+ * (its project is a temporary directory with no repository, so the gate
93
+ * cannot read the change set from git itself) or an intent-guard older than
94
+ * the release whose own `--base` reads the change set from git. Where the
95
+ * gate reads git itself, none of this applies and the change is judged.
96
+ *
97
+ * - A comma: `--paths` is comma-joined, so a comma in a filename arrives as
98
+ * two paths, a phantom that can be reported as outside allowed_paths and a
99
+ * real path that quietly stops being measured against a protected one.
100
+ * - A backslash: intent-guard refuses an explicit path list entry with one.
101
+ * - Leading or trailing whitespace: it cannot survive the list intact.
102
+ * - EVERY path starting with "-": intent-guard reads a `--paths` value that
103
+ * starts with "-" as a missing value, and there is no `--paths=value` form
104
+ * (verified against intent-guard 1.8.0: it is an unknown option). One path
105
+ * starting with "-" is fine once another leads the list
106
+ * (`orderForPathsFlag`), so this is refused only when every path does.
107
+ *
108
+ * A space or any other byte inside a path passes through unchanged.
109
+ */
110
+ export declare function pathsFlagRefusal(paths: readonly string[]): string | null;
111
+ /**
112
+ * The change set in the order it is joined for `--paths`: unchanged, except
113
+ * that when the first path starts with "-" the first path that does not is
114
+ * moved to the front, so the joined value does not start with "-". Order
115
+ * carries no meaning to the gate.
116
+ */
117
+ export declare function orderForPathsFlag(paths: readonly string[]): string[];