@primitive.ai/prim 0.1.0-alpha.98 → 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 (40) hide show
  1. package/README.md +11 -0
  2. package/dist/{chunk-7IPGD6CD.js → chunk-25DDRMWS.js} +2 -2
  3. package/dist/{chunk-B6EPQ4YH.js → chunk-2IRLFOEL.js} +123 -19
  4. package/dist/{chunk-WKLYYT63.js → chunk-2Q3OGSTV.js} +3 -3
  5. package/dist/{chunk-2DPLT2CQ.js → chunk-5LRKJTLA.js} +1 -1
  6. package/dist/{chunk-AN6XTFIN.js → chunk-6C3CCVDI.js} +2 -2
  7. package/dist/{chunk-NIQAVFP6.js → chunk-7VIMU2HR.js} +1 -1
  8. package/dist/{chunk-2DA2B4EC.js → chunk-EJPKZT5M.js} +2 -2
  9. package/dist/{chunk-HUZXBJJ5.js → chunk-FK7FJPWS.js} +1 -1
  10. package/dist/{chunk-QPMLAD2C.js → chunk-JJI7FU24.js} +2 -2
  11. package/dist/{chunk-PPZBEOWK.js → chunk-JJYS7IPD.js} +3 -3
  12. package/dist/{chunk-RT7DXMTN.js → chunk-K4JWJ6OM.js} +79 -266
  13. package/dist/{chunk-3X77XQGW.js → chunk-KGBMU76T.js} +1 -1
  14. package/dist/{chunk-JOR67B5T.js → chunk-O2WV5SQZ.js} +8 -8
  15. package/dist/{chunk-IL443QTF.js → chunk-X5BN67D2.js} +2 -2
  16. package/dist/{chunk-6QK75B7G.js → chunk-XG7S3LIL.js} +214 -11
  17. package/dist/{chunk-MN4X6RR6.js → chunk-XPS6LG6I.js} +5 -7
  18. package/dist/{chunk-BIAWZMCK.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 +177 -33
  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 +615 -515
  29. package/dist/hook-runtime/statusline-main.js +71 -16
  30. package/dist/hooks/post-commit.js +7 -7
  31. package/dist/hooks/post-rewrite.js +6 -6
  32. package/dist/hooks/post-tool-use.js +13 -13
  33. package/dist/hooks/pre-commit.js +4 -4
  34. package/dist/hooks/pre-tool-use.js +10 -11
  35. package/dist/hooks/prim-hook.js +14 -14
  36. package/dist/hooks/session-end.js +4 -4
  37. package/dist/hooks/session-start.js +11 -11
  38. package/dist/index.js +20 -20
  39. package/dist/statusline-main.js +71 -16
  40. package/package.json +1 -1
@@ -53,8 +53,8 @@ var require_ucs2length = __commonJS({
53
53
 
54
54
  // src/client.ts
55
55
  import { createHash as createHash2 } from "crypto";
56
- import { chmodSync, existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync3, rmSync as rmSync3 } from "fs";
57
- import { dirname as dirname3 } from "path";
56
+ import { chmodSync as chmodSync2, existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync5, rmSync as rmSync3 } from "fs";
57
+ import { dirname as dirname4 } from "path";
58
58
 
59
59
  // src/lib/atomic-file.ts
60
60
  import { randomUUID } from "crypto";
@@ -593,6 +593,174 @@ async function withFileLock(lockDir, operation, options = {}) {
593
593
  }
594
594
  }
595
595
 
596
+ // src/daemon/client-instance-id.ts
597
+ import { randomBytes as randomBytes2 } from "crypto";
598
+ import { chmodSync, lstatSync, readFileSync as readFileSync3 } from "fs";
599
+ import { join as join4 } from "path";
600
+ var CONFIG_DIRECTORY_MODE = 448;
601
+ var INSTANCE_FILE_MODE = 384;
602
+ var INSTANCE_ENTROPY_BYTES = 32;
603
+ var INSTANCE_BODY_CHARS = 43;
604
+ var INSTANCE_PREFIX = "pci_";
605
+ var CLIENT_INSTANCE_ID_RE = /^pci_[A-Za-z0-9_-]{43}$/u;
606
+ var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
607
+ function isClientInstanceId(value) {
608
+ return typeof value === "string" && CLIENT_INSTANCE_ID_RE.test(value);
609
+ }
610
+ function ensurePrivateConfigDirectory(configDir) {
611
+ ensureDurableDirectory(configDir, CONFIG_DIRECTORY_MODE);
612
+ const metadata = lstatSync(configDir);
613
+ if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
614
+ throw new Error("prim config path must be a private directory");
615
+ }
616
+ chmodSync(configDir, CONFIG_DIRECTORY_MODE);
617
+ syncDirectory(configDir);
618
+ }
619
+ function readExisting(path) {
620
+ let metadata;
621
+ try {
622
+ metadata = lstatSync(path);
623
+ } catch (error) {
624
+ if (error.code === "ENOENT") {
625
+ return;
626
+ }
627
+ throw error;
628
+ }
629
+ if (!metadata.isFile() || metadata.isSymbolicLink()) {
630
+ throw new Error("stored client instance identity is invalid");
631
+ }
632
+ chmodSync(path, INSTANCE_FILE_MODE);
633
+ if (metadata.size > MAX_STORED_BYTES) {
634
+ throw new Error("stored client instance identity is invalid");
635
+ }
636
+ const raw = readFileSync3(path, "utf8");
637
+ const value = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
638
+ if (raw !== value && raw !== `${value}
639
+ ` || !isClientInstanceId(value)) {
640
+ throw new Error("stored client instance identity is invalid");
641
+ }
642
+ return value;
643
+ }
644
+ function atomicWrite(path, value) {
645
+ atomicWriteFile(path, `${value}
646
+ `, { mode: INSTANCE_FILE_MODE });
647
+ }
648
+ async function getOrCreateClientInstanceId(options) {
649
+ const configDir = options.configDir;
650
+ const path = join4(configDir, "client_instance_id");
651
+ const lockPath = join4(configDir, "client-instance.lock");
652
+ ensurePrivateConfigDirectory(configDir);
653
+ return withFileLock(
654
+ lockPath,
655
+ () => {
656
+ const existing = readExisting(path);
657
+ if (existing !== void 0) {
658
+ return existing;
659
+ }
660
+ const generated = `${INSTANCE_PREFIX}${randomBytes2(INSTANCE_ENTROPY_BYTES).toString(
661
+ "base64url"
662
+ )}`;
663
+ if (!isClientInstanceId(generated)) {
664
+ throw new Error("generated client instance identity is invalid");
665
+ }
666
+ atomicWrite(path, generated);
667
+ return generated;
668
+ },
669
+ options.lockOptions
670
+ );
671
+ }
672
+
673
+ // src/lib/bin-path.ts
674
+ import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
675
+ import { dirname as dirname3, isAbsolute as isAbsolute2, join as join5 } from "path";
676
+ import { fileURLToPath } from "url";
677
+ var PKG_NAME = "@primitive.ai/prim";
678
+ var ROOT_WALK_LIMIT = 6;
679
+ var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
680
+ var resolvedRoot;
681
+ function locateRoot() {
682
+ if (resolvedRoot !== void 0) {
683
+ return resolvedRoot;
684
+ }
685
+ let dir = dirname3(fileURLToPath(import.meta.url));
686
+ for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
687
+ const manifestPath = join5(dir, "package.json");
688
+ if (existsSync2(manifestPath)) {
689
+ try {
690
+ const manifest = JSON.parse(readFileSync4(manifestPath, "utf-8"));
691
+ if (manifest.name === PKG_NAME && manifest.bin) {
692
+ resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
693
+ return resolvedRoot;
694
+ }
695
+ } catch {
696
+ }
697
+ }
698
+ const parent = dirname3(dir);
699
+ if (parent === dir) {
700
+ break;
701
+ }
702
+ dir = parent;
703
+ }
704
+ resolvedRoot = null;
705
+ return resolvedRoot;
706
+ }
707
+ function packageVersion() {
708
+ return locateRoot()?.version ?? null;
709
+ }
710
+ function shellQuote(value) {
711
+ return `'${value.replaceAll("'", `'"'"'`)}'`;
712
+ }
713
+ var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
714
+ var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
715
+ var PRIM_CONFIG_SHELL_RESOLVER = [
716
+ 'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
717
+ 'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
718
+ 'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
719
+ '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; ',
720
+ "fi; fi; "
721
+ ].join("");
722
+ function stableHookCommand(bin, args = "") {
723
+ if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
724
+ throw new Error("invalid stable hook command");
725
+ }
726
+ const resolver = [
727
+ // #242 and earlier identify managed commands by this package marker. Keep
728
+ // it as inert data during the rolling window so an older uninstall or
729
+ // reinstall can remove the stable entry without invoking npm or PATH.
730
+ `prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
731
+ PRIM_CONFIG_SHELL_RESOLVER,
732
+ `case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
733
+ 'exec "$prim_launcher" "$@"'
734
+ ].join("");
735
+ const suffix = args ? ` ${args}` : "";
736
+ return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
737
+ }
738
+ function detachedHookShimCommand(bin, args = "") {
739
+ return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
740
+ }
741
+
742
+ // src/lib/ingest-uploader.ts
743
+ var runtimeVersion = process.env.PRIM_RUNTIME_VERSION ?? packageVersion();
744
+ var VERSION_RE = /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/u;
745
+ var instanceId;
746
+ async function ingestUploaderHeaders() {
747
+ const headers = {};
748
+ if (runtimeVersion && runtimeVersion.length <= 64 && VERSION_RE.test(runtimeVersion)) {
749
+ headers["X-Prim-Uploader-Version"] = runtimeVersion;
750
+ }
751
+ instanceId ??= getOrCreateClientInstanceId({
752
+ configDir: primConfigDirectory(),
753
+ // Attribution must not consume the upload deadline waiting for another process.
754
+ lockOptions: { timeoutMs: 0 }
755
+ }).catch(() => {
756
+ instanceId = void 0;
757
+ return void 0;
758
+ });
759
+ const id = await instanceId;
760
+ if (id) headers["X-Prim-Client-Instance-Id"] = id;
761
+ return headers;
762
+ }
763
+
596
764
  // src/lib/terminal-safe.ts
597
765
  function replaceIsolatedSurrogates(value) {
598
766
  let out = "";
@@ -643,7 +811,7 @@ var DEFAULT_API_URL = "https://api.getprimitive.ai";
643
811
  var AUTH_EXPIRED_MESSAGE = "Authentication expired. Run `prim auth login` to re-authenticate.";
644
812
  function readTrimmed2(path) {
645
813
  try {
646
- const value = readFileSync3(path, "utf8").trim();
814
+ const value = readFileSync5(path, "utf8").trim();
647
815
  return value || void 0;
648
816
  } catch {
649
817
  return void 0;
@@ -659,16 +827,16 @@ function expiresAtFor(token, expiresIn) {
659
827
  return expiresIn === void 0 ? jwtExpiresAt(token) : Date.now() + expiresIn * 1e3;
660
828
  }
661
829
  function ensureConfigDirectory() {
662
- const directory = dirname3(TOKEN_FILE_PATH);
830
+ const directory = dirname4(TOKEN_FILE_PATH);
663
831
  mkdirSync3(directory, { recursive: true, mode: CONFIG_DIR_MODE });
664
- chmodSync(directory, CONFIG_DIR_MODE);
832
+ chmodSync2(directory, CONFIG_DIR_MODE);
665
833
  }
666
- function atomicWrite(path, content) {
834
+ function atomicWrite2(path, content) {
667
835
  ensureConfigDirectory();
668
836
  atomicWriteFile(path, content, { mode: CREDENTIAL_FILE_MODE });
669
837
  }
670
838
  function removeCredentialFile(path) {
671
- if (!existsSync2(path)) return false;
839
+ if (!existsSync3(path)) return false;
672
840
  rmSync3(path, { force: true });
673
841
  return true;
674
842
  }
@@ -702,7 +870,7 @@ function credentialFamilyMetadata(accessToken, refreshToken2, metadata) {
702
870
  return metadata === void 0 ? legacyBrokerCredentialMetadata(accessToken, refreshToken2) : { ...metadata, ...hashes };
703
871
  }
704
872
  function writeCredentialMigrationSentinel() {
705
- atomicWrite(
873
+ atomicWrite2(
706
874
  CREDENTIAL_MIGRATION_PATH,
707
875
  `${JSON.stringify({
708
876
  version: CREDENTIAL_MIGRATION_VERSION,
@@ -720,7 +888,7 @@ function bindLegacyBrokerGeneration(accessToken, refreshToken2, metadata) {
720
888
  return { state: "invalid" };
721
889
  }
722
890
  if (metadata.metadata === void 0) {
723
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
891
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
724
892
  `);
725
893
  }
726
894
  const migrationState = readCredentialMigrationState();
@@ -735,14 +903,14 @@ function preserveMarkerlessLegacyGeneration() {
735
903
  const refreshToken2 = readTrimmed2(REFRESH_TOKEN_PATH);
736
904
  if (!(accessToken && refreshToken2)) return;
737
905
  const familyMetadata = legacyBrokerCredentialMetadata(accessToken, refreshToken2);
738
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
906
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
739
907
  `);
740
908
  }
741
909
  function terminalFingerprint() {
742
910
  return readTrimmed2(TERMINAL_REFRESH_PATH);
743
911
  }
744
912
  function writeTerminalFingerprint(refreshToken2) {
745
- atomicWrite(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
913
+ atomicWrite2(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
746
914
  `);
747
915
  }
748
916
  function clearTerminalFingerprint() {
@@ -767,24 +935,24 @@ function commitCredentialsUnlocked(credentials) {
767
935
  if (credentials.metadata !== void 0) {
768
936
  preserveMarkerlessLegacyGeneration();
769
937
  writeCredentialMigrationSentinel();
770
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
938
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
771
939
  `);
772
- atomicWrite(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
940
+ atomicWrite2(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
773
941
  `);
774
- atomicWrite(REFRESH_TOKEN_PATH, `${refreshToken2}
942
+ atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
775
943
  `);
776
944
  } else {
777
- atomicWrite(REFRESH_TOKEN_PATH, `${refreshToken2}
945
+ atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
778
946
  `);
779
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
947
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
780
948
  `);
781
949
  removeCredentialFile(CREDENTIAL_METADATA_PATH);
782
950
  }
783
951
  const expiresAt = expiresAtFor(accessToken, credentials.expiresIn);
784
952
  if (expiresAt === void 0) removeCredentialFile(TOKEN_EXPIRES_PATH);
785
- else atomicWrite(TOKEN_EXPIRES_PATH, `${expiresAt}
953
+ else atomicWrite2(TOKEN_EXPIRES_PATH, `${expiresAt}
786
954
  `);
787
- atomicWrite(TOKEN_FILE_PATH, `${accessToken}
955
+ atomicWrite2(TOKEN_FILE_PATH, `${accessToken}
788
956
  `);
789
957
  clearTerminalFingerprint();
790
958
  _cachedCredential = { token: accessToken, source: "token_file" };
@@ -1018,12 +1186,13 @@ function selectedCredential() {
1018
1186
  }
1019
1187
  return _cachedCredential;
1020
1188
  }
1021
- function fetchWithToken(method, path, body, options, token, siteUrl) {
1189
+ async function fetchWithToken(method, path, body, options, token, siteUrl) {
1022
1190
  return fetch(`${siteUrl}${path}`, {
1023
1191
  method,
1024
1192
  headers: {
1025
1193
  Authorization: `Bearer ${token}`,
1026
- "Content-Type": "application/json"
1194
+ "Content-Type": "application/json",
1195
+ ...method === "POST" && path === "/api/cli/moves/ingest" ? await ingestUploaderHeaders() : {}
1027
1196
  },
1028
1197
  body: body === void 0 ? void 0 : JSON.stringify(body),
1029
1198
  signal: options?.signal
@@ -1087,15 +1256,15 @@ function getClient() {
1087
1256
 
1088
1257
  // src/lib/activation.ts
1089
1258
  import { execFileSync as execFileSync2 } from "child_process";
1090
- import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
1259
+ import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
1091
1260
  import { homedir as homedir2 } from "os";
1092
- import { join as join5 } from "path";
1261
+ import { join as join7 } from "path";
1093
1262
 
1094
1263
  // src/lib/git.ts
1095
1264
  import { execFileSync } from "child_process";
1096
1265
  import { createHash as createHash3 } from "crypto";
1097
- import { lstatSync, realpathSync } from "fs";
1098
- import { basename, dirname as dirname4, isAbsolute as isAbsolute2, relative, resolve as resolve2, sep } from "path";
1266
+ import { lstatSync as lstatSync2, realpathSync } from "fs";
1267
+ import { basename, dirname as dirname5, isAbsolute as isAbsolute3, relative, resolve as resolve2, sep } from "path";
1099
1268
  var GIT_TIMEOUT_MS = 1e3;
1100
1269
  var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
1101
1270
  var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
@@ -1209,12 +1378,12 @@ function nearestExistingAncestor(path) {
1209
1378
  let cursor = path;
1210
1379
  while (true) {
1211
1380
  try {
1212
- lstatSync(cursor);
1381
+ lstatSync2(cursor);
1213
1382
  break;
1214
1383
  } catch (error) {
1215
1384
  const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
1216
1385
  if (code !== "ENOENT" && code !== "ENOTDIR") return null;
1217
- const parent = dirname4(cursor);
1386
+ const parent = dirname5(cursor);
1218
1387
  if (parent === cursor) return null;
1219
1388
  suffix.unshift(cursor.slice(parent.length + (parent.endsWith(sep) ? 0 : 1)));
1220
1389
  cursor = parent;
@@ -1236,7 +1405,7 @@ function canonicalRepositoryPathScoped(filePath, context, baseDir) {
1236
1405
  const target = resolve2(resolved.real, ...resolved.suffix);
1237
1406
  const rel = relative(context.repoRoot, target);
1238
1407
  if (!rel || rel === ".") return { ok: false, reason: "invalid_path" };
1239
- if (isAbsolute2(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1408
+ if (isAbsolute3(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1240
1409
  return { ok: false, reason: "outside_repository" };
1241
1410
  }
1242
1411
  return { ok: true, file: sep === "/" ? rel : rel.split(sep).join("/") };
@@ -1247,7 +1416,7 @@ function canonicalRepositoryPathLegacy(filePath, cwd, repositoryRoot = canonical
1247
1416
  const absolute = resolve2(cwd, filePath);
1248
1417
  let target;
1249
1418
  try {
1250
- const stat = lstatSync(absolute);
1419
+ const stat = lstatSync2(absolute);
1251
1420
  if (!stat.isFile() || stat.isSymbolicLink()) return null;
1252
1421
  target = realpathSync.native(absolute);
1253
1422
  } catch (error) {
@@ -1255,15 +1424,15 @@ function canonicalRepositoryPathLegacy(filePath, cwd, repositoryRoot = canonical
1255
1424
  return null;
1256
1425
  }
1257
1426
  try {
1258
- const parent = realpathSync.native(dirname4(absolute));
1259
- if (!lstatSync(parent).isDirectory()) return null;
1427
+ const parent = realpathSync.native(dirname5(absolute));
1428
+ if (!lstatSync2(parent).isDirectory()) return null;
1260
1429
  target = resolve2(parent, basename(absolute));
1261
1430
  } catch {
1262
1431
  return null;
1263
1432
  }
1264
1433
  }
1265
1434
  const rel = relative(repositoryRoot, target);
1266
- if (!rel || isAbsolute2(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1435
+ if (!rel || isAbsolute3(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1267
1436
  return null;
1268
1437
  }
1269
1438
  return sep === "/" ? rel : rel.split(sep).join("/");
@@ -1341,10 +1510,10 @@ function hasProjectPrimInstall(cwd) {
1341
1510
  const root = gitToplevel(cwd);
1342
1511
  if (root === null || root === homedir2()) return false;
1343
1512
  for (const rel of PROJECT_INSTALL_FILES) {
1344
- const path = join5(root, rel);
1345
- if (existsSync3(path)) {
1513
+ const path = join7(root, rel);
1514
+ if (existsSync4(path)) {
1346
1515
  try {
1347
- const content = readFileSync4(path, "utf-8");
1516
+ const content = readFileSync6(path, "utf-8");
1348
1517
  if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
1349
1518
  } catch {
1350
1519
  }
@@ -1362,75 +1531,6 @@ function decisionIngestionStatus(cwd) {
1362
1531
  return isRepoActiveForCapture(cwd) ? "enabled" : "disabled";
1363
1532
  }
1364
1533
 
1365
- // src/lib/bin-path.ts
1366
- import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
1367
- import { dirname as dirname5, isAbsolute as isAbsolute3, join as join6 } from "path";
1368
- import { fileURLToPath } from "url";
1369
- var PKG_NAME = "@primitive.ai/prim";
1370
- var ROOT_WALK_LIMIT = 6;
1371
- var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
1372
- var resolvedRoot;
1373
- function locateRoot() {
1374
- if (resolvedRoot !== void 0) {
1375
- return resolvedRoot;
1376
- }
1377
- let dir = dirname5(fileURLToPath(import.meta.url));
1378
- for (let depth = 0; depth < ROOT_WALK_LIMIT; depth++) {
1379
- const manifestPath = join6(dir, "package.json");
1380
- if (existsSync4(manifestPath)) {
1381
- try {
1382
- const manifest = JSON.parse(readFileSync5(manifestPath, "utf-8"));
1383
- if (manifest.name === PKG_NAME && manifest.bin) {
1384
- resolvedRoot = { dir, version: manifest.version, bin: manifest.bin };
1385
- return resolvedRoot;
1386
- }
1387
- } catch {
1388
- }
1389
- }
1390
- const parent = dirname5(dir);
1391
- if (parent === dir) {
1392
- break;
1393
- }
1394
- dir = parent;
1395
- }
1396
- resolvedRoot = null;
1397
- return resolvedRoot;
1398
- }
1399
- function packageVersion() {
1400
- return locateRoot()?.version ?? null;
1401
- }
1402
- function shellQuote(value) {
1403
- return `'${value.replaceAll("'", `'"'"'`)}'`;
1404
- }
1405
- var STABLE_HOOK_ARGUMENTS_RE = /^[-A-Za-z0-9_ ]*$/u;
1406
- var STABLE_HOOK_BIN_RE = /^[A-Za-z0-9][A-Za-z0-9-]*$/u;
1407
- var PRIM_CONFIG_SHELL_RESOLVER = [
1408
- 'prim_absolute() { case "$1" in [/]* ) ;; *) return 1 ;; esac; case "$1" in [[:space:]]*|*[[:space:]]|*[/][/]*|*[/].[/]*|*[/]..[/]*|*[/].|*[/]..|?*[/]) return 1 ;; esac; }; ',
1409
- 'prim_config=${PRIM_CONFIG_DIR:-}; if ! prim_absolute "$prim_config"; then prim_config=${XDG_CONFIG_HOME:-}; if prim_absolute "$prim_config"; then ',
1410
- 'case "$prim_config" in /) prim_config=/prim ;; *) prim_config="$prim_config/prim" ;; esac; ',
1411
- '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; ',
1412
- "fi; fi; "
1413
- ].join("");
1414
- function stableHookCommand(bin, args = "") {
1415
- if (!STABLE_HOOK_BIN_RE.test(bin) || !STABLE_HOOK_ARGUMENTS_RE.test(args)) {
1416
- throw new Error("invalid stable hook command");
1417
- }
1418
- const resolver = [
1419
- // #242 and earlier identify managed commands by this package marker. Keep
1420
- // it as inert data during the rolling window so an older uninstall or
1421
- // reinstall can remove the stable entry without invoking npm or PATH.
1422
- `prim_legacy_reader='-p ${PKG_NAME}@stable prim-shim.sh ${bin} '; `,
1423
- PRIM_CONFIG_SHELL_RESOLVER,
1424
- `case "$prim_config" in /) prim_launcher=/${STABLE_HOOK_LAUNCHER_NAME} ;; *) prim_launcher="$prim_config/${STABLE_HOOK_LAUNCHER_NAME}" ;; esac; `,
1425
- 'exec "$prim_launcher" "$@"'
1426
- ].join("");
1427
- const suffix = args ? ` ${args}` : "";
1428
- return `/bin/sh -c ${shellQuote(resolver)} ${STABLE_HOOK_LAUNCHER_NAME} ${bin}${suffix}`;
1429
- }
1430
- function detachedHookShimCommand(bin, args = "") {
1431
- return `payload=$(cat); { trap '' HUP; printf '%s' "$payload" | { ${stableHookCommand(bin, args)}; }; } </dev/null >/dev/null 2>&1 &`;
1432
- }
1433
-
1434
1534
  // src/generated/cli-http-v1.validators.js
1435
1535
  var import_ucs2length = __toESM(require_ucs2length(), 1);
1436
1536
  var schema33 = { "type": "object", "properties": { "authenticated": { "type": "boolean", "const": true }, "organizationBindingVersion": { "type": "number", "const": 1 }, "captureAuthorityKind": { "type": "string", "enum": ["workos", "service_token"] }, "organizationId": { "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }] }, "workosOrganizationId": { "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }] } }, "required": ["authenticated", "organizationBindingVersion", "captureAuthorityKind", "organizationId", "workosOrganizationId"], "additionalProperties": false };
@@ -19941,12 +20041,12 @@ function parseAgent(argv) {
19941
20041
  }
19942
20042
 
19943
20043
  // src/hooks/codex-context.ts
19944
- import { createHash as createHash5, randomBytes as randomBytes3 } from "crypto";
20044
+ import { createHash as createHash5, randomBytes as randomBytes4 } from "crypto";
19945
20045
  import {
19946
- chmodSync as chmodSync2,
20046
+ chmodSync as chmodSync3,
19947
20047
  existsSync as existsSync5,
19948
20048
  mkdirSync as mkdirSync4,
19949
- readFileSync as readFileSync6,
20049
+ readFileSync as readFileSync7,
19950
20050
  readdirSync,
19951
20051
  renameSync as renameSync2,
19952
20052
  rmSync as rmSync4,
@@ -19954,11 +20054,11 @@ import {
19954
20054
  unlinkSync,
19955
20055
  writeFileSync as writeFileSync3
19956
20056
  } from "fs";
19957
- import { join as join8 } from "path";
20057
+ import { join as join9 } from "path";
19958
20058
 
19959
20059
  // src/daemon/client.ts
19960
20060
  import { createConnection } from "net";
19961
- import { join as join7 } from "path";
20061
+ import { join as join8 } from "path";
19962
20062
 
19963
20063
  // src/daemon/principal.ts
19964
20064
  import { createHash as createHash4 } from "crypto";
@@ -20008,7 +20108,7 @@ function parseDaemonResponseEnvelope(value) {
20008
20108
  }
20009
20109
 
20010
20110
  // src/daemon/client.ts
20011
- var SOCK_PATH = join7(primConfigDirectory(), "sock");
20111
+ var SOCK_PATH = join8(primConfigDirectory(), "sock");
20012
20112
  var DEFAULT_TIMEOUT_MS2 = 250;
20013
20113
  var nextRequestId = 1;
20014
20114
  function daemonRequest(method, params = {}, opts = {}) {
@@ -20096,7 +20196,7 @@ function daemonRequest(method, params = {}, opts = {}) {
20096
20196
  }
20097
20197
 
20098
20198
  // src/daemon/decision-digest-cache.ts
20099
- import { randomBytes as randomBytes2 } from "crypto";
20199
+ import { randomBytes as randomBytes3 } from "crypto";
20100
20200
  var DECISION_DIGEST_CACHE_LIMIT = 100;
20101
20201
  var DECISION_DIGEST_CACHE_WINDOW = "24h";
20102
20202
  var DECISION_DIGEST_CACHE_PATH = `/api/cli/decisions/recent?limit=${String(DECISION_DIGEST_CACHE_LIMIT)}&since=${DECISION_DIGEST_CACHE_WINDOW}`;
@@ -20285,10 +20385,10 @@ function appendCodexContext(output, context) {
20285
20385
  return next;
20286
20386
  }
20287
20387
  function stateRoot(namespace) {
20288
- return join8(primConfigDirectory(), namespace, "decision-digests");
20388
+ return join9(primConfigDirectory(), namespace, "decision-digests");
20289
20389
  }
20290
20390
  function draftStateRoot(namespace) {
20291
- return join8(primConfigDirectory(), namespace, "decision-draft-deliveries");
20391
+ return join9(primConfigDirectory(), namespace, "decision-draft-deliveries");
20292
20392
  }
20293
20393
  function workspaceFor(cwd) {
20294
20394
  try {
@@ -20300,12 +20400,12 @@ function workspaceFor(cwd) {
20300
20400
  function statePath(args) {
20301
20401
  const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}`;
20302
20402
  const key = createHash5("sha256").update(identity).digest("hex");
20303
- return join8(stateRoot(args.namespace), `${key}.json`);
20403
+ return join9(stateRoot(args.namespace), `${key}.json`);
20304
20404
  }
20305
20405
  function draftStatePath(args) {
20306
20406
  const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}\0${args.principalId}\0${args.organizationId}\0${args.credentialFingerprint}`;
20307
20407
  const key = createHash5("sha256").update(identity).digest("hex");
20308
- return join8(draftStateRoot(args.namespace), `${key}.json`);
20408
+ return join9(draftStateRoot(args.namespace), `${key}.json`);
20309
20409
  }
20310
20410
  function parseState(value) {
20311
20411
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
@@ -20346,7 +20446,7 @@ function parseDraftState(value) {
20346
20446
  function readState(path) {
20347
20447
  if (!existsSync5(path)) return void 0;
20348
20448
  try {
20349
- return parseState(JSON.parse(readFileSync6(path, "utf8")));
20449
+ return parseState(JSON.parse(readFileSync7(path, "utf8")));
20350
20450
  } catch {
20351
20451
  return void 0;
20352
20452
  }
@@ -20354,17 +20454,17 @@ function readState(path) {
20354
20454
  function readDraftState(path) {
20355
20455
  if (!existsSync5(path)) return void 0;
20356
20456
  try {
20357
- return parseDraftState(JSON.parse(readFileSync6(path, "utf8")));
20457
+ return parseDraftState(JSON.parse(readFileSync7(path, "utf8")));
20358
20458
  } catch {
20359
20459
  return void 0;
20360
20460
  }
20361
20461
  }
20362
20462
  function writeStateFile(path, directory, state) {
20363
20463
  mkdirSync4(directory, { recursive: true, mode: 448 });
20364
- chmodSync2(directory, 448);
20365
- const temporary = join8(
20464
+ chmodSync3(directory, 448);
20465
+ const temporary = join9(
20366
20466
  directory,
20367
- `.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes3(8).toString("hex")}`
20467
+ `.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes4(8).toString("hex")}`
20368
20468
  );
20369
20469
  try {
20370
20470
  writeFileSync3(temporary, `${JSON.stringify(state)}
@@ -20373,7 +20473,7 @@ function writeStateFile(path, directory, state) {
20373
20473
  mode: 384,
20374
20474
  flag: "wx"
20375
20475
  });
20376
- chmodSync2(temporary, 384);
20476
+ chmodSync3(temporary, 384);
20377
20477
  renameSync2(temporary, path);
20378
20478
  } finally {
20379
20479
  try {
@@ -20393,7 +20493,7 @@ function cleanupStateFiles(directory, now) {
20393
20493
  const files = [];
20394
20494
  const residue = [];
20395
20495
  for (const name of names) {
20396
- const path = join8(directory, name);
20496
+ const path = join9(directory, name);
20397
20497
  try {
20398
20498
  const mtimeMs = statSync2(path).mtimeMs;
20399
20499
  if (name.endsWith(".json")) {
@@ -20698,22 +20798,22 @@ async function prepareCodexContext(options) {
20698
20798
  }
20699
20799
 
20700
20800
  // src/commands/cursor-install.ts
20701
- import { existsSync as existsSync8, readFileSync as readFileSync9 } from "fs";
20801
+ import { existsSync as existsSync8, readFileSync as readFileSync10 } from "fs";
20702
20802
  import { homedir as homedir4 } from "os";
20703
- import { isAbsolute as isAbsolute5, join as join11 } from "path";
20803
+ import { isAbsolute as isAbsolute5, join as join12 } from "path";
20704
20804
 
20705
20805
  // src/lib/hook-runtime.ts
20706
- import { createHash as createHash6, randomBytes as randomBytes4 } from "crypto";
20806
+ import { createHash as createHash6, randomBytes as randomBytes5 } from "crypto";
20707
20807
  import {
20708
20808
  constants as constants2,
20709
20809
  accessSync,
20710
- chmodSync as chmodSync3,
20810
+ chmodSync as chmodSync4,
20711
20811
  copyFileSync,
20712
20812
  existsSync as existsSync6,
20713
- lstatSync as lstatSync2,
20813
+ lstatSync as lstatSync3,
20714
20814
  mkdirSync as mkdirSync5,
20715
20815
  mkdtempSync,
20716
- readFileSync as readFileSync7,
20816
+ readFileSync as readFileSync8,
20717
20817
  readdirSync as readdirSync2,
20718
20818
  realpathSync as realpathSync2,
20719
20819
  renameSync as renameSync3,
@@ -20722,7 +20822,7 @@ import {
20722
20822
  utimesSync,
20723
20823
  writeFileSync as writeFileSync4
20724
20824
  } from "fs";
20725
- import { delimiter, dirname as dirname6, isAbsolute as isAbsolute4, join as join9, resolve as resolve3 } from "path";
20825
+ import { delimiter, dirname as dirname6, isAbsolute as isAbsolute4, join as join10, resolve as resolve3 } from "path";
20726
20826
 
20727
20827
  // src/lib/git-hook-contract.ts
20728
20828
  var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
@@ -20815,9 +20915,9 @@ exec "$prim_node" "$prim_entry" "$@"
20815
20915
  `;
20816
20916
 
20817
20917
  // src/commands/claude-install.ts
20818
- import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
20918
+ import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
20819
20919
  import { homedir as homedir3 } from "os";
20820
- import { join as join10 } from "path";
20920
+ import { join as join11 } from "path";
20821
20921
  var CAPTURE_BIN = "prim-hook";
20822
20922
  var GATE_BIN = "prim-pre-tool-use";
20823
20923
  var POST_TOOL_USE_BIN = "prim-post-tool-use";
@@ -20826,7 +20926,7 @@ var SESSION_END_BIN = "prim-session-end";
20826
20926
  var STATUSLINE_BIN = "prim-statusline";
20827
20927
  var STATUSLINE_ARGS = "";
20828
20928
  var STATUSLINE_COMMAND = stableHookCommand(STATUSLINE_BIN, STATUSLINE_ARGS);
20829
- var USER_SCOPE_PATH = join10(homedir3(), ".claude", "settings.json");
20929
+ var USER_SCOPE_PATH = join11(homedir3(), ".claude", "settings.json");
20830
20930
  function projectRoot() {
20831
20931
  return gitToplevel() ?? process.cwd();
20832
20932
  }
@@ -20905,11 +21005,11 @@ function cursorConfigDirectory(env = process.env, home = homedir4(), platform =
20905
21005
  const explicit = env.CURSOR_CONFIG_DIR?.trim();
20906
21006
  if (explicit && isAbsolute5(explicit)) return explicit;
20907
21007
  const xdg = env.XDG_CONFIG_HOME?.trim();
20908
- if (platform !== "darwin" && xdg && isAbsolute5(xdg)) return join11(xdg, "cursor");
20909
- return join11(home, ".cursor");
21008
+ if (platform !== "darwin" && xdg && isAbsolute5(xdg)) return join12(xdg, "cursor");
21009
+ return join12(home, ".cursor");
20910
21010
  }
20911
21011
  function cursorHooksPath(scope, root = projectRoot()) {
20912
- return scope === "user" ? join11(cursorConfigDirectory(), "hooks.json") : join11(root, ".cursor", "hooks.json");
21012
+ return scope === "user" ? join12(cursorConfigDirectory(), "hooks.json") : join12(root, ".cursor", "hooks.json");
20913
21013
  }
20914
21014
  function plainObject(value) {
20915
21015
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -20918,7 +21018,7 @@ function readCursorHooks(path) {
20918
21018
  if (!existsSync8(path)) return {};
20919
21019
  let parsed;
20920
21020
  try {
20921
- parsed = JSON.parse(readFileSync9(path, "utf8"));
21021
+ parsed = JSON.parse(readFileSync10(path, "utf8"));
20922
21022
  } catch {
20923
21023
  throw new Error(`invalid Cursor hooks JSON at ${path}`);
20924
21024
  }
@@ -21455,8 +21555,8 @@ function demoteForMode(verdict, mode) {
21455
21555
  import { Buffer as Buffer2 } from "buffer";
21456
21556
 
21457
21557
  // src/hooks/redact.ts
21458
- import { existsSync as existsSync9, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
21459
- import { join as join12 } from "path";
21558
+ import { existsSync as existsSync9, readFileSync as readFileSync11, statSync as statSync4 } from "fs";
21559
+ import { join as join13 } from "path";
21460
21560
  import { Worker } from "worker_threads";
21461
21561
  var USER_HOME_RULES = [
21462
21562
  {