@primitive.ai/prim 0.1.0-alpha.123 → 0.1.0-alpha.124

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 +63 -0
  2. package/dist/{chunk-5ME3WD3P.js → chunk-3OKVMKK2.js} +6 -3
  3. package/dist/chunk-5BZWFN62.js +206 -0
  4. package/dist/{chunk-FXXMDO7D.js → chunk-5KPDY5GF.js} +4 -4
  5. package/dist/{chunk-HLMC7VS4.js → chunk-5MH2C5QG.js} +3878 -2644
  6. package/dist/{chunk-NMZSCSMY.js → chunk-6PSCGY2A.js} +11 -1
  7. package/dist/{chunk-OXW6PSPT.js → chunk-6VJ7C2B5.js} +15 -3
  8. package/dist/{chunk-DQ4I3FLF.js → chunk-6W72SEXC.js} +3 -3
  9. package/dist/{chunk-4M23K2KZ.js → chunk-6WKJWW6D.js} +2 -2
  10. package/dist/{chunk-3WQ7SBOZ.js → chunk-A6YTFBQ4.js} +3 -3
  11. package/dist/{chunk-NL5VU7EU.js → chunk-DGZX3MID.js} +3 -3
  12. package/dist/{chunk-4NUGCUQC.js → chunk-EER7VG3P.js} +2 -2
  13. package/dist/{chunk-JZC2LHS6.js → chunk-EWV7VIZ3.js} +1 -1
  14. package/dist/{chunk-WN7OURQ3.js → chunk-KMWXI7KO.js} +1 -1
  15. package/dist/{chunk-LOFMI3D4.js → chunk-KTXJJE5K.js} +2 -2
  16. package/dist/{chunk-4GYJHN26.js → chunk-Q2PVD5W2.js} +1575 -549
  17. package/dist/{chunk-S3ZIMGXV.js → chunk-QZWLZH6D.js} +76 -2
  18. package/dist/{chunk-CWV5ZQR6.js → chunk-TS2NX6YT.js} +5 -5
  19. package/dist/{chunk-GOMEWFMG.js → chunk-WLVEXOHC.js} +143 -61
  20. package/dist/{chunk-RUEIVZ6T.js → chunk-WQFJ5TEG.js} +2 -2
  21. package/dist/{chunk-T2T45KF6.js → chunk-ZMH6GJUG.js} +4 -4
  22. package/dist/daemon/server.js +7795 -5449
  23. package/dist/hook-runtime/daemon/server.js +7795 -5449
  24. package/dist/hook-runtime/hooks/post-commit.js +5828 -4329
  25. package/dist/hook-runtime/hooks/post-rewrite.js +4331 -2833
  26. package/dist/hook-runtime/hooks/post-tool-use.js +5241 -2891
  27. package/dist/hook-runtime/hooks/pre-commit.js +1253 -280
  28. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +4177 -1971
  29. package/dist/hook-runtime/hooks/prim-hook.js +4718 -2478
  30. package/dist/hook-runtime/hooks/session-end.js +392 -139
  31. package/dist/hook-runtime/hooks/session-start.js +4206 -1997
  32. package/dist/hook-runtime/index.js +6155 -3542
  33. package/dist/hook-runtime/statusline-main.js +368 -122
  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 +31 -21
  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 +16 -12
  42. package/dist/index.js +229 -149
  43. package/dist/statusline-main.js +368 -122
  44. package/package.json +3 -1
  45. package/dist/chunk-RRAC76LJ.js +0 -36
package/README.md CHANGED
@@ -660,3 +660,66 @@ characters. Use the same ID in commands and at
660
660
  `shortId` compatibility field contains the eight characters without the prefix.
661
661
  Existing full record IDs remain accepted as inputs. Upgrade the backend before
662
662
  this CLI; an unavailable identity produces an error rather than a storage ID.
663
+
664
+ ### Machine credentials
665
+
666
+ An administrator issues a separate WorkOS M2M application for each installation
667
+ or workload. Configure its application client ID and enter the secret at the
668
+ hidden prompt:
669
+
670
+ ```sh
671
+ prim auth configure-machine --client-id client_APPLICATION
672
+ prim auth status --json
673
+ prim setup
674
+ ```
675
+
676
+ For automated secret delivery, pipe the secret to
677
+ `prim auth configure-machine --client-id client_APPLICATION --client-secret-stdin`.
678
+ Never pass a secret as a command-line argument. CI can instead inject both
679
+ `PRIM_M2M_CLIENT_ID` and `PRIM_M2M_CLIENT_SECRET`, along with the selected
680
+ `PRIM_API_URL`. A complete environment pair overrides saved credentials;
681
+ partial pairs and a conflicting `PRIM_TOKEN` fail explicitly. Injected
682
+ credentials and tokens are never saved. Prim shares only verified identity
683
+ metadata with local hooks, tied to that credential generation and token expiry.
684
+
685
+ Injected credentials share access tokens through an authenticated, memory-only
686
+ local broker. Provider retry delays are shared across processes and survive
687
+ restarts without saving secrets or tokens. The broker runs from the copied
688
+ runtime and exits after five minutes without authenticated requests.
689
+
690
+ On macOS, launchd cannot inherit credentials from your terminal. Stop any
691
+ existing daemon and run `prim daemon start --foreground` in the environment
692
+ that supplies the machine credentials. Restart it with the new environment when
693
+ rotating credentials. Prim rejects launchd configuration in environment mode;
694
+ use saved machine credentials for a daemon that starts across logins.
695
+
696
+ Prim verifies the exchange and the API's protected machine identity before
697
+ activating credentials. It uses the OS credential store by default (persistent
698
+ Secret Service on Linux). If that store is unavailable on initial configuration,
699
+ Prim uses owner-only files in its private configuration directory. Once a store
700
+ is selected, a locked or failing keychain produces a recovery error rather than
701
+ falling back to an old credential. `prim auth clear` removes saved credentials;
702
+ unset injected environment variables separately.
703
+
704
+ Tokens renew with another client-credentials exchange, without refresh tokens.
705
+ Auth status reports identity, organization, effective scopes, storage, and expiry.
706
+ Use `prim doctor` for journal and daemon recovery details (JSON on stdout). Machine access
707
+ covers capture, checks, presence, organization-visible Decision reads, and the
708
+ machine's own Decision lifecycle. Manage GitHub App installation and human API
709
+ keys in the web application; the personal onboarding demo is not a machine task.
710
+
711
+ Flush pending activity under its original credentials before migration where
712
+ possible (`prim moves flush`). Machine capture uses separate, identity-bound
713
+ journals. Legacy activity and activity from another machine are retained rather
714
+ than reassigned. Terminal credential failures pause delivery while local capture
715
+ continues. Ask the administrator to enable or rotate the same machine, then run
716
+ `configure-machine` again. Do not edit or move journal records between identities.
717
+ For injected credentials, restart with the replacement environment. After
718
+ verifying the replacement, the administrator must revoke the old WorkOS client
719
+ secret; clearing local storage does not revoke it.
720
+
721
+ For concurrent backend/CLI development, `pnpm contracts:update --worktree <path>`
722
+ imports an explicitly unpublished backend contract. Canonical provenance remains
723
+ blocked until the backend is published and imported with
724
+ `pnpm contracts:update --revision <full-commit>`. Production releases must pass
725
+ `pnpm contracts:provenance`.
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-HLMC7VS4.js";
3
+ } from "./chunk-5MH2C5QG.js";
4
4
  import {
5
5
  stripControlChars
6
- } from "./chunk-S3ZIMGXV.js";
6
+ } from "./chunk-QZWLZH6D.js";
7
+ import {
8
+ hasMachineConfiguration
9
+ } from "./chunk-Q2PVD5W2.js";
7
10
 
8
11
  // src/lib/delivery-backlog.ts
9
12
  var MS_PER_SECOND = 1e3;
@@ -114,7 +117,7 @@ function formatStatusline(version, snapshot, resolveIngestionStatus, options = {
114
117
  const ingestionSuffix = (status) => status === void 0 ? "" : ` \xB7 Decision ingestion ${status}`;
115
118
  const ingestionStatus = snapshot === null || snapshot.healthy === false ? options.includeIngestionWhenUnavailable ? resolveIngestionStatus() : void 0 : resolveIngestionStatus();
116
119
  if (snapshot?.healthy === false && snapshot.needsReauth) {
117
- return `primitive ${version} (daemon: paused \xB7 run \`prim auth login\`${ingestionSuffix(ingestionStatus)})`;
120
+ return `primitive ${version} (daemon: paused \xB7 run \`${hasMachineConfiguration() ? "prim auth status" : "prim auth login"}\`${ingestionSuffix(ingestionStatus)})`;
118
121
  }
119
122
  const repositoryLabel = repositoryBindingDiagnosticLabel(
120
123
  snapshot !== null && snapshot.healthy !== false || options.includeIngestionWhenUnavailable === true ? options.resolveRepositoryBindingState?.() : void 0
@@ -0,0 +1,206 @@
1
+ import {
2
+ isMoveIngestRequest,
3
+ scheduleCollectScopeRefresh
4
+ } from "./chunk-5MH2C5QG.js";
5
+ import {
6
+ getPinnedClient,
7
+ getSiteUrl
8
+ } from "./chunk-QZWLZH6D.js";
9
+ import {
10
+ machineApiUrl,
11
+ machineJournalBucket,
12
+ parseMachineIdentity
13
+ } from "./chunk-Q2PVD5W2.js";
14
+
15
+ // src/protocol/decision-lifecycle.ts
16
+ var DECISION_LIFECYCLE_PROTOCOL_VERSION = 2;
17
+
18
+ // src/journal-organization.ts
19
+ var ORGANIZATION_BINDING_VERSION = 1;
20
+ var ORGANIZATION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
21
+ var UNBOUND_BUCKET = "_unbound";
22
+ var InvalidJournalEnvelopeError = class extends Error {
23
+ constructor() {
24
+ super("Invalid locally journaled move");
25
+ this.name = "InvalidJournalEnvelopeError";
26
+ }
27
+ };
28
+ function safeOrganizationId(value) {
29
+ return typeof value === "string" && ORGANIZATION_ID_RE.test(value);
30
+ }
31
+ function isCaptureAuthorityKind(value) {
32
+ return value === "workos" || value === "service_token";
33
+ }
34
+ function parseOrganizationBinding(value) {
35
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
36
+ return { state: "server_contract_unavailable" };
37
+ }
38
+ const record = value;
39
+ if (record.organizationBindingVersion === 2) {
40
+ try {
41
+ const principal = record.principal;
42
+ const identity = parseMachineIdentity(record, String(principal.clientId));
43
+ return { state: "current", binding: { captureAuthorityKind: "workos_m2m", ...identity } };
44
+ } catch {
45
+ return { state: "server_contract_unavailable" };
46
+ }
47
+ }
48
+ if (record.authenticated !== true || record.organizationBindingVersion !== ORGANIZATION_BINDING_VERSION || !isCaptureAuthorityKind(record.captureAuthorityKind)) {
49
+ return { state: "server_contract_unavailable" };
50
+ }
51
+ if (record.organizationId === null && record.workosOrganizationId === null) {
52
+ return { state: "no_current_organization" };
53
+ }
54
+ if (safeOrganizationId(record.organizationId) && record.workosOrganizationId === null) {
55
+ return { state: "organization_identity_unreconciled" };
56
+ }
57
+ if (!safeOrganizationId(record.organizationId) || !safeOrganizationId(record.workosOrganizationId)) {
58
+ return { state: "server_contract_unavailable" };
59
+ }
60
+ return {
61
+ state: "current",
62
+ binding: {
63
+ captureAuthorityKind: record.captureAuthorityKind,
64
+ organizationId: record.organizationId,
65
+ workosOrganizationId: record.workosOrganizationId
66
+ }
67
+ };
68
+ }
69
+ function summarizeRetainedBuckets(retained) {
70
+ const counts = /* @__PURE__ */ new Map();
71
+ for (const item of retained) {
72
+ counts.set(item.reason, (counts.get(item.reason) ?? 0) + 1);
73
+ }
74
+ return [...counts].sort(([left], [right]) => left.localeCompare(right)).map(([reason, count]) => `${reason}:${String(count)}`).join(", ");
75
+ }
76
+ function classifyJournalBuckets(buckets, binding) {
77
+ const deliverableBuckets = /* @__PURE__ */ new Set();
78
+ const retainedBuckets = [];
79
+ for (const bucket of [...new Set(buckets)].sort()) {
80
+ if (bucket === UNBOUND_BUCKET) {
81
+ retainedBuckets.push({ bucket, reason: "unbound" });
82
+ continue;
83
+ }
84
+ if (typeof binding === "string") {
85
+ retainedBuckets.push({ bucket, reason: binding });
86
+ continue;
87
+ }
88
+ if (binding.captureAuthorityKind === "workos_m2m") {
89
+ if (binding.clientId && bucket === machineJournalBucket({
90
+ apiUrl: machineApiUrl(getSiteUrl()),
91
+ clientId: binding.clientId
92
+ }))
93
+ deliverableBuckets.add(bucket);
94
+ else
95
+ retainedBuckets.push({
96
+ bucket,
97
+ reason: bucket.startsWith("_machine_") ? "machine_identity_mismatch" : "legacy_authority_retained"
98
+ });
99
+ continue;
100
+ }
101
+ if (bucket.startsWith("_machine_")) {
102
+ retainedBuckets.push({ bucket, reason: "machine_identity_mismatch" });
103
+ continue;
104
+ }
105
+ if (bucket === binding.organizationId || bucket === binding.workosOrganizationId) {
106
+ deliverableBuckets.add(bucket);
107
+ } else {
108
+ retainedBuckets.push({ bucket, reason: "organization_mismatch" });
109
+ }
110
+ }
111
+ return { deliverableBuckets, retainedBuckets };
112
+ }
113
+ function buildOrganizationBoundMoveRequest(batch, binding) {
114
+ const capturedOrganizationId = binding.captureAuthorityKind === "workos" ? binding.workosOrganizationId : binding.organizationId;
115
+ const request = {
116
+ batch: batch.map((move) => {
117
+ if (typeof move !== "object" || move === null || Array.isArray(move)) {
118
+ return move;
119
+ }
120
+ const { captureActor, ...wireMove } = move;
121
+ if (binding.captureAuthorityKind === "workos_m2m") {
122
+ if (!captureActor || captureActor.clientId !== binding.clientId || captureActor.apiUrl !== machineApiUrl(getSiteUrl()) || captureActor.machineId && captureActor.machineId !== binding.machineId || captureActor.organizationId && captureActor.organizationId !== binding.organizationId)
123
+ throw new InvalidJournalEnvelopeError();
124
+ } else if (captureActor) throw new InvalidJournalEnvelopeError();
125
+ return {
126
+ ...wireMove,
127
+ envelopeVersion: binding.captureAuthorityKind === "workos_m2m" ? 5 : 4,
128
+ ...binding.captureAuthorityKind === "workos_m2m" ? { capturedMachineId: binding.machineId } : {},
129
+ capturedOrganizationId,
130
+ captureAuthorityKind: binding.captureAuthorityKind,
131
+ decisionLifecycleProtocolVersion: DECISION_LIFECYCLE_PROTOCOL_VERSION
132
+ };
133
+ })
134
+ };
135
+ if (!isMoveIngestRequest(request)) {
136
+ throw new InvalidJournalEnvelopeError();
137
+ }
138
+ return request;
139
+ }
140
+ async function inspectJournalDelivery(buckets, options = {}) {
141
+ const bucketList = [...new Set(buckets)];
142
+ let client;
143
+ try {
144
+ client = options.client ?? await (options.createClient ?? (() => getPinnedClient()))();
145
+ } catch {
146
+ return classifyJournalBuckets(bucketList, "identity_unavailable");
147
+ }
148
+ let parsed;
149
+ try {
150
+ parsed = parseOrganizationBinding(
151
+ await client.get("/api/cli/auth/status", {
152
+ signal: AbortSignal.timeout(1e4),
153
+ quietRefresh: true
154
+ })
155
+ );
156
+ } catch {
157
+ return classifyJournalBuckets(bucketList, "identity_unavailable");
158
+ }
159
+ if (parsed.state !== "current") {
160
+ return classifyJournalBuckets(bucketList, parsed.state);
161
+ }
162
+ return {
163
+ client,
164
+ binding: parsed.binding,
165
+ ...classifyJournalBuckets(bucketList, parsed.binding)
166
+ };
167
+ }
168
+
169
+ // src/ingest-response.ts
170
+ var IngestAcknowledgementError = class extends Error {
171
+ constructor(message) {
172
+ super(message);
173
+ this.name = "IngestAcknowledgementError";
174
+ }
175
+ };
176
+ function requireDurableIngestAcknowledgement(value, expected, cwd = process.cwd()) {
177
+ if (typeof value !== "object" || value === null) {
178
+ throw new IngestAcknowledgementError("ingest response was not an object");
179
+ }
180
+ const response = value;
181
+ if (response.disposition !== "persisted") {
182
+ throw new IngestAcknowledgementError("ingest response did not confirm persistence");
183
+ }
184
+ if (response.acknowledged !== expected) {
185
+ throw new IngestAcknowledgementError(
186
+ `ingest acknowledged ${String(response.acknowledged)} of ${String(expected)} moves`
187
+ );
188
+ }
189
+ if (typeof response.collectScopeVersion === "number" && Number.isSafeInteger(response.collectScopeVersion) && response.collectScopeVersion >= 0) {
190
+ const roots = typeof cwd === "string" ? [cwd] : cwd;
191
+ for (const root of new Set(roots)) {
192
+ scheduleCollectScopeRefresh(root, response.collectScopeVersion);
193
+ }
194
+ }
195
+ return value;
196
+ }
197
+
198
+ export {
199
+ InvalidJournalEnvelopeError,
200
+ parseOrganizationBinding,
201
+ summarizeRetainedBuckets,
202
+ classifyJournalBuckets,
203
+ buildOrganizationBoundMoveRequest,
204
+ inspectJournalDelivery,
205
+ requireDurableIngestAcknowledgement
206
+ };
@@ -4,20 +4,20 @@ import {
4
4
  import {
5
5
  analyzeShellTargets,
6
6
  extractFileTargets
7
- } from "./chunk-3WQ7SBOZ.js";
7
+ } from "./chunk-A6YTFBQ4.js";
8
8
  import {
9
9
  scrubEnvironmentPaths
10
- } from "./chunk-4NUGCUQC.js";
10
+ } from "./chunk-EER7VG3P.js";
11
11
  import {
12
12
  cachedCollectScopeAdmits
13
- } from "./chunk-HLMC7VS4.js";
13
+ } from "./chunk-5MH2C5QG.js";
14
14
  import {
15
15
  canonicalRepositoryPath,
16
16
  currentBranch,
17
17
  isRepoActiveForCapture,
18
18
  relatedWorktreeTarget,
19
19
  repoSyncId
20
- } from "./chunk-4GYJHN26.js";
20
+ } from "./chunk-Q2PVD5W2.js";
21
21
 
22
22
  // src/hooks/file-refs.ts
23
23
  var MAX_PREFLIGHT_FILE_TARGETS = 25;