@primitive.ai/prim 0.1.0-alpha.128 → 0.1.0-alpha.129

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 (43) hide show
  1. package/dist/{chunk-6QAXVFRJ.js → chunk-BVGASV3B.js} +942 -123
  2. package/dist/{chunk-M6KIDB5R.js → chunk-DYXCJ6WZ.js} +10 -10
  3. package/dist/{chunk-B3ICJZXV.js → chunk-FHDTJP2C.js} +2 -2
  4. package/dist/{chunk-XINFTNA2.js → chunk-HDL3UXYJ.js} +5 -5
  5. package/dist/{chunk-C357P37M.js → chunk-IJ3W2YBM.js} +4 -4
  6. package/dist/{chunk-N6PZE7HX.js → chunk-IZAEAALI.js} +2 -2
  7. package/dist/{chunk-PTZ6BWSU.js → chunk-KZNOT2YH.js} +2 -2
  8. package/dist/{chunk-P4O7L7JZ.js → chunk-L7U3G4XR.js} +2 -2
  9. package/dist/{chunk-EQWUCFXK.js → chunk-LBZJD2I4.js} +3 -5
  10. package/dist/{chunk-PRJ7P6J5.js → chunk-MMMY57UA.js} +22 -837
  11. package/dist/{chunk-WEGZGF3K.js → chunk-NWWTFQP2.js} +1 -1
  12. package/dist/{chunk-NYDM4HSS.js → chunk-QSDWWEHF.js} +2 -2
  13. package/dist/{chunk-3KPTVK4N.js → chunk-RAEOSDQ6.js} +1 -1
  14. package/dist/{chunk-E57UVUJL.js → chunk-RS5ADTDF.js} +4 -4
  15. package/dist/{chunk-ANMNGGTN.js → chunk-RWJ7WHTJ.js} +2 -2
  16. package/dist/{chunk-RDT2IV2Z.js → chunk-SJE7OWVS.js} +3 -3
  17. package/dist/{chunk-VLT2KGPE.js → chunk-USJ4JGDC.js} +3 -3
  18. package/dist/{chunk-ZCT23NBS.js → chunk-YPHDV5AS.js} +2 -2
  19. package/dist/{chunk-QQ3G5SXX.js → chunk-YSV43WLK.js} +1 -1
  20. package/dist/{chunk-4DYEBYKM.js → chunk-ZKIBD5MO.js} +2 -2
  21. package/dist/daemon/server.js +624 -289
  22. package/dist/hook-runtime/daemon/server.js +624 -289
  23. package/dist/hook-runtime/hooks/post-commit.js +307 -186
  24. package/dist/hook-runtime/hooks/post-rewrite.js +302 -181
  25. package/dist/hook-runtime/hooks/post-tool-use.js +490 -276
  26. package/dist/hook-runtime/hooks/pre-commit.js +516 -181
  27. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +221 -7
  28. package/dist/hook-runtime/hooks/prim-hook.js +511 -297
  29. package/dist/hook-runtime/hooks/session-end.js +229 -229
  30. package/dist/hook-runtime/hooks/session-start.js +170 -14
  31. package/dist/hook-runtime/index.js +1623 -1607
  32. package/dist/hook-runtime/statusline-main.js +245 -124
  33. package/dist/hooks/post-commit.js +7 -7
  34. package/dist/hooks/post-rewrite.js +6 -6
  35. package/dist/hooks/post-tool-use.js +15 -15
  36. package/dist/hooks/pre-commit.js +4 -4
  37. package/dist/hooks/pre-tool-use-worker.js +9 -9
  38. package/dist/hooks/prim-hook.js +16 -16
  39. package/dist/hooks/session-end.js +4 -4
  40. package/dist/hooks/session-start.js +12 -13
  41. package/dist/index.js +24 -24
  42. package/dist/statusline-main.js +245 -124
  43. package/package.json +1 -1
@@ -54,35 +54,35 @@ var require_ucs2length = __commonJS({
54
54
 
55
55
  // src/hooks/post-commit.ts
56
56
  import { execFileSync as execFileSync7, spawn as spawn2 } from "child_process";
57
- import { lstatSync as lstatSync7, readFileSync as readFileSync18 } from "fs";
58
- import { basename as basename4, dirname as dirname12, isAbsolute as isAbsolute5, join as join20 } from "path";
59
- import { fileURLToPath as fileURLToPath4 } from "url";
57
+ import { lstatSync as lstatSync8, readFileSync as readFileSync19 } from "fs";
58
+ import { basename as basename4, dirname as dirname14, isAbsolute as isAbsolute6, join as join22 } from "path";
59
+ import { fileURLToPath as fileURLToPath5 } from "url";
60
60
 
61
61
  // src/binding.ts
62
- import { existsSync as existsSync4, readFileSync as readFileSync8 } from "fs";
63
- import { dirname as dirname6, join as join10 } from "path";
62
+ import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
63
+ import { dirname as dirname8, join as join12 } from "path";
64
64
 
65
65
  // src/lib/credentials.ts
66
- import { createHash as createHash6 } from "crypto";
67
- import { readFileSync as readFileSync7 } from "fs";
68
- import { join as join9 } from "path";
66
+ import { createHash as createHash7 } from "crypto";
67
+ import { readFileSync as readFileSync8 } from "fs";
68
+ import { join as join11 } from "path";
69
69
 
70
70
  // src/lib/machine-credentials.ts
71
71
  import { execFileSync as execFileSync2 } from "child_process";
72
- import { createHash as createHash5, randomBytes as randomBytes3, randomUUID as randomUUID2 } from "crypto";
72
+ import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as randomUUID2 } from "crypto";
73
73
  import {
74
- chmodSync,
75
- existsSync as existsSync3,
74
+ chmodSync as chmodSync2,
75
+ existsSync as existsSync5,
76
76
  linkSync,
77
- lstatSync as lstatSync4,
78
- mkdirSync as mkdirSync3,
79
- readFileSync as readFileSync6,
80
- rmSync as rmSync6,
81
- writeFileSync as writeFileSync3
77
+ lstatSync as lstatSync5,
78
+ mkdirSync as mkdirSync4,
79
+ readFileSync as readFileSync7,
80
+ rmSync as rmSync7,
81
+ writeFileSync as writeFileSync4
82
82
  } from "fs";
83
- import { createRequire } from "module";
84
- import { dirname as dirname5, join as join8 } from "path";
85
- import { fileURLToPath as fileURLToPath3 } from "url";
83
+ import { createRequire as createRequire2 } from "module";
84
+ import { dirname as dirname7, join as join10 } from "path";
85
+ import { fileURLToPath as fileURLToPath4 } from "url";
86
86
 
87
87
  // src/lib/atomic-file.ts
88
88
  import { randomUUID } from "crypto";
@@ -169,13 +169,27 @@ import { existsSync, mkdirSync as mkdirSync2, readFileSync, rmSync as rmSync2, s
169
169
  import { dirname as dirname2, join } from "path";
170
170
  var syncSleeper = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
171
171
 
172
- // src/lib/machine-broker.ts
173
- import { spawn } from "child_process";
174
- import { createHash, createHmac, randomBytes as randomBytes2, timingSafeEqual } from "crypto";
175
- import { lstatSync, readFileSync as readFileSync3, rmSync as rmSync3 } from "fs";
176
- import { createServer } from "http";
177
- import { basename, join as join4 } from "path";
178
- import { fileURLToPath as fileURLToPath2 } from "url";
172
+ // src/lib/hook-runtime.ts
173
+ import { createHash, randomBytes as randomBytes2 } from "crypto";
174
+ import {
175
+ constants as constants2,
176
+ accessSync,
177
+ chmodSync,
178
+ copyFileSync,
179
+ existsSync as existsSync4,
180
+ lstatSync,
181
+ mkdirSync as mkdirSync3,
182
+ mkdtempSync,
183
+ readFileSync as readFileSync3,
184
+ readdirSync,
185
+ realpathSync,
186
+ renameSync as renameSync2,
187
+ rmSync as rmSync3,
188
+ statSync as statSync2,
189
+ utimesSync,
190
+ writeFileSync as writeFileSync3
191
+ } from "fs";
192
+ import { delimiter, dirname as dirname5, isAbsolute as isAbsolute3, join as join5, resolve } from "path";
179
193
 
180
194
  // src/lib/bin-path.ts
181
195
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
@@ -183,6 +197,7 @@ import { dirname as dirname3, isAbsolute, join as join2 } from "path";
183
197
  import { fileURLToPath } from "url";
184
198
  var PKG_NAME = "@primitive.ai/prim";
185
199
  var ROOT_WALK_LIMIT = 6;
200
+ var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
186
201
  var resolvedRoot;
187
202
  function locateRoot() {
188
203
  if (resolvedRoot !== void 0) {
@@ -221,6 +236,140 @@ var PRIM_CONFIG_SHELL_RESOLVER = [
221
236
  "fi; fi; "
222
237
  ].join("");
223
238
 
239
+ // src/lib/git-hook-contract.ts
240
+ var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
241
+ # prim git hook entrypoint v1 \u2014 managed by prim; do not edit.
242
+ # Run by the "# >>> prim <hook> hook >>>" block in a Git hook file. Acts only
243
+ # where prim is active (git config prim.active true) and never fails the hook.
244
+ case "$0" in */*) prim_dir=\${0%/*} ;; *) exit 0 ;; esac
245
+ prim_launcher="$prim_dir/${STABLE_HOOK_LAUNCHER_NAME}"
246
+ [ -x "$prim_launcher" ] || exit 0
247
+ [ "$(git config --get prim.active 2>/dev/null)" = "true" ] || exit 0
248
+ prim_hook=\${1-}
249
+ if [ "$#" -gt 0 ]; then shift; fi
250
+ case "$prim_hook" in
251
+ pre-commit)
252
+ "$prim_launcher" prim-pre-commit "$@" || :
253
+ ;;
254
+ post-commit)
255
+ prim_sha=$(git rev-parse --verify HEAD 2>/dev/null) || exit 0
256
+ case "$prim_sha" in *[!0-9a-f]* | "") exit 0 ;; esac
257
+ case "\${#prim_sha}" in 40 | 64) ;; *) exit 0 ;; esac
258
+ prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
259
+ prim_observed=$(mktemp "\${TMPDIR:-/tmp}/prim-post-commit-observed.XXXXXXXX" 2>/dev/null) || prim_observed=
260
+ (
261
+ trap '' HUP
262
+ trap 'if [ -n "$prim_observed" ]; then rm -f "$prim_observed"; fi' 0
263
+ PRIM_COMMIT_SHA=$prim_sha PRIM_COMMIT_BRANCH=$prim_branch PRIM_COMMIT_OBSERVED_FILE=$prim_observed "$prim_launcher" prim-post-commit
264
+ ) </dev/null >/dev/null 2>&1 &
265
+ ;;
266
+ post-rewrite)
267
+ case "\${1-}" in amend | rebase) prim_source=$1 ;; *) exit 0 ;; esac
268
+ prim_pairs=$(mktemp "\${TMPDIR:-/tmp}/prim-post-rewrite-pairs.XXXXXXXX" 2>/dev/null) || exit 0
269
+ if ! chmod 600 "$prim_pairs" 2>/dev/null || ! cat >"$prim_pairs"; then
270
+ rm -f "$prim_pairs"
271
+ exit 0
272
+ fi
273
+ prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
274
+ (
275
+ trap '' HUP
276
+ trap 'rm -f "$prim_pairs"' 0
277
+ PRIM_REWRITE_SOURCE=$prim_source PRIM_REWRITE_BRANCH=$prim_branch PRIM_REWRITE_PAIRS_FILE=$prim_pairs "$prim_launcher" prim-post-rewrite
278
+ ) </dev/null >/dev/null 2>&1 &
279
+ ;;
280
+ esac
281
+ exit 0
282
+ `;
283
+
284
+ // src/lib/native-keyring.ts
285
+ import { existsSync as existsSync3 } from "fs";
286
+ import { createRequire } from "module";
287
+ import { dirname as dirname4, join as join3 } from "path";
288
+ import { fileURLToPath as fileURLToPath2 } from "url";
289
+ var require2 = createRequire(import.meta.url);
290
+
291
+ // src/lib/paths.ts
292
+ import { homedir } from "os";
293
+ import { isAbsolute as isAbsolute2, join as join4, normalize } from "path";
294
+ var UNSAFE_CONFIG_PATH_CHARACTERS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
295
+ function absolutePath(value, variable) {
296
+ if (value !== void 0 && UNSAFE_CONFIG_PATH_CHARACTERS.test(value)) {
297
+ throw new Error(`${variable} contains unsafe characters`);
298
+ }
299
+ if (!value || value.trim() !== value || !isAbsolute2(value)) return;
300
+ const normalized = normalize(value);
301
+ return normalized === value ? value : void 0;
302
+ }
303
+ function resolvePrimConfigDirectory(options = {}) {
304
+ const env = options.env ?? process.env;
305
+ const explicit = absolutePath(env.PRIM_CONFIG_DIR, "PRIM_CONFIG_DIR");
306
+ if (explicit) return { path: explicit, source: "explicit" };
307
+ const xdgConfigHome = absolutePath(env.XDG_CONFIG_HOME, "XDG_CONFIG_HOME");
308
+ if (xdgConfigHome) return { path: join4(xdgConfigHome, "prim"), source: "xdg" };
309
+ const home = absolutePath(options.homeDir ?? homedir(), "HOME");
310
+ if (!home) {
311
+ throw new Error("cannot resolve Primitive config directory: HOME is not an absolute path");
312
+ }
313
+ return { path: join4(home, ".config", "prim"), source: "default" };
314
+ }
315
+ function primConfigDirectory(options = {}) {
316
+ return resolvePrimConfigDirectory(options).path;
317
+ }
318
+
319
+ // src/lib/hook-runtime.ts
320
+ var RELEASE_PREFIX = "release-";
321
+ var MAX_MANIFEST_BYTES = 64 * 1024;
322
+ var RELEASE_GRACE_MS = 10 * 60 * 1e3;
323
+ var HOOK_RUNTIME_ENTRIES = {
324
+ // SessionStart self-healing resolves this exact CLI entry to run
325
+ // `daemon ensure`; it must travel with the immutable hook release.
326
+ prim: "dist/index.js",
327
+ "prim-hook": "dist/hooks/prim-hook.js",
328
+ "prim-pre-commit": "dist/hooks/pre-commit.js",
329
+ "prim-post-commit": "dist/hooks/post-commit.js",
330
+ "prim-post-rewrite": "dist/hooks/post-rewrite.js",
331
+ "prim-pre-tool-use-worker": "dist/hooks/pre-tool-use-worker.js",
332
+ "prim-pre-tool-use": "dist/hooks/pre-tool-use.js",
333
+ "prim-post-tool-use": "dist/hooks/post-tool-use.js",
334
+ "prim-session-start": "dist/hooks/session-start.js",
335
+ "prim-session-end": "dist/hooks/session-end.js",
336
+ "prim-daemon-server": "dist/daemon/server.js",
337
+ "prim-statusline": "dist/statusline-main.js"
338
+ };
339
+ var SOURCE_ENTRIES = Object.fromEntries(
340
+ Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, target]) => [
341
+ bin,
342
+ target.replace(/^dist\//u, "")
343
+ ])
344
+ );
345
+ var STABLE_HOOK_LAUNCHER_CONTENT = `#!/bin/sh
346
+ set -eu
347
+ case "$0" in */*) prim_launcher_dir=\${0%/*} ;; *) exit 78 ;; esac
348
+ IFS= read -r prim_release_name < "$prim_launcher_dir/hook-runtime/current" || exit 69
349
+ case "$prim_release_name" in ${RELEASE_PREFIX}*) ;; *) exit 69 ;; esac
350
+ prim_release_id=\${prim_release_name#${RELEASE_PREFIX}}
351
+ case "$prim_release_id" in *[!0-9a-f]*|"") exit 69 ;; esac
352
+ [ "\${#prim_release_id}" -eq 64 ] || exit 69
353
+ prim_release="$prim_launcher_dir/hook-runtime/releases/$prim_release_name"
354
+ case "\${1-}" in
355
+ ${Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, entry]) => ` ${bin}) prim_entry="$prim_release/${entry}" ;;`).join("\n")}
356
+ *) exit 64 ;;
357
+ esac
358
+ shift
359
+ IFS= read -r prim_node < "$prim_release/node" || exit 69
360
+ case "$prim_node" in /*) ;; *) exit 69 ;; esac
361
+ [ -x "$prim_node" ] && [ -f "$prim_entry" ] || exit 69
362
+ exec "$prim_node" "$prim_entry" "$@"
363
+ `;
364
+
365
+ // src/lib/machine-broker.ts
366
+ import { spawn } from "child_process";
367
+ import { createHash as createHash2, createHmac, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
368
+ import { lstatSync as lstatSync2, readFileSync as readFileSync4, rmSync as rmSync4 } from "fs";
369
+ import { createServer } from "http";
370
+ import { basename, join as join6 } from "path";
371
+ import { fileURLToPath as fileURLToPath3 } from "url";
372
+
224
373
  // src/lib/loopback-fetch.ts
225
374
  import { request } from "http";
226
375
  import { Readable } from "stream";
@@ -377,34 +526,6 @@ function parseMachineIdentity(value, clientId) {
377
526
  };
378
527
  }
379
528
 
380
- // src/lib/paths.ts
381
- import { homedir } from "os";
382
- import { isAbsolute as isAbsolute2, join as join3, normalize } from "path";
383
- var UNSAFE_CONFIG_PATH_CHARACTERS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
384
- function absolutePath(value, variable) {
385
- if (value !== void 0 && UNSAFE_CONFIG_PATH_CHARACTERS.test(value)) {
386
- throw new Error(`${variable} contains unsafe characters`);
387
- }
388
- if (!value || value.trim() !== value || !isAbsolute2(value)) return;
389
- const normalized = normalize(value);
390
- return normalized === value ? value : void 0;
391
- }
392
- function resolvePrimConfigDirectory(options = {}) {
393
- const env = options.env ?? process.env;
394
- const explicit = absolutePath(env.PRIM_CONFIG_DIR, "PRIM_CONFIG_DIR");
395
- if (explicit) return { path: explicit, source: "explicit" };
396
- const xdgConfigHome = absolutePath(env.XDG_CONFIG_HOME, "XDG_CONFIG_HOME");
397
- if (xdgConfigHome) return { path: join3(xdgConfigHome, "prim"), source: "xdg" };
398
- const home = absolutePath(options.homeDir ?? homedir(), "HOME");
399
- if (!home) {
400
- throw new Error("cannot resolve Primitive config directory: HOME is not an absolute path");
401
- }
402
- return { path: join3(home, ".config", "prim"), source: "default" };
403
- }
404
- function primConfigDirectory(options = {}) {
405
- return resolvePrimConfigDirectory(options).path;
406
- }
407
-
408
529
  // src/lib/machine-broker.ts
409
530
  var MAX_RESPONSE_BYTES = 96 * 1024;
410
531
  var MAX_FORWARD_REQUEST_BYTES = 12 * 1024 * 1024;
@@ -413,23 +534,23 @@ var MAX_FORWARD_RESPONSE_BYTES = 36 * 1024 * 1024;
413
534
  var IDLE_MS = 5 * 6e4;
414
535
 
415
536
  // src/lib/machine-retry.ts
416
- import { createHash as createHash2 } from "crypto";
417
- import { lstatSync as lstatSync2, readFileSync as readFileSync4, readdirSync, rmSync as rmSync4 } from "fs";
418
- import { join as join5 } from "path";
537
+ import { createHash as createHash3 } from "crypto";
538
+ import { lstatSync as lstatSync3, readFileSync as readFileSync5, readdirSync as readdirSync2, rmSync as rmSync5 } from "fs";
539
+ import { join as join7 } from "path";
419
540
  var MAX_SERVER_WAIT_MS = 15 * 6e4;
420
541
 
421
542
  // src/lib/session-identity.ts
422
543
  import { execFile } from "child_process";
423
- import { createHash as createHash4 } from "crypto";
424
- import { rmSync as rmSync5 } from "fs";
425
- import { join as join7 } from "path";
544
+ import { createHash as createHash5 } from "crypto";
545
+ import { rmSync as rmSync6 } from "fs";
546
+ import { join as join9 } from "path";
426
547
  import { promisify } from "util";
427
548
 
428
549
  // src/lib/git.ts
429
550
  import { execFileSync } from "child_process";
430
- import { createHash as createHash3 } from "crypto";
431
- import { lstatSync as lstatSync3, readFileSync as readFileSync5, realpathSync } from "fs";
432
- import { basename as basename2, dirname as dirname4, isAbsolute as isAbsolute3, join as join6, relative, resolve, sep } from "path";
551
+ import { createHash as createHash4 } from "crypto";
552
+ import { lstatSync as lstatSync4, readFileSync as readFileSync6, realpathSync as realpathSync2 } from "fs";
553
+ import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute4, join as join8, relative, resolve as resolve2, sep } from "path";
433
554
  var GIT_TIMEOUT_MS = 1e3;
434
555
  var MAX_SETTINGS_BYTES = 1024 * 1024;
435
556
  var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
@@ -483,12 +604,12 @@ function githubRepositoryFromRemote(remote) {
483
604
  return path ? parseGithubRepositoryName(path) : null;
484
605
  }
485
606
  function checkoutSettingsText(repoRoot) {
486
- const path = join6(repoRoot, ".claude", "settings.json");
607
+ const path = join8(repoRoot, ".claude", "settings.json");
487
608
  try {
488
- if (!lstatSync3(join6(repoRoot, ".claude")).isDirectory()) return null;
489
- const stat = lstatSync3(path);
609
+ if (!lstatSync4(join8(repoRoot, ".claude")).isDirectory()) return null;
610
+ const stat = lstatSync4(path);
490
611
  if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
491
- return readFileSync5(path, "utf8");
612
+ return readFileSync6(path, "utf8");
492
613
  } catch {
493
614
  return null;
494
615
  }
@@ -541,16 +662,16 @@ function normalizeOriginRemote(remote) {
541
662
  }
542
663
  }
543
664
  function opaqueRepoKey(source, value) {
544
- return `repo_v1_${createHash3("sha256").update(`${source}\0${value}`).digest("hex")}`;
665
+ return `repo_v1_${createHash4("sha256").update(`${source}\0${value}`).digest("hex")}`;
545
666
  }
546
667
  function resolveRepositoryContext(cwd = process.cwd()) {
547
668
  const top = gitToplevel(cwd);
548
669
  if (!top) return null;
549
670
  let repoRoot;
550
671
  try {
551
- repoRoot = realpathSync.native(top);
672
+ repoRoot = realpathSync2.native(top);
552
673
  } catch {
553
- repoRoot = resolve(top);
674
+ repoRoot = resolve2(top);
554
675
  }
555
676
  const origin = gitValue(repoRoot, ["config", "--get", "remote.origin.url"]);
556
677
  const repoFullName = githubRepositoryFullName(repoRoot) ?? void 0;
@@ -620,7 +741,7 @@ var CHALLENGE_GONE = failure(
620
741
  NEW_SESSION_REMEDY
621
742
  );
622
743
  function hash(value) {
623
- return createHash4("sha256").update(value).digest("hex");
744
+ return createHash5("sha256").update(value).digest("hex");
624
745
  }
625
746
  function sessionContext(deps) {
626
747
  const env = deps.env ?? process.env;
@@ -647,9 +768,9 @@ function sessionContext(deps) {
647
768
  clientId: environment.clientId,
648
769
  generation: environment.generation,
649
770
  sessionId,
650
- tokenPath: join7(directory, `session_identity_${key}.json`),
651
- statePath: join7(directory, `session_identity_${key}.state.json`),
652
- lockPath: join7(directory, "session-identity.lock")
771
+ tokenPath: join9(directory, `session_identity_${key}.json`),
772
+ statePath: join9(directory, `session_identity_${key}.state.json`),
773
+ lockPath: join9(directory, "session-identity.lock")
653
774
  };
654
775
  }
655
776
  function readRecord(path) {
@@ -715,7 +836,7 @@ var SERVER_CONTRACT_FAILURE = failure(
715
836
  function sessionScoped(deps) {
716
837
  return !deps.localEnvironment && !deps.environmentOnly && sessionIdentityMode(deps);
717
838
  }
718
- var require2 = createRequire(import.meta.url);
839
+ var require3 = createRequire2(import.meta.url);
719
840
  var DEFAULT_API_URL2 = "https://api.getprimitive.ai";
720
841
  var PROFILE_FILE = "machine_profile.json";
721
842
  var cached;
@@ -726,10 +847,10 @@ function apiUrlFor(deps) {
726
847
  return machineApiUrl((deps.env ?? process.env).PRIM_API_URL?.trim() || DEFAULT_API_URL2);
727
848
  }
728
849
  function hash2(value) {
729
- return createHash5("sha256").update(value).digest("hex");
850
+ return createHash6("sha256").update(value).digest("hex");
730
851
  }
731
852
  function environmentContextPath(deps, clientId) {
732
- return join8(
853
+ return join10(
733
854
  configurationDirectory(deps),
734
855
  `machine_context_${hash2(`${apiUrlFor(deps)}\0${clientId}`)}.json`
735
856
  );
@@ -757,7 +878,7 @@ function readEnvironmentContext(environment, deps) {
757
878
  }
758
879
  function protectPath(path, directory) {
759
880
  if (process.platform !== "win32") {
760
- chmodSync(path, directory ? 448 : 384);
881
+ chmodSync2(path, directory ? 448 : 384);
761
882
  return;
762
883
  }
763
884
  const encodedPath = Buffer.from(path).toString("base64");
@@ -774,8 +895,8 @@ function protectPath(path, directory) {
774
895
  );
775
896
  }
776
897
  function ensureDirectory(directory) {
777
- mkdirSync3(directory, { recursive: true, mode: 448 });
778
- if (lstatSync4(directory).isSymbolicLink())
898
+ mkdirSync4(directory, { recursive: true, mode: 448 });
899
+ if (lstatSync5(directory).isSymbolicLink())
779
900
  throw new MachineAuthError(
780
901
  "unsafe_storage",
781
902
  "Credential directory must not be a symbolic link."
@@ -788,14 +909,14 @@ function readMachineMetadata(path) {
788
909
  function readPrivate(path) {
789
910
  let raw;
790
911
  try {
791
- const stat = lstatSync4(path);
912
+ const stat = lstatSync5(path);
792
913
  if (!stat.isFile() || stat.size > 96 * 1024 || process.platform !== "win32" && ((stat.mode & 63) !== 0 || stat.uid !== process.getuid?.())) {
793
914
  throw new MachineAuthError(
794
915
  "unsafe_storage",
795
916
  "Machine credential files must be owner-only regular files."
796
917
  );
797
918
  }
798
- raw = readFileSync6(path, "utf8");
919
+ raw = readFileSync7(path, "utf8");
799
920
  } catch (error) {
800
921
  if (error.code === "ENOENT") return void 0;
801
922
  throw error;
@@ -840,7 +961,7 @@ function parseProfile(value) {
840
961
  };
841
962
  }
842
963
  function readMachineProfile(deps = {}) {
843
- const value = readPrivate(join8(configurationDirectory(deps), PROFILE_FILE));
964
+ const value = readPrivate(join10(configurationDirectory(deps), PROFILE_FILE));
844
965
  return value === void 0 ? void 0 : parseProfile(value);
845
966
  }
846
967
  var NETWORK_SECRET_AUTH = "network-secret";
@@ -849,20 +970,20 @@ var INJECTED_IDENTITY_TTL_MS = 60 * 6e4;
849
970
  var brokerKeys = /* @__PURE__ */ new Map();
850
971
  function networkSecretBrokerKey(deps, clientId) {
851
972
  const directory = configurationDirectory(deps);
852
- const path = join8(directory, `machine_network_${hash2(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
973
+ const path = join10(directory, `machine_network_${hash2(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
853
974
  const known = brokerKeys.get(path);
854
975
  if (known) return known;
855
976
  ensureDirectory(directory);
856
977
  const read = () => {
857
978
  try {
858
- const stat = lstatSync4(path);
979
+ const stat = lstatSync5(path);
859
980
  if (!stat.isFile() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || typeof process.getuid === "function" && stat.uid !== process.getuid()))
860
981
  throw new MachineAuthError(
861
982
  "unsafe_storage",
862
983
  `The machine broker key at ${path} is not an owner-only file. Delete it and retry.`,
863
984
  true
864
985
  );
865
- const value = readFileSync6(path, "utf8").trim();
986
+ const value = readFileSync7(path, "utf8").trim();
866
987
  return { key: /^[a-f0-9]{64}$/u.test(value) ? value : void 0 };
867
988
  } catch (error) {
868
989
  if (error.code === "ENOENT") return void 0;
@@ -881,16 +1002,16 @@ function networkSecretBrokerKey(deps, clientId) {
881
1002
  `The machine broker key at ${path} is damaged. Delete it and retry.`,
882
1003
  true
883
1004
  );
884
- const staged = `${path}.${process.pid}.${randomBytes3(6).toString("hex")}`;
1005
+ const staged = `${path}.${process.pid}.${randomBytes4(6).toString("hex")}`;
885
1006
  try {
886
- writeFileSync3(staged, `${randomBytes3(32).toString("hex")}
1007
+ writeFileSync4(staged, `${randomBytes4(32).toString("hex")}
887
1008
  `, { mode: 384, flag: "wx" });
888
1009
  protectPath(staged, false);
889
1010
  linkSync(staged, path);
890
1011
  } catch (error) {
891
1012
  if (error.code !== "EEXIST") throw error;
892
1013
  } finally {
893
- rmSync6(staged, { force: true });
1014
+ rmSync7(staged, { force: true });
894
1015
  }
895
1016
  }
896
1017
  const key = read()?.key;
@@ -949,7 +1070,7 @@ function environmentCredentials(deps) {
949
1070
  }
950
1071
  function hasMachineConfiguration(deps = {}) {
951
1072
  const env = deps.env ?? process.env;
952
- const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || env.PRIM_M2M_CLIENT_AUTH !== void 0 || existsSync3(join8(configurationDirectory(deps), PROFILE_FILE));
1073
+ const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || env.PRIM_M2M_CLIENT_AUTH !== void 0 || existsSync5(join10(configurationDirectory(deps), PROFILE_FILE));
953
1074
  if (configured && env.PRIM_TOKEN?.trim()) {
954
1075
  throw new MachineAuthError(
955
1076
  "conflicting_credentials",
@@ -1009,20 +1130,20 @@ function machinePendingBucket(identity) {
1009
1130
 
1010
1131
  // src/lib/credentials.ts
1011
1132
  var CONFIG_DIRECTORY = primConfigDirectory();
1012
- var TOKEN_FILE_PATH = join9(CONFIG_DIRECTORY, "token");
1013
- var REFRESH_TOKEN_PATH = join9(CONFIG_DIRECTORY, "refresh_token");
1014
- var TOKEN_EXPIRES_PATH = join9(CONFIG_DIRECTORY, "token_expires_at");
1015
- var TERMINAL_REFRESH_PATH = join9(CONFIG_DIRECTORY, "refresh_terminal");
1016
- var CREDENTIAL_METADATA_PATH = join9(CONFIG_DIRECTORY, "credential_metadata.json");
1017
- var CREDENTIAL_FAMILY_PATH = join9(CONFIG_DIRECTORY, "credential_family.json");
1018
- var CREDENTIAL_MIGRATION_PATH = join9(CONFIG_DIRECTORY, "credential_migration.json");
1019
- var CREDENTIAL_LOCK_PATH = join9(CONFIG_DIRECTORY, "credentials.lock");
1133
+ var TOKEN_FILE_PATH = join11(CONFIG_DIRECTORY, "token");
1134
+ var REFRESH_TOKEN_PATH = join11(CONFIG_DIRECTORY, "refresh_token");
1135
+ var TOKEN_EXPIRES_PATH = join11(CONFIG_DIRECTORY, "token_expires_at");
1136
+ var TERMINAL_REFRESH_PATH = join11(CONFIG_DIRECTORY, "refresh_terminal");
1137
+ var CREDENTIAL_METADATA_PATH = join11(CONFIG_DIRECTORY, "credential_metadata.json");
1138
+ var CREDENTIAL_FAMILY_PATH = join11(CONFIG_DIRECTORY, "credential_family.json");
1139
+ var CREDENTIAL_MIGRATION_PATH = join11(CONFIG_DIRECTORY, "credential_migration.json");
1140
+ var CREDENTIAL_LOCK_PATH = join11(CONFIG_DIRECTORY, "credentials.lock");
1020
1141
  var MAX_CREDENTIAL_METADATA_BYTES = 4096;
1021
1142
  var CREDENTIAL_MIGRATION_VERSION = 1;
1022
1143
  var CREDENTIAL_MIGRATION_STATE = "family_bound";
1023
1144
  function readTrimmed(path) {
1024
1145
  try {
1025
- const value = readFileSync7(path, "utf8").trim();
1146
+ const value = readFileSync8(path, "utf8").trim();
1026
1147
  return value || void 0;
1027
1148
  } catch {
1028
1149
  return void 0;
@@ -1059,7 +1180,7 @@ function resolveAuthCredential(options = {}) {
1059
1180
  return { token: stored, source: "token_file" };
1060
1181
  }
1061
1182
  function credentialFingerprint(value) {
1062
- return createHash6("sha256").update(value).digest("hex");
1183
+ return createHash7("sha256").update(value).digest("hex");
1063
1184
  }
1064
1185
  function parseLegacyBrokerCredentialMetadata(value) {
1065
1186
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
@@ -1079,7 +1200,7 @@ function parseLegacyBrokerCredentialMetadata(value) {
1079
1200
  function readBoundedCredentialJson(path) {
1080
1201
  let raw;
1081
1202
  try {
1082
- raw = readFileSync7(path, "utf8");
1203
+ raw = readFileSync8(path, "utf8");
1083
1204
  } catch (error) {
1084
1205
  return error.code === "ENOENT" ? void 0 : null;
1085
1206
  }
@@ -1152,14 +1273,14 @@ function jwtOrganizationId(token) {
1152
1273
 
1153
1274
  // src/binding.ts
1154
1275
  var PRIM_CONFIG_DIR = primConfigDirectory();
1155
- var SESSIONS_DIR = join10(PRIM_CONFIG_DIR, "sessions");
1276
+ var SESSIONS_DIR = join12(PRIM_CONFIG_DIR, "sessions");
1156
1277
  var WORKSPACE_FILE = ".prim/workspace.json";
1157
1278
  function readJsonSafe(path) {
1158
- if (!existsSync4(path)) {
1279
+ if (!existsSync6(path)) {
1159
1280
  return;
1160
1281
  }
1161
1282
  try {
1162
- return JSON.parse(readFileSync8(path, "utf-8"));
1283
+ return JSON.parse(readFileSync9(path, "utf-8"));
1163
1284
  } catch {
1164
1285
  return;
1165
1286
  }
@@ -1168,17 +1289,17 @@ function fromSessionMarker(sessionId) {
1168
1289
  if (!sessionId) {
1169
1290
  return;
1170
1291
  }
1171
- const marker = readJsonSafe(join10(SESSIONS_DIR, `${sessionId}.json`));
1292
+ const marker = readJsonSafe(join12(SESSIONS_DIR, `${sessionId}.json`));
1172
1293
  return marker?.orgId;
1173
1294
  }
1174
1295
  function fromWorkspaceFile(startDir) {
1175
1296
  let dir = startDir;
1176
1297
  while (true) {
1177
- const config = readJsonSafe(join10(dir, WORKSPACE_FILE));
1298
+ const config = readJsonSafe(join12(dir, WORKSPACE_FILE));
1178
1299
  if (config?.orgId) {
1179
1300
  return config.orgId;
1180
1301
  }
1181
- const parent = dirname6(dir);
1302
+ const parent = dirname8(dir);
1182
1303
  if (parent === dir) {
1183
1304
  return;
1184
1305
  }
@@ -1214,26 +1335,26 @@ function resolveOrg(args) {
1214
1335
  import {
1215
1336
  appendFileSync,
1216
1337
  closeSync as closeSync2,
1217
- existsSync as existsSync7,
1338
+ existsSync as existsSync9,
1218
1339
  fstatSync,
1219
- mkdirSync as mkdirSync5,
1340
+ mkdirSync as mkdirSync6,
1220
1341
  openSync as openSync2,
1221
1342
  opendirSync,
1222
- readFileSync as readFileSync12,
1343
+ readFileSync as readFileSync13,
1223
1344
  readSync,
1224
- readdirSync as readdirSync3
1345
+ readdirSync as readdirSync4
1225
1346
  } from "fs";
1226
- import { dirname as dirname9, join as join14 } from "path";
1347
+ import { dirname as dirname11, join as join16 } from "path";
1227
1348
 
1228
1349
  // src/client.ts
1229
- import { createHash as createHash7 } from "crypto";
1230
- import { chmodSync as chmodSync3, existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync10, rmSync as rmSync7 } from "fs";
1231
- import { dirname as dirname7 } from "path";
1350
+ import { createHash as createHash8 } from "crypto";
1351
+ import { chmodSync as chmodSync4, existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync11, rmSync as rmSync8 } from "fs";
1352
+ import { dirname as dirname9 } from "path";
1232
1353
 
1233
1354
  // src/daemon/client-instance-id.ts
1234
- import { randomBytes as randomBytes4 } from "crypto";
1235
- import { chmodSync as chmodSync2, lstatSync as lstatSync5, readFileSync as readFileSync9 } from "fs";
1236
- import { join as join11 } from "path";
1355
+ import { randomBytes as randomBytes5 } from "crypto";
1356
+ import { chmodSync as chmodSync3, lstatSync as lstatSync6, readFileSync as readFileSync10 } from "fs";
1357
+ import { join as join13 } from "path";
1237
1358
  var INSTANCE_BODY_CHARS = 43;
1238
1359
  var INSTANCE_PREFIX = "pci_";
1239
1360
  var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
@@ -1253,17 +1374,17 @@ var CLI_MANAGEMENT_RESPONSE_MAX_BYTES = 2 * 1024 * 1024;
1253
1374
 
1254
1375
  // src/drain-progress.ts
1255
1376
  import {
1256
- chmodSync as chmodSync4,
1257
- existsSync as existsSync6,
1258
- readFileSync as readFileSync11,
1259
- readdirSync as readdirSync2,
1260
- rmSync as rmSync8,
1377
+ chmodSync as chmodSync5,
1378
+ existsSync as existsSync8,
1379
+ readFileSync as readFileSync12,
1380
+ readdirSync as readdirSync3,
1381
+ rmSync as rmSync9,
1261
1382
  rmdirSync
1262
1383
  } from "fs";
1263
- import { basename as basename3, dirname as dirname8, join as join13 } from "path";
1384
+ import { basename as basename3, dirname as dirname10, join as join15 } from "path";
1264
1385
 
1265
1386
  // src/journal.ts
1266
- var JOURNAL_DIR = join14(primConfigDirectory(), "moves");
1387
+ var JOURNAL_DIR = join16(primConfigDirectory(), "moves");
1267
1388
  var UNBOUND_BUCKET = "_unbound";
1268
1389
  var JOURNAL_BASENAME = "journal.ndjson";
1269
1390
  var JOURNAL_STATS_SAMPLE_BYTES = 64 * 1024;
@@ -1275,26 +1396,26 @@ function envSlug(apiUrl) {
1275
1396
  return slug;
1276
1397
  }
1277
1398
  function currentEnvDir() {
1278
- return join14(JOURNAL_DIR, envSlug(getSiteUrl()));
1399
+ return join16(JOURNAL_DIR, envSlug(getSiteUrl()));
1279
1400
  }
1280
1401
  var DIR_MODE = 448;
1281
1402
  var FILE_MODE = 384;
1282
1403
  var SAFE_BUCKET = /^[A-Za-z0-9_-]+$/;
1283
1404
  var RESERVED_BUCKETS = /* @__PURE__ */ new Set([UNBOUND_BUCKET, "_legacy"]);
1284
1405
  function appendMoveToPath(path, move) {
1285
- const dir = dirname9(path);
1286
- if (!existsSync7(dir)) {
1287
- mkdirSync5(dir, { recursive: true, mode: DIR_MODE });
1406
+ const dir = dirname11(path);
1407
+ if (!existsSync9(dir)) {
1408
+ mkdirSync6(dir, { recursive: true, mode: DIR_MODE });
1288
1409
  }
1289
1410
  appendFileSync(path, `${JSON.stringify(move)}
1290
1411
  `, { mode: FILE_MODE });
1291
1412
  }
1292
1413
  function bucketDir(orgId) {
1293
1414
  const safe = orgId !== void 0 && SAFE_BUCKET.test(orgId) && !RESERVED_BUCKETS.has(orgId);
1294
- return join14(currentEnvDir(), safe ? orgId : UNBOUND_BUCKET);
1415
+ return join16(currentEnvDir(), safe ? orgId : UNBOUND_BUCKET);
1295
1416
  }
1296
1417
  function journalPath(orgId) {
1297
- return join14(bucketDir(orgId), JOURNAL_BASENAME);
1418
+ return join16(bucketDir(orgId), JOURNAL_BASENAME);
1298
1419
  }
1299
1420
  function appendMove(move, orgId) {
1300
1421
  const actor = machineCaptureActor();
@@ -1307,21 +1428,21 @@ var FLUSHING_PREFIX = `${JOURNAL_BASENAME}.flushing.`;
1307
1428
 
1308
1429
  // src/lib/activation.ts
1309
1430
  import { execFileSync as execFileSync4 } from "child_process";
1310
- import { existsSync as existsSync9, readFileSync as readFileSync14 } from "fs";
1431
+ import { existsSync as existsSync11, readFileSync as readFileSync15 } from "fs";
1311
1432
  import { homedir as homedir2 } from "os";
1312
- import { join as join16 } from "path";
1433
+ import { join as join18 } from "path";
1313
1434
 
1314
1435
  // src/lib/cloud-prepared.ts
1315
- import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync13, rmSync as rmSync9, writeFileSync as writeFileSync4 } from "fs";
1316
- import { join as join15 } from "path";
1436
+ import { existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync14, rmSync as rmSync10, writeFileSync as writeFileSync5 } from "fs";
1437
+ import { join as join17 } from "path";
1317
1438
  var CLOUD_PREPARED_MARKER = "cloud-prepared";
1318
1439
  function cloudPreparedPath(env = process.env) {
1319
- return join15(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
1440
+ return join17(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
1320
1441
  }
1321
1442
  function isPreparedCloudSession(env = process.env) {
1322
1443
  if (!isClaudeCloudSession(env)) return false;
1323
1444
  try {
1324
- return existsSync8(cloudPreparedPath(env));
1445
+ return existsSync10(cloudPreparedPath(env));
1325
1446
  } catch {
1326
1447
  return false;
1327
1448
  }
@@ -1440,10 +1561,10 @@ function repoSyncId(cwd) {
1440
1561
  function projectPrimInstallAt(root) {
1441
1562
  if (root === null || root === homedir2()) return false;
1442
1563
  for (const rel of PROJECT_INSTALL_FILES) {
1443
- const path = join16(root, rel);
1444
- if (existsSync9(path)) {
1564
+ const path = join18(root, rel);
1565
+ if (existsSync11(path)) {
1445
1566
  try {
1446
- const content = readFileSync14(path, "utf-8");
1567
+ const content = readFileSync15(path, "utf-8");
1447
1568
  if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
1448
1569
  } catch {
1449
1570
  }
@@ -28444,8 +28565,8 @@ function cachedCollectScopeAdmits(cwd, facts) {
28444
28565
 
28445
28566
  // src/lib/commit-heartbeat.ts
28446
28567
  import { execFileSync as execFileSync5 } from "child_process";
28447
- import { mkdirSync as mkdirSync7, readFileSync as readFileSync15, readdirSync as readdirSync4, unlinkSync } from "fs";
28448
- import { dirname as dirname10, join as join17, resolve as resolve3 } from "path";
28568
+ import { mkdirSync as mkdirSync8, readFileSync as readFileSync16, readdirSync as readdirSync5, unlinkSync } from "fs";
28569
+ import { dirname as dirname12, join as join19, resolve as resolve4 } from "path";
28449
28570
  var FIRED_DIR = "prim/post-commit-fired";
28450
28571
  var GIT_TIMEOUT_MS4 = 1e3;
28451
28572
  var MAX_STAMP_BYTES = 1024;
@@ -28460,11 +28581,11 @@ function gitPath(cwd, relative2) {
28460
28581
  timeout: GIT_TIMEOUT_MS4
28461
28582
  }).replace(/\r?\n$/u, "");
28462
28583
  if (value === "" || /[\0\r\n]/u.test(value)) throw new Error("Git returned an unsafe path");
28463
- return resolve3(cwd, value);
28584
+ return resolve4(cwd, value);
28464
28585
  }
28465
28586
  function ensurePrivateParent(path) {
28466
- mkdirSync7(dirname10(dirname10(path)), { recursive: true, mode: 448 });
28467
- mkdirSync7(dirname10(path), { recursive: true, mode: 448 });
28587
+ mkdirSync8(dirname12(dirname12(path)), { recursive: true, mode: 448 });
28588
+ mkdirSync8(dirname12(path), { recursive: true, mode: 448 });
28468
28589
  }
28469
28590
  function writeStamp(path, at) {
28470
28591
  ensurePrivateParent(path);
@@ -28473,7 +28594,7 @@ function writeStamp(path, at) {
28473
28594
  }
28474
28595
  function readStampAt(path) {
28475
28596
  try {
28476
- const raw = readFileSync15(path, "utf8");
28597
+ const raw = readFileSync16(path, "utf8");
28477
28598
  if (raw.length > MAX_STAMP_BYTES) return void 0;
28478
28599
  const parsed = JSON.parse(raw);
28479
28600
  return typeof parsed.at === "number" && Number.isSafeInteger(parsed.at) && parsed.at > 0 ? parsed.at : void 0;
@@ -28485,11 +28606,11 @@ function recordPostCommitFired(cwd, sha, now = Date.now()) {
28485
28606
  if (!sha || !FULL_SHA_RE.test(sha)) return;
28486
28607
  try {
28487
28608
  const dir = gitPath(cwd, FIRED_DIR);
28488
- writeStamp(join17(dir, sha), now);
28489
- const names = readdirSync4(dir).filter((name) => FULL_SHA_RE.test(name));
28609
+ writeStamp(join19(dir, sha), now);
28610
+ const names = readdirSync5(dir).filter((name) => FULL_SHA_RE.test(name));
28490
28611
  if (names.length <= MAX_FIRED_STAMPS + PRUNE_SLACK) return;
28491
- const stale = names.map((name) => ({ name, at: readStampAt(join17(dir, name)) ?? 0 })).sort((left, right) => right.at - left.at || left.name.localeCompare(right.name)).slice(MAX_FIRED_STAMPS);
28492
- for (const { name } of stale) unlinkSync(join17(dir, name));
28612
+ const stale = names.map((name) => ({ name, at: readStampAt(join19(dir, name)) ?? 0 })).sort((left, right) => right.at - left.at || left.name.localeCompare(right.name)).slice(MAX_FIRED_STAMPS);
28613
+ for (const { name } of stale) unlinkSync(join19(dir, name));
28493
28614
  } catch {
28494
28615
  }
28495
28616
  }
@@ -28504,22 +28625,22 @@ function unattendedEnv(env = process.env) {
28504
28625
  import { execFileSync as execFileSync6 } from "child_process";
28505
28626
  import { randomUUID as randomUUID3 } from "crypto";
28506
28627
  import {
28507
- constants as constants2,
28508
- chmodSync as chmodSync5,
28628
+ constants as constants3,
28629
+ chmodSync as chmodSync6,
28509
28630
  closeSync as closeSync3,
28510
28631
  fchmodSync as fchmodSync2,
28511
28632
  fsyncSync as fsyncSync2,
28512
28633
  linkSync as linkSync2,
28513
- lstatSync as lstatSync6,
28514
- mkdirSync as mkdirSync8,
28634
+ lstatSync as lstatSync7,
28635
+ mkdirSync as mkdirSync9,
28515
28636
  openSync as openSync3,
28516
- readFileSync as readFileSync16,
28517
- statSync as statSync2,
28637
+ readFileSync as readFileSync17,
28638
+ statSync as statSync3,
28518
28639
  unlinkSync as unlinkSync2,
28519
- writeFileSync as writeFileSync5
28640
+ writeFileSync as writeFileSync6
28520
28641
  } from "fs";
28521
- import { dirname as dirname11, isAbsolute as isAbsolute4, join as join18, resolve as resolve4 } from "path";
28522
- var WORKSPACE_ID_RELATIVE_PATH = join18("prim", "workspace-id");
28642
+ import { dirname as dirname13, isAbsolute as isAbsolute5, join as join20, resolve as resolve5 } from "path";
28643
+ var WORKSPACE_ID_RELATIVE_PATH = join20("prim", "workspace-id");
28523
28644
  var MAX_ANCESTORS = 64;
28524
28645
  var MAX_GIT_FILE_BYTES = 4096;
28525
28646
  var MAX_ID_FILE_BYTES = 128;
@@ -28565,7 +28686,7 @@ function resolveWorkspaceIdPath(cwd) {
28565
28686
  }
28566
28687
  return {
28567
28688
  status: "resolved",
28568
- path: isAbsolute4(gitPath2) ? resolve4(gitPath2) : resolve4(cwd, gitPath2)
28689
+ path: isAbsolute5(gitPath2) ? resolve5(gitPath2) : resolve5(cwd, gitPath2)
28569
28690
  };
28570
28691
  } catch (error) {
28571
28692
  const code = errorCode(error);
@@ -28576,21 +28697,21 @@ function resolveWorkspaceIdPath(cwd) {
28576
28697
  }
28577
28698
  }
28578
28699
  function resolveFromFilesystem(cwd) {
28579
- let current = resolve4(cwd);
28700
+ let current = resolve5(cwd);
28580
28701
  for (let depth = 0; depth < MAX_ANCESTORS; depth += 1) {
28581
- const dotGit = join18(current, ".git");
28702
+ const dotGit = join20(current, ".git");
28582
28703
  try {
28583
- const stat = lstatSync6(dotGit);
28704
+ const stat = lstatSync7(dotGit);
28584
28705
  if (stat.isDirectory() && isGitDirectory(dotGit)) {
28585
- return join18(dotGit, WORKSPACE_ID_RELATIVE_PATH);
28706
+ return join20(dotGit, WORKSPACE_ID_RELATIVE_PATH);
28586
28707
  }
28587
28708
  if (stat.isFile() && stat.size <= MAX_GIT_FILE_BYTES) {
28588
- const contents = readFileSync16(dotGit, "utf8");
28709
+ const contents = readFileSync17(dotGit, "utf8");
28589
28710
  const match = /^gitdir: (.+?)(?:\r?\n)?$/.exec(contents);
28590
28711
  if (match?.[1]) {
28591
- const gitDirectory = isAbsolute4(match[1]) ? resolve4(match[1]) : resolve4(current, match[1]);
28712
+ const gitDirectory = isAbsolute5(match[1]) ? resolve5(match[1]) : resolve5(current, match[1]);
28592
28713
  if (isGitDirectory(gitDirectory)) {
28593
- return join18(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
28714
+ return join20(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
28594
28715
  }
28595
28716
  }
28596
28717
  }
@@ -28601,7 +28722,7 @@ function resolveFromFilesystem(cwd) {
28601
28722
  return null;
28602
28723
  }
28603
28724
  }
28604
- const parent = dirname11(current);
28725
+ const parent = dirname13(current);
28605
28726
  if (parent === current) break;
28606
28727
  current = parent;
28607
28728
  }
@@ -28609,7 +28730,7 @@ function resolveFromFilesystem(cwd) {
28609
28730
  }
28610
28731
  function isGitDirectory(path) {
28611
28732
  try {
28612
- return statSync2(join18(path, "HEAD")).isFile();
28733
+ return statSync3(join20(path, "HEAD")).isFile();
28613
28734
  } catch {
28614
28735
  return false;
28615
28736
  }
@@ -28617,7 +28738,7 @@ function isGitDirectory(path) {
28617
28738
  function inspectPath(path) {
28618
28739
  let stat;
28619
28740
  try {
28620
- stat = lstatSync6(path);
28741
+ stat = lstatSync7(path);
28621
28742
  } catch (error) {
28622
28743
  const code = errorCode(error);
28623
28744
  if (code === "ENOENT" || code === "ENOTDIR") return { status: "missing", path };
@@ -28628,7 +28749,7 @@ function inspectPath(path) {
28628
28749
  return { status: "corrupt", path, reason: "invalid_content" };
28629
28750
  }
28630
28751
  try {
28631
- const contents = readFileSync16(path, "utf8");
28752
+ const contents = readFileSync17(path, "utf8");
28632
28753
  const workspaceId = contents.endsWith("\n") ? contents.slice(0, -1) : contents;
28633
28754
  if ((contents === workspaceId || contents === `${workspaceId}
28634
28755
  `) && isCanonicalWorkspaceId(workspaceId)) {
@@ -28645,22 +28766,22 @@ function inspectPath(path) {
28645
28766
  }
28646
28767
  }
28647
28768
  function createWorkspaceId(path) {
28648
- const parent = dirname11(path);
28769
+ const parent = dirname13(path);
28649
28770
  const workspaceId = randomUUID3();
28650
- const temporaryPath = join18(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
28771
+ const temporaryPath = join20(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
28651
28772
  let temporaryCreated = false;
28652
28773
  let publishing = false;
28653
28774
  try {
28654
- mkdirSync8(parent, { recursive: true, mode: 448 });
28655
- chmodSync5(parent, 448);
28775
+ mkdirSync9(parent, { recursive: true, mode: 448 });
28776
+ chmodSync6(parent, 448);
28656
28777
  const fd = openSync3(
28657
28778
  temporaryPath,
28658
- constants2.O_CREAT | constants2.O_EXCL | constants2.O_WRONLY,
28779
+ constants3.O_CREAT | constants3.O_EXCL | constants3.O_WRONLY,
28659
28780
  384
28660
28781
  );
28661
28782
  temporaryCreated = true;
28662
28783
  try {
28663
- writeFileSync5(fd, `${workspaceId}
28784
+ writeFileSync6(fd, `${workspaceId}
28664
28785
  `, "utf8");
28665
28786
  fchmodSync2(fd, 384);
28666
28787
  fsyncSync2(fd);
@@ -28707,7 +28828,7 @@ function errorCode(error) {
28707
28828
  }
28708
28829
 
28709
28830
  // src/hooks/prim-hook-core.ts
28710
- import { createHash as createHash8, randomUUID as randomUUID4 } from "crypto";
28831
+ import { createHash as createHash9, randomUUID as randomUUID4 } from "crypto";
28711
28832
  import { platform } from "os";
28712
28833
 
28713
28834
  // src/protocol/move.ts
@@ -28716,8 +28837,8 @@ var AGENT_ENVELOPE_VERSION = 3;
28716
28837
  var ENVELOPE_VERSION = LEGACY_ENVELOPE_VERSION;
28717
28838
 
28718
28839
  // src/hooks/redact.ts
28719
- import { existsSync as existsSync10, readFileSync as readFileSync17, statSync as statSync3 } from "fs";
28720
- import { join as join19 } from "path";
28840
+ import { existsSync as existsSync12, readFileSync as readFileSync18, statSync as statSync4 } from "fs";
28841
+ import { join as join21 } from "path";
28721
28842
  import { Worker } from "worker_threads";
28722
28843
  var USER_HOME_RULES = [
28723
28844
  {
@@ -28860,7 +28981,7 @@ function toCommitMove(commit, cliVersion, cwd, context = {}) {
28860
28981
  const validatedAttribution = validatedWorkspaceId ? attribution : void 0;
28861
28982
  const validatedCapturedAt = typeof capturedAt === "number" && Number.isSafeInteger(capturedAt) && capturedAt > 0 ? capturedAt : Date.now();
28862
28983
  const fullSha = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(commit.sha);
28863
- const moveId = validatedRepoSyncId && validatedWorkspaceId && fullSha ? `commit:v2:${createHash8("sha256").update(
28984
+ const moveId = validatedRepoSyncId && validatedWorkspaceId && fullSha ? `commit:v2:${createHash9("sha256").update(
28864
28985
  JSON.stringify(["commit:v2", validatedRepoSyncId, validatedWorkspaceId, commit.sha])
28865
28986
  ).digest("hex")}` : `commit:v2:unscoped:${randomUUID4()}`;
28866
28987
  const base = {
@@ -28898,7 +29019,7 @@ function toCommitMove(commit, cliVersion, cwd, context = {}) {
28898
29019
  }
28899
29020
 
28900
29021
  // src/hooks/post-commit.ts
28901
- var here = dirname12(fileURLToPath4(import.meta.url));
29022
+ var here = dirname14(fileURLToPath5(import.meta.url));
28902
29023
  var GIT_TIMEOUT_MS5 = 1e3;
28903
29024
  var FULL_SHA_RE2 = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u;
28904
29025
  var OBSERVATION_MARKER_RE = /^prim-post-commit-observed\.[A-Za-z0-9]+$/u;
@@ -28906,9 +29027,9 @@ var MAX_OBSERVATION_MARKER_AGE_MS = 10 * 60 * 1e3;
28906
29027
  var MAX_OBSERVATION_MARKER_FUTURE_SKEW_MS = 5e3;
28907
29028
  function capturedAtFromLauncher(env = process.env, now = Date.now()) {
28908
29029
  const path = env.PRIM_COMMIT_OBSERVED_FILE;
28909
- if (!path || !isAbsolute5(path) || !OBSERVATION_MARKER_RE.test(basename4(path))) return;
29030
+ if (!path || !isAbsolute6(path) || !OBSERVATION_MARKER_RE.test(basename4(path))) return;
28910
29031
  try {
28911
- const stat = lstatSync7(path);
29032
+ const stat = lstatSync8(path);
28912
29033
  const capturedAt = Math.trunc(stat.mtimeMs);
28913
29034
  const uid = process.getuid?.();
28914
29035
  if (!stat.isFile() || stat.isSymbolicLink() || stat.size !== 0 || stat.nlink !== 1 || (stat.mode & 63) !== 0 || uid !== void 0 && stat.uid !== uid || !Number.isSafeInteger(capturedAt) || capturedAt <= 0 || capturedAt < now - MAX_OBSERVATION_MARKER_AGE_MS || capturedAt > now + MAX_OBSERVATION_MARKER_FUTURE_SKEW_MS) {
@@ -28992,14 +29113,14 @@ function readCommit() {
28992
29113
  }
28993
29114
  function resolveCliVersion() {
28994
29115
  try {
28995
- const pkg = JSON.parse(readFileSync18(join20(here, "..", "..", "package.json"), "utf-8"));
29116
+ const pkg = JSON.parse(readFileSync19(join22(here, "..", "..", "package.json"), "utf-8"));
28996
29117
  return pkg.version ?? "unknown";
28997
29118
  } catch {
28998
29119
  return "unknown";
28999
29120
  }
29000
29121
  }
29001
29122
  function spawnBackgroundFlush() {
29002
- const entry = join20(here, "..", "index.js");
29123
+ const entry = join22(here, "..", "index.js");
29003
29124
  spawn2(process.execPath, [entry, "moves", "flush"], {
29004
29125
  detached: true,
29005
29126
  stdio: "ignore",