@primitive.ai/prim 0.1.0-alpha.127 → 0.1.0-alpha.129

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 (44) hide show
  1. package/README.md +76 -5
  2. package/dist/{chunk-HZI5PBN4.js → chunk-BVGASV3B.js} +2047 -138
  3. package/dist/{chunk-72NIZMZN.js → chunk-DYXCJ6WZ.js} +15 -10
  4. package/dist/{chunk-TNWI3JWK.js → chunk-FHDTJP2C.js} +4 -2
  5. package/dist/{chunk-C4QNBSWB.js → chunk-HDL3UXYJ.js} +8 -8
  6. package/dist/{chunk-RV3JFSMX.js → chunk-IJ3W2YBM.js} +4 -4
  7. package/dist/{chunk-O65UVJZH.js → chunk-IZAEAALI.js} +2 -2
  8. package/dist/{chunk-H74RDXKP.js → chunk-KZNOT2YH.js} +2 -2
  9. package/dist/{chunk-R4EYLEIK.js → chunk-L7U3G4XR.js} +2 -2
  10. package/dist/{chunk-MGKSZSTV.js → chunk-LBZJD2I4.js} +3 -5
  11. package/dist/{chunk-UUQT5GMO.js → chunk-MMMY57UA.js} +22 -837
  12. package/dist/{chunk-H6X52UVF.js → chunk-NWWTFQP2.js} +1 -1
  13. package/dist/{chunk-WGTUNUIS.js → chunk-QSDWWEHF.js} +5 -5
  14. package/dist/{chunk-NVDPKW7Z.js → chunk-RAEOSDQ6.js} +3 -51
  15. package/dist/{chunk-KFRGVHGB.js → chunk-RS5ADTDF.js} +6 -6
  16. package/dist/{chunk-A5VTE43F.js → chunk-RWJ7WHTJ.js} +2 -2
  17. package/dist/{chunk-VVFVENU4.js → chunk-SJE7OWVS.js} +6 -6
  18. package/dist/{chunk-L6IL4N6Y.js → chunk-USJ4JGDC.js} +34 -34
  19. package/dist/{chunk-JCKOW45X.js → chunk-YPHDV5AS.js} +2 -2
  20. package/dist/{chunk-F3FDVHR7.js → chunk-YSV43WLK.js} +1 -1
  21. package/dist/{chunk-URYZDQFH.js → chunk-ZKIBD5MO.js} +3 -5
  22. package/dist/daemon/server.js +1769 -487
  23. package/dist/hook-runtime/daemon/server.js +1769 -487
  24. package/dist/hook-runtime/hooks/post-commit.js +611 -337
  25. package/dist/hook-runtime/hooks/post-rewrite.js +606 -332
  26. package/dist/hook-runtime/hooks/post-tool-use.js +1841 -683
  27. package/dist/hook-runtime/hooks/pre-commit.js +1713 -434
  28. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +1308 -150
  29. package/dist/hook-runtime/hooks/prim-hook.js +1863 -705
  30. package/dist/hook-runtime/hooks/session-end.js +538 -385
  31. package/dist/hook-runtime/hooks/session-start.js +1379 -233
  32. package/dist/hook-runtime/index.js +5438 -4052
  33. package/dist/hook-runtime/statusline-main.js +547 -273
  34. package/dist/hooks/post-commit.js +7 -7
  35. package/dist/hooks/post-rewrite.js +6 -6
  36. package/dist/hooks/post-tool-use.js +18 -18
  37. package/dist/hooks/pre-commit.js +4 -4
  38. package/dist/hooks/pre-tool-use-worker.js +9 -9
  39. package/dist/hooks/prim-hook.js +16 -16
  40. package/dist/hooks/session-end.js +4 -4
  41. package/dist/hooks/session-start.js +64 -22
  42. package/dist/index.js +396 -52
  43. package/dist/statusline-main.js +547 -273
  44. package/package.json +1 -1
package/README.md CHANGED
@@ -158,20 +158,21 @@ step-by-step the agent follows — and the manual fallback — live in
158
158
 
159
159
  Prim runs in [Claude Code cloud sessions](https://code.claude.com/docs/en/claude-code-on-the-web).
160
160
  Configure it once; each session then connects without manual steps. The repository must
161
- already be connected to Primitive (`prim github connect`, from your own machine).
161
+ already be connected to Primitive (`npx --yes @primitive.ai/prim@latest github connect`
162
+ in a clone of it, from your own machine).
162
163
 
163
164
  1. **Mint credentials for the environment** on your own machine. This signs you in once,
164
165
  enrolls a separate installation in your name, and prints its credentials. Nothing is
165
166
  stored locally, and your machine's own credentials are untouched:
166
167
 
167
168
  ```bash
168
- prim auth enroll --new-installation "Claude Code cloud" --print-env
169
+ npx --yes @primitive.ai/prim@latest auth enroll --new-installation "Claude Code cloud" --print-env
169
170
  ```
170
171
 
171
172
  2. **Configure the [cloud environment](https://code.claude.com/docs/en/cloud-environments)**:
172
173
  - **Network access**: Limited, with `api.getprimitive.ai` and `signin.getprimitive.ai`
173
174
  under Allowed domains (both are blocked by default), and **Allow package managers**
174
- left on so the setup script can install prim. A change to Allowed domains reaches
175
+ left on so the setup script can fetch prim. A change to Allowed domains reaches
175
176
  prim only in sessions started after it: a running session keeps the network rules
176
177
  it started with.
177
178
  - **Credentials**: give the secret to the environment's proxy, which no session can
@@ -194,10 +195,15 @@ already be connected to Primitive (`prim github connect`, from your own machine)
194
195
  ```bash
195
196
  #!/bin/bash
196
197
  set -euo pipefail
197
- npm install -g @primitive.ai/prim@latest
198
- prim setup --cloud --prepare
198
+ npx --yes @primitive.ai/prim@latest setup --cloud --prepare
199
199
  ```
200
200
 
201
+ No global install is needed: the hooks run from a runtime `--prepare` stages in
202
+ the image, and in a session prim's commands run as
203
+ `npx --yes @primitive.ai/prim@latest ...`. To have `prim` on the VM's PATH as well,
204
+ use `npm install -g @primitive.ai/prim@latest` followed by
205
+ `prim setup --cloud --prepare` instead.
206
+
201
207
  `--prepare` needs no credentials or network to Primitive. It wires prim into the
202
208
  VM's user-scope Claude Code settings, which every session reads at startup, so
203
209
  repositories need no commit. It marks the environment so sessions activate the
@@ -280,6 +286,68 @@ repository in Claude Code; where prim is not installed they do nothing. Upgrade
280
286
  across a team before committing a new project install: older releases fail `prim doctor`
281
287
  on such a file, and the reinstall they suggest restores the earlier text.
282
288
 
289
+ #### An environment your organization shares
290
+
291
+ The credentials above belong to one person: in an environment several people use, every
292
+ session's work would be attributed to whoever minted them. For an environment the whole
293
+ organization shares, an organization admin creates an environment credential instead.
294
+ It can do one thing: identify sessions. Each session's work is then attributed to the
295
+ member who started it.
296
+
297
+ 1. **The admin creates the credential once**, on their own machine:
298
+
299
+ ```bash
300
+ npx --yes @primitive.ai/prim@latest auth enroll --new-environment "Team cloud" --print-env
301
+ ```
302
+
303
+ It prints `PRIM_M2M_CLIENT_ID`, `PRIM_M2M_CLIENT_SECRET`, and
304
+ `PRIM_CLOUD_IDENTITY=session` (plus `PRIM_API_URL` for a non-default deployment).
305
+
306
+ 2. **The admin configures the shared environment** as in the steps above, with these
307
+ differences:
308
+ - **Credentials**: every member can read a shared environment's variables, so hold
309
+ the secret as a **Username and password** network secret for host
310
+ `signin.getprimitive.ai` (username: the client ID, password: the client secret).
311
+ Set these **Environment variables**, keeping any other line the command printed
312
+ except `PRIM_M2M_CLIENT_SECRET`:
313
+
314
+ ```text
315
+ PRIM_M2M_CLIENT_ID=client_...
316
+ PRIM_M2M_CLIENT_AUTH=network-secret
317
+ PRIM_CLOUD_IDENTITY=session
318
+ ```
319
+
320
+ Put `PRIM_M2M_CLIENT_SECRET` in the variables only in an environment no one else
321
+ uses.
322
+ - **Network access** and the **Setup script** are the same as above:
323
+ `api.getprimitive.ai` and `signin.getprimitive.ai` under Allowed domains, and
324
+ `npx --yes @primitive.ai/prim@latest setup --cloud --prepare`.
325
+
326
+ 3. **Each member links their GitHub account once**, in their first session. Session
327
+ start tells them their GitHub account is not linked yet; the agent runs
328
+ `prim auth link`, which prints a sign-in URL and a code. The member signs in to
329
+ Primitive as themselves, and the session is attributed to them from then on. The
330
+ sign-in is used for the link alone and is not stored.
331
+
332
+ After that, every session identifies its member with no action. At the start of each
333
+ session, prim creates the session's `claude/…` branch on GitHub at its starting commit
334
+ (Claude Code would create the same branch when it first pushes); Claude Code pushes as
335
+ the GitHub account of the person who started the session, which is how Primitive learns
336
+ whose session it is. Prim never force-pushes it, sets no upstream, and pushes nothing
337
+ else. The member's token stays in the session's VM (owner-only, in prim's config
338
+ directory) and lasts 12 hours, renewed while the session runs; a new session identifies
339
+ again. Until a session is identified, nothing it captures is sent to Primitive, and a
340
+ session that never identifies sends nothing as anyone.
341
+
342
+ `prim setup --cloud` reports this as its `identity` step, `prim auth status` names the
343
+ member the session acts as, and `prim doctor`'s `auth` line names the person the
344
+ session is attributed to. Identification fails, with the fix named, when the session's
345
+ checkout is not on its `claude/…` branch, when that branch is already on GitHub (a
346
+ resumed session whose token lapsed, or one whose branch was pushed first: start a new
347
+ session), when the push is refused, when GitHub's notice of the push does not reach
348
+ Primitive within 15 seconds (check that Primitive's GitHub App has access to the
349
+ repository), or when the repository is not connected to Primitive.
350
+
283
351
  ## Commands
284
352
 
285
353
  ### Setup
@@ -328,6 +396,9 @@ prim auth set-token <token> # Save a bearer token (e.g. for CI)
328
396
  prim auth clear # Remove saved tokens
329
397
  prim auth status # Check authentication status
330
398
  prim auth enroll --new-installation <name> --print-env # Credentials for a cloud environment
399
+ prim auth enroll --new-environment <name> --print-env # Organization credential for a shared cloud environment
400
+ prim auth identify # Identify who started this cloud session (shared environments)
401
+ prim auth link # Link your GitHub account to Primitive, once, from a cloud session
331
402
  prim auth api-keys mint --name <name> [--expires-at <epoch-ms>] # Mint a user key; secret prints once
332
403
  prim auth api-keys list [--limit <count>] [--after <api-key-id>] # List user-key metadata
333
404
  prim auth api-keys revoke <api-key-id> # Revoke a user key