@primitive.ai/prim 0.1.0-alpha.122 → 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 (47) hide show
  1. package/README.md +81 -5
  2. package/dist/{chunk-5ME3WD3P.js → chunk-3OKVMKK2.js} +6 -3
  3. package/dist/chunk-5BZWFN62.js +206 -0
  4. package/dist/{chunk-QG3GASJO.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-JYPVPYW3.js → chunk-A6YTFBQ4.js} +3 -3
  11. package/dist/{chunk-7LXRFXZG.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-HG7FJK7R.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-ZQ7UK5US.js → chunk-TS2NX6YT.js} +31 -9
  19. package/dist/{chunk-AKGRY7OU.js → chunk-WLVEXOHC.js} +145 -63
  20. package/dist/{chunk-FT673ALA.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 +5242 -2892
  27. package/dist/hook-runtime/hooks/pre-commit.js +1253 -280
  28. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +4272 -1982
  29. package/dist/hook-runtime/hooks/pre-tool-use.js +13 -3
  30. package/dist/hook-runtime/hooks/prim-hook.js +4719 -2479
  31. package/dist/hook-runtime/hooks/session-end.js +393 -140
  32. package/dist/hook-runtime/hooks/session-start.js +4207 -1998
  33. package/dist/hook-runtime/index.js +6157 -3544
  34. package/dist/hook-runtime/statusline-main.js +368 -122
  35. package/dist/hooks/post-commit.js +7 -7
  36. package/dist/hooks/post-rewrite.js +6 -6
  37. package/dist/hooks/post-tool-use.js +31 -21
  38. package/dist/hooks/pre-commit.js +4 -4
  39. package/dist/hooks/pre-tool-use-worker.js +88 -18
  40. package/dist/hooks/pre-tool-use.js +13 -3
  41. package/dist/hooks/prim-hook.js +16 -16
  42. package/dist/hooks/session-end.js +4 -4
  43. package/dist/hooks/session-start.js +16 -12
  44. package/dist/index.js +230 -150
  45. package/dist/statusline-main.js +368 -122
  46. package/package.json +5 -2
  47. package/dist/chunk-RRAC76LJ.js +0 -36
@@ -5,14 +5,20 @@ import {
5
5
  CREDENTIAL_MIGRATION_PATH,
6
6
  CREDENTIAL_MIGRATION_STATE,
7
7
  CREDENTIAL_MIGRATION_VERSION,
8
+ MachineAuthError,
8
9
  REFRESH_TOKEN_PATH,
9
10
  TERMINAL_REFRESH_PATH,
10
11
  TOKEN_EXPIRES_PATH,
11
12
  TOKEN_FILE_PATH,
12
13
  WORKOS_CONNECT_RESPONSE_MAX_BYTES,
14
+ acquireMachineCredential,
13
15
  atomicWriteFile,
16
+ cachedMachineCredential,
14
17
  ensureDurableDirectory,
18
+ hasMachineConfiguration,
15
19
  jwtExpiresAt,
20
+ machineContext,
21
+ machineSessionEnded,
16
22
  packageVersion,
17
23
  parseWorkosConnectTokens,
18
24
  primConfigDirectory,
@@ -23,7 +29,7 @@ import {
23
29
  syncDirectory,
24
30
  withFileLock,
25
31
  workosConnectTokenEndpoint
26
- } from "./chunk-4GYJHN26.js";
32
+ } from "./chunk-Q2PVD5W2.js";
27
33
 
28
34
  // src/decisions/identity.ts
29
35
  var PUBLIC_ID = /^dec_[0-9a-f]{8}$/u;
@@ -289,6 +295,7 @@ function removeCredentialFile(path) {
289
295
  return true;
290
296
  }
291
297
  function getTokenExpiresAt() {
298
+ if (hasMachineConfiguration()) return cachedMachineCredential()?.expiresAt;
292
299
  const stored = readTrimmed(TOKEN_EXPIRES_PATH);
293
300
  if (stored === void 0) return void 0;
294
301
  const value = Number(stored);
@@ -365,6 +372,7 @@ function clearTerminalFingerprint() {
365
372
  removeCredentialFile(TERMINAL_REFRESH_PATH);
366
373
  }
367
374
  function isSessionEnded() {
375
+ if (hasMachineConfiguration()) return machineSessionEnded();
368
376
  if (resolveAuthCredential()?.source !== "token_file") return false;
369
377
  const refreshToken2 = readTrimmed(REFRESH_TOKEN_PATH);
370
378
  const ended = terminalFingerprint();
@@ -660,6 +668,8 @@ async function performTokenRefresh(options = {}) {
660
668
  }
661
669
  var _refreshInFlight;
662
670
  function refreshToken(options = {}) {
671
+ if (hasMachineConfiguration())
672
+ return acquireMachineCredential(options).then((credential) => credential?.accessToken);
663
673
  if (_refreshInFlight) return _refreshInFlight;
664
674
  const attempt = performTokenRefresh(options).then((token) => {
665
675
  if (token) _cachedCredential = { token, source: "token_file" };
@@ -720,7 +730,8 @@ async function fetchWithToken(method, path, body, options, token, siteUrl) {
720
730
  ...method === "POST" && path === "/api/cli/moves/ingest" ? await ingestUploaderHeaders() : {}
721
731
  },
722
732
  body: body === void 0 ? void 0 : JSON.stringify(body),
723
- signal: options?.signal
733
+ signal: options?.signal,
734
+ redirect: options?.redirect
724
735
  });
725
736
  }
726
737
  async function responseValue(response) {
@@ -735,7 +746,66 @@ async function responseValue(response) {
735
746
  }
736
747
  return publicDecisionResponse(await response.json());
737
748
  }
749
+ async function machineClient(options = {}, management = false) {
750
+ let credential;
751
+ try {
752
+ credential = await acquireMachineCredential(options);
753
+ } catch (error) {
754
+ if (!(error instanceof MachineAuthError)) throw error;
755
+ throw new HttpError(error.terminal ? 401 : 503, error.message, { error: error.code });
756
+ }
757
+ if (!credential) return void 0;
758
+ const selected = credential;
759
+ const parse = management ? managementResponseValue : responseValue;
760
+ const send = async (method, path, body, requestOptions = {}) => {
761
+ if (machineContext()?.generation !== selected.generation) {
762
+ throw new HttpError(409, "Machine identity changed; restart the operation.");
763
+ }
764
+ const current = await acquireMachineCredential({ signal: requestOptions.signal });
765
+ if (!current || current.generation !== selected.generation || current.machineId !== selected.machineId || current.organizationId !== selected.organizationId)
766
+ throw new HttpError(409, "Machine identity changed; restart the operation.");
767
+ let response = await fetchWithToken(
768
+ method,
769
+ path,
770
+ body,
771
+ { ...requestOptions, redirect: "error" },
772
+ current.accessToken,
773
+ selected.apiUrl
774
+ );
775
+ if (response.status === 401) {
776
+ const renewed = await acquireMachineCredential({
777
+ force: true,
778
+ signal: requestOptions.signal
779
+ });
780
+ if (!renewed || renewed.generation !== selected.generation || renewed.machineId !== selected.machineId || renewed.organizationId !== selected.organizationId) {
781
+ throw new HttpError(409, "Machine identity changed; restart the operation.");
782
+ }
783
+ response = await fetchWithToken(
784
+ method,
785
+ path,
786
+ body,
787
+ { ...requestOptions, redirect: "error" },
788
+ renewed.accessToken,
789
+ renewed.apiUrl
790
+ );
791
+ }
792
+ if (response.status === 401)
793
+ throw new HttpError(
794
+ 401,
795
+ "Machine access was rejected. Ask your administrator to check or rotate its credentials."
796
+ );
797
+ return parse(response);
798
+ };
799
+ return {
800
+ get: (path, opts) => send("GET", path, void 0, opts),
801
+ post: (path, body, opts) => send("POST", path, body, opts),
802
+ delete: (path, body, opts) => send("DELETE", path, body, opts)
803
+ };
804
+ }
738
805
  async function request(method, path, body, options) {
806
+ const machine = await machineClient(options);
807
+ if (machine)
808
+ return method === "GET" ? machine.get(path, options) : machine.post(path, body, options);
739
809
  const siteUrl = getSiteUrl();
740
810
  let credential = selectedCredential();
741
811
  let refreshAttempted = false;
@@ -779,6 +849,8 @@ function getClient() {
779
849
  };
780
850
  }
781
851
  async function getPinnedClient(options = {}) {
852
+ const machine = await machineClient(options);
853
+ if (machine) return machine;
782
854
  const siteUrl = getSiteUrl();
783
855
  let credential = selectedCredential();
784
856
  if (credential && isTokenExpiringSoon(credential)) {
@@ -799,6 +871,8 @@ async function getPinnedClient(options = {}) {
799
871
  };
800
872
  }
801
873
  async function getPinnedManagementClient(options = {}) {
874
+ const machine = await machineClient(options, true);
875
+ if (machine) return machine;
802
876
  const siteUrl = getSiteUrl();
803
877
  let credential = selectedCredential();
804
878
  if (credential && isTokenExpiringSoon(credential)) {
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  analyzeShellTargets,
3
3
  extractFileTargets
4
- } from "./chunk-JYPVPYW3.js";
4
+ } from "./chunk-A6YTFBQ4.js";
5
5
  import {
6
6
  DEFAULT_RULES,
7
7
  scrub
8
- } from "./chunk-4NUGCUQC.js";
8
+ } from "./chunk-EER7VG3P.js";
9
9
  import {
10
10
  boundedHealthError,
11
11
  isPreflightResponseV4
12
- } from "./chunk-HLMC7VS4.js";
12
+ } from "./chunk-5MH2C5QG.js";
13
13
  import {
14
14
  getClient,
15
15
  terminalSafeLine
16
- } from "./chunk-S3ZIMGXV.js";
16
+ } from "./chunk-QZWLZH6D.js";
17
17
  import {
18
18
  canonicalGitRoot,
19
19
  canonicalRepositoryPath
20
- } from "./chunk-4GYJHN26.js";
20
+ } from "./chunk-Q2PVD5W2.js";
21
21
 
22
22
  // src/hooks/approval-copy.ts
23
23
  var MAX_EXCERPT_CHARS = 80;
@@ -82,6 +82,7 @@ function approvalSummary(evidence, preview) {
82
82
  // src/hooks/preflight-v3.ts
83
83
  import { Buffer } from "buffer";
84
84
  var PREFLIGHT_PROTOCOL_VERSION = 3;
85
+ var PREFLIGHT_TIMEOUT_MS = 12e3;
85
86
  var MAX_PREFLIGHT_PATHS = 32;
86
87
  var MAX_PROPOSAL_BYTES = 6144;
87
88
  var MAX_CLIENT_VERSION_CHARS = 32;
@@ -171,6 +172,13 @@ function parsePreflightResponse(value) {
171
172
  function decisionDisclosureContext(response) {
172
173
  return response.decisionDisclosures?.map(({ decisionId }) => `[primitive] hidden Decision: prim decisions show ${decisionId}`).join("\n") ?? "";
173
174
  }
175
+ async function requestPreflight(request, signal = AbortSignal.timeout(PREFLIGHT_TIMEOUT_MS)) {
176
+ const response = await getClient().post("/api/cli/decisions/conflict-check", request, {
177
+ signal,
178
+ quietRefresh: true
179
+ });
180
+ return parsePreflightResponse(response);
181
+ }
174
182
  function proposedChangeExcerpt(proposal) {
175
183
  try {
176
184
  const input = JSON.parse(proposal);
@@ -236,6 +244,16 @@ function resultForPreflight(response, preview = "Review the requested change.",
236
244
  unavailable: response.verdict === "unavailable" ? unavailable : void 0
237
245
  };
238
246
  }
247
+ function unverifiedResult(message) {
248
+ return {
249
+ verdict: "unavailable",
250
+ conflicts: [],
251
+ reason: "",
252
+ additionalContext: "",
253
+ truncated: false,
254
+ unavailable: message
255
+ };
256
+ }
239
257
 
240
258
  // src/hooks/preflight-v4.ts
241
259
  import { createHash } from "crypto";
@@ -356,7 +374,7 @@ function resultForPreflight2(response, preview, invocation, proposalTruncated =
356
374
  proposalTruncated
357
375
  );
358
376
  }
359
- async function requestPreflight(operation, deadline = performance.now() + PREFLIGHT_WAIT_MS) {
377
+ async function requestPreflight2(operation, deadline = performance.now() + PREFLIGHT_WAIT_MS) {
360
378
  if (operation.operation !== "start" && !SAFE_ID.test(operation.checkId))
361
379
  throw new PreflightPausedError("Invalid check identity");
362
380
  const remaining = deadline - performance.now();
@@ -403,7 +421,7 @@ async function waitForPreflight(operation, options = {}) {
403
421
  while (true) {
404
422
  let response;
405
423
  try {
406
- response = await requestPreflight(next, deadline);
424
+ response = await requestPreflight2(next, deadline);
407
425
  } catch (error) {
408
426
  if (error instanceof PreflightPausedError) throw error;
409
427
  if (performance.now() >= deadline)
@@ -445,15 +463,19 @@ async function waitForPreflight(operation, options = {}) {
445
463
 
446
464
  export {
447
465
  editPreview,
466
+ PREFLIGHT_TIMEOUT_MS,
448
467
  boundedClientVersion,
449
468
  resolvePreflightTargets,
450
469
  proposalFor,
451
470
  proposalIsTruncated,
471
+ requestPreflight,
472
+ resultForPreflight,
473
+ unverifiedResult,
452
474
  PREFLIGHT_PROTOCOL_VERSION2 as PREFLIGHT_PROTOCOL_VERSION,
453
475
  toolInputDigest,
454
476
  hasCompleteCoverage,
455
477
  hasConfirmedConflict,
456
- resultForPreflight2 as resultForPreflight,
457
- requestPreflight,
478
+ resultForPreflight2,
479
+ requestPreflight2,
458
480
  waitForPreflight
459
481
  };