@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
package/README.md CHANGED
@@ -13,24 +13,26 @@ presence — from the command line and via session + git hooks.
13
13
  > organization, gates can warn, pause, or block a conflicting edit until you resolve
14
14
  > the decision and retry. Automatic decision capture in active repositories is separate.
15
15
 
16
- When Enforcement is enabled, the V4 gate waits for complete Decision coverage.
17
- It polls for up to 240 seconds, limits individual requests to 10 seconds, and
18
- pauses the tool on incomplete evaluation or service failure, including in warn
19
- mode. A paused response includes a check ID:
16
+ When Enforcement is enabled, automatic V4 checks wait at most **two seconds**.
17
+ Confirmed conflicts found in that window retain the existing review/warning
18
+ behavior. Otherwise work proceeds silently, including on timeout, incomplete
19
+ coverage, authentication problems, or service failure. Admitted evaluations
20
+ continue in the backend for internal review; later results cannot stop or undo
21
+ an edit and do not send a user notification.
22
+
23
+ Explicit inspection and recovery retain their longer wait:
20
24
 
21
25
  ```bash
22
26
  prim decisions preflight status <checkId>
23
- prim decisions preflight resume <checkId> # Finish evaluation, then retry the tool
27
+ prim decisions preflight resume <checkId>
24
28
  ```
25
29
 
26
- The backend must support V4 before this CLI is rolled out. There is no V3 fallback.
27
- Re-run `prim <agent> install` and `prim doctor` to repair the 300-second hook timeout
28
- and check host failure protection. Claude needs 2.1.295+ (`onFailure: "block"`),
29
- Cursor uses the verified 3.24.9+ baseline (`failClosed: true`), and Hermes needs
30
- `fail_closed` shell-hook support. Codex supports explicit deny but does not
31
- provide a documented fail-closed policy for a hook crash, kill, or host timeout;
32
- Primitive cannot guarantee that host failure boundary. Reload/restart and trust
33
- the updated hooks as directed by the installer.
30
+ There is no V3 fallback. Re-run `prim <agent> install` and `prim doctor` to repair
31
+ the two-second hook timeout and fail-open settings. Claude uses its default
32
+ failure behavior, Cursor uses `failClosed: false`, and Hermes uses
33
+ `fail_closed: false`. Codex also permits the action if the hook fails. Reload or
34
+ restart the host as directed by the installer. Older installations retain their
35
+ blocking behavior until upgraded and repaired.
34
36
 
35
37
  ## Installation
36
38
 
@@ -583,18 +585,16 @@ They never install or upgrade the host or change your host settings.
583
585
 
584
586
  ```bash
585
587
  pnpm test:preflight-host # Installed Codex
586
- pnpm test:preflight-host:claude # Claude 2.1.295+ on PATH
588
+ pnpm test:preflight-host:claude # Claude 2.1.284+ on PATH
587
589
  pnpm test:preflight-host:claude --binary /path/to/compatible/claude
588
590
  # CLI_CLAUDE_BIN also selects the Claude binary.
589
591
  ```
590
592
 
591
- Each check covers completed allow, paused evaluation in warn mode, malformed
592
- backend JSON, CLI deadline expiry, hook crash, and host watchdog expiry. Deadline
593
- expiry uses an accelerated remaining 240-second budget; the watchdog uses a
594
- one-second timeout. These checks do not wait 240/300 seconds. Claude's
595
- `onFailure: "block"` blocks the crash and watchdog cases. The Codex check records
596
- its current limitation by expecting execution in those two cases; explicit CLI
597
- denials still block. Unsupported Claude versions fail before the fixture runs.
593
+ Each check covers completed allow, confirmed conflict, paused evaluation, malformed
594
+ backend JSON, CLI deadline expiry, hook crash, and host watchdog expiry. Only the
595
+ confirmed conflict prevents the sentinel write. The hook budget and watchdog are
596
+ two seconds; no fixture waits minutes. Unsupported Claude versions fail before
597
+ the fixture runs.
598
598
  The separate `pnpm test:preflight-v4 --schema /path/to/cli-http-v1.schema.json`
599
599
  check validates the built CLI against a supplied authoritative backend contract.
600
600
 
package/SKILL.md CHANGED
@@ -40,11 +40,11 @@ When Enforcement is enabled, before an edit (Claude Code: Edit/Write/MultiEdit;
40
40
 
41
41
  - **deny** -- the edit is blocked. Name each governing Decision and the proposed conflicting edit. Overriding a Decision requires explicit human approval for that specific override. Reconcile bypasses are disabled until a host can provide verifiable human approval; keep the edit blocked and choose a compatible approach.
42
42
  - **warn / additional context** -- the edit proceeds, but a relevant prior decision is surfaced. Read it. Cursor, Codex, and Hermes map a would-be `ask` to **deny**. Do not change gate settings, use sandbox escalation, or request prefix permissions to evade the block. Automatic approval review, `--yes`, and an agent assertion are not human approval.
43
- - **"Operation paused"** -- the check has not covered every eligible Decision. The tool is denied, including in warn mode. Use the supplied `prim decisions preflight resume <checkId>` command, then retry the tool call. `prim decisions preflight status <checkId>` inspects progress without restarting it.
43
+ - **No confirmed conflict within two seconds** -- work proceeds silently. Incomplete checks and service failures do not deny the tool or add a notice. Already admitted evaluations continue for internal review; later findings do not stop or undo that edit.
44
44
 
45
- When enabled, the V4 gate polls durable evaluation for up to 240 seconds, with each request bounded to 10 seconds. Incomplete coverage, network/auth failures, malformed responses, and expired checks pause the tool operation. Completed checks retain normal block/warn policy. The full tool input is hashed before the proposal is redacted and truncated, so a changed retry cannot reuse another proposal’s evaluation. The backend must support V4; the CLI never falls back to V3.
45
+ The two-second automatic budget includes local preparation, authentication, and network requests. A confirmed conflict can retain normal block/warn policy while other Decisions are still being evaluated; partial coverage remains explicit in the receipt. The full tool input is hashed before redaction and truncation. The CLI never falls back to V3. Explicit `prim decisions preflight status <checkId>` and `resume <checkId>` remain available for internal inspection and recovery with the longer manual budget.
46
46
 
47
- Run `prim <agent> install` to repair the 300-second hook timeout and host failure policy, then `prim doctor`. Claude requires 2.1.295+ (`onFailure: "block"`); Cursor requires the verified 3.24.9+ baseline (`failClosed: true`); Hermes requires installed `fail_closed` support. Codex honors an explicit deny but has no documented fail-closed policy for a crashed, killed, or host-timed-out hook; doctor reports that limitation. Restart or refresh the host as directed after changing hook settings.
47
+ Run `prim <agent> install` to repair the two-second hook timeout and fail-open settings, then `prim doctor`. Claude uses its default failure behavior; Cursor uses `failClosed: false`; Hermes uses `fail_closed: false`. Codex also permits tools on hook failure. Restart or refresh the host as directed. Older CLI installations retain blocking behavior until upgraded and repaired.
48
48
 
49
49
  ## Read the graph before large or load-bearing edits
50
50
 
@@ -3,7 +3,7 @@ import {
3
3
  isTerminalSafeText,
4
4
  terminalSafeLine,
5
5
  terminalSafeText
6
- } from "./chunk-6JHKKLA2.js";
6
+ } from "./chunk-U67RBNIZ.js";
7
7
 
8
8
  // src/decisions/feedback.ts
9
9
  var FEEDBACK_PROTOCOL_VERSION = 2;
@@ -1,23 +1,25 @@
1
1
  import {
2
- analyzeShellTargets,
3
- extractFileTargets
4
- } from "./chunk-I3J344DF.js";
2
+ analyzeShellTargets
3
+ } from "./chunk-4L7TAM5S.js";
5
4
  import {
6
5
  DEFAULT_RULES,
7
6
  scrub
8
- } from "./chunk-6IRAGUYK.js";
7
+ } from "./chunk-NQFRQ56V.js";
9
8
  import {
10
9
  boundedHealthError,
11
10
  isPreflightResponseV4
12
- } from "./chunk-3TIKBQHV.js";
11
+ } from "./chunk-5BQ2NEMP.js";
13
12
  import {
14
13
  getClient,
15
14
  terminalSafeLine
16
- } from "./chunk-6JHKKLA2.js";
15
+ } from "./chunk-U67RBNIZ.js";
17
16
  import {
18
17
  canonicalGitRoot,
19
18
  canonicalRepositoryPath
20
- } from "./chunk-XG7S3LIL.js";
19
+ } from "./chunk-P2O7NLVN.js";
20
+ import {
21
+ extractFileTargets
22
+ } from "./chunk-W27EFR7W.js";
21
23
 
22
24
  // src/hooks/approval-copy.ts
23
25
  var MAX_EXCERPT_CHARS = 80;
@@ -103,7 +105,7 @@ function resolvePreflightTargets(args) {
103
105
  if (typeof command !== "string") {
104
106
  return { paths: [], coverage: "unverified", mutation: "present" };
105
107
  }
106
- const shell = analyzeShellTargets(command);
108
+ const shell = analyzeShellTargets(command, args.cwd);
107
109
  rawPaths = shell.paths;
108
110
  coverage = shell.coverage;
109
111
  mutation = shell.mutation;
@@ -308,6 +310,14 @@ function hasCompleteCoverage(response) {
308
310
  }
309
311
  return coverage.status === "completed" && coverage.discoveryComplete && coverage.candidateCount === coverage.evaluatedCount + coverage.bypassedCount && coverage.submittedCount === coverage.evaluatedCount && coverage.semanticBatchCount === coverage.completedSemanticBatchCount;
310
312
  }
313
+ function hasConfirmedConflict(response) {
314
+ const coverage = response.evaluationCoverage;
315
+ return (response.state === "completed" || response.state === "processing" || response.state === "paused") && response.conflicts.length > 0 && coverage.discoveryComplete && (response.state !== "completed" || hasCompleteCoverage(response)) && coverage.evaluatedCount <= coverage.candidateCount && coverage.evaluatedCount > 0 && coverage.completedSemanticBatchCount > 0 && (coverage.status === "partial" || coverage.status === "completed") && ["ask", "block", "warn"].includes(response.verdict) && [
316
+ "high_confidence_contradiction",
317
+ "aged_high_confidence_contradiction",
318
+ "provisional_or_uncertain_contradiction"
319
+ ].includes(response.reasonCode);
320
+ }
311
321
  function isNoTargetsSkip(response) {
312
322
  const coverage = response.evaluationCoverage;
313
323
  return response.state === "completed" && response.verdict === "allow" && response.reasonCode === "no_targets_skipped" && response.checkId === void 0 && response.evaluationId === void 0 && response.conflicts.length === 0 && response.bypassed.length === 0 && coverage.status === "completed" && coverage.discoveryComplete && coverage.candidateCount === 0 && coverage.submittedCount === 0 && coverage.evaluatedCount === 0 && coverage.bypassedCount === 0 && coverage.semanticBatchCount === 0 && coverage.completedSemanticBatchCount === 0;
@@ -325,7 +335,7 @@ function pausedResult(message, checkId) {
325
335
  return { verdict: "deny", conflicts: [], reason, additionalContext: reason, truncated: false };
326
336
  }
327
337
  function resultForPreflight2(response, preview, invocation, proposalTruncated = false) {
328
- if (!hasCompleteCoverage(response))
338
+ if (!hasCompleteCoverage(response) && !hasConfirmedConflict(response))
329
339
  return pausedResult(response.message || response.reasonCode, response.checkId);
330
340
  return resultForPreflight(
331
341
  {
@@ -354,7 +364,7 @@ async function requestPreflight(operation, deadline = performance.now() + PREFLI
354
364
  const remaining = deadline - performance.now();
355
365
  if (remaining <= 0)
356
366
  throw new PreflightPausedError(
357
- "The 240-second check wait expired",
367
+ "The check deadline expired",
358
368
  operation.operation === "start" ? void 0 : operation.checkId
359
369
  );
360
370
  const value = await getClient().post(ENDPOINT, operation, {
@@ -363,7 +373,7 @@ async function requestPreflight(operation, deadline = performance.now() + PREFLI
363
373
  });
364
374
  if (performance.now() >= deadline)
365
375
  throw new PreflightPausedError(
366
- "The 240-second check wait expired",
376
+ "The check deadline expired",
367
377
  operation.operation === "start" ? void 0 : operation.checkId
368
378
  );
369
379
  const response = parsePreflightResponse2(value);
@@ -372,7 +382,7 @@ async function requestPreflight(operation, deadline = performance.now() + PREFLI
372
382
  "The enforcement service returned an incompatible V4 response",
373
383
  operation.operation === "start" ? void 0 : operation.checkId
374
384
  );
375
- if (response.reasonCode === "no_targets_skipped" && !(operation.operation === "start" && operation.paths.length === 0 && operation.coverage === "unverified" && isNoTargetsSkip(response))) {
385
+ if (response.reasonCode === "no_targets_skipped" && !(operation.operation === "start" && !operation.shellCheck && operation.paths.length === 0 && operation.coverage === "unverified" && isNoTargetsSkip(response))) {
376
386
  throw new PreflightPausedError(
377
387
  "The enforcement service returned an invalid target-policy exemption",
378
388
  operation.operation === "start" ? void 0 : operation.checkId
@@ -388,6 +398,7 @@ async function requestPreflight(operation, deadline = performance.now() + PREFLI
388
398
  async function waitForPreflight(operation, options = {}) {
389
399
  const deadline = options.deadline ?? performance.now() + PREFLIGHT_WAIT_MS;
390
400
  let next = operation;
401
+ const shellCheck = operation.operation === "start" ? operation.shellCheck : void 0;
391
402
  let evaluationId;
392
403
  let lastProgress;
393
404
  let checkId = operation.operation === "start" ? void 0 : operation.checkId;
@@ -398,7 +409,7 @@ async function waitForPreflight(operation, options = {}) {
398
409
  } catch (error) {
399
410
  if (error instanceof PreflightPausedError) throw error;
400
411
  if (performance.now() >= deadline)
401
- throw new PreflightPausedError("The 240-second check wait expired", checkId);
412
+ throw new PreflightPausedError("The check deadline expired", checkId);
402
413
  if (checkId)
403
414
  throw new PreflightPausedError(
404
415
  "The enforcement service could not finish this check",
@@ -406,6 +417,9 @@ async function waitForPreflight(operation, options = {}) {
406
417
  );
407
418
  throw error;
408
419
  }
420
+ if (shellCheck && response.shellCheck?.targetMode !== shellCheck.targetMode && !(response.reasonCode === "enforcement_disabled" && hasCompleteCoverage(response))) {
421
+ throw new PreflightPausedError("The backend did not confirm shell-check support", checkId);
422
+ }
409
423
  if (isUnidentifiedPause(response)) {
410
424
  if (checkId) throw new PreflightPausedError(response.message || response.reasonCode, checkId);
411
425
  return response;
@@ -417,13 +431,13 @@ async function waitForPreflight(operation, options = {}) {
417
431
  );
418
432
  checkId = response.checkId;
419
433
  evaluationId = response.evaluationId;
420
- if (response.state !== "processing") return response;
434
+ if (response.state !== "processing" || options.stopOnConflict && hasConfirmedConflict(response))
435
+ return response;
421
436
  const progress = JSON.stringify(response.evaluationCoverage);
422
437
  if (progress !== lastProgress) options.onProgress?.(response);
423
438
  lastProgress = progress;
424
439
  const remaining = deadline - performance.now();
425
- if (remaining <= 0)
426
- throw new PreflightPausedError("The 240-second check wait expired", checkId);
440
+ if (remaining <= 0) throw new PreflightPausedError("The check deadline expired", checkId);
427
441
  await delay(
428
442
  Math.min(remaining, Math.max(100, Math.min(5e3, response.retryAfterMs ?? 1e3)))
429
443
  );
@@ -438,9 +452,9 @@ export {
438
452
  proposalFor,
439
453
  proposalIsTruncated,
440
454
  PREFLIGHT_PROTOCOL_VERSION2 as PREFLIGHT_PROTOCOL_VERSION,
441
- PREFLIGHT_WAIT_MS,
442
455
  toolInputDigest,
443
456
  hasCompleteCoverage,
457
+ hasConfirmedConflict,
444
458
  PreflightPausedError,
445
459
  pausedResult,
446
460
  resultForPreflight2 as resultForPreflight,