@primitive.ai/prim 0.1.0-alpha.9 → 0.1.0-alpha.91

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 (47) hide show
  1. package/README.md +303 -37
  2. package/SKILL.md +269 -0
  3. package/dist/chunk-4GLVJLEQ.js +55 -0
  4. package/dist/chunk-5AFRMOPX.js +209 -0
  5. package/dist/chunk-5GYQ4J3D.js +126 -0
  6. package/dist/chunk-67VNLLBN.js +789 -0
  7. package/dist/chunk-BTNNEH2W.js +79 -0
  8. package/dist/chunk-EWZMDD44.js +1474 -0
  9. package/dist/chunk-EZXEWFDG.js +210 -0
  10. package/dist/chunk-FBAYCS3X.js +327 -0
  11. package/dist/chunk-FKXFUUWJ.js +36 -0
  12. package/dist/chunk-FOLKHXLJ.js +1529 -0
  13. package/dist/chunk-H4UNYFUC.js +196 -0
  14. package/dist/chunk-HU4PW6I6.js +264 -0
  15. package/dist/chunk-KFXF2V5G.js +155 -0
  16. package/dist/chunk-LFFLHSQO.js +78 -0
  17. package/dist/chunk-M6RIJVRE.js +18358 -0
  18. package/dist/chunk-NAHHFSLH.js +258 -0
  19. package/dist/chunk-OAAP2MY6.js +262 -0
  20. package/dist/chunk-PCVGBE5B.js +659 -0
  21. package/dist/chunk-VW3FDYRT.js +517 -0
  22. package/dist/chunk-WX52U7Z2.js +112 -0
  23. package/dist/chunk-ZB4F75SZ.js +843 -0
  24. package/dist/daemon/server.js +21633 -0
  25. package/dist/hook-runtime/daemon/server.js +21633 -0
  26. package/dist/hook-runtime/hooks/post-commit.js +19258 -0
  27. package/dist/hook-runtime/hooks/post-rewrite.js +19273 -0
  28. package/dist/hook-runtime/hooks/post-tool-use.js +26365 -0
  29. package/dist/hook-runtime/hooks/pre-commit.js +1314 -0
  30. package/dist/hook-runtime/hooks/pre-tool-use.js +25832 -0
  31. package/dist/hook-runtime/hooks/prim-hook.js +26386 -0
  32. package/dist/hook-runtime/hooks/session-end.js +1078 -0
  33. package/dist/hook-runtime/hooks/session-start.js +28779 -0
  34. package/dist/hook-runtime/index.js +50987 -0
  35. package/dist/hook-runtime/statusline-main.js +809 -0
  36. package/dist/hooks/post-commit.js +190 -0
  37. package/dist/hooks/post-rewrite.js +203 -0
  38. package/dist/hooks/post-tool-use.js +288 -0
  39. package/dist/hooks/pre-commit.js +16 -101
  40. package/dist/hooks/pre-tool-use.js +369 -0
  41. package/dist/hooks/prim-hook.js +229 -0
  42. package/dist/hooks/session-end.js +59 -0
  43. package/dist/hooks/session-start.js +316 -0
  44. package/dist/index.js +8875 -429
  45. package/dist/statusline-main.js +809 -0
  46. package/package.json +35 -13
  47. package/dist/chunk-3APLWTLB.js +0 -165
package/README.md CHANGED
@@ -1,10 +1,18 @@
1
1
  # @primitive.ai/prim
2
2
 
3
- The official CLI for [Primitive](https://getprimitive.ai). Manage specs, contexts, projects, and git hooks from the command line.
3
+ The official CLI for [Primitive](https://getprimitive.ai)'s **decision graph**. It
4
+ passively captures the decisions your team makes while coding and reports team
5
+ presence — from the command line and via session + git hooks.
4
6
 
5
7
  > [!WARNING]
6
8
  > This project is in **alpha**. Commands and APIs may change between releases.
7
9
 
10
+ > [!NOTE]
11
+ > **Conflict Gates** check each edit against the decision graph and surface any
12
+ > load-bearing decision it conflicts with. When **Enforcement** is enabled for your
13
+ > organization, gates can warn, pause, or block a conflicting edit until you reconcile
14
+ > the decision and retry. Automatic decision capture in active repositories is separate.
15
+
8
16
  ## Installation
9
17
 
10
18
  Requires Node.js 20+.
@@ -19,21 +27,91 @@ Or run directly without installing:
19
27
  npx @primitive.ai/prim
20
28
  ```
21
29
 
30
+ In commands such as `npx --yes @primitive.ai/prim@latest ...`, the first `--yes`
31
+ belongs to **npm**: it skips npm's package-install confirmation. It does not approve a
32
+ Primitive action. Prim's own global `--yes` comes after the package name, for example
33
+ `npx --yes @primitive.ai/prim@latest --yes decisions create ... --attribution user`,
34
+ and applies only to that Prim invocation.
35
+
22
36
  ## Quick Start
23
37
 
38
+ One command does the whole install — auth, session hooks, daemon, git hooks,
39
+ skill, and the welcome:
40
+
41
+ ```bash
42
+ prim setup # add --agent cursor, codex, or hermes; --no-daemon explicitly opts out
43
+ ```
44
+
45
+ Or run the steps individually:
46
+
24
47
  ```bash
25
- # Authenticate via browser (WorkOS OAuth)
48
+ # 1. Authenticate via browser (WorkOS OAuth)
26
49
  prim auth login
27
50
 
28
- # List your specs
29
- prim spec list
51
+ # 2. Wire the session hooks (decision capture + presence)
52
+ prim claude install # or: prim cursor install / prim codex install / prim hermes install
53
+
54
+ # 3. Start the companion daemon (latency + team presence)
55
+ prim daemon start
30
56
 
31
- # Install the pre-commit hook
57
+ # 4. Install the git hooks (pre-commit decision check + post-commit capture)
32
58
  prim hooks install
33
59
  ```
34
60
 
61
+ `prim setup` (and `prim claude preauth`) also pre-authorize prim so an agent's own
62
+ calls never stall on a permission prompt: a scoped `Bash(npx --yes @primitive.ai/prim*)`
63
+ allow-rule for default mode (it covers both the `@latest` onboarding form and the bare
64
+ day-to-day form), plus an `autoMode.environment` trust line so auto mode's safety
65
+ classifier treats prim as trusted tooling rather than untrusted downloaded code.
66
+
67
+ ### Set up with your coding agent
68
+
69
+ Paste this into Claude Code (or any coding agent). The command is in **your** message,
70
+ so the agent runs it directly — instead of fetching a doc and executing a command from
71
+ it, which an auto-mode safety classifier blocks as untrusted-origin code:
72
+
73
+ ```text
74
+ Install the Primitive CLI and activate passive decision capture for this repository: run `npx --yes @primitive.ai/prim@latest setup` and surface its output. Drive it yourself; I'll only click Authorize in the browser. This request authorizes setup's built-in activation of this repository and an idempotent retry of that step, but not activation in another repository or creation of a Decision. If enable or health fails, surface the actual error; do not claim fresh activation approval is required. Then show me the welcome.
75
+ ```
76
+
77
+ That single command runs the whole install and current-repository activation in one
78
+ process (auth → session hooks → daemon → git hooks → skill → welcome). The detailed
79
+ step-by-step the agent follows — and the manual fallback — live in
80
+ [`setup.md`](./setup.md).
81
+
35
82
  ## Commands
36
83
 
84
+ ### Setup
85
+
86
+ ```bash
87
+ prim setup # Run the whole install in one shot
88
+ prim setup --agent cursor # Same, for Cursor IDE and Cursor CLI
89
+ prim setup --agent codex # Same, for OpenAI Codex
90
+ prim setup --agent hermes # Same, for Hermes Agent (global-only config)
91
+ prim setup --no-daemon # Stop it and persistently opt out of supervised delivery
92
+ ```
93
+
94
+ Orchestrates auth → session hooks → supervised daemon → capture-health gate → git hooks → skill → welcome,
95
+ re-running each underlying command so every step behaves exactly as if run by
96
+ hand (including the browser login). Idempotent — safe to re-run.
97
+
98
+ ### Uninstall
99
+
100
+ ```bash
101
+ prim uninstall
102
+ ```
103
+
104
+ Stops the companion daemon, removes the current repository's Prim-owned agent
105
+ and Git-hook surfaces when run inside a Git repository, removes the user-scoped
106
+ Claude, Cursor, Codex, Hermes, and Git-hook surfaces, then deletes only schema-valid
107
+ Prim runtime bytes. Foreign configuration is retained; ambiguous ownership
108
+ makes the command fail closed and retain the runtimes. If a removal races or
109
+ fails after one runtime changes, its JSON result reports each runtime's exact
110
+ state so rerunning can safely finish cleanup. Authentication,
111
+ undelivered journals, repository bindings, and agent skill guidance are kept.
112
+ Use `prim skill uninstall --agent <claude|cursor|codex|hermes> --scope <project|user>`
113
+ when you also want to remove a known skill target.
114
+
37
115
  ### Auth
38
116
 
39
117
  ```bash
@@ -41,59 +119,247 @@ prim auth login # Authenticate via browser
41
119
  prim auth set-token <token> # Save a bearer token (e.g. for CI)
42
120
  prim auth clear # Remove saved tokens
43
121
  prim auth status # Check authentication status
122
+ prim auth api-keys mint --name <name> [--expires-at <epoch-ms>] # Mint a user key; secret prints once
123
+ prim auth api-keys list [--limit <count>] [--after <api-key-id>] # List user-key metadata
124
+ prim auth api-keys revoke <api-key-id> # Revoke a user key
125
+ ```
126
+
127
+ ### GitHub
128
+
129
+ ```bash
130
+ prim github connect # Install or reuse the Primitive GitHub App for this checkout
131
+ prim github connect --no-browser # Print the installation URL without opening it
44
132
  ```
45
133
 
46
- ### Specs
134
+ The command first reuses existing repository access. When access is missing, it creates a
135
+ server-owned GitHub App installation intent, opens its installation URL unless browser opening is
136
+ suppressed, polls the same intent, then verifies and persists this checkout's binding. A completed
137
+ installation without admin access to this repository remains truthfully unbound.
138
+
139
+ ### Session integration
140
+
141
+ Wires the agent's session hooks so the decisions you make are captured into the
142
+ graph, and presence is reported. Each hook
143
+ self-resolves the CLI at run time (PATH, then a local install, then
144
+ `npx --yes @latest`), so it keeps working with no global install.
47
145
 
48
- Specs are documents that drive implementation. They can be synced to a project DAG and mapped to file patterns for automatic pre-commit hook integration.
146
+ Installs into the current project by default — the repo's `.claude/settings.json`,
147
+ `.cursor/hooks.json`, or `.codex/hooks.json`, resolved from the git root (so any subdirectory works);
148
+ pass `--scope user` to install machine-wide. Hermes is the exception: it reads
149
+ shell hooks only from the global `~/.hermes/config.yaml`, so `prim hermes install`
150
+ is always user-scoped — and prim merges in place, leaving the rest of that file
151
+ (providers, models, your own hooks) untouched.
49
152
 
50
153
  ```bash
51
- prim spec list # List all specs
52
- prim spec list --project-id <id> # Find spec for a root project
53
- prim spec get <id> # Show spec details
54
- prim spec get <id> --text-only # Print raw spec text
55
- prim spec update <id> --file spec.md # Update spec from file
56
- prim spec update <id> --name "New" # Rename a spec
57
- prim spec sync <id> # Trigger spec-to-project sync
58
- prim spec map <id> -p "src/auth/**" # Map file patterns to a spec
59
- prim spec unmap <id> # Clear all file patterns
60
- prim spec unmap <id> -p "src/auth/**" # Remove specific pattern
61
- prim spec auto-map <id> # Auto-detect file patterns
154
+ prim claude install # Install Claude Code hooks (project scope; uninstall / status)
155
+ prim claude install --scope user # Install machine-wide instead
156
+ prim cursor install # Install native Cursor hooks (project scope)
157
+ prim cursor install --scope user # Install hooks, skill, and CLI footer machine-wide
158
+ prim codex install # Install OpenAI Codex hooks (project scope)
159
+ prim hermes install # Install Hermes Agent hooks (global ~/.hermes/config.yaml)
160
+ ```
161
+
162
+ Passive capture is repo-scoped even when these integrations are installed at user
163
+ scope. `prim enable` marks the current Git repo active; `prim disable` makes it
164
+ inactive. A project-scoped install activates its repo automatically. In an inactive
165
+ repo, session content is not passively captured. Here “inactive” means Prim's normal
166
+ effective capture check is false, including an explicit local `prim.active=false`.
167
+
168
+ An agent may still deliberately record one Decision from an inactive repo with
169
+ `prim decisions create`, but each invocation needs its own user approval. An explicit
170
+ request such as “record this Decision” supplies that approval for that one create; for
171
+ a proactive suggestion, the agent must show the proposed Decision and ask first. The
172
+ agent then passes Prim's global `--yes` for that invocation. This one-time approval does
173
+ not activate passive capture, and neither npm's `npx --yes`, setup approval, nor an
174
+ earlier create counts as approval for another Decision.
175
+
176
+ When a person runs `prim decisions create` interactively in an inactive repo, Prim
177
+ asks for that one-time approval itself. In non-interactive use it creates nothing
178
+ unless Prim's global `--yes` is present.
179
+
180
+ #### Claude decision feedback
181
+
182
+ Claude Code receives eventual, human-visible feedback when automatic capture
183
+ creates a `change` Decision. A later Claude `Stop` or fresh
184
+ `SessionStart` in the same Git worktree can display:
185
+
186
+ ```text
187
+ [prim] response → created Decision (dec_a1b2c3d4): Use the stable API (https://app.getprimitive.ai/decisions/r571n1dqjdrtyxxpf0fnzee4gn8aed6q)
188
+ ```
189
+
190
+ An author-private draft uses an actionable publish prompt instead:
191
+
192
+ ```text
193
+ [prim] publish this Decision draft (dec_a1b2c3d4)? Use the stable API (https://app.getprimitive.ai/decisions/r571n1dqjdrtyxxpf0fnzee4gn8aed6q) Run `prim decisions publish decision-full-1` to share it with your team.
62
194
  ```
63
195
 
64
- ### Contexts
196
+ This is a hook `systemMessage` for the person using Claude Code; it is not
197
+ injected into the model's context. Delivery is at-least-once at the stdout
198
+ handoff boundary: prim acknowledges only after writing the hook response, so a
199
+ failed acknowledgment can show the same notification again. Notifications are
200
+ eligible for 24 hours. The originating session gets limited preference, but any
201
+ concurrent Claude session in the same worktree may consume the backlog. A hook
202
+ claims at most 40 notifications and renders at most 8,000 Unicode code points;
203
+ `hasMore` work is left for a later Stop or SessionStart rather than extending
204
+ the current hook.
205
+
206
+ Worktree scope comes from an opaque UUID stored under the worktree's Git
207
+ metadata (equivalent to `git rev-parse --git-path prim/workspace-id`), never an
208
+ absolute repository path. Linked worktrees receive distinct IDs, moving a
209
+ worktree preserves its ID, and a clone creates a new one. A corrupt or
210
+ unwritable identity is never silently replaced: capture falls back to the
211
+ legacy envelope. Disable/uninstall does not delete the identity.
212
+
213
+ Feedback uses the invoking CLI's credentials for direct HTTPS calls rather
214
+ than the daemon, avoiding cross-organization token ambiguity. One absolute
215
+ three-second in-process budget covers token refresh, lease, parsing, rendering,
216
+ and acknowledgment. This is not a hard three-second wall clock: it cannot
217
+ preempt shell/PATH or `npx` resolution, Node startup, Claude's own hook
218
+ scheduling, or synchronous filesystem work. The Git fallback has a separate
219
+ short timeout.
220
+
221
+ Alternatives considered:
222
+
223
+ | Option | Benefit | Limitation |
224
+ | --- | --- | --- |
225
+ | Existing hooks + direct HTTPS (current) | No new install surface; uses the invoking credentials | In-process budget is not a host-enforced wall clock |
226
+ | Claude's native hook timeout | Host-enforced termination | Settings migration; may kill a cold `npx` startup |
227
+ | Daemon routing | Lower steady-state latency | Daemon token/org may not match a concurrent session |
228
+ | Dedicated feedback binary | Lower startup overhead | New distribution and install migration |
229
+ | Synchronous pre-Stop classification | Stronger same-turn immediacy | Adds model latency and cost to the hook path |
230
+ | Detached delivery | Does not block Stop | Cannot return the current hook's `systemMessage` |
231
+
232
+ Run `prim claude status` to verify both existing feedback handlers are installed
233
+ and `prim doctor` to inspect server capability. No new
234
+ hook registration or binary is required when upgrading an existing correct
235
+ installation.
236
+
237
+ ### Daemon
238
+
239
+ A supervised long-lived companion process that continuously drains captured
240
+ Moves, accelerates decision-graph reads, and powers the "team: N online"
241
+ presence count. `prim setup` requires it to become healthy unless the explicit
242
+ `--no-daemon` opt-out is supplied; hooks still fail soft if it later degrades.
243
+
244
+ ```bash
245
+ prim daemon start # start (stop / restart / status)
246
+ ```
247
+
248
+ ### Decisions
249
+
250
+ Read and respond to the decision graph.
251
+
252
+ ```bash
253
+ prim decisions recent # Recent decisions feed (--author <name> for one teammate's)
254
+ prim decisions show <id> # Drill into one decision
255
+ prim decisions cascade <id> # Blast radius of a decision
256
+ prim decisions check --files <…> # Active decisions referencing files (warn-only)
257
+ prim decisions confirm <id> # Answer a rationale-confirmation prompt
258
+ prim decisions create --intent <…> --attribution <user|agent> # Record with explicit origin
259
+ prim decisions link <child> --on <parent> # Relate: <child> depends on <parent>
260
+ prim decisions unlink <child> --on <parent> # Remove that dependency
261
+ ```
262
+
263
+ `<id>` accepts a full decision ID or its short ID. STDOUT is machine-readable
264
+ JSON; human-readable status goes to STDERR.
265
+
266
+ When passive capture is inactive in the current repo, an approved one-time create is:
65
267
 
66
268
  ```bash
67
- prim context list # List all contexts
68
- prim context list --scope project # Filter by scope
69
- prim context list --project-id <id> # List contexts for a project
70
- prim context get <id> # Get context details
71
- prim context create -s project -n "Name" # Create a context
72
- prim context create -s project -n "Name" --file path/to/file
73
- prim context update <id> --name "New" # Update a context
74
- prim context delete <id> # Delete a context
75
- prim context link <id> --project <pid> # Link context to project
76
- prim context unlink <id> --project <pid> # Unlink context from project
269
+ npx --yes @primitive.ai/prim@latest --yes decisions create --intent "…" --attribution user
77
270
  ```
78
271
 
79
- ### Projects
272
+ Here npm's first `--yes` only permits package resolution; Prim's second `--yes`
273
+ confirms this create. It does not enable the repo or authorize a later create.
274
+
275
+ Every create requires `--attribution user|agent`. Use `user` only when the person
276
+ directly stated, selected, or confirmed the exact recorded choice. Use `agent` when
277
+ the agent introduced that exact choice while pursuing a broader request. A broad task
278
+ prompt or permission to implement does not make the resulting agent choice a user
279
+ Decision. If the origin is ambiguous, confirm the exact choice with the person before
280
+ creating it; do not guess.
281
+
282
+ `link` / `unlink` curate the dependency edges the automatic linker would otherwise
283
+ own — `<child>` depends on `<parent>`. Both are idempotent and refuse any link that
284
+ would create a cycle (exit 2); an unresolved id exits 4.
285
+
286
+ ### Reconcile
80
287
 
81
288
  ```bash
82
- prim project create -n "Project name" # Create a project
83
- prim project create -n "Project name" -d "Description" # Create with description
84
- prim project create -n "Project name" --spec <contextId> # Create and link a spec
289
+ prim reconcile <id> # Mint a single-use bypass for a decision Conflict Gates flagged
85
290
  ```
86
291
 
292
+ When Conflict Gates **Enforcement** is enabled for your organization, this command
293
+ authorizes one retry for the named decision.
294
+
87
295
  ### Hooks
88
296
 
89
297
  ```bash
90
- prim hooks install # Install pre-commit hook
91
- prim hooks uninstall # Remove pre-commit hook
298
+ prim hooks install # Install git hooks (pre-commit decision check + post-commit capture)
299
+ prim hooks uninstall # Remove the prim git hooks
300
+ ```
301
+
302
+ The pre-commit hook checks staged files against the live decision graph
303
+ (warn-only — it never blocks the commit). The post-commit hook records each
304
+ commit as a capture boundary for classification. Supports
305
+ [Husky](https://typicode.github.io/husky/) — `prim hooks install` detects Husky
306
+ and offers to install into `.husky/`.
307
+
308
+ ### Presence statusline
309
+
310
+ ```bash
311
+ prim statusline # Render the team-presence statusline (reads the daemon)
92
312
  ```
93
313
 
94
- The pre-commit hook automatically syncs specs when you commit changes to files matching a spec's file patterns (configured via `prim spec map`).
314
+ Claude Code and Cursor CLI each have one custom status-line slot. Their user-scope
315
+ installations use a staged, lightweight Primitive renderer when that slot is empty
316
+ or already Primitive's; an existing custom status line is preserved even with
317
+ `--force` and reported explicitly. Cursor's Primitive footer replaces Cursor's
318
+ default footer and requires a Cursor CLI restart after installation or removal. Use
319
+ `prim daemon status` or `prim doctor` for the same health signal in that case.
320
+
321
+ ### Welcome
322
+
323
+ ```bash
324
+ prim welcome # Brief orientation to the decision graph (shown after setup)
325
+ ```
326
+
327
+ ### Session & journal
328
+
329
+ Lower-level plumbing for the capture pipeline — org binding and the local move
330
+ journal. Capture works automatically once the session hooks are installed **and the
331
+ repo is active**; these are for inspecting and steering it (e.g. multi-org machines).
332
+
333
+ ```bash
334
+ prim session start <id> # Pin a Claude Code session to an org (list / drop <id>)
335
+ prim moves bind # Pin the current directory to an org via .prim/workspace.json (drop)
336
+ prim moves status # Per-bucket pending stats for the local journal
337
+ prim moves tail # Pretty-print recent journal entries
338
+ prim moves flush # Drain the local journals to the server (also runs from hooks)
339
+ ```
340
+
341
+ ### Skill
342
+
343
+ ```bash
344
+ prim skill install --agent claude # Install the decision-graph guide for Claude Code
345
+ prim skill install --agent cursor # Install the native Cursor skill
346
+ prim skill install --agent codex # …or write the guide into another agent's rules file
347
+ prim skill uninstall --agent claude # Remove it
348
+ prim skill status --agent claude # Report whether it's installed
349
+ ```
95
350
 
96
- Supports [Husky](https://typicode.github.io/husky/) — `prim hooks install` detects Husky and offers to install into `.husky/pre-commit`.
351
+ Teaches your agent how to work with the decision graph. For **Claude Code**
352
+ (`--agent claude`) this installs a skills-directory plugin at
353
+ `<repo>/.claude/skills/prim/` (or `~/.claude/skills/prim/` with `--scope user`)
354
+ — a `.claude-plugin/plugin.json` + `SKILL.md` that auto-loads as the model-invoked
355
+ `prim@skills-dir` skill, no marketplace step; restart Claude Code or run
356
+ `/reload-plugins` after installing. For **Cursor**, it installs an owned `SKILL.md`
357
+ at `<repo>/.cursor/skills/prim/` (or `~/.cursor/skills/prim/` with `--scope user`)
358
+ without overwriting foreign or locally edited files. For the remaining agents it
359
+ writes a managed block into the rules file that agent reads (`--agent codex` →
360
+ AGENTS.md or `--agent hermes` → .hermes.md). A bare
361
+ `prim skill install` (no `--agent`) auto-detects a rules file and writes the
362
+ block; pass `--target <path>` for an explicit file.
97
363
 
98
364
  ## Development
99
365