@primitive.ai/prim 0.1.0-alpha.117 → 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 (50) hide show
  1. package/README.md +21 -21
  2. package/SKILL.md +3 -3
  3. package/dist/{chunk-FTW4ZCBA.js → chunk-2AKDX4RU.js} +1 -1
  4. package/dist/{chunk-D3ZDZZYS.js → chunk-2JA524SC.js} +31 -17
  5. package/dist/{chunk-I3J344DF.js → chunk-4L7TAM5S.js} +122 -287
  6. package/dist/{chunk-3TIKBQHV.js → chunk-5BQ2NEMP.js} +2741 -2540
  7. package/dist/{chunk-LEUZDTNT.js → chunk-A6M2M5A2.js} +1 -1
  8. package/dist/{chunk-JKJ22ONL.js → chunk-CCGFRNAA.js} +6 -6
  9. package/dist/{chunk-CXMLAWC2.js → chunk-CSE44DPA.js} +2 -2
  10. package/dist/{chunk-NEQI2VLM.js → chunk-D235RJNO.js} +5 -5
  11. package/dist/{chunk-4SN5BCIG.js → chunk-GYQOZGGF.js} +2 -2
  12. package/dist/{chunk-LLKJAET2.js → chunk-HXICZG5J.js} +8 -16
  13. package/dist/chunk-JSBRDJBE.js +30 -0
  14. package/dist/chunk-KZB4ABIB.js +13 -0
  15. package/dist/{chunk-KGBMU76T.js → chunk-LBCPRHNG.js} +1 -1
  16. package/dist/{chunk-HMD5K6W7.js → chunk-LTTF4MBE.js} +2 -2
  17. package/dist/{chunk-JKO6PZWQ.js → chunk-MWNRXAEB.js} +26 -48
  18. package/dist/{chunk-6IRAGUYK.js → chunk-NQFRQ56V.js} +2 -2
  19. package/dist/{chunk-XG7S3LIL.js → chunk-P2O7NLVN.js} +887 -918
  20. package/dist/{chunk-J5HBSRAV.js → chunk-SLDZJD6Q.js} +1 -1
  21. package/dist/{chunk-4OEJ2ONG.js → chunk-TC4FTRYO.js} +2 -13
  22. package/dist/{chunk-6JHKKLA2.js → chunk-U67RBNIZ.js} +46 -46
  23. package/dist/{chunk-S55JKCHQ.js → chunk-VOC4KOOP.js} +2 -2
  24. package/dist/chunk-W27EFR7W.js +271 -0
  25. package/dist/{chunk-RLBASQJD.js → chunk-XWAKFL3T.js} +9 -7
  26. package/dist/daemon/server.js +2733 -2531
  27. package/dist/hook-runtime/daemon/server.js +2734 -2531
  28. package/dist/hook-runtime/hooks/post-commit.js +2741 -2538
  29. package/dist/hook-runtime/hooks/post-rewrite.js +2741 -2538
  30. package/dist/hook-runtime/hooks/post-tool-use.js +2883 -2579
  31. package/dist/hook-runtime/hooks/pre-commit.js +1 -0
  32. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +35089 -0
  33. package/dist/hook-runtime/hooks/pre-tool-use.js +109 -35539
  34. package/dist/hook-runtime/hooks/prim-hook.js +2875 -2571
  35. package/dist/hook-runtime/hooks/session-end.js +19 -16
  36. package/dist/hook-runtime/hooks/session-start.js +2834 -2632
  37. package/dist/hook-runtime/index.js +3030 -2830
  38. package/dist/hook-runtime/statusline-main.js +6 -2
  39. package/dist/hooks/post-commit.js +8 -7
  40. package/dist/hooks/post-rewrite.js +7 -6
  41. package/dist/hooks/post-tool-use.js +26 -22
  42. package/dist/hooks/pre-commit.js +5 -4
  43. package/dist/hooks/pre-tool-use-worker.js +264 -0
  44. package/dist/hooks/pre-tool-use.js +93 -250
  45. package/dist/hooks/prim-hook.js +26 -22
  46. package/dist/hooks/session-end.js +10 -7
  47. package/dist/hooks/session-start.js +22 -19
  48. package/dist/index.js +59 -54
  49. package/dist/statusline-main.js +5 -2
  50. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire as __primCreateRequire } from "node:module"; const require = __primCreateRequire(import.meta.url);
2
3
 
3
4
  // src/commands/statusline.ts
4
5
  import { readFileSync as readFileSync7 } from "fs";
@@ -583,7 +584,7 @@ var GIT_TIMEOUT_MS2 = 1e3;
583
584
  var REPO_SYNC_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
584
585
  var PROJECT_INSTALL_FILES = [".claude/settings.json", ".codex/hooks.json", ".cursor/hooks.json"];
585
586
  var PRIM_HOOK_BINS = ["prim-hook", "prim-pre-tool-use", "prim-post-tool-use"];
586
- function repoActiveFlag(cwd) {
587
+ function repoActiveFlag(cwd, strict = false) {
587
588
  try {
588
589
  const value = execFileSync2("git", ["config", "--get", PRIM_ACTIVE_KEY], {
589
590
  cwd,
@@ -593,8 +594,11 @@ function repoActiveFlag(cwd) {
593
594
  }).trim();
594
595
  if (value === "true") return "true";
595
596
  if (value === "false") return "false";
597
+ if (strict) throw new Error("Repository activation is invalid");
596
598
  return void 0;
597
- } catch {
599
+ } catch (error) {
600
+ if (strict && !(typeof error === "object" && error !== null && "status" in error && error.status === 1))
601
+ throw error;
598
602
  return void 0;
599
603
  }
600
604
  }
@@ -1,32 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  recordPostCommitFired
4
- } from "../chunk-KGBMU76T.js";
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-S55JKCHQ.js";
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-HMD5K6W7.js";
19
- import "../chunk-6IRAGUYK.js";
18
+ } from "../chunk-LTTF4MBE.js";
19
+ import "../chunk-NQFRQ56V.js";
20
20
  import {
21
21
  cachedCollectScopeAdmits
22
- } from "../chunk-3TIKBQHV.js";
23
- import "../chunk-6JHKKLA2.js";
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-XG7S3LIL.js";
29
+ } from "../chunk-P2O7NLVN.js";
30
+ import "../chunk-JSBRDJBE.js";
30
31
 
31
32
  // src/hooks/post-commit.ts
32
33
  import { execFileSync, spawn } from "child_process";
@@ -5,25 +5,26 @@ import {
5
5
  import {
6
6
  canonicalRewritePairs,
7
7
  toRewriteMove
8
- } from "../chunk-S55JKCHQ.js";
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-HMD5K6W7.js";
16
- import "../chunk-6IRAGUYK.js";
15
+ } from "../chunk-LTTF4MBE.js";
16
+ import "../chunk-NQFRQ56V.js";
17
17
  import {
18
18
  cachedCollectScopeAdmits
19
- } from "../chunk-3TIKBQHV.js";
20
- import "../chunk-6JHKKLA2.js";
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-XG7S3LIL.js";
26
+ } from "../chunk-P2O7NLVN.js";
27
+ import "../chunk-JSBRDJBE.js";
27
28
 
28
29
  // src/hooks/post-rewrite.ts
29
30
  import { execFileSync, spawn } from "child_process";
@@ -1,58 +1,62 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  requireDurableIngestAcknowledgement
4
- } from "../chunk-LEUZDTNT.js";
4
+ } from "../chunk-A6M2M5A2.js";
5
5
  import {
6
6
  enrichHookPayloadWithFileRefs,
7
7
  preserveHookFileMetadata
8
- } from "../chunk-RLBASQJD.js";
8
+ } from "../chunk-XWAKFL3T.js";
9
+ import {
10
+ appendCodexContext,
11
+ prepareCodexContext
12
+ } from "../chunk-HXICZG5J.js";
13
+ import "../chunk-GYQOZGGF.js";
9
14
  import {
10
15
  postToolInvocationId,
11
16
  toMove,
12
17
  toolOutcomeFor
13
- } from "../chunk-S55JKCHQ.js";
18
+ } from "../chunk-VOC4KOOP.js";
14
19
  import {
15
20
  getOrCreateWorkspaceId
16
21
  } from "../chunk-EZXEWFDG.js";
17
22
  import {
18
23
  appendMove,
19
24
  resolveOrg
20
- } from "../chunk-HMD5K6W7.js";
25
+ } from "../chunk-LTTF4MBE.js";
26
+ import "../chunk-SLDZJD6Q.js";
21
27
  import {
22
28
  observeDemoInvocation
23
- } from "../chunk-CXMLAWC2.js";
29
+ } from "../chunk-CSE44DPA.js";
24
30
  import {
25
- appendCodexContext,
26
- prepareCodexContext
27
- } from "../chunk-LLKJAET2.js";
28
- import "../chunk-I3J344DF.js";
29
- import "../chunk-4SN5BCIG.js";
31
+ normalizeEnvelope,
32
+ readHookStdin,
33
+ shouldSuppressImportedCursorHandler
34
+ } from "../chunk-TC4FTRYO.js";
35
+ import "../chunk-4L7TAM5S.js";
36
+ import "../chunk-MWNRXAEB.js";
30
37
  import {
31
38
  scrubFromCwd
32
- } from "../chunk-6IRAGUYK.js";
39
+ } from "../chunk-NQFRQ56V.js";
33
40
  import {
34
41
  bold,
35
42
  cachedCollectScopeAdmits,
36
43
  color
37
- } from "../chunk-3TIKBQHV.js";
44
+ } from "../chunk-5BQ2NEMP.js";
38
45
  import {
39
46
  getClient,
40
47
  terminalSafeLine
41
- } from "../chunk-6JHKKLA2.js";
42
- import {
43
- normalizeEnvelope,
44
- parseAgent,
45
- readHookStdin,
46
- shouldSuppressImportedCursorHandler
47
- } from "../chunk-4OEJ2ONG.js";
48
- import "../chunk-JKO6PZWQ.js";
49
- import "../chunk-J5HBSRAV.js";
48
+ } from "../chunk-U67RBNIZ.js";
50
49
  import {
51
50
  currentBranch,
52
51
  isRepoActiveForCapture,
53
52
  repoSyncId,
54
53
  resolveRepositoryContext
55
- } from "../chunk-XG7S3LIL.js";
54
+ } from "../chunk-P2O7NLVN.js";
55
+ import {
56
+ parseAgent
57
+ } from "../chunk-KZB4ABIB.js";
58
+ import "../chunk-W27EFR7W.js";
59
+ import "../chunk-JSBRDJBE.js";
56
60
 
57
61
  // src/hooks/post-tool-use.ts
58
62
  import { readFileSync } from "fs";
@@ -2,10 +2,11 @@
2
2
  import {
3
3
  checkAffectedDecisions,
4
4
  formatDecisionsWarning
5
- } from "../chunk-NEQI2VLM.js";
6
- import "../chunk-6JHKKLA2.js";
7
- import "../chunk-J5HBSRAV.js";
8
- import "../chunk-XG7S3LIL.js";
5
+ } from "../chunk-D235RJNO.js";
6
+ import "../chunk-SLDZJD6Q.js";
7
+ import "../chunk-U67RBNIZ.js";
8
+ import "../chunk-P2O7NLVN.js";
9
+ import "../chunk-JSBRDJBE.js";
9
10
 
10
11
  // src/hooks/pre-commit.ts
11
12
  import { execSync } from "child_process";
@@ -0,0 +1,264 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ PREFLIGHT_PROTOCOL_VERSION,
4
+ PreflightPausedError,
5
+ boundedClientVersion,
6
+ editPreview,
7
+ hasCompleteCoverage,
8
+ hasConfirmedConflict,
9
+ pausedResult,
10
+ proposalFor,
11
+ proposalIsTruncated,
12
+ resolvePreflightTargets,
13
+ resultForPreflight,
14
+ toolInputDigest,
15
+ waitForPreflight
16
+ } from "../chunk-2JA524SC.js";
17
+ import {
18
+ observeDemoInvocation
19
+ } from "../chunk-CSE44DPA.js";
20
+ import {
21
+ normalizeEnvelope,
22
+ readHookStdin,
23
+ shouldSuppressImportedCursorHandler
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";
43
+ import {
44
+ buildCodexOutput,
45
+ buildCursorOutput,
46
+ buildHermesOutput,
47
+ buildHookOutput,
48
+ demoteForMode,
49
+ failOpenCodex,
50
+ failOpenCursor,
51
+ failOpenHermes,
52
+ failOpenOutput,
53
+ readHookMode
54
+ } from "../chunk-W27EFR7W.js";
55
+ import "../chunk-JSBRDJBE.js";
56
+
57
+ // src/hooks/pre-tool-use-worker.ts
58
+ import { realpathSync } from "fs";
59
+ import { relative } from "path";
60
+ var STDIN_TIMEOUT_MS = 1e3;
61
+ var deadline = performance.now() + Math.max(0, Number(process.argv.at(-1)) - Date.now());
62
+ var agent = parseAgent(process.argv);
63
+ async function emit(output, confirmed = false) {
64
+ return await new Promise((resolve) => {
65
+ try {
66
+ process.stdout.write(
67
+ `${JSON.stringify({ output, confirmed })}
68
+ `,
69
+ (error) => resolve(!error)
70
+ );
71
+ } catch {
72
+ resolve(false);
73
+ }
74
+ });
75
+ }
76
+ function failOpen() {
77
+ if (agent === "hermes") return failOpenHermes();
78
+ if (agent === "cursor") return failOpenCursor();
79
+ return agent === "codex" ? failOpenCodex() : failOpenOutput();
80
+ }
81
+ function invocationId(envelope) {
82
+ const value = agent === "hermes" ? envelope.extra?.tool_call_id : envelope.tool_use_id;
83
+ return typeof value === "string" && value.length > 0 ? value : void 0;
84
+ }
85
+ function hermesAdvisory(result, aggregate) {
86
+ const parts = [];
87
+ if (aggregate === "warn") parts.push(result.reason);
88
+ if (result.verdict === "unavailable") {
89
+ parts.push(result.unavailable ?? result.reason);
90
+ }
91
+ if (result.additionalContext && result.additionalContext !== result.reason) {
92
+ parts.push(result.additionalContext);
93
+ }
94
+ const message = [...new Set(parts.filter(Boolean))].join("\n");
95
+ return message.startsWith("[primitive]") ? message : message ? `[primitive] ${message}` : "";
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
+ }
105
+ async function main() {
106
+ const mode = readHookMode(process.env);
107
+ if (mode === "off") {
108
+ await emit(failOpen(), true);
109
+ return;
110
+ }
111
+ let raw;
112
+ try {
113
+ raw = await readHookStdin(STDIN_TIMEOUT_MS);
114
+ } catch {
115
+ await emit(failOpen());
116
+ return;
117
+ }
118
+ let envelope;
119
+ try {
120
+ const incoming = JSON.parse(raw);
121
+ if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) {
122
+ throw new Error("The hook envelope must be an object");
123
+ }
124
+ const fields = incoming;
125
+ if (agent !== "cursor" && shouldSuppressImportedCursorHandler(fields, "prim-pre-tool-use")) {
126
+ await emit(failOpenCursor(), true);
127
+ return;
128
+ }
129
+ envelope = normalizeEnvelope(fields, agent);
130
+ if (typeof envelope.hook_event_name !== "string" || !envelope.hook_event_name) {
131
+ throw new Error("The hook event identity is unavailable");
132
+ }
133
+ } catch {
134
+ await emit(failOpen());
135
+ return;
136
+ }
137
+ try {
138
+ if (observeDemoInvocation(envelope, agent, false).invocation) {
139
+ await emit(failOpen(), true);
140
+ return;
141
+ }
142
+ } catch {
143
+ }
144
+ if (envelope.hook_event_name !== "PreToolUse") {
145
+ await emit(failOpen(), true);
146
+ return;
147
+ }
148
+ if (typeof envelope.tool_name !== "string" || !envelope.tool_name) {
149
+ await emit(failOpen());
150
+ return;
151
+ }
152
+ const toolName = envelope.tool_name;
153
+ protectedShell = (agent === "claude_code" || agent === "codex") && toolName === "Bash";
154
+ const cwd = typeof envelope.cwd === "string" && envelope.cwd.length > 0 ? envelope.cwd : process.cwd();
155
+ const targets = resolvePreflightTargets({
156
+ toolName,
157
+ toolInput: envelope.tool_input,
158
+ agent,
159
+ cwd
160
+ });
161
+ if (targets.mutation === "none") {
162
+ await emit(failOpen(), true);
163
+ return;
164
+ }
165
+ if (repoActiveFlag(cwd, protectedShell) !== "true") {
166
+ await emit(failOpen(), true);
167
+ return;
168
+ }
169
+ if (!protectedShell && targets.paths.length === 0 && !targets.definite) {
170
+ await emit(failOpen());
171
+ return;
172
+ }
173
+ if (agent === "cursor" && targets.coverage === "unverified") {
174
+ await emit(failOpen());
175
+ return;
176
+ }
177
+ const binding = repoSyncId(cwd);
178
+ const branch = currentBranch(cwd);
179
+ const sessionId = envelope.session_id;
180
+ const callId = invocationId(envelope);
181
+ if (!binding || typeof sessionId !== "string" || !sessionId || !callId) {
182
+ if (protectedShell) {
183
+ await pause("Repository or invocation identity is unavailable");
184
+ return;
185
+ }
186
+ await emit(failOpen());
187
+ return;
188
+ }
189
+ const collectScopeAdmits = cachedCollectScopeAdmits(cwd, {
190
+ repository: githubRepositoryFullName(cwd) ?? void 0,
191
+ branch,
192
+ agent,
193
+ paths: targets.paths,
194
+ pathsComplete: targets.coverage === "complete"
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;
203
+ const request = {
204
+ protocolVersion: PREFLIGHT_PROTOCOL_VERSION,
205
+ operation: "start",
206
+ toolInputDigest: toolInputDigest(toolName, envelope.tool_input),
207
+ agent,
208
+ clientMode: mode,
209
+ clientVersion: boundedClientVersion(packageVersion()),
210
+ sessionId,
211
+ invocationId: callId,
212
+ repoSyncId: binding,
213
+ paths: targets.paths,
214
+ coverage: targets.coverage,
215
+ ...protectedShell ? {
216
+ shellCheck: {
217
+ targetMode: targets.coverage === "complete" ? "files" : "repository"
218
+ }
219
+ } : {},
220
+ ...branch === void 0 ? {} : { branch },
221
+ proposal: collectScopeAdmits ? proposalFor(proposalInput) : ""
222
+ };
223
+ let result;
224
+ try {
225
+ const response = await waitForPreflight(request, {
226
+ deadline,
227
+ stopOnConflict: !protectedShell
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
+ }
233
+ if (!hasConfirmedConflict(response)) {
234
+ await emit(failOpen(), true);
235
+ return;
236
+ }
237
+ result = resultForPreflight(
238
+ response,
239
+ editPreview(toolName, envelope.tool_input, targets.paths),
240
+ request,
241
+ collectScopeAdmits && (toolName === "Bash" || toolName === "Shell") && proposalIsTruncated(proposalInput)
242
+ );
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());
250
+ return;
251
+ }
252
+ const aggregate = demoteForMode(result.verdict === "unavailable" ? "deny" : result.verdict, mode);
253
+ if (agent === "hermes" && aggregate !== "deny" && aggregate !== "ask") {
254
+ const advisory = hermesAdvisory(result, aggregate);
255
+ if (advisory) process.stderr.write(`${advisory}
256
+ `);
257
+ }
258
+ const output = agent === "hermes" ? buildHermesOutput(aggregate, [result]) : agent === "cursor" ? buildCursorOutput(aggregate, [result]) : agent === "codex" ? buildCodexOutput(aggregate, [result]) : buildHookOutput(aggregate, [result]);
259
+ await emit(output, true);
260
+ }
261
+ main().catch(async () => {
262
+ if (protectedShell) await pause("Shell evaluation is unavailable");
263
+ else await emit(failOpen());
264
+ });