@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
|
@@ -584,7 +584,7 @@ var GIT_TIMEOUT_MS2 = 1e3;
|
|
|
584
584
|
var REPO_SYNC_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
585
585
|
var PROJECT_INSTALL_FILES = [".claude/settings.json", ".codex/hooks.json", ".cursor/hooks.json"];
|
|
586
586
|
var PRIM_HOOK_BINS = ["prim-hook", "prim-pre-tool-use", "prim-post-tool-use"];
|
|
587
|
-
function repoActiveFlag(cwd) {
|
|
587
|
+
function repoActiveFlag(cwd, strict = false) {
|
|
588
588
|
try {
|
|
589
589
|
const value = execFileSync2("git", ["config", "--get", PRIM_ACTIVE_KEY], {
|
|
590
590
|
cwd,
|
|
@@ -594,8 +594,11 @@ function repoActiveFlag(cwd) {
|
|
|
594
594
|
}).trim();
|
|
595
595
|
if (value === "true") return "true";
|
|
596
596
|
if (value === "false") return "false";
|
|
597
|
+
if (strict) throw new Error("Repository activation is invalid");
|
|
597
598
|
return void 0;
|
|
598
|
-
} catch {
|
|
599
|
+
} catch (error) {
|
|
600
|
+
if (strict && !(typeof error === "object" && error !== null && "status" in error && error.status === 1))
|
|
601
|
+
throw error;
|
|
599
602
|
return void 0;
|
|
600
603
|
}
|
|
601
604
|
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
recordPostCommitFired
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-LBCPRHNG.js";
|
|
5
5
|
import {
|
|
6
6
|
unattendedEnv
|
|
7
7
|
} from "../chunk-OYHYCK4K.js";
|
|
8
8
|
import {
|
|
9
9
|
commitAttributionFromEnvironment,
|
|
10
10
|
toCommitMove
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-VOC4KOOP.js";
|
|
12
12
|
import {
|
|
13
13
|
getOrCreateWorkspaceId
|
|
14
14
|
} from "../chunk-EZXEWFDG.js";
|
|
15
15
|
import {
|
|
16
16
|
appendMove,
|
|
17
17
|
resolveOrg
|
|
18
|
-
} from "../chunk-
|
|
19
|
-
import "../chunk-
|
|
18
|
+
} from "../chunk-LTTF4MBE.js";
|
|
19
|
+
import "../chunk-NQFRQ56V.js";
|
|
20
20
|
import {
|
|
21
21
|
cachedCollectScopeAdmits
|
|
22
|
-
} from "../chunk-
|
|
23
|
-
import "../chunk-
|
|
22
|
+
} from "../chunk-5BQ2NEMP.js";
|
|
23
|
+
import "../chunk-U67RBNIZ.js";
|
|
24
24
|
import {
|
|
25
25
|
githubRepositoryFullName,
|
|
26
26
|
isRepoActiveForCapture,
|
|
27
27
|
repoSyncId,
|
|
28
28
|
resolveRepositoryContext
|
|
29
|
-
} from "../chunk-
|
|
29
|
+
} from "../chunk-P2O7NLVN.js";
|
|
30
30
|
import "../chunk-JSBRDJBE.js";
|
|
31
31
|
|
|
32
32
|
// src/hooks/post-commit.ts
|
|
@@ -5,25 +5,25 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
canonicalRewritePairs,
|
|
7
7
|
toRewriteMove
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-VOC4KOOP.js";
|
|
9
9
|
import {
|
|
10
10
|
getOrCreateWorkspaceId
|
|
11
11
|
} from "../chunk-EZXEWFDG.js";
|
|
12
12
|
import {
|
|
13
13
|
appendMove,
|
|
14
14
|
resolveOrg
|
|
15
|
-
} from "../chunk-
|
|
16
|
-
import "../chunk-
|
|
15
|
+
} from "../chunk-LTTF4MBE.js";
|
|
16
|
+
import "../chunk-NQFRQ56V.js";
|
|
17
17
|
import {
|
|
18
18
|
cachedCollectScopeAdmits
|
|
19
|
-
} from "../chunk-
|
|
20
|
-
import "../chunk-
|
|
19
|
+
} from "../chunk-5BQ2NEMP.js";
|
|
20
|
+
import "../chunk-U67RBNIZ.js";
|
|
21
21
|
import {
|
|
22
22
|
githubRepositoryFullName,
|
|
23
23
|
isRepoActiveForCapture,
|
|
24
24
|
repoSyncId,
|
|
25
25
|
resolveRepositoryContext
|
|
26
|
-
} from "../chunk-
|
|
26
|
+
} from "../chunk-P2O7NLVN.js";
|
|
27
27
|
import "../chunk-JSBRDJBE.js";
|
|
28
28
|
|
|
29
29
|
// src/hooks/post-rewrite.ts
|
|
@@ -1,60 +1,61 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
requireDurableIngestAcknowledgement
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-A6M2M5A2.js";
|
|
5
5
|
import {
|
|
6
6
|
enrichHookPayloadWithFileRefs,
|
|
7
7
|
preserveHookFileMetadata
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-XWAKFL3T.js";
|
|
9
9
|
import {
|
|
10
10
|
appendCodexContext,
|
|
11
11
|
prepareCodexContext
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-
|
|
12
|
+
} from "../chunk-HXICZG5J.js";
|
|
13
|
+
import "../chunk-GYQOZGGF.js";
|
|
14
14
|
import {
|
|
15
15
|
postToolInvocationId,
|
|
16
16
|
toMove,
|
|
17
17
|
toolOutcomeFor
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-VOC4KOOP.js";
|
|
19
19
|
import {
|
|
20
20
|
getOrCreateWorkspaceId
|
|
21
21
|
} from "../chunk-EZXEWFDG.js";
|
|
22
22
|
import {
|
|
23
23
|
appendMove,
|
|
24
24
|
resolveOrg
|
|
25
|
-
} from "../chunk-
|
|
26
|
-
import "../chunk-
|
|
25
|
+
} from "../chunk-LTTF4MBE.js";
|
|
26
|
+
import "../chunk-SLDZJD6Q.js";
|
|
27
27
|
import {
|
|
28
28
|
observeDemoInvocation
|
|
29
|
-
} from "../chunk-
|
|
29
|
+
} from "../chunk-CSE44DPA.js";
|
|
30
30
|
import {
|
|
31
31
|
normalizeEnvelope,
|
|
32
32
|
readHookStdin,
|
|
33
33
|
shouldSuppressImportedCursorHandler
|
|
34
|
-
} from "../chunk-
|
|
35
|
-
import "../chunk-
|
|
36
|
-
import "../chunk-
|
|
34
|
+
} from "../chunk-TC4FTRYO.js";
|
|
35
|
+
import "../chunk-4L7TAM5S.js";
|
|
36
|
+
import "../chunk-MWNRXAEB.js";
|
|
37
37
|
import {
|
|
38
38
|
scrubFromCwd
|
|
39
|
-
} from "../chunk-
|
|
39
|
+
} from "../chunk-NQFRQ56V.js";
|
|
40
40
|
import {
|
|
41
41
|
bold,
|
|
42
42
|
cachedCollectScopeAdmits,
|
|
43
43
|
color
|
|
44
|
-
} from "../chunk-
|
|
44
|
+
} from "../chunk-5BQ2NEMP.js";
|
|
45
45
|
import {
|
|
46
46
|
getClient,
|
|
47
47
|
terminalSafeLine
|
|
48
|
-
} from "../chunk-
|
|
48
|
+
} from "../chunk-U67RBNIZ.js";
|
|
49
49
|
import {
|
|
50
50
|
currentBranch,
|
|
51
51
|
isRepoActiveForCapture,
|
|
52
52
|
repoSyncId,
|
|
53
53
|
resolveRepositoryContext
|
|
54
|
-
} from "../chunk-
|
|
54
|
+
} from "../chunk-P2O7NLVN.js";
|
|
55
55
|
import {
|
|
56
56
|
parseAgent
|
|
57
57
|
} from "../chunk-KZB4ABIB.js";
|
|
58
|
+
import "../chunk-W27EFR7W.js";
|
|
58
59
|
import "../chunk-JSBRDJBE.js";
|
|
59
60
|
|
|
60
61
|
// src/hooks/post-tool-use.ts
|
package/dist/hooks/pre-commit.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
checkAffectedDecisions,
|
|
4
4
|
formatDecisionsWarning
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-D235RJNO.js";
|
|
6
|
+
import "../chunk-SLDZJD6Q.js";
|
|
7
|
+
import "../chunk-U67RBNIZ.js";
|
|
8
|
+
import "../chunk-P2O7NLVN.js";
|
|
9
9
|
import "../chunk-JSBRDJBE.js";
|
|
10
10
|
|
|
11
11
|
// src/hooks/pre-commit.ts
|
|
@@ -1,24 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
PREFLIGHT_PROTOCOL_VERSION,
|
|
4
|
+
PreflightPausedError,
|
|
4
5
|
boundedClientVersion,
|
|
5
6
|
editPreview,
|
|
7
|
+
hasCompleteCoverage,
|
|
6
8
|
hasConfirmedConflict,
|
|
9
|
+
pausedResult,
|
|
7
10
|
proposalFor,
|
|
8
11
|
proposalIsTruncated,
|
|
9
12
|
resolvePreflightTargets,
|
|
10
13
|
resultForPreflight,
|
|
11
14
|
toolInputDigest,
|
|
12
15
|
waitForPreflight
|
|
13
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-2JA524SC.js";
|
|
14
17
|
import {
|
|
15
18
|
observeDemoInvocation
|
|
16
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-CSE44DPA.js";
|
|
17
20
|
import {
|
|
18
21
|
normalizeEnvelope,
|
|
19
22
|
readHookStdin,
|
|
20
23
|
shouldSuppressImportedCursorHandler
|
|
21
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-TC4FTRYO.js";
|
|
25
|
+
import "../chunk-4L7TAM5S.js";
|
|
26
|
+
import "../chunk-MWNRXAEB.js";
|
|
27
|
+
import "../chunk-NQFRQ56V.js";
|
|
28
|
+
import {
|
|
29
|
+
cachedCollectScopeAdmits
|
|
30
|
+
} from "../chunk-5BQ2NEMP.js";
|
|
31
|
+
import "../chunk-U67RBNIZ.js";
|
|
32
|
+
import {
|
|
33
|
+
canonicalGitRoot,
|
|
34
|
+
currentBranch,
|
|
35
|
+
githubRepositoryFullName,
|
|
36
|
+
packageVersion,
|
|
37
|
+
repoActiveFlag,
|
|
38
|
+
repoSyncId
|
|
39
|
+
} from "../chunk-P2O7NLVN.js";
|
|
40
|
+
import {
|
|
41
|
+
parseAgent
|
|
42
|
+
} from "../chunk-KZB4ABIB.js";
|
|
22
43
|
import {
|
|
23
44
|
buildCodexOutput,
|
|
24
45
|
buildCursorOutput,
|
|
@@ -30,26 +51,12 @@ import {
|
|
|
30
51
|
failOpenHermes,
|
|
31
52
|
failOpenOutput,
|
|
32
53
|
readHookMode
|
|
33
|
-
} from "../chunk-
|
|
34
|
-
import "../chunk-VEI7KUOU.js";
|
|
35
|
-
import "../chunk-LEEWUN74.js";
|
|
36
|
-
import {
|
|
37
|
-
cachedCollectScopeAdmits
|
|
38
|
-
} from "../chunk-JGOFEG6T.js";
|
|
39
|
-
import "../chunk-UMSJ4DU2.js";
|
|
40
|
-
import {
|
|
41
|
-
currentBranch,
|
|
42
|
-
githubRepositoryFullName,
|
|
43
|
-
isRepoActive,
|
|
44
|
-
packageVersion,
|
|
45
|
-
repoSyncId
|
|
46
|
-
} from "../chunk-3NJ4FUPK.js";
|
|
47
|
-
import {
|
|
48
|
-
parseAgent
|
|
49
|
-
} from "../chunk-KZB4ABIB.js";
|
|
54
|
+
} from "../chunk-W27EFR7W.js";
|
|
50
55
|
import "../chunk-JSBRDJBE.js";
|
|
51
56
|
|
|
52
57
|
// src/hooks/pre-tool-use-worker.ts
|
|
58
|
+
import { realpathSync } from "fs";
|
|
59
|
+
import { relative } from "path";
|
|
53
60
|
var STDIN_TIMEOUT_MS = 1e3;
|
|
54
61
|
var deadline = performance.now() + Math.max(0, Number(process.argv.at(-1)) - Date.now());
|
|
55
62
|
var agent = parseAgent(process.argv);
|
|
@@ -87,10 +94,18 @@ function hermesAdvisory(result, aggregate) {
|
|
|
87
94
|
const message = [...new Set(parts.filter(Boolean))].join("\n");
|
|
88
95
|
return message.startsWith("[primitive]") ? message : message ? `[primitive] ${message}` : "";
|
|
89
96
|
}
|
|
97
|
+
var protectedShell = false;
|
|
98
|
+
async function pause(message, checkId) {
|
|
99
|
+
const result = pausedResult(message, checkId);
|
|
100
|
+
await emit(
|
|
101
|
+
agent === "codex" ? buildCodexOutput("deny", [result]) : buildHookOutput("deny", [result]),
|
|
102
|
+
true
|
|
103
|
+
);
|
|
104
|
+
}
|
|
90
105
|
async function main() {
|
|
91
106
|
const mode = readHookMode(process.env);
|
|
92
107
|
if (mode === "off") {
|
|
93
|
-
await emit(failOpen());
|
|
108
|
+
await emit(failOpen(), true);
|
|
94
109
|
return;
|
|
95
110
|
}
|
|
96
111
|
let raw;
|
|
@@ -108,7 +123,7 @@ async function main() {
|
|
|
108
123
|
}
|
|
109
124
|
const fields = incoming;
|
|
110
125
|
if (agent !== "cursor" && shouldSuppressImportedCursorHandler(fields, "prim-pre-tool-use")) {
|
|
111
|
-
await emit(failOpenCursor());
|
|
126
|
+
await emit(failOpenCursor(), true);
|
|
112
127
|
return;
|
|
113
128
|
}
|
|
114
129
|
envelope = normalizeEnvelope(fields, agent);
|
|
@@ -121,13 +136,13 @@ async function main() {
|
|
|
121
136
|
}
|
|
122
137
|
try {
|
|
123
138
|
if (observeDemoInvocation(envelope, agent, false).invocation) {
|
|
124
|
-
await emit(failOpen());
|
|
139
|
+
await emit(failOpen(), true);
|
|
125
140
|
return;
|
|
126
141
|
}
|
|
127
142
|
} catch {
|
|
128
143
|
}
|
|
129
144
|
if (envelope.hook_event_name !== "PreToolUse") {
|
|
130
|
-
await emit(failOpen());
|
|
145
|
+
await emit(failOpen(), true);
|
|
131
146
|
return;
|
|
132
147
|
}
|
|
133
148
|
if (typeof envelope.tool_name !== "string" || !envelope.tool_name) {
|
|
@@ -135,6 +150,7 @@ async function main() {
|
|
|
135
150
|
return;
|
|
136
151
|
}
|
|
137
152
|
const toolName = envelope.tool_name;
|
|
153
|
+
protectedShell = (agent === "claude_code" || agent === "codex") && toolName === "Bash";
|
|
138
154
|
const cwd = typeof envelope.cwd === "string" && envelope.cwd.length > 0 ? envelope.cwd : process.cwd();
|
|
139
155
|
const targets = resolvePreflightTargets({
|
|
140
156
|
toolName,
|
|
@@ -143,14 +159,14 @@ async function main() {
|
|
|
143
159
|
cwd
|
|
144
160
|
});
|
|
145
161
|
if (targets.mutation === "none") {
|
|
146
|
-
await emit(failOpen());
|
|
162
|
+
await emit(failOpen(), true);
|
|
147
163
|
return;
|
|
148
164
|
}
|
|
149
|
-
if (
|
|
150
|
-
await emit(failOpen());
|
|
165
|
+
if (repoActiveFlag(cwd, protectedShell) !== "true") {
|
|
166
|
+
await emit(failOpen(), true);
|
|
151
167
|
return;
|
|
152
168
|
}
|
|
153
|
-
if (targets.paths.length === 0 && !targets.definite) {
|
|
169
|
+
if (!protectedShell && targets.paths.length === 0 && !targets.definite) {
|
|
154
170
|
await emit(failOpen());
|
|
155
171
|
return;
|
|
156
172
|
}
|
|
@@ -163,6 +179,10 @@ async function main() {
|
|
|
163
179
|
const sessionId = envelope.session_id;
|
|
164
180
|
const callId = invocationId(envelope);
|
|
165
181
|
if (!binding || typeof sessionId !== "string" || !sessionId || !callId) {
|
|
182
|
+
if (protectedShell) {
|
|
183
|
+
await pause("Repository or invocation identity is unavailable");
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
166
186
|
await emit(failOpen());
|
|
167
187
|
return;
|
|
168
188
|
}
|
|
@@ -173,6 +193,13 @@ async function main() {
|
|
|
173
193
|
paths: targets.paths,
|
|
174
194
|
pathsComplete: targets.coverage === "complete"
|
|
175
195
|
});
|
|
196
|
+
const root = protectedShell ? canonicalGitRoot(cwd) : null;
|
|
197
|
+
const proposalInput = protectedShell ? {
|
|
198
|
+
...typeof envelope.tool_input === "string" ? { command: envelope.tool_input } : envelope.tool_input,
|
|
199
|
+
repositoryCwd: root ? relative(root, realpathSync(cwd)).replaceAll("\\", "/") || "." : null,
|
|
200
|
+
knownWritePaths: targets.paths,
|
|
201
|
+
targetCoverage: targets.coverage
|
|
202
|
+
} : envelope.tool_input;
|
|
176
203
|
const request = {
|
|
177
204
|
protocolVersion: PREFLIGHT_PROTOCOL_VERSION,
|
|
178
205
|
operation: "start",
|
|
@@ -185,27 +212,41 @@ async function main() {
|
|
|
185
212
|
repoSyncId: binding,
|
|
186
213
|
paths: targets.paths,
|
|
187
214
|
coverage: targets.coverage,
|
|
215
|
+
...protectedShell ? {
|
|
216
|
+
shellCheck: {
|
|
217
|
+
targetMode: targets.coverage === "complete" ? "files" : "repository"
|
|
218
|
+
}
|
|
219
|
+
} : {},
|
|
188
220
|
...branch === void 0 ? {} : { branch },
|
|
189
|
-
proposal: collectScopeAdmits ? proposalFor(
|
|
221
|
+
proposal: collectScopeAdmits ? proposalFor(proposalInput) : ""
|
|
190
222
|
};
|
|
191
223
|
let result;
|
|
192
224
|
try {
|
|
193
225
|
const response = await waitForPreflight(request, {
|
|
194
226
|
deadline,
|
|
195
|
-
stopOnConflict:
|
|
227
|
+
stopOnConflict: !protectedShell
|
|
196
228
|
});
|
|
229
|
+
if (protectedShell && (!hasCompleteCoverage(response) || !hasConfirmedConflict(response) && response.verdict !== "allow" || response.evaluationCoverage.candidateCount > 0 && proposalIsTruncated(proposalInput))) {
|
|
230
|
+
await pause(response.message || "Shell evaluation is incomplete", response.checkId);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
197
233
|
if (!hasConfirmedConflict(response)) {
|
|
198
|
-
await emit(failOpen());
|
|
234
|
+
await emit(failOpen(), true);
|
|
199
235
|
return;
|
|
200
236
|
}
|
|
201
237
|
result = resultForPreflight(
|
|
202
238
|
response,
|
|
203
239
|
editPreview(toolName, envelope.tool_input, targets.paths),
|
|
204
240
|
request,
|
|
205
|
-
collectScopeAdmits && (toolName === "Bash" || toolName === "Shell") && proposalIsTruncated(
|
|
241
|
+
collectScopeAdmits && (toolName === "Bash" || toolName === "Shell") && proposalIsTruncated(proposalInput)
|
|
206
242
|
);
|
|
207
|
-
} catch {
|
|
208
|
-
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (protectedShell)
|
|
245
|
+
await pause(
|
|
246
|
+
"Shell evaluation is unavailable or exceeded the two-second deadline",
|
|
247
|
+
error instanceof PreflightPausedError ? error.checkId : void 0
|
|
248
|
+
);
|
|
249
|
+
else await emit(failOpen());
|
|
209
250
|
return;
|
|
210
251
|
}
|
|
211
252
|
const aggregate = demoteForMode(result.verdict === "unavailable" ? "deny" : result.verdict, mode);
|
|
@@ -218,5 +259,6 @@ async function main() {
|
|
|
218
259
|
await emit(output, true);
|
|
219
260
|
}
|
|
220
261
|
main().catch(async () => {
|
|
221
|
-
await
|
|
262
|
+
if (protectedShell) await pause("Shell evaluation is unavailable");
|
|
263
|
+
else await emit(failOpen());
|
|
222
264
|
});
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
parseAgent
|
|
4
4
|
} from "../chunk-KZB4ABIB.js";
|
|
5
|
+
import {
|
|
6
|
+
readHookMode
|
|
7
|
+
} from "../chunk-W27EFR7W.js";
|
|
5
8
|
import "../chunk-JSBRDJBE.js";
|
|
6
9
|
|
|
7
10
|
// src/hooks/pre-tool-use.ts
|
|
@@ -19,6 +22,28 @@ var child;
|
|
|
19
22
|
var finished = false;
|
|
20
23
|
var stdout = "";
|
|
21
24
|
var stderr = "";
|
|
25
|
+
var input = "";
|
|
26
|
+
var pauseReason = "[primitive] Operation paused: shell evaluation did not finish within two seconds. Retry the tool call to validate the current invocation.";
|
|
27
|
+
function fallback() {
|
|
28
|
+
if (readHookMode(process.env) === "off" || agent !== "claude_code" && agent !== "codex")
|
|
29
|
+
return silent;
|
|
30
|
+
try {
|
|
31
|
+
const envelope = JSON.parse(input);
|
|
32
|
+
if (envelope?.hook_event_name !== "PreToolUse" || envelope?.tool_name !== "Bash") return silent;
|
|
33
|
+
} catch {
|
|
34
|
+
return silent;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
hookSpecificOutput: {
|
|
38
|
+
hookEventName: "PreToolUse",
|
|
39
|
+
permissionDecision: "deny",
|
|
40
|
+
permissionDecisionReason: pauseReason
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
process.stdin.setEncoding("utf8").on("data", (chunk) => {
|
|
45
|
+
input += chunk;
|
|
46
|
+
});
|
|
22
47
|
function stopWorker() {
|
|
23
48
|
if (!child?.pid) return;
|
|
24
49
|
try {
|
|
@@ -27,7 +52,7 @@ function stopWorker() {
|
|
|
27
52
|
} catch {
|
|
28
53
|
}
|
|
29
54
|
}
|
|
30
|
-
function finish(output =
|
|
55
|
+
function finish(output = fallback(), diagnostics = "") {
|
|
31
56
|
if (finished) return;
|
|
32
57
|
finished = true;
|
|
33
58
|
clearTimeout(timer);
|
package/dist/hooks/prim-hook.js
CHANGED
|
@@ -8,61 +8,62 @@ import {
|
|
|
8
8
|
acknowledgeDecisionFeedback,
|
|
9
9
|
leaseDecisionFeedback,
|
|
10
10
|
renderFeedback
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-2AKDX4RU.js";
|
|
12
12
|
import {
|
|
13
13
|
recordConversationCaptured
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-LBCPRHNG.js";
|
|
15
15
|
import {
|
|
16
16
|
unattendedEnv
|
|
17
17
|
} from "../chunk-OYHYCK4K.js";
|
|
18
18
|
import {
|
|
19
19
|
enrichHookPayloadWithFileRefs,
|
|
20
20
|
preserveHookFileMetadata
|
|
21
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-XWAKFL3T.js";
|
|
22
22
|
import {
|
|
23
23
|
prepareCodexContext
|
|
24
|
-
} from "../chunk-
|
|
25
|
-
import "../chunk-
|
|
24
|
+
} from "../chunk-HXICZG5J.js";
|
|
25
|
+
import "../chunk-GYQOZGGF.js";
|
|
26
26
|
import {
|
|
27
27
|
postToolInvocationId,
|
|
28
28
|
shouldFlushAfter,
|
|
29
29
|
toMove
|
|
30
|
-
} from "../chunk-
|
|
30
|
+
} from "../chunk-VOC4KOOP.js";
|
|
31
31
|
import {
|
|
32
32
|
getOrCreateWorkspaceId
|
|
33
33
|
} from "../chunk-EZXEWFDG.js";
|
|
34
34
|
import {
|
|
35
35
|
appendMove,
|
|
36
36
|
resolveOrg
|
|
37
|
-
} from "../chunk-
|
|
38
|
-
import "../chunk-
|
|
37
|
+
} from "../chunk-LTTF4MBE.js";
|
|
38
|
+
import "../chunk-SLDZJD6Q.js";
|
|
39
39
|
import {
|
|
40
40
|
observeDemoInvocation
|
|
41
|
-
} from "../chunk-
|
|
41
|
+
} from "../chunk-CSE44DPA.js";
|
|
42
42
|
import {
|
|
43
43
|
normalizeEnvelope,
|
|
44
44
|
readHookStdin,
|
|
45
45
|
shouldSuppressImportedCursorHandler
|
|
46
|
-
} from "../chunk-
|
|
47
|
-
import "../chunk-
|
|
48
|
-
import "../chunk-
|
|
46
|
+
} from "../chunk-TC4FTRYO.js";
|
|
47
|
+
import "../chunk-4L7TAM5S.js";
|
|
48
|
+
import "../chunk-MWNRXAEB.js";
|
|
49
49
|
import {
|
|
50
50
|
scrubFromCwd,
|
|
51
51
|
writeHookDebug
|
|
52
|
-
} from "../chunk-
|
|
52
|
+
} from "../chunk-NQFRQ56V.js";
|
|
53
53
|
import {
|
|
54
54
|
cachedCollectScopeAdmits
|
|
55
|
-
} from "../chunk-
|
|
56
|
-
import "../chunk-
|
|
55
|
+
} from "../chunk-5BQ2NEMP.js";
|
|
56
|
+
import "../chunk-U67RBNIZ.js";
|
|
57
57
|
import {
|
|
58
58
|
currentBranch,
|
|
59
59
|
isRepoActiveForCapture,
|
|
60
60
|
repoSyncId,
|
|
61
61
|
resolveRepositoryContext
|
|
62
|
-
} from "../chunk-
|
|
62
|
+
} from "../chunk-P2O7NLVN.js";
|
|
63
63
|
import {
|
|
64
64
|
parseAgent
|
|
65
65
|
} from "../chunk-KZB4ABIB.js";
|
|
66
|
+
import "../chunk-W27EFR7W.js";
|
|
66
67
|
import "../chunk-JSBRDJBE.js";
|
|
67
68
|
|
|
68
69
|
// src/hooks/prim-hook.ts
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
daemonRequest
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-SLDZJD6Q.js";
|
|
5
5
|
import {
|
|
6
6
|
normalizeEnvelope,
|
|
7
7
|
readHookStdin,
|
|
8
8
|
shouldSuppressImportedCursorHandler
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-TC4FTRYO.js";
|
|
10
|
+
import "../chunk-MWNRXAEB.js";
|
|
11
11
|
import {
|
|
12
12
|
isRepoActiveForCapture
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-P2O7NLVN.js";
|
|
14
14
|
import {
|
|
15
15
|
parseAgent
|
|
16
16
|
} from "../chunk-KZB4ABIB.js";
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
kickDaemonEnsure,
|
|
8
8
|
refreshClaudePlugins,
|
|
9
9
|
warmBinCache
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-CCGFRNAA.js";
|
|
11
11
|
import {
|
|
12
12
|
buildHookOutput,
|
|
13
13
|
handoffHookOutput
|
|
@@ -17,43 +17,43 @@ import {
|
|
|
17
17
|
acknowledgeDecisionFeedback,
|
|
18
18
|
leaseDecisionFeedback,
|
|
19
19
|
renderFeedback
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-2AKDX4RU.js";
|
|
21
21
|
import {
|
|
22
22
|
clearHooksWired,
|
|
23
23
|
recordHooksWired
|
|
24
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-LBCPRHNG.js";
|
|
25
25
|
import "../chunk-OYHYCK4K.js";
|
|
26
26
|
import {
|
|
27
27
|
prepareCodexContext
|
|
28
|
-
} from "../chunk-
|
|
29
|
-
import "../chunk-
|
|
28
|
+
} from "../chunk-HXICZG5J.js";
|
|
29
|
+
import "../chunk-GYQOZGGF.js";
|
|
30
30
|
import {
|
|
31
31
|
getOrCreateWorkspaceId
|
|
32
32
|
} from "../chunk-EZXEWFDG.js";
|
|
33
33
|
import {
|
|
34
34
|
daemonRequest
|
|
35
|
-
} from "../chunk-
|
|
35
|
+
} from "../chunk-SLDZJD6Q.js";
|
|
36
36
|
import {
|
|
37
37
|
normalizeEnvelope,
|
|
38
38
|
readHookStdin,
|
|
39
39
|
shouldSuppressImportedCursorHandler
|
|
40
|
-
} from "../chunk-
|
|
40
|
+
} from "../chunk-TC4FTRYO.js";
|
|
41
41
|
import {
|
|
42
42
|
MANAGED_GIT_HOOK_NAMES
|
|
43
|
-
} from "../chunk-
|
|
43
|
+
} from "../chunk-MWNRXAEB.js";
|
|
44
44
|
import {
|
|
45
45
|
fetchAndCacheCollectScope
|
|
46
|
-
} from "../chunk-
|
|
46
|
+
} from "../chunk-5BQ2NEMP.js";
|
|
47
47
|
import {
|
|
48
48
|
getSiteUrl,
|
|
49
49
|
isSessionEnded
|
|
50
|
-
} from "../chunk-
|
|
50
|
+
} from "../chunk-U67RBNIZ.js";
|
|
51
51
|
import {
|
|
52
52
|
gitToplevel,
|
|
53
53
|
isRepoActiveForCapture,
|
|
54
54
|
repoActiveFlag,
|
|
55
55
|
setRepoActive
|
|
56
|
-
} from "../chunk-
|
|
56
|
+
} from "../chunk-P2O7NLVN.js";
|
|
57
57
|
import {
|
|
58
58
|
parseAgent
|
|
59
59
|
} from "../chunk-KZB4ABIB.js";
|