@primitive.ai/prim 0.1.0-alpha.125 → 0.1.0-alpha.127

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 (45) hide show
  1. package/README.md +140 -1
  2. package/SKILL.md +6 -1
  3. package/dist/{chunk-JFWJN2ME.js → chunk-72NIZMZN.js} +114 -5
  4. package/dist/{chunk-2BEUR3DU.js → chunk-A5VTE43F.js} +2 -2
  5. package/dist/{chunk-6OPSSJHO.js → chunk-C4QNBSWB.js} +24 -9
  6. package/dist/{chunk-BFYJLI7V.js → chunk-F3FDVHR7.js} +1 -1
  7. package/dist/{chunk-YP4OXKNX.js → chunk-H6X52UVF.js} +1 -1
  8. package/dist/{chunk-ND6TYHNI.js → chunk-H74RDXKP.js} +2 -2
  9. package/dist/{chunk-NJBN3WXF.js → chunk-HZI5PBN4.js} +785 -154
  10. package/dist/{chunk-FYYHBOOM.js → chunk-JCKOW45X.js} +2 -2
  11. package/dist/{chunk-DT7E3SD5.js → chunk-KFRGVHGB.js} +4 -4
  12. package/dist/{chunk-TI37ME2D.js → chunk-L6IL4N6Y.js} +16 -7
  13. package/dist/{chunk-HPA7RGSZ.js → chunk-MGKSZSTV.js} +7 -8
  14. package/dist/{chunk-ZKXNJB6U.js → chunk-NVDPKW7Z.js} +69 -29
  15. package/dist/{chunk-NBNQI3YJ.js → chunk-O65UVJZH.js} +6 -3
  16. package/dist/{chunk-74DQDWLW.js → chunk-R4EYLEIK.js} +7 -2
  17. package/dist/{chunk-R35M4RCY.js → chunk-RV3JFSMX.js} +4 -4
  18. package/dist/{chunk-PPZ56EVJ.js → chunk-TNWI3JWK.js} +1 -1
  19. package/dist/{chunk-6KXQQ7CQ.js → chunk-URYZDQFH.js} +3 -3
  20. package/dist/{chunk-L32WYFJT.js → chunk-UUQT5GMO.js} +135 -12
  21. package/dist/{chunk-EZXIKEMA.js → chunk-VVFVENU4.js} +6 -4
  22. package/dist/{chunk-O73J3KQQ.js → chunk-WGTUNUIS.js} +5 -2
  23. package/dist/daemon/server.js +805 -218
  24. package/dist/hook-runtime/daemon/server.js +805 -218
  25. package/dist/hook-runtime/hooks/post-commit.js +286 -59
  26. package/dist/hook-runtime/hooks/post-rewrite.js +278 -51
  27. package/dist/hook-runtime/hooks/post-tool-use.js +672 -194
  28. package/dist/hook-runtime/hooks/pre-commit.js +536 -88
  29. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +616 -165
  30. package/dist/hook-runtime/hooks/prim-hook.js +642 -167
  31. package/dist/hook-runtime/hooks/session-end.js +263 -47
  32. package/dist/hook-runtime/hooks/session-start.js +1103 -476
  33. package/dist/hook-runtime/index.js +3645 -2120
  34. package/dist/hook-runtime/statusline-main.js +257 -29
  35. package/dist/hooks/post-commit.js +7 -7
  36. package/dist/hooks/post-rewrite.js +6 -6
  37. package/dist/hooks/post-tool-use.js +15 -15
  38. package/dist/hooks/pre-commit.js +4 -4
  39. package/dist/hooks/pre-tool-use-worker.js +14 -15
  40. package/dist/hooks/prim-hook.js +16 -16
  41. package/dist/hooks/session-end.js +4 -4
  42. package/dist/hooks/session-start.js +49 -18
  43. package/dist/index.js +1014 -271
  44. package/dist/statusline-main.js +257 -29
  45. package/package.json +1 -1
@@ -2,10 +2,15 @@
2
2
  import { createRequire as __primCreateRequire } from "node:module"; const require = __primCreateRequire(import.meta.url);
3
3
 
4
4
  // src/commands/statusline.ts
5
- import { readFileSync as readFileSync10 } from "fs";
5
+ import { readFileSync as readFileSync12 } from "fs";
6
6
  import { dirname as dirname7, resolve as resolve3 } from "path";
7
7
  import { fileURLToPath as fileURLToPath4 } from "url";
8
8
 
9
+ // src/lib/cloud-env.ts
10
+ function isClaudeCloudSession(env = process.env) {
11
+ return env.CLAUDE_CODE_REMOTE === "true";
12
+ }
13
+
9
14
  // src/client.ts
10
15
  import { createHash as createHash5 } from "crypto";
11
16
  import { chmodSync as chmodSync3, existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync8, rmSync as rmSync6 } from "fs";
@@ -33,8 +38,17 @@ import { join as join7 } from "path";
33
38
 
34
39
  // src/lib/machine-credentials.ts
35
40
  import { execFileSync } from "child_process";
36
- import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
37
- import { chmodSync, existsSync as existsSync3, lstatSync as lstatSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync5, rmSync as rmSync5 } from "fs";
41
+ import { createHash as createHash3, randomBytes as randomBytes3, randomUUID as randomUUID2 } from "crypto";
42
+ import {
43
+ chmodSync,
44
+ existsSync as existsSync3,
45
+ linkSync,
46
+ lstatSync as lstatSync3,
47
+ mkdirSync as mkdirSync3,
48
+ readFileSync as readFileSync5,
49
+ rmSync as rmSync5,
50
+ writeFileSync as writeFileSync3
51
+ } from "fs";
38
52
  import { createRequire } from "module";
39
53
  import { dirname as dirname4, join as join6 } from "path";
40
54
  import { fileURLToPath as fileURLToPath3 } from "url";
@@ -97,6 +111,10 @@ var PRIM_CONFIG_SHELL_RESOLVER = [
97
111
  "fi; fi; "
98
112
  ].join("");
99
113
 
114
+ // src/lib/loopback-fetch.ts
115
+ import { request } from "http";
116
+ import { Readable } from "stream";
117
+
100
118
  // src/lib/workos-connect.ts
101
119
  var DISCOVERY_MAX_BYTES = 16 * 1024;
102
120
  var WORKOS_CONNECT_RESPONSE_MAX_BYTES = 64 * 1024;
@@ -272,12 +290,16 @@ function primConfigDirectory(options = {}) {
272
290
 
273
291
  // src/lib/machine-broker.ts
274
292
  var MAX_RESPONSE_BYTES = 96 * 1024;
293
+ var MAX_FORWARD_REQUEST_BYTES = 12 * 1024 * 1024;
294
+ var MAX_API_RESPONSE_BYTES = 8 * 1024 * 1024;
295
+ var MAX_FORWARD_RESPONSE_BYTES = 36 * 1024 * 1024;
275
296
  var IDLE_MS = 5 * 6e4;
276
297
 
277
298
  // src/lib/machine-retry.ts
278
299
  import { createHash as createHash2 } from "crypto";
279
- import { lstatSync as lstatSync2, readFileSync as readFileSync4, rmSync as rmSync4 } from "fs";
300
+ import { lstatSync as lstatSync2, readFileSync as readFileSync4, readdirSync, rmSync as rmSync4 } from "fs";
280
301
  import { join as join5 } from "path";
302
+ var MAX_SERVER_WAIT_MS = 15 * 6e4;
281
303
 
282
304
  // src/lib/machine-credentials.ts
283
305
  var require2 = createRequire(import.meta.url);
@@ -320,6 +342,33 @@ function readEnvironmentContext(environment, deps) {
320
342
  return void 0;
321
343
  }
322
344
  }
345
+ function protectPath(path, directory) {
346
+ if (process.platform !== "win32") {
347
+ chmodSync(path, directory ? 448 : 384);
348
+ return;
349
+ }
350
+ const encodedPath = Buffer.from(path).toString("base64");
351
+ 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)`;
352
+ execFileSync(
353
+ "powershell.exe",
354
+ [
355
+ "-NoProfile",
356
+ "-NonInteractive",
357
+ "-EncodedCommand",
358
+ Buffer.from(script, "utf16le").toString("base64")
359
+ ],
360
+ { stdio: "pipe", encoding: "utf8", windowsHide: true }
361
+ );
362
+ }
363
+ function ensureDirectory(directory) {
364
+ mkdirSync3(directory, { recursive: true, mode: 448 });
365
+ if (lstatSync3(directory).isSymbolicLink())
366
+ throw new MachineAuthError(
367
+ "unsafe_storage",
368
+ "Credential directory must not be a symbolic link."
369
+ );
370
+ protectPath(directory, true);
371
+ }
323
372
  function readPrivate(path) {
324
373
  let raw;
325
374
  try {
@@ -378,10 +427,98 @@ function readMachineProfile(deps = {}) {
378
427
  const value = readPrivate(join6(configurationDirectory(deps), PROFILE_FILE));
379
428
  return value === void 0 ? void 0 : parseProfile(value);
380
429
  }
430
+ var NETWORK_SECRET_AUTH = "network-secret";
431
+ var NETWORK_TOKEN_AUTH = "network-token";
432
+ var INJECTED_IDENTITY_TTL_MS = 60 * 6e4;
433
+ var brokerKeys = /* @__PURE__ */ new Map();
434
+ function networkSecretBrokerKey(deps, clientId) {
435
+ const directory = configurationDirectory(deps);
436
+ const path = join6(directory, `machine_network_${hash(`${apiUrlFor(deps)}\0${clientId}`)}.key`);
437
+ const known = brokerKeys.get(path);
438
+ if (known) return known;
439
+ ensureDirectory(directory);
440
+ const read = () => {
441
+ try {
442
+ const stat = lstatSync3(path);
443
+ if (!stat.isFile() || process.platform !== "win32" && ((stat.mode & 63) !== 0 || typeof process.getuid === "function" && stat.uid !== process.getuid()))
444
+ throw new MachineAuthError(
445
+ "unsafe_storage",
446
+ `The machine broker key at ${path} is not an owner-only file. Delete it and retry.`,
447
+ true
448
+ );
449
+ const value = readFileSync5(path, "utf8").trim();
450
+ return { key: /^[a-f0-9]{64}$/u.test(value) ? value : void 0 };
451
+ } catch (error) {
452
+ if (error.code === "ENOENT") return void 0;
453
+ throw error;
454
+ }
455
+ };
456
+ for (let attempt = 0; attempt < 2; attempt += 1) {
457
+ const existing = read();
458
+ if (existing?.key) {
459
+ brokerKeys.set(path, existing.key);
460
+ return existing.key;
461
+ }
462
+ if (existing)
463
+ throw new MachineAuthError(
464
+ "unsafe_storage",
465
+ `The machine broker key at ${path} is damaged. Delete it and retry.`,
466
+ true
467
+ );
468
+ const staged = `${path}.${process.pid}.${randomBytes3(6).toString("hex")}`;
469
+ try {
470
+ writeFileSync3(staged, `${randomBytes3(32).toString("hex")}
471
+ `, { mode: 384, flag: "wx" });
472
+ protectPath(staged, false);
473
+ linkSync(staged, path);
474
+ } catch (error) {
475
+ if (error.code !== "EEXIST") throw error;
476
+ } finally {
477
+ rmSync5(staged, { force: true });
478
+ }
479
+ }
480
+ const key = read()?.key;
481
+ if (!key)
482
+ throw new MachineAuthError("unsafe_storage", "The machine broker key is unreadable.", true);
483
+ brokerKeys.set(path, key);
484
+ return key;
485
+ }
381
486
  function environmentCredentials(deps) {
382
487
  const env = deps.env ?? process.env;
383
- const { PRIM_M2M_CLIENT_ID: clientId, PRIM_M2M_CLIENT_SECRET: clientSecret } = env;
384
- if (clientId === void 0 && clientSecret === void 0) return void 0;
488
+ const {
489
+ PRIM_M2M_CLIENT_ID: clientId,
490
+ PRIM_M2M_CLIENT_SECRET: clientSecret,
491
+ PRIM_M2M_CLIENT_AUTH: auth
492
+ } = env;
493
+ if (clientId === void 0 && clientSecret === void 0 && auth === void 0) return void 0;
494
+ if (auth !== void 0 && auth !== NETWORK_SECRET_AUTH && auth !== NETWORK_TOKEN_AUTH)
495
+ throw new MachineAuthError(
496
+ "incomplete_machine_credentials",
497
+ `PRIM_M2M_CLIENT_AUTH accepts ${NETWORK_SECRET_AUTH} or ${NETWORK_TOKEN_AUTH}.`
498
+ );
499
+ if (auth !== void 0) {
500
+ if (!clientId || !/^client_[\w-]+$/u.test(clientId))
501
+ throw new MachineAuthError(
502
+ "incomplete_machine_credentials",
503
+ `Set PRIM_M2M_CLIENT_ID with PRIM_M2M_CLIENT_AUTH=${auth}.`
504
+ );
505
+ if (clientSecret !== void 0)
506
+ throw new MachineAuthError(
507
+ "conflicting_credentials",
508
+ `Unset PRIM_M2M_CLIENT_SECRET: with PRIM_M2M_CLIENT_AUTH=${auth} the environment's network secret supplies it.`
509
+ );
510
+ const generation = hash(`${apiUrlFor(deps)}\0${clientId}\0${auth}\0broker-proxy`);
511
+ const credentials = {
512
+ clientId,
513
+ generation,
514
+ ...auth === NETWORK_TOKEN_AUTH ? { tokenInjection: "network" } : { secretInjection: "network" }
515
+ };
516
+ Object.defineProperty(credentials, "clientSecret", {
517
+ enumerable: true,
518
+ get: () => networkSecretBrokerKey(deps, clientId)
519
+ });
520
+ return credentials;
521
+ }
385
522
  if (!clientId || !clientSecret || !/^client_[\w-]+$/u.test(clientId) || !machineString(clientSecret)) {
386
523
  throw new MachineAuthError(
387
524
  "incomplete_machine_credentials",
@@ -396,7 +533,7 @@ function environmentCredentials(deps) {
396
533
  }
397
534
  function hasMachineConfiguration(deps = {}) {
398
535
  const env = deps.env ?? process.env;
399
- const configured = env.PRIM_M2M_CLIENT_ID !== void 0 || env.PRIM_M2M_CLIENT_SECRET !== void 0 || existsSync3(join6(configurationDirectory(deps), PROFILE_FILE));
536
+ 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));
400
537
  if (configured && env.PRIM_TOKEN?.trim()) {
401
538
  throw new MachineAuthError(
402
539
  "conflicting_credentials",
@@ -451,7 +588,7 @@ function readTrimmed(path) {
451
588
  function resolveAuthCredential(options = {}) {
452
589
  if (!options.tokenFilePath && hasMachineConfiguration({ env: options.env })) {
453
590
  const machine = cachedMachineCredential({ env: options.env });
454
- return machine ? { token: machine.accessToken, source: "machine" } : void 0;
591
+ return machine?.accessToken ? { token: machine.accessToken, source: "machine" } : void 0;
455
592
  }
456
593
  const envToken = (options.env ?? process.env).PRIM_TOKEN?.trim();
457
594
  if (envToken) return { token: envToken, source: "environment" };
@@ -567,7 +704,7 @@ function decodeJwtPayload(token) {
567
704
  }
568
705
 
569
706
  // src/daemon/client-instance-id.ts
570
- import { randomBytes as randomBytes3 } from "crypto";
707
+ import { randomBytes as randomBytes4 } from "crypto";
571
708
  import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync7 } from "fs";
572
709
  import { join as join8 } from "path";
573
710
  var INSTANCE_BODY_CHARS = 43;
@@ -691,7 +828,7 @@ var nextRequestId = 1;
691
828
  function daemonRequest(method, params = {}, opts = {}) {
692
829
  const id = nextRequestId++;
693
830
  const caller = resolveDaemonPrincipal();
694
- const request = {
831
+ const request2 = {
695
832
  id,
696
833
  method,
697
834
  params,
@@ -730,7 +867,7 @@ function daemonRequest(method, params = {}, opts = {}) {
730
867
  });
731
868
  socket.on("connect", () => {
732
869
  try {
733
- socket?.write(`${JSON.stringify(request)}
870
+ socket?.write(`${JSON.stringify(request2)}
734
871
  `);
735
872
  } catch {
736
873
  clearTimeout(timer);
@@ -776,9 +913,25 @@ function daemonRequest(method, params = {}, opts = {}) {
776
913
 
777
914
  // src/lib/activation.ts
778
915
  import { execFileSync as execFileSync4 } from "child_process";
779
- import { existsSync as existsSync5, readFileSync as readFileSync9 } from "fs";
916
+ import { existsSync as existsSync6, readFileSync as readFileSync11 } from "fs";
780
917
  import { homedir as homedir2 } from "os";
918
+ import { join as join13 } from "path";
919
+
920
+ // src/lib/cloud-prepared.ts
921
+ import { existsSync as existsSync5, mkdirSync as mkdirSync5, readFileSync as readFileSync9, rmSync as rmSync7, writeFileSync as writeFileSync4 } from "fs";
781
922
  import { join as join11 } from "path";
923
+ var CLOUD_PREPARED_MARKER = "cloud-prepared";
924
+ function cloudPreparedPath(env = process.env) {
925
+ return join11(primConfigDirectory({ env }), CLOUD_PREPARED_MARKER);
926
+ }
927
+ function isPreparedCloudSession(env = process.env) {
928
+ if (!isClaudeCloudSession(env)) return false;
929
+ try {
930
+ return existsSync5(cloudPreparedPath(env));
931
+ } catch {
932
+ return false;
933
+ }
934
+ }
782
935
 
783
936
  // src/lib/demo-pause.ts
784
937
  import { execFileSync as execFileSync2 } from "child_process";
@@ -844,11 +997,12 @@ function healDemoPause(cwd, pause, options = {}) {
844
997
  // src/lib/git.ts
845
998
  import { execFileSync as execFileSync3 } from "child_process";
846
999
  import { createHash as createHash7 } from "crypto";
847
- import { lstatSync as lstatSync5, realpathSync } from "fs";
848
- import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute3, relative, resolve as resolve2, sep } from "path";
1000
+ import { lstatSync as lstatSync5, readFileSync as readFileSync10, realpathSync } from "fs";
1001
+ import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute3, join as join12, relative, resolve as resolve2, sep } from "path";
849
1002
  var GIT_TIMEOUT_MS2 = 1e3;
1003
+ var MAX_SETTINGS_BYTES = 1024 * 1024;
850
1004
  var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
851
- var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
1005
+ var GITHUB_REPOSITORY_PATTERN = /^(?!\.{1,2}$)[A-Za-z0-9._-]{1,100}$/u;
852
1006
  function gitToplevel(cwd) {
853
1007
  try {
854
1008
  return execFileSync3("git", ["rev-parse", "--show-toplevel"], {
@@ -874,23 +1028,83 @@ function gitValue(cwd, args) {
874
1028
  return void 0;
875
1029
  }
876
1030
  }
877
- function githubRepositoryFullName(cwd) {
878
- const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
879
- if (!remote || [...remote].some((char) => char < " " || char === "\x7F")) return null;
1031
+ function parseGithubRepositoryName(path) {
1032
+ const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
1033
+ if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
1034
+ return null;
1035
+ }
1036
+ return `${parts[0]}/${parts[1]}`;
1037
+ }
1038
+ function githubRepositoryFromRemote(remote) {
1039
+ if ([...remote].some((char) => char < " " || char === "\x7F")) return null;
880
1040
  const match = /^(?:git@github\.com:([^?#]+)|(?:https|ssh):\/\/(?:[^/@]+@)?github\.com(?::\d+)?\/([^?#]+))$/i.exec(
881
1041
  remote
882
1042
  );
883
1043
  const path = match?.[1] ?? match?.[2];
884
- if (!path) return null;
885
- const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
886
- if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
1044
+ return path ? parseGithubRepositoryName(path) : null;
1045
+ }
1046
+ function checkoutSettingsText(repoRoot) {
1047
+ const path = join12(repoRoot, ".claude", "settings.json");
1048
+ try {
1049
+ if (!lstatSync5(join12(repoRoot, ".claude")).isDirectory()) return null;
1050
+ const stat = lstatSync5(path);
1051
+ if (!stat.isFile() || stat.size > MAX_SETTINGS_BYTES) return null;
1052
+ return readFileSync10(path, "utf8");
1053
+ } catch {
887
1054
  return null;
888
1055
  }
889
- return `${parts[0]}/${parts[1]}`;
1056
+ }
1057
+ function checkoutDeclaration(repoRoot, name) {
1058
+ const text = checkoutSettingsText(repoRoot);
1059
+ if (text === null) return null;
1060
+ let parsed;
1061
+ try {
1062
+ parsed = JSON.parse(text);
1063
+ } catch {
1064
+ return null;
1065
+ }
1066
+ const env = typeof parsed === "object" && parsed !== null ? parsed.env : void 0;
1067
+ const value = typeof env === "object" && env !== null ? env[name] : void 0;
1068
+ return typeof value === "string" ? value : null;
1069
+ }
1070
+ function declaredGithubRepository(repoRoot) {
1071
+ const value = checkoutDeclaration(repoRoot, "PRIM_REPOSITORY");
1072
+ return value === null ? null : parseGithubRepositoryName(value.trim());
1073
+ }
1074
+ function githubRepositoryFullName(cwd) {
1075
+ const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
1076
+ if (remote) {
1077
+ const fromOrigin = githubRepositoryFromRemote(remote);
1078
+ if (fromOrigin || normalizeOriginRemote(remote)) return fromOrigin;
1079
+ }
1080
+ const root = gitToplevel(cwd);
1081
+ return root ? declaredGithubRepository(root) : null;
1082
+ }
1083
+ function normalizeOriginRemote(remote) {
1084
+ const value = remote.trim();
1085
+ if (!value) return void 0;
1086
+ const scp = !value.includes("://") ? /^(?:[^@/\s]+@)?(?<host>[^:/\s]+):(?<path>.+)$/.exec(value)?.groups : void 0;
1087
+ if (scp?.host && scp.path) {
1088
+ const path = scp.path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
1089
+ return path ? `${scp.host.toLowerCase()}/${path}` : void 0;
1090
+ }
1091
+ try {
1092
+ const url = new URL(value);
1093
+ url.username = "";
1094
+ url.password = "";
1095
+ url.search = "";
1096
+ url.hash = "";
1097
+ const path = url.pathname.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
1098
+ if (url.host && path) return `${url.host.toLowerCase()}/${path}`;
1099
+ return void 0;
1100
+ } catch {
1101
+ return void 0;
1102
+ }
890
1103
  }
891
1104
 
892
1105
  // src/lib/activation.ts
893
1106
  var PRIM_ACTIVE_KEY = "prim.active";
1107
+ var PRIM_ACTIVE_DECLARATION = "PRIM_ACTIVE";
894
1108
  var PRIM_REPO_SYNC_ID_KEY = "prim.repoSyncId";
895
1109
  var PRIM_REPO_SYNC_REPOSITORY_KEY = "prim.repoSyncRepository";
896
1110
  var PRIM_REPO_BINDING_STATE_KEY = "prim.repoBindingState";
@@ -947,14 +1161,13 @@ function repositoryBindingState(cwd) {
947
1161
  if (marker !== void 0) return "invalid";
948
1162
  return rawId === void 0 ? "unbound" : repoSyncId(cwd) ? void 0 : "unbound";
949
1163
  }
950
- function hasProjectPrimInstall(cwd) {
951
- const root = gitToplevel(cwd);
1164
+ function projectPrimInstallAt(root) {
952
1165
  if (root === null || root === homedir2()) return false;
953
1166
  for (const rel of PROJECT_INSTALL_FILES) {
954
- const path = join11(root, rel);
955
- if (existsSync5(path)) {
1167
+ const path = join13(root, rel);
1168
+ if (existsSync6(path)) {
956
1169
  try {
957
- const content = readFileSync9(path, "utf-8");
1170
+ const content = readFileSync11(path, "utf-8");
958
1171
  if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
959
1172
  } catch {
960
1173
  }
@@ -962,12 +1175,27 @@ function hasProjectPrimInstall(cwd) {
962
1175
  }
963
1176
  return false;
964
1177
  }
1178
+ var UNPARSED_OPT_OUT = /"PRIM_ACTIVE"\s*:\s*"\s*false\s*"/u;
1179
+ function declaresInactiveAt(root) {
1180
+ if (root === null || root === homedir2()) return false;
1181
+ if (checkoutDeclaration(root, PRIM_ACTIVE_DECLARATION)?.trim() === "false") return true;
1182
+ const text = checkoutSettingsText(root);
1183
+ if (text === null || !UNPARSED_OPT_OUT.test(text)) return false;
1184
+ try {
1185
+ JSON.parse(text);
1186
+ return false;
1187
+ } catch {
1188
+ return true;
1189
+ }
1190
+ }
965
1191
  function isRepoActiveForCapture(cwd, options = {}) {
966
1192
  let { active: flag, pause } = readCaptureConfig(cwd);
967
1193
  if (pause && healDemoPause(cwd, pause, options)) flag = repoActiveFlag(cwd);
968
1194
  if (flag === "true") return true;
969
1195
  if (flag === "false") return false;
970
- return hasProjectPrimInstall(cwd);
1196
+ const root = gitToplevel(cwd);
1197
+ if (declaresInactiveAt(root)) return false;
1198
+ return projectPrimInstallAt(root) || isPreparedCloudSession() && root !== null;
971
1199
  }
972
1200
  function decisionIngestionStatus(cwd) {
973
1201
  return isRepoActiveForCapture(cwd) ? "enabled" : "disabled";
@@ -1112,7 +1340,7 @@ function readPackageVersion() {
1112
1340
  ];
1113
1341
  for (const path of candidates) {
1114
1342
  try {
1115
- const pkg = JSON.parse(readFileSync10(path, "utf-8"));
1343
+ const pkg = JSON.parse(readFileSync12(path, "utf-8"));
1116
1344
  if (pkg.version) {
1117
1345
  return pkg.version;
1118
1346
  }
@@ -1,32 +1,32 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  recordPostCommitFired
4
- } from "../chunk-BFYJLI7V.js";
4
+ } from "../chunk-F3FDVHR7.js";
5
5
  import {
6
6
  unattendedEnv
7
7
  } from "../chunk-OYHYCK4K.js";
8
8
  import {
9
9
  commitAttributionFromEnvironment,
10
10
  toCommitMove
11
- } from "../chunk-FYYHBOOM.js";
11
+ } from "../chunk-JCKOW45X.js";
12
12
  import {
13
13
  getOrCreateWorkspaceId
14
14
  } from "../chunk-EZXEWFDG.js";
15
15
  import {
16
16
  appendMove,
17
17
  resolveOrg
18
- } from "../chunk-NBNQI3YJ.js";
19
- import "../chunk-74DQDWLW.js";
18
+ } from "../chunk-O65UVJZH.js";
19
+ import "../chunk-R4EYLEIK.js";
20
20
  import {
21
21
  cachedCollectScopeAdmits
22
- } from "../chunk-O73J3KQQ.js";
23
- import "../chunk-ZKXNJB6U.js";
22
+ } from "../chunk-WGTUNUIS.js";
23
+ import "../chunk-NVDPKW7Z.js";
24
24
  import {
25
25
  githubRepositoryFullName,
26
26
  isRepoActiveForCapture,
27
27
  repoSyncId,
28
28
  resolveRepositoryContext
29
- } from "../chunk-NJBN3WXF.js";
29
+ } from "../chunk-HZI5PBN4.js";
30
30
  import "../chunk-JSBRDJBE.js";
31
31
 
32
32
  // src/hooks/post-commit.ts
@@ -5,25 +5,25 @@ import {
5
5
  import {
6
6
  canonicalRewritePairs,
7
7
  toRewriteMove
8
- } from "../chunk-FYYHBOOM.js";
8
+ } from "../chunk-JCKOW45X.js";
9
9
  import {
10
10
  getOrCreateWorkspaceId
11
11
  } from "../chunk-EZXEWFDG.js";
12
12
  import {
13
13
  appendMove,
14
14
  resolveOrg
15
- } from "../chunk-NBNQI3YJ.js";
16
- import "../chunk-74DQDWLW.js";
15
+ } from "../chunk-O65UVJZH.js";
16
+ import "../chunk-R4EYLEIK.js";
17
17
  import {
18
18
  cachedCollectScopeAdmits
19
- } from "../chunk-O73J3KQQ.js";
20
- import "../chunk-ZKXNJB6U.js";
19
+ } from "../chunk-WGTUNUIS.js";
20
+ import "../chunk-NVDPKW7Z.js";
21
21
  import {
22
22
  githubRepositoryFullName,
23
23
  isRepoActiveForCapture,
24
24
  repoSyncId,
25
25
  resolveRepositoryContext
26
- } from "../chunk-NJBN3WXF.js";
26
+ } from "../chunk-HZI5PBN4.js";
27
27
  import "../chunk-JSBRDJBE.js";
28
28
 
29
29
  // src/hooks/post-rewrite.ts
@@ -4,58 +4,58 @@ import {
4
4
  buildOrganizationBoundMoveRequest,
5
5
  parseOrganizationBinding,
6
6
  requireDurableIngestAcknowledgement
7
- } from "../chunk-TI37ME2D.js";
7
+ } from "../chunk-L6IL4N6Y.js";
8
8
  import {
9
9
  enrichHookPayloadWithFileRefs,
10
10
  preserveHookFileMetadata
11
- } from "../chunk-R35M4RCY.js";
11
+ } from "../chunk-RV3JFSMX.js";
12
12
  import {
13
13
  appendCodexContext,
14
14
  prepareCodexContext
15
- } from "../chunk-DT7E3SD5.js";
16
- import "../chunk-6KXQQ7CQ.js";
15
+ } from "../chunk-KFRGVHGB.js";
16
+ import "../chunk-URYZDQFH.js";
17
17
  import {
18
18
  postToolInvocationId,
19
19
  toMove,
20
20
  toolOutcomeFor
21
- } from "../chunk-FYYHBOOM.js";
21
+ } from "../chunk-JCKOW45X.js";
22
22
  import {
23
23
  getOrCreateWorkspaceId
24
24
  } from "../chunk-EZXEWFDG.js";
25
25
  import {
26
26
  appendMove,
27
27
  resolveOrg
28
- } from "../chunk-NBNQI3YJ.js";
29
- import "../chunk-YP4OXKNX.js";
28
+ } from "../chunk-O65UVJZH.js";
29
+ import "../chunk-H6X52UVF.js";
30
30
  import {
31
31
  observeDemoInvocation
32
- } from "../chunk-2BEUR3DU.js";
32
+ } from "../chunk-A5VTE43F.js";
33
33
  import {
34
34
  normalizeEnvelope,
35
35
  readHookStdin,
36
36
  shouldSuppressImportedCursorHandler
37
- } from "../chunk-ND6TYHNI.js";
38
- import "../chunk-HPA7RGSZ.js";
39
- import "../chunk-L32WYFJT.js";
37
+ } from "../chunk-H74RDXKP.js";
38
+ import "../chunk-MGKSZSTV.js";
39
+ import "../chunk-UUQT5GMO.js";
40
40
  import {
41
41
  scrubFromCwd
42
- } from "../chunk-74DQDWLW.js";
42
+ } from "../chunk-R4EYLEIK.js";
43
43
  import {
44
44
  bold,
45
45
  cachedCollectScopeAdmits,
46
46
  color
47
- } from "../chunk-O73J3KQQ.js";
47
+ } from "../chunk-WGTUNUIS.js";
48
48
  import {
49
49
  getClient,
50
50
  getPinnedClient,
51
51
  terminalSafeLine
52
- } from "../chunk-ZKXNJB6U.js";
52
+ } from "../chunk-NVDPKW7Z.js";
53
53
  import {
54
54
  currentBranch,
55
55
  isRepoActiveForCapture,
56
56
  repoSyncId,
57
57
  resolveRepositoryContext
58
- } from "../chunk-NJBN3WXF.js";
58
+ } from "../chunk-HZI5PBN4.js";
59
59
  import {
60
60
  parseAgent
61
61
  } from "../chunk-KZB4ABIB.js";
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  checkAffectedDecisions,
4
4
  formatDecisionsWarning
5
- } from "../chunk-EZXIKEMA.js";
6
- import "../chunk-YP4OXKNX.js";
7
- import "../chunk-ZKXNJB6U.js";
8
- import "../chunk-NJBN3WXF.js";
5
+ } from "../chunk-VVFVENU4.js";
6
+ import "../chunk-H6X52UVF.js";
7
+ import "../chunk-NVDPKW7Z.js";
8
+ import "../chunk-HZI5PBN4.js";
9
9
  import "../chunk-JSBRDJBE.js";
10
10
 
11
11
  // src/hooks/pre-commit.ts
@@ -3,6 +3,7 @@ import {
3
3
  PREFLIGHT_PROTOCOL_VERSION,
4
4
  PREFLIGHT_TIMEOUT_MS,
5
5
  boundedClientVersion,
6
+ coverageNote,
6
7
  editPreview,
7
8
  hasConfirmedConflict,
8
9
  proposalFor,
@@ -14,15 +15,15 @@ import {
14
15
  toolInputDigest,
15
16
  unverifiedResult,
16
17
  waitForPreflight
17
- } from "../chunk-6OPSSJHO.js";
18
+ } from "../chunk-C4QNBSWB.js";
18
19
  import {
19
20
  observeDemoInvocation
20
- } from "../chunk-2BEUR3DU.js";
21
+ } from "../chunk-A5VTE43F.js";
21
22
  import {
22
23
  normalizeEnvelope,
23
24
  readHookStdin,
24
25
  shouldSuppressImportedCursorHandler
25
- } from "../chunk-ND6TYHNI.js";
26
+ } from "../chunk-H74RDXKP.js";
26
27
  import {
27
28
  buildCodexOutput,
28
29
  buildCursorOutput,
@@ -34,21 +35,22 @@ import {
34
35
  failOpenHermes,
35
36
  failOpenOutput,
36
37
  readHookMode
37
- } from "../chunk-HPA7RGSZ.js";
38
- import "../chunk-L32WYFJT.js";
39
- import "../chunk-74DQDWLW.js";
38
+ } from "../chunk-MGKSZSTV.js";
39
+ import "../chunk-UUQT5GMO.js";
40
+ import "../chunk-R4EYLEIK.js";
40
41
  import {
41
42
  cachedCollectScopeAdmits
42
- } from "../chunk-O73J3KQQ.js";
43
- import "../chunk-ZKXNJB6U.js";
43
+ } from "../chunk-WGTUNUIS.js";
44
+ import "../chunk-NVDPKW7Z.js";
44
45
  import {
45
46
  canonicalGitRoot,
47
+ cloudSetupPointer,
46
48
  currentBranch,
47
49
  githubRepositoryFullName,
48
50
  packageVersion,
49
51
  repoActiveFlag,
50
52
  repoSyncId
51
- } from "../chunk-NJBN3WXF.js";
53
+ } from "../chunk-HZI5PBN4.js";
52
54
  import {
53
55
  parseAgent
54
56
  } from "../chunk-KZB4ABIB.js";
@@ -186,7 +188,7 @@ async function main() {
186
188
  const callId = invocationId(envelope);
187
189
  if (!binding || typeof sessionId !== "string" || !sessionId || !callId) {
188
190
  await unverified(
189
- !binding ? "GitHub repo connection is required" : "Session or tool identity is missing"
191
+ !binding ? cloudSetupPointer("GitHub repo connection is required") : "Session or tool identity is missing"
190
192
  );
191
193
  return;
192
194
  }
@@ -236,15 +238,12 @@ async function main() {
236
238
  if (result2.verdict === "unavailable") {
237
239
  result2.unavailable = `${result2.unavailable || "Decision check is unavailable"}; change was not verified.`;
238
240
  }
239
- const coverage = response.evaluationCoverage;
240
241
  const notes = [
241
242
  ...targets.coverage === "unverified" ? [
242
243
  "[primitive] Some mutation targets could not be resolved; the complete change was not verified."
243
244
  ] : [],
244
- ...coverage && (coverage.status !== "completed" || coverage.selectionOmissions?.length || coverage.evidenceOmissions?.length) ? [
245
- "[primitive] Decision coverage is incomplete; some candidates or evidence were not evaluated."
246
- ] : []
247
- ];
245
+ coverageNote(response)
246
+ ].filter(Boolean);
248
247
  if (notes.length > 0) {
249
248
  const note = notes.join("\n");
250
249
  result2.reason = [result2.reason, note].filter(Boolean).join("\n");