@primitive.ai/prim 0.1.0-alpha.97 → 0.1.0-alpha.99

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 (41) hide show
  1. package/README.md +20 -0
  2. package/dist/{chunk-ZYK3TBEW.js → chunk-25DDRMWS.js} +4 -6
  3. package/dist/{chunk-LY6NJ7KL.js → chunk-2IRLFOEL.js} +123 -19
  4. package/dist/{chunk-27ADT6FQ.js → chunk-2Q3OGSTV.js} +44 -6
  5. package/dist/{chunk-35FMRWJH.js → chunk-5LRKJTLA.js} +1 -1
  6. package/dist/{chunk-RK4ZS3HG.js → chunk-6C3CCVDI.js} +2 -2
  7. package/dist/{chunk-UO2U6IKF.js → chunk-7VIMU2HR.js} +1 -1
  8. package/dist/{chunk-OW4GJBLW.js → chunk-EJPKZT5M.js} +2 -2
  9. package/dist/{chunk-2MBV7ZMV.js → chunk-FK7FJPWS.js} +1 -1
  10. package/dist/{chunk-4GHANPWQ.js → chunk-JJI7FU24.js} +2 -2
  11. package/dist/{chunk-AJYZB5PF.js → chunk-JJYS7IPD.js} +3 -3
  12. package/dist/{chunk-Y5W4TZM7.js → chunk-K4JWJ6OM.js} +80 -269
  13. package/dist/{chunk-XEDJ5N3M.js → chunk-KGBMU76T.js} +2 -4
  14. package/dist/{chunk-7KABYYWG.js → chunk-O2WV5SQZ.js} +11 -13
  15. package/dist/{chunk-FBPZ4YUD.js → chunk-X5BN67D2.js} +2 -2
  16. package/dist/{chunk-DWRSEC34.js → chunk-XG7S3LIL.js} +596 -16
  17. package/dist/{chunk-3I4GEWXQ.js → chunk-XPS6LG6I.js} +8 -12
  18. package/dist/{chunk-QNPTWTBG.js → chunk-ZNLIGT3J.js} +2 -2
  19. package/dist/daemon/server.js +247 -180
  20. package/dist/hook-runtime/daemon/server.js +247 -180
  21. package/dist/hook-runtime/hooks/post-commit.js +114 -59
  22. package/dist/hook-runtime/hooks/post-rewrite.js +109 -54
  23. package/dist/hook-runtime/hooks/post-tool-use.js +256 -156
  24. package/dist/hook-runtime/hooks/pre-commit.js +374 -31
  25. package/dist/hook-runtime/hooks/pre-tool-use.js +237 -137
  26. package/dist/hook-runtime/hooks/prim-hook.js +281 -181
  27. package/dist/hook-runtime/hooks/session-start.js +209 -109
  28. package/dist/hook-runtime/index.js +656 -521
  29. package/dist/hook-runtime/statusline-main.js +71 -16
  30. package/dist/hooks/post-commit.js +7 -8
  31. package/dist/hooks/post-rewrite.js +6 -7
  32. package/dist/hooks/post-tool-use.js +13 -14
  33. package/dist/hooks/pre-commit.js +4 -4
  34. package/dist/hooks/pre-tool-use.js +11 -14
  35. package/dist/hooks/prim-hook.js +14 -15
  36. package/dist/hooks/session-end.js +6 -7
  37. package/dist/hooks/session-start.js +13 -14
  38. package/dist/index.js +33 -35
  39. package/dist/statusline-main.js +71 -16
  40. package/package.json +1 -1
  41. package/dist/chunk-DHOQGHKQ.js +0 -379
@@ -53,8 +53,8 @@ var require_ucs2length = __commonJS({
53
53
 
54
54
  // src/hooks/prim-hook.ts
55
55
  import { spawn } from "child_process";
56
- import { readFileSync as readFileSync16 } from "fs";
57
- import { dirname as dirname13, join as join18 } from "path";
56
+ import { readFileSync as readFileSync17 } from "fs";
57
+ import { dirname as dirname13, join as join19 } from "path";
58
58
  import { fileURLToPath as fileURLToPath2 } from "url";
59
59
 
60
60
  // src/binding.ts
@@ -438,8 +438,8 @@ function resolveOrg(args) {
438
438
 
439
439
  // src/client.ts
440
440
  import { createHash as createHash2 } from "crypto";
441
- import { chmodSync, existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, rmSync as rmSync3 } from "fs";
442
- import { dirname as dirname4 } from "path";
441
+ import { chmodSync as chmodSync2, existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync6, rmSync as rmSync3 } from "fs";
442
+ import { dirname as dirname5 } from "path";
443
443
 
444
444
  // src/lib/atomic-file.ts
445
445
  import { randomUUID } from "crypto";
@@ -662,6 +662,174 @@ async function withFileLock(lockDir, operation, options = {}) {
662
662
  }
663
663
  }
664
664
 
665
+ // src/daemon/client-instance-id.ts
666
+ import { randomBytes as randomBytes2 } from "crypto";
667
+ import { chmodSync, lstatSync, readFileSync as readFileSync4 } from "fs";
668
+ import { join as join5 } from "path";
669
+ var CONFIG_DIRECTORY_MODE = 448;
670
+ var INSTANCE_FILE_MODE = 384;
671
+ var INSTANCE_ENTROPY_BYTES = 32;
672
+ var INSTANCE_BODY_CHARS = 43;
673
+ var INSTANCE_PREFIX = "pci_";
674
+ var CLIENT_INSTANCE_ID_RE = /^pci_[A-Za-z0-9_-]{43}$/u;
675
+ var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
676
+ function isClientInstanceId(value) {
677
+ return typeof value === "string" && CLIENT_INSTANCE_ID_RE.test(value);
678
+ }
679
+ function ensurePrivateConfigDirectory(configDir) {
680
+ ensureDurableDirectory(configDir, CONFIG_DIRECTORY_MODE);
681
+ const metadata = lstatSync(configDir);
682
+ if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
683
+ throw new Error("prim config path must be a private directory");
684
+ }
685
+ chmodSync(configDir, CONFIG_DIRECTORY_MODE);
686
+ syncDirectory(configDir);
687
+ }
688
+ function readExisting(path) {
689
+ let metadata;
690
+ try {
691
+ metadata = lstatSync(path);
692
+ } catch (error) {
693
+ if (error.code === "ENOENT") {
694
+ return;
695
+ }
696
+ throw error;
697
+ }
698
+ if (!metadata.isFile() || metadata.isSymbolicLink()) {
699
+ throw new Error("stored client instance identity is invalid");
700
+ }
701
+ chmodSync(path, INSTANCE_FILE_MODE);
702
+ if (metadata.size > MAX_STORED_BYTES) {
703
+ throw new Error("stored client instance identity is invalid");
704
+ }
705
+ const raw = readFileSync4(path, "utf8");
706
+ const value = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
707
+ if (raw !== value && raw !== `${value}
708
+ ` || !isClientInstanceId(value)) {
709
+ throw new Error("stored client instance identity is invalid");
710
+ }
711
+ return value;
712
+ }
713
+ function atomicWrite(path, value) {
714
+ atomicWriteFile(path, `${value}
715
+ `, { mode: INSTANCE_FILE_MODE });
716
+ }
717
+ async function getOrCreateClientInstanceId(options) {
718
+ const configDir = options.configDir;
719
+ const path = join5(configDir, "client_instance_id");
720
+ const lockPath = join5(configDir, "client-instance.lock");
721
+ ensurePrivateConfigDirectory(configDir);
722
+ return withFileLock(
723
+ lockPath,
724
+ () => {
725
+ const existing = readExisting(path);
726
+ if (existing !== void 0) {
727
+ return existing;
728
+ }
729
+ const generated = `${INSTANCE_PREFIX}${randomBytes2(INSTANCE_ENTROPY_BYTES).toString(
730
+ "base64url"
731
+ )}`;
732
+ if (!isClientInstanceId(generated)) {
733
+ throw new Error("generated client instance identity is invalid");
734
+ }
735
+ atomicWrite(path, generated);
736
+ return generated;
737
+ },
738
+ options.lockOptions
739
+ );
740
+ }
741
+
742
+ // src/lib/bin-path.ts
743
+ import { existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
744
+ import { dirname as dirname4, isAbsolute as isAbsolute2, join as join6 } from "path";
745
+ import { fileURLToPath } from "url";
746
+ var PKG_NAME = "@primitive.ai/prim";
747
+ var ROOT_WALK_LIMIT = 6;
748
+ var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
749
+ var resolvedRoot;
750
+ function locateRoot() {
751
+ if (resolvedRoot !== void 0) {
752
+ return resolvedRoot;
753
+ }
754
+ let dir = dirname4(fileURLToPath(import.meta.url));
755
+ for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
756
+ const manifestPath = join6(dir, "package.json");
757
+ if (existsSync3(manifestPath)) {
758
+ try {
759
+ const manifest = JSON.parse(readFileSync5(manifestPath, "utf-8"));
760
+ if (manifest.name === PKG_NAME && manifest.bin) {
761
+ resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
762
+ return resolvedRoot;
763
+ }
764
+ } catch {
765
+ }
766
+ }
767
+ const parent = dirname4(dir);
768
+ if (parent === dir) {
769
+ break;
770
+ }
771
+ dir = parent;
772
+ }
773
+ resolvedRoot = null;
774
+ return resolvedRoot;
775
+ }
776
+ function packageVersion() {
777
+ return locateRoot()?.version ?? null;
778
+ }
779
+ function shellQuote(value) {
780
+ return `'${value.replaceAll("'", `'"'"'`)}'`;
781
+ }
782
+ var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
783
+ var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
784
+ var PRIM_CONFIG_SHELL_RESOLVER = [
785
+ 'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
786
+ 'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
787
+ 'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
788
+ 'else prim_home=${HOME:-}; prim_absolute "$prim_home" || exit 78; case "$prim_home" in /) prim_config=/.config/prim ;; *) prim_config="$prim_home/.config/prim" ;; esac; ',
789
+ "fi; fi; "
790
+ ].join("");
791
+ function stableHookCommand(bin, args = "") {
792
+ if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
793
+ throw new Error("invalid stable hook command");
794
+ }
795
+ const resolver = [
796
+ // #242 and earlier identify managed commands by this package marker. Keep
797
+ // it as inert data during the rolling window so an older uninstall or
798
+ // reinstall can remove the stable entry without invoking npm or PATH.
799
+ `prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
800
+ PRIM_CONFIG_SHELL_RESOLVER,
801
+ `case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
802
+ 'exec "$prim_launcher" "$@"'
803
+ ].join("");
804
+ const suffix = args ? ` ${args}` : "";
805
+ return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
806
+ }
807
+ function detachedHookShimCommand(bin, args = "") {
808
+ return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
809
+ }
810
+
811
+ // src/lib/ingest-uploader.ts
812
+ var runtimeVersion = process.env.PRIM_RUNTIME_VERSION ?? packageVersion();
813
+ var VERSION_RE = /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/u;
814
+ var instanceId;
815
+ async function ingestUploaderHeaders() {
816
+ const headers = {};
817
+ if (runtimeVersion && runtimeVersion.length <= 64 && VERSION_RE.test(runtimeVersion)) {
818
+ headers["X-Prim-Uploader-Version"] = runtimeVersion;
819
+ }
820
+ instanceId ??= getOrCreateClientInstanceId({
821
+ configDir: primConfigDirectory(),
822
+ // Attribution must not consume the upload deadline waiting for another process.
823
+ lockOptions: { timeoutMs: 0 }
824
+ }).catch(() => {
825
+ instanceId = void 0;
826
+ return void 0;
827
+ });
828
+ const id = await instanceId;
829
+ if (id) headers["X-Prim-Client-Instance-Id"] = id;
830
+ return headers;
831
+ }
832
+
665
833
  // src/lib/terminal-safe.ts
666
834
  function replaceIsolatedSurrogates(value) {
667
835
  let out = "";
@@ -715,7 +883,7 @@ var DEFAULT_API_URL = "https://api.getprimitive.ai";
715
883
  var AUTH_EXPIRED_MESSAGE = "Authentication expired. Run `prim auth login` to re-authenticate.";
716
884
  function readTrimmed2(path) {
717
885
  try {
718
- const value = readFileSync4(path, "utf8").trim();
886
+ const value = readFileSync6(path, "utf8").trim();
719
887
  return value || void 0;
720
888
  } catch {
721
889
  return void 0;
@@ -731,16 +899,16 @@ function expiresAtFor(token, expiresIn) {
731
899
  return expiresIn === void 0 ? jwtExpiresAt(token) : Date.now() + expiresIn * 1e3;
732
900
  }
733
901
  function ensureConfigDirectory() {
734
- const directory = dirname4(TOKEN_FILE_PATH);
902
+ const directory = dirname5(TOKEN_FILE_PATH);
735
903
  mkdirSync3(directory, { recursive: true, mode: CONFIG_DIR_MODE });
736
- chmodSync(directory, CONFIG_DIR_MODE);
904
+ chmodSync2(directory, CONFIG_DIR_MODE);
737
905
  }
738
- function atomicWrite(path, content) {
906
+ function atomicWrite2(path, content) {
739
907
  ensureConfigDirectory();
740
908
  atomicWriteFile(path, content, { mode: CREDENTIAL_FILE_MODE });
741
909
  }
742
910
  function removeCredentialFile(path) {
743
- if (!existsSync3(path)) return false;
911
+ if (!existsSync4(path)) return false;
744
912
  rmSync3(path, { force: true });
745
913
  return true;
746
914
  }
@@ -774,7 +942,7 @@ function credentialFamilyMetadata(accessToken, refreshToken2, metadata) {
774
942
  return metadata === void 0 ? legacyBrokerCredentialMetadata(accessToken, refreshToken2) : { ...metadata, ...hashes };
775
943
  }
776
944
  function writeCredentialMigrationSentinel() {
777
- atomicWrite(
945
+ atomicWrite2(
778
946
  CREDENTIAL_MIGRATION_PATH,
779
947
  `${JSON.stringify({
780
948
  version: CREDENTIAL_MIGRATION_VERSION,
@@ -792,7 +960,7 @@ function bindLegacyBrokerGeneration(accessToken, refreshToken2, metadata) {
792
960
  return { state: "invalid" };
793
961
  }
794
962
  if (metadata.metadata === void 0) {
795
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
963
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
796
964
  `);
797
965
  }
798
966
  const migrationState = readCredentialMigrationState();
@@ -807,14 +975,14 @@ function preserveMarkerlessLegacyGeneration() {
807
975
  const refreshToken2 = readTrimmed2(REFRESH_TOKEN_PATH);
808
976
  if (!(accessToken && refreshToken2)) return;
809
977
  const familyMetadata = legacyBrokerCredentialMetadata(accessToken, refreshToken2);
810
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
978
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
811
979
  `);
812
980
  }
813
981
  function terminalFingerprint() {
814
982
  return readTrimmed2(TERMINAL_REFRESH_PATH);
815
983
  }
816
984
  function writeTerminalFingerprint(refreshToken2) {
817
- atomicWrite(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
985
+ atomicWrite2(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
818
986
  `);
819
987
  }
820
988
  function clearTerminalFingerprint() {
@@ -839,24 +1007,24 @@ function commitCredentialsUnlocked(credentials) {
839
1007
  if (credentials.metadata !== void 0) {
840
1008
  preserveMarkerlessLegacyGeneration();
841
1009
  writeCredentialMigrationSentinel();
842
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1010
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
843
1011
  `);
844
- atomicWrite(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
1012
+ atomicWrite2(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
845
1013
  `);
846
- atomicWrite(REFRESH_TOKEN_PATH, `${refreshToken2}
1014
+ atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
847
1015
  `);
848
1016
  } else {
849
- atomicWrite(REFRESH_TOKEN_PATH, `${refreshToken2}
1017
+ atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
850
1018
  `);
851
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1019
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
852
1020
  `);
853
1021
  removeCredentialFile(CREDENTIAL_METADATA_PATH);
854
1022
  }
855
1023
  const expiresAt = expiresAtFor(accessToken, credentials.expiresIn);
856
1024
  if (expiresAt === void 0) removeCredentialFile(TOKEN_EXPIRES_PATH);
857
- else atomicWrite(TOKEN_EXPIRES_PATH, `${expiresAt}
1025
+ else atomicWrite2(TOKEN_EXPIRES_PATH, `${expiresAt}
858
1026
  `);
859
- atomicWrite(TOKEN_FILE_PATH, `${accessToken}
1027
+ atomicWrite2(TOKEN_FILE_PATH, `${accessToken}
860
1028
  `);
861
1029
  clearTerminalFingerprint();
862
1030
  _cachedCredential = { token: accessToken, source: "token_file" };
@@ -1090,12 +1258,13 @@ function selectedCredential() {
1090
1258
  }
1091
1259
  return _cachedCredential;
1092
1260
  }
1093
- function fetchWithToken(method, path, body, options, token, siteUrl) {
1261
+ async function fetchWithToken(method, path, body, options, token, siteUrl) {
1094
1262
  return fetch(`${siteUrl}${path}`, {
1095
1263
  method,
1096
1264
  headers: {
1097
1265
  Authorization: `Bearer ${token}`,
1098
- "Content-Type": "application/json"
1266
+ "Content-Type": "application/json",
1267
+ ...method === "POST" && path === "/api/cli/moves/ingest" ? await ingestUploaderHeaders() : {}
1099
1268
  },
1100
1269
  body: body === void 0 ? void 0 : JSON.stringify(body),
1101
1270
  signal: options?.signal
@@ -1342,30 +1511,30 @@ async function acknowledgeDecisionFeedback(input, dependencies = {}) {
1342
1511
  import {
1343
1512
  appendFileSync,
1344
1513
  closeSync as closeSync2,
1345
- existsSync as existsSync5,
1514
+ existsSync as existsSync6,
1346
1515
  fstatSync,
1347
1516
  mkdirSync as mkdirSync4,
1348
1517
  openSync as openSync2,
1349
1518
  opendirSync,
1350
- readFileSync as readFileSync6,
1519
+ readFileSync as readFileSync8,
1351
1520
  readSync,
1352
1521
  readdirSync as readdirSync2
1353
1522
  } from "fs";
1354
- import { dirname as dirname6, join as join7 } from "path";
1523
+ import { dirname as dirname7, join as join9 } from "path";
1355
1524
 
1356
1525
  // src/drain-progress.ts
1357
1526
  import {
1358
- chmodSync as chmodSync2,
1359
- existsSync as existsSync4,
1360
- readFileSync as readFileSync5,
1527
+ chmodSync as chmodSync3,
1528
+ existsSync as existsSync5,
1529
+ readFileSync as readFileSync7,
1361
1530
  readdirSync,
1362
1531
  rmSync as rmSync4,
1363
1532
  rmdirSync
1364
1533
  } from "fs";
1365
- import { basename, dirname as dirname5, join as join6 } from "path";
1534
+ import { basename, dirname as dirname6, join as join8 } from "path";
1366
1535
 
1367
1536
  // src/journal.ts
1368
- var JOURNAL_DIR = join7(primConfigDirectory(), "moves");
1537
+ var JOURNAL_DIR = join9(primConfigDirectory(), "moves");
1369
1538
  var UNBOUND_BUCKET = "_unbound";
1370
1539
  var JOURNAL_BASENAME = "journal.ndjson";
1371
1540
  var JOURNAL_STATS_SAMPLE_BYTES = 64 * 1024;
@@ -1377,15 +1546,15 @@ function envSlug(apiUrl) {
1377
1546
  return slug;
1378
1547
  }
1379
1548
  function currentEnvDir() {
1380
- return join7(JOURNAL_DIR, envSlug(getSiteUrl()));
1549
+ return join9(JOURNAL_DIR, envSlug(getSiteUrl()));
1381
1550
  }
1382
1551
  var DIR_MODE = 448;
1383
1552
  var FILE_MODE2 = 384;
1384
1553
  var SAFE_BUCKET = /^[A-Za-z0-9_-]+$/;
1385
1554
  var RESERVED_BUCKETS = /* @__PURE__ */ new Set([UNBOUND_BUCKET, "_legacy"]);
1386
1555
  function appendMoveToPath(path, move) {
1387
- const dir = dirname6(path);
1388
- if (!existsSync5(dir)) {
1556
+ const dir = dirname7(path);
1557
+ if (!existsSync6(dir)) {
1389
1558
  mkdirSync4(dir, { recursive: true, mode: DIR_MODE });
1390
1559
  }
1391
1560
  appendFileSync(path, `${JSON.stringify(move)}
@@ -1393,10 +1562,10 @@ function appendMoveToPath(path, move) {
1393
1562
  }
1394
1563
  function bucketDir(orgId) {
1395
1564
  const safe = orgId !== void 0 && SAFE_BUCKET.test(orgId) && !RESERVED_BUCKETS.has(orgId);
1396
- return join7(currentEnvDir(), safe ? orgId : UNBOUND_BUCKET);
1565
+ return join9(currentEnvDir(), safe ? orgId : UNBOUND_BUCKET);
1397
1566
  }
1398
1567
  function journalPath(orgId) {
1399
- return join7(bucketDir(orgId), JOURNAL_BASENAME);
1568
+ return join9(bucketDir(orgId), JOURNAL_BASENAME);
1400
1569
  }
1401
1570
  function appendMove(move, orgId) {
1402
1571
  appendMoveToPath(journalPath(orgId), move);
@@ -1405,15 +1574,15 @@ var FLUSHING_PREFIX = `${JOURNAL_BASENAME}.flushing.`;
1405
1574
 
1406
1575
  // src/lib/activation.ts
1407
1576
  import { execFileSync as execFileSync2 } from "child_process";
1408
- import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
1577
+ import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
1409
1578
  import { homedir as homedir2 } from "os";
1410
- import { join as join8 } from "path";
1579
+ import { join as join10 } from "path";
1411
1580
 
1412
1581
  // src/lib/git.ts
1413
1582
  import { execFileSync } from "child_process";
1414
1583
  import { createHash as createHash3 } from "crypto";
1415
- import { lstatSync, realpathSync } from "fs";
1416
- import { basename as basename2, dirname as dirname7, isAbsolute as isAbsolute2, relative, resolve as resolve2, sep } from "path";
1584
+ import { lstatSync as lstatSync2, realpathSync } from "fs";
1585
+ import { basename as basename2, dirname as dirname8, isAbsolute as isAbsolute3, relative, resolve as resolve2, sep } from "path";
1417
1586
  var GIT_TIMEOUT_MS = 1e3;
1418
1587
  var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
1419
1588
  var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
@@ -1468,13 +1637,13 @@ function canonicalGitRoot(cwd) {
1468
1637
  }
1469
1638
  }
1470
1639
  function relatedWorktreeTarget(path, cwd, origin) {
1471
- let parent = dirname7(resolve2(cwd, path));
1640
+ let parent = dirname8(resolve2(cwd, path));
1472
1641
  while (true) {
1473
1642
  try {
1474
1643
  realpathSync.native(parent);
1475
1644
  break;
1476
1645
  } catch {
1477
- const next = dirname7(parent);
1646
+ const next = dirname8(parent);
1478
1647
  if (next === parent) return null;
1479
1648
  parent = next;
1480
1649
  }
@@ -1552,12 +1721,12 @@ function nearestExistingAncestor(path) {
1552
1721
  let cursor = path;
1553
1722
  while (true) {
1554
1723
  try {
1555
- lstatSync(cursor);
1724
+ lstatSync2(cursor);
1556
1725
  break;
1557
1726
  } catch (error) {
1558
1727
  const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
1559
1728
  if (code !== "ENOENT" && code !== "ENOTDIR") return null;
1560
- const parent = dirname7(cursor);
1729
+ const parent = dirname8(cursor);
1561
1730
  if (parent === cursor) return null;
1562
1731
  suffix.unshift(cursor.slice(parent.length + (parent.endsWith(sep) ? 0 : 1)));
1563
1732
  cursor = parent;
@@ -1579,7 +1748,7 @@ function canonicalRepositoryPathScoped(filePath, context, baseDir) {
1579
1748
  const target = resolve2(resolved.real, ...resolved.suffix);
1580
1749
  const rel = relative(context.repoRoot, target);
1581
1750
  if (!rel || rel === ".") return { ok: false, reason: "invalid_path" };
1582
- if (isAbsolute2(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1751
+ if (isAbsolute3(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1583
1752
  return { ok: false, reason: "outside_repository" };
1584
1753
  }
1585
1754
  return { ok: true, file: sep === "/" ? rel : rel.split(sep).join("/") };
@@ -1590,7 +1759,7 @@ function canonicalRepositoryPathLegacy(filePath, cwd, repositoryRoot = canonical
1590
1759
  const absolute = resolve2(cwd, filePath);
1591
1760
  let target;
1592
1761
  try {
1593
- const stat = lstatSync(absolute);
1762
+ const stat = lstatSync2(absolute);
1594
1763
  if (!stat.isFile() || stat.isSymbolicLink()) return null;
1595
1764
  target = realpathSync.native(absolute);
1596
1765
  } catch (error) {
@@ -1598,15 +1767,15 @@ function canonicalRepositoryPathLegacy(filePath, cwd, repositoryRoot = canonical
1598
1767
  return null;
1599
1768
  }
1600
1769
  try {
1601
- const parent = realpathSync.native(dirname7(absolute));
1602
- if (!lstatSync(parent).isDirectory()) return null;
1770
+ const parent = realpathSync.native(dirname8(absolute));
1771
+ if (!lstatSync2(parent).isDirectory()) return null;
1603
1772
  target = resolve2(parent, basename2(absolute));
1604
1773
  } catch {
1605
1774
  return null;
1606
1775
  }
1607
1776
  }
1608
1777
  const rel = relative(repositoryRoot, target);
1609
- if (!rel || isAbsolute2(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1778
+ if (!rel || isAbsolute3(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1610
1779
  return null;
1611
1780
  }
1612
1781
  return sep === "/" ? rel : rel.split(sep).join("/");
@@ -1681,10 +1850,10 @@ function hasProjectPrimInstall(cwd) {
1681
1850
  const root = gitToplevel(cwd);
1682
1851
  if (root === null || root === homedir2()) return false;
1683
1852
  for (const rel of PROJECT_INSTALL_FILES) {
1684
- const path = join8(root, rel);
1685
- if (existsSync6(path)) {
1853
+ const path = join10(root, rel);
1854
+ if (existsSync7(path)) {
1686
1855
  try {
1687
- const content = readFileSync7(path, "utf-8");
1856
+ const content = readFileSync9(path, "utf-8");
1688
1857
  if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
1689
1858
  } catch {
1690
1859
  }
@@ -20203,8 +20372,8 @@ function cachedCollectScopeAdmits(cwd, facts) {
20203
20372
 
20204
20373
  // src/lib/commit-heartbeat.ts
20205
20374
  import { execFileSync as execFileSync3 } from "child_process";
20206
- import { mkdirSync as mkdirSync5, readFileSync as readFileSync8, readdirSync as readdirSync3, unlinkSync } from "fs";
20207
- import { dirname as dirname8, join as join9, resolve as resolve3 } from "path";
20375
+ import { mkdirSync as mkdirSync5, readFileSync as readFileSync10, readdirSync as readdirSync3, unlinkSync } from "fs";
20376
+ import { dirname as dirname9, join as join11, resolve as resolve3 } from "path";
20208
20377
  var GIT_TIMEOUT_MS3 = 1e3;
20209
20378
  function gitPath(cwd, relative3) {
20210
20379
  const value = execFileSync3("git", ["rev-parse", "--git-path", relative3], {
@@ -20217,8 +20386,8 @@ function gitPath(cwd, relative3) {
20217
20386
  return resolve3(cwd, value);
20218
20387
  }
20219
20388
  function ensurePrivateParent(path) {
20220
- mkdirSync5(dirname8(dirname8(path)), { recursive: true, mode: 448 });
20221
- mkdirSync5(dirname8(path), { recursive: true, mode: 448 });
20389
+ mkdirSync5(dirname9(dirname9(path)), { recursive: true, mode: 448 });
20390
+ mkdirSync5(dirname9(path), { recursive: true, mode: 448 });
20222
20391
  }
20223
20392
  function writeStamp(path, at) {
20224
20393
  ensurePrivateParent(path);
@@ -20243,21 +20412,21 @@ import { execFileSync as execFileSync4 } from "child_process";
20243
20412
  import { randomUUID as randomUUID2 } from "crypto";
20244
20413
  import {
20245
20414
  constants as constants2,
20246
- chmodSync as chmodSync3,
20415
+ chmodSync as chmodSync4,
20247
20416
  closeSync as closeSync3,
20248
20417
  fchmodSync as fchmodSync2,
20249
20418
  fsyncSync as fsyncSync2,
20250
20419
  linkSync,
20251
- lstatSync as lstatSync2,
20420
+ lstatSync as lstatSync3,
20252
20421
  mkdirSync as mkdirSync6,
20253
20422
  openSync as openSync3,
20254
- readFileSync as readFileSync9,
20423
+ readFileSync as readFileSync11,
20255
20424
  statSync as statSync2,
20256
20425
  unlinkSync as unlinkSync2,
20257
20426
  writeFileSync as writeFileSync3
20258
20427
  } from "fs";
20259
- import { dirname as dirname9, isAbsolute as isAbsolute3, join as join10, resolve as resolve4 } from "path";
20260
- var WORKSPACE_ID_RELATIVE_PATH = join10("prim", "workspace-id");
20428
+ import { dirname as dirname10, isAbsolute as isAbsolute4, join as join12, resolve as resolve4 } from "path";
20429
+ var WORKSPACE_ID_RELATIVE_PATH = join12("prim", "workspace-id");
20261
20430
  var MAX_ANCESTORS = 64;
20262
20431
  var MAX_GIT_FILE_BYTES = 4096;
20263
20432
  var MAX_ID_FILE_BYTES = 128;
@@ -20303,7 +20472,7 @@ function resolveWorkspaceIdPath(cwd) {
20303
20472
  }
20304
20473
  return {
20305
20474
  status: "resolved",
20306
- path: isAbsolute3(gitPath2) ? resolve4(gitPath2) : resolve4(cwd, gitPath2)
20475
+ path: isAbsolute4(gitPath2) ? resolve4(gitPath2) : resolve4(cwd, gitPath2)
20307
20476
  };
20308
20477
  } catch (error) {
20309
20478
  const code = errorCode(error);
@@ -20316,19 +20485,19 @@ function resolveWorkspaceIdPath(cwd) {
20316
20485
  function resolveFromFilesystem(cwd) {
20317
20486
  let current = resolve4(cwd);
20318
20487
  for (let depth = 0; depth < MAX_ANCESTORS; depth += 1) {
20319
- const dotGit = join10(current, ".git");
20488
+ const dotGit = join12(current, ".git");
20320
20489
  try {
20321
- const stat = lstatSync2(dotGit);
20490
+ const stat = lstatSync3(dotGit);
20322
20491
  if (stat.isDirectory() && isGitDirectory(dotGit)) {
20323
- return join10(dotGit, WORKSPACE_ID_RELATIVE_PATH);
20492
+ return join12(dotGit, WORKSPACE_ID_RELATIVE_PATH);
20324
20493
  }
20325
20494
  if (stat.isFile() && stat.size <= MAX_GIT_FILE_BYTES) {
20326
- const contents = readFileSync9(dotGit, "utf8");
20495
+ const contents = readFileSync11(dotGit, "utf8");
20327
20496
  const match = /^gitdir: (.+?)(?:\r?\n)?$/.exec(contents);
20328
20497
  if (match?.[1]) {
20329
- const gitDirectory = isAbsolute3(match[1]) ? resolve4(match[1]) : resolve4(current, match[1]);
20498
+ const gitDirectory = isAbsolute4(match[1]) ? resolve4(match[1]) : resolve4(current, match[1]);
20330
20499
  if (isGitDirectory(gitDirectory)) {
20331
- return join10(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
20500
+ return join12(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
20332
20501
  }
20333
20502
  }
20334
20503
  }
@@ -20339,7 +20508,7 @@ function resolveFromFilesystem(cwd) {
20339
20508
  return null;
20340
20509
  }
20341
20510
  }
20342
- const parent = dirname9(current);
20511
+ const parent = dirname10(current);
20343
20512
  if (parent === current) break;
20344
20513
  current = parent;
20345
20514
  }
@@ -20347,7 +20516,7 @@ function resolveFromFilesystem(cwd) {
20347
20516
  }
20348
20517
  function isGitDirectory(path) {
20349
20518
  try {
20350
- return statSync2(join10(path, "HEAD")).isFile();
20519
+ return statSync2(join12(path, "HEAD")).isFile();
20351
20520
  } catch {
20352
20521
  return false;
20353
20522
  }
@@ -20355,7 +20524,7 @@ function isGitDirectory(path) {
20355
20524
  function inspectPath(path) {
20356
20525
  let stat;
20357
20526
  try {
20358
- stat = lstatSync2(path);
20527
+ stat = lstatSync3(path);
20359
20528
  } catch (error) {
20360
20529
  const code = errorCode(error);
20361
20530
  if (code === "ENOENT" || code === "ENOTDIR") return { status: "missing", path };
@@ -20366,7 +20535,7 @@ function inspectPath(path) {
20366
20535
  return { status: "corrupt", path, reason: "invalid_content" };
20367
20536
  }
20368
20537
  try {
20369
- const contents = readFileSync9(path, "utf8");
20538
+ const contents = readFileSync11(path, "utf8");
20370
20539
  const workspaceId = contents.endsWith("\n") ? contents.slice(0, -1) : contents;
20371
20540
  if ((contents === workspaceId || contents === `${workspaceId}
20372
20541
  `) && isCanonicalWorkspaceId(workspaceId)) {
@@ -20383,14 +20552,14 @@ function inspectPath(path) {
20383
20552
  }
20384
20553
  }
20385
20554
  function createWorkspaceId(path) {
20386
- const parent = dirname9(path);
20555
+ const parent = dirname10(path);
20387
20556
  const workspaceId = randomUUID2();
20388
- const temporaryPath = join10(parent, `.workspace-id-${process.pid}-${randomUUID2()}.tmp`);
20557
+ const temporaryPath = join12(parent, `.workspace-id-${process.pid}-${randomUUID2()}.tmp`);
20389
20558
  let temporaryCreated = false;
20390
20559
  let publishing = false;
20391
20560
  try {
20392
20561
  mkdirSync6(parent, { recursive: true, mode: 448 });
20393
- chmodSync3(parent, 448);
20562
+ chmodSync4(parent, 448);
20394
20563
  const fd = openSync3(
20395
20564
  temporaryPath,
20396
20565
  constants2.O_CREAT | constants2.O_EXCL | constants2.O_WRONLY,
@@ -20455,12 +20624,12 @@ function parseAgent(argv) {
20455
20624
  }
20456
20625
 
20457
20626
  // src/hooks/codex-context.ts
20458
- import { createHash as createHash5, randomBytes as randomBytes3 } from "crypto";
20627
+ import { createHash as createHash5, randomBytes as randomBytes4 } from "crypto";
20459
20628
  import {
20460
- chmodSync as chmodSync4,
20629
+ chmodSync as chmodSync5,
20461
20630
  existsSync as existsSync8,
20462
20631
  mkdirSync as mkdirSync7,
20463
- readFileSync as readFileSync11,
20632
+ readFileSync as readFileSync12,
20464
20633
  readdirSync as readdirSync4,
20465
20634
  renameSync as renameSync2,
20466
20635
  rmSync as rmSync5,
@@ -20468,11 +20637,11 @@ import {
20468
20637
  unlinkSync as unlinkSync3,
20469
20638
  writeFileSync as writeFileSync4
20470
20639
  } from "fs";
20471
- import { join as join13 } from "path";
20640
+ import { join as join14 } from "path";
20472
20641
 
20473
20642
  // src/daemon/client.ts
20474
20643
  import { createConnection } from "net";
20475
- import { join as join11 } from "path";
20644
+ import { join as join13 } from "path";
20476
20645
 
20477
20646
  // src/daemon/principal.ts
20478
20647
  import { createHash as createHash4 } from "crypto";
@@ -20522,7 +20691,7 @@ function parseDaemonResponseEnvelope(value) {
20522
20691
  }
20523
20692
 
20524
20693
  // src/daemon/client.ts
20525
- var SOCK_PATH = join11(primConfigDirectory(), "sock");
20694
+ var SOCK_PATH = join13(primConfigDirectory(), "sock");
20526
20695
  var DEFAULT_TIMEOUT_MS2 = 250;
20527
20696
  var nextRequestId = 1;
20528
20697
  function daemonRequest(method, params = {}, opts = {}) {
@@ -20610,7 +20779,7 @@ function daemonRequest(method, params = {}, opts = {}) {
20610
20779
  }
20611
20780
 
20612
20781
  // src/daemon/decision-digest-cache.ts
20613
- import { randomBytes as randomBytes2 } from "crypto";
20782
+ import { randomBytes as randomBytes3 } from "crypto";
20614
20783
  var DECISION_DIGEST_CACHE_LIMIT = 100;
20615
20784
  var DECISION_DIGEST_CACHE_WINDOW = "24h";
20616
20785
  var DECISION_DIGEST_CACHE_PATH = `/api/cli/decisions/recent?limit=${String(DECISION_DIGEST_CACHE_LIMIT)}&since=${DECISION_DIGEST_CACHE_WINDOW}`;
@@ -20622,75 +20791,6 @@ function isActionablePrivateDraft(row) {
20622
20791
  return typeof candidate.id === "string" && SAFE_PRIVATE_DRAFT_ID.test(candidate.id) && typeof candidate.intent === "string" && candidate.authorIsSelf === true && candidate.stage === "draft" && (candidate.intentKind === void 0 || candidate.intentKind === "change");
20623
20792
  }
20624
20793
 
20625
- // src/lib/bin-path.ts
20626
- import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
20627
- import { dirname as dirname10, isAbsolute as isAbsolute4, join as join12 } from "path";
20628
- import { fileURLToPath } from "url";
20629
- var PKG_NAME = "@primitive.ai/prim";
20630
- var ROOT_WALK_LIMIT = 6;
20631
- var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
20632
- var resolvedRoot;
20633
- function locateRoot() {
20634
- if (resolvedRoot !== void 0) {
20635
- return resolvedRoot;
20636
- }
20637
- let dir = dirname10(fileURLToPath(import.meta.url));
20638
- for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
20639
- const manifestPath = join12(dir, "package.json");
20640
- if (existsSync7(manifestPath)) {
20641
- try {
20642
- const manifest = JSON.parse(readFileSync10(manifestPath, "utf-8"));
20643
- if (manifest.name === PKG_NAME && manifest.bin) {
20644
- resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
20645
- return resolvedRoot;
20646
- }
20647
- } catch {
20648
- }
20649
- }
20650
- const parent = dirname10(dir);
20651
- if (parent === dir) {
20652
- break;
20653
- }
20654
- dir = parent;
20655
- }
20656
- resolvedRoot = null;
20657
- return resolvedRoot;
20658
- }
20659
- function packageVersion() {
20660
- return locateRoot()?.version ?? null;
20661
- }
20662
- function shellQuote(value) {
20663
- return `'${value.replaceAll("'", `'"'"'`)}'`;
20664
- }
20665
- var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
20666
- var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
20667
- var PRIM_CONFIG_SHELL_RESOLVER = [
20668
- 'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
20669
- 'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
20670
- 'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
20671
- 'else prim_home=${HOME:-}; prim_absolute "$prim_home" || exit 78; case "$prim_home" in /) prim_config=/.config/prim ;; *) prim_config="$prim_home/.config/prim" ;; esac; ',
20672
- "fi; fi; "
20673
- ].join("");
20674
- function stableHookCommand(bin, args = "") {
20675
- if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
20676
- throw new Error("invalid stable hook command");
20677
- }
20678
- const resolver = [
20679
- // #242 and earlier identify managed commands by this package marker. Keep
20680
- // it as inert data during the rolling window so an older uninstall or
20681
- // reinstall can remove the stable entry without invoking npm or PATH.
20682
- `prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
20683
- PRIM_CONFIG_SHELL_RESOLVER,
20684
- `case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
20685
- 'exec "$prim_launcher" "$@"'
20686
- ].join("");
20687
- const suffix = args ? ` ${args}` : "";
20688
- return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
20689
- }
20690
- function detachedHookShimCommand(bin, args = "") {
20691
- return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
20692
- }
20693
-
20694
20794
  // src/lib/ansi.ts
20695
20795
  var MAX_HEALTH_ERROR_LENGTH = 240;
20696
20796
  function boundedHealthError(value) {
@@ -20838,10 +20938,10 @@ var STATE_VERSION = 1;
20838
20938
  var DRAFT_STATE_VERSION = 2;
20839
20939
  var NO_CURSOR = -1;
20840
20940
  function stateRoot(namespace) {
20841
- return join13(primConfigDirectory(), namespace, "decision-digests");
20941
+ return join14(primConfigDirectory(), namespace, "decision-digests");
20842
20942
  }
20843
20943
  function draftStateRoot(namespace) {
20844
- return join13(primConfigDirectory(), namespace, "decision-draft-deliveries");
20944
+ return join14(primConfigDirectory(), namespace, "decision-draft-deliveries");
20845
20945
  }
20846
20946
  function workspaceFor(cwd) {
20847
20947
  try {
@@ -20853,12 +20953,12 @@ function workspaceFor(cwd) {
20853
20953
  function statePath(args) {
20854
20954
  const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}`;
20855
20955
  const key = createHash5("sha256").update(identity).digest("hex");
20856
- return join13(stateRoot(args.namespace), `${key}.json`);
20956
+ return join14(stateRoot(args.namespace), `${key}.json`);
20857
20957
  }
20858
20958
  function draftStatePath(args) {
20859
20959
  const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}\0${args.principalId}\0${args.organizationId}\0${args.credentialFingerprint}`;
20860
20960
  const key = createHash5("sha256").update(identity).digest("hex");
20861
- return join13(draftStateRoot(args.namespace), `${key}.json`);
20961
+ return join14(draftStateRoot(args.namespace), `${key}.json`);
20862
20962
  }
20863
20963
  function parseState(value) {
20864
20964
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
@@ -20899,7 +20999,7 @@ function parseDraftState(value) {
20899
20999
  function readState(path) {
20900
21000
  if (!existsSync8(path)) return void 0;
20901
21001
  try {
20902
- return parseState(JSON.parse(readFileSync11(path, "utf8")));
21002
+ return parseState(JSON.parse(readFileSync12(path, "utf8")));
20903
21003
  } catch {
20904
21004
  return void 0;
20905
21005
  }
@@ -20907,17 +21007,17 @@ function readState(path) {
20907
21007
  function readDraftState(path) {
20908
21008
  if (!existsSync8(path)) return void 0;
20909
21009
  try {
20910
- return parseDraftState(JSON.parse(readFileSync11(path, "utf8")));
21010
+ return parseDraftState(JSON.parse(readFileSync12(path, "utf8")));
20911
21011
  } catch {
20912
21012
  return void 0;
20913
21013
  }
20914
21014
  }
20915
21015
  function writeStateFile(path, directory, state) {
20916
21016
  mkdirSync7(directory, { recursive: true, mode: 448 });
20917
- chmodSync4(directory, 448);
20918
- const temporary = join13(
21017
+ chmodSync5(directory, 448);
21018
+ const temporary = join14(
20919
21019
  directory,
20920
- `.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes3(8).toString("hex")}`
21020
+ `.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes4(8).toString("hex")}`
20921
21021
  );
20922
21022
  try {
20923
21023
  writeFileSync4(temporary, `${JSON.stringify(state)}
@@ -20926,7 +21026,7 @@ function writeStateFile(path, directory, state) {
20926
21026
  mode: 384,
20927
21027
  flag: "wx"
20928
21028
  });
20929
- chmodSync4(temporary, 384);
21029
+ chmodSync5(temporary, 384);
20930
21030
  renameSync2(temporary, path);
20931
21031
  } finally {
20932
21032
  try {
@@ -20946,7 +21046,7 @@ function cleanupStateFiles(directory, now) {
20946
21046
  const files = [];
20947
21047
  const residue = [];
20948
21048
  for (const name of names) {
20949
- const path = join13(directory, name);
21049
+ const path = join14(directory, name);
20950
21050
  try {
20951
21051
  const mtimeMs = statSync3(path).mtimeMs;
20952
21052
  if (name.endsWith(".json")) {
@@ -21284,22 +21384,22 @@ async function processCodexMessageContext(envelope, deps = defaultDeps) {
21284
21384
  }
21285
21385
 
21286
21386
  // src/commands/cursor-install.ts
21287
- import { existsSync as existsSync11, readFileSync as readFileSync14 } from "fs";
21387
+ import { existsSync as existsSync11, readFileSync as readFileSync15 } from "fs";
21288
21388
  import { homedir as homedir4 } from "os";
21289
- import { isAbsolute as isAbsolute6, join as join16 } from "path";
21389
+ import { isAbsolute as isAbsolute6, join as join17 } from "path";
21290
21390
 
21291
21391
  // src/lib/hook-runtime.ts
21292
- import { createHash as createHash6, randomBytes as randomBytes4 } from "crypto";
21392
+ import { createHash as createHash6, randomBytes as randomBytes5 } from "crypto";
21293
21393
  import {
21294
21394
  constants as constants3,
21295
21395
  accessSync,
21296
- chmodSync as chmodSync5,
21396
+ chmodSync as chmodSync6,
21297
21397
  copyFileSync,
21298
21398
  existsSync as existsSync9,
21299
- lstatSync as lstatSync3,
21399
+ lstatSync as lstatSync4,
21300
21400
  mkdirSync as mkdirSync8,
21301
21401
  mkdtempSync,
21302
- readFileSync as readFileSync12,
21402
+ readFileSync as readFileSync13,
21303
21403
  readdirSync as readdirSync5,
21304
21404
  realpathSync as realpathSync2,
21305
21405
  renameSync as renameSync3,
@@ -21308,7 +21408,7 @@ import {
21308
21408
  utimesSync,
21309
21409
  writeFileSync as writeFileSync5
21310
21410
  } from "fs";
21311
- import { delimiter, dirname as dirname11, isAbsolute as isAbsolute5, join as join14, resolve as resolve5 } from "path";
21411
+ import { delimiter, dirname as dirname11, isAbsolute as isAbsolute5, join as join15, resolve as resolve5 } from "path";
21312
21412
 
21313
21413
  // src/lib/git-hook-contract.ts
21314
21414
  var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
@@ -21401,9 +21501,9 @@ exec "$prim_node" "$prim_entry" "$@"
21401
21501
  `;
21402
21502
 
21403
21503
  // src/commands/claude-install.ts
21404
- import { existsSync as existsSync10, readFileSync as readFileSync13 } from "fs";
21504
+ import { existsSync as existsSync10, readFileSync as readFileSync14 } from "fs";
21405
21505
  import { homedir as homedir3 } from "os";
21406
- import { join as join15 } from "path";
21506
+ import { join as join16 } from "path";
21407
21507
  var CAPTURE_BIN = "prim-hook";
21408
21508
  var GATE_BIN = "prim-pre-tool-use";
21409
21509
  var POST_TOOL_USE_BIN = "prim-post-tool-use";
@@ -21412,7 +21512,7 @@ var SESSION_END_BIN = "prim-session-end";
21412
21512
  var STATUSLINE_BIN = "prim-statusline";
21413
21513
  var STATUSLINE_ARGS = "";
21414
21514
  var STATUSLINE_COMMAND = stableHookCommand(STATUSLINE_BIN, STATUSLINE_ARGS);
21415
- var USER_SCOPE_PATH = join15(homedir3(), ".claude", "settings.json");
21515
+ var USER_SCOPE_PATH = join16(homedir3(), ".claude", "settings.json");
21416
21516
  function projectRoot() {
21417
21517
  return gitToplevel() ?? process.cwd();
21418
21518
  }
@@ -21491,11 +21591,11 @@ function cursorConfigDirectory(env = process.env, home = homedir4(), platform2 =
21491
21591
  const explicit = env.CURSOR_CONFIG_DIR?.trim();
21492
21592
  if (explicit && isAbsolute6(explicit)) return explicit;
21493
21593
  const xdg = env.XDG_CONFIG_HOME?.trim();
21494
- if (platform2 !== "darwin" && xdg && isAbsolute6(xdg)) return join16(xdg, "cursor");
21495
- return join16(home, ".cursor");
21594
+ if (platform2 !== "darwin" && xdg && isAbsolute6(xdg)) return join17(xdg, "cursor");
21595
+ return join17(home, ".cursor");
21496
21596
  }
21497
21597
  function cursorHooksPath(scope, root = projectRoot()) {
21498
- return scope === "user" ? join16(cursorConfigDirectory(), "hooks.json") : join16(root, ".cursor", "hooks.json");
21598
+ return scope === "user" ? join17(cursorConfigDirectory(), "hooks.json") : join17(root, ".cursor", "hooks.json");
21499
21599
  }
21500
21600
  function plainObject(value) {
21501
21601
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -21504,7 +21604,7 @@ function readCursorHooks(path) {
21504
21604
  if (!existsSync11(path)) return {};
21505
21605
  let parsed;
21506
21606
  try {
21507
- parsed = JSON.parse(readFileSync14(path, "utf8"));
21607
+ parsed = JSON.parse(readFileSync15(path, "utf8"));
21508
21608
  } catch {
21509
21609
  throw new Error(`invalid Cursor hooks JSON at ${path}`);
21510
21610
  }
@@ -21775,8 +21875,8 @@ function extractFileTargets(toolName, toolInput, agent = "claude_code") {
21775
21875
  }
21776
21876
 
21777
21877
  // src/hooks/redact.ts
21778
- import { existsSync as existsSync12, readFileSync as readFileSync15, statSync as statSync5 } from "fs";
21779
- import { join as join17 } from "path";
21878
+ import { existsSync as existsSync12, readFileSync as readFileSync16, statSync as statSync5 } from "fs";
21879
+ import { join as join18 } from "path";
21780
21880
  import { Worker } from "worker_threads";
21781
21881
  var USER_HOME_RULES = [
21782
21882
  {
@@ -21852,7 +21952,7 @@ function normalizedWorkspaceFlags(value) {
21852
21952
  return [...new Set(`g${requested}`)].sort().join("");
21853
21953
  }
21854
21954
  function loadWorkspaceRules(cwd) {
21855
- const path = join17(cwd, WORKSPACE_FILE2);
21955
+ const path = join18(cwd, WORKSPACE_FILE2);
21856
21956
  if (!existsSync12(path)) return [];
21857
21957
  let cfg;
21858
21958
  try {
@@ -21860,7 +21960,7 @@ function loadWorkspaceRules(cwd) {
21860
21960
  debugRedaction(`ignoring oversized ${WORKSPACE_FILE2}`);
21861
21961
  return [];
21862
21962
  }
21863
- cfg = JSON.parse(readFileSync15(path, "utf-8"));
21963
+ cfg = JSON.parse(readFileSync16(path, "utf-8"));
21864
21964
  } catch {
21865
21965
  debugRedaction(`ignoring unparseable ${WORKSPACE_FILE2}`);
21866
21966
  return [];
@@ -26881,14 +26981,14 @@ function emitOutput(output, acknowledge) {
26881
26981
  }
26882
26982
  function resolveCliVersion() {
26883
26983
  try {
26884
- const pkg = JSON.parse(readFileSync16(join18(here, "..", "..", "package.json"), "utf-8"));
26984
+ const pkg = JSON.parse(readFileSync17(join19(here, "..", "..", "package.json"), "utf-8"));
26885
26985
  return pkg.version ?? "unknown";
26886
26986
  } catch {
26887
26987
  return "unknown";
26888
26988
  }
26889
26989
  }
26890
26990
  function spawnBackgroundFlush() {
26891
- const entry = join18(here, "..", "index.js");
26991
+ const entry = join19(here, "..", "index.js");
26892
26992
  spawn(process.execPath, [entry, "moves", "flush"], {
26893
26993
  detached: true,
26894
26994
  stdio: "ignore",