@primitive.ai/prim 0.1.0-alpha.112 → 0.1.0-alpha.114

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.
@@ -58239,34 +58239,10 @@ function registerMovesCommands(program3) {
58239
58239
  }
58240
58240
 
58241
58241
  // src/commands/reconcile.ts
58242
- var EXIT_OK4 = 0;
58243
58242
  var EXIT_USAGE2 = 2;
58244
58243
  var EXIT_SERVER = 3;
58245
58244
  var HTTP_CLIENT_ERROR_MIN = 400;
58246
58245
  var HTTP_SERVER_ERROR_MIN = 500;
58247
- function isOk(value) {
58248
- if (typeof value !== "object" || value === null) {
58249
- return false;
58250
- }
58251
- const v = value;
58252
- return v.ok === true && typeof v.bypassId === "string" && typeof v.expiresAt === "number";
58253
- }
58254
- function formatExpiresIn(expiresAt) {
58255
- const remainingMs = expiresAt - Date.now();
58256
- if (remainingMs <= 0) {
58257
- return "expired";
58258
- }
58259
- const SECONDS_PER_MINUTE = 60;
58260
- const minutes = Math.floor(remainingMs / (SECONDS_PER_MINUTE * 1e3));
58261
- const seconds = Math.floor(remainingMs / 1e3 % SECONDS_PER_MINUTE);
58262
- if (minutes === 0) {
58263
- return `${seconds}s`;
58264
- }
58265
- return `${minutes}m${seconds.toString().padStart(2, "0")}s`;
58266
- }
58267
- function renderDecisionIdentifier(short, id) {
58268
- return renderIdentifier({ id, shortId: short });
58269
- }
58270
58246
  function isDomainRejection(err) {
58271
58247
  return err instanceof HttpError && err.status >= HTTP_CLIENT_ERROR_MIN && err.status < HTTP_SERVER_ERROR_MIN;
58272
58248
  }
@@ -58275,48 +58251,23 @@ async function performReconcile(idOrShortId, opts = {}) {
58275
58251
  await performResolution(idOrShortId, opts);
58276
58252
  return;
58277
58253
  }
58278
- const client = getClient();
58279
- const body = { idOrShortId };
58280
- if (opts.flag) {
58281
- body.conflictFlagId = opts.flag;
58282
- }
58283
- let response;
58284
- try {
58285
- response = await client.post("/api/cli/reconcile/issue", body);
58286
- } catch (err) {
58287
- if (isDomainRejection(err)) {
58288
- process.stderr.write(`[prim] reconcile rejected: ${err.message}
58254
+ const message = "Overriding a governing Decision requires explicit human approval. This host cannot provide verifiable human approval, so reconcile bypasses are disabled. Keep the edit blocked and choose a compatible change.";
58255
+ process.stderr.write(`[prim] reconcile rejected: ${message}
58289
58256
  `);
58290
- console.log(JSON.stringify({ ok: false, status: err.status, error: err.message }, null, 2));
58291
- process.exitCode = EXIT_USAGE2;
58292
- return;
58293
- }
58294
- const message = err instanceof Error ? err.message : String(err);
58295
- process.stderr.write(`[prim] reconcile failed: ${message}
58296
- `);
58297
- console.log(JSON.stringify({ ok: false, error: message }, null, 2));
58298
- process.exitCode = EXIT_SERVER;
58299
- return;
58300
- }
58301
- if (isOk(response)) {
58302
- const ident = renderDecisionIdentifier(response.decisionShortId, response.decisionId);
58303
- const verb = response.reissued ? "reissued" : "issued";
58304
- process.stderr.write(
58305
- `[prim] reconcile bypass ${verb} for ${ident} (expires in ${formatExpiresIn(response.expiresAt)})
58306
- `
58307
- );
58308
- console.log(JSON.stringify(response, null, 2));
58309
- process.exitCode = EXIT_OK4;
58310
- return;
58311
- }
58312
- process.stderr.write("[prim] reconcile: malformed server response\n");
58313
- console.log(JSON.stringify({ ok: false, response }, null, 2));
58314
- process.exitCode = EXIT_SERVER;
58257
+ console.log(
58258
+ JSON.stringify({
58259
+ ok: false,
58260
+ error: "human_approval_required",
58261
+ decisionId: decisionIdentifier(idOrShortId),
58262
+ message
58263
+ })
58264
+ );
58265
+ process.exitCode = EXIT_USAGE2;
58315
58266
  }
58316
58267
  async function performResolution(idOrShortId, opts) {
58317
58268
  if (!opts.check || !["followed", "superseded"].includes(opts.outcome ?? "") || opts.flag) {
58318
58269
  process.stderr.write(
58319
- "[prim] resolution requires --check <checkId> and --outcome followed|superseded; --flag is for bypasses\n"
58270
+ "[prim] resolution requires --check <checkId> and --outcome followed|superseded; --flag is unsupported because bypasses are disabled\n"
58320
58271
  );
58321
58272
  console.log(JSON.stringify({ ok: false, error: "invalid_resolution_arguments" }));
58322
58273
  process.exitCode = EXIT_USAGE2;
@@ -58346,10 +58297,7 @@ async function performResolution(idOrShortId, opts) {
58346
58297
  }
58347
58298
  }
58348
58299
  function registerReconcileCommands(program3) {
58349
- program3.command("reconcile <idOrShortId>").description("Record a resolution or issue a single-use bypass for Conflict Gates Enforcement").option(
58350
- "--flag <conflictFlagId>",
58351
- "Specific flag id to bind the bypass to (default: the decision's latest unack'd flag)"
58352
- ).option("--check <checkId>", "Original conflict check to resolve; does not issue a bypass").option(
58300
+ program3.command("reconcile <idOrShortId>").description("Record a resolution for Conflict Gates Enforcement; bypasses are disabled").option("--flag <conflictFlagId>", "Legacy bypass flag (always rejected)").option("--check <checkId>", "Original conflict check to resolve; does not issue a bypass").option(
58353
58301
  "--outcome <outcome>",
58354
58302
  "Confirmed resolution: followed or superseded (requires --check)"
58355
58303
  ).option("--json", "(reserved; STDOUT is always JSON)").action(async (idOrShortId, opts) => {
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  enrichHookPayloadWithFileRefs,
7
7
  preserveHookFileMetadata
8
- } from "../chunk-IW5HCCOW.js";
8
+ } from "../chunk-IMYELJIV.js";
9
9
  import {
10
10
  postToolInvocationId,
11
11
  toMove,
@@ -20,7 +20,7 @@ import {
20
20
  } from "../chunk-HMD5K6W7.js";
21
21
  import {
22
22
  observeDemoInvocation
23
- } from "../chunk-XV6C5ZV2.js";
23
+ } from "../chunk-RUUSUF43.js";
24
24
  import {
25
25
  appendCodexContext,
26
26
  prepareCodexContext
@@ -13,7 +13,7 @@ import {
13
13
  failOpenOutput,
14
14
  observeDemoInvocation,
15
15
  readHookMode
16
- } from "../chunk-XV6C5ZV2.js";
16
+ } from "../chunk-RUUSUF43.js";
17
17
  import {
18
18
  appendCodexContext,
19
19
  hasVisibleCodexMessage,
@@ -174,6 +174,9 @@ function proposalFor(toolInput) {
174
174
  const redacted = scrub(toolInput, DEFAULT_RULES);
175
175
  return truncateUtf8(JSON.stringify(redacted) ?? "", MAX_PROPOSAL_BYTES);
176
176
  }
177
+ function proposalIsTruncated(toolInput) {
178
+ return Buffer.byteLength(JSON.stringify(scrub(toolInput, DEFAULT_RULES)) ?? "") > MAX_PROPOSAL_BYTES;
179
+ }
177
180
  function parsePreflightResponse(value) {
178
181
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
179
182
  const response = value;
@@ -210,24 +213,47 @@ async function requestPreflight(request, signal = AbortSignal.timeout(PREFLIGHT_
210
213
  });
211
214
  return parsePreflightResponse(response);
212
215
  }
213
- function resultForPreflight(response, preview = "Review the requested change.") {
216
+ function proposedChangeExcerpt(proposal) {
217
+ try {
218
+ const input = JSON.parse(proposal);
219
+ if (input && typeof input === "object") {
220
+ for (const key of ["new_string", "new_str", "content", "command"]) {
221
+ if (typeof input[key] === "string") return boundedHealthError(input[key]);
222
+ }
223
+ }
224
+ } catch {
225
+ }
226
+ return boundedHealthError(proposal);
227
+ }
228
+ function resultForPreflight(response, preview = "Review the requested change.", invocation, proposalTruncated = false) {
214
229
  const verdict = response.verdict === "block" ? "deny" : response.verdict;
215
230
  const message = boundedHealthError(response.message) ?? "";
216
231
  const unavailable = message || boundedHealthError(response.reasonCode);
217
232
  const safe = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
218
233
  const directives = response.conflicts.flatMap((value) => {
219
234
  if (!value || typeof value !== "object") return [];
220
- const { decisionId, shortId } = value;
235
+ const { decisionId, shortId, title } = value;
221
236
  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;
222
237
  if (!id) return [];
223
238
  return [
224
- `To reconcile, run: prim reconcile ${id}`,
239
+ `Governing Decision ${id}${typeof title === "string" && boundedHealthError(title) ? `: ${boundedHealthError(title)}` : ""}.`,
225
240
  ...response.checkId && safe.test(response.checkId) ? [
226
- `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.`
241
+ `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.`
227
242
  ] : []
228
243
  ];
229
244
  });
230
- const guidance = [message, ...new Set(directives)].filter(Boolean).join("\n");
245
+ const blocked = response.verdict === "ask" || response.verdict === "block";
246
+ const proposal = invocation ? proposedChangeExcerpt(invocation.proposal) : void 0;
247
+ const editContext = blocked && invocation ? [
248
+ `Proposed edit to: ${invocation.paths.map((path) => boundedHealthError(path)).join(", ")}.`,
249
+ ...proposal ? [`Proposed change (excerpt): ${proposal}`] : []
250
+ ] : [];
251
+ const approvalContext = blocked ? [
252
+ "Overriding these Decisions requires explicit human approval naming each Decision and the proposed conflicting edit.",
253
+ "Reconcile bypasses are disabled: this host integration cannot provide verifiable human approval for a bypass. Keep the edit blocked and choose a compatible change.",
254
+ "Sandbox escalation, automatic review, prefix permissions, --yes, and an agent's assertion of approval do not authorize an override."
255
+ ] : [];
256
+ const guidance = [message, ...editContext, ...new Set(directives), ...approvalContext].filter(Boolean).join("\n");
231
257
  const reason = response.conflicts.length > 0 || response.verdict === "ask" || response.verdict === "block" ? approvalSummary(
232
258
  {
233
259
  conflicts: response.conflicts,
@@ -238,12 +264,14 @@ function resultForPreflight(response, preview = "Review the requested change.")
238
264
  preview
239
265
  ) : message;
240
266
  const disclosureContext = decisionDisclosureContext(response);
267
+ const truncationNote = proposalTruncated ? "[primitive] shell proposal was truncated; the complete change was not verified" : "";
241
268
  return {
242
269
  verdict,
243
270
  conflicts: response.conflicts,
244
- reason,
271
+ reason: [reason, truncationNote].filter(Boolean).join("\n"),
245
272
  additionalContext: [
246
273
  disclosureContext,
274
+ truncationNote,
247
275
  ["warn", "ask", "block"].includes(response.verdict) ? guidance : ""
248
276
  ].filter(Boolean).join("\n"),
249
277
  truncated: false,
@@ -264,6 +292,7 @@ function unverifiedResult(message) {
264
292
  // src/hooks/pre-tool-use.ts
265
293
  var STDIN_TIMEOUT_MS = 1e3;
266
294
  var agent = parseAgent(process.argv);
295
+ var uncheckedMutation;
267
296
  async function emit(output) {
268
297
  return await new Promise((resolve) => {
269
298
  try {
@@ -389,8 +418,12 @@ async function main() {
389
418
  await emit(failOpen());
390
419
  return;
391
420
  }
421
+ uncheckedMutation = envelope;
392
422
  if (targets.paths.length === 0 && !targets.definite) {
393
- await emit(failOpen());
423
+ await emitUnverified(
424
+ "shell command write targets could not be determined; change was not verified",
425
+ envelope
426
+ );
394
427
  return;
395
428
  }
396
429
  if (agent === "cursor" && targets.coverage === "unverified") {
@@ -437,7 +470,9 @@ async function main() {
437
470
  }
438
471
  result = resultForPreflight(
439
472
  response,
440
- editPreview(toolName, envelope.tool_input, targets.paths)
473
+ editPreview(toolName, envelope.tool_input, targets.paths),
474
+ request,
475
+ collectScopeAdmits && (toolName === "Bash" || toolName === "Shell") && proposalIsTruncated(envelope.tool_input)
441
476
  );
442
477
  } catch (error) {
443
478
  await emitUnverified(preflightFailure(error), envelope);
@@ -465,5 +500,10 @@ async function main() {
465
500
  await emit(output);
466
501
  }
467
502
  main().catch(async () => {
468
- await emit(failOpen());
503
+ if (uncheckedMutation)
504
+ await emitUnverified(
505
+ "hook failed while checking a possible write; change was not verified",
506
+ uncheckedMutation
507
+ );
508
+ else await emit(failOpen());
469
509
  });
@@ -18,7 +18,7 @@ import {
18
18
  import {
19
19
  enrichHookPayloadWithFileRefs,
20
20
  preserveHookFileMetadata
21
- } from "../chunk-IW5HCCOW.js";
21
+ } from "../chunk-IMYELJIV.js";
22
22
  import {
23
23
  postToolInvocationId,
24
24
  shouldFlushAfter,
@@ -33,7 +33,7 @@ import {
33
33
  } from "../chunk-HMD5K6W7.js";
34
34
  import {
35
35
  observeDemoInvocation
36
- } from "../chunk-XV6C5ZV2.js";
36
+ } from "../chunk-RUUSUF43.js";
37
37
  import {
38
38
  prepareCodexContext
39
39
  } from "../chunk-PJW6JZMH.js";
package/dist/index.js CHANGED
@@ -9536,34 +9536,10 @@ function registerMovesCommands(program2) {
9536
9536
  }
9537
9537
 
9538
9538
  // src/commands/reconcile.ts
9539
- var EXIT_OK4 = 0;
9540
9539
  var EXIT_USAGE2 = 2;
9541
9540
  var EXIT_SERVER = 3;
9542
9541
  var HTTP_CLIENT_ERROR_MIN = 400;
9543
9542
  var HTTP_SERVER_ERROR_MIN = 500;
9544
- function isOk(value) {
9545
- if (typeof value !== "object" || value === null) {
9546
- return false;
9547
- }
9548
- const v = value;
9549
- return v.ok === true && typeof v.bypassId === "string" && typeof v.expiresAt === "number";
9550
- }
9551
- function formatExpiresIn(expiresAt) {
9552
- const remainingMs = expiresAt - Date.now();
9553
- if (remainingMs <= 0) {
9554
- return "expired";
9555
- }
9556
- const SECONDS_PER_MINUTE = 60;
9557
- const minutes = Math.floor(remainingMs / (SECONDS_PER_MINUTE * 1e3));
9558
- const seconds = Math.floor(remainingMs / 1e3 % SECONDS_PER_MINUTE);
9559
- if (minutes === 0) {
9560
- return `${seconds}s`;
9561
- }
9562
- return `${minutes}m${seconds.toString().padStart(2, "0")}s`;
9563
- }
9564
- function renderDecisionIdentifier(short, id) {
9565
- return renderIdentifier({ id, shortId: short });
9566
- }
9567
9543
  function isDomainRejection(err) {
9568
9544
  return err instanceof HttpError && err.status >= HTTP_CLIENT_ERROR_MIN && err.status < HTTP_SERVER_ERROR_MIN;
9569
9545
  }
@@ -9572,48 +9548,23 @@ async function performReconcile(idOrShortId, opts = {}) {
9572
9548
  await performResolution(idOrShortId, opts);
9573
9549
  return;
9574
9550
  }
9575
- const client = getClient();
9576
- const body = { idOrShortId };
9577
- if (opts.flag) {
9578
- body.conflictFlagId = opts.flag;
9579
- }
9580
- let response;
9581
- try {
9582
- response = await client.post("/api/cli/reconcile/issue", body);
9583
- } catch (err) {
9584
- if (isDomainRejection(err)) {
9585
- process.stderr.write(`[prim] reconcile rejected: ${err.message}
9551
+ const message = "Overriding a governing Decision requires explicit human approval. This host cannot provide verifiable human approval, so reconcile bypasses are disabled. Keep the edit blocked and choose a compatible change.";
9552
+ process.stderr.write(`[prim] reconcile rejected: ${message}
9586
9553
  `);
9587
- console.log(JSON.stringify({ ok: false, status: err.status, error: err.message }, null, 2));
9588
- process.exitCode = EXIT_USAGE2;
9589
- return;
9590
- }
9591
- const message = err instanceof Error ? err.message : String(err);
9592
- process.stderr.write(`[prim] reconcile failed: ${message}
9593
- `);
9594
- console.log(JSON.stringify({ ok: false, error: message }, null, 2));
9595
- process.exitCode = EXIT_SERVER;
9596
- return;
9597
- }
9598
- if (isOk(response)) {
9599
- const ident = renderDecisionIdentifier(response.decisionShortId, response.decisionId);
9600
- const verb = response.reissued ? "reissued" : "issued";
9601
- process.stderr.write(
9602
- `[prim] reconcile bypass ${verb} for ${ident} (expires in ${formatExpiresIn(response.expiresAt)})
9603
- `
9604
- );
9605
- console.log(JSON.stringify(response, null, 2));
9606
- process.exitCode = EXIT_OK4;
9607
- return;
9608
- }
9609
- process.stderr.write("[prim] reconcile: malformed server response\n");
9610
- console.log(JSON.stringify({ ok: false, response }, null, 2));
9611
- process.exitCode = EXIT_SERVER;
9554
+ console.log(
9555
+ JSON.stringify({
9556
+ ok: false,
9557
+ error: "human_approval_required",
9558
+ decisionId: decisionIdentifier(idOrShortId),
9559
+ message
9560
+ })
9561
+ );
9562
+ process.exitCode = EXIT_USAGE2;
9612
9563
  }
9613
9564
  async function performResolution(idOrShortId, opts) {
9614
9565
  if (!opts.check || !["followed", "superseded"].includes(opts.outcome ?? "") || opts.flag) {
9615
9566
  process.stderr.write(
9616
- "[prim] resolution requires --check <checkId> and --outcome followed|superseded; --flag is for bypasses\n"
9567
+ "[prim] resolution requires --check <checkId> and --outcome followed|superseded; --flag is unsupported because bypasses are disabled\n"
9617
9568
  );
9618
9569
  console.log(JSON.stringify({ ok: false, error: "invalid_resolution_arguments" }));
9619
9570
  process.exitCode = EXIT_USAGE2;
@@ -9643,10 +9594,7 @@ async function performResolution(idOrShortId, opts) {
9643
9594
  }
9644
9595
  }
9645
9596
  function registerReconcileCommands(program2) {
9646
- program2.command("reconcile <idOrShortId>").description("Record a resolution or issue a single-use bypass for Conflict Gates Enforcement").option(
9647
- "--flag <conflictFlagId>",
9648
- "Specific flag id to bind the bypass to (default: the decision's latest unack'd flag)"
9649
- ).option("--check <checkId>", "Original conflict check to resolve; does not issue a bypass").option(
9597
+ program2.command("reconcile <idOrShortId>").description("Record a resolution for Conflict Gates Enforcement; bypasses are disabled").option("--flag <conflictFlagId>", "Legacy bypass flag (always rejected)").option("--check <checkId>", "Original conflict check to resolve; does not issue a bypass").option(
9650
9598
  "--outcome <outcome>",
9651
9599
  "Confirmed resolution: followed or superseded (requires --check)"
9652
9600
  ).option("--json", "(reserved; STDOUT is always JSON)").action(async (idOrShortId, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primitive.ai/prim",
3
- "version": "0.1.0-alpha.112",
3
+ "version": "0.1.0-alpha.114",
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",
@@ -62,11 +62,16 @@
62
62
  "format": "biome check --fix src/ scripts/",
63
63
  "format:check": "biome check src/ scripts/",
64
64
  "typecheck": "tsc --noEmit",
65
+ "check:reconcile-golden": "node scripts/check-reconcile-golden.mjs",
65
66
  "test": "vitest run",
66
67
  "test:watch": "vitest",
67
- "test:coverage": "vitest run --coverage"
68
+ "test:coverage": "vitest run --coverage",
69
+ "check:shell-targets-golden": "node scripts/check-shell-targets-golden.mjs"
68
70
  },
69
71
  "dependencies": {
72
+ "@lezer/common": "^1.5.4",
73
+ "@lezer/javascript": "^1.5.6",
74
+ "@lezer/python": "^1.1.19",
70
75
  "commander": "^12.1.0",
71
76
  "diff": "^5.2.0",
72
77
  "unbash": "4.0.3",