@primitive.ai/prim 0.1.0-alpha.127 → 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 (44) hide show
  1. package/README.md +76 -5
  2. package/dist/{chunk-HZI5PBN4.js → chunk-BVGASV3B.js} +2047 -138
  3. package/dist/{chunk-72NIZMZN.js → chunk-DYXCJ6WZ.js} +15 -10
  4. package/dist/{chunk-TNWI3JWK.js → chunk-FHDTJP2C.js} +4 -2
  5. package/dist/{chunk-C4QNBSWB.js → chunk-HDL3UXYJ.js} +8 -8
  6. package/dist/{chunk-RV3JFSMX.js → chunk-IJ3W2YBM.js} +4 -4
  7. package/dist/{chunk-O65UVJZH.js → chunk-IZAEAALI.js} +2 -2
  8. package/dist/{chunk-H74RDXKP.js → chunk-KZNOT2YH.js} +2 -2
  9. package/dist/{chunk-R4EYLEIK.js → chunk-L7U3G4XR.js} +2 -2
  10. package/dist/{chunk-MGKSZSTV.js → chunk-LBZJD2I4.js} +3 -5
  11. package/dist/{chunk-UUQT5GMO.js → chunk-MMMY57UA.js} +22 -837
  12. package/dist/{chunk-H6X52UVF.js → chunk-NWWTFQP2.js} +1 -1
  13. package/dist/{chunk-WGTUNUIS.js → chunk-QSDWWEHF.js} +5 -5
  14. package/dist/{chunk-NVDPKW7Z.js → chunk-RAEOSDQ6.js} +3 -51
  15. package/dist/{chunk-KFRGVHGB.js → chunk-RS5ADTDF.js} +6 -6
  16. package/dist/{chunk-A5VTE43F.js → chunk-RWJ7WHTJ.js} +2 -2
  17. package/dist/{chunk-VVFVENU4.js → chunk-SJE7OWVS.js} +6 -6
  18. package/dist/{chunk-L6IL4N6Y.js → chunk-USJ4JGDC.js} +34 -34
  19. package/dist/{chunk-JCKOW45X.js → chunk-YPHDV5AS.js} +2 -2
  20. package/dist/{chunk-F3FDVHR7.js → chunk-YSV43WLK.js} +1 -1
  21. package/dist/{chunk-URYZDQFH.js → chunk-ZKIBD5MO.js} +3 -5
  22. package/dist/daemon/server.js +1769 -487
  23. package/dist/hook-runtime/daemon/server.js +1769 -487
  24. package/dist/hook-runtime/hooks/post-commit.js +611 -337
  25. package/dist/hook-runtime/hooks/post-rewrite.js +606 -332
  26. package/dist/hook-runtime/hooks/post-tool-use.js +1841 -683
  27. package/dist/hook-runtime/hooks/pre-commit.js +1713 -434
  28. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +1308 -150
  29. package/dist/hook-runtime/hooks/prim-hook.js +1863 -705
  30. package/dist/hook-runtime/hooks/session-end.js +538 -385
  31. package/dist/hook-runtime/hooks/session-start.js +1379 -233
  32. package/dist/hook-runtime/index.js +5438 -4052
  33. package/dist/hook-runtime/statusline-main.js +547 -273
  34. package/dist/hooks/post-commit.js +7 -7
  35. package/dist/hooks/post-rewrite.js +6 -6
  36. package/dist/hooks/post-tool-use.js +18 -18
  37. package/dist/hooks/pre-commit.js +4 -4
  38. package/dist/hooks/pre-tool-use-worker.js +9 -9
  39. package/dist/hooks/prim-hook.js +16 -16
  40. package/dist/hooks/session-end.js +4 -4
  41. package/dist/hooks/session-start.js +64 -22
  42. package/dist/index.js +396 -52
  43. package/dist/statusline-main.js +547 -273
  44. package/package.json +1 -1
@@ -55,42 +55,42 @@ var require_ucs2length = __commonJS({
55
55
  // src/hooks/post-rewrite.ts
56
56
  import { execFileSync as execFileSync6, spawn as spawn2 } from "child_process";
57
57
  import {
58
- constants as constants3,
58
+ constants as constants4,
59
59
  closeSync as closeSync4,
60
60
  fstatSync as fstatSync2,
61
- lstatSync as lstatSync7,
61
+ lstatSync as lstatSync8,
62
62
  openSync as openSync4,
63
- readFileSync as readFileSync17,
63
+ readFileSync as readFileSync18,
64
64
  unlinkSync as unlinkSync2
65
65
  } from "fs";
66
- import { basename as basename4, dirname as dirname11, isAbsolute as isAbsolute5, join as join18 } from "path";
67
- import { fileURLToPath as fileURLToPath4 } from "url";
66
+ import { basename as basename4, dirname as dirname13, isAbsolute as isAbsolute6, join as join21 } from "path";
67
+ import { fileURLToPath as fileURLToPath5 } from "url";
68
68
 
69
69
  // src/binding.ts
70
- import { existsSync as existsSync4, readFileSync as readFileSync7 } from "fs";
71
- import { dirname as dirname5, join as join8 } from "path";
70
+ import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
71
+ import { dirname as dirname8, join as join12 } from "path";
72
72
 
73
73
  // src/lib/credentials.ts
74
- import { createHash as createHash4 } from "crypto";
75
- import { readFileSync as readFileSync6 } from "fs";
76
- import { join as join7 } from "path";
74
+ import { createHash as createHash7 } from "crypto";
75
+ import { readFileSync as readFileSync8 } from "fs";
76
+ import { join as join11 } from "path";
77
77
 
78
78
  // src/lib/machine-credentials.ts
79
- import { execFileSync } from "child_process";
80
- import { createHash as createHash3, randomBytes as randomBytes3, randomUUID as randomUUID2 } from "crypto";
79
+ import { execFileSync as execFileSync2 } from "child_process";
80
+ import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as randomUUID2 } from "crypto";
81
81
  import {
82
- chmodSync,
83
- existsSync as existsSync3,
82
+ chmodSync as chmodSync2,
83
+ existsSync as existsSync5,
84
84
  linkSync,
85
- lstatSync as lstatSync3,
86
- mkdirSync as mkdirSync3,
87
- readFileSync as readFileSync5,
88
- rmSync as rmSync5,
89
- writeFileSync as writeFileSync3
85
+ lstatSync as lstatSync5,
86
+ mkdirSync as mkdirSync4,
87
+ readFileSync as readFileSync7,
88
+ rmSync as rmSync7,
89
+ writeFileSync as writeFileSync4
90
90
  } from "fs";
91
- import { createRequire } from "module";
92
- import { dirname as dirname4, join as join6 } from "path";
93
- import { fileURLToPath as fileURLToPath3 } from "url";
91
+ import { createRequire as createRequire2 } from "module";
92
+ import { dirname as dirname7, join as join10 } from "path";
93
+ import { fileURLToPath as fileURLToPath4 } from "url";
94
94
 
95
95
  // src/lib/atomic-file.ts
96
96
  import { randomUUID } from "crypto";
@@ -113,13 +113,27 @@ import { existsSync, mkdirSync as mkdirSync2, readFileSync, rmSync as rmSync2, s
113
113
  import { dirname as dirname2, join } from "path";
114
114
  var syncSleeper = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
115
115
 
116
- // src/lib/machine-broker.ts
117
- import { spawn } from "child_process";
118
- import { createHash, createHmac, randomBytes as randomBytes2, timingSafeEqual } from "crypto";
119
- import { lstatSync, readFileSync as readFileSync3, rmSync as rmSync3 } from "fs";
120
- import { createServer } from "http";
121
- import { basename, join as join4 } from "path";
122
- import { fileURLToPath as fileURLToPath2 } from "url";
116
+ // src/lib/hook-runtime.ts
117
+ import { createHash, randomBytes as randomBytes2 } from "crypto";
118
+ import {
119
+ constants as constants2,
120
+ accessSync,
121
+ chmodSync,
122
+ copyFileSync,
123
+ existsSync as existsSync4,
124
+ lstatSync,
125
+ mkdirSync as mkdirSync3,
126
+ mkdtempSync,
127
+ readFileSync as readFileSync3,
128
+ readdirSync,
129
+ realpathSync,
130
+ renameSync as renameSync2,
131
+ rmSync as rmSync3,
132
+ statSync as statSync2,
133
+ utimesSync,
134
+ writeFileSync as writeFileSync3
135
+ } from "fs";
136
+ import { delimiter, dirname as dirname5, isAbsolute as isAbsolute3, join as join5, resolve } from "path";
123
137
 
124
138
  // src/lib/bin-path.ts
125
139
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
@@ -127,6 +141,7 @@ import { dirname as dirname3, isAbsolute, join as join2 } from "path";
127
141
  import { fileURLToPath } from "url";
128
142
  var PKG_NAME = "@primitive.ai/prim";
129
143
  var ROOT_WALK_LIMIT = 6;
144
+ var STABLE_HOOK_LAUNCHER_NAME = "prim-hook-launcher-v1";
130
145
  var resolvedRoot;
131
146
  function locateRoot() {
132
147
  if (resolvedRoot !== void 0) {
@@ -165,6 +180,140 @@ var PRIM_CONFIG_SHELL_RESOLVER = [
165
180
  "fi; fi; "
166
181
  ].join("");
167
182
 
183
+ // src/lib/git-hook-contract.ts
184
+ var GIT_HOOK_ENTRYPOINT_CONTENT = `#!/bin/sh
185
+ # prim git hook entrypoint v1 \u2014 managed by prim; do not edit.
186
+ # Run by the "# >>> prim <hook> hook >>>" block in a Git hook file. Acts only
187
+ # where prim is active (git config prim.active true) and never fails the hook.
188
+ case "$0" in */*) prim_dir=\${0%/*} ;; *) exit 0 ;; esac
189
+ prim_launcher="$prim_dir/${STABLE_HOOK_LAUNCHER_NAME}"
190
+ [ -x "$prim_launcher" ] || exit 0
191
+ [ "$(git config --get prim.active 2>/dev/null)" = "true" ] || exit 0
192
+ prim_hook=\${1-}
193
+ if [ "$#" -gt 0 ]; then shift; fi
194
+ case "$prim_hook" in
195
+ pre-commit)
196
+ "$prim_launcher" prim-pre-commit "$@" || :
197
+ ;;
198
+ post-commit)
199
+ prim_sha=$(git rev-parse --verify HEAD 2>/dev/null) || exit 0
200
+ case "$prim_sha" in *[!0-9a-f]* | "") exit 0 ;; esac
201
+ case "\${#prim_sha}" in 40 | 64) ;; *) exit 0 ;; esac
202
+ prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
203
+ prim_observed=$(mktemp "\${TMPDIR:-/tmp}/prim-post-commit-observed.XXXXXXXX" 2>/dev/null) || prim_observed=
204
+ (
205
+ trap '' HUP
206
+ trap 'if [ -n "$prim_observed" ]; then rm -f "$prim_observed"; fi' 0
207
+ PRIM_COMMIT_SHA=$prim_sha PRIM_COMMIT_BRANCH=$prim_branch PRIM_COMMIT_OBSERVED_FILE=$prim_observed "$prim_launcher" prim-post-commit
208
+ ) </dev/null >/dev/null 2>&1 &
209
+ ;;
210
+ post-rewrite)
211
+ case "\${1-}" in amend | rebase) prim_source=$1 ;; *) exit 0 ;; esac
212
+ prim_pairs=$(mktemp "\${TMPDIR:-/tmp}/prim-post-rewrite-pairs.XXXXXXXX" 2>/dev/null) || exit 0
213
+ if ! chmod 600 "$prim_pairs" 2>/dev/null || ! cat >"$prim_pairs"; then
214
+ rm -f "$prim_pairs"
215
+ exit 0
216
+ fi
217
+ prim_branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || prim_branch=
218
+ (
219
+ trap '' HUP
220
+ trap 'rm -f "$prim_pairs"' 0
221
+ PRIM_REWRITE_SOURCE=$prim_source PRIM_REWRITE_BRANCH=$prim_branch PRIM_REWRITE_PAIRS_FILE=$prim_pairs "$prim_launcher" prim-post-rewrite
222
+ ) </dev/null >/dev/null 2>&1 &
223
+ ;;
224
+ esac
225
+ exit 0
226
+ `;
227
+
228
+ // src/lib/native-keyring.ts
229
+ import { existsSync as existsSync3 } from "fs";
230
+ import { createRequire } from "module";
231
+ import { dirname as dirname4, join as join3 } from "path";
232
+ import { fileURLToPath as fileURLToPath2 } from "url";
233
+ var require2 = createRequire(import.meta.url);
234
+
235
+ // src/lib/paths.ts
236
+ import { homedir } from "os";
237
+ import { isAbsolute as isAbsolute2, join as join4, normalize } from "path";
238
+ var UNSAFE_CONFIG_PATH_CHARACTERS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
239
+ function absolutePath(value, variable) {
240
+ if (value !== void 0 && UNSAFE_CONFIG_PATH_CHARACTERS.test(value)) {
241
+ throw new Error(`${variable} contains unsafe characters`);
242
+ }
243
+ if (!value || value.trim() !== value || !isAbsolute2(value)) return;
244
+ const normalized = normalize(value);
245
+ return normalized === value ? value : void 0;
246
+ }
247
+ function resolvePrimConfigDirectory(options = {}) {
248
+ const env = options.env ?? process.env;
249
+ const explicit = absolutePath(env.PRIM_CONFIG_DIR, "PRIM_CONFIG_DIR");
250
+ if (explicit) return { path: explicit, source: "explicit" };
251
+ const xdgConfigHome = absolutePath(env.XDG_CONFIG_HOME, "XDG_CONFIG_HOME");
252
+ if (xdgConfigHome) return { path: join4(xdgConfigHome, "prim"), source: "xdg" };
253
+ const home = absolutePath(options.homeDir ?? homedir(), "HOME");
254
+ if (!home) {
255
+ throw new Error("cannot resolve Primitive config directory: HOME is not an absolute path");
256
+ }
257
+ return { path: join4(home, ".config", "prim"), source: "default" };
258
+ }
259
+ function primConfigDirectory(options = {}) {
260
+ return resolvePrimConfigDirectory(options).path;
261
+ }
262
+
263
+ // src/lib/hook-runtime.ts
264
+ var RELEASE_PREFIX = "release-";
265
+ var MAX_MANIFEST_BYTES = 64 * 1024;
266
+ var RELEASE_GRACE_MS = 10 * 60 * 1e3;
267
+ var HOOK_RUNTIME_ENTRIES = {
268
+ // SessionStart self-healing resolves this exact CLI entry to run
269
+ // `daemon ensure`; it must travel with the immutable hook release.
270
+ prim: "dist/index.js",
271
+ "prim-hook": "dist/hooks/prim-hook.js",
272
+ "prim-pre-commit": "dist/hooks/pre-commit.js",
273
+ "prim-post-commit": "dist/hooks/post-commit.js",
274
+ "prim-post-rewrite": "dist/hooks/post-rewrite.js",
275
+ "prim-pre-tool-use-worker": "dist/hooks/pre-tool-use-worker.js",
276
+ "prim-pre-tool-use": "dist/hooks/pre-tool-use.js",
277
+ "prim-post-tool-use": "dist/hooks/post-tool-use.js",
278
+ "prim-session-start": "dist/hooks/session-start.js",
279
+ "prim-session-end": "dist/hooks/session-end.js",
280
+ "prim-daemon-server": "dist/daemon/server.js",
281
+ "prim-statusline": "dist/statusline-main.js"
282
+ };
283
+ var SOURCE_ENTRIES = Object.fromEntries(
284
+ Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, target]) => [
285
+ bin,
286
+ target.replace(/^dist\//u, "")
287
+ ])
288
+ );
289
+ var STABLE_HOOK_LAUNCHER_CONTENT = `#!/bin/sh
290
+ set -eu
291
+ case "$0" in */*) prim_launcher_dir=\${0%/*} ;; *) exit 78 ;; esac
292
+ IFS= read -r prim_release_name < "$prim_launcher_dir/hook-runtime/current" || exit 69
293
+ case "$prim_release_name" in ${RELEASE_PREFIX}*) ;; *) exit 69 ;; esac
294
+ prim_release_id=\${prim_release_name#${RELEASE_PREFIX}}
295
+ case "$prim_release_id" in *[!0-9a-f]*|"") exit 69 ;; esac
296
+ [ "\${#prim_release_id}" -eq 64 ] || exit 69
297
+ prim_release="$prim_launcher_dir/hook-runtime/releases/$prim_release_name"
298
+ case "\${1-}" in
299
+ ${Object.entries(HOOK_RUNTIME_ENTRIES).map(([bin, entry]) => ` ${bin}) prim_entry="$prim_release/${entry}" ;;`).join("\n")}
300
+ *) exit 64 ;;
301
+ esac
302
+ shift
303
+ IFS= read -r prim_node < "$prim_release/node" || exit 69
304
+ case "$prim_node" in /*) ;; *) exit 69 ;; esac
305
+ [ -x "$prim_node" ] && [ -f "$prim_entry" ] || exit 69
306
+ exec "$prim_node" "$prim_entry" "$@"
307
+ `;
308
+
309
+ // src/lib/machine-broker.ts
310
+ import { spawn } from "child_process";
311
+ import { createHash as createHash2, createHmac, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
312
+ import { lstatSync as lstatSync2, readFileSync as readFileSync4, rmSync as rmSync4 } from "fs";
313
+ import { createServer } from "http";
314
+ import { basename, join as join6 } from "path";
315
+ import { fileURLToPath as fileURLToPath3 } from "url";
316
+
168
317
  // src/lib/loopback-fetch.ts
169
318
  import { request } from "http";
170
319
  import { Readable } from "stream";
@@ -173,6 +322,8 @@ import { Readable } from "stream";
173
322
  function isClaudeCloudSession(env = process.env) {
174
323
  return env.CLAUDE_CODE_REMOTE === "true";
175
324
  }
325
+ var CLOUD_REJECTED_CREDENTIALS_REMEDY = 'correct the credentials in the cloud environment\'s settings, or if the installation was revoked mint a replacement on your own machine with `prim auth enroll --new-installation "Claude Code cloud" --print-env`; then start a new cloud session';
326
+ var CLOUD_REJECTED_CREDENTIALS_NOTICE = `Primitive is not connected in this Claude Code cloud session: its credentials were rejected. To fix it, ${CLOUD_REJECTED_CREDENTIALS_REMEDY}.`;
176
327
 
177
328
  // src/lib/workos-connect.ts
178
329
  var DISCOVERY_MAX_BYTES = 16 * 1024;
@@ -319,34 +470,6 @@ function parseMachineIdentity(value, clientId) {
319
470
  };
320
471
  }
321
472
 
322
- // src/lib/paths.ts
323
- import { homedir } from "os";
324
- import { isAbsolute as isAbsolute2, join as join3, normalize } from "path";
325
- var UNSAFE_CONFIG_PATH_CHARACTERS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
326
- function absolutePath(value, variable) {
327
- if (value !== void 0 && UNSAFE_CONFIG_PATH_CHARACTERS.test(value)) {
328
- throw new Error(`${variable} contains unsafe characters`);
329
- }
330
- if (!value || value.trim() !== value || !isAbsolute2(value)) return;
331
- const normalized = normalize(value);
332
- return normalized === value ? value : void 0;
333
- }
334
- function resolvePrimConfigDirectory(options = {}) {
335
- const env = options.env ?? process.env;
336
- const explicit = absolutePath(env.PRIM_CONFIG_DIR, "PRIM_CONFIG_DIR");
337
- if (explicit) return { path: explicit, source: "explicit" };
338
- const xdgConfigHome = absolutePath(env.XDG_CONFIG_HOME, "XDG_CONFIG_HOME");
339
- if (xdgConfigHome) return { path: join3(xdgConfigHome, "prim"), source: "xdg" };
340
- const home = absolutePath(options.homeDir ?? homedir(), "HOME");
341
- if (!home) {
342
- throw new Error("cannot resolve Primitive config directory: HOME is not an absolute path");
343
- }
344
- return { path: join3(home, ".config", "prim"), source: "default" };
345
- }
346
- function primConfigDirectory(options = {}) {
347
- return resolvePrimConfigDirectory(options).path;
348
- }
349
-
350
473
  // src/lib/machine-broker.ts
351
474
  var MAX_RESPONSE_BYTES = 96 * 1024;
352
475
  var MAX_FORWARD_REQUEST_BYTES = 12 * 1024 * 1024;
@@ -355,29 +478,325 @@ var MAX_FORWARD_RESPONSE_BYTES = 36 * 1024 * 1024;
355
478
  var IDLE_MS = 5 * 6e4;
356
479
 
357
480
  // src/lib/machine-retry.ts
358
- import { createHash as createHash2 } from "crypto";
359
- import { lstatSync as lstatSync2, readFileSync as readFileSync4, readdirSync, rmSync as rmSync4 } from "fs";
360
- import { join as join5 } from "path";
481
+ import { createHash as createHash3 } from "crypto";
482
+ import { lstatSync as lstatSync3, readFileSync as readFileSync5, readdirSync as readdirSync2, rmSync as rmSync5 } from "fs";
483
+ import { join as join7 } from "path";
361
484
  var MAX_SERVER_WAIT_MS = 15 * 6e4;
362
485
 
363
- // src/lib/machine-credentials.ts
364
- var require2 = createRequire(import.meta.url);
486
+ // src/lib/session-identity.ts
487
+ import { execFile } from "child_process";
488
+ import { createHash as createHash5 } from "crypto";
489
+ import { rmSync as rmSync6 } from "fs";
490
+ import { join as join9 } from "path";
491
+ import { promisify } from "util";
492
+
493
+ // src/lib/git.ts
494
+ import { execFileSync } from "child_process";
495
+ import { createHash as createHash4 } from "crypto";
496
+ import { lstatSync as lstatSync4, readFileSync as readFileSync6, realpathSync as realpathSync2 } from "fs";
497
+ import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute4, join as join8, relative, resolve as resolve2, sep } from "path";
498
+ var GIT_TIMEOUT_MS = 1e3;
499
+ var MAX_SETTINGS_BYTES = 1024 * 1024;
500
+ var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
501
+ var GITHUB_REPOSITORY_PATTERN = /^(?!\.{1,2}$)[A-Za-z0-9._-]{1,100}$/u;
502
+ var CREDENTIAL_VARIABLE = /^(?:PRIM_TOKEN|PRIM_M2M_\w+)$/u;
503
+ function gitChildEnvironment(env = process.env) {
504
+ return Object.fromEntries(
505
+ Object.entries(env).filter(([name]) => !CREDENTIAL_VARIABLE.test(name))
506
+ );
507
+ }
508
+ function gitToplevel(cwd) {
509
+ try {
510
+ return execFileSync("git", ["rev-parse", "--show-toplevel"], {
511
+ cwd,
512
+ encoding: "utf-8",
513
+ stdio: ["ignore", "pipe", "ignore"],
514
+ timeout: GIT_TIMEOUT_MS,
515
+ env: gitChildEnvironment()
516
+ }).trim();
517
+ } catch {
518
+ return null;
519
+ }
520
+ }
521
+ function gitValue(cwd, args) {
522
+ try {
523
+ const value = execFileSync("git", args, {
524
+ cwd,
525
+ encoding: "utf-8",
526
+ stdio: ["ignore", "pipe", "ignore"],
527
+ timeout: GIT_TIMEOUT_MS,
528
+ env: gitChildEnvironment()
529
+ }).trim();
530
+ return value || void 0;
531
+ } catch {
532
+ return void 0;
533
+ }
534
+ }
535
+ function parseGithubRepositoryName(path) {
536
+ const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
537
+ if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
538
+ return null;
539
+ }
540
+ return `${parts[0]}/${parts[1]}`;
541
+ }
542
+ function githubRepositoryFromRemote(remote) {
543
+ if ([...remote].some((char) => char < " " || char === "\x7F")) return null;
544
+ const match = /^(?:git@github\.com:([^?#]+)|(?:https|ssh):\/\/(?:[^/@]+@)?github\.com(?::\d+)?\/([^?#]+))$/i.exec(
545
+ remote
546
+ );
547
+ const path = match?.[1] ?? match?.[2];
548
+ return path ? parseGithubRepositoryName(path) : null;
549
+ }
550
+ function checkoutSettingsText(repoRoot) {
551
+ const path = join8(repoRoot, ".claude", "settings.json");
552
+ try {
553
+ if (!lstatSync4(join8(repoRoot, ".claude")).isDirectory()) return null;
554
+ const stat = lstatSync4(path);
555
+ if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
556
+ return readFileSync6(path, "utf8");
557
+ } catch {
558
+ return null;
559
+ }
560
+ }
561
+ function checkoutDeclaration(repoRoot, name) {
562
+ const text = checkoutSettingsText(repoRoot);
563
+ if (text === null) return null;
564
+ let parsed;
565
+ try {
566
+ parsed = JSON.parse(text);
567
+ } catch {
568
+ return null;
569
+ }
570
+ const env = typeof parsed === "object" && parsed !== null ? parsed.env : void 0;
571
+ const value = typeof env === "object" && env !== null ? env[name] : void 0;
572
+ return typeof value === "string" ? value : null;
573
+ }
574
+ function declaredGithubRepository(repoRoot) {
575
+ const value = checkoutDeclaration(repoRoot, "PRIM_REPOSITORY");
576
+ return value === null ? null : parseGithubRepositoryName(value.trim());
577
+ }
578
+ function githubRepositoryFullName(cwd) {
579
+ const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
580
+ if (remote) {
581
+ const fromOrigin = githubRepositoryFromRemote(remote);
582
+ if (fromOrigin || normalizeOriginRemote(remote)) return fromOrigin;
583
+ }
584
+ const root = gitToplevel(cwd);
585
+ return root ? declaredGithubRepository(root) : null;
586
+ }
587
+ function normalizeOriginRemote(remote) {
588
+ const value = remote.trim();
589
+ if (!value) return void 0;
590
+ const scp = !value.includes("://") ? /^(?:[^@/\s]+@)?(?<host>[^:/\s]+):(?<path>.+)$/.exec(value)?.groups : void 0;
591
+ if (scp?.host && scp.path) {
592
+ const path = scp.path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
593
+ return path ? `${scp.host.toLowerCase()}/${path}` : void 0;
594
+ }
595
+ try {
596
+ const url = new URL(value);
597
+ url.username = "";
598
+ url.password = "";
599
+ url.search = "";
600
+ url.hash = "";
601
+ const path = url.pathname.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
602
+ if (url.host && path) return `${url.host.toLowerCase()}/${path}`;
603
+ return void 0;
604
+ } catch {
605
+ return void 0;
606
+ }
607
+ }
608
+ function opaqueRepoKey(source, value) {
609
+ return `repo_v1_${createHash4("sha256").update(`${source}\0${value}`).digest("hex")}`;
610
+ }
611
+ function resolveRepositoryContext(cwd = process.cwd()) {
612
+ const top = gitToplevel(cwd);
613
+ if (!top) return null;
614
+ let repoRoot;
615
+ try {
616
+ repoRoot = realpathSync2.native(top);
617
+ } catch {
618
+ repoRoot = resolve2(top);
619
+ }
620
+ const origin = gitValue(repoRoot, ["config", "--get", "remote.origin.url"]);
621
+ const repoFullName = githubRepositoryFullName(repoRoot) ?? void 0;
622
+ const normalizedOrigin = origin ? normalizeOriginRemote(origin) : void 0;
623
+ if (normalizedOrigin) {
624
+ return {
625
+ repoRoot,
626
+ repoKey: opaqueRepoKey("origin", normalizedOrigin),
627
+ identitySource: "origin",
628
+ repoFullName
629
+ };
630
+ }
631
+ if (repoFullName) {
632
+ return {
633
+ repoRoot,
634
+ repoKey: opaqueRepoKey("origin", `github.com/${repoFullName}`),
635
+ identitySource: "declared",
636
+ repoFullName
637
+ };
638
+ }
639
+ const roots = gitValue(repoRoot, ["rev-list", "--max-parents=0", "HEAD"])?.split(/\s+/).filter(Boolean).sort();
640
+ if (roots && roots.length > 0) {
641
+ return {
642
+ repoRoot,
643
+ repoKey: opaqueRepoKey("root_commit", roots.join("\n")),
644
+ identitySource: "root_commit",
645
+ repoFullName
646
+ };
647
+ }
648
+ return { repoRoot, repoFullName };
649
+ }
650
+
651
+ // src/lib/session-identity.ts
652
+ var SESSION_IDENTITY_VARIABLE = "PRIM_CLOUD_IDENTITY";
653
+ var SESSION_IDENTITY_VALUE = "session";
654
+ var SESSION_ID_VARIABLE = "CLAUDE_CODE_REMOTE_SESSION_ID";
655
+ var SESSION_TOKEN_PREFIX = "prim_sess_";
656
+ var SESSION_ID = /^[A-Za-z0-9._:-]{1,200}$/u;
365
657
  var DEFAULT_API_URL = "https://api.getprimitive.ai";
658
+ var RENEW_BEFORE_MS = 6e4;
659
+ var BACKGROUND_RETRY_MS = 5 * 6e4;
660
+ var RESPONSE_MAX_BYTES = 64 * 1024;
661
+ function sessionIdentityRequested(env = process.env) {
662
+ return isClaudeCloudSession(env) && env[SESSION_IDENTITY_VARIABLE]?.trim() === SESSION_IDENTITY_VALUE;
663
+ }
664
+ function sessionIdentityMode(deps = {}) {
665
+ const env = deps.env ?? process.env;
666
+ return sessionIdentityRequested(env) && (env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || env.PRIM_M2M_CLIENT_AUTH !== void 0);
667
+ }
668
+ function failure(code, cause, remedy) {
669
+ return { status: "failed", code, cause, remedy };
670
+ }
671
+ var NEW_SESSION_REMEDY = "start a new cloud session";
672
+ var SESSION_REVOKED = failure(
673
+ "session_revoked",
674
+ "Primitive no longer accepts this session's member token: an organization admin revoked the session or the member's GitHub link, the member left the organization, or the token was renewed elsewhere",
675
+ `${NEW_SESSION_REMEDY}, which identifies you again through GitHub (if your GitHub link was removed, run \`prim auth link\` there when it asks)`
676
+ );
677
+ var CHALLENGE_WINDOW_PASSED = failure(
678
+ "challenge_expired",
679
+ "this session's identity check expired before it was exchanged for a token (a verified check stays usable, including for linking a GitHub account, for 30 minutes)",
680
+ `${NEW_SESSION_REMEDY}, and if it asks you to link your GitHub account, run \`prim auth link\` there right away`
681
+ );
682
+ var CHALLENGE_GONE = failure(
683
+ "challenge_not_found",
684
+ "Primitive no longer knows this session's identity check (the environment credential may have been replaced since)",
685
+ NEW_SESSION_REMEDY
686
+ );
687
+ function hash(value) {
688
+ return createHash5("sha256").update(value).digest("hex");
689
+ }
690
+ function sessionContext(deps) {
691
+ const env = deps.env ?? process.env;
692
+ const environment = environmentCredentials(deps);
693
+ if (!environment)
694
+ return failure(
695
+ "environment_credential_missing",
696
+ "the cloud environment has no environment credential",
697
+ 'ask an organization admin to create one with `prim auth enroll --new-environment "<name>" --print-env` and add it to the environment, then start a new cloud session'
698
+ );
699
+ const sessionId = env[SESSION_ID_VARIABLE]?.trim();
700
+ if (!sessionId || !SESSION_ID.test(sessionId))
701
+ return failure(
702
+ "session_id_missing",
703
+ `this Claude Code cloud session does not report a session ID Primitive accepts (${SESSION_ID_VARIABLE})`,
704
+ NEW_SESSION_REMEDY
705
+ );
706
+ const apiUrl = machineApiUrl(env.PRIM_API_URL?.trim() || DEFAULT_API_URL);
707
+ const directory = deps.directory ?? primConfigDirectory({ env });
708
+ const key = hash(`${apiUrl}\0${environment.clientId}\0${sessionId}`);
709
+ return {
710
+ directory,
711
+ apiUrl,
712
+ clientId: environment.clientId,
713
+ generation: environment.generation,
714
+ sessionId,
715
+ tokenPath: join9(directory, `session_identity_${key}.json`),
716
+ statePath: join9(directory, `session_identity_${key}.state.json`),
717
+ lockPath: join9(directory, "session-identity.lock")
718
+ };
719
+ }
720
+ function readRecord(path) {
721
+ try {
722
+ const value = readMachineMetadata(path);
723
+ return value === void 0 ? void 0 : machineRecord(value);
724
+ } catch {
725
+ return void 0;
726
+ }
727
+ }
728
+ function finiteNumber(value) {
729
+ return typeof value === "number" && Number.isFinite(value);
730
+ }
731
+ function readToken(context) {
732
+ const data = readRecord(context.tokenPath);
733
+ if (!data || data.version !== 1 || data.apiUrl !== context.apiUrl || data.clientId !== context.clientId || data.generation !== context.generation || data.sessionId !== context.sessionId || !machineString(data.accessToken, 8192) || !data.accessToken.startsWith(SESSION_TOKEN_PREFIX) || !finiteNumber(data.expiresAt) || !finiteNumber(data.refreshAfter) || !machineString(data.userId, 256) || !machineString(data.displayName, 256) || !machineString(data.organizationId, 256) || !machineString(data.issuer, 2048) || !machineString(data.audience, 256))
734
+ return void 0;
735
+ const identity = data.identity;
736
+ if (!identity || identity.clientId !== context.clientId || identity.authorizedUserId !== data.userId || identity.organizationId !== data.organizationId)
737
+ return void 0;
738
+ return data;
739
+ }
740
+ function tokenValid(record, now = Date.now()) {
741
+ return now < record.expiresAt - RENEW_BEFORE_MS;
742
+ }
743
+ function toCredential(record) {
744
+ return {
745
+ issuer: record.issuer,
746
+ audience: record.audience,
747
+ ...record.identity,
748
+ accessToken: record.accessToken,
749
+ expiresAt: record.expiresAt,
750
+ apiUrl: record.apiUrl,
751
+ generation: record.generation,
752
+ storage: "environment",
753
+ session: {
754
+ userId: record.userId,
755
+ displayName: record.displayName,
756
+ ...record.githubLogin ? { githubLogin: record.githubLogin } : {},
757
+ refreshAfter: record.refreshAfter
758
+ }
759
+ };
760
+ }
761
+ function cachedSessionCredential(deps = {}) {
762
+ if (!sessionIdentityMode(deps)) return void 0;
763
+ let context;
764
+ try {
765
+ context = sessionContext(deps);
766
+ } catch {
767
+ return void 0;
768
+ }
769
+ if ("status" in context) return void 0;
770
+ const record = readToken(context);
771
+ return record && tokenValid(record) ? toCredential(record) : void 0;
772
+ }
773
+ var SERVER_CONTRACT_FAILURE = failure(
774
+ "server_contract",
775
+ "Primitive's answer did not identify the linked member",
776
+ "update prim (`npx --yes @primitive.ai/prim@latest`) and run `prim setup --cloud`; if it persists, report it to Primitive"
777
+ );
778
+
779
+ // src/lib/machine-credentials.ts
780
+ function sessionScoped(deps) {
781
+ return !deps.localEnvironment && !deps.environmentOnly && sessionIdentityMode(deps);
782
+ }
783
+ var require3 = createRequire2(import.meta.url);
784
+ var DEFAULT_API_URL2 = "https://api.getprimitive.ai";
366
785
  var PROFILE_FILE = "machine_profile.json";
367
786
  var cached;
368
787
  function configurationDirectory(deps) {
369
788
  return deps.directory ?? primConfigDirectory({ env: deps.env });
370
789
  }
371
790
  function apiUrlFor(deps) {
372
- return machineApiUrl((deps.env ?? process.env).PRIM_API_URL?.trim() || DEFAULT_API_URL);
791
+ return machineApiUrl((deps.env ?? process.env).PRIM_API_URL?.trim() || DEFAULT_API_URL2);
373
792
  }
374
- function hash(value) {
375
- return createHash3("sha256").update(value).digest("hex");
793
+ function hash2(value) {
794
+ return createHash6("sha256").update(value).digest("hex");
376
795
  }
377
796
  function environmentContextPath(deps, clientId) {
378
- return join6(
797
+ return join10(
379
798
  configurationDirectory(deps),
380
- `machine_context_${hash(`${apiUrlFor(deps)}\0${clientId}`)}.json`
799
+ `machine_context_${hash2(`${apiUrlFor(deps)}\0${clientId}`)}.json`
381
800
  );
382
801
  }
383
802
  function readEnvironmentContext(environment, deps) {
@@ -403,12 +822,12 @@ function readEnvironmentContext(environment, deps) {
403
822
  }
404
823
  function protectPath(path, directory) {
405
824
  if (process.platform !== "win32") {
406
- chmodSync(path, directory ? 448 : 384);
825
+ chmodSync2(path, directory ? 448 : 384);
407
826
  return;
408
827
  }
409
828
  const encodedPath = Buffer.from(path).toString("base64");
410
829
  const script = `$ErrorActionPreference = 'Stop'; $p = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${encodedPath}')); $sid = [Security.Principal.WindowsIdentity]::GetCurrent().User; $acl = [System.Security.AccessControl.${directory ? "DirectorySecurity" : "FileSecurity"}]::new(); $acl.SetOwner($sid); $acl.SetAccessRuleProtection($true, $false); $rule = [System.Security.AccessControl.FileSystemAccessRule]::new($sid, 'FullControl', '${directory ? "ContainerInherit, ObjectInherit" : "None"}', 'None', 'Allow'); $acl.AddAccessRule($rule); [System.IO.${directory ? "Directory" : "File"}]::SetAccessControl($p, $acl)`;
411
- execFileSync(
830
+ execFileSync2(
412
831
  "powershell.exe",
413
832
  [
414
833
  "-NoProfile",
@@ -420,25 +839,28 @@ function protectPath(path, directory) {
420
839
  );
421
840
  }
422
841
  function ensureDirectory(directory) {
423
- mkdirSync3(directory, { recursive: true, mode: 448 });
424
- if (lstatSync3(directory).isSymbolicLink())
842
+ mkdirSync4(directory, { recursive: true, mode: 448 });
843
+ if (lstatSync5(directory).isSymbolicLink())
425
844
  throw new MachineAuthError(
426
845
  "unsafe_storage",
427
846
  "Credential directory must not be a symbolic link."
428
847
  );
429
848
  protectPath(directory, true);
430
849
  }
850
+ function readMachineMetadata(path) {
851
+ return readPrivate(path);
852
+ }
431
853
  function readPrivate(path) {
432
854
  let raw;
433
855
  try {
434
- const stat = lstatSync3(path);
856
+ const stat = lstatSync5(path);
435
857
  if (!stat.isFile() || stat.size > 96 * 1024 || process.platform !== "win32" && ((stat.mode & 63) !== 0 || stat.uid !== process.getuid?.())) {
436
858
  throw new MachineAuthError(
437
859
  "unsafe_storage",
438
860
  "Machine credential files must be owner-only regular files."
439
861
  );
440
862
  }
441
- raw = readFileSync5(path, "utf8");
863
+ raw = readFileSync7(path, "utf8");
442
864
  } catch (error) {
443
865
  if (error.code === "ENOENT") return void 0;
444
866
  throw error;
@@ -483,7 +905,7 @@ function parseProfile(value) {
483
905
  };
484
906
  }
485
907
  function readMachineProfile(deps = {}) {
486
- const value = readPrivate(join6(configurationDirectory(deps), PROFILE_FILE));
908
+ const value = readPrivate(join10(configurationDirectory(deps), PROFILE_FILE));
487
909
  return value === void 0 ? void 0 : parseProfile(value);
488
910
  }
489
911
  var NETWORK_SECRET_AUTH = "network-secret";
@@ -492,20 +914,20 @@ var INJECTED_IDENTITY_TTL_MS = 60 * 6e4;
492
914
  var brokerKeys = /* @__PURE__ */ new Map();
493
915
  function networkSecretBrokerKey(deps, clientId) {
494
916
  const directory = configurationDirectory(deps);
495
- const path = join6(directory, `machine_network_${hash(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
917
+ const path = join10(directory, `machine_network_${hash2(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
496
918
  const known = brokerKeys.get(path);
497
919
  if (known) return known;
498
920
  ensureDirectory(directory);
499
921
  const read = () => {
500
922
  try {
501
- const stat = lstatSync3(path);
923
+ const stat = lstatSync5(path);
502
924
  if (!stat.isFile() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || typeof process.getuid === "function" && stat.uid !== process.getuid()))
503
925
  throw new MachineAuthError(
504
926
  "unsafe_storage",
505
927
  `The machine broker key at ${path} is not an owner-only file. Delete it and retry.`,
506
928
  true
507
929
  );
508
- const value = readFileSync5(path, "utf8").trim();
930
+ const value = readFileSync7(path, "utf8").trim();
509
931
  return { key: /^[a-f0-9]{64}$/u.test(value) ? value : void 0 };
510
932
  } catch (error) {
511
933
  if (error.code === "ENOENT") return void 0;
@@ -524,16 +946,16 @@ function networkSecretBrokerKey(deps, clientId) {
524
946
  `The machine broker key at ${path} is damaged. Delete it and retry.`,
525
947
  true
526
948
  );
527
- const staged = `${path}.${process.pid}.${randomBytes3(6).toString("hex")}`;
949
+ const staged = `${path}.${process.pid}.${randomBytes4(6).toString("hex")}`;
528
950
  try {
529
- writeFileSync3(staged, `${randomBytes3(32).toString("hex")}
951
+ writeFileSync4(staged, `${randomBytes4(32).toString("hex")}
530
952
  `, { mode: 384, flag: "wx" });
531
953
  protectPath(staged, false);
532
954
  linkSync(staged, path);
533
955
  } catch (error) {
534
956
  if (error.code !== "EEXIST") throw error;
535
957
  } finally {
536
- rmSync5(staged, { force: true });
958
+ rmSync7(staged, { force: true });
537
959
  }
538
960
  }
539
961
  const key = read()?.key;
@@ -566,7 +988,7 @@ function environmentCredentials(deps) {
566
988
  "conflicting_credentials",
567
989
  `Unset PRIM_M2M_CLIENT_SECRET: with PRIM_M2M_CLIENT_AUTH=${auth} the environment's network secret supplies it.`
568
990
  );
569
- const generation = hash(`${apiUrlFor(deps)}\0${clientId}\0${auth}\0broker-proxy`);
991
+ const generation = hash2(`${apiUrlFor(deps)}\0${clientId}\0${auth}\0broker-proxy`);
570
992
  const credentials = {
571
993
  clientId,
572
994
  generation,
@@ -587,12 +1009,12 @@ function environmentCredentials(deps) {
587
1009
  return {
588
1010
  clientId,
589
1011
  clientSecret,
590
- generation: hash(`${apiUrlFor(deps)}\0${clientId}\0${clientSecret}`)
1012
+ generation: hash2(`${apiUrlFor(deps)}\0${clientId}\0${clientSecret}`)
591
1013
  };
592
1014
  }
593
1015
  function hasMachineConfiguration(deps = {}) {
594
1016
  const env = deps.env ?? process.env;
595
- const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || env.PRIM_M2M_CLIENT_AUTH !== void 0 || existsSync3(join6(configurationDirectory(deps), PROFILE_FILE));
1017
+ 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));
596
1018
  if (configured && env.PRIM_TOKEN?.trim()) {
597
1019
  throw new MachineAuthError(
598
1020
  "conflicting_credentials",
@@ -604,6 +1026,7 @@ function hasMachineConfiguration(deps = {}) {
604
1026
  }
605
1027
  function machineContext(deps = {}) {
606
1028
  if (!hasMachineConfiguration(deps)) return void 0;
1029
+ if (sessionScoped(deps)) return cachedSessionCredential(deps);
607
1030
  const environment = environmentCredentials(deps);
608
1031
  if (environment) {
609
1032
  if (environmentTerminal === environment.generation) return void 0;
@@ -618,6 +1041,7 @@ function machineContext(deps = {}) {
618
1041
  return profile;
619
1042
  }
620
1043
  function cachedMachineCredential(deps = {}) {
1044
+ if (sessionScoped(deps)) return cachedSessionCredential(deps);
621
1045
  const context = machineContext(deps);
622
1046
  return context && cached?.generation === context.generation && cached.apiUrl === context.apiUrl ? cached : void 0;
623
1047
  }
@@ -639,31 +1063,31 @@ function machineCaptureActor(deps = {}) {
639
1063
  return injected ? { kind: "machine", apiUrl: apiUrlFor(deps), clientId: injected.clientId } : void 0;
640
1064
  }
641
1065
  function machineJournalBucket(identity) {
642
- return `_machine_${hash(`${identity.apiUrl}\0${identity.clientId}${identity.authorizedUserId ? `\0${identity.authorizedUserId}` : ""}`)}`;
1066
+ return `_machine_${hash2(`${identity.apiUrl}\0${identity.clientId}${identity.authorizedUserId ? `\0${identity.authorizedUserId}` : ""}`)}`;
643
1067
  }
644
1068
  function identityPending(actor) {
645
1069
  return actor.machineId === void 0 && actor.organizationId === void 0 && actor.authorizedUserId === void 0;
646
1070
  }
647
1071
  function machinePendingBucket(identity) {
648
- return `_machine_pending_${hash(`${identity.apiUrl}\0${identity.clientId}`)}`;
1072
+ return `_machine_pending_${hash2(`${identity.apiUrl}\0${identity.clientId}`)}`;
649
1073
  }
650
1074
 
651
1075
  // src/lib/credentials.ts
652
1076
  var CONFIG_DIRECTORY = primConfigDirectory();
653
- var TOKEN_FILE_PATH = join7(CONFIG_DIRECTORY, "token");
654
- var REFRESH_TOKEN_PATH = join7(CONFIG_DIRECTORY, "refresh_token");
655
- var TOKEN_EXPIRES_PATH = join7(CONFIG_DIRECTORY, "token_expires_at");
656
- var TERMINAL_REFRESH_PATH = join7(CONFIG_DIRECTORY, "refresh_terminal");
657
- var CREDENTIAL_METADATA_PATH = join7(CONFIG_DIRECTORY, "credential_metadata.json");
658
- var CREDENTIAL_FAMILY_PATH = join7(CONFIG_DIRECTORY, "credential_family.json");
659
- var CREDENTIAL_MIGRATION_PATH = join7(CONFIG_DIRECTORY, "credential_migration.json");
660
- var CREDENTIAL_LOCK_PATH = join7(CONFIG_DIRECTORY, "credentials.lock");
1077
+ var TOKEN_FILE_PATH = join11(CONFIG_DIRECTORY, "token");
1078
+ var REFRESH_TOKEN_PATH = join11(CONFIG_DIRECTORY, "refresh_token");
1079
+ var TOKEN_EXPIRES_PATH = join11(CONFIG_DIRECTORY, "token_expires_at");
1080
+ var TERMINAL_REFRESH_PATH = join11(CONFIG_DIRECTORY, "refresh_terminal");
1081
+ var CREDENTIAL_METADATA_PATH = join11(CONFIG_DIRECTORY, "credential_metadata.json");
1082
+ var CREDENTIAL_FAMILY_PATH = join11(CONFIG_DIRECTORY, "credential_family.json");
1083
+ var CREDENTIAL_MIGRATION_PATH = join11(CONFIG_DIRECTORY, "credential_migration.json");
1084
+ var CREDENTIAL_LOCK_PATH = join11(CONFIG_DIRECTORY, "credentials.lock");
661
1085
  var MAX_CREDENTIAL_METADATA_BYTES = 4096;
662
1086
  var CREDENTIAL_MIGRATION_VERSION = 1;
663
1087
  var CREDENTIAL_MIGRATION_STATE = "family_bound";
664
1088
  function readTrimmed(path) {
665
1089
  try {
666
- const value = readFileSync6(path, "utf8").trim();
1090
+ const value = readFileSync8(path, "utf8").trim();
667
1091
  return value || void 0;
668
1092
  } catch {
669
1093
  return void 0;
@@ -700,7 +1124,7 @@ function resolveAuthCredential(options = {}) {
700
1124
  return { token: stored, source: "token_file" };
701
1125
  }
702
1126
  function credentialFingerprint(value) {
703
- return createHash4("sha256").update(value).digest("hex");
1127
+ return createHash7("sha256").update(value).digest("hex");
704
1128
  }
705
1129
  function parseLegacyBrokerCredentialMetadata(value) {
706
1130
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
@@ -720,7 +1144,7 @@ function parseLegacyBrokerCredentialMetadata(value) {
720
1144
  function readBoundedCredentialJson(path) {
721
1145
  let raw;
722
1146
  try {
723
- raw = readFileSync6(path, "utf8");
1147
+ raw = readFileSync8(path, "utf8");
724
1148
  } catch (error) {
725
1149
  return error.code === "ENOENT" ? void 0 : null;
726
1150
  }
@@ -793,14 +1217,14 @@ function jwtOrganizationId(token) {
793
1217
 
794
1218
  // src/binding.ts
795
1219
  var PRIM_CONFIG_DIR = primConfigDirectory();
796
- var SESSIONS_DIR = join8(PRIM_CONFIG_DIR, "sessions");
1220
+ var SESSIONS_DIR = join12(PRIM_CONFIG_DIR, "sessions");
797
1221
  var WORKSPACE_FILE = ".prim/workspace.json";
798
1222
  function readJsonSafe(path) {
799
- if (!existsSync4(path)) {
1223
+ if (!existsSync6(path)) {
800
1224
  return;
801
1225
  }
802
1226
  try {
803
- return JSON.parse(readFileSync7(path, "utf-8"));
1227
+ return JSON.parse(readFileSync9(path, "utf-8"));
804
1228
  } catch {
805
1229
  return;
806
1230
  }
@@ -809,17 +1233,17 @@ function fromSessionMarker(sessionId) {
809
1233
  if (!sessionId) {
810
1234
  return;
811
1235
  }
812
- const marker = readJsonSafe(join8(SESSIONS_DIR, `${sessionId}.json`));
1236
+ const marker = readJsonSafe(join12(SESSIONS_DIR, `${sessionId}.json`));
813
1237
  return marker?.orgId;
814
1238
  }
815
1239
  function fromWorkspaceFile(startDir) {
816
1240
  let dir = startDir;
817
1241
  while (true) {
818
- const config = readJsonSafe(join8(dir, WORKSPACE_FILE));
1242
+ const config = readJsonSafe(join12(dir, WORKSPACE_FILE));
819
1243
  if (config?.orgId) {
820
1244
  return config.orgId;
821
1245
  }
822
- const parent = dirname5(dir);
1246
+ const parent = dirname8(dir);
823
1247
  if (parent === dir) {
824
1248
  return;
825
1249
  }
@@ -855,26 +1279,26 @@ function resolveOrg(args) {
855
1279
  import {
856
1280
  appendFileSync,
857
1281
  closeSync as closeSync2,
858
- existsSync as existsSync7,
1282
+ existsSync as existsSync9,
859
1283
  fstatSync,
860
- mkdirSync as mkdirSync5,
1284
+ mkdirSync as mkdirSync6,
861
1285
  openSync as openSync2,
862
1286
  opendirSync,
863
- readFileSync as readFileSync11,
1287
+ readFileSync as readFileSync13,
864
1288
  readSync,
865
- readdirSync as readdirSync3
1289
+ readdirSync as readdirSync4
866
1290
  } from "fs";
867
- import { dirname as dirname8, join as join12 } from "path";
1291
+ import { dirname as dirname11, join as join16 } from "path";
868
1292
 
869
1293
  // src/client.ts
870
- import { createHash as createHash5 } from "crypto";
871
- import { chmodSync as chmodSync3, existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync9, rmSync as rmSync6 } from "fs";
872
- import { dirname as dirname6 } from "path";
1294
+ import { createHash as createHash8 } from "crypto";
1295
+ import { chmodSync as chmodSync4, existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync11, rmSync as rmSync8 } from "fs";
1296
+ import { dirname as dirname9 } from "path";
873
1297
 
874
1298
  // src/daemon/client-instance-id.ts
875
- import { randomBytes as randomBytes4 } from "crypto";
876
- import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync8 } from "fs";
877
- import { join as join9 } from "path";
1299
+ import { randomBytes as randomBytes5 } from "crypto";
1300
+ import { chmodSync as chmodSync3, lstatSync as lstatSync6, readFileSync as readFileSync10 } from "fs";
1301
+ import { join as join13 } from "path";
878
1302
  var INSTANCE_BODY_CHARS = 43;
879
1303
  var INSTANCE_PREFIX = "pci_";
880
1304
  var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
@@ -883,28 +1307,28 @@ var MAX_STORED_BYTES = INSTANCE_PREFIX.length + INSTANCE_BODY_CHARS + 1;
883
1307
  var runtimeVersion = process.env.PRIM_RUNTIME_VERSION ?? packageVersion();
884
1308
 
885
1309
  // src/client.ts
886
- var DEFAULT_API_URL2 = "https://api.getprimitive.ai";
1310
+ var DEFAULT_API_URL3 = "https://api.getprimitive.ai";
887
1311
  function getSiteUrl() {
888
1312
  return getSiteUrlForEnvironment(process.env.PRIM_API_URL);
889
1313
  }
890
1314
  function getSiteUrlForEnvironment(primApiUrl) {
891
- return primApiUrl?.trim() || DEFAULT_API_URL2;
1315
+ return primApiUrl?.trim() || DEFAULT_API_URL3;
892
1316
  }
893
1317
  var CLI_MANAGEMENT_RESPONSE_MAX_BYTES = 2 * 1024 * 1024;
894
1318
 
895
1319
  // src/drain-progress.ts
896
1320
  import {
897
- chmodSync as chmodSync4,
898
- existsSync as existsSync6,
899
- readFileSync as readFileSync10,
900
- readdirSync as readdirSync2,
901
- rmSync as rmSync7,
1321
+ chmodSync as chmodSync5,
1322
+ existsSync as existsSync8,
1323
+ readFileSync as readFileSync12,
1324
+ readdirSync as readdirSync3,
1325
+ rmSync as rmSync9,
902
1326
  rmdirSync
903
1327
  } from "fs";
904
- import { basename as basename2, dirname as dirname7, join as join11 } from "path";
1328
+ import { basename as basename3, dirname as dirname10, join as join15 } from "path";
905
1329
 
906
1330
  // src/journal.ts
907
- var JOURNAL_DIR = join12(primConfigDirectory(), "moves");
1331
+ var JOURNAL_DIR = join16(primConfigDirectory(), "moves");
908
1332
  var UNBOUND_BUCKET = "_unbound";
909
1333
  var JOURNAL_BASENAME = "journal.ndjson";
910
1334
  var JOURNAL_STATS_SAMPLE_BYTES = 64 * 1024;
@@ -916,26 +1340,26 @@ function envSlug(apiUrl) {
916
1340
  return slug;
917
1341
  }
918
1342
  function currentEnvDir() {
919
- return join12(JOURNAL_DIR, envSlug(getSiteUrl()));
1343
+ return join16(JOURNAL_DIR, envSlug(getSiteUrl()));
920
1344
  }
921
1345
  var DIR_MODE = 448;
922
1346
  var FILE_MODE = 384;
923
1347
  var SAFE_BUCKET = /^[A-Za-z0-9_-]+$/;
924
1348
  var RESERVED_BUCKETS = /* @__PURE__ */ new Set([UNBOUND_BUCKET, "_legacy"]);
925
1349
  function appendMoveToPath(path, move) {
926
- const dir = dirname8(path);
927
- if (!existsSync7(dir)) {
928
- mkdirSync5(dir, { recursive: true, mode: DIR_MODE });
1350
+ const dir = dirname11(path);
1351
+ if (!existsSync9(dir)) {
1352
+ mkdirSync6(dir, { recursive: true, mode: DIR_MODE });
929
1353
  }
930
1354
  appendFileSync(path, `${JSON.stringify(move)}
931
1355
  `, { mode: FILE_MODE });
932
1356
  }
933
1357
  function bucketDir(orgId) {
934
1358
  const safe = orgId !== void 0 && SAFE_BUCKET.test(orgId) && !RESERVED_BUCKETS.has(orgId);
935
- return join12(currentEnvDir(), safe ? orgId : UNBOUND_BUCKET);
1359
+ return join16(currentEnvDir(), safe ? orgId : UNBOUND_BUCKET);
936
1360
  }
937
1361
  function journalPath(orgId) {
938
- return join12(bucketDir(orgId), JOURNAL_BASENAME);
1362
+ return join16(bucketDir(orgId), JOURNAL_BASENAME);
939
1363
  }
940
1364
  function appendMove(move, orgId) {
941
1365
  const actor = machineCaptureActor();
@@ -948,38 +1372,38 @@ var FLUSHING_PREFIX = `${JOURNAL_BASENAME}.flushing.`;
948
1372
 
949
1373
  // src/lib/activation.ts
950
1374
  import { execFileSync as execFileSync4 } from "child_process";
951
- import { existsSync as existsSync9, readFileSync as readFileSync14 } from "fs";
1375
+ import { existsSync as existsSync11, readFileSync as readFileSync15 } from "fs";
952
1376
  import { homedir as homedir2 } from "os";
953
- import { join as join15 } from "path";
1377
+ import { join as join18 } from "path";
954
1378
 
955
1379
  // src/lib/cloud-prepared.ts
956
- import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync12, rmSync as rmSync8, writeFileSync as writeFileSync4 } from "fs";
957
- import { join as join13 } from "path";
1380
+ import { existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync14, rmSync as rmSync10, writeFileSync as writeFileSync5 } from "fs";
1381
+ import { join as join17 } from "path";
958
1382
  var CLOUD_PREPARED_MARKER = "cloud-prepared";
959
1383
  function cloudPreparedPath(env = process.env) {
960
- return join13(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
1384
+ return join17(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
961
1385
  }
962
1386
  function isPreparedCloudSession(env = process.env) {
963
1387
  if (!isClaudeCloudSession(env)) return false;
964
1388
  try {
965
- return existsSync8(cloudPreparedPath(env));
1389
+ return existsSync10(cloudPreparedPath(env));
966
1390
  } catch {
967
1391
  return false;
968
1392
  }
969
1393
  }
970
1394
 
971
1395
  // src/lib/demo-pause.ts
972
- import { execFileSync as execFileSync2 } from "child_process";
1396
+ import { execFileSync as execFileSync3 } from "child_process";
973
1397
  var DEMO_PAUSE_MS = 30 * 6e4;
974
1398
  var PAUSE_KEY = "prim.demoPause";
975
- var GIT_TIMEOUT_MS = 1e3;
1399
+ var GIT_TIMEOUT_MS2 = 1e3;
976
1400
  function git(cwd, args) {
977
1401
  try {
978
- return execFileSync2("git", args, {
1402
+ return execFileSync3("git", args, {
979
1403
  cwd,
980
1404
  encoding: "utf-8",
981
1405
  stdio: ["ignore", "pipe", "ignore"],
982
- timeout: GIT_TIMEOUT_MS
1406
+ timeout: GIT_TIMEOUT_MS2
983
1407
  });
984
1408
  } catch {
985
1409
  return void 0;
@@ -987,10 +1411,10 @@ function git(cwd, args) {
987
1411
  }
988
1412
  function setLocal(cwd, key, value) {
989
1413
  try {
990
- execFileSync2(
1414
+ execFileSync3(
991
1415
  "git",
992
1416
  value === null ? ["config", "--local", "--unset", key] : ["config", "--local", key, value],
993
- { cwd, stdio: ["ignore", "ignore", "pipe"], timeout: GIT_TIMEOUT_MS }
1417
+ { cwd, stdio: ["ignore", "ignore", "pipe"], timeout: GIT_TIMEOUT_MS2 }
994
1418
  );
995
1419
  } catch (error) {
996
1420
  if (value !== null || error.status !== 5) throw error;
@@ -1029,156 +1453,6 @@ function healDemoPause(cwd, pause, options = {}) {
1029
1453
  }
1030
1454
  }
1031
1455
 
1032
- // src/lib/git.ts
1033
- import { execFileSync as execFileSync3 } from "child_process";
1034
- import { createHash as createHash6 } from "crypto";
1035
- import { lstatSync as lstatSync5, readFileSync as readFileSync13, realpathSync } from "fs";
1036
- import { basename as basename3, dirname as dirname9, isAbsolute as isAbsolute3, join as join14, relative, resolve as resolve2, sep } from "path";
1037
- var GIT_TIMEOUT_MS2 = 1e3;
1038
- var MAX_SETTINGS_BYTES = 1024 * 1024;
1039
- var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
1040
- var GITHUB_REPOSITORY_PATTERN = /^(?!\.{1,2}$)[A-Za-z0-9._-]{1,100}$/u;
1041
- function gitToplevel(cwd) {
1042
- try {
1043
- return execFileSync3("git", ["rev-parse", "--show-toplevel"], {
1044
- cwd,
1045
- encoding: "utf-8",
1046
- stdio: ["ignore", "pipe", "ignore"],
1047
- timeout: GIT_TIMEOUT_MS2
1048
- }).trim();
1049
- } catch {
1050
- return null;
1051
- }
1052
- }
1053
- function gitValue(cwd, args) {
1054
- try {
1055
- const value = execFileSync3("git", args, {
1056
- cwd,
1057
- encoding: "utf-8",
1058
- stdio: ["ignore", "pipe", "ignore"],
1059
- timeout: GIT_TIMEOUT_MS2
1060
- }).trim();
1061
- return value || void 0;
1062
- } catch {
1063
- return void 0;
1064
- }
1065
- }
1066
- function parseGithubRepositoryName(path) {
1067
- const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
1068
- if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
1069
- return null;
1070
- }
1071
- return `${parts[0]}/${parts[1]}`;
1072
- }
1073
- function githubRepositoryFromRemote(remote) {
1074
- if ([...remote].some((char) => char < " " || char === "\x7F")) return null;
1075
- const match = /^(?:git@github\.com:([^?#]+)|(?:https|ssh):\/\/(?:[^/@]+@)?github\.com(?::\d+)?\/([^?#]+))$/i.exec(
1076
- remote
1077
- );
1078
- const path = match?.[1] ?? match?.[2];
1079
- return path ? parseGithubRepositoryName(path) : null;
1080
- }
1081
- function checkoutSettingsText(repoRoot) {
1082
- const path = join14(repoRoot, ".claude", "settings.json");
1083
- try {
1084
- if (!lstatSync5(join14(repoRoot, ".claude")).isDirectory()) return null;
1085
- const stat = lstatSync5(path);
1086
- if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
1087
- return readFileSync13(path, "utf8");
1088
- } catch {
1089
- return null;
1090
- }
1091
- }
1092
- function checkoutDeclaration(repoRoot, name) {
1093
- const text = checkoutSettingsText(repoRoot);
1094
- if (text === null) return null;
1095
- let parsed;
1096
- try {
1097
- parsed = JSON.parse(text);
1098
- } catch {
1099
- return null;
1100
- }
1101
- const env = typeof parsed === "object" && parsed !== null ? parsed.env : void 0;
1102
- const value = typeof env === "object" && env !== null ? env[name] : void 0;
1103
- return typeof value === "string" ? value : null;
1104
- }
1105
- function declaredGithubRepository(repoRoot) {
1106
- const value = checkoutDeclaration(repoRoot, "PRIM_REPOSITORY");
1107
- return value === null ? null : parseGithubRepositoryName(value.trim());
1108
- }
1109
- function githubRepositoryFullName(cwd) {
1110
- const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
1111
- if (remote) {
1112
- const fromOrigin = githubRepositoryFromRemote(remote);
1113
- if (fromOrigin || normalizeOriginRemote(remote)) return fromOrigin;
1114
- }
1115
- const root = gitToplevel(cwd);
1116
- return root ? declaredGithubRepository(root) : null;
1117
- }
1118
- function normalizeOriginRemote(remote) {
1119
- const value = remote.trim();
1120
- if (!value) return void 0;
1121
- const scp = !value.includes("://") ? /^(?:[^@/\s]+@)?(?<host>[^:/\s]+):(?<path>.+)$/.exec(value)?.groups : void 0;
1122
- if (scp?.host && scp.path) {
1123
- const path = scp.path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
1124
- return path ? `${scp.host.toLowerCase()}/${path}` : void 0;
1125
- }
1126
- try {
1127
- const url = new URL(value);
1128
- url.username = "";
1129
- url.password = "";
1130
- url.search = "";
1131
- url.hash = "";
1132
- const path = url.pathname.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
1133
- if (url.host && path) return `${url.host.toLowerCase()}/${path}`;
1134
- return void 0;
1135
- } catch {
1136
- return void 0;
1137
- }
1138
- }
1139
- function opaqueRepoKey(source, value) {
1140
- return `repo_v1_${createHash6("sha256").update(`${source}\0${value}`).digest("hex")}`;
1141
- }
1142
- function resolveRepositoryContext(cwd = process.cwd()) {
1143
- const top = gitToplevel(cwd);
1144
- if (!top) return null;
1145
- let repoRoot;
1146
- try {
1147
- repoRoot = realpathSync.native(top);
1148
- } catch {
1149
- repoRoot = resolve2(top);
1150
- }
1151
- const origin = gitValue(repoRoot, ["config", "--get", "remote.origin.url"]);
1152
- const repoFullName = githubRepositoryFullName(repoRoot) ?? void 0;
1153
- const normalizedOrigin = origin ? normalizeOriginRemote(origin) : void 0;
1154
- if (normalizedOrigin) {
1155
- return {
1156
- repoRoot,
1157
- repoKey: opaqueRepoKey("origin", normalizedOrigin),
1158
- identitySource: "origin",
1159
- repoFullName
1160
- };
1161
- }
1162
- if (repoFullName) {
1163
- return {
1164
- repoRoot,
1165
- repoKey: opaqueRepoKey("origin", `github.com/${repoFullName}`),
1166
- identitySource: "declared",
1167
- repoFullName
1168
- };
1169
- }
1170
- const roots = gitValue(repoRoot, ["rev-list", "--max-parents=0", "HEAD"])?.split(/\s+/).filter(Boolean).sort();
1171
- if (roots && roots.length > 0) {
1172
- return {
1173
- repoRoot,
1174
- repoKey: opaqueRepoKey("root_commit", roots.join("\n")),
1175
- identitySource: "root_commit",
1176
- repoFullName
1177
- };
1178
- }
1179
- return { repoRoot, repoFullName };
1180
- }
1181
-
1182
1456
  // src/lib/activation.ts
1183
1457
  var PRIM_ACTIVE_KEY = "prim.active";
1184
1458
  var PRIM_ACTIVE_DECLARATION = "PRIM_ACTIVE";
@@ -1231,10 +1505,10 @@ function repoSyncId(cwd) {
1231
1505
  function projectPrimInstallAt(root) {
1232
1506
  if (root === null || root === homedir2()) return false;
1233
1507
  for (const rel of PROJECT_INSTALL_FILES) {
1234
- const path = join15(root, rel);
1235
- if (existsSync9(path)) {
1508
+ const path = join18(root, rel);
1509
+ if (existsSync11(path)) {
1236
1510
  try {
1237
- const content = readFileSync14(path, "utf-8");
1511
+ const content = readFileSync15(path, "utf-8");
1238
1512
  if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
1239
1513
  } catch {
1240
1514
  }
@@ -28243,22 +28517,22 @@ function unattendedEnv(env = process.env) {
28243
28517
  import { execFileSync as execFileSync5 } from "child_process";
28244
28518
  import { randomUUID as randomUUID3 } from "crypto";
28245
28519
  import {
28246
- constants as constants2,
28247
- chmodSync as chmodSync5,
28520
+ constants as constants3,
28521
+ chmodSync as chmodSync6,
28248
28522
  closeSync as closeSync3,
28249
28523
  fchmodSync as fchmodSync2,
28250
28524
  fsyncSync as fsyncSync2,
28251
28525
  linkSync as linkSync2,
28252
- lstatSync as lstatSync6,
28253
- mkdirSync as mkdirSync7,
28526
+ lstatSync as lstatSync7,
28527
+ mkdirSync as mkdirSync8,
28254
28528
  openSync as openSync3,
28255
- readFileSync as readFileSync15,
28256
- statSync as statSync2,
28529
+ readFileSync as readFileSync16,
28530
+ statSync as statSync3,
28257
28531
  unlinkSync,
28258
- writeFileSync as writeFileSync5
28532
+ writeFileSync as writeFileSync6
28259
28533
  } from "fs";
28260
- import { dirname as dirname10, isAbsolute as isAbsolute4, join as join16, resolve as resolve3 } from "path";
28261
- var WORKSPACE_ID_RELATIVE_PATH = join16("prim", "workspace-id");
28534
+ import { dirname as dirname12, isAbsolute as isAbsolute5, join as join19, resolve as resolve4 } from "path";
28535
+ var WORKSPACE_ID_RELATIVE_PATH = join19("prim", "workspace-id");
28262
28536
  var MAX_ANCESTORS = 64;
28263
28537
  var MAX_GIT_FILE_BYTES = 4096;
28264
28538
  var MAX_ID_FILE_BYTES = 128;
@@ -28304,7 +28578,7 @@ function resolveWorkspaceIdPath(cwd) {
28304
28578
  }
28305
28579
  return {
28306
28580
  status: "resolved",
28307
- path: isAbsolute4(gitPath) ? resolve3(gitPath) : resolve3(cwd, gitPath)
28581
+ path: isAbsolute5(gitPath) ? resolve4(gitPath) : resolve4(cwd, gitPath)
28308
28582
  };
28309
28583
  } catch (error) {
28310
28584
  const code = errorCode(error);
@@ -28315,21 +28589,21 @@ function resolveWorkspaceIdPath(cwd) {
28315
28589
  }
28316
28590
  }
28317
28591
  function resolveFromFilesystem(cwd) {
28318
- let current = resolve3(cwd);
28592
+ let current = resolve4(cwd);
28319
28593
  for (let depth = 0; depth < MAX_ANCESTORS; depth += 1) {
28320
- const dotGit = join16(current, ".git");
28594
+ const dotGit = join19(current, ".git");
28321
28595
  try {
28322
- const stat = lstatSync6(dotGit);
28596
+ const stat = lstatSync7(dotGit);
28323
28597
  if (stat.isDirectory() && isGitDirectory(dotGit)) {
28324
- return join16(dotGit, WORKSPACE_ID_RELATIVE_PATH);
28598
+ return join19(dotGit, WORKSPACE_ID_RELATIVE_PATH);
28325
28599
  }
28326
28600
  if (stat.isFile() && stat.size <= MAX_GIT_FILE_BYTES) {
28327
- const contents = readFileSync15(dotGit, "utf8");
28601
+ const contents = readFileSync16(dotGit, "utf8");
28328
28602
  const match = /^gitdir: (.+?)(?:\r?\n)?$/.exec(contents);
28329
28603
  if (match?.[1]) {
28330
- const gitDirectory = isAbsolute4(match[1]) ? resolve3(match[1]) : resolve3(current, match[1]);
28604
+ const gitDirectory = isAbsolute5(match[1]) ? resolve4(match[1]) : resolve4(current, match[1]);
28331
28605
  if (isGitDirectory(gitDirectory)) {
28332
- return join16(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
28606
+ return join19(gitDirectory, WORKSPACE_ID_RELATIVE_PATH);
28333
28607
  }
28334
28608
  }
28335
28609
  }
@@ -28340,7 +28614,7 @@ function resolveFromFilesystem(cwd) {
28340
28614
  return null;
28341
28615
  }
28342
28616
  }
28343
- const parent = dirname10(current);
28617
+ const parent = dirname12(current);
28344
28618
  if (parent === current) break;
28345
28619
  current = parent;
28346
28620
  }
@@ -28348,7 +28622,7 @@ function resolveFromFilesystem(cwd) {
28348
28622
  }
28349
28623
  function isGitDirectory(path) {
28350
28624
  try {
28351
- return statSync2(join16(path, "HEAD")).isFile();
28625
+ return statSync3(join19(path, "HEAD")).isFile();
28352
28626
  } catch {
28353
28627
  return false;
28354
28628
  }
@@ -28356,7 +28630,7 @@ function isGitDirectory(path) {
28356
28630
  function inspectPath(path) {
28357
28631
  let stat;
28358
28632
  try {
28359
- stat = lstatSync6(path);
28633
+ stat = lstatSync7(path);
28360
28634
  } catch (error) {
28361
28635
  const code = errorCode(error);
28362
28636
  if (code === "ENOENT" || code === "ENOTDIR") return { status: "missing", path };
@@ -28367,7 +28641,7 @@ function inspectPath(path) {
28367
28641
  return { status: "corrupt", path, reason: "invalid_content" };
28368
28642
  }
28369
28643
  try {
28370
- const contents = readFileSync15(path, "utf8");
28644
+ const contents = readFileSync16(path, "utf8");
28371
28645
  const workspaceId = contents.endsWith("\n") ? contents.slice(0, -1) : contents;
28372
28646
  if ((contents === workspaceId || contents === `${workspaceId}
28373
28647
  `) && isCanonicalWorkspaceId(workspaceId)) {
@@ -28384,22 +28658,22 @@ function inspectPath(path) {
28384
28658
  }
28385
28659
  }
28386
28660
  function createWorkspaceId(path) {
28387
- const parent = dirname10(path);
28661
+ const parent = dirname12(path);
28388
28662
  const workspaceId = randomUUID3();
28389
- const temporaryPath = join16(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
28663
+ const temporaryPath = join19(parent, `.workspace-id-${process.pid}-${randomUUID3()}.tmp`);
28390
28664
  let temporaryCreated = false;
28391
28665
  let publishing = false;
28392
28666
  try {
28393
- mkdirSync7(parent, { recursive: true, mode: 448 });
28394
- chmodSync5(parent, 448);
28667
+ mkdirSync8(parent, { recursive: true, mode: 448 });
28668
+ chmodSync6(parent, 448);
28395
28669
  const fd = openSync3(
28396
28670
  temporaryPath,
28397
- constants2.O_CREAT | constants2.O_EXCL | constants2.O_WRONLY,
28671
+ constants3.O_CREAT | constants3.O_EXCL | constants3.O_WRONLY,
28398
28672
  384
28399
28673
  );
28400
28674
  temporaryCreated = true;
28401
28675
  try {
28402
- writeFileSync5(fd, `${workspaceId}
28676
+ writeFileSync6(fd, `${workspaceId}
28403
28677
  `, "utf8");
28404
28678
  fchmodSync2(fd, 384);
28405
28679
  fsyncSync2(fd);
@@ -28446,7 +28720,7 @@ function errorCode(error) {
28446
28720
  }
28447
28721
 
28448
28722
  // src/hooks/prim-hook-core.ts
28449
- import { createHash as createHash7, randomUUID as randomUUID4 } from "crypto";
28723
+ import { createHash as createHash9, randomUUID as randomUUID4 } from "crypto";
28450
28724
  import { platform } from "os";
28451
28725
 
28452
28726
  // src/protocol/move.ts
@@ -28454,8 +28728,8 @@ var LEGACY_ENVELOPE_VERSION = 1;
28454
28728
  var ENVELOPE_VERSION = LEGACY_ENVELOPE_VERSION;
28455
28729
 
28456
28730
  // src/hooks/redact.ts
28457
- import { existsSync as existsSync10, readFileSync as readFileSync16, statSync as statSync3 } from "fs";
28458
- import { join as join17 } from "path";
28731
+ import { existsSync as existsSync12, readFileSync as readFileSync17, statSync as statSync4 } from "fs";
28732
+ import { join as join20 } from "path";
28459
28733
  import { Worker } from "worker_threads";
28460
28734
  var USER_HOME_RULES = [
28461
28735
  {
@@ -28607,7 +28881,7 @@ function toRewriteMove(rewrite, cliVersion, cwd, context) {
28607
28881
  const moves = [];
28608
28882
  for (let offset = 0; offset < pairs.length; offset += MAX_REWRITE_PAIRS_PER_MOVE) {
28609
28883
  const sortedPairs = pairs.slice(offset, offset + MAX_REWRITE_PAIRS_PER_MOVE);
28610
- const moveId = `rewrite:v1:${createHash7("sha256").update(JSON.stringify(["rewrite:v1", repoSyncId2, workspaceId, rewrite.source, sortedPairs])).digest("hex")}`;
28884
+ const moveId = `rewrite:v1:${createHash9("sha256").update(JSON.stringify(["rewrite:v1", repoSyncId2, workspaceId, rewrite.source, sortedPairs])).digest("hex")}`;
28611
28885
  moves.push({
28612
28886
  moveId,
28613
28887
  capturedAt: observedAt,
@@ -28639,7 +28913,7 @@ function toRewriteMove(rewrite, cliVersion, cwd, context) {
28639
28913
  }
28640
28914
 
28641
28915
  // src/hooks/post-rewrite.ts
28642
- var here = dirname11(fileURLToPath4(import.meta.url));
28916
+ var here = dirname13(fileURLToPath5(import.meta.url));
28643
28917
  var GIT_TIMEOUT_MS4 = 1e3;
28644
28918
  var MAX_PAIRS_FILE_BYTES = 1048576;
28645
28919
  var MAX_PAIRS_FILE_AGE_MS = 10 * 60 * 1e3;
@@ -28669,17 +28943,17 @@ function privatePairsFileStat(stat, now) {
28669
28943
  }
28670
28944
  function rewritePairsFromLauncher(env = process.env, now = Date.now()) {
28671
28945
  const path = env.PRIM_REWRITE_PAIRS_FILE;
28672
- if (!path || !isAbsolute5(path) || !PAIRS_FILE_RE.test(basename4(path))) return;
28946
+ if (!path || !isAbsolute6(path) || !PAIRS_FILE_RE.test(basename4(path))) return;
28673
28947
  let fd;
28674
28948
  try {
28675
- const pathStat = lstatSync7(path);
28949
+ const pathStat = lstatSync8(path);
28676
28950
  if (!privatePairsFileStat(pathStat, now)) return;
28677
- fd = openSync4(path, constants3.O_RDONLY | constants3.O_NOFOLLOW);
28951
+ fd = openSync4(path, constants4.O_RDONLY | constants4.O_NOFOLLOW);
28678
28952
  const openStat = fstatSync2(fd);
28679
28953
  if (!privatePairsFileStat(openStat, now) || openStat.dev !== pathStat.dev || openStat.ino !== pathStat.ino) {
28680
28954
  return;
28681
28955
  }
28682
- const bytes = readFileSync17(fd);
28956
+ const bytes = readFileSync18(fd);
28683
28957
  if (bytes.length !== openStat.size) return;
28684
28958
  let text;
28685
28959
  try {
@@ -28709,7 +28983,7 @@ function rewritePairsFromLauncher(env = process.env, now = Date.now()) {
28709
28983
  }
28710
28984
  function unlinkSnapshot(snapshot) {
28711
28985
  try {
28712
- const current = lstatSync7(snapshot.path);
28986
+ const current = lstatSync8(snapshot.path);
28713
28987
  if (current.isFile() && !current.isSymbolicLink() && current.dev === snapshot.dev && current.ino === snapshot.ino) {
28714
28988
  unlinkSync2(snapshot.path);
28715
28989
  }
@@ -28735,14 +29009,14 @@ function validBranch(value) {
28735
29009
  }
28736
29010
  function resolveCliVersion() {
28737
29011
  try {
28738
- const pkg = JSON.parse(readFileSync17(join18(here, "..", "..", "package.json"), "utf-8"));
29012
+ const pkg = JSON.parse(readFileSync18(join21(here, "..", "..", "package.json"), "utf-8"));
28739
29013
  return pkg.version ?? "unknown";
28740
29014
  } catch {
28741
29015
  return "unknown";
28742
29016
  }
28743
29017
  }
28744
29018
  function spawnBackgroundFlush() {
28745
- const entry = join18(here, "..", "index.js");
29019
+ const entry = join21(here, "..", "index.js");
28746
29020
  spawn2(process.execPath, [entry, "moves", "flush"], {
28747
29021
  detached: true,
28748
29022
  stdio: "ignore",