@scopebond/hook 0.5.0 → 0.7.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.
- package/README.md +139 -12
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +667 -69
- package/dist/cli.js.map +1 -1
- package/dist/cloud.d.ts +2 -0
- package/dist/cloud.d.ts.map +1 -1
- package/dist/cloud.js +1 -1
- package/dist/cloud.js.map +1 -1
- package/dist/explain.d.ts +44 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +75 -0
- package/dist/explain.js.map +1 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +9 -3
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +36 -28
- package/dist/init.js.map +1 -1
- package/dist/install.d.ts +63 -3
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +242 -28
- package/dist/install.js.map +1 -1
- package/dist/map.d.ts +12 -3
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +765 -60
- package/dist/map.js.map +1 -1
- package/dist/minimize.d.ts +6 -3
- package/dist/minimize.d.ts.map +1 -1
- package/dist/minimize.js +24 -4
- package/dist/minimize.js.map +1 -1
- package/dist/rules.d.ts +51 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +216 -0
- package/dist/rules.js.map +1 -0
- package/dist/runtime-install.d.ts +25 -0
- package/dist/runtime-install.d.ts.map +1 -0
- package/dist/runtime-install.js +106 -0
- package/dist/runtime-install.js.map +1 -0
- package/dist/runtime.d.ts +17 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +122 -11
- package/dist/runtime.js.map +1 -1
- package/dist/shell.d.ts +53 -4
- package/dist/shell.d.ts.map +1 -1
- package/dist/shell.js +737 -81
- package/dist/shell.js.map +1 -1
- package/dist/version.d.ts +5 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +6 -2
- package/dist/version.js.map +1 -1
- package/package.json +3 -3
package/dist/install.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// SB112 — the user-level installer. One install per developer machine (not per repo):
|
|
2
2
|
// keys and a starter policy live in a user-level home (~/.scopebond, override
|
|
3
3
|
// SCOPEBOND_HOME), and the hook is registered by absolute path in the user-level agent
|
|
4
|
-
// config (~/.claude/settings.json, ~/.cursor/hooks.json, ~/.codex/hooks.json).
|
|
5
|
-
//
|
|
6
|
-
|
|
4
|
+
// config (~/.claude/settings.json, ~/.cursor/hooks.json, ~/.codex/hooks.json). When a
|
|
5
|
+
// user-level install exists, a project-local `.scopebond` is used only if the user
|
|
6
|
+
// trusted that exact policy (`scopebond trust`, or `init` in the project): a cloned
|
|
7
|
+
// repository, or an agent inside it, must not be able to swap in its own policy.
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { mkdirSync, writeFileSync, existsSync, readFileSync, rmSync, copyFileSync } from "node:fs";
|
|
7
10
|
import { homedir } from "node:os";
|
|
8
|
-
import { dirname, join } from "node:path";
|
|
11
|
+
import { dirname, join, resolve } from "node:path";
|
|
9
12
|
/** The user-level Scopebond home. `SCOPEBOND_HOME` overrides it (tests, CI). */
|
|
10
13
|
export function userHome() {
|
|
11
14
|
return process.env.SCOPEBOND_HOME ?? join(homedir(), ".scopebond");
|
|
@@ -19,10 +22,80 @@ export function userHarnessFile(harness) {
|
|
|
19
22
|
return join(homedir(), ".codex", "hooks.json");
|
|
20
23
|
return join(homedir(), ".claude", "settings.json");
|
|
21
24
|
}
|
|
25
|
+
/** The project-level agent config file for a harness — what `init` writes, so the
|
|
26
|
+
* hook travels with the repository rather than the machine. */
|
|
27
|
+
export function projectHarnessFile(harness, cwd = process.cwd()) {
|
|
28
|
+
if (harness === "cursor")
|
|
29
|
+
return join(cwd, ".cursor", "hooks.json");
|
|
30
|
+
if (harness === "codex")
|
|
31
|
+
return join(cwd, ".codex", "hooks.json");
|
|
32
|
+
return join(cwd, ".claude", "settings.json");
|
|
33
|
+
}
|
|
34
|
+
export function harnessScopes(harness, cwd = process.cwd()) {
|
|
35
|
+
const project = projectHarnessFile(harness, cwd);
|
|
36
|
+
const user = userHarnessFile(harness);
|
|
37
|
+
return {
|
|
38
|
+
project: isHarnessConfigured(project) ? project : null,
|
|
39
|
+
user: isHarnessConfigured(user) ? user : null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** One word for where a harness is wired, for a status line. */
|
|
43
|
+
export function harnessScopeLabel(scopes) {
|
|
44
|
+
if (scopes.project && scopes.user)
|
|
45
|
+
return "configured (project + user)";
|
|
46
|
+
if (scopes.project)
|
|
47
|
+
return "configured (this project)";
|
|
48
|
+
if (scopes.user)
|
|
49
|
+
return "configured (user-level)";
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
/** The file in the user home that pins trusted project policies: absolute project
|
|
53
|
+
* config dir → SHA-256 of its policy.json. It lives under the protected home, so the
|
|
54
|
+
* governed agent cannot write it. */
|
|
55
|
+
export function trustedProjectsFile() {
|
|
56
|
+
return join(userHome(), "trusted-projects.json");
|
|
57
|
+
}
|
|
58
|
+
function policyDigest(dir) {
|
|
59
|
+
try {
|
|
60
|
+
return createHash("sha256").update(readFileSync(join(dir, "policy.json"))).digest("hex");
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function readTrusted() {
|
|
67
|
+
try {
|
|
68
|
+
const p = JSON.parse(readFileSync(trustedProjectsFile(), "utf8"));
|
|
69
|
+
return isRecord(p) ? p : {};
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const trustKey = (dir) => resolve(dir).replace(/\\/g, "/").toLowerCase();
|
|
76
|
+
/** Pin the project's current policy as trusted. Editing the policy afterwards un-trusts
|
|
77
|
+
* it until the user trusts it again, so a rewrite by the agent never takes effect. */
|
|
78
|
+
export function trustProjectPolicy(dir) {
|
|
79
|
+
const digest = policyDigest(dir);
|
|
80
|
+
if (!digest)
|
|
81
|
+
throw new Error(`no policy at ${join(dir, "policy.json")}`);
|
|
82
|
+
const trusted = readTrusted();
|
|
83
|
+
trusted[trustKey(dir)] = digest;
|
|
84
|
+
mkdirSync(userHome(), { recursive: true });
|
|
85
|
+
writeFileSync(trustedProjectsFile(), JSON.stringify(trusted, null, 2) + "\n");
|
|
86
|
+
return digest;
|
|
87
|
+
}
|
|
88
|
+
/** Whether the project's policy is exactly the one the user trusted. */
|
|
89
|
+
export function isTrustedProject(dir) {
|
|
90
|
+
const digest = policyDigest(dir);
|
|
91
|
+
return !!digest && readTrusted()[trustKey(dir)] === digest;
|
|
92
|
+
}
|
|
22
93
|
/** Resolve the config dir for a hook event, most specific first:
|
|
23
94
|
* explicit override → the payload's project → $CLAUDE_PROJECT_DIR → the user home.
|
|
24
95
|
* A project dir counts only when it has been scaffolded (a policy.json), so a bare
|
|
25
|
-
* working directory never shadows the user-level install
|
|
96
|
+
* working directory never shadows the user-level install — and, once a user-level
|
|
97
|
+
* install exists, only when its policy is trusted (`isTrustedProject`). Otherwise the
|
|
98
|
+
* user's own policy governs: a repository cannot bring a weaker one with it. */
|
|
26
99
|
export function resolveConfigDir(payloadCwd) {
|
|
27
100
|
if (process.env.SCOPEBOND_HOOK_DIR)
|
|
28
101
|
return process.env.SCOPEBOND_HOOK_DIR;
|
|
@@ -31,35 +104,119 @@ export function resolveConfigDir(payloadCwd) {
|
|
|
31
104
|
candidates.push(join(payloadCwd, ".scopebond"));
|
|
32
105
|
if (process.env.CLAUDE_PROJECT_DIR)
|
|
33
106
|
candidates.push(join(process.env.CLAUDE_PROJECT_DIR, ".scopebond"));
|
|
107
|
+
const home = userHome();
|
|
108
|
+
const homeInstalled = existsSync(join(home, "policy.json"));
|
|
34
109
|
for (const dir of candidates) {
|
|
35
|
-
if (existsSync(join(dir, "policy.json")))
|
|
110
|
+
if (existsSync(join(dir, "policy.json")) && (!homeInstalled || isTrustedProject(dir)))
|
|
36
111
|
return dir;
|
|
37
112
|
}
|
|
38
|
-
|
|
39
|
-
if (existsSync(join(home, "policy.json")))
|
|
113
|
+
if (homeInstalled)
|
|
40
114
|
return home;
|
|
41
115
|
// Nothing scaffolded yet: prefer the payload project, else the user home.
|
|
42
116
|
return candidates[0] ?? home;
|
|
43
117
|
}
|
|
118
|
+
/** A project policy present but ignored because it is not trusted (for status/doctor). */
|
|
119
|
+
export function untrustedProjectPolicy(payloadCwd) {
|
|
120
|
+
if (process.env.SCOPEBOND_HOOK_DIR || !existsSync(join(userHome(), "policy.json")))
|
|
121
|
+
return null;
|
|
122
|
+
const dirs = [payloadCwd, process.env.CLAUDE_PROJECT_DIR].filter(Boolean).map((d) => join(d, ".scopebond"));
|
|
123
|
+
return dirs.find((d) => existsSync(join(d, "policy.json")) && !isTrustedProject(d)) ?? null;
|
|
124
|
+
}
|
|
44
125
|
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/
|
|
49
|
-
|
|
126
|
+
/** Whether a harness command string is one of ours. This is the single matcher for
|
|
127
|
+
* every form the installer has ever written, and it is what makes re-running `init`
|
|
128
|
+
* or `install` replace the entry instead of appending a second one:
|
|
129
|
+
* - `npx -y @scopebond/hook@0.6.0 claude` (portable)
|
|
130
|
+
* - `"<node>" "<…/@scopebond/hook/dist/cli.js>" claude` (pinned, POSIX)
|
|
131
|
+
* - `"<node>" "<…\@scopebond\hook\dist\cli.js>" claude` (pinned, Windows)
|
|
132
|
+
* - `scopebond-hook claude` (legacy global binary)
|
|
133
|
+
* The separator class matters: a Windows pinned path spells the scope
|
|
134
|
+
* `@scopebond\hook`, and matching only `@scopebond/hook` let a second `init`
|
|
135
|
+
* install a duplicate hook — which would double-check every tool call.
|
|
136
|
+
*
|
|
137
|
+
* Written with substring and token tests rather than one regular expression: the
|
|
138
|
+
* previous `(^|["\s])scopebond(["'\s]).*\b(claude|cursor|codex)\b` backtracked
|
|
139
|
+
* polynomially on a long run of `\tscopebond\t` (CodeQL js/polynomial-redos). The
|
|
140
|
+
* input is a command out of a config file rather than a request, so this was not
|
|
141
|
+
* reachable by an attacker — but a linear check is also the clearer one. */
|
|
142
|
+
const HARNESS_SUBCOMMANDS = new Set(["claude", "cursor", "codex"]);
|
|
143
|
+
/** Long enough for any real command; a bound keeps the work linear and small. */
|
|
144
|
+
const MAX_COMMAND = 4096;
|
|
145
|
+
const unquote = (token) => token.replace(/^["']+|["']+$/g, "");
|
|
146
|
+
export const isScopebondHookCommand = (cmd) => {
|
|
147
|
+
if (typeof cmd !== "string" || cmd.length === 0 || cmd.length > MAX_COMMAND)
|
|
148
|
+
return false;
|
|
149
|
+
const lower = cmd.toLowerCase();
|
|
150
|
+
// The package itself, in either path spelling (`@scopebond/hook`, `@scopebond\hook`).
|
|
151
|
+
if (lower.includes("@scopebond/hook") || lower.includes("@scopebond\\hook"))
|
|
152
|
+
return true;
|
|
153
|
+
// The legacy global binary, as a whole token.
|
|
154
|
+
if (/(^|[\s"'])scopebond-hook([\s"']|$)/.test(cmd))
|
|
155
|
+
return true;
|
|
156
|
+
// An absolute or bare form whose last argument is one of our harness subcommands:
|
|
157
|
+
// `<node> <…/cli.js> claude`, `scopebond cursor`.
|
|
158
|
+
const tokens = cmd.split(/\s+/).filter(Boolean);
|
|
159
|
+
const last = unquote(tokens[tokens.length - 1] ?? "");
|
|
160
|
+
if (!HARNESS_SUBCOMMANDS.has(last))
|
|
161
|
+
return false;
|
|
162
|
+
return tokens.some((token) => {
|
|
163
|
+
const t = unquote(token).toLowerCase();
|
|
164
|
+
return t.includes("scopebond") || /cli\.(m|c)?js$/.test(t);
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const isScopebond = isScopebondHookCommand;
|
|
168
|
+
/** Whether a harness hook entry (either shape: a bare command, or a group with a
|
|
169
|
+
* nested `hooks` array) is a Scopebond entry. */
|
|
170
|
+
export const harnessEntryMatches = (e) => isRecord(e) && (isScopebond(e.command) || (Array.isArray(e.hooks) && e.hooks.some((h) => isRecord(h) && isScopebond(h.command))));
|
|
171
|
+
const entryMatches = harnessEntryMatches;
|
|
172
|
+
/** Read an agent's JSON config for merging. A missing file is an empty config; a file
|
|
173
|
+
* that exists but does not parse as a JSON object is an error — rewriting it would
|
|
174
|
+
* silently delete the user's other settings, so the installer stops instead. */
|
|
175
|
+
export function readHarnessConfig(file) {
|
|
176
|
+
if (!existsSync(file))
|
|
177
|
+
return {};
|
|
178
|
+
const text = readFileSync(file, "utf8");
|
|
179
|
+
if (!text.trim())
|
|
180
|
+
return {};
|
|
181
|
+
let parsed;
|
|
182
|
+
try {
|
|
183
|
+
parsed = JSON.parse(text);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
throw new Error(`${file} is not valid JSON (${error.message}); fix or move it, then run this again — it was left unchanged`);
|
|
187
|
+
}
|
|
188
|
+
if (!isRecord(parsed))
|
|
189
|
+
throw new Error(`${file} is not a JSON object; fix or move it, then run this again — it was left unchanged`);
|
|
190
|
+
return parsed;
|
|
191
|
+
}
|
|
192
|
+
/** Copy an agent config aside before changing it, once. Re-running an installer must not
|
|
193
|
+
* overwrite the backup with the already-modified file, or the original is lost on the
|
|
194
|
+
* second run — so an existing backup is left alone. Returns the backup path when one was
|
|
195
|
+
* written.
|
|
196
|
+
*
|
|
197
|
+
* This exists because these installers rewrite files the user did not create and may not
|
|
198
|
+
* know are involved (`~/.claude/settings.json` holds their theme, plugins and
|
|
199
|
+
* permissions), and the undo was previously "hope the merge was right". */
|
|
200
|
+
export function backupHarnessConfig(file) {
|
|
201
|
+
if (!existsSync(file))
|
|
202
|
+
return null;
|
|
203
|
+
const backup = `${file}.scopebond-backup`;
|
|
204
|
+
if (existsSync(backup))
|
|
205
|
+
return null;
|
|
206
|
+
try {
|
|
207
|
+
copyFileSync(file, backup);
|
|
208
|
+
return backup;
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
50
214
|
/** Write (idempotently) a harness hook entry pointing at an explicit command string.
|
|
51
215
|
* Shared by the project installer (npx command) and the user installer (absolute path). */
|
|
52
216
|
export function writeHarnessConfig(file, harness, command) {
|
|
217
|
+
const config = readHarnessConfig(file);
|
|
218
|
+
backupHarnessConfig(file);
|
|
53
219
|
mkdirSync(dirname(file), { recursive: true });
|
|
54
|
-
let config = {};
|
|
55
|
-
if (existsSync(file)) {
|
|
56
|
-
try {
|
|
57
|
-
const p = JSON.parse(readFileSync(file, "utf8"));
|
|
58
|
-
if (isRecord(p))
|
|
59
|
-
config = p;
|
|
60
|
-
}
|
|
61
|
-
catch { /* start fresh on unreadable */ }
|
|
62
|
-
}
|
|
63
220
|
const hooks = isRecord(config.hooks) ? config.hooks : (config.hooks = {});
|
|
64
221
|
if (harness === "cursor") {
|
|
65
222
|
config.version = config.version ?? 1;
|
|
@@ -96,12 +253,11 @@ export function removeHarnessConfig(file) {
|
|
|
96
253
|
return false;
|
|
97
254
|
let config;
|
|
98
255
|
try {
|
|
99
|
-
|
|
100
|
-
config = isRecord(p) ? p : {};
|
|
256
|
+
config = readHarnessConfig(file);
|
|
101
257
|
}
|
|
102
258
|
catch {
|
|
103
259
|
return true;
|
|
104
|
-
}
|
|
260
|
+
} // unreadable: leave it untouched
|
|
105
261
|
const hooks = isRecord(config.hooks) ? config.hooks : {};
|
|
106
262
|
for (const [event, value] of Object.entries(hooks)) {
|
|
107
263
|
if (Array.isArray(value))
|
|
@@ -118,10 +274,17 @@ export function cursorDetected() {
|
|
|
118
274
|
export function codexDetected() {
|
|
119
275
|
return existsSync(join(homedir(), ".codex"));
|
|
120
276
|
}
|
|
121
|
-
/** The absolute command a
|
|
122
|
-
*
|
|
277
|
+
/** The absolute command a harness entry runs: the current Node executable and the
|
|
278
|
+
* absolute path to this CLI, so it does not depend on PATH.
|
|
279
|
+
*
|
|
280
|
+
* Both paths are always quoted on Windows, even without a space in them. A harness
|
|
281
|
+
* runs this string through a shell, and that shell may be bash (Git Bash, WSL, a
|
|
282
|
+
* dev container), where an unquoted Windows path loses every backslash and the
|
|
283
|
+
* hook dies with MODULE_NOT_FOUND. Inside double quotes bash leaves a backslash
|
|
284
|
+
* alone unless it precedes $ ` " \ or a newline — none of which occur in a Windows
|
|
285
|
+
* path — and cmd.exe and PowerShell accept quoted paths too. */
|
|
123
286
|
export function absoluteHookCommand(cliPath, harness) {
|
|
124
|
-
const quote = (s) => (/\s/.test(s) ? `"${s}"` : s);
|
|
287
|
+
const quote = (s) => (process.platform === "win32" || /\s/.test(s) ? `"${s}"` : s);
|
|
125
288
|
return `${quote(process.execPath)} ${quote(cliPath)} ${harness}`;
|
|
126
289
|
}
|
|
127
290
|
export function isHarnessConfigured(file) {
|
|
@@ -137,6 +300,57 @@ export function isHarnessConfigured(file) {
|
|
|
137
300
|
return false;
|
|
138
301
|
}
|
|
139
302
|
}
|
|
303
|
+
/** Every Scopebond command string a harness config currently runs. `doctor` uses it to
|
|
304
|
+
* check that a pinned command still resolves: a hook entry that cannot start is worse
|
|
305
|
+
* than none, because a harness can read the failure as "no hook". */
|
|
306
|
+
export function configuredHookCommands(file) {
|
|
307
|
+
if (!existsSync(file))
|
|
308
|
+
return [];
|
|
309
|
+
const found = [];
|
|
310
|
+
const collect = (entry) => {
|
|
311
|
+
if (!isRecord(entry))
|
|
312
|
+
return;
|
|
313
|
+
if (isScopebond(entry.command))
|
|
314
|
+
found.push(String(entry.command));
|
|
315
|
+
if (Array.isArray(entry.hooks))
|
|
316
|
+
for (const h of entry.hooks)
|
|
317
|
+
collect(h);
|
|
318
|
+
};
|
|
319
|
+
try {
|
|
320
|
+
const p = JSON.parse(readFileSync(file, "utf8"));
|
|
321
|
+
if (!isRecord(p) || !isRecord(p.hooks))
|
|
322
|
+
return [];
|
|
323
|
+
for (const list of Object.values(p.hooks))
|
|
324
|
+
if (Array.isArray(list))
|
|
325
|
+
for (const e of list)
|
|
326
|
+
collect(e);
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
return found;
|
|
332
|
+
}
|
|
333
|
+
/** Whether a configured hook command can actually start. An `npx` form always can
|
|
334
|
+
* (npm resolves it); a pinned command names two absolute paths — the Node binary and
|
|
335
|
+
* the CLI — and either can go away: a Node version manager switching versions, or the
|
|
336
|
+
* Scopebond home being cleared. Both are exactly what this check exists to catch. */
|
|
337
|
+
export function hookCommandResolves(command) {
|
|
338
|
+
if (/(^|\s)npx(\.cmd)?\s/.test(command))
|
|
339
|
+
return true;
|
|
340
|
+
// `"<node>" "<cli.js>" claude`: check every token that names a file on disk.
|
|
341
|
+
const tokens = command.match(/"[^"]+"|\S+/g) ?? [];
|
|
342
|
+
let checked = 0;
|
|
343
|
+
for (const raw of tokens) {
|
|
344
|
+
const candidate = raw.replace(/^"|"$/g, "");
|
|
345
|
+
if (!/\.(m|c)?js$|\.exe$/i.test(candidate))
|
|
346
|
+
continue;
|
|
347
|
+
checked += 1;
|
|
348
|
+
if (!existsSync(candidate))
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
// A bare `node cli.js` form on POSIX has no .exe to check; the .js still counted.
|
|
352
|
+
return checked > 0 || !/[\\/]/.test(command.split(/\s+/)[0] ?? "");
|
|
353
|
+
}
|
|
140
354
|
/** Remove the user-level home (keys, policy, receipts). */
|
|
141
355
|
export function purgeHome() {
|
|
142
356
|
rmSync(userHome(), { recursive: true, force: true });
|
package/dist/install.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.js","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,8EAA8E;AAC9E,uFAAuF;AACvF,4GAA4G;AAC5G,iEAAiE;AAEjE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,YA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,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACpC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACtF,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,KAAK,CAAC;IAAC,CAAC;AAC3B,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,SAAS;IACvB,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC","sourcesContent":["// SB112 — the user-level installer. One install per developer machine (not per repo):\n// keys and a starter policy live in a user-level home (~/.scopebond, override\n// SCOPEBOND_HOME), and the hook is registered by absolute path in the user-level agent\n// config (~/.claude/settings.json, ~/.cursor/hooks.json, ~/.codex/hooks.json). A project-local `.scopebond`\n// still wins when present, so per-project policies keep working.\n\nimport { mkdirSync, writeFileSync, existsSync, readFileSync, rmSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport type Harness = \"claude\" | \"cursor\" | \"codex\";\n\n/** The user-level Scopebond home. `SCOPEBOND_HOME` overrides it (tests, CI). */\nexport function userHome(): string {\n return process.env.SCOPEBOND_HOME ?? join(homedir(), \".scopebond\");\n}\n\n/** The user-level agent config file for a harness. `HOME`/`USERPROFILE` (via homedir)\n * roots it; SCOPEBOND_HOME does not move the agent's own config. */\nexport function userHarnessFile(harness: Harness): string {\n if (harness === \"cursor\") return join(homedir(), \".cursor\", \"hooks.json\");\n if (harness === \"codex\") return join(homedir(), \".codex\", \"hooks.json\");\n return join(homedir(), \".claude\", \"settings.json\");\n}\n\n/** Resolve the config dir for a hook event, most specific first:\n * explicit override → the payload's project → $CLAUDE_PROJECT_DIR → the user home.\n * A project dir counts only when it has been scaffolded (a policy.json), so a bare\n * working directory never shadows the user-level install. */\nexport function resolveConfigDir(payloadCwd: string | undefined): string {\n if (process.env.SCOPEBOND_HOOK_DIR) return process.env.SCOPEBOND_HOOK_DIR;\n const candidates: string[] = [];\n if (payloadCwd) candidates.push(join(payloadCwd, \".scopebond\"));\n if (process.env.CLAUDE_PROJECT_DIR) candidates.push(join(process.env.CLAUDE_PROJECT_DIR, \".scopebond\"));\n for (const dir of candidates) {\n if (existsSync(join(dir, \"policy.json\"))) return dir;\n }\n const home = userHome();\n if (existsSync(join(home, \"policy.json\"))) return home;\n // Nothing scaffolded yet: prefer the payload project, else the user home.\n return candidates[0] ?? home;\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === \"object\" && v !== null && !Array.isArray(v);\nconst isScopebond = (cmd: unknown): boolean =>\n typeof cmd === \"string\" && (\n /@scopebond\\/hook|scopebond-hook(\\s|$)/.test(cmd) ||\n // the user-level absolute form: `<node> <…/cli.js> claude|cursor|codex`\n /cli\\.js[\"']?\\s+(claude|cursor|codex)\\s*$/.test(cmd) ||\n /(^|[\"\\s])scopebond([\"'\\s]).*\\b(claude|cursor|codex)\\b/.test(cmd)\n );\nconst entryMatches = (e: unknown): boolean =>\n isRecord(e) && (isScopebond(e.command) || (Array.isArray(e.hooks) && e.hooks.some((h) => isRecord(h) && isScopebond(h.command))));\n\n/** Write (idempotently) a harness hook entry pointing at an explicit command string.\n * Shared by the project installer (npx command) and the user installer (absolute path). */\nexport function writeHarnessConfig(file: string, harness: Harness, command: string): string {\n mkdirSync(dirname(file), { recursive: true });\n let config: Record<string, unknown> = {};\n if (existsSync(file)) { try { const p = JSON.parse(readFileSync(file, \"utf8\")); if (isRecord(p)) config = p; } catch { /* start fresh on unreadable */ } }\n const hooks = isRecord(config.hooks) ? config.hooks : (config.hooks = {});\n if (harness === \"cursor\") {\n config.version = config.version ?? 1;\n for (const event of [\"beforeShellExecution\", \"beforeMCPExecution\", \"beforeReadFile\", \"afterFileEdit\"]) {\n const list = Array.isArray((hooks as Record<string, unknown>)[event]) ? (hooks as Record<string, unknown[]>)[event] : ((hooks as Record<string, unknown[]>)[event] = []);\n const at = list.findIndex(entryMatches);\n const entry = { command: command.replace(/\\bclaude$/, \"cursor\") };\n if (at >= 0) list[at] = entry; else list.push(entry);\n }\n } else {\n const list = Array.isArray((hooks as Record<string, unknown>).PreToolUse) ? (hooks as Record<string, unknown[]>).PreToolUse : ((hooks as Record<string, unknown[]>).PreToolUse = []);\n const at = list.findIndex(entryMatches);\n // Codex matchers are regular expressions; omitting the matcher means every tool.\n // A literal \"*\" is not a valid regular expression and causes Codex to skip the group.\n const entry = harness === \"codex\"\n ? { hooks: [{ type: \"command\", command, timeout: 30, statusMessage: \"Checking this action with Scopebond\" }] }\n : { matcher: \"*\", hooks: [{ type: \"command\", command }] };\n if (at >= 0) list[at] = entry; else list.push(entry);\n }\n writeFileSync(file, JSON.stringify(config, null, 2) + \"\\n\");\n return file;\n}\n\n/** Remove any Scopebond hook entry from a user-level harness config, leaving the rest\n * intact. Returns true if the file existed. */\nexport function removeHarnessConfig(file: string): boolean {\n if (!existsSync(file)) return false;\n let config: Record<string, unknown>;\n try { const p = JSON.parse(readFileSync(file, \"utf8\")); config = isRecord(p) ? p : {}; } catch { return true; }\n const hooks = isRecord(config.hooks) ? config.hooks : {};\n for (const [event, value] of Object.entries(hooks)) {\n if (Array.isArray(value)) (hooks as Record<string, unknown[]>)[event] = value.filter((e) => !entryMatches(e));\n }\n writeFileSync(file, JSON.stringify(config, null, 2) + \"\\n\");\n return true;\n}\n\n/** Detect a Cursor install by its user config directory. */\nexport function cursorDetected(): boolean {\n return existsSync(join(homedir(), \".cursor\"));\n}\n\n/** Detect a Codex install by its user config directory. */\nexport function codexDetected(): boolean {\n return existsSync(join(homedir(), \".codex\"));\n}\n\n/** The absolute command a user-level harness entry runs: the current Node executable\n * and the absolute path to this CLI, so it does not depend on PATH. */\nexport function absoluteHookCommand(cliPath: string, harness: Harness): string {\n const quote = (s: string) => (/\\s/.test(s) ? `\"${s}\"` : s);\n return `${quote(process.execPath)} ${quote(cliPath)} ${harness}`;\n}\n\nexport function isHarnessConfigured(file: string): boolean {\n if (!existsSync(file)) return false;\n try {\n const p = JSON.parse(readFileSync(file, \"utf8\"));\n if (!isRecord(p) || !isRecord(p.hooks)) return false;\n return Object.values(p.hooks).some((v) => Array.isArray(v) && v.some(entryMatches));\n } catch { return false; }\n}\n\n/** Remove the user-level home (keys, policy, receipts). */\nexport function purgeHome(): void {\n rmSync(userHome(), { recursive: true, force: true });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,8EAA8E;AAC9E,uFAAuF;AACvF,sFAAsF;AACtF,mFAAmF;AACnF,oFAAoF;AACpF,iFAAiF;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAInD,gFAAgF;AAChF,MAAM,UAAU,QAAQ;IACtB,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AACrE,CAAC;AAED;qEACqE;AAC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AAC,IAAI,EAAE,CAAC,CAAC;AACrE,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,SAAS;IACvB,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC","sourcesContent":["// SB112 — the user-level installer. One install per developer machine (not per repo):\n// keys and a starter policy live in a user-level home (~/.scopebond, override\n// SCOPEBOND_HOME), and the hook is registered by absolute path in the user-level agent\n// config (~/.claude/settings.json, ~/.cursor/hooks.json, ~/.codex/hooks.json). When a\n// user-level install exists, a project-local `.scopebond` is used only if the user\n// trusted that exact policy (`scopebond trust`, or `init` in the project): a cloned\n// repository, or an agent inside it, must not be able to swap in its own policy.\n\nimport { createHash } from \"node:crypto\";\nimport { mkdirSync, writeFileSync, existsSync, readFileSync, rmSync, copyFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join, resolve } from \"node:path\";\n\nexport type Harness = \"claude\" | \"cursor\" | \"codex\";\n\n/** The user-level Scopebond home. `SCOPEBOND_HOME` overrides it (tests, CI). */\nexport function userHome(): string {\n return process.env.SCOPEBOND_HOME ?? join(homedir(), \".scopebond\");\n}\n\n/** The user-level agent config file for a harness. `HOME`/`USERPROFILE` (via homedir)\n * roots it; SCOPEBOND_HOME does not move the agent's own config. */\nexport function userHarnessFile(harness: Harness): string {\n if (harness === \"cursor\") return join(homedir(), \".cursor\", \"hooks.json\");\n if (harness === \"codex\") return join(homedir(), \".codex\", \"hooks.json\");\n return join(homedir(), \".claude\", \"settings.json\");\n}\n\n/** The project-level agent config file for a harness — what `init` writes, so the\n * hook travels with the repository rather than the machine. */\nexport function projectHarnessFile(harness: Harness, cwd: string = process.cwd()): string {\n if (harness === \"cursor\") return join(cwd, \".cursor\", \"hooks.json\");\n if (harness === \"codex\") return join(cwd, \".codex\", \"hooks.json\");\n return join(cwd, \".claude\", \"settings.json\");\n}\n\n/** Which config files actually carry a Scopebond hook for this harness. There are two\n * places it can live — the project config `init` writes and the user config `install`\n * writes — and `status`/`doctor` must look at both: checking only the user one told\n * everyone who ran `init` that their install had failed. */\nexport interface HarnessScopes { project: string | null; user: string | null }\n\nexport function harnessScopes(harness: Harness, cwd: string = process.cwd()): HarnessScopes {\n const project = projectHarnessFile(harness, cwd);\n const user = userHarnessFile(harness);\n return {\n project: isHarnessConfigured(project) ? project : null,\n user: isHarnessConfigured(user) ? user : null,\n };\n}\n\n/** One word for where a harness is wired, for a status line. */\nexport function harnessScopeLabel(scopes: HarnessScopes): string {\n if (scopes.project && scopes.user) return \"configured (project + user)\";\n if (scopes.project) return \"configured (this project)\";\n if (scopes.user) return \"configured (user-level)\";\n return \"\";\n}\n\n/** The file in the user home that pins trusted project policies: absolute project\n * config dir → SHA-256 of its policy.json. It lives under the protected home, so the\n * governed agent cannot write it. */\nexport function trustedProjectsFile(): string {\n return join(userHome(), \"trusted-projects.json\");\n}\n\nfunction policyDigest(dir: string): string | null {\n try { return createHash(\"sha256\").update(readFileSync(join(dir, \"policy.json\"))).digest(\"hex\"); } catch { return null; }\n}\n\nfunction readTrusted(): Record<string, string> {\n try { const p = JSON.parse(readFileSync(trustedProjectsFile(), \"utf8\")); return isRecord(p) ? (p as Record<string, string>) : {}; } catch { return {}; }\n}\n\nconst trustKey = (dir: string): string => resolve(dir).replace(/\\\\/g, \"/\").toLowerCase();\n\n/** Pin the project's current policy as trusted. Editing the policy afterwards un-trusts\n * it until the user trusts it again, so a rewrite by the agent never takes effect. */\nexport function trustProjectPolicy(dir: string): string {\n const digest = policyDigest(dir);\n if (!digest) throw new Error(`no policy at ${join(dir, \"policy.json\")}`);\n const trusted = readTrusted();\n trusted[trustKey(dir)] = digest;\n mkdirSync(userHome(), { recursive: true });\n writeFileSync(trustedProjectsFile(), JSON.stringify(trusted, null, 2) + \"\\n\");\n return digest;\n}\n\n/** Whether the project's policy is exactly the one the user trusted. */\nexport function isTrustedProject(dir: string): boolean {\n const digest = policyDigest(dir);\n return !!digest && readTrusted()[trustKey(dir)] === digest;\n}\n\n/** Resolve the config dir for a hook event, most specific first:\n * explicit override → the payload's project → $CLAUDE_PROJECT_DIR → the user home.\n * A project dir counts only when it has been scaffolded (a policy.json), so a bare\n * working directory never shadows the user-level install — and, once a user-level\n * install exists, only when its policy is trusted (`isTrustedProject`). Otherwise the\n * user's own policy governs: a repository cannot bring a weaker one with it. */\nexport function resolveConfigDir(payloadCwd: string | undefined): string {\n if (process.env.SCOPEBOND_HOOK_DIR) return process.env.SCOPEBOND_HOOK_DIR;\n const candidates: string[] = [];\n if (payloadCwd) candidates.push(join(payloadCwd, \".scopebond\"));\n if (process.env.CLAUDE_PROJECT_DIR) candidates.push(join(process.env.CLAUDE_PROJECT_DIR, \".scopebond\"));\n const home = userHome();\n const homeInstalled = existsSync(join(home, \"policy.json\"));\n for (const dir of candidates) {\n if (existsSync(join(dir, \"policy.json\")) && (!homeInstalled || isTrustedProject(dir))) return dir;\n }\n if (homeInstalled) return home;\n // Nothing scaffolded yet: prefer the payload project, else the user home.\n return candidates[0] ?? home;\n}\n\n/** A project policy present but ignored because it is not trusted (for status/doctor). */\nexport function untrustedProjectPolicy(payloadCwd: string | undefined): string | null {\n if (process.env.SCOPEBOND_HOOK_DIR || !existsSync(join(userHome(), \"policy.json\"))) return null;\n const dirs = [payloadCwd, process.env.CLAUDE_PROJECT_DIR].filter(Boolean).map((d) => join(d as string, \".scopebond\"));\n return dirs.find((d) => existsSync(join(d, \"policy.json\")) && !isTrustedProject(d)) ?? null;\n}\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === \"object\" && v !== null && !Array.isArray(v);\n\n/** Whether a harness command string is one of ours. This is the single matcher for\n * every form the installer has ever written, and it is what makes re-running `init`\n * or `install` replace the entry instead of appending a second one:\n * - `npx -y @scopebond/hook@0.6.0 claude` (portable)\n * - `\"<node>\" \"<…/@scopebond/hook/dist/cli.js>\" claude` (pinned, POSIX)\n * - `\"<node>\" \"<…\\@scopebond\\hook\\dist\\cli.js>\" claude` (pinned, Windows)\n * - `scopebond-hook claude` (legacy global binary)\n * The separator class matters: a Windows pinned path spells the scope\n * `@scopebond\\hook`, and matching only `@scopebond/hook` let a second `init`\n * install a duplicate hook — which would double-check every tool call.\n *\n * Written with substring and token tests rather than one regular expression: the\n * previous `(^|[\"\\s])scopebond([\"'\\s]).*\\b(claude|cursor|codex)\\b` backtracked\n * polynomially on a long run of `\\tscopebond\\t` (CodeQL js/polynomial-redos). The\n * input is a command out of a config file rather than a request, so this was not\n * reachable by an attacker — but a linear check is also the clearer one. */\nconst HARNESS_SUBCOMMANDS = new Set([\"claude\", \"cursor\", \"codex\"]);\n/** Long enough for any real command; a bound keeps the work linear and small. */\nconst MAX_COMMAND = 4096;\nconst unquote = (token: string): string => token.replace(/^[\"']+|[\"']+$/g, \"\");\n\nexport const isScopebondHookCommand = (cmd: unknown): boolean => {\n if (typeof cmd !== \"string\" || cmd.length === 0 || cmd.length > MAX_COMMAND) return false;\n const lower = cmd.toLowerCase();\n // The package itself, in either path spelling (`@scopebond/hook`, `@scopebond\\hook`).\n if (lower.includes(\"@scopebond/hook\") || lower.includes(\"@scopebond\\\\hook\")) return true;\n // The legacy global binary, as a whole token.\n if (/(^|[\\s\"'])scopebond-hook([\\s\"']|$)/.test(cmd)) return true;\n // An absolute or bare form whose last argument is one of our harness subcommands:\n // `<node> <…/cli.js> claude`, `scopebond cursor`.\n const tokens = cmd.split(/\\s+/).filter(Boolean);\n const last = unquote(tokens[tokens.length - 1] ?? \"\");\n if (!HARNESS_SUBCOMMANDS.has(last)) return false;\n return tokens.some((token) => {\n const t = unquote(token).toLowerCase();\n return t.includes(\"scopebond\") || /cli\\.(m|c)?js$/.test(t);\n });\n};\nconst isScopebond = isScopebondHookCommand;\n\n/** Whether a harness hook entry (either shape: a bare command, or a group with a\n * nested `hooks` array) is a Scopebond entry. */\nexport const harnessEntryMatches = (e: unknown): boolean =>\n isRecord(e) && (isScopebond(e.command) || (Array.isArray(e.hooks) && e.hooks.some((h) => isRecord(h) && isScopebond(h.command))));\nconst entryMatches = harnessEntryMatches;\n\n/** Read an agent's JSON config for merging. A missing file is an empty config; a file\n * that exists but does not parse as a JSON object is an error — rewriting it would\n * silently delete the user's other settings, so the installer stops instead. */\nexport function readHarnessConfig(file: string): Record<string, unknown> {\n if (!existsSync(file)) return {};\n const text = readFileSync(file, \"utf8\");\n if (!text.trim()) return {};\n let parsed: unknown;\n try { parsed = JSON.parse(text); } catch (error) {\n throw new Error(`${file} is not valid JSON (${(error as Error).message}); fix or move it, then run this again — it was left unchanged`);\n }\n if (!isRecord(parsed)) throw new Error(`${file} is not a JSON object; fix or move it, then run this again — it was left unchanged`);\n return parsed;\n}\n\n/** Copy an agent config aside before changing it, once. Re-running an installer must not\n * overwrite the backup with the already-modified file, or the original is lost on the\n * second run — so an existing backup is left alone. Returns the backup path when one was\n * written.\n *\n * This exists because these installers rewrite files the user did not create and may not\n * know are involved (`~/.claude/settings.json` holds their theme, plugins and\n * permissions), and the undo was previously \"hope the merge was right\". */\nexport function backupHarnessConfig(file: string): string | null {\n if (!existsSync(file)) return null;\n const backup = `${file}.scopebond-backup`;\n if (existsSync(backup)) return null;\n try { copyFileSync(file, backup); return backup; } catch { return null; }\n}\n\n/** Write (idempotently) a harness hook entry pointing at an explicit command string.\n * Shared by the project installer (npx command) and the user installer (absolute path). */\nexport function writeHarnessConfig(file: string, harness: Harness, command: string): string {\n const config = readHarnessConfig(file);\n backupHarnessConfig(file);\n mkdirSync(dirname(file), { recursive: true });\n const hooks = isRecord(config.hooks) ? config.hooks : (config.hooks = {});\n if (harness === \"cursor\") {\n config.version = config.version ?? 1;\n for (const event of [\"beforeShellExecution\", \"beforeMCPExecution\", \"beforeReadFile\", \"afterFileEdit\"]) {\n const list = Array.isArray((hooks as Record<string, unknown>)[event]) ? (hooks as Record<string, unknown[]>)[event] : ((hooks as Record<string, unknown[]>)[event] = []);\n const at = list.findIndex(entryMatches);\n const entry = { command: command.replace(/\\bclaude$/, \"cursor\") };\n if (at >= 0) list[at] = entry; else list.push(entry);\n }\n } else {\n const list = Array.isArray((hooks as Record<string, unknown>).PreToolUse) ? (hooks as Record<string, unknown[]>).PreToolUse : ((hooks as Record<string, unknown[]>).PreToolUse = []);\n const at = list.findIndex(entryMatches);\n // Codex matchers are regular expressions; omitting the matcher means every tool.\n // A literal \"*\" is not a valid regular expression and causes Codex to skip the group.\n const entry = harness === \"codex\"\n ? { hooks: [{ type: \"command\", command, timeout: 30, statusMessage: \"Checking this action with Scopebond\" }] }\n : { matcher: \"*\", hooks: [{ type: \"command\", command }] };\n if (at >= 0) list[at] = entry; else list.push(entry);\n }\n writeFileSync(file, JSON.stringify(config, null, 2) + \"\\n\");\n return file;\n}\n\n/** Remove any Scopebond hook entry from a user-level harness config, leaving the rest\n * intact. Returns true if the file existed. */\nexport function removeHarnessConfig(file: string): boolean {\n if (!existsSync(file)) return false;\n let config: Record<string, unknown>;\n try { config = readHarnessConfig(file); } catch { return true; } // unreadable: leave it untouched\n const hooks = isRecord(config.hooks) ? config.hooks : {};\n for (const [event, value] of Object.entries(hooks)) {\n if (Array.isArray(value)) (hooks as Record<string, unknown[]>)[event] = value.filter((e) => !entryMatches(e));\n }\n writeFileSync(file, JSON.stringify(config, null, 2) + \"\\n\");\n return true;\n}\n\n/** Detect a Cursor install by its user config directory. */\nexport function cursorDetected(): boolean {\n return existsSync(join(homedir(), \".cursor\"));\n}\n\n/** Detect a Codex install by its user config directory. */\nexport function codexDetected(): boolean {\n return existsSync(join(homedir(), \".codex\"));\n}\n\n/** The absolute command a harness entry runs: the current Node executable and the\n * absolute path to this CLI, so it does not depend on PATH.\n *\n * Both paths are always quoted on Windows, even without a space in them. A harness\n * runs this string through a shell, and that shell may be bash (Git Bash, WSL, a\n * dev container), where an unquoted Windows path loses every backslash and the\n * hook dies with MODULE_NOT_FOUND. Inside double quotes bash leaves a backslash\n * alone unless it precedes $ ` \" \\ or a newline — none of which occur in a Windows\n * path — and cmd.exe and PowerShell accept quoted paths too. */\nexport function absoluteHookCommand(cliPath: string, harness: Harness): string {\n const quote = (s: string) => (process.platform === \"win32\" || /\\s/.test(s) ? `\"${s}\"` : s);\n return `${quote(process.execPath)} ${quote(cliPath)} ${harness}`;\n}\n\nexport function isHarnessConfigured(file: string): boolean {\n if (!existsSync(file)) return false;\n try {\n const p = JSON.parse(readFileSync(file, \"utf8\"));\n if (!isRecord(p) || !isRecord(p.hooks)) return false;\n return Object.values(p.hooks).some((v) => Array.isArray(v) && v.some(entryMatches));\n } catch { return false; }\n}\n\n/** Every Scopebond command string a harness config currently runs. `doctor` uses it to\n * check that a pinned command still resolves: a hook entry that cannot start is worse\n * than none, because a harness can read the failure as \"no hook\". */\nexport function configuredHookCommands(file: string): string[] {\n if (!existsSync(file)) return [];\n const found: string[] = [];\n const collect = (entry: unknown): void => {\n if (!isRecord(entry)) return;\n if (isScopebond(entry.command)) found.push(String(entry.command));\n if (Array.isArray(entry.hooks)) for (const h of entry.hooks) collect(h);\n };\n try {\n const p = JSON.parse(readFileSync(file, \"utf8\"));\n if (!isRecord(p) || !isRecord(p.hooks)) return [];\n for (const list of Object.values(p.hooks)) if (Array.isArray(list)) for (const e of list) collect(e);\n } catch { return []; }\n return found;\n}\n\n/** Whether a configured hook command can actually start. An `npx` form always can\n * (npm resolves it); a pinned command names two absolute paths — the Node binary and\n * the CLI — and either can go away: a Node version manager switching versions, or the\n * Scopebond home being cleared. Both are exactly what this check exists to catch. */\nexport function hookCommandResolves(command: string): boolean {\n if (/(^|\\s)npx(\\.cmd)?\\s/.test(command)) return true;\n // `\"<node>\" \"<cli.js>\" claude`: check every token that names a file on disk.\n const tokens = command.match(/\"[^\"]+\"|\\S+/g) ?? [];\n let checked = 0;\n for (const raw of tokens) {\n const candidate = raw.replace(/^\"|\"$/g, \"\");\n if (!/\\.(m|c)?js$|\\.exe$/i.test(candidate)) continue;\n checked += 1;\n if (!existsSync(candidate)) return false;\n }\n // A bare `node cli.js` form on POSIX has no .exe to check; the .js still counted.\n return checked > 0 || !/[\\\\/]/.test(command.split(/\\s+/)[0] ?? \"\");\n}\n\n/** Remove the user-level home (keys, policy, receipts). */\nexport function purgeHome(): void {\n rmSync(userHome(), { recursive: true, force: true });\n}\n"]}
|
package/dist/map.d.ts
CHANGED
|
@@ -4,12 +4,21 @@ export interface NormalizedIntent {
|
|
|
4
4
|
}
|
|
5
5
|
export interface Mapped {
|
|
6
6
|
intent: NormalizedIntent;
|
|
7
|
-
/** false when no taxonomy type applies (an unknown tool
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
/** false when no taxonomy type applies (an unknown tool) or when the command's
|
|
8
|
+
* effect cannot be judged from its text (`patch`, `git apply`, `tar x`): emitted to
|
|
9
|
+
* the observation path (not_evaluated) in normal mode and denied by the closed
|
|
10
|
+
* allowlist in strict mode — never granted. A shell command that could not be
|
|
11
|
+
* parsed, or whose program is only known at run time, is evaluated with an empty
|
|
12
|
+
* program, which the starter policy denies in every mode. */
|
|
10
13
|
evaluated: boolean;
|
|
11
14
|
/** The native tool/event name, for diagnostics. */
|
|
12
15
|
source: string;
|
|
16
|
+
/** True when the harness only tells us about this action *after* it happened, so a
|
|
17
|
+
* policy decision on it records and flags the action but did not prevent it. Cursor's
|
|
18
|
+
* `afterFileEdit` is the case that exists today: it has no before-edit counterpart,
|
|
19
|
+
* so a file write there is observed, not stopped. Callers must not describe such a
|
|
20
|
+
* decision as prevention. */
|
|
21
|
+
postHoc?: boolean;
|
|
13
22
|
}
|
|
14
23
|
/** A bare `git push` (no ref) pushes the current branch. The mapper cannot know it,
|
|
15
24
|
* so the runtime resolves it and fills it in here, before evaluation — otherwise the
|
package/dist/map.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AACD,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,gBAAgB,CAAC;IACzB;;;;;kEAK8D;IAC9D,SAAS,EAAE,OAAO,CAAC;IACnB,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf;;;;kCAI8B;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAkpBD;;;uCAGuC;AACvC,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,EAAE,CAM5F;AAED,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAyBzE;AAED;;kFAEkF;AAClF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAaxE;AAED,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAqBxF"}
|