@primitive.ai/prim 0.1.0-alpha.111 → 0.1.0-alpha.113

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 (40) hide show
  1. package/README.md +18 -5
  2. package/SKILL.md +20 -16
  3. package/dist/{chunk-KQ4WBK5R.js → chunk-3KKEV7VI.js} +2 -2
  4. package/dist/{chunk-2IRLFOEL.js → chunk-6JHKKLA2.js} +79 -1
  5. package/dist/{chunk-IQZA65NV.js → chunk-7DVEH7FO.js} +1 -1
  6. package/dist/{chunk-W4ZEPZLK.js → chunk-BXLH4LDU.js} +1 -1
  7. package/dist/{chunk-GA2RXPJL.js → chunk-DWAXFXDG.js} +2 -2
  8. package/dist/{chunk-7VIMU2HR.js → chunk-FTW4ZCBA.js} +2 -2
  9. package/dist/{chunk-JJI7FU24.js → chunk-HMD5K6W7.js} +1 -1
  10. package/dist/{chunk-HTRFPXMD.js → chunk-IW5HCCOW.js} +3 -3
  11. package/dist/{chunk-UDBBJWQH.js → chunk-IZXLH3R5.js} +930 -582
  12. package/dist/{chunk-5LRKJTLA.js → chunk-J5HBSRAV.js} +7 -5
  13. package/dist/{chunk-5BLGBSDM.js → chunk-JDIAPBY7.js} +1 -1
  14. package/dist/{chunk-2Q3OGSTV.js → chunk-NEQI2VLM.js} +2 -2
  15. package/dist/{chunk-AOJ254C2.js → chunk-PJW6JZMH.js} +4 -4
  16. package/dist/{chunk-43ZKL27W.js → chunk-RTULPLS7.js} +1 -1
  17. package/dist/{chunk-CTRAJCPN.js → chunk-XV6C5ZV2.js} +1 -1
  18. package/dist/daemon/server.js +1184 -754
  19. package/dist/hook-runtime/daemon/server.js +1184 -754
  20. package/dist/hook-runtime/hooks/post-commit.js +929 -581
  21. package/dist/hook-runtime/hooks/post-rewrite.js +929 -581
  22. package/dist/hook-runtime/hooks/post-tool-use.js +1015 -588
  23. package/dist/hook-runtime/hooks/pre-commit.js +85 -6
  24. package/dist/hook-runtime/hooks/pre-tool-use.js +1047 -597
  25. package/dist/hook-runtime/hooks/prim-hook.js +1016 -589
  26. package/dist/hook-runtime/hooks/session-end.js +14 -12
  27. package/dist/hook-runtime/hooks/session-start.js +1016 -589
  28. package/dist/hook-runtime/index.js +1283 -915
  29. package/dist/hook-runtime/statusline-main.js +7 -5
  30. package/dist/hooks/post-commit.js +5 -5
  31. package/dist/hooks/post-rewrite.js +5 -5
  32. package/dist/hooks/post-tool-use.js +12 -12
  33. package/dist/hooks/pre-commit.js +3 -3
  34. package/dist/hooks/pre-tool-use.js +40 -17
  35. package/dist/hooks/prim-hook.js +12 -12
  36. package/dist/hooks/session-end.js +1 -1
  37. package/dist/hooks/session-start.js +7 -7
  38. package/dist/index.js +189 -247
  39. package/dist/statusline-main.js +7 -5
  40. package/package.json +3 -1
@@ -382,10 +382,6 @@ function getSiteUrlForEnvironment(primApiUrl) {
382
382
  }
383
383
  var CLI_MANAGEMENT_RESPONSE_MAX_BYTES = 2 * 1024 * 1024;
384
384
 
385
- // src/daemon/client.ts
386
- import { createConnection } from "net";
387
- import { join as join7 } from "path";
388
-
389
385
  // src/daemon/principal.ts
390
386
  import { createHash as createHash3 } from "crypto";
391
387
  var PRINCIPAL_COMPONENT_MAX_LENGTH = 512;
@@ -412,6 +408,7 @@ function resolveDaemonPrincipal(token = resolveAuthCredential()?.token) {
412
408
  // src/daemon/protocol.ts
413
409
  var DAEMON_JSON_REQUEST_MAX_BYTES = 64 * 1024;
414
410
  var DAEMON_JSON_RESPONSE_MAX_BYTES = 8 * 1024 * 1024;
411
+ var DECISION_IDENTITY_VERSION = 7;
415
412
  function isRecord(value) {
416
413
  return typeof value === "object" && value !== null && !Array.isArray(value);
417
414
  }
@@ -424,6 +421,7 @@ function parseDaemonResponseEnvelope(value) {
424
421
  if (value.error !== void 0 && typeof value.error !== "string") return void 0;
425
422
  return {
426
423
  id: value.id,
424
+ ...typeof value.decisionIdentityVersion === "number" ? { decisionIdentityVersion: value.decisionIdentityVersion } : {},
427
425
  ok: value.ok,
428
426
  ...value.result === void 0 ? {} : { result: value.result },
429
427
  ...value.error === void 0 ? {} : { error: value.error }
@@ -431,6 +429,8 @@ function parseDaemonResponseEnvelope(value) {
431
429
  }
432
430
 
433
431
  // src/daemon/client.ts
432
+ import { createConnection } from "net";
433
+ import { join as join7 } from "path";
434
434
  var SOCK_PATH = join7(primConfigDirectory(), "sock");
435
435
  var DEFAULT_TIMEOUT_MS = 250;
436
436
  var nextRequestId = 1;
@@ -503,7 +503,9 @@ function daemonRequest(method, params = {}, opts = {}) {
503
503
  return;
504
504
  }
505
505
  clearTimeout(timer);
506
- settle(res.ok && res.result !== void 0 ? res.result : null);
506
+ settle(
507
+ (!(method.startsWith("decisions_") || method.startsWith("decision_")) || res.decisionIdentityVersion === DECISION_IDENTITY_VERSION) && res.ok && res.result !== void 0 ? res.result : null
508
+ );
507
509
  } catch {
508
510
  clearTimeout(timer);
509
511
  settle(null);
@@ -8,19 +8,19 @@ import {
8
8
  import {
9
9
  commitAttributionFromEnvironment,
10
10
  toCommitMove
11
- } from "../chunk-43ZKL27W.js";
11
+ } from "../chunk-RTULPLS7.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-JJI7FU24.js";
19
- import "../chunk-KQ4WBK5R.js";
18
+ } from "../chunk-HMD5K6W7.js";
19
+ import "../chunk-3KKEV7VI.js";
20
20
  import {
21
21
  cachedCollectScopeAdmits
22
- } from "../chunk-UDBBJWQH.js";
23
- import "../chunk-2IRLFOEL.js";
22
+ } from "../chunk-IZXLH3R5.js";
23
+ import "../chunk-6JHKKLA2.js";
24
24
  import {
25
25
  githubRepositoryFullName,
26
26
  isRepoActiveForCapture,
@@ -5,19 +5,19 @@ import {
5
5
  import {
6
6
  canonicalRewritePairs,
7
7
  toRewriteMove
8
- } from "../chunk-43ZKL27W.js";
8
+ } from "../chunk-RTULPLS7.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-JJI7FU24.js";
16
- import "../chunk-KQ4WBK5R.js";
15
+ } from "../chunk-HMD5K6W7.js";
16
+ import "../chunk-3KKEV7VI.js";
17
17
  import {
18
18
  cachedCollectScopeAdmits
19
- } from "../chunk-UDBBJWQH.js";
20
- import "../chunk-2IRLFOEL.js";
19
+ } from "../chunk-IZXLH3R5.js";
20
+ import "../chunk-6JHKKLA2.js";
21
21
  import {
22
22
  githubRepositoryFullName,
23
23
  isRepoActiveForCapture,
@@ -1,44 +1,44 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  requireDurableIngestAcknowledgement
4
- } from "../chunk-W4ZEPZLK.js";
4
+ } from "../chunk-BXLH4LDU.js";
5
5
  import {
6
6
  enrichHookPayloadWithFileRefs,
7
7
  preserveHookFileMetadata
8
- } from "../chunk-HTRFPXMD.js";
8
+ } from "../chunk-IW5HCCOW.js";
9
9
  import {
10
10
  postToolInvocationId,
11
11
  toMove,
12
12
  toolOutcomeFor
13
- } from "../chunk-43ZKL27W.js";
13
+ } from "../chunk-RTULPLS7.js";
14
14
  import {
15
15
  getOrCreateWorkspaceId
16
16
  } from "../chunk-EZXEWFDG.js";
17
17
  import {
18
18
  appendMove,
19
19
  resolveOrg
20
- } from "../chunk-JJI7FU24.js";
20
+ } from "../chunk-HMD5K6W7.js";
21
21
  import {
22
22
  observeDemoInvocation
23
- } from "../chunk-CTRAJCPN.js";
23
+ } from "../chunk-XV6C5ZV2.js";
24
24
  import {
25
25
  appendCodexContext,
26
26
  prepareCodexContext
27
- } from "../chunk-AOJ254C2.js";
28
- import "../chunk-5BLGBSDM.js";
29
- import "../chunk-GA2RXPJL.js";
27
+ } from "../chunk-PJW6JZMH.js";
28
+ import "../chunk-JDIAPBY7.js";
29
+ import "../chunk-DWAXFXDG.js";
30
30
  import {
31
31
  scrubFromCwd
32
- } from "../chunk-KQ4WBK5R.js";
32
+ } from "../chunk-3KKEV7VI.js";
33
33
  import {
34
34
  bold,
35
35
  cachedCollectScopeAdmits,
36
36
  color
37
- } from "../chunk-UDBBJWQH.js";
37
+ } from "../chunk-IZXLH3R5.js";
38
38
  import {
39
39
  getClient,
40
40
  terminalSafeLine
41
- } from "../chunk-2IRLFOEL.js";
41
+ } from "../chunk-6JHKKLA2.js";
42
42
  import {
43
43
  normalizeEnvelope,
44
44
  parseAgent,
@@ -46,7 +46,7 @@ import {
46
46
  shouldSuppressImportedCursorHandler
47
47
  } from "../chunk-NH3VC7YO.js";
48
48
  import "../chunk-PO5QAYD7.js";
49
- import "../chunk-5LRKJTLA.js";
49
+ import "../chunk-J5HBSRAV.js";
50
50
  import {
51
51
  currentBranch,
52
52
  isRepoActiveForCapture,
@@ -2,9 +2,9 @@
2
2
  import {
3
3
  checkAffectedDecisions,
4
4
  formatDecisionsWarning
5
- } from "../chunk-2Q3OGSTV.js";
6
- import "../chunk-2IRLFOEL.js";
7
- import "../chunk-5LRKJTLA.js";
5
+ } from "../chunk-NEQI2VLM.js";
6
+ import "../chunk-6JHKKLA2.js";
7
+ import "../chunk-J5HBSRAV.js";
8
8
  import "../chunk-XG7S3LIL.js";
9
9
 
10
10
  // src/hooks/pre-commit.ts
@@ -13,27 +13,27 @@ import {
13
13
  failOpenOutput,
14
14
  observeDemoInvocation,
15
15
  readHookMode
16
- } from "../chunk-CTRAJCPN.js";
16
+ } from "../chunk-XV6C5ZV2.js";
17
17
  import {
18
18
  appendCodexContext,
19
19
  hasVisibleCodexMessage,
20
20
  prepareCodexContext
21
- } from "../chunk-AOJ254C2.js";
22
- import "../chunk-5BLGBSDM.js";
23
- import "../chunk-GA2RXPJL.js";
21
+ } from "../chunk-PJW6JZMH.js";
22
+ import "../chunk-JDIAPBY7.js";
23
+ import "../chunk-DWAXFXDG.js";
24
24
  import {
25
25
  DEFAULT_RULES,
26
26
  scrub
27
- } from "../chunk-KQ4WBK5R.js";
27
+ } from "../chunk-3KKEV7VI.js";
28
28
  import {
29
29
  boundedHealthError,
30
30
  cachedCollectScopeAdmits
31
- } from "../chunk-UDBBJWQH.js";
31
+ } from "../chunk-IZXLH3R5.js";
32
32
  import {
33
33
  HttpError,
34
34
  getClient,
35
35
  terminalSafeLine
36
- } from "../chunk-2IRLFOEL.js";
36
+ } from "../chunk-6JHKKLA2.js";
37
37
  import {
38
38
  normalizeEnvelope,
39
39
  parseAgent,
@@ -41,7 +41,7 @@ import {
41
41
  shouldSuppressImportedCursorHandler
42
42
  } from "../chunk-NH3VC7YO.js";
43
43
  import "../chunk-PO5QAYD7.js";
44
- import "../chunk-5LRKJTLA.js";
44
+ import "../chunk-J5HBSRAV.js";
45
45
  import {
46
46
  canonicalGitRoot,
47
47
  canonicalRepositoryPath,
@@ -58,7 +58,6 @@ var MAX_EXCERPT_CHARS = 80;
58
58
  var MAX_TITLE_CHARS = 140;
59
59
  var MAX_PATH_CHARS = 120;
60
60
  var MAX_VISIBLE_CONFLICTS = 3;
61
- var SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
62
61
  function displayText(value, maxChars) {
63
62
  const redacted = scrub(value, DEFAULT_RULES);
64
63
  const clean = terminalSafeLine(typeof redacted === "string" ? redacted : "");
@@ -86,7 +85,7 @@ Proposed replacement: \u201C${after}\u201D` : `Edit ${targets}.`;
86
85
  return `Change ${targets}.`;
87
86
  }
88
87
  function decisionLabel(conflict) {
89
- const id = typeof conflict.shortId === "string" && SAFE_ID.test(conflict.shortId) ? `dec_${conflict.shortId}` : typeof conflict.decisionId === "string" && SAFE_ID.test(conflict.decisionId) ? conflict.decisionId : "unknown";
88
+ const id = typeof conflict.shortId === "string" && /^[0-9a-f]{8}$/u.test(conflict.shortId) ? `dec_${conflict.shortId}` : typeof conflict.decisionId === "string" && /^dec_[0-9a-f]{8}$/u.test(conflict.decisionId) ? conflict.decisionId : "unknown";
90
89
  const title = typeof conflict.title === "string" ? displayText(conflict.title, MAX_TITLE_CHARS) : "";
91
90
  return title ? `Decision ${id}: \u201C${title}\u201D.` : `Decision ${id}: details unavailable; inspect it before approving.`;
92
91
  }
@@ -211,24 +210,47 @@ async function requestPreflight(request, signal = AbortSignal.timeout(PREFLIGHT_
211
210
  });
212
211
  return parsePreflightResponse(response);
213
212
  }
214
- function resultForPreflight(response, preview = "Review the requested change.") {
213
+ function proposedChangeExcerpt(proposal) {
214
+ try {
215
+ const input = JSON.parse(proposal);
216
+ if (input && typeof input === "object") {
217
+ for (const key of ["new_string", "new_str", "content", "command"]) {
218
+ if (typeof input[key] === "string") return boundedHealthError(input[key]);
219
+ }
220
+ }
221
+ } catch {
222
+ }
223
+ return boundedHealthError(proposal);
224
+ }
225
+ function resultForPreflight(response, preview = "Review the requested change.", invocation) {
215
226
  const verdict = response.verdict === "block" ? "deny" : response.verdict;
216
227
  const message = boundedHealthError(response.message) ?? "";
217
228
  const unavailable = message || boundedHealthError(response.reasonCode);
218
229
  const safe = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
219
230
  const directives = response.conflicts.flatMap((value) => {
220
231
  if (!value || typeof value !== "object") return [];
221
- const { decisionId, shortId } = value;
222
- const id = typeof shortId === "string" && safe.test(shortId) ? `dec_${shortId}` : typeof decisionId === "string" && safe.test(decisionId) ? decisionId : void 0;
232
+ const { decisionId, shortId, title } = value;
233
+ const id = typeof shortId === "string" && /^[0-9a-f]{8}$/u.test(shortId) ? `dec_${shortId}` : typeof decisionId === "string" && /^dec_[0-9a-f]{8}$/u.test(decisionId) ? decisionId : void 0;
223
234
  if (!id) return [];
224
235
  return [
225
- `To reconcile, run: prim reconcile ${id}`,
236
+ `Governing Decision ${id}${typeof title === "string" && boundedHealthError(title) ? `: ${boundedHealthError(title)}` : ""}.`,
226
237
  ...response.checkId && safe.test(response.checkId) ? [
227
- `Check: ${response.checkId}. After resolving, record the confirmed outcome: prim reconcile ${id} --check ${response.checkId} --outcome followed (retained Decision), or --outcome superseded (after replacing it). A bypass alone is not a resolution.`
238
+ `Check: ${response.checkId}. After resolving, record the confirmed outcome: prim reconcile ${id} --check ${response.checkId} --outcome followed (retained Decision), or --outcome superseded (after replacing it). Recording a resolution does not authorize an override.`
228
239
  ] : []
229
240
  ];
230
241
  });
231
- const guidance = [message, ...new Set(directives)].filter(Boolean).join("\n");
242
+ const blocked = response.verdict === "ask" || response.verdict === "block";
243
+ const proposal = invocation ? proposedChangeExcerpt(invocation.proposal) : void 0;
244
+ const editContext = blocked && invocation ? [
245
+ `Proposed edit to: ${invocation.paths.map((path) => boundedHealthError(path)).join(", ")}.`,
246
+ ...proposal ? [`Proposed change (excerpt): ${proposal}`] : []
247
+ ] : [];
248
+ const approvalContext = blocked ? [
249
+ "Overriding these Decisions requires explicit human approval naming each Decision and the proposed conflicting edit.",
250
+ "Reconcile bypasses are disabled: this host integration cannot provide verifiable human approval for a bypass. Keep the edit blocked and choose a compatible change.",
251
+ "Sandbox escalation, automatic review, prefix permissions, --yes, and an agent's assertion of approval do not authorize an override."
252
+ ] : [];
253
+ const guidance = [message, ...editContext, ...new Set(directives), ...approvalContext].filter(Boolean).join("\n");
232
254
  const reason = response.conflicts.length > 0 || response.verdict === "ask" || response.verdict === "block" ? approvalSummary(
233
255
  {
234
256
  conflicts: response.conflicts,
@@ -438,7 +460,8 @@ async function main() {
438
460
  }
439
461
  result = resultForPreflight(
440
462
  response,
441
- editPreview(toolName, envelope.tool_input, targets.paths)
463
+ editPreview(toolName, envelope.tool_input, targets.paths),
464
+ request
442
465
  );
443
466
  } catch (error) {
444
467
  await emitUnverified(preflightFailure(error), envelope);
@@ -8,7 +8,7 @@ import {
8
8
  acknowledgeDecisionFeedback,
9
9
  leaseDecisionFeedback,
10
10
  renderFeedback
11
- } from "../chunk-7VIMU2HR.js";
11
+ } from "../chunk-FTW4ZCBA.js";
12
12
  import {
13
13
  recordConversationCaptured
14
14
  } from "../chunk-KGBMU76T.js";
@@ -18,35 +18,35 @@ import {
18
18
  import {
19
19
  enrichHookPayloadWithFileRefs,
20
20
  preserveHookFileMetadata
21
- } from "../chunk-HTRFPXMD.js";
21
+ } from "../chunk-IW5HCCOW.js";
22
22
  import {
23
23
  postToolInvocationId,
24
24
  shouldFlushAfter,
25
25
  toMove
26
- } from "../chunk-43ZKL27W.js";
26
+ } from "../chunk-RTULPLS7.js";
27
27
  import {
28
28
  getOrCreateWorkspaceId
29
29
  } from "../chunk-EZXEWFDG.js";
30
30
  import {
31
31
  appendMove,
32
32
  resolveOrg
33
- } from "../chunk-JJI7FU24.js";
33
+ } from "../chunk-HMD5K6W7.js";
34
34
  import {
35
35
  observeDemoInvocation
36
- } from "../chunk-CTRAJCPN.js";
36
+ } from "../chunk-XV6C5ZV2.js";
37
37
  import {
38
38
  prepareCodexContext
39
- } from "../chunk-AOJ254C2.js";
40
- import "../chunk-5BLGBSDM.js";
41
- import "../chunk-GA2RXPJL.js";
39
+ } from "../chunk-PJW6JZMH.js";
40
+ import "../chunk-JDIAPBY7.js";
41
+ import "../chunk-DWAXFXDG.js";
42
42
  import {
43
43
  scrubFromCwd,
44
44
  writeHookDebug
45
- } from "../chunk-KQ4WBK5R.js";
45
+ } from "../chunk-3KKEV7VI.js";
46
46
  import {
47
47
  cachedCollectScopeAdmits
48
- } from "../chunk-UDBBJWQH.js";
49
- import "../chunk-2IRLFOEL.js";
48
+ } from "../chunk-IZXLH3R5.js";
49
+ import "../chunk-6JHKKLA2.js";
50
50
  import {
51
51
  normalizeEnvelope,
52
52
  parseAgent,
@@ -54,7 +54,7 @@ import {
54
54
  shouldSuppressImportedCursorHandler
55
55
  } from "../chunk-NH3VC7YO.js";
56
56
  import "../chunk-PO5QAYD7.js";
57
- import "../chunk-5LRKJTLA.js";
57
+ import "../chunk-J5HBSRAV.js";
58
58
  import {
59
59
  currentBranch,
60
60
  isRepoActiveForCapture,
@@ -8,7 +8,7 @@ import {
8
8
  import "../chunk-PO5QAYD7.js";
9
9
  import {
10
10
  daemonRequest
11
- } from "../chunk-5LRKJTLA.js";
11
+ } from "../chunk-J5HBSRAV.js";
12
12
  import {
13
13
  isRepoActiveForCapture
14
14
  } from "../chunk-XG7S3LIL.js";
@@ -7,7 +7,7 @@ import {
7
7
  kickDaemonEnsure,
8
8
  refreshClaudePlugins,
9
9
  warmBinCache
10
- } from "../chunk-IQZA65NV.js";
10
+ } from "../chunk-7DVEH7FO.js";
11
11
  import {
12
12
  buildHookOutput,
13
13
  handoffHookOutput
@@ -17,7 +17,7 @@ import {
17
17
  acknowledgeDecisionFeedback,
18
18
  leaseDecisionFeedback,
19
19
  renderFeedback
20
- } from "../chunk-7VIMU2HR.js";
20
+ } from "../chunk-FTW4ZCBA.js";
21
21
  import {
22
22
  clearHooksWired,
23
23
  recordHooksWired
@@ -28,15 +28,15 @@ import {
28
28
  } from "../chunk-EZXEWFDG.js";
29
29
  import {
30
30
  prepareCodexContext
31
- } from "../chunk-AOJ254C2.js";
32
- import "../chunk-GA2RXPJL.js";
31
+ } from "../chunk-PJW6JZMH.js";
32
+ import "../chunk-DWAXFXDG.js";
33
33
  import {
34
34
  fetchAndCacheCollectScope
35
- } from "../chunk-UDBBJWQH.js";
35
+ } from "../chunk-IZXLH3R5.js";
36
36
  import {
37
37
  getSiteUrl,
38
38
  isSessionEnded
39
- } from "../chunk-2IRLFOEL.js";
39
+ } from "../chunk-6JHKKLA2.js";
40
40
  import {
41
41
  normalizeEnvelope,
42
42
  parseAgent,
@@ -48,7 +48,7 @@ import {
48
48
  } from "../chunk-PO5QAYD7.js";
49
49
  import {
50
50
  daemonRequest
51
- } from "../chunk-5LRKJTLA.js";
51
+ } from "../chunk-J5HBSRAV.js";
52
52
  import {
53
53
  gitToplevel,
54
54
  isRepoActiveForCapture,