@vaultcompass/conductor 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -78
- package/dist/cli.js +204 -37
- package/dist/external-config.d.ts +2 -1
- package/dist/external-config.js +34 -13
- package/dist/gate-runner.d.ts +128 -17
- package/dist/gate-runner.js +365 -53
- package/dist/git.d.ts +80 -0
- package/dist/git.js +224 -0
- package/dist/init-policy.js +2 -1
- package/dist/init.js +40 -3
- package/dist/intent-base.d.ts +64 -1
- package/dist/intent-base.js +194 -40
- package/dist/intent-prepare.d.ts +33 -2
- package/dist/intent-prepare.js +448 -35
- package/dist/intent-spec.d.ts +28 -0
- package/dist/intent-spec.js +22 -5
- package/dist/normalize.d.ts +9 -0
- package/dist/normalize.js +19 -5
- package/dist/output-sarif.js +12 -13
- package/dist/output-text.d.ts +52 -2
- package/dist/output-text.js +150 -16
- package/dist/policy.js +9 -7
- package/dist/products.js +1 -1
- package/dist/resolve.d.ts +1 -0
- package/dist/resolve.js +1 -1
- package/dist/run.d.ts +8 -0
- package/dist/run.js +63 -13
- package/dist/trust-base.d.ts +133 -24
- package/dist/trust-base.js +353 -60
- package/package.json +1 -1
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
}): GitResult;
|
|
19
|
+
/**
|
|
20
|
+
* A PATH with every entry that would resolve against the working directory
|
|
21
|
+
* removed: an empty entry (which means the current directory) and a relative
|
|
22
|
+
* one. Returns the cleaned value and what was removed, in order.
|
|
23
|
+
*
|
|
24
|
+
* Used on a run with a trust base, where the working directory of nearly
|
|
25
|
+
* every child is the tree under judgment, so that every PATH lookup, for
|
|
26
|
+
* git, for node in a gate's "#!/usr/bin/env node" line, or for a gate,
|
|
27
|
+
* resolves against an absolute directory.
|
|
28
|
+
*/
|
|
29
|
+
export declare function absolutePathEntries(pathValue: string): {
|
|
30
|
+
value: string;
|
|
31
|
+
removed: string[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The nearest directory at or above `start` holding a `.git` entry (the
|
|
35
|
+
* work tree a git run from `start` would find), resolved, or null. Found
|
|
36
|
+
* without running git, because it decides which git may be run.
|
|
37
|
+
*/
|
|
38
|
+
export declare function workTreeAbove(start: string): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* The first git on `pathValue` whose real path (symlinks resolved) is
|
|
41
|
+
* outside every root in `excluded`, as that real path, or null when there
|
|
42
|
+
* is none. Only absolute PATH entries are considered.
|
|
43
|
+
*/
|
|
44
|
+
export declare function gitOutside(pathValue: string, excluded: readonly string[]): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Pins every git call in this process to the first git on `pathValue` that
|
|
47
|
+
* is outside the given work trees, and returns it; null, with nothing
|
|
48
|
+
* pinned, when there is none. Called once on a pull-request run.
|
|
49
|
+
*/
|
|
50
|
+
export declare function pinGitOutside(pathValue: string, excluded: readonly string[]): string | null;
|
|
51
|
+
/** Whether the pinned git program's real path is inside `root`. */
|
|
52
|
+
export declare function pinnedGitInside(root: string): boolean;
|
|
53
|
+
/** Whether `candidate`'s real path is `root`'s real path or under it. */
|
|
54
|
+
export declare function realPathInside(root: string, candidate: string): boolean;
|
|
55
|
+
/** The name every private git directory starts with, under the temp directory. */
|
|
56
|
+
export declare const GIT_SHIM_PREFIX = "conductor-git-";
|
|
57
|
+
/**
|
|
58
|
+
* On a run with a trust base: creates the private directory that goes first
|
|
59
|
+
* on PATH for every child the run starts, so that a gate, or anything a gate
|
|
60
|
+
* starts, that looks git up by name runs the pinned `program` and never a git
|
|
61
|
+
* found in a PATH entry inside the tree being judged.
|
|
62
|
+
*
|
|
63
|
+
* The directory is a fresh mkdtemp directory under `tempRoot`, mode 0700,
|
|
64
|
+
* holding exactly one entry, `git`, a symbolic link to `program`, so no other
|
|
65
|
+
* lookup is shadowed. git finds its helpers through its own exec path, not
|
|
66
|
+
* through PATH, so a link is enough. Throws, with a sentence saying why and
|
|
67
|
+
* what to set, when `tempRoot` is inside one of `excluded` or the directory
|
|
68
|
+
* cannot be made; it never returns an unprotected result silently.
|
|
69
|
+
*
|
|
70
|
+
* On Windows it creates nothing and returns null: a symbolic link needs a
|
|
71
|
+
* privilege there, and a git.cmd wrapper is not found by a child that starts
|
|
72
|
+
* git without a shell. There the gates look git up through the cleaned PATH.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createGitShim(program: string, tempRoot: string, excluded: readonly string[], platform?: NodeJS.Platform): string | null;
|
|
75
|
+
/** Why a run cannot go ahead when the temp directory is inside the tree. */
|
|
76
|
+
export declare function tempInsideTreeMessage(tempRoot: string): string;
|
|
77
|
+
/** Removes a directory createGitShim made. Never throws. */
|
|
78
|
+
export declare function removeGitShim(dir: string): void;
|
|
79
|
+
/** git's first line of complaint, without a trailing full stop. */
|
|
80
|
+
export declare function gitComplaint(result: GitResult): string;
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
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
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
status: child.status,
|
|
44
|
+
stdout: typeof child.stdout === 'string' ? child.stdout : '',
|
|
45
|
+
stderr: typeof child.stderr === 'string' ? child.stderr : '',
|
|
46
|
+
error: child.error,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A PATH with every entry that would resolve against the working directory
|
|
51
|
+
* removed: an empty entry (which means the current directory) and a relative
|
|
52
|
+
* one. Returns the cleaned value and what was removed, in order.
|
|
53
|
+
*
|
|
54
|
+
* Used on a run with a trust base, where the working directory of nearly
|
|
55
|
+
* every child is the tree under judgment, so that every PATH lookup, for
|
|
56
|
+
* git, for node in a gate's "#!/usr/bin/env node" line, or for a gate,
|
|
57
|
+
* resolves against an absolute directory.
|
|
58
|
+
*/
|
|
59
|
+
export function absolutePathEntries(pathValue) {
|
|
60
|
+
const kept = [];
|
|
61
|
+
const removed = [];
|
|
62
|
+
for (const entry of pathValue.split(path.delimiter)) {
|
|
63
|
+
if (entry !== '' && path.isAbsolute(entry)) {
|
|
64
|
+
kept.push(entry);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
removed.push(entry);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { value: kept.join(path.delimiter), removed };
|
|
71
|
+
}
|
|
72
|
+
/** Whether `candidate` (already resolved) is `root` or under it. */
|
|
73
|
+
function isInside(root, candidate) {
|
|
74
|
+
const relative = path.relative(root, candidate);
|
|
75
|
+
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
|
|
76
|
+
}
|
|
77
|
+
function realOrNull(candidate) {
|
|
78
|
+
try {
|
|
79
|
+
return realpathSync(candidate);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The nearest directory at or above `start` holding a `.git` entry (the
|
|
87
|
+
* work tree a git run from `start` would find), resolved, or null. Found
|
|
88
|
+
* without running git, because it decides which git may be run.
|
|
89
|
+
*/
|
|
90
|
+
export function workTreeAbove(start) {
|
|
91
|
+
let current = realOrNull(start);
|
|
92
|
+
while (current !== null) {
|
|
93
|
+
if (existsSync(path.join(current, '.git'))) {
|
|
94
|
+
return current;
|
|
95
|
+
}
|
|
96
|
+
const parent = path.dirname(current);
|
|
97
|
+
if (parent === current) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
current = parent;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The first git on `pathValue` whose real path (symlinks resolved) is
|
|
106
|
+
* outside every root in `excluded`, as that real path, or null when there
|
|
107
|
+
* is none. Only absolute PATH entries are considered.
|
|
108
|
+
*/
|
|
109
|
+
export function gitOutside(pathValue, excluded) {
|
|
110
|
+
const roots = excluded.map((root) => realOrNull(root) ?? root);
|
|
111
|
+
for (const dir of pathValue.split(path.delimiter)) {
|
|
112
|
+
if (dir === '' || !path.isAbsolute(dir)) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const real = realOrNull(path.join(dir, 'git'));
|
|
116
|
+
if (real === null) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
if (!statSync(real).isFile()) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
accessSync(real, constants.X_OK);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (roots.some((root) => isInside(root, real))) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
return real;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Pins every git call in this process to the first git on `pathValue` that
|
|
137
|
+
* is outside the given work trees, and returns it; null, with nothing
|
|
138
|
+
* pinned, when there is none. Called once on a pull-request run.
|
|
139
|
+
*/
|
|
140
|
+
export function pinGitOutside(pathValue, excluded) {
|
|
141
|
+
const chosen = gitOutside(pathValue, excluded);
|
|
142
|
+
if (chosen !== null) {
|
|
143
|
+
useGitProgram(chosen);
|
|
144
|
+
}
|
|
145
|
+
return chosen;
|
|
146
|
+
}
|
|
147
|
+
/** Whether the pinned git program's real path is inside `root`. */
|
|
148
|
+
export function pinnedGitInside(root) {
|
|
149
|
+
const real = realOrNull(gitProgram);
|
|
150
|
+
const resolvedRoot = realOrNull(root) ?? root;
|
|
151
|
+
return real !== null && path.isAbsolute(gitProgram) && isInside(resolvedRoot, real);
|
|
152
|
+
}
|
|
153
|
+
/** Whether `candidate`'s real path is `root`'s real path or under it. */
|
|
154
|
+
export function realPathInside(root, candidate) {
|
|
155
|
+
const real = realOrNull(candidate) ?? candidate;
|
|
156
|
+
return isInside(realOrNull(root) ?? root, real);
|
|
157
|
+
}
|
|
158
|
+
/** The name every private git directory starts with, under the temp directory. */
|
|
159
|
+
export const GIT_SHIM_PREFIX = 'conductor-git-';
|
|
160
|
+
/**
|
|
161
|
+
* On a run with a trust base: creates the private directory that goes first
|
|
162
|
+
* on PATH for every child the run starts, so that a gate, or anything a gate
|
|
163
|
+
* starts, that looks git up by name runs the pinned `program` and never a git
|
|
164
|
+
* found in a PATH entry inside the tree being judged.
|
|
165
|
+
*
|
|
166
|
+
* The directory is a fresh mkdtemp directory under `tempRoot`, mode 0700,
|
|
167
|
+
* holding exactly one entry, `git`, a symbolic link to `program`, so no other
|
|
168
|
+
* lookup is shadowed. git finds its helpers through its own exec path, not
|
|
169
|
+
* through PATH, so a link is enough. Throws, with a sentence saying why and
|
|
170
|
+
* what to set, when `tempRoot` is inside one of `excluded` or the directory
|
|
171
|
+
* cannot be made; it never returns an unprotected result silently.
|
|
172
|
+
*
|
|
173
|
+
* On Windows it creates nothing and returns null: a symbolic link needs a
|
|
174
|
+
* privilege there, and a git.cmd wrapper is not found by a child that starts
|
|
175
|
+
* git without a shell. There the gates look git up through the cleaned PATH.
|
|
176
|
+
*/
|
|
177
|
+
export function createGitShim(program, tempRoot, excluded, platform = process.platform) {
|
|
178
|
+
if (platform === 'win32') {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const realTemp = realOrNull(tempRoot) ?? tempRoot;
|
|
182
|
+
if (excluded.some((root) => realPathInside(root, realTemp))) {
|
|
183
|
+
throw new Error(tempInsideTreeMessage(tempRoot));
|
|
184
|
+
}
|
|
185
|
+
let dir;
|
|
186
|
+
try {
|
|
187
|
+
dir = mkdtempSync(path.join(realTemp, GIT_SHIM_PREFIX));
|
|
188
|
+
chmodSync(dir, 0o700);
|
|
189
|
+
symlinkSync(program, path.join(dir, 'git'));
|
|
190
|
+
return dir;
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
if (dir !== undefined) {
|
|
194
|
+
removeGitShim(dir);
|
|
195
|
+
}
|
|
196
|
+
throw new Error('conductor could not create the private git directory it puts first on PATH for the ' +
|
|
197
|
+
`gates under the system temporary directory (${tempRoot}): ` +
|
|
198
|
+
`${err instanceof Error ? err.message : String(err)}. ${SHIM_REMEDY}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const SHIM_REMEDY = 'Set TMPDIR to a writable directory outside the repository. Nothing was checked.';
|
|
202
|
+
/** Why a run cannot go ahead when the temp directory is inside the tree. */
|
|
203
|
+
export function tempInsideTreeMessage(tempRoot) {
|
|
204
|
+
return (`the system temporary directory (${tempRoot}) is inside the repository being judged, ` +
|
|
205
|
+
'and on a pull-request run conductor keeps the directory it puts first on PATH for ' +
|
|
206
|
+
`the gates outside that tree. ${SHIM_REMEDY}`);
|
|
207
|
+
}
|
|
208
|
+
/** Removes a directory createGitShim made. Never throws. */
|
|
209
|
+
export function removeGitShim(dir) {
|
|
210
|
+
try {
|
|
211
|
+
rmSync(dir, { recursive: true, force: true });
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
// Nothing left to remove, or not removable; the run's outcome stands.
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** git's first line of complaint, without a trailing full stop. */
|
|
218
|
+
export function gitComplaint(result) {
|
|
219
|
+
if (result.error !== undefined) {
|
|
220
|
+
return `git could not be run: ${result.error.message}`;
|
|
221
|
+
}
|
|
222
|
+
const line = (result.stderr.trim().split('\n')[0] ?? '').replace(/\.+$/, '');
|
|
223
|
+
return line === '' ? `git exited ${result.status ?? -1}` : line;
|
|
224
|
+
}
|
package/dist/init-policy.js
CHANGED
|
@@ -2,6 +2,7 @@ import { statSync } from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { NATIVE_CONTRACT_PATH } from './intent-prepare.js';
|
|
4
4
|
import { DEFAULT_STAGE_FOR_ROLE, GATE_ROLES, POLICY_FILE_NAME, PRODUCT_FOR_ROLE } from './policy.js';
|
|
5
|
+
import { installName } from './normalize.js';
|
|
5
6
|
import { CANDIDATES } from './resolve.js';
|
|
6
7
|
export { POLICY_FILE_NAME };
|
|
7
8
|
/** Names of the gates whose binary resolves right now. */
|
|
@@ -96,7 +97,7 @@ export function renderPolicy(detected, frozenContractPath) {
|
|
|
96
97
|
const enabled = detected.has(role);
|
|
97
98
|
lines.push(` # ${ROLE_DESCRIPTION[role]}`);
|
|
98
99
|
if (!enabled) {
|
|
99
|
-
lines.push(` # not found in node_modules/.bin or on PATH. Install ${product}, then set enabled: true.`);
|
|
100
|
+
lines.push(` # not found in node_modules/.bin or on PATH. Install ${installName(product)}, then set enabled: true.`);
|
|
100
101
|
}
|
|
101
102
|
lines.push(` ${role}:`);
|
|
102
103
|
lines.push(` product: ${product}`);
|
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
|
-
|
|
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
|
-
|
|
923
|
+
writeManifestFile(manifestPath, `${JSON.stringify({ ...manifest, files: remaining, adopted }, null, 2)}\n`);
|
|
887
924
|
}
|
|
888
925
|
actions.push({
|
|
889
926
|
kind: 'skip',
|
package/dist/intent-base.d.ts
CHANGED
|
@@ -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;
|
|
@@ -23,6 +23,38 @@ export declare function resolveBaseRef(options: {
|
|
|
23
23
|
base?: string;
|
|
24
24
|
env: NodeJS.ProcessEnv;
|
|
25
25
|
}): BaseResolution | null;
|
|
26
|
+
export type ResolvedBase = {
|
|
27
|
+
ok: true;
|
|
28
|
+
base: BaseResolution | null;
|
|
29
|
+
} | {
|
|
30
|
+
ok: false;
|
|
31
|
+
detail: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The base to diff against, resolved against the repository and always
|
|
35
|
+
* spelled so a tag cannot shadow it (the same class as the trust base: git
|
|
36
|
+
* resolves a short origin/<base> through refs/tags/ first, so a tag at
|
|
37
|
+
* HEAD~1 would narrow the change set to the last commit).
|
|
38
|
+
*
|
|
39
|
+
* - An explicit --base keeps its meaning, but a short name that matches
|
|
40
|
+
* more than one kind of ref is refused (refuseAmbiguousRef).
|
|
41
|
+
* - Otherwise, on a pull request: refs/conductor/trust-base (the composite
|
|
42
|
+
* action's private fetch) when it exists, else refs/remotes/origin/<base>,
|
|
43
|
+
* both in full. The private ref wins and is not compared against the
|
|
44
|
+
* remote-tracking ref. If neither exists the spelled remote ref is returned and the
|
|
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.
|
|
48
|
+
* - Null outside a pull request.
|
|
49
|
+
*
|
|
50
|
+
* Nothing is deepened here: a depth-1 private ref has no merge base and the
|
|
51
|
+
* diff fails closed, the same outcome as a depth-1 origin/<base> always had.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveBaseRefInRepo(repoRoot: string, options: {
|
|
54
|
+
base?: string;
|
|
55
|
+
trustBase?: string;
|
|
56
|
+
env: NodeJS.ProcessEnv;
|
|
57
|
+
}): ResolvedBase;
|
|
26
58
|
/**
|
|
27
59
|
* The branch this run is about.
|
|
28
60
|
*
|
|
@@ -52,3 +84,34 @@ export declare function currentBranch(repoRoot: string, env: NodeJS.ProcessEnv):
|
|
|
52
84
|
* git error, because an empty path set is indistinguishable from a clean run.
|
|
53
85
|
*/
|
|
54
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[];
|