@primitive.ai/prim 0.1.0-alpha.116 → 0.1.0-alpha.118

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 (47) hide show
  1. package/README.md +21 -21
  2. package/SKILL.md +3 -3
  3. package/dist/{chunk-XG7S3LIL.js → chunk-3NJ4FUPK.js} +889 -919
  4. package/dist/{chunk-J5HBSRAV.js → chunk-4HEWA4IO.js} +1 -1
  5. package/dist/{chunk-LEUZDTNT.js → chunk-B3FVP7VQ.js} +1 -1
  6. package/dist/{chunk-4OEJ2ONG.js → chunk-C2AEY4AI.js} +2 -13
  7. package/dist/{chunk-S55JKCHQ.js → chunk-C2AJBMP2.js} +2 -2
  8. package/dist/{chunk-D3ZDZZYS.js → chunk-CHRICRVE.js} +17 -10
  9. package/dist/{chunk-HMD5K6W7.js → chunk-ECP7EGOD.js} +2 -2
  10. package/dist/{chunk-FTW4ZCBA.js → chunk-FPDOBG3H.js} +1 -1
  11. package/dist/{chunk-3TIKBQHV.js → chunk-JGOFEG6T.js} +6 -4
  12. package/dist/chunk-JSBRDJBE.js +30 -0
  13. package/dist/{chunk-KGBMU76T.js → chunk-JXQVXU2K.js} +1 -1
  14. package/dist/chunk-KZB4ABIB.js +13 -0
  15. package/dist/{chunk-I3J344DF.js → chunk-L3NUFCOD.js} +5 -5
  16. package/dist/{chunk-6IRAGUYK.js → chunk-LEEWUN74.js} +2 -2
  17. package/dist/{chunk-JKJ22ONL.js → chunk-OHLVHT6R.js} +6 -6
  18. package/dist/{chunk-RLBASQJD.js → chunk-OIXHRN32.js} +4 -4
  19. package/dist/{chunk-LLKJAET2.js → chunk-PYIIYC3A.js} +8 -16
  20. package/dist/{chunk-NEQI2VLM.js → chunk-Q4CWXKNV.js} +5 -5
  21. package/dist/{chunk-4SN5BCIG.js → chunk-QX7QFMLF.js} +2 -2
  22. package/dist/{chunk-CXMLAWC2.js → chunk-SCOEPFOV.js} +2 -2
  23. package/dist/{chunk-6JHKKLA2.js → chunk-UMSJ4DU2.js} +46 -46
  24. package/dist/{chunk-JKO6PZWQ.js → chunk-VEI7KUOU.js} +26 -48
  25. package/dist/hook-runtime/daemon/server.js +1 -0
  26. package/dist/hook-runtime/hooks/post-commit.js +1 -0
  27. package/dist/hook-runtime/hooks/post-rewrite.js +1 -0
  28. package/dist/hook-runtime/hooks/post-tool-use.js +29 -29
  29. package/dist/hook-runtime/hooks/pre-commit.js +1 -0
  30. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +34746 -0
  31. package/dist/hook-runtime/hooks/pre-tool-use.js +82 -35549
  32. package/dist/hook-runtime/hooks/prim-hook.js +22 -22
  33. package/dist/hook-runtime/hooks/session-end.js +14 -14
  34. package/dist/hook-runtime/hooks/session-start.js +100 -100
  35. package/dist/hook-runtime/index.js +244 -256
  36. package/dist/hook-runtime/statusline-main.js +1 -0
  37. package/dist/hooks/post-commit.js +8 -7
  38. package/dist/hooks/post-rewrite.js +7 -6
  39. package/dist/hooks/post-tool-use.js +25 -22
  40. package/dist/hooks/pre-commit.js +5 -4
  41. package/dist/hooks/pre-tool-use-worker.js +222 -0
  42. package/dist/hooks/pre-tool-use.js +73 -257
  43. package/dist/hooks/prim-hook.js +25 -22
  44. package/dist/hooks/session-end.js +10 -7
  45. package/dist/hooks/session-start.js +22 -19
  46. package/dist/index.js +54 -53
  47. 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";
@@ -1,32 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  recordPostCommitFired
4
- } from "../chunk-KGBMU76T.js";
4
+ } from "../chunk-JXQVXU2K.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-C2AJBMP2.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-ECP7EGOD.js";
19
+ import "../chunk-LEEWUN74.js";
20
20
  import {
21
21
  cachedCollectScopeAdmits
22
- } from "../chunk-3TIKBQHV.js";
23
- import "../chunk-6JHKKLA2.js";
22
+ } from "../chunk-JGOFEG6T.js";
23
+ import "../chunk-UMSJ4DU2.js";
24
24
  import {
25
25
  githubRepositoryFullName,
26
26
  isRepoActiveForCapture,
27
27
  repoSyncId,
28
28
  resolveRepositoryContext
29
- } from "../chunk-XG7S3LIL.js";
29
+ } from "../chunk-3NJ4FUPK.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-C2AJBMP2.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-ECP7EGOD.js";
16
+ import "../chunk-LEEWUN74.js";
17
17
  import {
18
18
  cachedCollectScopeAdmits
19
- } from "../chunk-3TIKBQHV.js";
20
- import "../chunk-6JHKKLA2.js";
19
+ } from "../chunk-JGOFEG6T.js";
20
+ import "../chunk-UMSJ4DU2.js";
21
21
  import {
22
22
  githubRepositoryFullName,
23
23
  isRepoActiveForCapture,
24
24
  repoSyncId,
25
25
  resolveRepositoryContext
26
- } from "../chunk-XG7S3LIL.js";
26
+ } from "../chunk-3NJ4FUPK.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,61 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  requireDurableIngestAcknowledgement
4
- } from "../chunk-LEUZDTNT.js";
4
+ } from "../chunk-B3FVP7VQ.js";
5
5
  import {
6
6
  enrichHookPayloadWithFileRefs,
7
7
  preserveHookFileMetadata
8
- } from "../chunk-RLBASQJD.js";
8
+ } from "../chunk-OIXHRN32.js";
9
+ import {
10
+ appendCodexContext,
11
+ prepareCodexContext
12
+ } from "../chunk-PYIIYC3A.js";
13
+ import "../chunk-QX7QFMLF.js";
9
14
  import {
10
15
  postToolInvocationId,
11
16
  toMove,
12
17
  toolOutcomeFor
13
- } from "../chunk-S55JKCHQ.js";
18
+ } from "../chunk-C2AJBMP2.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-ECP7EGOD.js";
26
+ import "../chunk-4HEWA4IO.js";
21
27
  import {
22
28
  observeDemoInvocation
23
- } from "../chunk-CXMLAWC2.js";
29
+ } from "../chunk-SCOEPFOV.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-C2AEY4AI.js";
35
+ import "../chunk-L3NUFCOD.js";
36
+ import "../chunk-VEI7KUOU.js";
30
37
  import {
31
38
  scrubFromCwd
32
- } from "../chunk-6IRAGUYK.js";
39
+ } from "../chunk-LEEWUN74.js";
33
40
  import {
34
41
  bold,
35
42
  cachedCollectScopeAdmits,
36
43
  color
37
- } from "../chunk-3TIKBQHV.js";
44
+ } from "../chunk-JGOFEG6T.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-UMSJ4DU2.js";
50
49
  import {
51
50
  currentBranch,
52
51
  isRepoActiveForCapture,
53
52
  repoSyncId,
54
53
  resolveRepositoryContext
55
- } from "../chunk-XG7S3LIL.js";
54
+ } from "../chunk-3NJ4FUPK.js";
55
+ import {
56
+ parseAgent
57
+ } from "../chunk-KZB4ABIB.js";
58
+ import "../chunk-JSBRDJBE.js";
56
59
 
57
60
  // src/hooks/post-tool-use.ts
58
61
  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-Q4CWXKNV.js";
6
+ import "../chunk-4HEWA4IO.js";
7
+ import "../chunk-UMSJ4DU2.js";
8
+ import "../chunk-3NJ4FUPK.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,222 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ PREFLIGHT_PROTOCOL_VERSION,
4
+ boundedClientVersion,
5
+ editPreview,
6
+ hasConfirmedConflict,
7
+ proposalFor,
8
+ proposalIsTruncated,
9
+ resolvePreflightTargets,
10
+ resultForPreflight,
11
+ toolInputDigest,
12
+ waitForPreflight
13
+ } from "../chunk-CHRICRVE.js";
14
+ import {
15
+ observeDemoInvocation
16
+ } from "../chunk-SCOEPFOV.js";
17
+ import {
18
+ normalizeEnvelope,
19
+ readHookStdin,
20
+ shouldSuppressImportedCursorHandler
21
+ } from "../chunk-C2AEY4AI.js";
22
+ import {
23
+ buildCodexOutput,
24
+ buildCursorOutput,
25
+ buildHermesOutput,
26
+ buildHookOutput,
27
+ demoteForMode,
28
+ failOpenCodex,
29
+ failOpenCursor,
30
+ failOpenHermes,
31
+ failOpenOutput,
32
+ readHookMode
33
+ } from "../chunk-L3NUFCOD.js";
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";
50
+ import "../chunk-JSBRDJBE.js";
51
+
52
+ // src/hooks/pre-tool-use-worker.ts
53
+ var STDIN_TIMEOUT_MS = 1e3;
54
+ var deadline = performance.now() + Math.max(0, Number(process.argv.at(-1)) - Date.now());
55
+ var agent = parseAgent(process.argv);
56
+ async function emit(output, confirmed = false) {
57
+ return await new Promise((resolve) => {
58
+ try {
59
+ process.stdout.write(
60
+ `${JSON.stringify({ output, confirmed })}
61
+ `,
62
+ (error) => resolve(!error)
63
+ );
64
+ } catch {
65
+ resolve(false);
66
+ }
67
+ });
68
+ }
69
+ function failOpen() {
70
+ if (agent === "hermes") return failOpenHermes();
71
+ if (agent === "cursor") return failOpenCursor();
72
+ return agent === "codex" ? failOpenCodex() : failOpenOutput();
73
+ }
74
+ function invocationId(envelope) {
75
+ const value = agent === "hermes" ? envelope.extra?.tool_call_id : envelope.tool_use_id;
76
+ return typeof value === "string" && value.length > 0 ? value : void 0;
77
+ }
78
+ function hermesAdvisory(result, aggregate) {
79
+ const parts = [];
80
+ if (aggregate === "warn") parts.push(result.reason);
81
+ if (result.verdict === "unavailable") {
82
+ parts.push(result.unavailable ?? result.reason);
83
+ }
84
+ if (result.additionalContext && result.additionalContext !== result.reason) {
85
+ parts.push(result.additionalContext);
86
+ }
87
+ const message = [...new Set(parts.filter(Boolean))].join("\n");
88
+ return message.startsWith("[primitive]") ? message : message ? `[primitive] ${message}` : "";
89
+ }
90
+ async function main() {
91
+ const mode = readHookMode(process.env);
92
+ if (mode === "off") {
93
+ await emit(failOpen());
94
+ return;
95
+ }
96
+ let raw;
97
+ try {
98
+ raw = await readHookStdin(STDIN_TIMEOUT_MS);
99
+ } catch {
100
+ await emit(failOpen());
101
+ return;
102
+ }
103
+ let envelope;
104
+ try {
105
+ const incoming = JSON.parse(raw);
106
+ if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) {
107
+ throw new Error("The hook envelope must be an object");
108
+ }
109
+ const fields = incoming;
110
+ if (agent !== "cursor" && shouldSuppressImportedCursorHandler(fields, "prim-pre-tool-use")) {
111
+ await emit(failOpenCursor());
112
+ return;
113
+ }
114
+ envelope = normalizeEnvelope(fields, agent);
115
+ if (typeof envelope.hook_event_name !== "string" || !envelope.hook_event_name) {
116
+ throw new Error("The hook event identity is unavailable");
117
+ }
118
+ } catch {
119
+ await emit(failOpen());
120
+ return;
121
+ }
122
+ try {
123
+ if (observeDemoInvocation(envelope, agent, false).invocation) {
124
+ await emit(failOpen());
125
+ return;
126
+ }
127
+ } catch {
128
+ }
129
+ if (envelope.hook_event_name !== "PreToolUse") {
130
+ await emit(failOpen());
131
+ return;
132
+ }
133
+ if (typeof envelope.tool_name !== "string" || !envelope.tool_name) {
134
+ await emit(failOpen());
135
+ return;
136
+ }
137
+ const toolName = envelope.tool_name;
138
+ const cwd = typeof envelope.cwd === "string" && envelope.cwd.length > 0 ? envelope.cwd : process.cwd();
139
+ const targets = resolvePreflightTargets({
140
+ toolName,
141
+ toolInput: envelope.tool_input,
142
+ agent,
143
+ cwd
144
+ });
145
+ if (targets.mutation === "none") {
146
+ await emit(failOpen());
147
+ return;
148
+ }
149
+ if (!isRepoActive(cwd)) {
150
+ await emit(failOpen());
151
+ return;
152
+ }
153
+ if (targets.paths.length === 0 && !targets.definite) {
154
+ await emit(failOpen());
155
+ return;
156
+ }
157
+ if (agent === "cursor" && targets.coverage === "unverified") {
158
+ await emit(failOpen());
159
+ return;
160
+ }
161
+ const binding = repoSyncId(cwd);
162
+ const branch = currentBranch(cwd);
163
+ const sessionId = envelope.session_id;
164
+ const callId = invocationId(envelope);
165
+ if (!binding || typeof sessionId !== "string" || !sessionId || !callId) {
166
+ await emit(failOpen());
167
+ return;
168
+ }
169
+ const collectScopeAdmits = cachedCollectScopeAdmits(cwd, {
170
+ repository: githubRepositoryFullName(cwd) ?? void 0,
171
+ branch,
172
+ agent,
173
+ paths: targets.paths,
174
+ pathsComplete: targets.coverage === "complete"
175
+ });
176
+ const request = {
177
+ protocolVersion: PREFLIGHT_PROTOCOL_VERSION,
178
+ operation: "start",
179
+ toolInputDigest: toolInputDigest(toolName, envelope.tool_input),
180
+ agent,
181
+ clientMode: mode,
182
+ clientVersion: boundedClientVersion(packageVersion()),
183
+ sessionId,
184
+ invocationId: callId,
185
+ repoSyncId: binding,
186
+ paths: targets.paths,
187
+ coverage: targets.coverage,
188
+ ...branch === void 0 ? {} : { branch },
189
+ proposal: collectScopeAdmits ? proposalFor(envelope.tool_input) : ""
190
+ };
191
+ let result;
192
+ try {
193
+ const response = await waitForPreflight(request, {
194
+ deadline,
195
+ stopOnConflict: true
196
+ });
197
+ if (!hasConfirmedConflict(response)) {
198
+ await emit(failOpen());
199
+ return;
200
+ }
201
+ result = resultForPreflight(
202
+ response,
203
+ editPreview(toolName, envelope.tool_input, targets.paths),
204
+ request,
205
+ collectScopeAdmits && (toolName === "Bash" || toolName === "Shell") && proposalIsTruncated(envelope.tool_input)
206
+ );
207
+ } catch {
208
+ await emit(failOpen());
209
+ return;
210
+ }
211
+ const aggregate = demoteForMode(result.verdict === "unavailable" ? "deny" : result.verdict, mode);
212
+ if (agent === "hermes" && aggregate !== "deny" && aggregate !== "ask") {
213
+ const advisory = hermesAdvisory(result, aggregate);
214
+ if (advisory) process.stderr.write(`${advisory}
215
+ `);
216
+ }
217
+ const output = agent === "hermes" ? buildHermesOutput(aggregate, [result]) : agent === "cursor" ? buildCursorOutput(aggregate, [result]) : agent === "codex" ? buildCodexOutput(aggregate, [result]) : buildHookOutput(aggregate, [result]);
218
+ await emit(output, true);
219
+ }
220
+ main().catch(async () => {
221
+ await emit(failOpen());
222
+ });