@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
@@ -1110,7 +1110,7 @@ function readHookStdin(timeoutMs = 1e3, maxBytes = DEFAULT_MAX_BYTES) {
1110
1110
 
1111
1111
  // src/client.ts
1112
1112
  import { createHash as createHash4 } from "crypto";
1113
- import { chmodSync as chmodSync2, existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync7, rmSync as rmSync4 } from "fs";
1113
+ import { chmodSync as chmodSync3, existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync8, rmSync as rmSync4 } from "fs";
1114
1114
  import { dirname as dirname7 } from "path";
1115
1115
 
1116
1116
  // src/lib/credentials.ts
@@ -1401,6 +1401,105 @@ function jwtExpiresAt(token) {
1401
1401
  return typeof exp === "number" && Number.isFinite(exp) ? exp * 1e3 : void 0;
1402
1402
  }
1403
1403
 
1404
+ // src/daemon/client-instance-id.ts
1405
+ import { randomBytes as randomBytes3 } from "crypto";
1406
+ import { chmodSync as chmodSync2, lstatSync as lstatSync3, readFileSync as readFileSync7 } from "fs";
1407
+ import { join as join8 } from "path";
1408
+ var CONFIG_DIRECTORY_MODE = 448;
1409
+ var INSTANCE_FILE_MODE = 384;
1410
+ var INSTANCE_ENTROPY_BYTES = 32;
1411
+ var INSTANCE_BODY_CHARS = 43;
1412
+ var INSTANCE_PREFIX = "pci_";
1413
+ var CLIENT_INSTANCE_ID_RE = /^pci_[A-Za-z0-9_-]{43}$/u;
1414
+ var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
1415
+ function isClientInstanceId(value) {
1416
+ return typeof value === "string" && CLIENT_INSTANCE_ID_RE.test(value);
1417
+ }
1418
+ function ensurePrivateConfigDirectory(configDir) {
1419
+ ensureDurableDirectory(configDir, CONFIG_DIRECTORY_MODE);
1420
+ const metadata = lstatSync3(configDir);
1421
+ if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
1422
+ throw new Error("prim config path must be a private directory");
1423
+ }
1424
+ chmodSync2(configDir, CONFIG_DIRECTORY_MODE);
1425
+ syncDirectory(configDir);
1426
+ }
1427
+ function readExisting(path) {
1428
+ let metadata;
1429
+ try {
1430
+ metadata = lstatSync3(path);
1431
+ } catch (error) {
1432
+ if (error.code === "ENOENT") {
1433
+ return;
1434
+ }
1435
+ throw error;
1436
+ }
1437
+ if (!metadata.isFile() || metadata.isSymbolicLink()) {
1438
+ throw new Error("stored client instance identity is invalid");
1439
+ }
1440
+ chmodSync2(path, INSTANCE_FILE_MODE);
1441
+ if (metadata.size > MAX_STORED_BYTES) {
1442
+ throw new Error("stored client instance identity is invalid");
1443
+ }
1444
+ const raw = readFileSync7(path, "utf8");
1445
+ const value = raw.endsWith("\n") ? raw.slice(0, -1) : raw;
1446
+ if (raw !== value && raw !== `${value}
1447
+ ` || !isClientInstanceId(value)) {
1448
+ throw new Error("stored client instance identity is invalid");
1449
+ }
1450
+ return value;
1451
+ }
1452
+ function atomicWrite(path, value) {
1453
+ atomicWriteFile(path, `${value}
1454
+ `, { mode: INSTANCE_FILE_MODE });
1455
+ }
1456
+ async function getOrCreateClientInstanceId(options) {
1457
+ const configDir = options.configDir;
1458
+ const path = join8(configDir, "client_instance_id");
1459
+ const lockPath = join8(configDir, "client-instance.lock");
1460
+ ensurePrivateConfigDirectory(configDir);
1461
+ return withFileLock(
1462
+ lockPath,
1463
+ () => {
1464
+ const existing = readExisting(path);
1465
+ if (existing !== void 0) {
1466
+ return existing;
1467
+ }
1468
+ const generated = `${INSTANCE_PREFIX}${randomBytes3(INSTANCE_ENTROPY_BYTES).toString(
1469
+ "base64url"
1470
+ )}`;
1471
+ if (!isClientInstanceId(generated)) {
1472
+ throw new Error("generated client instance identity is invalid");
1473
+ }
1474
+ atomicWrite(path, generated);
1475
+ return generated;
1476
+ },
1477
+ options.lockOptions
1478
+ );
1479
+ }
1480
+
1481
+ // src/lib/ingest-uploader.ts
1482
+ var runtimeVersion = process.env.PRIM_RUNTIME_VERSION ?? packageVersion();
1483
+ var VERSION_RE = /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/u;
1484
+ var instanceId;
1485
+ async function ingestUploaderHeaders() {
1486
+ const headers = {};
1487
+ if (runtimeVersion && runtimeVersion.length <= 64 && VERSION_RE.test(runtimeVersion)) {
1488
+ headers["X-Prim-Uploader-Version"] = runtimeVersion;
1489
+ }
1490
+ instanceId ??= getOrCreateClientInstanceId({
1491
+ configDir: primConfigDirectory(),
1492
+ // Attribution must not consume the upload deadline waiting for another process.
1493
+ lockOptions: { timeoutMs: 0 }
1494
+ }).catch(() => {
1495
+ instanceId = void 0;
1496
+ return void 0;
1497
+ });
1498
+ const id = await instanceId;
1499
+ if (id) headers["X-Prim-Client-Instance-Id"] = id;
1500
+ return headers;
1501
+ }
1502
+
1404
1503
  // src/lib/terminal-safe.ts
1405
1504
  function replaceIsolatedSurrogates(value) {
1406
1505
  let out = "";
@@ -1454,7 +1553,7 @@ var DEFAULT_API_URL = "https://api.getprimitive.ai";
1454
1553
  var AUTH_EXPIRED_MESSAGE = "Authentication expired. Run `prim auth login` to re-authenticate.";
1455
1554
  function readTrimmed2(path) {
1456
1555
  try {
1457
- const value = readFileSync7(path, "utf8").trim();
1556
+ const value = readFileSync8(path, "utf8").trim();
1458
1557
  return value || void 0;
1459
1558
  } catch {
1460
1559
  return void 0;
@@ -1472,9 +1571,9 @@ function expiresAtFor(token, expiresIn) {
1472
1571
  function ensureConfigDirectory() {
1473
1572
  const directory = dirname7(TOKEN_FILE_PATH);
1474
1573
  mkdirSync4(directory, { recursive: true, mode: CONFIG_DIR_MODE });
1475
- chmodSync2(directory, CONFIG_DIR_MODE);
1574
+ chmodSync3(directory, CONFIG_DIR_MODE);
1476
1575
  }
1477
- function atomicWrite(path, content) {
1576
+ function atomicWrite2(path, content) {
1478
1577
  ensureConfigDirectory();
1479
1578
  atomicWriteFile(path, content, { mode: CREDENTIAL_FILE_MODE });
1480
1579
  }
@@ -1513,7 +1612,7 @@ function credentialFamilyMetadata(accessToken, refreshToken2, metadata) {
1513
1612
  return metadata === void 0 ? legacyBrokerCredentialMetadata(accessToken, refreshToken2) : { ...metadata, ...hashes };
1514
1613
  }
1515
1614
  function writeCredentialMigrationSentinel() {
1516
- atomicWrite(
1615
+ atomicWrite2(
1517
1616
  CREDENTIAL_MIGRATION_PATH,
1518
1617
  `${JSON.stringify({
1519
1618
  version: CREDENTIAL_MIGRATION_VERSION,
@@ -1531,7 +1630,7 @@ function bindLegacyBrokerGeneration(accessToken, refreshToken2, metadata) {
1531
1630
  return { state: "invalid" };
1532
1631
  }
1533
1632
  if (metadata.metadata === void 0) {
1534
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1633
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1535
1634
  `);
1536
1635
  }
1537
1636
  const migrationState = readCredentialMigrationState();
@@ -1546,14 +1645,14 @@ function preserveMarkerlessLegacyGeneration() {
1546
1645
  const refreshToken2 = readTrimmed2(REFRESH_TOKEN_PATH);
1547
1646
  if (!(accessToken && refreshToken2)) return;
1548
1647
  const familyMetadata = legacyBrokerCredentialMetadata(accessToken, refreshToken2);
1549
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1648
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1550
1649
  `);
1551
1650
  }
1552
1651
  function terminalFingerprint() {
1553
1652
  return readTrimmed2(TERMINAL_REFRESH_PATH);
1554
1653
  }
1555
1654
  function writeTerminalFingerprint(refreshToken2) {
1556
- atomicWrite(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
1655
+ atomicWrite2(TERMINAL_REFRESH_PATH, `${refreshFingerprint(refreshToken2)}
1557
1656
  `);
1558
1657
  }
1559
1658
  function clearTerminalFingerprint() {
@@ -1578,24 +1677,24 @@ function commitCredentialsUnlocked(credentials) {
1578
1677
  if (credentials.metadata !== void 0) {
1579
1678
  preserveMarkerlessLegacyGeneration();
1580
1679
  writeCredentialMigrationSentinel();
1581
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1680
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1582
1681
  `);
1583
- atomicWrite(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
1682
+ atomicWrite2(CREDENTIAL_METADATA_PATH, `${JSON.stringify(familyMetadata)}
1584
1683
  `);
1585
- atomicWrite(REFRESH_TOKEN_PATH, `${refreshToken2}
1684
+ atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
1586
1685
  `);
1587
1686
  } else {
1588
- atomicWrite(REFRESH_TOKEN_PATH, `${refreshToken2}
1687
+ atomicWrite2(REFRESH_TOKEN_PATH, `${refreshToken2}
1589
1688
  `);
1590
- atomicWrite(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1689
+ atomicWrite2(CREDENTIAL_FAMILY_PATH, `${JSON.stringify(familyMetadata)}
1591
1690
  `);
1592
1691
  removeCredentialFile(CREDENTIAL_METADATA_PATH);
1593
1692
  }
1594
1693
  const expiresAt = expiresAtFor(accessToken, credentials.expiresIn);
1595
1694
  if (expiresAt === void 0) removeCredentialFile(TOKEN_EXPIRES_PATH);
1596
- else atomicWrite(TOKEN_EXPIRES_PATH, `${expiresAt}
1695
+ else atomicWrite2(TOKEN_EXPIRES_PATH, `${expiresAt}
1597
1696
  `);
1598
- atomicWrite(TOKEN_FILE_PATH, `${accessToken}
1697
+ atomicWrite2(TOKEN_FILE_PATH, `${accessToken}
1599
1698
  `);
1600
1699
  clearTerminalFingerprint();
1601
1700
  _cachedCredential = { token: accessToken, source: "token_file" };
@@ -1829,12 +1928,13 @@ function selectedCredential() {
1829
1928
  }
1830
1929
  return _cachedCredential;
1831
1930
  }
1832
- function fetchWithToken(method, path, body, options, token, siteUrl) {
1931
+ async function fetchWithToken(method, path, body, options, token, siteUrl) {
1833
1932
  return fetch(`${siteUrl}${path}`, {
1834
1933
  method,
1835
1934
  headers: {
1836
1935
  Authorization: `Bearer ${token}`,
1837
- "Content-Type": "application/json"
1936
+ "Content-Type": "application/json",
1937
+ ...method === "POST" && path === "/api/cli/moves/ingest" ? await ingestUploaderHeaders() : {}
1838
1938
  },
1839
1939
  body: body === void 0 ? void 0 : JSON.stringify(body),
1840
1940
  signal: options?.signal
@@ -1903,10 +2003,10 @@ import {
1903
2003
  closeSync as closeSync3,
1904
2004
  existsSync as existsSync8,
1905
2005
  fstatSync as fstatSync2,
1906
- lstatSync as lstatSync4,
2006
+ lstatSync as lstatSync5,
1907
2007
  mkdirSync as mkdirSync5,
1908
2008
  openSync as openSync3,
1909
- readFileSync as readFileSync9,
2009
+ readFileSync as readFileSync10,
1910
2010
  readSync as readSync2,
1911
2011
  readdirSync as readdirSync3,
1912
2012
  realpathSync as realpathSync3,
@@ -1914,7 +2014,7 @@ import {
1914
2014
  rmdirSync as rmdirSync2
1915
2015
  } from "fs";
1916
2016
  import { homedir as homedir5 } from "os";
1917
- import { dirname as dirname9, isAbsolute as isAbsolute6, join as join11, relative as relative2, resolve as resolve5, sep as sep2 } from "path";
2017
+ import { dirname as dirname9, isAbsolute as isAbsolute6, join as join12, relative as relative2, resolve as resolve5, sep as sep2 } from "path";
1918
2018
  import { fileURLToPath as fileURLToPath3 } from "url";
1919
2019
 
1920
2020
  // node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/browser/dist/nodes/identity.js
@@ -8191,16 +8291,16 @@ import {
8191
8291
  closeSync as closeSync2,
8192
8292
  existsSync as existsSync7,
8193
8293
  fstatSync,
8194
- lstatSync as lstatSync3,
8294
+ lstatSync as lstatSync4,
8195
8295
  openSync as openSync2,
8196
- readFileSync as readFileSync8,
8296
+ readFileSync as readFileSync9,
8197
8297
  readSync,
8198
8298
  readdirSync as readdirSync2,
8199
8299
  rmdirSync,
8200
8300
  unlinkSync
8201
8301
  } from "fs";
8202
8302
  import { homedir as homedir4 } from "os";
8203
- import { dirname as dirname8, join as join10, resolve as resolve4 } from "path";
8303
+ import { dirname as dirname8, join as join11, resolve as resolve4 } from "path";
8204
8304
  import { fileURLToPath as fileURLToPath2 } from "url";
8205
8305
 
8206
8306
  // node_modules/.pnpm/diff@5.2.2/node_modules/diff/lib/index.mjs
@@ -8370,7 +8470,7 @@ Diff.prototype = {
8370
8470
  tokenize: function tokenize(value) {
8371
8471
  return value.split("");
8372
8472
  },
8373
- join: function join9(chars) {
8473
+ join: function join10(chars) {
8374
8474
  return chars.join("");
8375
8475
  }
8376
8476
  };
@@ -8564,7 +8664,7 @@ var SKILL_BEGIN_BUFFER = Buffer.from(SKILL_BEGIN);
8564
8664
  var SKILL_END_BUFFER = Buffer.from(SKILL_END);
8565
8665
  function readCodexGuidance(path) {
8566
8666
  try {
8567
- const entry = lstatSync3(path);
8667
+ const entry = lstatSync4(path);
8568
8668
  if (entry.isSymbolicLink() || !entry.isFile()) return null;
8569
8669
  const fd = openSync2(path, constants3.O_RDONLY | constants3.O_NOFOLLOW);
8570
8670
  try {
@@ -8587,10 +8687,10 @@ function readCodexGuidance(path) {
8587
8687
  }
8588
8688
  }
8589
8689
  function effectiveCodexGuidance(scope) {
8590
- const override = readCodexGuidance(join10(scope, "AGENTS.override.md"));
8690
+ const override = readCodexGuidance(join11(scope, "AGENTS.override.md"));
8591
8691
  if (override === null) return null;
8592
8692
  if (override !== void 0 && override.toString("utf8").trim().length > 0) return override;
8593
- const base = readCodexGuidance(join10(scope, "AGENTS.md"));
8693
+ const base = readCodexGuidance(join11(scope, "AGENTS.md"));
8594
8694
  return base ?? null;
8595
8695
  }
8596
8696
  function hasUsablePrimBlock(content, visibleBytes) {
@@ -8613,7 +8713,7 @@ function hasUsablePrimBlock(content, visibleBytes) {
8613
8713
  }
8614
8714
  function hasUsableCodexGuidance(projectRoot2) {
8615
8715
  try {
8616
- const codexHome = process.env.CODEX_HOME?.trim() ? resolve4(process.env.CODEX_HOME) : join10(homedir4(), ".codex");
8716
+ const codexHome = process.env.CODEX_HOME?.trim() ? resolve4(process.env.CODEX_HOME) : join11(homedir4(), ".codex");
8617
8717
  const scopes = [
8618
8718
  { path: codexHome, visibleBytes: CODEX_GUIDANCE_LIMIT_BYTES },
8619
8719
  { path: projectRoot2, visibleBytes: CODEX_DEFAULT_PROJECT_GUIDANCE_BYTES }
@@ -8633,19 +8733,19 @@ function sha256(content) {
8633
8733
  }
8634
8734
  function cursorSkillDirectory(cwd, scope) {
8635
8735
  const base = scope === "user" ? cursorConfigDirectory() : gitToplevel(cwd) ?? cwd;
8636
- return join10(base, scope === "user" ? "skills" : ".cursor/skills", "prim");
8736
+ return join11(base, scope === "user" ? "skills" : ".cursor/skills", "prim");
8637
8737
  }
8638
8738
  function cursorSkillPaths(cwd, scope) {
8639
8739
  const directory = cursorSkillDirectory(cwd, scope);
8640
8740
  return {
8641
8741
  directory,
8642
- skill: join10(directory, "SKILL.md"),
8643
- manifest: join10(directory, CURSOR_SKILL_MANIFEST)
8742
+ skill: join11(directory, "SKILL.md"),
8743
+ manifest: join11(directory, CURSOR_SKILL_MANIFEST)
8644
8744
  };
8645
8745
  }
8646
8746
  function readCursorSkillManifest(path) {
8647
8747
  try {
8648
- const value = JSON.parse(readFileSync8(path, "utf8"));
8748
+ const value = JSON.parse(readFileSync9(path, "utf8"));
8649
8749
  if (!value || typeof value !== "object" || Array.isArray(value)) return;
8650
8750
  const record = value;
8651
8751
  if (record.version !== 1 || record.owner !== CURSOR_SKILL_OWNER || typeof record.contentSha256 !== "string" || !/^[0-9a-f]{64}$/u.test(record.contentSha256)) {
@@ -8659,7 +8759,7 @@ function readCursorSkillManifest(path) {
8659
8759
  function cursorSkillStatus(cwd, scope) {
8660
8760
  const paths = cursorSkillPaths(cwd, scope);
8661
8761
  const manifest = readCursorSkillManifest(paths.manifest);
8662
- const content = existsSync7(paths.skill) ? readFileSync8(paths.skill, "utf8") : void 0;
8762
+ const content = existsSync7(paths.skill) ? readFileSync9(paths.skill, "utf8") : void 0;
8663
8763
  const owned = manifest !== void 0;
8664
8764
  const installed = owned && content !== void 0 && sha256(content) === manifest.contentSha256;
8665
8765
  return {
@@ -8676,12 +8776,12 @@ function loadSkill() {
8676
8776
  let dir = __dirname;
8677
8777
  while (dir !== dirname8(dir)) {
8678
8778
  const p = resolve4(dir, "SKILL.md");
8679
- if (existsSync7(p)) return readFileSync8(p, "utf-8");
8779
+ if (existsSync7(p)) return readFileSync9(p, "utf-8");
8680
8780
  dir = dirname8(dir);
8681
8781
  }
8682
8782
  throw new Error("SKILL.md not found in package");
8683
8783
  }
8684
- function atomicWrite2(target, content) {
8784
+ function atomicWrite3(target, content) {
8685
8785
  atomicWriteFile(target, content);
8686
8786
  }
8687
8787
 
@@ -8693,14 +8793,14 @@ var MAX_SKILL_BYTES = 1024 * 1024;
8693
8793
  var REFRESH_LOCK_TIMEOUT_MS = 150;
8694
8794
  var REFRESH_LOCK_POLL_MS = 10;
8695
8795
  function pluginDirFor(cwd, scope) {
8696
- const base = scope === "user" ? join11(homedir5(), ".claude") : join11(gitToplevel(cwd) ?? cwd, ".claude");
8697
- return join11(base, "skills", "prim");
8796
+ const base = scope === "user" ? join12(homedir5(), ".claude") : join12(gitToplevel(cwd) ?? cwd, ".claude");
8797
+ return join12(base, "skills", "prim");
8698
8798
  }
8699
8799
  function packageVersion2() {
8700
8800
  let dir = __dirname2;
8701
8801
  while (dir !== dirname9(dir)) {
8702
8802
  const p = resolve5(dir, "package.json");
8703
- if (existsSync8(p)) return JSON.parse(readFileSync9(p, "utf-8")).version;
8803
+ if (existsSync8(p)) return JSON.parse(readFileSync10(p, "utf-8")).version;
8704
8804
  dir = dirname9(dir);
8705
8805
  }
8706
8806
  return "0.0.0";
@@ -8716,8 +8816,8 @@ function renderClaudePlugin() {
8716
8816
  }
8717
8817
  function pluginPaths(dir) {
8718
8818
  return {
8719
- manifestPath: join11(dir, ".claude-plugin", "plugin.json"),
8720
- skillPath: join11(dir, "SKILL.md")
8819
+ manifestPath: join12(dir, ".claude-plugin", "plugin.json"),
8820
+ skillPath: join12(dir, "SKILL.md")
8721
8821
  };
8722
8822
  }
8723
8823
  function pathIsInside(root, path) {
@@ -8727,7 +8827,7 @@ function pathIsInside(root, path) {
8727
8827
  function managedPathsAreSafe(paths, projectRoot2) {
8728
8828
  try {
8729
8829
  const managed = [paths.manifestPath, paths.skillPath];
8730
- if (managed.some((path) => !lstatSync4(path).isFile())) return false;
8830
+ if (managed.some((path) => !lstatSync5(path).isFile())) return false;
8731
8831
  if (projectRoot2 === void 0) return true;
8732
8832
  const realRoot = realpathSync3(projectRoot2);
8733
8833
  return managed.every((path) => pathIsInside(realRoot, realpathSync3(path)));
@@ -8782,9 +8882,9 @@ function inspectRecognizedInstallation(paths, projectRoot2) {
8782
8882
  };
8783
8883
  }
8784
8884
  function refreshLockDir(physicalPluginDir) {
8785
- const cacheRoot = process.env.XDG_CACHE_HOME || join11(homedir5(), ".cache");
8885
+ const cacheRoot = process.env.XDG_CACHE_HOME || join12(homedir5(), ".cache");
8786
8886
  const identity = createHash6("sha256").update(physicalPluginDir).digest("hex");
8787
- return join11(cacheRoot, "prim", "skill-refresh-locks", `${identity}.lock`);
8887
+ return join12(cacheRoot, "prim", "skill-refresh-locks", `${identity}.lock`);
8788
8888
  }
8789
8889
  async function refreshClaudePlugins(cwd, options = {}) {
8790
8890
  const result = { installed: 0, refreshed: 0 };
@@ -8792,7 +8892,7 @@ async function refreshClaudePlugins(cwd, options = {}) {
8792
8892
  if (options.includeProject !== false) {
8793
8893
  const projectRoot2 = options.projectRoot ?? gitToplevel(cwd);
8794
8894
  if (projectRoot2 !== null && isAbsolute6(projectRoot2)) {
8795
- candidates.push({ dir: join11(projectRoot2, ".claude", "skills", "prim"), projectRoot: projectRoot2 });
8895
+ candidates.push({ dir: join12(projectRoot2, ".claude", "skills", "prim"), projectRoot: projectRoot2 });
8796
8896
  }
8797
8897
  }
8798
8898
  candidates.push({ dir: pluginDirFor(cwd, "user") });
@@ -8820,13 +8920,13 @@ async function refreshClaudePlugins(cwd, options = {}) {
8820
8920
  }
8821
8921
  if (current.manifest !== desired.manifest) {
8822
8922
  if (!managedPathsAreSafe(paths, projectRoot2)) throw new Error("unsafe managed path");
8823
- atomicWrite2(manifestPath, desired.manifest);
8923
+ atomicWrite3(manifestPath, desired.manifest);
8824
8924
  if (!changed) result.refreshed += 1;
8825
8925
  changed = true;
8826
8926
  }
8827
8927
  if (current.skill !== desired.skill) {
8828
8928
  if (!managedPathsAreSafe(paths, projectRoot2)) throw new Error("unsafe managed path");
8829
- atomicWrite2(skillPath, desired.skill);
8929
+ atomicWrite3(skillPath, desired.skill);
8830
8930
  if (!changed) result.refreshed += 1;
8831
8931
  changed = true;
8832
8932
  }
@@ -8856,7 +8956,7 @@ async function refreshClaudePlugins(cwd, options = {}) {
8856
8956
 
8857
8957
  // src/daemon/client.ts
8858
8958
  import { createConnection } from "net";
8859
- import { join as join12 } from "path";
8959
+ import { join as join13 } from "path";
8860
8960
 
8861
8961
  // src/daemon/principal.ts
8862
8962
  import { createHash as createHash7 } from "crypto";
@@ -8906,7 +9006,7 @@ function parseDaemonResponseEnvelope(value) {
8906
9006
  }
8907
9007
 
8908
9008
  // src/daemon/client.ts
8909
- var SOCK_PATH = join12(primConfigDirectory(), "sock");
9009
+ var SOCK_PATH = join13(primConfigDirectory(), "sock");
8910
9010
  var DEFAULT_TIMEOUT_MS2 = 250;
8911
9011
  var nextRequestId = 1;
8912
9012
  function daemonRequest(method, params = {}, opts = {}) {
@@ -9212,9 +9312,9 @@ async function acknowledgeDecisionFeedback(input, dependencies = {}) {
9212
9312
 
9213
9313
  // src/lib/activation.ts
9214
9314
  import { execFileSync as execFileSync2 } from "child_process";
9215
- import { existsSync as existsSync9, readFileSync as readFileSync10 } from "fs";
9315
+ import { existsSync as existsSync9, readFileSync as readFileSync11 } from "fs";
9216
9316
  import { homedir as homedir6 } from "os";
9217
- import { join as join13 } from "path";
9317
+ import { join as join14 } from "path";
9218
9318
  var PRIM_ACTIVE_KEY = "prim.active";
9219
9319
  var PRIM_REPO_SYNC_ID_KEY = "prim.repoSyncId";
9220
9320
  var PRIM_REPO_SYNC_REPOSITORY_KEY = "prim.repoSyncRepository";
@@ -9312,10 +9412,10 @@ function hasProjectPrimInstall(cwd) {
9312
9412
  const root = gitToplevel(cwd);
9313
9413
  if (root === null || root === homedir6()) return false;
9314
9414
  for (const rel of PROJECT_INSTALL_FILES) {
9315
- const path = join13(root, rel);
9415
+ const path = join14(root, rel);
9316
9416
  if (existsSync9(path)) {
9317
9417
  try {
9318
- const content = readFileSync10(path, "utf-8");
9418
+ const content = readFileSync11(path, "utf-8");
9319
9419
  if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
9320
9420
  } catch {
9321
9421
  }
@@ -9334,15 +9434,15 @@ function decisionIngestionStatus(cwd) {
9334
9434
  }
9335
9435
 
9336
9436
  // src/lib/bin-cache.ts
9337
- import { chmodSync as chmodSync3, mkdirSync as mkdirSync6 } from "fs";
9437
+ import { chmodSync as chmodSync4, mkdirSync as mkdirSync6 } from "fs";
9338
9438
  import { homedir as homedir7 } from "os";
9339
- import { join as join14 } from "path";
9439
+ import { join as join15 } from "path";
9340
9440
  var GIT_HOOK_CACHE_SHELL_DIR = "${XDG_CACHE_HOME:-$HOME/.cache}/prim/bin";
9341
9441
  var GIT_HOOK_CACHE_TTL_MINUTES = 1440;
9342
9442
  var GIT_HOOK_CACHED_BINS = ["prim-post-commit", "prim-post-rewrite"];
9343
9443
  function binCacheDir() {
9344
- const base = process.env.XDG_CACHE_HOME || join14(homedir7(), ".cache");
9345
- return join14(base, "prim", "bin");
9444
+ const base = process.env.XDG_CACHE_HOME || join15(homedir7(), ".cache");
9445
+ return join15(base, "prim", "bin");
9346
9446
  }
9347
9447
  function writeAtomic(path, content) {
9348
9448
  atomicWriteFile(path, content, { mode: 384 });
@@ -9354,12 +9454,12 @@ function warmBinCache() {
9354
9454
  }
9355
9455
  const dir = binCacheDir();
9356
9456
  mkdirSync6(dir, { recursive: true, mode: 448 });
9357
- chmodSync3(dir, 448);
9358
- writeAtomic(join14(dir, "node"), process.execPath);
9457
+ chmodSync4(dir, 448);
9458
+ writeAtomic(join15(dir, "node"), process.execPath);
9359
9459
  for (const bin of GIT_HOOK_CACHED_BINS) {
9360
9460
  const file = binFile(bin);
9361
9461
  if (file) {
9362
- writeAtomic(join14(dir, bin), file);
9462
+ writeAtomic(join15(dir, bin), file);
9363
9463
  }
9364
9464
  }
9365
9465
  } catch {
@@ -27710,8 +27810,8 @@ async function fetchAndCacheCollectScope(cwd, dependencies = defaultDependencies
27710
27810
 
27711
27811
  // src/lib/commit-heartbeat.ts
27712
27812
  import { execFileSync as execFileSync3 } from "child_process";
27713
- import { mkdirSync as mkdirSync7, readFileSync as readFileSync11, readdirSync as readdirSync4, unlinkSync as unlinkSync2 } from "fs";
27714
- import { dirname as dirname10, join as join15, resolve as resolve6 } from "path";
27813
+ import { mkdirSync as mkdirSync7, readFileSync as readFileSync12, readdirSync as readdirSync4, unlinkSync as unlinkSync2 } from "fs";
27814
+ import { dirname as dirname10, join as join16, resolve as resolve6 } from "path";
27715
27815
  var WIRED_PATH = "prim/git-hooks-wired";
27716
27816
  var GIT_TIMEOUT_MS3 = 1e3;
27717
27817
  var MAX_STAMP_BYTES = 1024;
@@ -27723,7 +27823,7 @@ function commonPath(cwd, relative4) {
27723
27823
  timeout: GIT_TIMEOUT_MS3
27724
27824
  }).replace(/\r?\n$/u, "");
27725
27825
  if (value === "" || /[\0\r\n]/u.test(value)) throw new Error("Git returned an unsafe path");
27726
- return join15(resolve6(cwd, value), relative4);
27826
+ return join16(resolve6(cwd, value), relative4);
27727
27827
  }
27728
27828
  function ensurePrivateParent(path) {
27729
27829
  mkdirSync7(dirname10(dirname10(path)), { recursive: true, mode: 448 });
@@ -27736,7 +27836,7 @@ function writeStamp(path, at) {
27736
27836
  }
27737
27837
  function readStampAt(path) {
27738
27838
  try {
27739
- const raw = readFileSync11(path, "utf8");
27839
+ const raw = readFileSync12(path, "utf8");
27740
27840
  if (raw.length > MAX_STAMP_BYTES) return void 0;
27741
27841
  const parsed = JSON.parse(raw);
27742
27842
  return typeof parsed.at === "number" && Number.isSafeInteger(parsed.at) && parsed.at > 0 ? parsed.at : void 0;
@@ -27768,16 +27868,16 @@ import {
27768
27868
  existsSync as existsSync10,
27769
27869
  fchmodSync as fchmodSync2,
27770
27870
  fsyncSync as fsyncSync2,
27771
- lstatSync as lstatSync5,
27871
+ lstatSync as lstatSync6,
27772
27872
  mkdirSync as mkdirSync8,
27773
27873
  openSync as openSync4,
27774
- readFileSync as readFileSync12,
27874
+ readFileSync as readFileSync13,
27775
27875
  realpathSync as realpathSync4,
27776
27876
  renameSync as renameSync3,
27777
27877
  unlinkSync as unlinkSync3,
27778
27878
  writeFileSync as writeFileSync4
27779
27879
  } from "fs";
27780
- import { basename as basename2, dirname as dirname11, isAbsolute as isAbsolute8, join as join16, relative as relative3, resolve as resolve7, sep as sep3 } from "path";
27880
+ import { basename as basename2, dirname as dirname11, isAbsolute as isAbsolute8, join as join17, relative as relative3, resolve as resolve7, sep as sep3 } from "path";
27781
27881
 
27782
27882
  // src/lib/git-hook-legacy.ts
27783
27883
  import { isAbsolute as isAbsolute7 } from "path";
@@ -28086,7 +28186,7 @@ function realpathLoose(path) {
28086
28186
  let current = resolve7(path);
28087
28187
  for (; ; ) {
28088
28188
  try {
28089
- return join16(realpathSync4.native(current), ...missing);
28189
+ return join17(realpathSync4.native(current), ...missing);
28090
28190
  } catch {
28091
28191
  const parent = dirname11(current);
28092
28192
  if (parent === current) return resolve7(path);
@@ -28101,7 +28201,7 @@ function isWithin(path, directory) {
28101
28201
  }
28102
28202
  function primGitHooksDirectory() {
28103
28203
  try {
28104
- return join16(primConfigDirectory(), "git-hooks");
28204
+ return join17(primConfigDirectory(), "git-hooks");
28105
28205
  } catch {
28106
28206
  return void 0;
28107
28207
  }
@@ -28180,7 +28280,7 @@ function resolveEffectiveGitHook(hookName, cwd = process.cwd()) {
28180
28280
  }
28181
28281
  function assertSafeFile(path, spec) {
28182
28282
  if (!existsSync10(path)) return void 0;
28183
- const stat = lstatSync5(path);
28283
+ const stat = lstatSync6(path);
28184
28284
  if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_HOOK_BYTES) {
28185
28285
  throw new Error(`unsafe ${spec.hookName} hook target: ${path}`);
28186
28286
  }
@@ -28210,7 +28310,7 @@ function assertUsableHuskyDispatcher(target, spec) {
28210
28310
  }
28211
28311
  }
28212
28312
  function readHookFile(path) {
28213
- const value = readFileSync12(path);
28313
+ const value = readFileSync13(path);
28214
28314
  return Buffer.isBuffer(value) ? value : Buffer.from(value);
28215
28315
  }
28216
28316
  function decodeHookText(content, spec) {
@@ -28283,11 +28383,11 @@ function blockInsertionPoint(content, allowShebangless, spec, huskyV8) {
28283
28383
  var HUSKY_SPEC_MAJOR_RE = /^\s*[~^]?=?\s*v?([0-9]+)(?:\.(?:[0-9]+|[xX*])){0,2}(?:-[0-9A-Za-z.-]+)?\s*$/u;
28284
28384
  function declaredHuskyMajor(dir) {
28285
28385
  for (let current = resolve7(dir); ; ) {
28286
- const manifest = join16(current, "package.json");
28386
+ const manifest = join17(current, "package.json");
28287
28387
  if (existsSync10(manifest)) {
28288
28388
  try {
28289
- if (lstatSync5(manifest).size > MAX_HOOK_BYTES) return void 0;
28290
- const parsed = JSON.parse(readFileSync12(manifest, "utf8"));
28389
+ if (lstatSync6(manifest).size > MAX_HOOK_BYTES) return void 0;
28390
+ const parsed = JSON.parse(readFileSync13(manifest, "utf8"));
28291
28391
  const range = parsed.devDependencies?.husky ?? parsed.dependencies?.husky;
28292
28392
  const major = typeof range === "string" ? HUSKY_SPEC_MAJOR_RE.exec(range)?.[1] : void 0;
28293
28393
  return major === void 0 ? void 0 : Number(major);
@@ -28296,15 +28396,15 @@ function declaredHuskyMajor(dir) {
28296
28396
  }
28297
28397
  }
28298
28398
  const parent = dirname11(current);
28299
- if (parent === current || existsSync10(join16(current, ".git"))) return void 0;
28399
+ if (parent === current || existsSync10(join17(current, ".git"))) return void 0;
28300
28400
  current = parent;
28301
28401
  }
28302
28402
  }
28303
28403
  function isHuskyV8Hook(hookPath) {
28304
- const runtime = join16(dirname11(hookPath), "_", "husky.sh");
28404
+ const runtime = join17(dirname11(hookPath), "_", "husky.sh");
28305
28405
  try {
28306
- const stat = lstatSync5(runtime);
28307
- return stat.isFile() && stat.size <= MAX_HOOK_BYTES && readFileSync12(runtime, "utf8").includes("husky_skip_init");
28406
+ const stat = lstatSync6(runtime);
28407
+ return stat.isFile() && stat.size <= MAX_HOOK_BYTES && readFileSync13(runtime, "utf8").includes("husky_skip_init");
28308
28408
  } catch (error) {
28309
28409
  if (errorCode(error) !== "ENOENT") return false;
28310
28410
  }
@@ -28449,7 +28549,7 @@ function errorCode(error) {
28449
28549
  function assertTargetUnchanged(path, expected, spec, stat) {
28450
28550
  let current;
28451
28551
  try {
28452
- current = lstatSync5(path);
28552
+ current = lstatSync6(path);
28453
28553
  } catch (error) {
28454
28554
  if (expected === void 0 && errorCode(error) === "ENOENT") return;
28455
28555
  throw new Error(`${spec.hookName} hook changed concurrently: ${path}`);
@@ -28618,21 +28718,21 @@ import { execFileSync as execFileSync5 } from "child_process";
28618
28718
  import { randomUUID as randomUUID3 } from "crypto";
28619
28719
  import {
28620
28720
  constants as constants6,
28621
- chmodSync as chmodSync4,
28721
+ chmodSync as chmodSync5,
28622
28722
  closeSync as closeSync5,
28623
28723
  fchmodSync as fchmodSync3,
28624
28724
  fsyncSync as fsyncSync3,
28625
28725
  linkSync,
28626
- lstatSync as lstatSync6,
28726
+ lstatSync as lstatSync7,
28627
28727
  mkdirSync as mkdirSync9,
28628
28728
  openSync as openSync5,
28629
- readFileSync as readFileSync13,
28729
+ readFileSync as readFileSync14,
28630
28730
  statSync as statSync3,
28631
28731
  unlinkSync as unlinkSync4,
28632
28732
  writeFileSync as writeFileSync5
28633
28733
  } from "fs";
28634
- import { dirname as dirname12, isAbsolute as isAbsolute9, join as join17, resolve as resolve8 } from "path";
28635
- var WORKSPACE_ID_RELATIVE_PATH = join17("prim", "workspace-id");
28734
+ import { dirname as dirname12, isAbsolute as isAbsolute9, join as join18, resolve as resolve8 } from "path";
28735
+ var WORKSPACE_ID_RELATIVE_PATH = join18("prim", "workspace-id");
28636
28736
  var MAX_ANCESTORS = 64;
28637
28737
  var MAX_GIT_FILE_BYTES = 4096;
28638
28738
  var MAX_ID_FILE_BYTES = 128;
@@ -28691,19 +28791,19 @@ function resolveWorkspaceIdPath(cwd) {
28691
28791
  function resolveFromFilesystem(cwd) {
28692
28792
  let current = resolve8(cwd);
28693
28793
  for (let depth = 0; depth < MAX_ANCESTORS; depth += 1) {
28694
- const dotGit = join17(current, ".git");
28794
+ const dotGit = join18(current, ".git");
28695
28795
  try {
28696
- const stat = lstatSync6(dotGit);
28796
+ const stat = lstatSync7(dotGit);
28697
28797
  if (stat.isDirectory() && isGitDirectory(dotGit)) {
28698
- return join17(dotGit, WORKSPACE_ID_RELATIVE_PATH);
28798
+ return join18(dotGit, WORKSPACE_ID_RELATIVE_PATH);
28699
28799
  }
28700
28800
  if (stat.isFile() && stat.size <= MAX_GIT_FILE_BYTES) {
28701
- const contents = readFileSync13(dotGit, "utf8");
28801
+ const contents = readFileSync14(dotGit, "utf8");
28702
28802
  const match = /^gitdir: (.+?)(?:\r?\n)?$/.exec(contents);
28703
28803
  if (match?.[1]) {
28704
28804
  const gitDirectory = isAbsolute9(match[1]) ? resolve8(match[1]) : resolve8(current, match[1]);
28705
28805
  if (isGitDirectory(gitDirectory)) {
28706
- return join17(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
28806
+ return join18(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
28707
28807
  }
28708
28808
  }
28709
28809
  }
@@ -28722,7 +28822,7 @@ function resolveFromFilesystem(cwd) {
28722
28822
  }
28723
28823
  function isGitDirectory(path) {
28724
28824
  try {
28725
- return statSync3(join17(path, "HEAD")).isFile();
28825
+ return statSync3(join18(path, "HEAD")).isFile();
28726
28826
  } catch {
28727
28827
  return false;
28728
28828
  }
@@ -28730,7 +28830,7 @@ function isGitDirectory(path) {
28730
28830
  function inspectPath(path) {
28731
28831
  let stat;
28732
28832
  try {
28733
- stat = lstatSync6(path);
28833
+ stat = lstatSync7(path);
28734
28834
  } catch (error) {
28735
28835
  const code = errorCode2(error);
28736
28836
  if (code === "ENOENT" || code === "ENOTDIR") return { status: "missing", path };
@@ -28741,7 +28841,7 @@ function inspectPath(path) {
28741
28841
  return { status: "corrupt", path, reason: "invalid_content" };
28742
28842
  }
28743
28843
  try {
28744
- const contents = readFileSync13(path, "utf8");
28844
+ const contents = readFileSync14(path, "utf8");
28745
28845
  const workspaceId = contents.endsWith("\n") ? contents.slice(0, -1) : contents;
28746
28846
  if ((contents === workspaceId || contents === `${workspaceId}
28747
28847
  `) && isCanonicalWorkspaceId(workspaceId)) {
@@ -28760,12 +28860,12 @@ function inspectPath(path) {
28760
28860
  function createWorkspaceId(path) {
28761
28861
  const parent = dirname12(path);
28762
28862
  const workspaceId = randomUUID3();
28763
- const temporaryPath = join17(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
28863
+ const temporaryPath = join18(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
28764
28864
  let temporaryCreated = false;
28765
28865
  let publishing = false;
28766
28866
  try {
28767
28867
  mkdirSync9(parent, { recursive: true, mode: 448 });
28768
- chmodSync4(parent, 448);
28868
+ chmodSync5(parent, 448);
28769
28869
  const fd = openSync5(
28770
28870
  temporaryPath,
28771
28871
  constants6.O_CREAT | constants6.O_EXCL | constants6.O_WRONLY,
@@ -28820,12 +28920,12 @@ function errorCode2(error) {
28820
28920
  }
28821
28921
 
28822
28922
  // src/hooks/codex-context.ts
28823
- import { createHash as createHash9, randomBytes as randomBytes4 } from "crypto";
28923
+ import { createHash as createHash9, randomBytes as randomBytes5 } from "crypto";
28824
28924
  import {
28825
- chmodSync as chmodSync5,
28925
+ chmodSync as chmodSync6,
28826
28926
  existsSync as existsSync11,
28827
28927
  mkdirSync as mkdirSync10,
28828
- readFileSync as readFileSync14,
28928
+ readFileSync as readFileSync15,
28829
28929
  readdirSync as readdirSync5,
28830
28930
  renameSync as renameSync4,
28831
28931
  rmSync as rmSync6,
@@ -28833,10 +28933,10 @@ import {
28833
28933
  unlinkSync as unlinkSync5,
28834
28934
  writeFileSync as writeFileSync6
28835
28935
  } from "fs";
28836
- import { join as join18 } from "path";
28936
+ import { join as join19 } from "path";
28837
28937
 
28838
28938
  // src/daemon/decision-digest-cache.ts
28839
- import { randomBytes as randomBytes3 } from "crypto";
28939
+ import { randomBytes as randomBytes4 } from "crypto";
28840
28940
  var DECISION_DIGEST_CACHE_LIMIT = 100;
28841
28941
  var DECISION_DIGEST_CACHE_WINDOW = "24h";
28842
28942
  var DECISION_DIGEST_CACHE_PATH = `/api/cli/decisions/recent?limit=${String(DECISION_DIGEST_CACHE_LIMIT)}&since=${DECISION_DIGEST_CACHE_WINDOW}`;
@@ -28986,10 +29086,10 @@ var STATE_VERSION = 1;
28986
29086
  var DRAFT_STATE_VERSION = 2;
28987
29087
  var NO_CURSOR = -1;
28988
29088
  function stateRoot(namespace) {
28989
- return join18(primConfigDirectory(), namespace, "decision-digests");
29089
+ return join19(primConfigDirectory(), namespace, "decision-digests");
28990
29090
  }
28991
29091
  function draftStateRoot(namespace) {
28992
- return join18(primConfigDirectory(), namespace, "decision-draft-deliveries");
29092
+ return join19(primConfigDirectory(), namespace, "decision-draft-deliveries");
28993
29093
  }
28994
29094
  function workspaceFor(cwd) {
28995
29095
  try {
@@ -29001,12 +29101,12 @@ function workspaceFor(cwd) {
29001
29101
  function statePath(args) {
29002
29102
  const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}`;
29003
29103
  const key = createHash9("sha256").update(identity).digest("hex");
29004
- return join18(stateRoot(args.namespace), `${key}.json`);
29104
+ return join19(stateRoot(args.namespace), `${key}.json`);
29005
29105
  }
29006
29106
  function draftStatePath(args) {
29007
29107
  const identity = `${args.siteUrl}\0${workspaceFor(args.cwd)}\0${args.sessionId}\0${args.principalId}\0${args.organizationId}\0${args.credentialFingerprint}`;
29008
29108
  const key = createHash9("sha256").update(identity).digest("hex");
29009
- return join18(draftStateRoot(args.namespace), `${key}.json`);
29109
+ return join19(draftStateRoot(args.namespace), `${key}.json`);
29010
29110
  }
29011
29111
  function parseState(value) {
29012
29112
  if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
@@ -29047,7 +29147,7 @@ function parseDraftState(value) {
29047
29147
  function readState(path) {
29048
29148
  if (!existsSync11(path)) return void 0;
29049
29149
  try {
29050
- return parseState(JSON.parse(readFileSync14(path, "utf8")));
29150
+ return parseState(JSON.parse(readFileSync15(path, "utf8")));
29051
29151
  } catch {
29052
29152
  return void 0;
29053
29153
  }
@@ -29055,17 +29155,17 @@ function readState(path) {
29055
29155
  function readDraftState(path) {
29056
29156
  if (!existsSync11(path)) return void 0;
29057
29157
  try {
29058
- return parseDraftState(JSON.parse(readFileSync14(path, "utf8")));
29158
+ return parseDraftState(JSON.parse(readFileSync15(path, "utf8")));
29059
29159
  } catch {
29060
29160
  return void 0;
29061
29161
  }
29062
29162
  }
29063
29163
  function writeStateFile(path, directory, state) {
29064
29164
  mkdirSync10(directory, { recursive: true, mode: 448 });
29065
- chmodSync5(directory, 448);
29066
- const temporary = join18(
29165
+ chmodSync6(directory, 448);
29166
+ const temporary = join19(
29067
29167
  directory,
29068
- `.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes4(8).toString("hex")}`
29168
+ `.${path.slice(directory.length + 1)}.tmp-${process.pid}-${randomBytes5(8).toString("hex")}`
29069
29169
  );
29070
29170
  try {
29071
29171
  writeFileSync6(temporary, `${JSON.stringify(state)}
@@ -29074,7 +29174,7 @@ function writeStateFile(path, directory, state) {
29074
29174
  mode: 384,
29075
29175
  flag: "wx"
29076
29176
  });
29077
- chmodSync5(temporary, 384);
29177
+ chmodSync6(temporary, 384);
29078
29178
  renameSync4(temporary, path);
29079
29179
  } finally {
29080
29180
  try {
@@ -29094,7 +29194,7 @@ function cleanupStateFiles(directory, now) {
29094
29194
  const files = [];
29095
29195
  const residue = [];
29096
29196
  for (const name of names) {
29097
- const path = join18(directory, name);
29197
+ const path = join19(directory, name);
29098
29198
  try {
29099
29199
  const mtimeMs = statSync4(path).mtimeMs;
29100
29200
  if (name.endsWith(".json")) {