@primitive.ai/prim 0.1.0-alpha.118 → 0.1.0-alpha.119
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/dist/{chunk-FPDOBG3H.js → chunk-2AKDX4RU.js} +1 -1
- package/dist/{chunk-CHRICRVE.js → chunk-2JA524SC.js} +21 -14
- package/dist/{chunk-L3NUFCOD.js → chunk-4L7TAM5S.js} +120 -285
- package/dist/{chunk-JGOFEG6T.js → chunk-5BQ2NEMP.js} +2732 -2533
- package/dist/{chunk-B3FVP7VQ.js → chunk-A6M2M5A2.js} +1 -1
- package/dist/{chunk-OHLVHT6R.js → chunk-CCGFRNAA.js} +3 -3
- package/dist/{chunk-SCOEPFOV.js → chunk-CSE44DPA.js} +2 -2
- package/dist/{chunk-Q4CWXKNV.js → chunk-D235RJNO.js} +3 -3
- package/dist/{chunk-QX7QFMLF.js → chunk-GYQOZGGF.js} +2 -2
- package/dist/{chunk-PYIIYC3A.js → chunk-HXICZG5J.js} +4 -4
- package/dist/{chunk-JXQVXU2K.js → chunk-LBCPRHNG.js} +1 -1
- package/dist/{chunk-ECP7EGOD.js → chunk-LTTF4MBE.js} +2 -2
- package/dist/{chunk-VEI7KUOU.js → chunk-MWNRXAEB.js} +1 -1
- package/dist/{chunk-LEEWUN74.js → chunk-NQFRQ56V.js} +2 -2
- package/dist/{chunk-3NJ4FUPK.js → chunk-P2O7NLVN.js} +5 -6
- package/dist/{chunk-4HEWA4IO.js → chunk-SLDZJD6Q.js} +1 -1
- package/dist/{chunk-C2AEY4AI.js → chunk-TC4FTRYO.js} +2 -2
- package/dist/{chunk-UMSJ4DU2.js → chunk-U67RBNIZ.js} +1 -1
- package/dist/{chunk-C2AJBMP2.js → chunk-VOC4KOOP.js} +2 -2
- package/dist/chunk-W27EFR7W.js +271 -0
- package/dist/{chunk-OIXHRN32.js → chunk-XWAKFL3T.js} +9 -7
- package/dist/daemon/server.js +2733 -2531
- package/dist/hook-runtime/daemon/server.js +2733 -2531
- package/dist/hook-runtime/hooks/post-commit.js +2740 -2538
- package/dist/hook-runtime/hooks/post-rewrite.js +2740 -2538
- package/dist/hook-runtime/hooks/post-tool-use.js +2854 -2550
- package/dist/hook-runtime/hooks/pre-tool-use-worker.js +2907 -2564
- package/dist/hook-runtime/hooks/pre-tool-use.js +36 -1
- package/dist/hook-runtime/hooks/prim-hook.js +2853 -2549
- package/dist/hook-runtime/hooks/session-end.js +5 -2
- package/dist/hook-runtime/hooks/session-start.js +2740 -2538
- package/dist/hook-runtime/index.js +2793 -2581
- package/dist/hook-runtime/statusline-main.js +5 -2
- package/dist/hooks/post-commit.js +7 -7
- package/dist/hooks/post-rewrite.js +6 -6
- package/dist/hooks/post-tool-use.js +16 -15
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use-worker.js +77 -35
- package/dist/hooks/pre-tool-use.js +26 -1
- package/dist/hooks/prim-hook.js +17 -16
- package/dist/hooks/session-end.js +4 -4
- package/dist/hooks/session-start.js +11 -11
- package/dist/index.js +20 -16
- package/dist/statusline-main.js +5 -2
- package/package.json +1 -1
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
analyzeShellTargets
|
|
3
|
-
|
|
4
|
-
} from "./chunk-L3NUFCOD.js";
|
|
2
|
+
analyzeShellTargets
|
|
3
|
+
} from "./chunk-4L7TAM5S.js";
|
|
5
4
|
import {
|
|
6
5
|
DEFAULT_RULES,
|
|
7
6
|
scrub
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NQFRQ56V.js";
|
|
9
8
|
import {
|
|
10
9
|
boundedHealthError,
|
|
11
10
|
isPreflightResponseV4
|
|
12
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-5BQ2NEMP.js";
|
|
13
12
|
import {
|
|
14
13
|
getClient,
|
|
15
14
|
terminalSafeLine
|
|
16
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-U67RBNIZ.js";
|
|
17
16
|
import {
|
|
18
17
|
canonicalGitRoot,
|
|
19
18
|
canonicalRepositoryPath
|
|
20
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-P2O7NLVN.js";
|
|
20
|
+
import {
|
|
21
|
+
extractFileTargets
|
|
22
|
+
} from "./chunk-W27EFR7W.js";
|
|
21
23
|
|
|
22
24
|
// src/hooks/approval-copy.ts
|
|
23
25
|
var MAX_EXCERPT_CHARS = 80;
|
|
@@ -103,7 +105,7 @@ function resolvePreflightTargets(args) {
|
|
|
103
105
|
if (typeof command !== "string") {
|
|
104
106
|
return { paths: [], coverage: "unverified", mutation: "present" };
|
|
105
107
|
}
|
|
106
|
-
const shell = analyzeShellTargets(command);
|
|
108
|
+
const shell = analyzeShellTargets(command, args.cwd);
|
|
107
109
|
rawPaths = shell.paths;
|
|
108
110
|
coverage = shell.coverage;
|
|
109
111
|
mutation = shell.mutation;
|
|
@@ -362,7 +364,7 @@ async function requestPreflight(operation, deadline = performance.now() + PREFLI
|
|
|
362
364
|
const remaining = deadline - performance.now();
|
|
363
365
|
if (remaining <= 0)
|
|
364
366
|
throw new PreflightPausedError(
|
|
365
|
-
"The
|
|
367
|
+
"The check deadline expired",
|
|
366
368
|
operation.operation === "start" ? void 0 : operation.checkId
|
|
367
369
|
);
|
|
368
370
|
const value = await getClient().post(ENDPOINT, operation, {
|
|
@@ -371,7 +373,7 @@ async function requestPreflight(operation, deadline = performance.now() + PREFLI
|
|
|
371
373
|
});
|
|
372
374
|
if (performance.now() >= deadline)
|
|
373
375
|
throw new PreflightPausedError(
|
|
374
|
-
"The
|
|
376
|
+
"The check deadline expired",
|
|
375
377
|
operation.operation === "start" ? void 0 : operation.checkId
|
|
376
378
|
);
|
|
377
379
|
const response = parsePreflightResponse2(value);
|
|
@@ -380,7 +382,7 @@ async function requestPreflight(operation, deadline = performance.now() + PREFLI
|
|
|
380
382
|
"The enforcement service returned an incompatible V4 response",
|
|
381
383
|
operation.operation === "start" ? void 0 : operation.checkId
|
|
382
384
|
);
|
|
383
|
-
if (response.reasonCode === "no_targets_skipped" && !(operation.operation === "start" && operation.paths.length === 0 && operation.coverage === "unverified" && isNoTargetsSkip(response))) {
|
|
385
|
+
if (response.reasonCode === "no_targets_skipped" && !(operation.operation === "start" && !operation.shellCheck && operation.paths.length === 0 && operation.coverage === "unverified" && isNoTargetsSkip(response))) {
|
|
384
386
|
throw new PreflightPausedError(
|
|
385
387
|
"The enforcement service returned an invalid target-policy exemption",
|
|
386
388
|
operation.operation === "start" ? void 0 : operation.checkId
|
|
@@ -396,6 +398,7 @@ async function requestPreflight(operation, deadline = performance.now() + PREFLI
|
|
|
396
398
|
async function waitForPreflight(operation, options = {}) {
|
|
397
399
|
const deadline = options.deadline ?? performance.now() + PREFLIGHT_WAIT_MS;
|
|
398
400
|
let next = operation;
|
|
401
|
+
const shellCheck = operation.operation === "start" ? operation.shellCheck : void 0;
|
|
399
402
|
let evaluationId;
|
|
400
403
|
let lastProgress;
|
|
401
404
|
let checkId = operation.operation === "start" ? void 0 : operation.checkId;
|
|
@@ -406,7 +409,7 @@ async function waitForPreflight(operation, options = {}) {
|
|
|
406
409
|
} catch (error) {
|
|
407
410
|
if (error instanceof PreflightPausedError) throw error;
|
|
408
411
|
if (performance.now() >= deadline)
|
|
409
|
-
throw new PreflightPausedError("The
|
|
412
|
+
throw new PreflightPausedError("The check deadline expired", checkId);
|
|
410
413
|
if (checkId)
|
|
411
414
|
throw new PreflightPausedError(
|
|
412
415
|
"The enforcement service could not finish this check",
|
|
@@ -414,6 +417,9 @@ async function waitForPreflight(operation, options = {}) {
|
|
|
414
417
|
);
|
|
415
418
|
throw error;
|
|
416
419
|
}
|
|
420
|
+
if (shellCheck && response.shellCheck?.targetMode !== shellCheck.targetMode && !(response.reasonCode === "enforcement_disabled" && hasCompleteCoverage(response))) {
|
|
421
|
+
throw new PreflightPausedError("The backend did not confirm shell-check support", checkId);
|
|
422
|
+
}
|
|
417
423
|
if (isUnidentifiedPause(response)) {
|
|
418
424
|
if (checkId) throw new PreflightPausedError(response.message || response.reasonCode, checkId);
|
|
419
425
|
return response;
|
|
@@ -431,8 +437,7 @@ async function waitForPreflight(operation, options = {}) {
|
|
|
431
437
|
if (progress !== lastProgress) options.onProgress?.(response);
|
|
432
438
|
lastProgress = progress;
|
|
433
439
|
const remaining = deadline - performance.now();
|
|
434
|
-
if (remaining <= 0)
|
|
435
|
-
throw new PreflightPausedError("The 240-second check wait expired", checkId);
|
|
440
|
+
if (remaining <= 0) throw new PreflightPausedError("The check deadline expired", checkId);
|
|
436
441
|
await delay(
|
|
437
442
|
Math.min(remaining, Math.max(100, Math.min(5e3, response.retryAfterMs ?? 1e3)))
|
|
438
443
|
);
|
|
@@ -450,6 +455,8 @@ export {
|
|
|
450
455
|
toolInputDigest,
|
|
451
456
|
hasCompleteCoverage,
|
|
452
457
|
hasConfirmedConflict,
|
|
458
|
+
PreflightPausedError,
|
|
459
|
+
pausedResult,
|
|
453
460
|
resultForPreflight2 as resultForPreflight,
|
|
454
461
|
requestPreflight,
|
|
455
462
|
waitForPreflight
|
|
@@ -1,274 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
inspectHookRuntime
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MWNRXAEB.js";
|
|
4
4
|
import {
|
|
5
5
|
isDemoStatusResponse
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5BQ2NEMP.js";
|
|
7
7
|
import {
|
|
8
8
|
atomicWriteFile,
|
|
9
9
|
primConfigDirectory,
|
|
10
10
|
withFileLock,
|
|
11
11
|
withFileLockSync
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function anyUnverified(results) {
|
|
17
|
-
return results.some((r) => r.verdict === "unavailable" || r.truncated);
|
|
18
|
-
}
|
|
19
|
-
function unverifiedNote(results) {
|
|
20
|
-
const causes = [];
|
|
21
|
-
const unavailable = results.find((r) => r.verdict === "unavailable");
|
|
22
|
-
if (unavailable) {
|
|
23
|
-
causes.push(
|
|
24
|
-
unavailable.unavailable ? `decision check skipped \u2014 ${unavailable.unavailable}` : "decision check skipped \u2014 not verified"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
if (results.some((r) => r.truncated)) {
|
|
28
|
-
causes.push("decision check partial \u2014 conflict set truncated (per-file cap hit)");
|
|
29
|
-
}
|
|
30
|
-
return causes.map((c) => `[primitive] ${c}`).join("\n");
|
|
31
|
-
}
|
|
32
|
-
function blockingReason(results) {
|
|
33
|
-
const parts = results.filter((result) => result.verdict === "ask" || result.verdict === "deny").flatMap((result) => [result.reason, result.additionalContext]).filter((value) => value.length > 0);
|
|
34
|
-
return [...new Set(parts)].join("\n\n") || "[primitive] conflict detected (no detail available)";
|
|
35
|
-
}
|
|
36
|
-
function approvalReason(results) {
|
|
37
|
-
const summaries = results.filter((result) => result.verdict === "ask" || result.verdict === "deny").map((result) => result.reason).filter(Boolean);
|
|
38
|
-
return [
|
|
39
|
-
...new Set(summaries),
|
|
40
|
-
"Approve runs this edit once; it does not change these decisions."
|
|
41
|
-
].join("\n");
|
|
42
|
-
}
|
|
43
|
-
function agentContext(results) {
|
|
44
|
-
return [...new Set(results.map((result) => result.additionalContext).filter(Boolean))].join(
|
|
45
|
-
"\n\n"
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
function advisoryNote(aggregate, results) {
|
|
49
|
-
const details = results.flatMap((result) => [
|
|
50
|
-
...aggregate === "warn" ? [result.reason] : [],
|
|
51
|
-
result.additionalContext
|
|
52
|
-
]);
|
|
53
|
-
if (anyUnverified(results)) details.push(unverifiedNote(results));
|
|
54
|
-
return [...new Set(details.filter((value) => value.length > 0))].join("\n\n");
|
|
55
|
-
}
|
|
56
|
-
function buildHookOutput(aggregate, results) {
|
|
57
|
-
if (aggregate === "ask") {
|
|
58
|
-
const context = agentContext(results);
|
|
59
|
-
return {
|
|
60
|
-
hookSpecificOutput: {
|
|
61
|
-
hookEventName: "PreToolUse",
|
|
62
|
-
permissionDecision: "ask",
|
|
63
|
-
permissionDecisionReason: approvalReason(results),
|
|
64
|
-
...context ? { additionalContext: context } : {}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
if (aggregate === "deny") {
|
|
69
|
-
return {
|
|
70
|
-
hookSpecificOutput: {
|
|
71
|
-
hookEventName: "PreToolUse",
|
|
72
|
-
permissionDecision: aggregate,
|
|
73
|
-
permissionDecisionReason: blockingReason(results)
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
const notes = advisoryNote(aggregate, results);
|
|
78
|
-
if (notes.length > 0) {
|
|
79
|
-
return {
|
|
80
|
-
systemMessage: notes,
|
|
81
|
-
hookSpecificOutput: {
|
|
82
|
-
hookEventName: "PreToolUse",
|
|
83
|
-
permissionDecision: "allow",
|
|
84
|
-
additionalContext: notes
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
hookSpecificOutput: {
|
|
90
|
-
hookEventName: "PreToolUse",
|
|
91
|
-
permissionDecision: "allow"
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function buildCodexOutput(aggregate, results) {
|
|
96
|
-
if (aggregate === "deny" || aggregate === "ask") {
|
|
97
|
-
return {
|
|
98
|
-
hookSpecificOutput: {
|
|
99
|
-
hookEventName: "PreToolUse",
|
|
100
|
-
permissionDecision: "deny",
|
|
101
|
-
permissionDecisionReason: blockingReason(results)
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
const notes = advisoryNote(aggregate, results);
|
|
106
|
-
return notes ? {
|
|
107
|
-
systemMessage: notes,
|
|
108
|
-
hookSpecificOutput: { hookEventName: "PreToolUse", additionalContext: notes }
|
|
109
|
-
} : {};
|
|
110
|
-
}
|
|
111
|
-
function buildCursorOutput(aggregate, results) {
|
|
112
|
-
if (aggregate === "deny" || aggregate === "ask") {
|
|
113
|
-
const reason = blockingReason(results);
|
|
114
|
-
return { permission: "deny", user_message: reason, agent_message: reason };
|
|
115
|
-
}
|
|
116
|
-
const notes = advisoryNote(aggregate, results);
|
|
117
|
-
return notes ? { permission: "allow", agent_message: notes } : { permission: "allow" };
|
|
118
|
-
}
|
|
119
|
-
function failOpenOutput() {
|
|
120
|
-
return {
|
|
121
|
-
hookSpecificOutput: {
|
|
122
|
-
hookEventName: "PreToolUse",
|
|
123
|
-
permissionDecision: "allow"
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function failOpenCodex() {
|
|
128
|
-
return {};
|
|
129
|
-
}
|
|
130
|
-
function failOpenCursor() {
|
|
131
|
-
return { permission: "allow" };
|
|
132
|
-
}
|
|
133
|
-
function buildHermesOutput(aggregate, results) {
|
|
134
|
-
if (aggregate !== "deny" && aggregate !== "ask") {
|
|
135
|
-
return {};
|
|
136
|
-
}
|
|
137
|
-
const reason = results.filter((r) => r.verdict === "deny" || r.verdict === "ask").map((r) => r.reason).filter((s) => s.length > 0).join("\n\n");
|
|
138
|
-
const directive = results.map((r) => r.additionalContext).filter((s) => s.length > 0 && s !== reason).join("\n");
|
|
139
|
-
const message = [reason, directive].filter((s) => s.length > 0).join("\n\n") || "[primitive] conflict detected (no detail available)";
|
|
140
|
-
return { action: "block", message };
|
|
141
|
-
}
|
|
142
|
-
function failOpenHermes() {
|
|
143
|
-
return {};
|
|
144
|
-
}
|
|
145
|
-
var SUPPORTED_TOOLS = /* @__PURE__ */ new Set(["Edit", "Write", "MultiEdit", "NotebookEdit"]);
|
|
146
|
-
var APPLY_PATCH_FILE_RE = /^\*\*\* (?:Update|Add|Delete) File: (?<path>.+)$/;
|
|
147
|
-
var MOVE_FILE_RE = /^\*\*\* Move File:\s*(?<src>.+?)\s*->\s*(?<dst>.+?)\s*$/;
|
|
148
|
-
var MOVE_TO_RE = /^\*\*\* Move to: (?<dst>.+)$/;
|
|
149
|
-
var LINE_SPLIT_RE = /\r?\n/;
|
|
150
|
-
function parseApplyPatchTargets(command) {
|
|
151
|
-
const paths = /* @__PURE__ */ new Set();
|
|
152
|
-
let activeUpdate = false;
|
|
153
|
-
let complete = true;
|
|
154
|
-
for (const line of command.split(LINE_SPLIT_RE)) {
|
|
155
|
-
const path = APPLY_PATCH_FILE_RE.exec(line)?.groups?.path;
|
|
156
|
-
if (path) {
|
|
157
|
-
paths.add(path);
|
|
158
|
-
activeUpdate = line.startsWith("*** Update File:");
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
const moveTo = MOVE_TO_RE.exec(line)?.groups?.dst;
|
|
162
|
-
if (moveTo) {
|
|
163
|
-
if (activeUpdate) paths.add(moveTo);
|
|
164
|
-
else complete = false;
|
|
165
|
-
activeUpdate = false;
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
const move = MOVE_FILE_RE.exec(line)?.groups;
|
|
169
|
-
if (move?.src) {
|
|
170
|
-
paths.add(move.src);
|
|
171
|
-
if (move.dst) {
|
|
172
|
-
paths.add(move.dst);
|
|
173
|
-
}
|
|
174
|
-
activeUpdate = false;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
if (line === "*** Begin Patch" || line === "*** End Patch") activeUpdate = false;
|
|
178
|
-
else if (line.startsWith("*** ")) complete = false;
|
|
179
|
-
}
|
|
180
|
-
return { paths: [...paths], complete: complete && paths.size > 0 };
|
|
181
|
-
}
|
|
182
|
-
function extractCodexFileTargets(toolName, toolInput) {
|
|
183
|
-
if (toolName !== "apply_patch") {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
const text = codexPatchText(toolInput);
|
|
187
|
-
return text !== null ? parseApplyPatchTargets(text) : { paths: [], complete: false };
|
|
188
|
-
}
|
|
189
|
-
function codexPatchText(toolInput) {
|
|
190
|
-
if (typeof toolInput === "string") return toolInput;
|
|
191
|
-
if (!toolInput || typeof toolInput !== "object") return null;
|
|
192
|
-
const input = toolInput;
|
|
193
|
-
for (const key of ["command", "input", "patch"]) {
|
|
194
|
-
const value = input[key];
|
|
195
|
-
if (typeof value === "string") return value;
|
|
196
|
-
}
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
var HERMES_EDITING_TOOLS = /* @__PURE__ */ new Set(["write_file", "patch"]);
|
|
200
|
-
function extractHermesFileTargets(toolName, toolInput) {
|
|
201
|
-
if (!HERMES_EDITING_TOOLS.has(toolName)) {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
if (!toolInput || typeof toolInput !== "object") {
|
|
205
|
-
return { paths: [], complete: false };
|
|
206
|
-
}
|
|
207
|
-
const input = toolInput;
|
|
208
|
-
if (toolName === "patch" && input.mode === "patch") {
|
|
209
|
-
return typeof input.patch === "string" ? parseApplyPatchTargets(input.patch) : { paths: [], complete: false };
|
|
210
|
-
}
|
|
211
|
-
const paths = typeof input.path === "string" && input.path.length > 0 ? [input.path] : [];
|
|
212
|
-
const mode = input.mode;
|
|
213
|
-
return { paths, complete: paths.length > 0 && (mode === void 0 || mode === "replace") };
|
|
214
|
-
}
|
|
215
|
-
function extractCursorFileTargets(toolName, toolInput) {
|
|
216
|
-
if (toolName !== "Write" && toolName !== "Delete") return null;
|
|
217
|
-
if (!toolInput || typeof toolInput !== "object" || Array.isArray(toolInput)) {
|
|
218
|
-
return { paths: [], complete: false };
|
|
219
|
-
}
|
|
220
|
-
const input = toolInput;
|
|
221
|
-
const candidates = [input.file_path, input.path].filter(
|
|
222
|
-
(value) => typeof value === "string" && value.length > 0
|
|
223
|
-
);
|
|
224
|
-
const paths = [...new Set(candidates)];
|
|
225
|
-
return { paths, complete: paths.length === 1 };
|
|
226
|
-
}
|
|
227
|
-
function extractFileTargets(toolName, toolInput, agent = "claude_code") {
|
|
228
|
-
if (agent === "codex") {
|
|
229
|
-
return extractCodexFileTargets(toolName, toolInput);
|
|
230
|
-
}
|
|
231
|
-
if (agent === "cursor") {
|
|
232
|
-
return extractCursorFileTargets(toolName, toolInput);
|
|
233
|
-
}
|
|
234
|
-
if (agent === "hermes") {
|
|
235
|
-
return extractHermesFileTargets(toolName, toolInput);
|
|
236
|
-
}
|
|
237
|
-
if (!SUPPORTED_TOOLS.has(toolName)) {
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
if (!toolInput || typeof toolInput !== "object") {
|
|
241
|
-
return { paths: [], complete: false };
|
|
242
|
-
}
|
|
243
|
-
const input = toolInput;
|
|
244
|
-
if (toolName === "NotebookEdit") {
|
|
245
|
-
const paths2 = typeof input.notebook_path === "string" && input.notebook_path.length > 0 ? [input.notebook_path] : [];
|
|
246
|
-
return { paths: paths2, complete: paths2.length > 0 };
|
|
247
|
-
}
|
|
248
|
-
const paths = typeof input.file_path === "string" && input.file_path.length > 0 ? [input.file_path] : [];
|
|
249
|
-
return { paths, complete: paths.length > 0 };
|
|
250
|
-
}
|
|
251
|
-
function readHookMode(env) {
|
|
252
|
-
if (env.PRIM_BYPASS === "1" || env.PRIM_BYPASS === "true") {
|
|
253
|
-
return "off";
|
|
254
|
-
}
|
|
255
|
-
const mode = env.PRIM_HOOK_MODE;
|
|
256
|
-
if (mode === "off" || mode === "warn") {
|
|
257
|
-
return mode;
|
|
258
|
-
}
|
|
259
|
-
return "block";
|
|
260
|
-
}
|
|
261
|
-
function demoteForMode(verdict, mode) {
|
|
262
|
-
if (mode === "off") {
|
|
263
|
-
return "allow";
|
|
264
|
-
}
|
|
265
|
-
if (mode === "warn" && (verdict === "ask" || verdict === "deny")) {
|
|
266
|
-
return "warn";
|
|
267
|
-
}
|
|
268
|
-
return verdict;
|
|
269
|
-
}
|
|
12
|
+
} from "./chunk-P2O7NLVN.js";
|
|
13
|
+
import {
|
|
14
|
+
parseApplyPatchTargets
|
|
15
|
+
} from "./chunk-W27EFR7W.js";
|
|
270
16
|
|
|
271
17
|
// src/hooks/shell-targets.ts
|
|
18
|
+
import { realpathSync } from "fs";
|
|
19
|
+
import { posix, resolve } from "path";
|
|
272
20
|
import { parse } from "unbash";
|
|
273
21
|
|
|
274
22
|
// src/hooks/script-targets.ts
|
|
@@ -656,7 +404,7 @@ function staticPart(part) {
|
|
|
656
404
|
return STATIC_PARTS.has(part.type) || part.type === "DoubleQuoted" && part.parts.every(staticPart);
|
|
657
405
|
}
|
|
658
406
|
function staticWord(word) {
|
|
659
|
-
if (!word ||
|
|
407
|
+
if (!word || word.value.includes("\0") || word.value.includes("\n")) return;
|
|
660
408
|
if (word.parts ? !word.parts.every(staticPart) : word.value.startsWith("~") || /[*?\[$`]/.test(word.text))
|
|
661
409
|
return;
|
|
662
410
|
return word.value;
|
|
@@ -940,11 +688,66 @@ function unknown(state) {
|
|
|
940
688
|
state.complete = false;
|
|
941
689
|
state.mutation = true;
|
|
942
690
|
}
|
|
691
|
+
function addTarget(path, state) {
|
|
692
|
+
if (state.cwdUncertain) {
|
|
693
|
+
state.complete = false;
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
state.paths.add(
|
|
697
|
+
state.cwdPrefix && !posix.isAbsolute(path) ? posix.join(state.cwdPrefix, path) : path
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
function sedWriteTargets(words) {
|
|
701
|
+
const args = staticArgs(words);
|
|
702
|
+
if (!args) return;
|
|
703
|
+
let suffix;
|
|
704
|
+
let gnuInPlace = false;
|
|
705
|
+
const programs = [];
|
|
706
|
+
const files = [];
|
|
707
|
+
let positionalProgram = true;
|
|
708
|
+
let options = true;
|
|
709
|
+
for (let i = 0; i < args.length; i++) {
|
|
710
|
+
const arg = args[i];
|
|
711
|
+
if (options && arg === "--") {
|
|
712
|
+
options = false;
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
if (options && (arg === "-i" || arg === "--in-place")) {
|
|
716
|
+
if (suffix !== void 0) return;
|
|
717
|
+
suffix = "";
|
|
718
|
+
gnuInPlace = arg === "--in-place";
|
|
719
|
+
if (arg === "-i" && (args[i + 1] === "" || args[i + 1]?.startsWith("."))) suffix = args[++i];
|
|
720
|
+
} else if (options && (arg.startsWith("-i") || arg.startsWith("--in-place="))) {
|
|
721
|
+
if (suffix !== void 0) return;
|
|
722
|
+
gnuInPlace = arg.startsWith("--in-place=");
|
|
723
|
+
suffix = arg.startsWith("-i") ? arg.slice(2) : arg.slice("--in-place=".length);
|
|
724
|
+
} else if (options && (arg === "-e" || arg === "--expression")) {
|
|
725
|
+
const program = args[++i];
|
|
726
|
+
if (!program) return;
|
|
727
|
+
programs.push(program);
|
|
728
|
+
positionalProgram = false;
|
|
729
|
+
} else if (options && (arg.startsWith("-e") || arg.startsWith("--expression="))) {
|
|
730
|
+
programs.push(arg.startsWith("-e") ? arg.slice(2) : arg.slice("--expression=".length));
|
|
731
|
+
positionalProgram = false;
|
|
732
|
+
} else if (options && ["-E", "-r", "-n", "--regexp-extended", "--quiet", "--silent"].includes(arg)) {
|
|
733
|
+
} else if (options && arg.startsWith("-")) return;
|
|
734
|
+
else if (positionalProgram) {
|
|
735
|
+
programs.push(arg);
|
|
736
|
+
positionalProgram = false;
|
|
737
|
+
} else files.push(arg);
|
|
738
|
+
}
|
|
739
|
+
if (suffix === void 0 || !programs.length || !programs.every(safeSedProgram) || !files.length || files.some((file) => !file || file === "-"))
|
|
740
|
+
return;
|
|
741
|
+
if (suffix.includes("*") && !gnuInPlace) return;
|
|
742
|
+
return files.flatMap(
|
|
743
|
+
(file) => suffix ? [file, suffix.includes("*") ? suffix.replaceAll("*", file) : file + suffix] : [file]
|
|
744
|
+
);
|
|
745
|
+
}
|
|
943
746
|
function recordTarget(word, state) {
|
|
944
747
|
const path = staticWord(word);
|
|
945
748
|
if (path === "-" || path && (SINKS.has(path) || path.startsWith("/dev/fd/"))) return;
|
|
946
749
|
state.mutation = true;
|
|
947
|
-
if (path)
|
|
750
|
+
if (path) addTarget(path, state);
|
|
948
751
|
else state.complete = false;
|
|
949
752
|
}
|
|
950
753
|
function visitRedirect(redirect, state) {
|
|
@@ -974,7 +777,7 @@ function visitApplyPatch(command, state) {
|
|
|
974
777
|
continue;
|
|
975
778
|
}
|
|
976
779
|
const targets = parseApplyPatchTargets(redirect.content);
|
|
977
|
-
for (const path of targets.paths)
|
|
780
|
+
for (const path of targets.paths) addTarget(path, state);
|
|
978
781
|
if (!targets.complete) state.complete = false;
|
|
979
782
|
}
|
|
980
783
|
if (!hasBody) state.complete = false;
|
|
@@ -1013,7 +816,7 @@ function embeddedScript(command, name, state) {
|
|
|
1013
816
|
source = heredoc.content;
|
|
1014
817
|
}
|
|
1015
818
|
if (source !== void 0)
|
|
1016
|
-
for (const path of scriptWriteTargets(source, language))
|
|
819
|
+
for (const path of scriptWriteTargets(source, language)) addTarget(path, state);
|
|
1017
820
|
}
|
|
1018
821
|
function changesDirectory(value) {
|
|
1019
822
|
if (Array.isArray(value)) return value.some(changesDirectory);
|
|
@@ -1027,6 +830,7 @@ function changesDirectory(value) {
|
|
|
1027
830
|
}
|
|
1028
831
|
function visitCommand(command, state) {
|
|
1029
832
|
const name = staticWord(command.name);
|
|
833
|
+
if (command.prefix.length) unknown(state);
|
|
1030
834
|
const literalApplyPatch = name === "apply_patch" && !command.redirects.some((redirect) => redirect.operator === "<<-");
|
|
1031
835
|
if (literalApplyPatch) {
|
|
1032
836
|
visitApplyPatch(command, state);
|
|
@@ -1035,13 +839,15 @@ function visitCommand(command, state) {
|
|
|
1035
839
|
}
|
|
1036
840
|
if (name && (name === "node" || /^python(?:3(?:\.\d+)?)?$/.test(name))) {
|
|
1037
841
|
embeddedScript(command, name, state);
|
|
1038
|
-
} else if (!name || name.includes("/") || !literalApplyPatch && command.suffix.some((word) =>
|
|
842
|
+
} else if (!name || name.includes("/") || !literalApplyPatch && command.suffix.some((word) => staticWord(word) === void 0)) {
|
|
1039
843
|
unknown(state);
|
|
1040
844
|
} else if (literalApplyPatch) {
|
|
1041
845
|
} else if (!READ_ONLY_COMMANDS.has(name) && !knownNoWorktreeMutation(name, staticArgs(command.suffix))) {
|
|
1042
846
|
state.mutation = true;
|
|
1043
847
|
let targets;
|
|
1044
|
-
if (name === "
|
|
848
|
+
if (name === "sed") {
|
|
849
|
+
targets = sedWriteTargets(command.suffix);
|
|
850
|
+
} else if (name === "tee") {
|
|
1045
851
|
targets = operands(command.suffix, "ai", /* @__PURE__ */ new Set(["--append", "--ignore-interrupts"]));
|
|
1046
852
|
} else if (name === "touch") {
|
|
1047
853
|
targets = operands(command.suffix);
|
|
@@ -1056,7 +862,7 @@ function visitCommand(command, state) {
|
|
|
1056
862
|
if (pair?.length === 2) targets = name === "cp" ? [pair[1]] : pair;
|
|
1057
863
|
}
|
|
1058
864
|
if (!targets?.length) state.complete = false;
|
|
1059
|
-
else for (const target of targets)
|
|
865
|
+
else for (const target of targets) addTarget(target, state);
|
|
1060
866
|
}
|
|
1061
867
|
visitNested([command.name, command.prefix, command.suffix, command.redirects], state);
|
|
1062
868
|
}
|
|
@@ -1085,7 +891,45 @@ function visitStatement(statement, state) {
|
|
|
1085
891
|
for (const redirect of statement.redirects) visitRedirect(redirect, state);
|
|
1086
892
|
visitNested([statement.redirects, statement.command], state);
|
|
1087
893
|
}
|
|
1088
|
-
function
|
|
894
|
+
function visitStaticDirectoryChain(script, state, cwd) {
|
|
895
|
+
if (script.errors?.length || script.commands.length !== 1) return false;
|
|
896
|
+
const statement = script.commands[0];
|
|
897
|
+
const chain = statement.command;
|
|
898
|
+
if (statement.background || statement.redirects.length || chain.type !== "AndOr" || chain.operators.some((operator) => operator !== "&&") || chain.commands.some((command) => command.type !== "Command"))
|
|
899
|
+
return false;
|
|
900
|
+
const commands = chain.commands;
|
|
901
|
+
if (!commands.some((command) => staticWord(command.name) === "cd")) return false;
|
|
902
|
+
let prefix = "";
|
|
903
|
+
const visits = [];
|
|
904
|
+
for (const command of commands) {
|
|
905
|
+
if (staticWord(command.name) !== "cd") {
|
|
906
|
+
if (changesDirectory(command)) return false;
|
|
907
|
+
visits.push({ command, prefix });
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
const args = staticArgs(command.suffix);
|
|
911
|
+
if (!args || command.prefix.length || command.redirects.length) return false;
|
|
912
|
+
if (args[0] === "--") args.shift();
|
|
913
|
+
if (args.length !== 1 || !args[0] || args[0].startsWith("-")) return false;
|
|
914
|
+
if (process.env.CDPATH && !args[0].startsWith(".") && !posix.isAbsolute(args[0])) return false;
|
|
915
|
+
prefix = posix.isAbsolute(args[0]) ? args[0] : posix.join(prefix, args[0]);
|
|
916
|
+
if (cwd) {
|
|
917
|
+
try {
|
|
918
|
+
const absolute = resolve(realpathSync(cwd), prefix);
|
|
919
|
+
if (realpathSync(absolute) !== absolute) return false;
|
|
920
|
+
} catch {
|
|
921
|
+
return false;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
state.cwdUncertain = false;
|
|
926
|
+
for (const visit of visits) {
|
|
927
|
+
state.cwdPrefix = visit.prefix;
|
|
928
|
+
visitCommand(visit.command, state);
|
|
929
|
+
}
|
|
930
|
+
return true;
|
|
931
|
+
}
|
|
932
|
+
function analyzeShellTargets(source, cwd) {
|
|
1089
933
|
if (!source.trim())
|
|
1090
934
|
return { paths: [], coverage: "complete", mutation: "none" };
|
|
1091
935
|
try {
|
|
@@ -1097,7 +941,9 @@ function analyzeShellTargets(source) {
|
|
|
1097
941
|
definiteEdit: false,
|
|
1098
942
|
cwdUncertain: changesDirectory(script)
|
|
1099
943
|
};
|
|
1100
|
-
|
|
944
|
+
if (!visitStaticDirectoryChain(script, state, cwd)) {
|
|
945
|
+
for (const statement of script.commands) visitStatement(statement, state);
|
|
946
|
+
}
|
|
1101
947
|
if (script.errors?.length) state.mutation = true;
|
|
1102
948
|
return {
|
|
1103
949
|
paths: [...state.paths],
|
|
@@ -1113,7 +959,7 @@ function analyzeShellTargets(source) {
|
|
|
1113
959
|
// src/demo/state.ts
|
|
1114
960
|
import { createHash, randomUUID } from "crypto";
|
|
1115
961
|
import { existsSync, lstatSync, readFileSync, readdirSync } from "fs";
|
|
1116
|
-
import { join, resolve } from "path";
|
|
962
|
+
import { join, resolve as resolve2 } from "path";
|
|
1117
963
|
var RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
1118
964
|
var demoDirectory = () => join(primConfigDirectory(), "demo");
|
|
1119
965
|
var runPath = (id) => {
|
|
@@ -1156,7 +1002,7 @@ function prepareRun(agent, terminal = false) {
|
|
|
1156
1002
|
terminal,
|
|
1157
1003
|
agent,
|
|
1158
1004
|
preparationKey: preparationKey(agent),
|
|
1159
|
-
launcher: [process.execPath,
|
|
1005
|
+
launcher: [process.execPath, resolve2(process.argv[1])]
|
|
1160
1006
|
};
|
|
1161
1007
|
saveRun(run);
|
|
1162
1008
|
return run;
|
|
@@ -1178,7 +1024,7 @@ function demoCommand(run, action, choice, reason) {
|
|
|
1178
1024
|
function demoWelcomeCommand(run) {
|
|
1179
1025
|
return [
|
|
1180
1026
|
process.execPath,
|
|
1181
|
-
|
|
1027
|
+
resolve2(process.argv[1]),
|
|
1182
1028
|
"welcome",
|
|
1183
1029
|
"--after-demo",
|
|
1184
1030
|
...run.agent ? ["--agent", run.agent === "claude_code" ? "claude" : run.agent] : [],
|
|
@@ -1186,10 +1032,10 @@ function demoWelcomeCommand(run) {
|
|
|
1186
1032
|
].map(quote).join(" ");
|
|
1187
1033
|
}
|
|
1188
1034
|
function demoDiagnosticCommand(run) {
|
|
1189
|
-
return [process.execPath,
|
|
1035
|
+
return [process.execPath, resolve2(process.argv[1]), "demo", "status", run.id].map(quote).join(" ");
|
|
1190
1036
|
}
|
|
1191
1037
|
function demoResumeCommand(run) {
|
|
1192
|
-
return [process.execPath,
|
|
1038
|
+
return [process.execPath, resolve2(process.argv[1]), "demo", "resume", run.id].map(quote).join(" ");
|
|
1193
1039
|
}
|
|
1194
1040
|
function onboardingFinished() {
|
|
1195
1041
|
const path = join(demoDirectory(), "onboarding.json");
|
|
@@ -1306,17 +1152,6 @@ function isolationDiagnostics(run) {
|
|
|
1306
1152
|
}
|
|
1307
1153
|
|
|
1308
1154
|
export {
|
|
1309
|
-
buildHookOutput,
|
|
1310
|
-
buildCodexOutput,
|
|
1311
|
-
buildCursorOutput,
|
|
1312
|
-
failOpenOutput,
|
|
1313
|
-
failOpenCodex,
|
|
1314
|
-
failOpenCursor,
|
|
1315
|
-
buildHermesOutput,
|
|
1316
|
-
failOpenHermes,
|
|
1317
|
-
extractFileTargets,
|
|
1318
|
-
readHookMode,
|
|
1319
|
-
demoteForMode,
|
|
1320
1155
|
analyzeShellTargets,
|
|
1321
1156
|
RUN_ID,
|
|
1322
1157
|
runPath,
|