@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.
Files changed (45) hide show
  1. package/dist/{chunk-FPDOBG3H.js → chunk-2AKDX4RU.js} +1 -1
  2. package/dist/{chunk-CHRICRVE.js → chunk-2JA524SC.js} +21 -14
  3. package/dist/{chunk-L3NUFCOD.js → chunk-4L7TAM5S.js} +120 -285
  4. package/dist/{chunk-JGOFEG6T.js → chunk-5BQ2NEMP.js} +2732 -2533
  5. package/dist/{chunk-B3FVP7VQ.js → chunk-A6M2M5A2.js} +1 -1
  6. package/dist/{chunk-OHLVHT6R.js → chunk-CCGFRNAA.js} +3 -3
  7. package/dist/{chunk-SCOEPFOV.js → chunk-CSE44DPA.js} +2 -2
  8. package/dist/{chunk-Q4CWXKNV.js → chunk-D235RJNO.js} +3 -3
  9. package/dist/{chunk-QX7QFMLF.js → chunk-GYQOZGGF.js} +2 -2
  10. package/dist/{chunk-PYIIYC3A.js → chunk-HXICZG5J.js} +4 -4
  11. package/dist/{chunk-JXQVXU2K.js → chunk-LBCPRHNG.js} +1 -1
  12. package/dist/{chunk-ECP7EGOD.js → chunk-LTTF4MBE.js} +2 -2
  13. package/dist/{chunk-VEI7KUOU.js → chunk-MWNRXAEB.js} +1 -1
  14. package/dist/{chunk-LEEWUN74.js → chunk-NQFRQ56V.js} +2 -2
  15. package/dist/{chunk-3NJ4FUPK.js → chunk-P2O7NLVN.js} +5 -6
  16. package/dist/{chunk-4HEWA4IO.js → chunk-SLDZJD6Q.js} +1 -1
  17. package/dist/{chunk-C2AEY4AI.js → chunk-TC4FTRYO.js} +2 -2
  18. package/dist/{chunk-UMSJ4DU2.js → chunk-U67RBNIZ.js} +1 -1
  19. package/dist/{chunk-C2AJBMP2.js → chunk-VOC4KOOP.js} +2 -2
  20. package/dist/chunk-W27EFR7W.js +271 -0
  21. package/dist/{chunk-OIXHRN32.js → chunk-XWAKFL3T.js} +9 -7
  22. package/dist/daemon/server.js +2733 -2531
  23. package/dist/hook-runtime/daemon/server.js +2733 -2531
  24. package/dist/hook-runtime/hooks/post-commit.js +2740 -2538
  25. package/dist/hook-runtime/hooks/post-rewrite.js +2740 -2538
  26. package/dist/hook-runtime/hooks/post-tool-use.js +2854 -2550
  27. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +2907 -2564
  28. package/dist/hook-runtime/hooks/pre-tool-use.js +36 -1
  29. package/dist/hook-runtime/hooks/prim-hook.js +2853 -2549
  30. package/dist/hook-runtime/hooks/session-end.js +5 -2
  31. package/dist/hook-runtime/hooks/session-start.js +2740 -2538
  32. package/dist/hook-runtime/index.js +2793 -2581
  33. package/dist/hook-runtime/statusline-main.js +5 -2
  34. package/dist/hooks/post-commit.js +7 -7
  35. package/dist/hooks/post-rewrite.js +6 -6
  36. package/dist/hooks/post-tool-use.js +16 -15
  37. package/dist/hooks/pre-commit.js +4 -4
  38. package/dist/hooks/pre-tool-use-worker.js +77 -35
  39. package/dist/hooks/pre-tool-use.js +26 -1
  40. package/dist/hooks/prim-hook.js +17 -16
  41. package/dist/hooks/session-end.js +4 -4
  42. package/dist/hooks/session-start.js +11 -11
  43. package/dist/index.js +20 -16
  44. package/dist/statusline-main.js +5 -2
  45. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  scheduleCollectScopeRefresh
3
- } from "./chunk-JGOFEG6T.js";
3
+ } from "./chunk-5BQ2NEMP.js";
4
4
 
5
5
  // src/ingest-response.ts
6
6
  var IngestAcknowledgementError = class extends Error {
@@ -9,11 +9,11 @@ import {
9
9
  hookBlockContractVersion,
10
10
  inspectGitHookEntrypoint,
11
11
  managedHookBlock
12
- } from "./chunk-VEI7KUOU.js";
12
+ } from "./chunk-MWNRXAEB.js";
13
13
  import {
14
14
  HttpError,
15
15
  getClient
16
- } from "./chunk-UMSJ4DU2.js";
16
+ } from "./chunk-U67RBNIZ.js";
17
17
  import {
18
18
  atomicWriteFile,
19
19
  binFile,
@@ -27,7 +27,7 @@ import {
27
27
  setRepoSyncId,
28
28
  setRepositoryBindingState,
29
29
  withFileLock
30
- } from "./chunk-3NJ4FUPK.js";
30
+ } from "./chunk-P2O7NLVN.js";
31
31
 
32
32
  // src/commands/skill.ts
33
33
  import { createHash as createHash2 } from "crypto";
@@ -11,10 +11,10 @@ import {
11
11
  saveRun,
12
12
  sessionExcluded,
13
13
  sessionKey
14
- } from "./chunk-L3NUFCOD.js";
14
+ } from "./chunk-4L7TAM5S.js";
15
15
  import {
16
16
  packageVersion
17
- } from "./chunk-3NJ4FUPK.js";
17
+ } from "./chunk-P2O7NLVN.js";
18
18
 
19
19
  // src/demo/isolation.ts
20
20
  import { existsSync } from "fs";
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  daemonRequest
3
- } from "./chunk-4HEWA4IO.js";
3
+ } from "./chunk-SLDZJD6Q.js";
4
4
  import {
5
5
  getClient,
6
6
  getSiteUrl,
7
7
  terminalSafeLine
8
- } from "./chunk-UMSJ4DU2.js";
8
+ } from "./chunk-U67RBNIZ.js";
9
9
  import {
10
10
  canonicalGitRoot,
11
11
  canonicalRepositoryPath,
12
12
  currentBranch,
13
13
  repoSyncId
14
- } from "./chunk-3NJ4FUPK.js";
14
+ } from "./chunk-P2O7NLVN.js";
15
15
 
16
16
  // src/daemon/proxy.ts
17
17
  var DAEMON_HTTP_TIMEOUT_MS = 1e4;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-JGOFEG6T.js";
3
+ } from "./chunk-5BQ2NEMP.js";
4
4
  import {
5
5
  stripControlChars
6
- } from "./chunk-UMSJ4DU2.js";
6
+ } from "./chunk-U67RBNIZ.js";
7
7
 
8
8
  // src/lib/delivery-backlog.ts
9
9
  var MS_PER_SECOND = 1e3;
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  formatStatusline
3
- } from "./chunk-QX7QFMLF.js";
3
+ } from "./chunk-GYQOZGGF.js";
4
4
  import {
5
5
  daemonPrincipalsMatch,
6
6
  daemonRequest,
7
7
  resolveDaemonPrincipal
8
- } from "./chunk-4HEWA4IO.js";
8
+ } from "./chunk-SLDZJD6Q.js";
9
9
  import {
10
10
  getSiteUrl,
11
11
  isSessionEnded,
12
12
  terminalSafeText
13
- } from "./chunk-UMSJ4DU2.js";
13
+ } from "./chunk-U67RBNIZ.js";
14
14
  import {
15
15
  decisionIngestionStatus,
16
16
  gitToplevel,
@@ -18,7 +18,7 @@ import {
18
18
  primConfigDirectory,
19
19
  repositoryBindingState,
20
20
  withFileLock
21
- } from "./chunk-3NJ4FUPK.js";
21
+ } from "./chunk-P2O7NLVN.js";
22
22
 
23
23
  // src/hooks/codex-context.ts
24
24
  import { createHash, randomBytes as randomBytes2 } from "crypto";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  atomicWriteFile,
3
3
  repoActiveFlag
4
- } from "./chunk-3NJ4FUPK.js";
4
+ } from "./chunk-P2O7NLVN.js";
5
5
 
6
6
  // src/lib/commit-heartbeat.ts
7
7
  import { execFileSync } from "child_process";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  getSiteUrl
3
- } from "./chunk-UMSJ4DU2.js";
3
+ } from "./chunk-U67RBNIZ.js";
4
4
  import {
5
5
  atomicWriteFile,
6
6
  ensureDurableDirectory,
7
7
  jwtOrganizationId,
8
8
  primConfigDirectory,
9
9
  resolveAuthCredential
10
- } from "./chunk-3NJ4FUPK.js";
10
+ } from "./chunk-P2O7NLVN.js";
11
11
 
12
12
  // src/journal.ts
13
13
  import {
@@ -16,7 +16,7 @@ import {
16
16
  syncDirectory,
17
17
  syncFile,
18
18
  withFileLockSync
19
- } from "./chunk-3NJ4FUPK.js";
19
+ } from "./chunk-P2O7NLVN.js";
20
20
 
21
21
  // src/commands/claude-install.ts
22
22
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-JGOFEG6T.js";
3
+ } from "./chunk-5BQ2NEMP.js";
4
4
  import {
5
5
  terminalSafeLine
6
- } from "./chunk-UMSJ4DU2.js";
6
+ } from "./chunk-U67RBNIZ.js";
7
7
 
8
8
  // src/hooks/redact.ts
9
9
  import { existsSync, readFileSync, statSync } from "fs";
@@ -242,7 +242,7 @@ var GIT_TIMEOUT_MS2 = 1e3;
242
242
  var REPO_SYNC_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
243
243
  var PROJECT_INSTALL_FILES = [".claude/settings.json", ".codex/hooks.json", ".cursor/hooks.json"];
244
244
  var PRIM_HOOK_BINS = ["prim-hook", "prim-pre-tool-use", "prim-post-tool-use"];
245
- function repoActiveFlag(cwd) {
245
+ function repoActiveFlag(cwd, strict = false) {
246
246
  try {
247
247
  const value = execFileSync2("git", ["config", "--get", PRIM_ACTIVE_KEY], {
248
248
  cwd,
@@ -252,14 +252,14 @@ function repoActiveFlag(cwd) {
252
252
  }).trim();
253
253
  if (value === "true") return "true";
254
254
  if (value === "false") return "false";
255
+ if (strict) throw new Error("Repository activation is invalid");
255
256
  return void 0;
256
- } catch {
257
+ } catch (error) {
258
+ if (strict && !(typeof error === "object" && error !== null && "status" in error && error.status === 1))
259
+ throw error;
257
260
  return void 0;
258
261
  }
259
262
  }
260
- function isRepoActive(cwd) {
261
- return repoActiveFlag(cwd) === "true";
262
- }
263
263
  function setRepoActive(cwd, active) {
264
264
  execFileSync2("git", ["config", "--local", PRIM_ACTIVE_KEY, active ? "true" : "false"], {
265
265
  cwd,
@@ -1306,7 +1306,6 @@ export {
1306
1306
  resolveRepositoryContext,
1307
1307
  canonicalRepositoryPath,
1308
1308
  repoActiveFlag,
1309
- isRepoActive,
1310
1309
  setRepoActive,
1311
1310
  isValidRepoSyncId,
1312
1311
  localGitConfigValue,
@@ -2,7 +2,7 @@ import {
2
2
  decodeJwtPayload,
3
3
  primConfigDirectory,
4
4
  resolveAuthCredential
5
- } from "./chunk-3NJ4FUPK.js";
5
+ } from "./chunk-P2O7NLVN.js";
6
6
 
7
7
  // src/daemon/principal.ts
8
8
  import { createHash } from "crypto";
@@ -2,10 +2,10 @@ import {
2
2
  cursorHooksPath,
3
3
  hasExactCursorHandler,
4
4
  readCursorHooks
5
- } from "./chunk-VEI7KUOU.js";
5
+ } from "./chunk-MWNRXAEB.js";
6
6
  import {
7
7
  resolveRepositoryContext
8
- } from "./chunk-3NJ4FUPK.js";
8
+ } from "./chunk-P2O7NLVN.js";
9
9
 
10
10
  // src/hooks/cursor-coexistence.ts
11
11
  var CURSOR_EVENTS = /* @__PURE__ */ new Set([
@@ -23,7 +23,7 @@ import {
23
23
  syncDirectory,
24
24
  withFileLock,
25
25
  workosConnectTokenEndpoint
26
- } from "./chunk-3NJ4FUPK.js";
26
+ } from "./chunk-P2O7NLVN.js";
27
27
 
28
28
  // src/decisions/identity.ts
29
29
  var PUBLIC_ID = /^dec_[0-9a-f]{8}$/u;
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-EZXEWFDG.js";
4
4
  import {
5
5
  scrubEnvironmentPaths
6
- } from "./chunk-LEEWUN74.js";
6
+ } from "./chunk-NQFRQ56V.js";
7
7
  import {
8
8
  isValidRepoSyncId
9
- } from "./chunk-3NJ4FUPK.js";
9
+ } from "./chunk-P2O7NLVN.js";
10
10
 
11
11
  // src/hooks/prim-hook-core.ts
12
12
  import { createHash, randomUUID } from "crypto";
@@ -0,0 +1,271 @@
1
+ // src/hooks/pre-tool-use-scoring.ts
2
+ import { isAbsolute, relative, sep } from "path";
3
+ function anyUnverified(results) {
4
+ return results.some((r) => r.verdict === "unavailable" || r.truncated);
5
+ }
6
+ function unverifiedNote(results) {
7
+ const causes = [];
8
+ const unavailable = results.find((r) => r.verdict === "unavailable");
9
+ if (unavailable) {
10
+ causes.push(
11
+ unavailable.unavailable ? `decision check skipped \u2014 ${unavailable.unavailable}` : "decision check skipped \u2014 not verified"
12
+ );
13
+ }
14
+ if (results.some((r) => r.truncated)) {
15
+ causes.push("decision check partial \u2014 conflict set truncated (per-file cap hit)");
16
+ }
17
+ return causes.map((c) => `[primitive] ${c}`).join("\n");
18
+ }
19
+ function blockingReason(results) {
20
+ const parts = results.filter((result) => result.verdict === "ask" || result.verdict === "deny").flatMap((result) => [result.reason, result.additionalContext]).filter((value) => value.length > 0);
21
+ return [...new Set(parts)].join("\n\n") || "[primitive] conflict detected (no detail available)";
22
+ }
23
+ function approvalReason(results) {
24
+ const summaries = results.filter((result) => result.verdict === "ask" || result.verdict === "deny").map((result) => result.reason).filter(Boolean);
25
+ return [
26
+ ...new Set(summaries),
27
+ "Approve runs this edit once; it does not change these decisions."
28
+ ].join("\n");
29
+ }
30
+ function agentContext(results) {
31
+ return [...new Set(results.map((result) => result.additionalContext).filter(Boolean))].join(
32
+ "\n\n"
33
+ );
34
+ }
35
+ function advisoryNote(aggregate, results) {
36
+ const details = results.flatMap((result) => [
37
+ ...aggregate === "warn" ? [result.reason] : [],
38
+ result.additionalContext
39
+ ]);
40
+ if (anyUnverified(results)) details.push(unverifiedNote(results));
41
+ return [...new Set(details.filter((value) => value.length > 0))].join("\n\n");
42
+ }
43
+ function buildHookOutput(aggregate, results) {
44
+ if (aggregate === "ask") {
45
+ const context = agentContext(results);
46
+ return {
47
+ hookSpecificOutput: {
48
+ hookEventName: "PreToolUse",
49
+ permissionDecision: "ask",
50
+ permissionDecisionReason: approvalReason(results),
51
+ ...context ? { additionalContext: context } : {}
52
+ }
53
+ };
54
+ }
55
+ if (aggregate === "deny") {
56
+ return {
57
+ hookSpecificOutput: {
58
+ hookEventName: "PreToolUse",
59
+ permissionDecision: aggregate,
60
+ permissionDecisionReason: blockingReason(results)
61
+ }
62
+ };
63
+ }
64
+ const notes = advisoryNote(aggregate, results);
65
+ if (notes.length > 0) {
66
+ return {
67
+ systemMessage: notes,
68
+ hookSpecificOutput: {
69
+ hookEventName: "PreToolUse",
70
+ permissionDecision: "allow",
71
+ additionalContext: notes
72
+ }
73
+ };
74
+ }
75
+ return {
76
+ hookSpecificOutput: {
77
+ hookEventName: "PreToolUse",
78
+ permissionDecision: "allow"
79
+ }
80
+ };
81
+ }
82
+ function buildCodexOutput(aggregate, results) {
83
+ if (aggregate === "deny" || aggregate === "ask") {
84
+ return {
85
+ hookSpecificOutput: {
86
+ hookEventName: "PreToolUse",
87
+ permissionDecision: "deny",
88
+ permissionDecisionReason: blockingReason(results)
89
+ }
90
+ };
91
+ }
92
+ const notes = advisoryNote(aggregate, results);
93
+ return notes ? {
94
+ systemMessage: notes,
95
+ hookSpecificOutput: { hookEventName: "PreToolUse", additionalContext: notes }
96
+ } : {};
97
+ }
98
+ function buildCursorOutput(aggregate, results) {
99
+ if (aggregate === "deny" || aggregate === "ask") {
100
+ const reason = blockingReason(results);
101
+ return { permission: "deny", user_message: reason, agent_message: reason };
102
+ }
103
+ const notes = advisoryNote(aggregate, results);
104
+ return notes ? { permission: "allow", agent_message: notes } : { permission: "allow" };
105
+ }
106
+ function failOpenOutput() {
107
+ return {
108
+ hookSpecificOutput: {
109
+ hookEventName: "PreToolUse",
110
+ permissionDecision: "allow"
111
+ }
112
+ };
113
+ }
114
+ function failOpenCodex() {
115
+ return {};
116
+ }
117
+ function failOpenCursor() {
118
+ return { permission: "allow" };
119
+ }
120
+ function buildHermesOutput(aggregate, results) {
121
+ if (aggregate !== "deny" && aggregate !== "ask") {
122
+ return {};
123
+ }
124
+ const reason = results.filter((r) => r.verdict === "deny" || r.verdict === "ask").map((r) => r.reason).filter((s) => s.length > 0).join("\n\n");
125
+ const directive = results.map((r) => r.additionalContext).filter((s) => s.length > 0 && s !== reason).join("\n");
126
+ const message = [reason, directive].filter((s) => s.length > 0).join("\n\n") || "[primitive] conflict detected (no detail available)";
127
+ return { action: "block", message };
128
+ }
129
+ function failOpenHermes() {
130
+ return {};
131
+ }
132
+ var SUPPORTED_TOOLS = /* @__PURE__ */ new Set(["Edit", "Write", "MultiEdit", "NotebookEdit"]);
133
+ var APPLY_PATCH_FILE_RE = /^\*\*\* (?:Update|Add|Delete) File: (?<path>.+)$/;
134
+ var MOVE_FILE_RE = /^\*\*\* Move File:\s*(?<src>.+?)\s*->\s*(?<dst>.+?)\s*$/;
135
+ var MOVE_TO_RE = /^\*\*\* Move to: (?<dst>.+)$/;
136
+ var LINE_SPLIT_RE = /\r?\n/;
137
+ function parseApplyPatchTargets(command) {
138
+ const paths = /* @__PURE__ */ new Set();
139
+ let activeUpdate = false;
140
+ let complete = true;
141
+ for (const line of command.split(LINE_SPLIT_RE)) {
142
+ const path = APPLY_PATCH_FILE_RE.exec(line)?.groups?.path;
143
+ if (path) {
144
+ paths.add(path);
145
+ activeUpdate = line.startsWith("*** Update File:");
146
+ continue;
147
+ }
148
+ const moveTo = MOVE_TO_RE.exec(line)?.groups?.dst;
149
+ if (moveTo) {
150
+ if (activeUpdate) paths.add(moveTo);
151
+ else complete = false;
152
+ activeUpdate = false;
153
+ continue;
154
+ }
155
+ const move = MOVE_FILE_RE.exec(line)?.groups;
156
+ if (move?.src) {
157
+ paths.add(move.src);
158
+ if (move.dst) {
159
+ paths.add(move.dst);
160
+ }
161
+ activeUpdate = false;
162
+ continue;
163
+ }
164
+ if (line === "*** Begin Patch" || line === "*** End Patch") activeUpdate = false;
165
+ else if (line.startsWith("*** ")) complete = false;
166
+ }
167
+ return { paths: [...paths], complete: complete && paths.size > 0 };
168
+ }
169
+ function extractCodexFileTargets(toolName, toolInput) {
170
+ if (toolName !== "apply_patch") {
171
+ return null;
172
+ }
173
+ const text = codexPatchText(toolInput);
174
+ return text !== null ? parseApplyPatchTargets(text) : { paths: [], complete: false };
175
+ }
176
+ function codexPatchText(toolInput) {
177
+ if (typeof toolInput === "string") return toolInput;
178
+ if (!toolInput || typeof toolInput !== "object") return null;
179
+ const input = toolInput;
180
+ for (const key of ["command", "input", "patch"]) {
181
+ const value = input[key];
182
+ if (typeof value === "string") return value;
183
+ }
184
+ return null;
185
+ }
186
+ var HERMES_EDITING_TOOLS = /* @__PURE__ */ new Set(["write_file", "patch"]);
187
+ function extractHermesFileTargets(toolName, toolInput) {
188
+ if (!HERMES_EDITING_TOOLS.has(toolName)) {
189
+ return null;
190
+ }
191
+ if (!toolInput || typeof toolInput !== "object") {
192
+ return { paths: [], complete: false };
193
+ }
194
+ const input = toolInput;
195
+ if (toolName === "patch" && input.mode === "patch") {
196
+ return typeof input.patch === "string" ? parseApplyPatchTargets(input.patch) : { paths: [], complete: false };
197
+ }
198
+ const paths = typeof input.path === "string" && input.path.length > 0 ? [input.path] : [];
199
+ const mode = input.mode;
200
+ return { paths, complete: paths.length > 0 && (mode === void 0 || mode === "replace") };
201
+ }
202
+ function extractCursorFileTargets(toolName, toolInput) {
203
+ if (toolName !== "Write" && toolName !== "Delete") return null;
204
+ if (!toolInput || typeof toolInput !== "object" || Array.isArray(toolInput)) {
205
+ return { paths: [], complete: false };
206
+ }
207
+ const input = toolInput;
208
+ const candidates = [input.file_path, input.path].filter(
209
+ (value) => typeof value === "string" && value.length > 0
210
+ );
211
+ const paths = [...new Set(candidates)];
212
+ return { paths, complete: paths.length === 1 };
213
+ }
214
+ function extractFileTargets(toolName, toolInput, agent = "claude_code") {
215
+ if (agent === "codex") {
216
+ return extractCodexFileTargets(toolName, toolInput);
217
+ }
218
+ if (agent === "cursor") {
219
+ return extractCursorFileTargets(toolName, toolInput);
220
+ }
221
+ if (agent === "hermes") {
222
+ return extractHermesFileTargets(toolName, toolInput);
223
+ }
224
+ if (!SUPPORTED_TOOLS.has(toolName)) {
225
+ return null;
226
+ }
227
+ if (!toolInput || typeof toolInput !== "object") {
228
+ return { paths: [], complete: false };
229
+ }
230
+ const input = toolInput;
231
+ if (toolName === "NotebookEdit") {
232
+ const paths2 = typeof input.notebook_path === "string" && input.notebook_path.length > 0 ? [input.notebook_path] : [];
233
+ return { paths: paths2, complete: paths2.length > 0 };
234
+ }
235
+ const paths = typeof input.file_path === "string" && input.file_path.length > 0 ? [input.file_path] : [];
236
+ return { paths, complete: paths.length > 0 };
237
+ }
238
+ function readHookMode(env) {
239
+ if (env.PRIM_BYPASS === "1" || env.PRIM_BYPASS === "true") {
240
+ return "off";
241
+ }
242
+ const mode = env.PRIM_HOOK_MODE;
243
+ if (mode === "off" || mode === "warn") {
244
+ return mode;
245
+ }
246
+ return "block";
247
+ }
248
+ function demoteForMode(verdict, mode) {
249
+ if (mode === "off") {
250
+ return "allow";
251
+ }
252
+ if (mode === "warn" && (verdict === "ask" || verdict === "deny")) {
253
+ return "warn";
254
+ }
255
+ return verdict;
256
+ }
257
+
258
+ export {
259
+ buildHookOutput,
260
+ buildCodexOutput,
261
+ buildCursorOutput,
262
+ failOpenOutput,
263
+ failOpenCodex,
264
+ failOpenCursor,
265
+ buildHermesOutput,
266
+ failOpenHermes,
267
+ parseApplyPatchTargets,
268
+ extractFileTargets,
269
+ readHookMode,
270
+ demoteForMode
271
+ };
@@ -2,22 +2,24 @@ import {
2
2
  getOrCreateWorkspaceId
3
3
  } from "./chunk-EZXEWFDG.js";
4
4
  import {
5
- analyzeShellTargets,
6
- extractFileTargets
7
- } from "./chunk-L3NUFCOD.js";
5
+ analyzeShellTargets
6
+ } from "./chunk-4L7TAM5S.js";
8
7
  import {
9
8
  scrubEnvironmentPaths
10
- } from "./chunk-LEEWUN74.js";
9
+ } from "./chunk-NQFRQ56V.js";
11
10
  import {
12
11
  cachedCollectScopeAdmits
13
- } from "./chunk-JGOFEG6T.js";
12
+ } from "./chunk-5BQ2NEMP.js";
14
13
  import {
15
14
  canonicalRepositoryPath,
16
15
  currentBranch,
17
16
  isRepoActiveForCapture,
18
17
  relatedWorktreeTarget,
19
18
  repoSyncId
20
- } from "./chunk-3NJ4FUPK.js";
19
+ } from "./chunk-P2O7NLVN.js";
20
+ import {
21
+ extractFileTargets
22
+ } from "./chunk-W27EFR7W.js";
21
23
 
22
24
  // src/hooks/file-refs.ts
23
25
  var MAX_PREFLIGHT_FILE_TARGETS = 25;
@@ -42,7 +44,7 @@ function preserveHookFileMetadata(payload, resolution) {
42
44
  function resolveHookFileRefs(args) {
43
45
  const isShellTool = (args.agent === "claude_code" || args.agent === "codex") && args.toolName === "Bash" || args.agent === "cursor" && args.toolName === "Shell";
44
46
  const command = isShellTool ? typeof args.toolInput === "string" ? args.toolInput : args.toolInput && typeof args.toolInput === "object" && typeof args.toolInput.command === "string" ? args.toolInput.command : void 0 : void 0;
45
- const shell = command === void 0 ? void 0 : analyzeShellTargets(command);
47
+ const shell = command === void 0 ? void 0 : analyzeShellTargets(command, args.cwd);
46
48
  const shellMutation = shell?.mutation === "none" ? "none" : shell?.coverage === "complete" ? "resolved" : shell ? "unresolved" : void 0;
47
49
  const readPath = args.agent === "claude_code" && args.toolName === "Read" && args.toolInput && typeof args.toolInput === "object" && typeof args.toolInput.file_path === "string" ? [args.toolInput.file_path] : void 0;
48
50
  const nativeTargets = shell ? null : readPath ? { paths: readPath, complete: true } : extractFileTargets(args.toolName, args.toolInput, args.agent);