@primitive.ai/prim 0.1.0-alpha.109 → 0.1.0-alpha.110

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.
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  commitAttributionFromEnvironment,
10
10
  toCommitMove
11
- } from "../chunk-AIAYIXBJ.js";
11
+ } from "../chunk-43ZKL27W.js";
12
12
  import {
13
13
  getOrCreateWorkspaceId
14
14
  } from "../chunk-EZXEWFDG.js";
@@ -16,10 +16,10 @@ import {
16
16
  appendMove,
17
17
  resolveOrg
18
18
  } from "../chunk-JJI7FU24.js";
19
- import "../chunk-YQFJUBNU.js";
19
+ import "../chunk-KQ4WBK5R.js";
20
20
  import {
21
21
  cachedCollectScopeAdmits
22
- } from "../chunk-GFJ4QIVR.js";
22
+ } from "../chunk-UDBBJWQH.js";
23
23
  import "../chunk-2IRLFOEL.js";
24
24
  import {
25
25
  githubRepositoryFullName,
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  canonicalRewritePairs,
7
7
  toRewriteMove
8
- } from "../chunk-AIAYIXBJ.js";
8
+ } from "../chunk-43ZKL27W.js";
9
9
  import {
10
10
  getOrCreateWorkspaceId
11
11
  } from "../chunk-EZXEWFDG.js";
@@ -13,10 +13,10 @@ import {
13
13
  appendMove,
14
14
  resolveOrg
15
15
  } from "../chunk-JJI7FU24.js";
16
- import "../chunk-YQFJUBNU.js";
16
+ import "../chunk-KQ4WBK5R.js";
17
17
  import {
18
18
  cachedCollectScopeAdmits
19
- } from "../chunk-GFJ4QIVR.js";
19
+ } from "../chunk-UDBBJWQH.js";
20
20
  import "../chunk-2IRLFOEL.js";
21
21
  import {
22
22
  githubRepositoryFullName,
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  requireDurableIngestAcknowledgement
4
- } from "../chunk-EQYIPUFX.js";
4
+ } from "../chunk-W4ZEPZLK.js";
5
5
  import {
6
6
  enrichHookPayloadWithFileRefs,
7
7
  preserveHookFileMetadata
8
- } from "../chunk-FDXDV2AT.js";
8
+ } from "../chunk-HTRFPXMD.js";
9
9
  import {
10
10
  postToolInvocationId,
11
11
  toMove,
12
12
  toolOutcomeFor
13
- } from "../chunk-AIAYIXBJ.js";
13
+ } from "../chunk-43ZKL27W.js";
14
14
  import {
15
15
  getOrCreateWorkspaceId
16
16
  } from "../chunk-EZXEWFDG.js";
@@ -20,21 +20,21 @@ import {
20
20
  } from "../chunk-JJI7FU24.js";
21
21
  import {
22
22
  observeDemoInvocation
23
- } from "../chunk-D24AUSVP.js";
23
+ } from "../chunk-CTRAJCPN.js";
24
24
  import {
25
25
  appendCodexContext,
26
26
  prepareCodexContext
27
- } from "../chunk-QJOK2VOE.js";
28
- import "../chunk-LFZYNNQQ.js";
29
- import "../chunk-RXD6LFA2.js";
27
+ } from "../chunk-AOJ254C2.js";
28
+ import "../chunk-5BLGBSDM.js";
29
+ import "../chunk-GA2RXPJL.js";
30
30
  import {
31
31
  scrubFromCwd
32
- } from "../chunk-YQFJUBNU.js";
32
+ } from "../chunk-KQ4WBK5R.js";
33
33
  import {
34
34
  bold,
35
35
  cachedCollectScopeAdmits,
36
36
  color
37
- } from "../chunk-GFJ4QIVR.js";
37
+ } from "../chunk-UDBBJWQH.js";
38
38
  import {
39
39
  getClient,
40
40
  terminalSafeLine
@@ -13,25 +13,26 @@ import {
13
13
  failOpenOutput,
14
14
  observeDemoInvocation,
15
15
  readHookMode
16
- } from "../chunk-D24AUSVP.js";
16
+ } from "../chunk-CTRAJCPN.js";
17
17
  import {
18
18
  appendCodexContext,
19
19
  hasVisibleCodexMessage,
20
20
  prepareCodexContext
21
- } from "../chunk-QJOK2VOE.js";
22
- import "../chunk-LFZYNNQQ.js";
23
- import "../chunk-RXD6LFA2.js";
21
+ } from "../chunk-AOJ254C2.js";
22
+ import "../chunk-5BLGBSDM.js";
23
+ import "../chunk-GA2RXPJL.js";
24
24
  import {
25
25
  DEFAULT_RULES,
26
26
  scrub
27
- } from "../chunk-YQFJUBNU.js";
27
+ } from "../chunk-KQ4WBK5R.js";
28
28
  import {
29
29
  boundedHealthError,
30
30
  cachedCollectScopeAdmits
31
- } from "../chunk-GFJ4QIVR.js";
31
+ } from "../chunk-UDBBJWQH.js";
32
32
  import {
33
33
  HttpError,
34
- getClient
34
+ getClient,
35
+ terminalSafeLine
35
36
  } from "../chunk-2IRLFOEL.js";
36
37
  import {
37
38
  normalizeEnvelope,
@@ -52,6 +53,67 @@ import {
52
53
  resolveAuthCredential
53
54
  } from "../chunk-XG7S3LIL.js";
54
55
 
56
+ // src/hooks/approval-copy.ts
57
+ var MAX_EXCERPT_CHARS = 80;
58
+ var MAX_TITLE_CHARS = 140;
59
+ var MAX_PATH_CHARS = 120;
60
+ var MAX_VISIBLE_CONFLICTS = 3;
61
+ var SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
62
+ function displayText(value, maxChars) {
63
+ const redacted = scrub(value, DEFAULT_RULES);
64
+ const clean = terminalSafeLine(typeof redacted === "string" ? redacted : "");
65
+ const characters = Array.from(clean);
66
+ return characters.length > maxChars ? `${characters.slice(0, maxChars - 1).join("")}\u2026` : clean;
67
+ }
68
+ function targetLabel(paths) {
69
+ const shown = paths.slice(0, 2).map((path) => `\u201C${displayText(path, MAX_PATH_CHARS)}\u201D`);
70
+ if (shown.length === 0) return "the requested change";
71
+ const remaining = paths.length - shown.length;
72
+ return `${shown.join(" and ")}${remaining > 0 ? ` and ${remaining} more file(s)` : ""}`;
73
+ }
74
+ function editPreview(toolName, toolInput, paths) {
75
+ const input = toolInput && typeof toolInput === "object" ? toolInput : {};
76
+ const targets = targetLabel(paths);
77
+ if (toolName === "Edit") {
78
+ const before = typeof input.old_string === "string" ? displayText(input.old_string, MAX_EXCERPT_CHARS) : "";
79
+ const after = typeof input.new_string === "string" ? displayText(input.new_string, MAX_EXCERPT_CHARS) : "";
80
+ return before && after ? `Edit ${targets}:
81
+ Current text: \u201C${before}\u201D
82
+ Proposed replacement: \u201C${after}\u201D` : `Edit ${targets}.`;
83
+ }
84
+ if (toolName === "Write" || toolName === "NotebookEdit") return `Write ${targets}.`;
85
+ if (toolName === "Bash" || toolName === "Shell") return `Run a command affecting ${targets}.`;
86
+ return `Change ${targets}.`;
87
+ }
88
+ 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";
90
+ const title = typeof conflict.title === "string" ? displayText(conflict.title, MAX_TITLE_CHARS) : "";
91
+ return title ? `Decision ${id}: \u201C${title}\u201D.` : `Decision ${id}: details unavailable; inspect it before approving.`;
92
+ }
93
+ function incomplete(evidence) {
94
+ const coverage = evidence.evaluationCoverage;
95
+ return Array.isArray(coverage?.selectionOmissions) && coverage.selectionOmissions.length > 0 || Array.isArray(coverage?.evidenceOmissions) && coverage.evidenceOmissions.length > 0 || coverage?.status !== void 0 && coverage.status !== "completed" || ["candidate_set_truncated", "evidence_incomplete", "coverage_unverified"].includes(
96
+ evidence.reasonCode
97
+ );
98
+ }
99
+ function approvalSummary(evidence, preview) {
100
+ const lines = [preview];
101
+ if (evidence.conflicts.length > 0) {
102
+ lines.push("Primitive found a conflict with an existing decision.");
103
+ lines.push(...evidence.conflicts.slice(0, MAX_VISIBLE_CONFLICTS).map(decisionLabel));
104
+ const remaining = evidence.conflicts.length - MAX_VISIBLE_CONFLICTS;
105
+ if (remaining > 0) lines.push(`${remaining} more conflicting decision(s) need inspection.`);
106
+ } else {
107
+ lines.push(
108
+ displayText(evidence.message || "Primitive requires review before this change.", 180)
109
+ );
110
+ }
111
+ if (incomplete(evidence)) {
112
+ lines.push("Some potentially applicable decisions were not fully checked.");
113
+ }
114
+ return lines.filter(Boolean).join("\n");
115
+ }
116
+
55
117
  // src/hooks/preflight-v3.ts
56
118
  import { Buffer } from "buffer";
57
119
  var PREFLIGHT_PROTOCOL_VERSION = 3;
@@ -149,7 +211,7 @@ async function requestPreflight(request, signal = AbortSignal.timeout(PREFLIGHT_
149
211
  });
150
212
  return parsePreflightResponse(response);
151
213
  }
152
- function resultForPreflight(response) {
214
+ function resultForPreflight(response, preview = "Review the requested change.") {
153
215
  const verdict = response.verdict === "block" ? "deny" : response.verdict;
154
216
  const message = boundedHealthError(response.message) ?? "";
155
217
  const unavailable = message || boundedHealthError(response.reasonCode);
@@ -166,7 +228,16 @@ function resultForPreflight(response) {
166
228
  ] : []
167
229
  ];
168
230
  });
169
- const reason = [message, ...new Set(directives)].filter(Boolean).join("\n");
231
+ const guidance = [message, ...new Set(directives)].filter(Boolean).join("\n");
232
+ const reason = response.conflicts.length > 0 || response.verdict === "ask" || response.verdict === "block" ? approvalSummary(
233
+ {
234
+ conflicts: response.conflicts,
235
+ message,
236
+ reasonCode: response.reasonCode,
237
+ evaluationCoverage: response.evaluationCoverage
238
+ },
239
+ preview
240
+ ) : message;
170
241
  const disclosureContext = decisionDisclosureContext(response);
171
242
  return {
172
243
  verdict,
@@ -174,7 +245,7 @@ function resultForPreflight(response) {
174
245
  reason,
175
246
  additionalContext: [
176
247
  disclosureContext,
177
- ["warn", "ask", "block"].includes(response.verdict) ? reason : ""
248
+ ["warn", "ask", "block"].includes(response.verdict) ? guidance : ""
178
249
  ].filter(Boolean).join("\n"),
179
250
  truncated: false,
180
251
  unavailable: response.verdict === "unavailable" ? unavailable : void 0
@@ -365,7 +436,10 @@ async function main() {
365
436
  await emitUnverified("enforcement service returned an incompatible response", envelope);
366
437
  return;
367
438
  }
368
- result = resultForPreflight(response);
439
+ result = resultForPreflight(
440
+ response,
441
+ editPreview(toolName, envelope.tool_input, targets.paths)
442
+ );
369
443
  } catch (error) {
370
444
  await emitUnverified(preflightFailure(error), envelope);
371
445
  return;
@@ -18,12 +18,12 @@ import {
18
18
  import {
19
19
  enrichHookPayloadWithFileRefs,
20
20
  preserveHookFileMetadata
21
- } from "../chunk-FDXDV2AT.js";
21
+ } from "../chunk-HTRFPXMD.js";
22
22
  import {
23
23
  postToolInvocationId,
24
24
  shouldFlushAfter,
25
25
  toMove
26
- } from "../chunk-AIAYIXBJ.js";
26
+ } from "../chunk-43ZKL27W.js";
27
27
  import {
28
28
  getOrCreateWorkspaceId
29
29
  } from "../chunk-EZXEWFDG.js";
@@ -33,19 +33,19 @@ import {
33
33
  } from "../chunk-JJI7FU24.js";
34
34
  import {
35
35
  observeDemoInvocation
36
- } from "../chunk-D24AUSVP.js";
36
+ } from "../chunk-CTRAJCPN.js";
37
37
  import {
38
38
  prepareCodexContext
39
- } from "../chunk-QJOK2VOE.js";
40
- import "../chunk-LFZYNNQQ.js";
41
- import "../chunk-RXD6LFA2.js";
39
+ } from "../chunk-AOJ254C2.js";
40
+ import "../chunk-5BLGBSDM.js";
41
+ import "../chunk-GA2RXPJL.js";
42
42
  import {
43
43
  scrubFromCwd,
44
44
  writeHookDebug
45
- } from "../chunk-YQFJUBNU.js";
45
+ } from "../chunk-KQ4WBK5R.js";
46
46
  import {
47
47
  cachedCollectScopeAdmits
48
- } from "../chunk-GFJ4QIVR.js";
48
+ } from "../chunk-UDBBJWQH.js";
49
49
  import "../chunk-2IRLFOEL.js";
50
50
  import {
51
51
  normalizeEnvelope,
@@ -28,11 +28,11 @@ import {
28
28
  } from "../chunk-EZXEWFDG.js";
29
29
  import {
30
30
  prepareCodexContext
31
- } from "../chunk-QJOK2VOE.js";
32
- import "../chunk-RXD6LFA2.js";
31
+ } from "../chunk-AOJ254C2.js";
32
+ import "../chunk-GA2RXPJL.js";
33
33
  import {
34
34
  fetchAndCacheCollectScope
35
- } from "../chunk-GFJ4QIVR.js";
35
+ } from "../chunk-UDBBJWQH.js";
36
36
  import {
37
37
  getSiteUrl,
38
38
  isSessionEnded
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-IQZA65NV.js";
23
23
  import {
24
24
  requireDurableIngestAcknowledgement
25
- } from "./chunk-EQYIPUFX.js";
25
+ } from "./chunk-W4ZEPZLK.js";
26
26
  import {
27
27
  checkAffectedDecisions,
28
28
  daemonOrDirectGet,
@@ -75,7 +75,7 @@ import {
75
75
  readDemoJson,
76
76
  readRun,
77
77
  saveRun
78
- } from "./chunk-LFZYNNQQ.js";
78
+ } from "./chunk-5BLGBSDM.js";
79
79
  import {
80
80
  MS_PER_SECOND,
81
81
  deliveryBacklogState,
@@ -84,7 +84,7 @@ import {
84
84
  formatStatusline,
85
85
  formatTeammates,
86
86
  repositoryBindingDiagnosticLabel
87
- } from "./chunk-RXD6LFA2.js";
87
+ } from "./chunk-GA2RXPJL.js";
88
88
  import {
89
89
  bold,
90
90
  boundedHealthError,
@@ -109,7 +109,7 @@ import {
109
109
  isMoveIngestRequest,
110
110
  isReconcileResolutionResponse,
111
111
  stripAnsi
112
- } from "./chunk-GFJ4QIVR.js";
112
+ } from "./chunk-UDBBJWQH.js";
113
113
  import {
114
114
  CliManagementResponseError,
115
115
  HttpError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primitive.ai/prim",
3
- "version": "0.1.0-alpha.109",
3
+ "version": "0.1.0-alpha.110",
4
4
  "description": "CLI for Primitive's decision graph — passive decision capture, conflict gate, and team presence",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -52,6 +52,7 @@
52
52
  "contracts:generate": "node scripts/generate-cli-contract.mjs --write",
53
53
  "contracts:check": "node scripts/generate-cli-contract.mjs --check",
54
54
  "contracts:provenance": "node scripts/update-cli-contract.mjs --check",
55
+ "check:approval-copy-golden": "node scripts/check-approval-copy-golden.mjs",
55
56
  "contracts:update": "node scripts/update-cli-contract.mjs",
56
57
  "postbuild": "chmod +x ./dist/index.js ./dist/statusline-main.js ./dist/hooks/pre-commit.js ./dist/hooks/post-commit.js ./dist/hooks/post-rewrite.js ./dist/hooks/prim-hook.js ./dist/hooks/pre-tool-use.js ./dist/hooks/post-tool-use.js ./dist/hooks/session-start.js ./dist/hooks/session-end.js ./dist/daemon/server.js && node scripts/check-hook-runtime.mjs",
57
58
  "dev": "tsup src/index.ts src/statusline-main.ts src/hooks/pre-commit.ts src/hooks/post-commit.ts src/hooks/post-rewrite.ts src/hooks/prim-hook.ts src/hooks/pre-tool-use.ts src/hooks/post-tool-use.ts src/hooks/session-start.ts src/hooks/session-end.ts src/daemon/server.ts --format esm --watch --clean --splitting false",