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

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 (38) hide show
  1. package/README.md +62 -0
  2. package/SKILL.md +5 -3
  3. package/assets/primitive-gameplan/SKILL.md +134 -0
  4. package/assets/primitive-gameplan/claude-hooks.json +28 -0
  5. package/assets/primitive-gameplan/scripts/activate.mjs +37 -0
  6. package/dist/{chunk-IZXLH3R5.js → chunk-3TIKBQHV.js} +2584 -821
  7. package/dist/{chunk-NH3VC7YO.js → chunk-4OEJ2ONG.js} +1 -1
  8. package/dist/{chunk-DWAXFXDG.js → chunk-4SN5BCIG.js} +1 -1
  9. package/dist/{chunk-3KKEV7VI.js → chunk-6IRAGUYK.js} +1 -1
  10. package/dist/chunk-CXMLAWC2.js +96 -0
  11. package/dist/chunk-D3ZDZZYS.js +449 -0
  12. package/dist/{chunk-RUUSUF43.js → chunk-I3J344DF.js} +231 -94
  13. package/dist/{chunk-7DVEH7FO.js → chunk-JKJ22ONL.js} +1 -1
  14. package/dist/{chunk-PO5QAYD7.js → chunk-JKO6PZWQ.js} +119 -24
  15. package/dist/{chunk-BXLH4LDU.js → chunk-LEUZDTNT.js} +1 -1
  16. package/dist/{chunk-PJW6JZMH.js → chunk-LLKJAET2.js} +1 -1
  17. package/dist/{chunk-IMYELJIV.js → chunk-RLBASQJD.js} +3 -3
  18. package/dist/{chunk-RTULPLS7.js → chunk-S55JKCHQ.js} +1 -1
  19. package/dist/daemon/server.js +2583 -822
  20. package/dist/hook-runtime/daemon/server.js +2583 -822
  21. package/dist/hook-runtime/hooks/post-commit.js +2581 -820
  22. package/dist/hook-runtime/hooks/post-rewrite.js +2581 -820
  23. package/dist/hook-runtime/hooks/post-tool-use.js +2689 -921
  24. package/dist/hook-runtime/hooks/pre-tool-use.js +2922 -985
  25. package/dist/hook-runtime/hooks/prim-hook.js +2682 -914
  26. package/dist/hook-runtime/hooks/session-end.js +19 -12
  27. package/dist/hook-runtime/hooks/session-start.js +2828 -1060
  28. package/dist/hook-runtime/index.js +23395 -12348
  29. package/dist/hooks/post-commit.js +3 -3
  30. package/dist/hooks/post-rewrite.js +3 -3
  31. package/dist/hooks/post-tool-use.js +11 -11
  32. package/dist/hooks/pre-tool-use.js +78 -316
  33. package/dist/hooks/prim-hook.js +10 -10
  34. package/dist/hooks/session-end.js +2 -2
  35. package/dist/hooks/session-start.js +6 -6
  36. package/dist/index.js +564 -157
  37. package/package.json +8 -1
  38. package/dist/chunk-JDIAPBY7.js +0 -233
package/README.md CHANGED
@@ -13,6 +13,25 @@ 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:
20
+
21
+ ```bash
22
+ prim decisions preflight status <checkId>
23
+ prim decisions preflight resume <checkId> # Finish evaluation, then retry the tool
24
+ ```
25
+
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.
34
+
16
35
  ## Installation
17
36
 
18
37
  Requires Node.js 22.23.4+, 24.22.1+, or 26.12.1+ within those major versions.
@@ -203,6 +222,25 @@ prim codex install # Install OpenAI Codex hooks (user scope; --s
203
222
  prim hermes install # Install Hermes Agent hooks (global ~/.hermes/config.yaml)
204
223
  ```
205
224
 
225
+ For `$write-gameplan` or `$write-workstream` authoring in Codex, install the
226
+ separate Primitive planning companion from the target repository after the
227
+ public `$write-gameplan` skill is available:
228
+
229
+ ```bash
230
+ prim setup --agent codex
231
+ prim gameplan install --agent codex
232
+ prim gameplan status
233
+ ```
234
+
235
+ `gameplan install` adds the companion to this repository and a prompt dispatcher
236
+ to the user's Codex hooks, including linked worktrees. It does not replace the
237
+ public planning skill or install Conflict Gates; `setup` handles the latter.
238
+ Review `/hooks` in Codex and start a fresh session. `prim gameplan uninstall`
239
+ removes this repository's companion and leaves the shared user hook in place;
240
+ pass `--remove-user-hook` only when no other repository needs it. A Decision
241
+ scoped only to a code path named inside a gameplan is surfaced during planning,
242
+ but the edit gate sees the changed gameplan path.
243
+
206
244
  Passive capture is repo-scoped even when these integrations are installed at user
207
245
  scope. `prim enable` marks the current Git repo active; `prim disable` makes it
208
246
  inactive. A project-scoped install activates its repo automatically. In an inactive
@@ -536,6 +574,30 @@ pnpm typecheck # Type-check
536
574
  pnpm lint # Lint
537
575
  ```
538
576
 
577
+ ### Actual host validation
578
+
579
+ After `pnpm build`, optional E2E checks drive a real host's tool loop against a
580
+ local deterministic model provider. They use temporary HOME/configuration and a
581
+ sentinel file, synthetic credentials, and no real model requests or user account.
582
+ They never install or upgrade the host or change your host settings.
583
+
584
+ ```bash
585
+ pnpm test:preflight-host # Installed Codex
586
+ pnpm test:preflight-host:claude # Claude 2.1.295+ on PATH
587
+ pnpm test:preflight-host:claude --binary /path/to/compatible/claude
588
+ # CLI_CLAUDE_BIN also selects the Claude binary.
589
+ ```
590
+
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.
598
+ The separate `pnpm test:preflight-v4 --schema /path/to/cli-http-v1.schema.json`
599
+ check validates the built CLI against a supplied authoritative backend contract.
600
+
539
601
  ## License
540
602
 
541
603
  [MIT](LICENSE)
package/SKILL.md CHANGED
@@ -40,9 +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
- - **"decision check skipped / not verified" or "... partial / truncated"** -- the check could not fully run. Treat constraints as UNKNOWN, not clear; never read silence as 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.
44
44
 
45
- When enabled, the gate sends its preflight check directly to Primitive and fail-opens on infrastructure errors (for example, a network failure or org-unbound token) -- a service problem would not block your edit. That is why an "unavailable" note matters: it is the honest signal that the check, not your edit, is what failed.
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.
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.
46
48
 
47
49
  ## Read the graph before large or load-bearing edits
48
50
 
@@ -358,7 +360,7 @@ Examples:
358
360
  ## Pitfalls
359
361
 
360
362
  - **An "unavailable" / "not verified" decision check is not an all-clear.** Treat constraints as UNKNOWN and proceed deliberately; never read the silence as approval — the same holds for Conflict Gates once enabled.
361
- - **When Enforcement is enabled, a `deny` means a real prior decision conflicts.** Keep the edit blocked and pick an approach that respects it; intention alone never authorizes an override.
363
+ - **When Enforcement is enabled, `deny` blocks the edit for a conflict or an incomplete check.** Read the reason. Resolve the conflict or resume the check; intention alone never authorizes an override.
362
364
  - **Reconcile bypasses are disabled.** Human approval cannot be inferred from tool execution or automatic review.
363
365
  - **Capture of coding activity is automatic only in active repos; never inject moves by hand.** If an active repo's decisions aren't showing up, check that the session hooks are installed (`claude status` / `cursor status` / `codex status` / `hermes status`) and the daemon is running. Deliberately authoring a higher-order fork—either at the user's request or under the conservative proactive policy above—is a separate, supported path through `decisions create`; in an inactive repo, honor the per-invocation approval boundary above.
364
366
  - **Don't fabricate rationale on a confirmation.** If you don't know why a decision was made, say so rather than guessing.
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: primitive-gameplan
3
+ description: Use alongside write-gameplan and write-workstream to bring applicable Primitive Decisions into architectural discussion, review plans for unsupported architectural additions, and preserve engineer-approved resolutions. Does not replace either public skill or authorize implementation.
4
+ ---
5
+
6
+ # Primitive companion for gameplanning
7
+
8
+ Use the public planning skill unchanged. This companion adds decision context to
9
+ its existing architecture discussion and final review; it adds no schema fields
10
+ or human checkpoints between execution patches. Codex is the primary host:
11
+ discover this companion under `.agents/skills`, make the public skills available
12
+ to Codex, and use `$write-gameplan` or `$write-workstream`.
13
+ `prim gameplan install --agent codex` places a dispatcher
14
+ in the user's Codex hooks to load this companion for explicit invocations;
15
+ `AGENTS.md` also binds implicit planning-skill use.
16
+ Claude retains `/write-gameplan` and `/write-workstream` through
17
+ [the Claude hook configuration](claude-hooks.json), merged into
18
+ `.claude/settings.json` without replacing existing hooks.
19
+
20
+ ## Before choosing architecture
21
+
22
+ Inspect the requested behavior and its existing code path. Identify both the
23
+ intended code files and the plan/workstream path, even if the plan does not exist
24
+ yet. From the target repository root, use the installed `prim` CLI, or
25
+ `npx --yes @primitive.ai/prim` when there is no `prim` executable:
26
+
27
+ ```sh
28
+ prim auth status
29
+ prim decisions check --files "src/billing/export.ts,gameplans/billing-export.yaml"
30
+ prim decisions show dec_123
31
+ ```
32
+
33
+ Replace the example paths and ID with real ones. `check` accepts comma-separated
34
+ repo-relative paths and emits JSON without a `--json` flag. Check intended code
35
+ paths as well as the artifact: a decision scoped to billing may not govern the
36
+ gameplans directory. Repeat the lookup if the planned footprint expands. Use
37
+ `show` on decisions you will rely on to inspect their full constraints, rationale,
38
+ source/attribution, status, and scope. A path match alone does not settle a choice.
39
+
40
+ Give a short brief before patch decomposition: relevant settled choices,
41
+ explicitly rejected approaches, and remaining architectural questions. Cite the
42
+ Decision IDs and explain their bearing on this change. Do not invent a blanket
43
+ ban on validators, workers, or persistence from an example of overengineering.
44
+
45
+ An empty successful lookup means no matching decisions were returned, not that
46
+ the proposed architecture is approved. Nonzero exits, `unavailable`, partial or
47
+ truncated responses, and missing provenance mean coverage is unknown or limited.
48
+ Report that limitation and use available engineer-supplied constraints. Do not
49
+ claim Primitive clearance, start an authentication flow, enable capture, or change
50
+ enforcement settings merely to finish planning.
51
+
52
+ ## Resolve choices in the existing format
53
+
54
+ Use `architectureDesign.decisions[].resolution` in the public gameplan schema:
55
+
56
+ - `engineer_approved`: an actual engineer answer or identifiable engineer-approved
57
+ source covers this exact choice and scope. Evidence includes the Primitive ID,
58
+ substantive constraint, source of approval, and why it applies here.
59
+ - `constrained`: binding requirements eliminate meaningful alternatives; explain
60
+ that reasoning, including the applicable Decision when one supplies a constraint.
61
+ - `delegated`: the engineer explicitly delegated this choice within a stated
62
+ scope; retain that delegation. The agent's resulting selection is not a new
63
+ user-originated decision without ratification.
64
+ - `unresolved`: the remaining choice needs an answer. Keep it in `openQuestions`
65
+ too, and leave dependent patches/specs provisional until it is resolved.
66
+
67
+ Keep rationale in `resolution.rationale`. A captured agent suggestion, an author
68
+ name, adoption status alone, an existing implementation, or a broad milestone is
69
+ not evidence that an engineer approved a new mechanism. For example, approval of
70
+ PostgreSQL does not approve another durable ledger. Conflicting or ambiguous
71
+ Decisions require clarification; do not silently prefer the newest one.
72
+
73
+ When alternatives remain, present the minimal approach, credible alternatives,
74
+ and relevant prior constraints before choosing. Ask one question at a time when
75
+ answers depend on each other. Do not repeat a question already answered within
76
+ the same scope. For a workstream, use its existing decisions/open-questions prose
77
+ rather than introducing gameplan fields.
78
+
79
+ ## Review the complete artifact before handoff
80
+
81
+ Read the solution, operational considerations, every patch, and every formal spec
82
+ against the resolved architecture. Look for consequential choices introduced as
83
+ implementation details: another source of truth, validation boundary, state
84
+ lifetime, worker, scheduler, retry protocol, or cross-runtime data flow. Check
85
+ each against its actual evidence and scope, not merely whether an ID is present.
86
+ This is a semantic review by the planning agent: `prim decisions check` is a
87
+ lookup, not that review.
88
+
89
+ For an unsupported addition, identify the patch and concrete choice. Remove an
90
+ unnecessary agent-added mechanism consistently from the artifact, or present it
91
+ as an unresolved exception with alternatives before finalizing dependent work.
92
+ Discussion of a rejected option is allowed; adopting it without resolution is not.
93
+ Re-run the public skill's schema/spec validation after changes. A validator PASS
94
+ does not verify that a human approved the design.
95
+
96
+ ## Preserve the answers
97
+
98
+ At a natural planning boundary, retain durable engineer resolutions in Primitive
99
+ when recording is authorized. Check the applicable records and
100
+ `prim decisions recent --limit 20` to avoid duplicates. Use the installed Prim
101
+ recording policy when available; a request to draft a plan alone does not grant
102
+ permission to publish decisions into an inactive repository.
103
+
104
+ Before a create, check `prim decisions create --help`. Record the exact approved
105
+ choice with `--intent`, `--attribution user`, source-grounded `--rationale`, one
106
+ `--decided` per binding constraint, and `--alternatives` only for options actually
107
+ rejected. An agent selection under delegation uses `--attribution agent` unless
108
+ the engineer ratifies that selection. Missing rationale is a question, not a
109
+ license to invent one. Apply only the approved scope using `--files`,
110
+ `--scope-dir`, or `--scope-repo`; include the plan path when that scope governs it.
111
+ Do not silently broaden a code-only constraint to all plans or the whole repo.
112
+
113
+ Honor existing recording authorization without asking again. For an inactive repo,
114
+ Prim's global `--yes` is appropriate only for a specifically authorized create;
115
+ npm's `npx --yes` is merely package-install confirmation. Preserve returned IDs
116
+ in the existing evidence fields. Report failed writes as unsaved, retaining the
117
+ approved wording in the plan for recovery; after an ambiguous failure, check for
118
+ an existing record before retrying. Never invent an ID or a successful save.
119
+
120
+ For parent workstreams, follow the public skill's write-back procedure: present
121
+ the concrete edits and obtain its required approval before applying them. Saving
122
+ a Primitive Decision does not authorize a workstream edit.
123
+
124
+ ## Enforcement boundary
125
+
126
+ Existing Conflict Gates may inspect saved plans when enabled and in scope. This
127
+ companion neither installs nor enables gates. It does not guarantee detection of
128
+ every architectural implication or cryptographically verify approval. Chat-only
129
+ plans bypass file-write gates, and infrastructure failures may fail open.
130
+
131
+ If a gate flags a conflict, surface the governing Decision and resolve the
132
+ architectural choice with the engineer. Do not run `prim reconcile`, weaken gate
133
+ mode, or change/supersede the Decision merely to make the plan pass. A bypass or
134
+ change of constraint needs explicit engineer authorization for that action.
@@ -0,0 +1,28 @@
1
+ {
2
+ "hooks": {
3
+ "UserPromptExpansion": [
4
+ {
5
+ "matcher": "(^|:)write-(gameplan|workstream)$",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node \"$CLAUDE_PROJECT_DIR/.agents/skills/primitive-gameplan/scripts/activate.mjs\"",
10
+ "timeout": 5
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "PreToolUse": [
16
+ {
17
+ "matcher": "Skill",
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "node \"$CLAUDE_PROJECT_DIR/.agents/skills/primitive-gameplan/scripts/activate.mjs\"",
22
+ "timeout": 5
23
+ }
24
+ ]
25
+ }
26
+ ]
27
+ }
28
+ }
@@ -0,0 +1,37 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ const event = JSON.parse(readFileSync(0, "utf8"));
4
+ let name;
5
+ if (event.hook_event_name === "UserPromptSubmit") {
6
+ name = event.prompt?.match(
7
+ /^\s*[$/](write-(?:gameplan|workstream))(?=\s|$)/
8
+ )?.[1];
9
+ } else if (
10
+ event.hook_event_name === "UserPromptExpansion" &&
11
+ event.expansion_type === "slash_command"
12
+ ) {
13
+ name = event.command_name;
14
+ } else if (
15
+ event.hook_event_name === "PreToolUse" &&
16
+ event.tool_name === "Skill"
17
+ ) {
18
+ name = event.tool_input?.skill;
19
+ }
20
+
21
+ if (
22
+ typeof name === "string" &&
23
+ /^(?:[^:]+:)*write-(?:gameplan|workstream)$/.test(name)
24
+ ) {
25
+ const companion = readFileSync(
26
+ new URL("../SKILL.md", import.meta.url),
27
+ "utf8"
28
+ );
29
+ process.stdout.write(
30
+ `${JSON.stringify({
31
+ hookSpecificOutput: {
32
+ hookEventName: event.hook_event_name,
33
+ additionalContext: `This repository uses the Primitive planning companion alongside ${name}. Its local skill follows:\n\n${companion}`,
34
+ },
35
+ })}\n`
36
+ );
37
+ }