@primitive.ai/prim 0.1.0-alpha.8 → 0.1.0-alpha.81

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