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

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 +27 -0
  2. package/dist/{chunk-WQFJ5TEG.js → chunk-2BEUR3DU.js} +2 -2
  3. package/dist/{chunk-3OKVMKK2.js → chunk-6KXQQ7CQ.js} +3 -3
  4. package/dist/{chunk-TS2NX6YT.js → chunk-6OPSSJHO.js} +5 -5
  5. package/dist/{chunk-EER7VG3P.js → chunk-74DQDWLW.js} +2 -2
  6. package/dist/{chunk-KMWXI7KO.js → chunk-BFYJLI7V.js} +1 -1
  7. package/dist/{chunk-ZMH6GJUG.js → chunk-DT7E3SD5.js} +4 -4
  8. package/dist/{chunk-6W72SEXC.js → chunk-EZXIKEMA.js} +3 -3
  9. package/dist/{chunk-6WKJWW6D.js → chunk-FYYHBOOM.js} +2 -2
  10. package/dist/{chunk-A6YTFBQ4.js → chunk-HPA7RGSZ.js} +3 -3
  11. package/dist/{chunk-DGZX3MID.js → chunk-JFWJN2ME.js} +3 -3
  12. package/dist/{chunk-WLVEXOHC.js → chunk-L32WYFJT.js} +1 -1
  13. package/dist/{chunk-6VJ7C2B5.js → chunk-NBNQI3YJ.js} +2 -2
  14. package/dist/{chunk-KTXJJE5K.js → chunk-ND6TYHNI.js} +2 -2
  15. package/dist/{chunk-Q2PVD5W2.js → chunk-NJBN3WXF.js} +37 -5
  16. package/dist/{chunk-5MH2C5QG.js → chunk-O73J3KQQ.js} +7121 -5513
  17. package/dist/{chunk-EWV7VIZ3.js → chunk-PPZ56EVJ.js} +1 -1
  18. package/dist/{chunk-5KPDY5GF.js → chunk-R35M4RCY.js} +4 -4
  19. package/dist/{chunk-5BZWFN62.js → chunk-TI37ME2D.js} +12 -8
  20. package/dist/{chunk-6PSCGY2A.js → chunk-YP4OXKNX.js} +4 -2
  21. package/dist/{chunk-QZWLZH6D.js → chunk-ZKXNJB6U.js} +3 -3
  22. package/dist/daemon/server.js +7128 -5507
  23. package/dist/hook-runtime/daemon/server.js +7128 -5507
  24. package/dist/hook-runtime/hooks/post-commit.js +7106 -5496
  25. package/dist/hook-runtime/hooks/post-rewrite.js +7106 -5496
  26. package/dist/hook-runtime/hooks/post-tool-use.js +3595 -1977
  27. package/dist/hook-runtime/hooks/pre-commit.js +17 -7
  28. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +7112 -5500
  29. package/dist/hook-runtime/hooks/prim-hook.js +7117 -5502
  30. package/dist/hook-runtime/hooks/session-end.js +11 -4
  31. package/dist/hook-runtime/hooks/session-start.js +3584 -1970
  32. package/dist/hook-runtime/index.js +6376 -4464
  33. package/dist/hook-runtime/statusline-main.js +11 -4
  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 +15 -15
  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 +11 -11
  42. package/dist/index.js +9117 -8836
  43. package/dist/statusline-main.js +11 -4
  44. package/package.json +1 -1
package/README.md CHANGED
@@ -723,3 +723,30 @@ imports an explicitly unpublished backend contract. Canonical provenance remains
723
723
  blocked until the backend is published and imported with
724
724
  `pnpm contracts:update --revision <full-commit>`. Production releases must pass
725
725
  `pnpm contracts:provenance`.
726
+
727
+ ### Developer installation enrollment
728
+
729
+ When automatic enrollment is enabled by your organization, run `prim setup`.
730
+ Sign in once and select your organization; Prim registers this installation and
731
+ stores its machine credentials in the OS credential store (or the existing private
732
+ file fallback). Repeated setup reuses the installation. No WorkOS dashboard access
733
+ or copying of client secrets is required. `prim auth enroll` also enrolls an already
734
+ signed-in installation.
735
+
736
+ The installation authenticates the request while your account owns the Decisions.
737
+ Your private drafts, existing Decisions, and normal lifecycle permissions remain
738
+ available. Human/agent attribution and adoption rules stay the same. The installation
739
+ is recorded as provenance. Administrators can manage enrollment policy and revoke
740
+ installations in the web application's Settings → Developer installations.
741
+
742
+ Setup attempts to deliver pending legacy captures before changing credentials.
743
+ Any remaining activity stays under its original authorization; inspect it with
744
+ `prim moves status`. It is never uploaded under newly assigned authorship.
745
+ `prim auth status` reports the installation, authorized user, storage backend, and
746
+ expiry without revealing credentials. If older-secret retirement is pending, rerun
747
+ `prim auth enroll` to retry it.
748
+
749
+ On a server without enrollment, setup retains legacy authentication. Existing
750
+ manually configured machines and CI credentials remain service identities; routine
751
+ setup does not convert them into developer installations. GitHub installation and
752
+ API-key administration remain available in the web application.
@@ -11,10 +11,10 @@ import {
11
11
  saveRun,
12
12
  sessionExcluded,
13
13
  sessionKey
14
- } from "./chunk-A6YTFBQ4.js";
14
+ } from "./chunk-HPA7RGSZ.js";
15
15
  import {
16
16
  packageVersion
17
- } from "./chunk-Q2PVD5W2.js";
17
+ } from "./chunk-NJBN3WXF.js";
18
18
 
19
19
  // src/demo/isolation.ts
20
20
  import { existsSync } from "fs";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-5MH2C5QG.js";
3
+ } from "./chunk-O73J3KQQ.js";
4
4
  import {
5
5
  stripControlChars
6
- } from "./chunk-QZWLZH6D.js";
6
+ } from "./chunk-ZKXNJB6U.js";
7
7
  import {
8
8
  hasMachineConfiguration
9
- } from "./chunk-Q2PVD5W2.js";
9
+ } from "./chunk-NJBN3WXF.js";
10
10
 
11
11
  // src/lib/delivery-backlog.ts
12
12
  var MS_PER_SECOND = 1e3;
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  analyzeShellTargets,
3
3
  extractFileTargets
4
- } from "./chunk-A6YTFBQ4.js";
4
+ } from "./chunk-HPA7RGSZ.js";
5
5
  import {
6
6
  DEFAULT_RULES,
7
7
  scrub
8
- } from "./chunk-EER7VG3P.js";
8
+ } from "./chunk-74DQDWLW.js";
9
9
  import {
10
10
  boundedHealthError,
11
11
  isPreflightResponseV4
12
- } from "./chunk-5MH2C5QG.js";
12
+ } from "./chunk-O73J3KQQ.js";
13
13
  import {
14
14
  getClient,
15
15
  terminalSafeLine
16
- } from "./chunk-QZWLZH6D.js";
16
+ } from "./chunk-ZKXNJB6U.js";
17
17
  import {
18
18
  canonicalGitRoot,
19
19
  canonicalRepositoryPath
20
- } from "./chunk-Q2PVD5W2.js";
20
+ } from "./chunk-NJBN3WXF.js";
21
21
 
22
22
  // src/hooks/approval-copy.ts
23
23
  var MAX_EXCERPT_CHARS = 80;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-5MH2C5QG.js";
3
+ } from "./chunk-O73J3KQQ.js";
4
4
  import {
5
5
  terminalSafeLine
6
- } from "./chunk-QZWLZH6D.js";
6
+ } from "./chunk-ZKXNJB6U.js";
7
7
 
8
8
  // src/hooks/redact.ts
9
9
  import { existsSync, readFileSync, statSync } from "fs";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  atomicWriteFile,
3
3
  repoActiveFlag
4
- } from "./chunk-Q2PVD5W2.js";
4
+ } from "./chunk-NJBN3WXF.js";
5
5
 
6
6
  // src/lib/commit-heartbeat.ts
7
7
  import { execFileSync } from "child_process";
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  formatStatusline
3
- } from "./chunk-3OKVMKK2.js";
3
+ } from "./chunk-6KXQQ7CQ.js";
4
4
  import {
5
5
  daemonPrincipalsMatch,
6
6
  daemonRequest,
7
7
  resolveDaemonPrincipal
8
- } from "./chunk-6PSCGY2A.js";
8
+ } from "./chunk-YP4OXKNX.js";
9
9
  import {
10
10
  getSiteUrl,
11
11
  isSessionEnded,
12
12
  terminalSafeText
13
- } from "./chunk-QZWLZH6D.js";
13
+ } from "./chunk-ZKXNJB6U.js";
14
14
  import {
15
15
  decisionIngestionStatus,
16
16
  gitToplevel,
@@ -18,7 +18,7 @@ import {
18
18
  primConfigDirectory,
19
19
  repositoryBindingState,
20
20
  withFileLock
21
- } from "./chunk-Q2PVD5W2.js";
21
+ } from "./chunk-NJBN3WXF.js";
22
22
 
23
23
  // src/hooks/codex-context.ts
24
24
  import { createHash, randomBytes as randomBytes2 } from "crypto";
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  daemonRequest
3
- } from "./chunk-6PSCGY2A.js";
3
+ } from "./chunk-YP4OXKNX.js";
4
4
  import {
5
5
  getClient,
6
6
  getSiteUrl,
7
7
  terminalSafeLine
8
- } from "./chunk-QZWLZH6D.js";
8
+ } from "./chunk-ZKXNJB6U.js";
9
9
  import {
10
10
  canonicalGitRoot,
11
11
  canonicalRepositoryPath,
12
12
  currentBranch,
13
13
  repoSyncId
14
- } from "./chunk-Q2PVD5W2.js";
14
+ } from "./chunk-NJBN3WXF.js";
15
15
 
16
16
  // src/daemon/proxy.ts
17
17
  var DAEMON_HTTP_TIMEOUT_MS = 1e4;
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-EZXEWFDG.js";
4
4
  import {
5
5
  scrubEnvironmentPaths
6
- } from "./chunk-EER7VG3P.js";
6
+ } from "./chunk-74DQDWLW.js";
7
7
  import {
8
8
  isValidRepoSyncId
9
- } from "./chunk-Q2PVD5W2.js";
9
+ } from "./chunk-NJBN3WXF.js";
10
10
 
11
11
  // src/hooks/prim-hook-core.ts
12
12
  import { createHash, randomUUID } from "crypto";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  inspectHookRuntime
3
- } from "./chunk-WLVEXOHC.js";
3
+ } from "./chunk-L32WYFJT.js";
4
4
  import {
5
5
  isDemoStatusResponse
6
- } from "./chunk-5MH2C5QG.js";
6
+ } from "./chunk-O73J3KQQ.js";
7
7
  import {
8
8
  atomicWriteFile,
9
9
  primConfigDirectory,
10
10
  withFileLock,
11
11
  withFileLockSync
12
- } from "./chunk-Q2PVD5W2.js";
12
+ } from "./chunk-NJBN3WXF.js";
13
13
 
14
14
  // src/hooks/pre-tool-use-scoring.ts
15
15
  import { isAbsolute, relative, sep } from "path";
@@ -9,11 +9,11 @@ import {
9
9
  hookBlockContractVersion,
10
10
  inspectGitHookEntrypoint,
11
11
  managedHookBlock
12
- } from "./chunk-WLVEXOHC.js";
12
+ } from "./chunk-L32WYFJT.js";
13
13
  import {
14
14
  HttpError,
15
15
  getClient
16
- } from "./chunk-QZWLZH6D.js";
16
+ } from "./chunk-ZKXNJB6U.js";
17
17
  import {
18
18
  atomicWriteFile,
19
19
  binFile,
@@ -27,7 +27,7 @@ import {
27
27
  setRepoSyncId,
28
28
  setRepositoryBindingState,
29
29
  withFileLock
30
- } from "./chunk-Q2PVD5W2.js";
30
+ } from "./chunk-NJBN3WXF.js";
31
31
 
32
32
  // src/commands/skill.ts
33
33
  import { createHash as createHash3 } from "crypto";
@@ -16,7 +16,7 @@ import {
16
16
  syncDirectory,
17
17
  syncFile,
18
18
  withFileLockSync
19
- } from "./chunk-Q2PVD5W2.js";
19
+ } from "./chunk-NJBN3WXF.js";
20
20
 
21
21
  // src/commands/claude-install.ts
22
22
  import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getSiteUrl
3
- } from "./chunk-QZWLZH6D.js";
3
+ } from "./chunk-ZKXNJB6U.js";
4
4
  import {
5
5
  atomicWriteFile,
6
6
  ensureDurableDirectory,
@@ -11,7 +11,7 @@ import {
11
11
  machineJournalBucket,
12
12
  primConfigDirectory,
13
13
  resolveAuthCredential
14
- } from "./chunk-Q2PVD5W2.js";
14
+ } from "./chunk-NJBN3WXF.js";
15
15
 
16
16
  // src/journal.ts
17
17
  import {
@@ -2,10 +2,10 @@ import {
2
2
  cursorHooksPath,
3
3
  hasExactCursorHandler,
4
4
  readCursorHooks
5
- } from "./chunk-WLVEXOHC.js";
5
+ } from "./chunk-L32WYFJT.js";
6
6
  import {
7
7
  resolveRepositoryContext
8
- } from "./chunk-Q2PVD5W2.js";
8
+ } from "./chunk-NJBN3WXF.js";
9
9
 
10
10
  // src/hooks/cursor-coexistence.ts
11
11
  var CURSOR_EVENTS = /* @__PURE__ */ new Set([
@@ -1236,7 +1236,11 @@ function parseMachineConfiguration(value) {
1236
1236
  "The WorkOS issuer must be an HTTPS origin."
1237
1237
  );
1238
1238
  }
1239
- return { issuer: record.issuer, audience: record.audience };
1239
+ return {
1240
+ issuer: record.issuer,
1241
+ audience: record.audience,
1242
+ ...record.developer_enrollment === true ? { developerEnrollment: true } : {}
1243
+ };
1240
1244
  }
1241
1245
  function machineSignal(signal) {
1242
1246
  return signal ? AbortSignal.any([signal, AbortSignal.timeout(1e4)]) : AbortSignal.timeout(1e4);
@@ -1336,7 +1340,7 @@ async function exchangeMachineCredentials(configuration, clientId, clientSecret,
1336
1340
  function parseMachineIdentity(value, clientId) {
1337
1341
  const data = machineRecord(value);
1338
1342
  const principal = machineRecord(data.principal);
1339
- if (data.authenticated !== true || data.captureAuthorityKind !== "workos_m2m" || data.organizationBindingVersion !== 2 || principal.kind !== "machine" || principal.clientId !== clientId || !machineString(principal.machineId, 256) || !machineString(principal.displayName, 256) || !machineString(data.organizationId, 256) || !machineString(data.workosOrganizationId, 256) || !Array.isArray(principal.scopes) || !principal.scopes.every((scope) => machineString(scope, 128))) {
1343
+ if (data.authenticated !== true || data.captureAuthorityKind !== "workos_m2m" || ![2, 3].includes(data.organizationBindingVersion) || (data.organizationBindingVersion === 3 ? !machineString(principal.authorizedUserId, 256) : principal.authorizedUserId !== void 0) || principal.kind !== "machine" || principal.clientId !== clientId || !machineString(principal.machineId, 256) || !machineString(principal.displayName, 256) || !machineString(data.organizationId, 256) || !machineString(data.workosOrganizationId, 256) || !Array.isArray(principal.scopes) || !principal.scopes.every((scope) => machineString(scope, 128))) {
1340
1344
  throw new MachineAuthError(
1341
1345
  "machine_identity_rejected",
1342
1346
  "The API did not verify a machine identity.",
@@ -1345,6 +1349,7 @@ function parseMachineIdentity(value, clientId) {
1345
1349
  }
1346
1350
  return {
1347
1351
  machineId: principal.machineId,
1352
+ ...data.organizationBindingVersion === 3 ? { authorizedUserId: principal.authorizedUserId } : {},
1348
1353
  clientId,
1349
1354
  displayName: principal.displayName,
1350
1355
  organizationId: data.organizationId,
@@ -1671,6 +1676,7 @@ function writeEnvironmentContext(credential, deps) {
1671
1676
  organizationId,
1672
1677
  workosOrganizationId,
1673
1678
  displayName,
1679
+ authorizedUserId,
1674
1680
  scopes,
1675
1681
  expiresAt
1676
1682
  } = credential;
@@ -1686,6 +1692,7 @@ function writeEnvironmentContext(credential, deps) {
1686
1692
  organizationId,
1687
1693
  workosOrganizationId,
1688
1694
  displayName,
1695
+ authorizedUserId,
1689
1696
  scopes,
1690
1697
  expiresAt
1691
1698
  });
@@ -1783,7 +1790,7 @@ function parseStoredIdentity(data) {
1783
1790
  return parseMachineIdentity(
1784
1791
  {
1785
1792
  authenticated: true,
1786
- organizationBindingVersion: 2,
1793
+ organizationBindingVersion: data.authorizedUserId ? 3 : 2,
1787
1794
  captureAuthorityKind: "workos_m2m",
1788
1795
  organizationId: data.organizationId,
1789
1796
  workosOrganizationId: data.workosOrganizationId,
@@ -1891,6 +1898,7 @@ async function loadRecord(profile, deps, signal) {
1891
1898
  "generation",
1892
1899
  "storage",
1893
1900
  "machineId",
1901
+ "authorizedUserId",
1894
1902
  "clientId",
1895
1903
  "organizationId",
1896
1904
  "workosOrganizationId"
@@ -1961,6 +1969,18 @@ async function configureMachine(clientId, clientSecret, deps = {}, signal) {
1961
1969
  signal,
1962
1970
  deps.fetch
1963
1971
  );
1972
+ if (deps.expectedAuthorizedUserId && identity2.authorizedUserId !== deps.expectedAuthorizedUserId)
1973
+ throw new MachineAuthError(
1974
+ "delegation_mismatch",
1975
+ "The enrolled installation does not have the expected user delegation.",
1976
+ true
1977
+ );
1978
+ if (deps.expectedOrganizationId && identity2.organizationId !== deps.expectedOrganizationId)
1979
+ throw new MachineAuthError(
1980
+ "delegation_mismatch",
1981
+ "The installation belongs to a different organization.",
1982
+ true
1983
+ );
1964
1984
  return { configuration: configuration2, tokens: tokens2, identity: identity2 };
1965
1985
  }
1966
1986
  );
@@ -2128,7 +2148,7 @@ async function acquireMachineCredential(options = {}, deps = {}) {
2128
2148
  return { tokens: tokens2, identity: identity2 };
2129
2149
  }
2130
2150
  );
2131
- if (identity.machineId !== profile.machineId || identity.organizationId !== profile.organizationId || identity.workosOrganizationId !== profile.workosOrganizationId)
2151
+ if (identity.machineId !== profile.machineId || identity.authorizedUserId !== profile.authorizedUserId || identity.organizationId !== profile.organizationId || identity.workosOrganizationId !== profile.workosOrganizationId)
2132
2152
  throw new MachineAuthError(
2133
2153
  "identity_changed",
2134
2154
  "Machine identity changed; configure the new identity explicitly.",
@@ -2189,13 +2209,14 @@ function machineCaptureActor(deps = {}) {
2189
2209
  clientId: context.clientId,
2190
2210
  issuer: context.issuer,
2191
2211
  machineId: context.machineId,
2212
+ authorizedUserId: context.authorizedUserId,
2192
2213
  organizationId: context.organizationId
2193
2214
  };
2194
2215
  const injected = environmentCredentials(deps);
2195
2216
  return injected ? { kind: "machine", apiUrl: apiUrlFor(deps), clientId: injected.clientId } : void 0;
2196
2217
  }
2197
2218
  function machineJournalBucket(identity) {
2198
- return `_machine_${hash(`${identity.apiUrl}\0${identity.clientId}`)}`;
2219
+ return `_machine_${hash(`${identity.apiUrl}\0${identity.clientId}${identity.authorizedUserId ? `\0${identity.authorizedUserId}` : ""}`)}`;
2199
2220
  }
2200
2221
  function readRetiredProfiles(directory) {
2201
2222
  const value = readPrivate(join7(directory, "machine_retired.json"));
@@ -2224,6 +2245,12 @@ async function cleanupRetired(deps, signal) {
2224
2245
  if (pending.length) writePrivate(path, pending);
2225
2246
  else rmSync5(path, { force: true });
2226
2247
  }
2248
+ function prepareMachineMetadataDirectory(directory) {
2249
+ ensureDirectory(directory);
2250
+ }
2251
+ function writeMachineMetadata(path, value) {
2252
+ writePrivate(path, value);
2253
+ }
2227
2254
 
2228
2255
  // src/lib/credentials.ts
2229
2256
  import { createHash as createHash5 } from "crypto";
@@ -2407,7 +2434,10 @@ export {
2407
2434
  parseWorkosConnectTokens,
2408
2435
  pollWorkosDeviceAuthorization,
2409
2436
  MachineAuthError,
2437
+ machineString,
2438
+ machineRecord,
2410
2439
  machineApiUrl,
2440
+ discoverMachineConfiguration,
2411
2441
  parseMachineIdentity,
2412
2442
  verifyMachineIdentity,
2413
2443
  primConfigDirectory,
@@ -2422,6 +2452,8 @@ export {
2422
2452
  clearMachineCredentials,
2423
2453
  machineCaptureActor,
2424
2454
  machineJournalBucket,
2455
+ prepareMachineMetadataDirectory,
2456
+ writeMachineMetadata,
2425
2457
  TOKEN_FILE_PATH,
2426
2458
  REFRESH_TOKEN_PATH,
2427
2459
  TOKEN_EXPIRES_PATH,