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

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 +211 -1
  2. package/SKILL.md +6 -1
  3. package/dist/{chunk-ZKXNJB6U.js → chunk-3KPTVK4N.js} +70 -78
  4. package/dist/{chunk-6KXQQ7CQ.js → chunk-4DYEBYKM.js} +3 -5
  5. package/dist/{chunk-NJBN3WXF.js → chunk-6QAXVFRJ.js} +1900 -179
  6. package/dist/{chunk-R6NDP7OF.js → chunk-ANMNGGTN.js} +2 -2
  7. package/dist/{chunk-PPZ56EVJ.js → chunk-B3ICJZXV.js} +4 -2
  8. package/dist/{chunk-5D2C6RCH.js → chunk-C357P37M.js} +4 -4
  9. package/dist/{chunk-DT7E3SD5.js → chunk-E57UVUJL.js} +6 -6
  10. package/dist/{chunk-KKUDAQQZ.js → chunk-EQWUCFXK.js} +3 -3
  11. package/dist/{chunk-JFWJN2ME.js → chunk-M6KIDB5R.js} +119 -5
  12. package/dist/{chunk-NBNQI3YJ.js → chunk-N6PZE7HX.js} +6 -3
  13. package/dist/{chunk-O73J3KQQ.js → chunk-NYDM4HSS.js} +8 -5
  14. package/dist/{chunk-74DQDWLW.js → chunk-P4O7L7JZ.js} +7 -2
  15. package/dist/{chunk-L32WYFJT.js → chunk-PRJ7P6J5.js} +135 -12
  16. package/dist/{chunk-ND6TYHNI.js → chunk-PTZ6BWSU.js} +2 -2
  17. package/dist/{chunk-BFYJLI7V.js → chunk-QQ3G5SXX.js} +1 -1
  18. package/dist/{chunk-EZXIKEMA.js → chunk-RDT2IV2Z.js} +9 -7
  19. package/dist/{chunk-TI37ME2D.js → chunk-VLT2KGPE.js} +47 -38
  20. package/dist/{chunk-YP4OXKNX.js → chunk-WEGZGF3K.js} +1 -1
  21. package/dist/{chunk-C5VBPHOS.js → chunk-XINFTNA2.js} +23 -9
  22. package/dist/{chunk-FYYHBOOM.js → chunk-ZCT23NBS.js} +2 -2
  23. package/dist/daemon/server.js +1976 -442
  24. package/dist/hook-runtime/daemon/server.js +1976 -442
  25. package/dist/hook-runtime/hooks/post-commit.js +592 -212
  26. package/dist/hook-runtime/hooks/post-rewrite.js +584 -204
  27. package/dist/hook-runtime/hooks/post-tool-use.js +1997 -575
  28. package/dist/hook-runtime/hooks/pre-commit.js +1742 -350
  29. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +1656 -261
  30. package/dist/hook-runtime/hooks/prim-hook.js +1992 -573
  31. package/dist/hook-runtime/hooks/session-end.js +549 -180
  32. package/dist/hook-runtime/hooks/session-start.js +2213 -596
  33. package/dist/hook-runtime/index.js +5318 -2423
  34. package/dist/hook-runtime/statusline-main.js +531 -150
  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 +18 -18
  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 +95 -21
  43. package/dist/index.js +1386 -299
  44. package/dist/statusline-main.js +531 -150
  45. package/package.json +1 -1
@@ -11,10 +11,10 @@ import {
11
11
  saveRun,
12
12
  sessionExcluded,
13
13
  sessionKey
14
- } from "./chunk-KKUDAQQZ.js";
14
+ } from "./chunk-EQWUCFXK.js";
15
15
  import {
16
16
  packageVersion
17
- } from "./chunk-NJBN3WXF.js";
17
+ } from "./chunk-6QAXVFRJ.js";
18
18
 
19
19
  // src/demo/isolation.ts
20
20
  import { existsSync } from "fs";
@@ -1,9 +1,11 @@
1
1
  import {
2
- getClient,
2
+ getClient
3
+ } from "./chunk-3KPTVK4N.js";
4
+ import {
3
5
  isTerminalSafeText,
4
6
  terminalSafeLine,
5
7
  terminalSafeText
6
- } from "./chunk-ZKXNJB6U.js";
8
+ } from "./chunk-6QAXVFRJ.js";
7
9
 
8
10
  // src/decisions/feedback.ts
9
11
  var FEEDBACK_PROTOCOL_VERSION = 2;
@@ -4,20 +4,20 @@ import {
4
4
  import {
5
5
  analyzeShellTargets,
6
6
  extractFileTargets
7
- } from "./chunk-KKUDAQQZ.js";
7
+ } from "./chunk-EQWUCFXK.js";
8
8
  import {
9
9
  scrubEnvironmentPaths
10
- } from "./chunk-74DQDWLW.js";
10
+ } from "./chunk-P4O7L7JZ.js";
11
11
  import {
12
12
  cachedCollectScopeAdmits
13
- } from "./chunk-O73J3KQQ.js";
13
+ } from "./chunk-NYDM4HSS.js";
14
14
  import {
15
15
  canonicalRepositoryPath,
16
16
  currentBranch,
17
17
  isRepoActiveForCapture,
18
18
  relatedWorktreeTarget,
19
19
  repoSyncId
20
- } from "./chunk-NJBN3WXF.js";
20
+ } from "./chunk-6QAXVFRJ.js";
21
21
 
22
22
  // src/hooks/file-refs.ts
23
23
  var MAX_PREFLIGHT_FILE_TARGETS = 25;
@@ -1,24 +1,24 @@
1
1
  import {
2
2
  formatStatusline
3
- } from "./chunk-6KXQQ7CQ.js";
3
+ } from "./chunk-4DYEBYKM.js";
4
4
  import {
5
5
  daemonPrincipalsMatch,
6
6
  daemonRequest,
7
7
  resolveDaemonPrincipal
8
- } from "./chunk-YP4OXKNX.js";
8
+ } from "./chunk-WEGZGF3K.js";
9
9
  import {
10
10
  getSiteUrl,
11
- isSessionEnded,
12
- terminalSafeText
13
- } from "./chunk-ZKXNJB6U.js";
11
+ isSessionEnded
12
+ } from "./chunk-3KPTVK4N.js";
14
13
  import {
15
14
  decisionIngestionStatus,
16
15
  gitToplevel,
17
16
  packageVersion,
18
17
  primConfigDirectory,
19
18
  repositoryBindingState,
19
+ terminalSafeText,
20
20
  withFileLock
21
- } from "./chunk-NJBN3WXF.js";
21
+ } from "./chunk-6QAXVFRJ.js";
22
22
 
23
23
  // src/hooks/codex-context.ts
24
24
  import { createHash, randomBytes as randomBytes2 } from "crypto";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  inspectHookRuntime
3
- } from "./chunk-L32WYFJT.js";
3
+ } from "./chunk-PRJ7P6J5.js";
4
4
  import {
5
5
  isDemoStatusResponse
6
- } from "./chunk-O73J3KQQ.js";
6
+ } from "./chunk-NYDM4HSS.js";
7
7
  import {
8
8
  atomicWriteFile,
9
9
  primConfigDirectory,
10
10
  withFileLock,
11
11
  withFileLockSync
12
- } from "./chunk-NJBN3WXF.js";
12
+ } from "./chunk-6QAXVFRJ.js";
13
13
 
14
14
  // src/hooks/pre-tool-use-scoring.ts
15
15
  import { isAbsolute, relative, sep } from "path";
@@ -9,25 +9,35 @@ import {
9
9
  hookBlockContractVersion,
10
10
  inspectGitHookEntrypoint,
11
11
  managedHookBlock
12
- } from "./chunk-L32WYFJT.js";
12
+ } from "./chunk-PRJ7P6J5.js";
13
13
  import {
14
14
  HttpError,
15
- getClient
16
- } from "./chunk-ZKXNJB6U.js";
15
+ getClient,
16
+ getSiteUrl
17
+ } from "./chunk-3KPTVK4N.js";
17
18
  import {
19
+ CLOUD_CREDENTIALS_REMEDY,
20
+ CLOUD_REJECTED_CREDENTIALS_NOTICE,
21
+ MachineAuthError,
22
+ NETWORK_TOKEN_AUTH,
18
23
  atomicWriteFile,
19
24
  binFile,
20
25
  compareSemver,
21
26
  gitToplevel,
22
27
  githubRepositoryFullName,
28
+ hasMachineConfiguration,
29
+ isClaudeCloudSession,
23
30
  isValidRepoSyncId,
31
+ machineApiUrl,
32
+ originIdentifiesRepository,
24
33
  pinnedHookCommand,
25
34
  pinnedNpxCommand,
26
35
  primConfigDirectory,
36
+ resolveStoredCredential,
27
37
  setRepoSyncId,
28
38
  setRepositoryBindingState,
29
39
  withFileLock
30
- } from "./chunk-NJBN3WXF.js";
40
+ } from "./chunk-6QAXVFRJ.js";
31
41
 
32
42
  // src/commands/skill.ts
33
43
  import { createHash as createHash3 } from "crypto";
@@ -790,6 +800,103 @@ function registerSkillCommands(program) {
790
800
  });
791
801
  }
792
802
 
803
+ // src/lib/cloud-session.ts
804
+ function isCloudMachineSession(env = process.env) {
805
+ if (!isClaudeCloudSession(env)) return false;
806
+ try {
807
+ return hasMachineConfiguration({ env });
808
+ } catch {
809
+ return true;
810
+ }
811
+ }
812
+ var PRODUCTION_SIGN_IN_HOST = "signin.getprimitive.ai";
813
+ var PROBE_TIMEOUT_MS = 3e3;
814
+ function repositoryIdentityRemedy(root) {
815
+ return originIdentifiesRepository(root) ? "this checkout's origin is not a GitHub repository in owner/name form; Primitive connects GitHub repositories only" : "this checkout does not identify its GitHub repository. Commit the repository declaration: run `prim claude install --scope project` in a clone whose origin is on GitHub, which records PRIM_REPOSITORY in .claude/settings.json";
816
+ }
817
+ function hostOf(url, fallback) {
818
+ try {
819
+ return new URL(url).hostname || fallback;
820
+ } catch {
821
+ return fallback;
822
+ }
823
+ }
824
+ function cloudAllowedDomains(siteUrl = getSiteUrl(), signInHost = PRODUCTION_SIGN_IN_HOST, env = process.env) {
825
+ const api = hostOf(siteUrl, "api.getprimitive.ai");
826
+ return env.PRIM_M2M_CLIENT_AUTH === NETWORK_TOKEN_AUTH ? [api] : [.../* @__PURE__ */ new Set([api, signInHost])];
827
+ }
828
+ function cloudEgressRemedy(siteUrl, signInHost, env) {
829
+ return `add ${cloudAllowedDomains(siteUrl, signInHost, env).join(" and ")} to the cloud environment's Allowed domains (Network access: Limited), then start a new cloud session (a running session keeps the network rules it started with)`;
830
+ }
831
+ function probeFailure(error) {
832
+ const name = error instanceof Error ? error.name : "";
833
+ if (name === "TimeoutError" || name === "AbortError") return "timeout";
834
+ const cause = error?.cause;
835
+ const code = typeof cause?.code === "string" ? cause.code : "";
836
+ const message = typeof cause?.message === "string" ? cause.message : "";
837
+ if (code === "ENOTFOUND" || code === "EAI_AGAIN") return "blocked";
838
+ if (/cancel|tunnel|\(403\)/iu.test(message) && !/\(5\d\d\)/u.test(message)) return "blocked";
839
+ return code || "network error";
840
+ }
841
+ async function probe(url, fetchImpl) {
842
+ try {
843
+ const response = await fetchImpl(url, {
844
+ redirect: "manual",
845
+ signal: AbortSignal.timeout(PROBE_TIMEOUT_MS)
846
+ });
847
+ return { ok: true, response };
848
+ } catch (error) {
849
+ return { ok: false, failure: probeFailure(error) };
850
+ }
851
+ }
852
+ function unreachable(what, failure, remedy) {
853
+ if (failure === "blocked") return `this environment cannot reach ${what}. To fix it, ${remedy}.`;
854
+ if (failure === "timeout")
855
+ return `${what} did not answer in time. If this persists, check that you ${remedy.replace(/^add /u, "added ")}.`;
856
+ return `${what} could not be reached (${failure}). Check the environment's network access: ${remedy}.`;
857
+ }
858
+ function credentialRejected(error) {
859
+ return error instanceof HttpError && error.status === 401;
860
+ }
861
+ async function diagnoseCloudSession(options = {}) {
862
+ const env = options.env ?? process.env;
863
+ if (!isClaudeCloudSession(env)) return void 0;
864
+ const prefix = "Primitive is not connected in this Claude Code cloud session";
865
+ let machine;
866
+ try {
867
+ machine = hasMachineConfiguration({ env });
868
+ } catch (error) {
869
+ if (error instanceof MachineAuthError && (error.code === "conflicting_credentials" || env.PRIM_M2M_CLIENT_AUTH !== void 0))
870
+ return `${prefix}: ${error.message}`;
871
+ return `${prefix}: ${error instanceof MachineAuthError ? error.message : "its machine credentials are incomplete."} To fix it, ${CLOUD_CREDENTIALS_REMEDY}.`;
872
+ }
873
+ if (!machine && !resolveStoredCredential(env))
874
+ return `${prefix}: it has no credentials. To fix it, ${CLOUD_CREDENTIALS_REMEDY}.`;
875
+ if (machine && credentialRejected(options.bindFailure)) return CLOUD_REJECTED_CREDENTIALS_NOTICE;
876
+ if (options.cwd !== void 0 && !githubRepositoryFullName(options.cwd))
877
+ return `${prefix}: ${repositoryIdentityRemedy(options.cwd)}.`;
878
+ const fetchImpl = options.fetch ?? fetch;
879
+ const siteUrl = options.siteUrl ?? getSiteUrl();
880
+ const config = await probe(`${siteUrl.replace(/\/+$/u, "")}/api/cli/auth/m2m/config`, fetchImpl);
881
+ if (!config.ok)
882
+ return `${prefix}: ${unreachable("Primitive", config.failure, cloudEgressRemedy(siteUrl, void 0, env))}`;
883
+ if (machine && env.PRIM_M2M_CLIENT_AUTH !== NETWORK_TOKEN_AUTH) {
884
+ let issuer;
885
+ try {
886
+ const body = await config.response.json();
887
+ issuer = typeof body.issuer === "string" ? machineApiUrl(body.issuer) : void 0;
888
+ } catch {
889
+ issuer = void 0;
890
+ }
891
+ if (issuer) {
892
+ const signIn = await probe(issuer, fetchImpl);
893
+ if (!signIn.ok)
894
+ return `${prefix}: ${unreachable("Primitive's sign-in service", signIn.failure, cloudEgressRemedy(siteUrl, hostOf(issuer, PRODUCTION_SIGN_IN_HOST)))}`;
895
+ }
896
+ }
897
+ return `${prefix}: the repository could not be connected. Run \`prim setup --cloud\` for details.`;
898
+ }
899
+
793
900
  // src/lib/bin-cache.ts
794
901
  import { chmodSync, mkdirSync as mkdirSync2 } from "fs";
795
902
  import { homedir as homedir4 } from "os";
@@ -1881,7 +1988,9 @@ var InvalidRepositoryBindingResponseError = class extends Error {
1881
1988
  async function resolveRepositoryBindingWithClient(root, client, options) {
1882
1989
  const repositoryFullName = githubRepositoryFullName(root);
1883
1990
  if (!repositoryFullName) {
1884
- throw new Error("origin must be a GitHub HTTPS/SSH remote in owner/name form");
1991
+ throw new Error(
1992
+ originIdentifiesRepository(root) ? "origin must be a GitHub HTTPS/SSH remote in owner/name form" : "origin does not identify this checkout's repository; commit its repository declaration (`prim claude install --scope project`, run in a clone whose origin is on GitHub, records PRIM_REPOSITORY in .claude/settings.json)"
1993
+ );
1885
1994
  }
1886
1995
  let response;
1887
1996
  try {
@@ -1963,6 +2072,11 @@ function kickDaemonEnsure(options = {}) {
1963
2072
  }
1964
2073
 
1965
2074
  export {
2075
+ isCloudMachineSession,
2076
+ repositoryIdentityRemedy,
2077
+ cloudAllowedDomains,
2078
+ cloudEgressRemedy,
2079
+ diagnoseCloudSession,
1966
2080
  warmBinCache,
1967
2081
  isLegacyOwnedGlobalHook,
1968
2082
  gitHooksMode,
@@ -1,17 +1,19 @@
1
1
  import {
2
2
  getSiteUrl
3
- } from "./chunk-ZKXNJB6U.js";
3
+ } from "./chunk-3KPTVK4N.js";
4
4
  import {
5
5
  atomicWriteFile,
6
6
  ensureDurableDirectory,
7
7
  hasMachineConfiguration,
8
+ identityPending,
8
9
  jwtOrganizationId,
9
10
  machineCaptureActor,
10
11
  machineContext,
11
12
  machineJournalBucket,
13
+ machinePendingBucket,
12
14
  primConfigDirectory,
13
15
  resolveAuthCredential
14
- } from "./chunk-NJBN3WXF.js";
16
+ } from "./chunk-6QAXVFRJ.js";
15
17
 
16
18
  // src/journal.ts
17
19
  import {
@@ -155,7 +157,8 @@ function journalPath(orgId) {
155
157
  function appendMove(move, orgId) {
156
158
  const actor = machineCaptureActor();
157
159
  const captured = actor ? { ...move, captureActor: actor } : move;
158
- appendMoveToPath(journalPath(actor ? machineJournalBucket(actor) : orgId), captured);
160
+ const bucket = actor ? identityPending(actor) ? machinePendingBucket(actor) : machineJournalBucket(actor) : orgId;
161
+ appendMoveToPath(journalPath(bucket), captured);
159
162
  return captured;
160
163
  }
161
164
  function parseMoves(content) {
@@ -1,11 +1,11 @@
1
1
  import {
2
- getClient,
3
- terminalSafeLine
4
- } from "./chunk-ZKXNJB6U.js";
2
+ getClient
3
+ } from "./chunk-3KPTVK4N.js";
5
4
  import {
6
5
  localGitConfigValue,
7
- setLocalGitConfigValue
8
- } from "./chunk-NJBN3WXF.js";
6
+ setLocalGitConfigValue,
7
+ terminalSafeLine
8
+ } from "./chunk-6QAXVFRJ.js";
9
9
  import {
10
10
  __commonJS,
11
11
  __toESM
@@ -27199,6 +27199,9 @@ export {
27199
27199
  isPreflightResponseV4,
27200
27200
  isReconcileResolutionResponse,
27201
27201
  isGitHubInstallIntentStatusResponse,
27202
+ MAX_SCOPE_GLOB_CHARS,
27203
+ isScopeGlobPattern,
27204
+ isScopeDirectoryPrefix,
27202
27205
  cachedCollectScopeAdmits,
27203
27206
  fetchAndCacheCollectScope,
27204
27207
  scheduleCollectScopeRefresh,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  boundedHealthError
3
- } from "./chunk-O73J3KQQ.js";
3
+ } from "./chunk-NYDM4HSS.js";
4
4
  import {
5
5
  terminalSafeLine
6
- } from "./chunk-ZKXNJB6U.js";
6
+ } from "./chunk-6QAXVFRJ.js";
7
7
 
8
8
  // src/hooks/redact.ts
9
9
  import { existsSync, readFileSync, statSync } from "fs";
@@ -51,6 +51,11 @@ var DEFAULT_RULES = [
51
51
  pattern: /\bAWS_(?:SECRET_ACCESS_KEY|SESSION_TOKEN)"?\s*[:=]\s*["']?[A-Za-z0-9/+=]{20,}["']?/gi,
52
52
  reason: "aws-secret"
53
53
  },
54
+ {
55
+ // `prim auth enroll --print-env` output an agent may write into a file.
56
+ pattern: /\bPRIM_M2M_CLIENT_SECRET"?\s*[:=]\s*["']?[^\s"']+["']?/g,
57
+ reason: "prim-m2m-secret"
58
+ },
54
59
  { pattern: /\bAIza[0-9A-Za-z_-]{35}(?![0-9A-Za-z_-])/g, reason: "gcp-api-key" },
55
60
  {
56
61
  pattern: /\bya29\.[0-9A-Za-z_-]{20,}(?![0-9A-Za-z_-])/g,
@@ -1,25 +1,30 @@
1
1
  import {
2
+ PRIM_ACTIVE_DECLARATION,
2
3
  PRIM_CONFIG_SHELL_RESOLVER,
3
4
  STABLE_HOOK_LAUNCHER_NAME,
4
5
  atomicWriteFile,
6
+ clearCloudPrepared,
5
7
  commandMatchesBin,
6
8
  compareSemver,
7
9
  detachedHookShimCommand,
8
10
  gitToplevel,
9
11
  hookCommandResolution,
10
12
  hookCommandResolutions,
13
+ originGithubRepository,
11
14
  packageRoot,
12
15
  packageVersion,
16
+ parseGithubRepositoryName,
13
17
  primConfigDirectory,
18
+ quietWithoutLauncher,
14
19
  shellQuote,
15
20
  stableHookCommand,
16
21
  syncDirectory,
17
22
  syncFile,
18
23
  withFileLockSync
19
- } from "./chunk-NJBN3WXF.js";
24
+ } from "./chunk-6QAXVFRJ.js";
20
25
 
21
26
  // src/commands/claude-install.ts
22
- import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
27
+ import { existsSync as existsSync3, lstatSync as lstatSync2, readFileSync as readFileSync2 } from "fs";
23
28
  import { homedir } from "os";
24
29
  import { join as join3 } from "path";
25
30
 
@@ -893,6 +898,7 @@ var USER_SCOPE_PATH = join3(homedir(), ".claude", "settings.json");
893
898
  function projectRoot() {
894
899
  return gitToplevel() ?? process.cwd();
895
900
  }
901
+ var PRIM_REPOSITORY_ENV = "PRIM_REPOSITORY";
896
902
  var projectScopePath = () => join3(projectRoot(), ".claude", "settings.json");
897
903
  var CAPTURE_EVENTS = [
898
904
  "SessionStart",
@@ -930,6 +936,20 @@ var REGISTRATIONS = [
930
936
  makeRegistration("SessionStart", "*", SESSION_START_BIN),
931
937
  makeDetachedRegistration("SessionEnd", "*", SESSION_END_BIN)
932
938
  ];
939
+ var PROJECT_DEFERRAL_PREFIX = 'prim_project="$CLAUDE_PROJECT_DIR/.claude/settings.json"; [ -f "$prim_project" ] && [ "$(cd -- "$CLAUDE_PROJECT_DIR" 2>/dev/null && pwd -P)" != "$(cd -- "${HOME:-/}" 2>/dev/null && pwd -P)" ] &&';
940
+ function deferToProjectInstall(command, bin) {
941
+ if (!/^[a-z-]+$/u.test(bin)) throw new Error(`unexpected hook bin ${bin}`);
942
+ const trimmed = command.trimEnd();
943
+ const body = trimmed.endsWith("&") ? `{ ${trimmed} }` : `{ ${trimmed}; }`;
944
+ return `${PROJECT_DEFERRAL_PREFIX} grep -qsE -- "(^|[[:space:]\\"])${bin}([[:space:]\\"]|\\$)" "$prim_project" || ${body}`;
945
+ }
946
+ function usesProjectDeferral(settings) {
947
+ return Object.values(settings.hooks ?? {}).some(
948
+ (entries) => (entries ?? []).some(
949
+ (entry) => (entry.hooks ?? []).some((hook) => hook.command?.startsWith(PROJECT_DEFERRAL_PREFIX))
950
+ )
951
+ );
952
+ }
933
953
  var PRIM_PERMISSION_RULE = "Bash(npx --yes @primitive.ai/prim*)";
934
954
  var LEGACY_PRIM_PERMISSION_RULES = [
935
955
  "Bash(npx --yes @primitive.ai/prim@latest:*)",
@@ -968,7 +988,9 @@ function hasAnyHookRegistration(settings) {
968
988
  return ownedRegistrationEntries(settings).length > 0;
969
989
  }
970
990
  function entryMatchesRegistration(owned, registration) {
971
- return owned.event === registration.event && owned.entry.matcher === registration.matcher && owned.entry.hooks?.length === 1 && owned.entry.hooks[0].type === "command" && owned.entry.hooks[0].command === registration.command && owned.entry.hooks[0].timeout === registration.timeout && owned.entry.hooks[0].onFailure === registration.onFailure && (registration.bin !== GATE_BIN || owned.entry.hooks[0].async !== true);
991
+ return owned.event === registration.event && owned.entry.matcher === registration.matcher && owned.entry.hooks?.length === 1 && owned.entry.hooks[0].type === "command" && // A project install is complete in either text: plain, as releases wrote
992
+ // it before a project install went quiet without a launcher, or quiet.
993
+ (owned.entry.hooks[0].command === registration.command || owned.entry.hooks[0].command === quietWithoutLauncher(registration.command) || owned.entry.hooks[0].command === deferToProjectInstall(registration.command, registration.bin)) && owned.entry.hooks[0].timeout === registration.timeout && owned.entry.hooks[0].onFailure === registration.onFailure && (registration.bin !== GATE_BIN || owned.entry.hooks[0].async !== true);
972
994
  }
973
995
  function hasCompleteHookRegistration(settings) {
974
996
  const owned = ownedRegistrationEntries(settings);
@@ -1106,9 +1128,76 @@ function removeAutoModeTrust(settings) {
1106
1128
  const hasOther = Object.values(nextAutoMode).some((v) => v !== void 0);
1107
1129
  return { ...settings, autoMode: hasOther ? nextAutoMode : void 0 };
1108
1130
  }
1131
+ function applyRepositoryDeclaration(settings, repository, force = false) {
1132
+ if (!repository) return settings;
1133
+ const env = isPlainObject(settings.env) ? settings.env : {};
1134
+ const existing = env[PRIM_REPOSITORY_ENV];
1135
+ if (existing === repository) return settings;
1136
+ if (!force && typeof existing === "string" && parseGithubRepositoryName(existing.trim()))
1137
+ return settings;
1138
+ return { ...settings, env: { ...env, [PRIM_REPOSITORY_ENV]: repository } };
1139
+ }
1140
+ function removeRepositoryDeclaration(settings, repository) {
1141
+ if (!repository || !isPlainObject(settings.env)) return settings;
1142
+ if (settings.env[PRIM_REPOSITORY_ENV] !== repository) return settings;
1143
+ const { [PRIM_REPOSITORY_ENV]: _removed, ...env } = settings.env;
1144
+ return { ...settings, env: Object.keys(env).length > 0 ? env : void 0 };
1145
+ }
1146
+ function applyInactiveDeclaration(settings, inactive) {
1147
+ const env = isPlainObject(settings.env) ? settings.env : {};
1148
+ const existing = env[PRIM_ACTIVE_DECLARATION];
1149
+ const declared = typeof existing === "string" && existing.trim() === "false";
1150
+ if (inactive)
1151
+ return declared ? settings : { ...settings, env: { ...env, [PRIM_ACTIVE_DECLARATION]: "false" } };
1152
+ if (!declared) return settings;
1153
+ const { [PRIM_ACTIVE_DECLARATION]: _removed, ...rest } = env;
1154
+ return { ...settings, env: Object.keys(rest).length > 0 ? rest : void 0 };
1155
+ }
1156
+ function planProjectInactiveDeclaration(root, inactive) {
1157
+ if (root === homedir())
1158
+ throw new Error(
1159
+ "this repository's root is your home directory, whose .claude/settings.json is your user settings; it cannot carry a repository opt-out"
1160
+ );
1161
+ const directory = join3(root, ".claude");
1162
+ const path = join3(directory, "settings.json");
1163
+ const kind = (target) => {
1164
+ try {
1165
+ return lstatSync2(target);
1166
+ } catch (error) {
1167
+ if (error.code === "ENOENT") return void 0;
1168
+ throw error;
1169
+ }
1170
+ };
1171
+ const directoryStat = kind(directory);
1172
+ const fileStat = kind(path);
1173
+ if (directoryStat && !directoryStat.isDirectory() || fileStat && !fileStat.isFile())
1174
+ throw new Error(
1175
+ `${path} must be a regular file in a real .claude directory (not a symbolic link) to carry the repository's opt-out`
1176
+ );
1177
+ const before = readSettings(path);
1178
+ const after = applyInactiveDeclaration(before, inactive);
1179
+ const changed = JSON.stringify(before) !== JSON.stringify(after);
1180
+ return {
1181
+ path,
1182
+ changed,
1183
+ apply: () => {
1184
+ if (changed) atomicWrite(path, after);
1185
+ }
1186
+ };
1187
+ }
1188
+ function projectSettingsAfterInstall(settings, root, force = false) {
1189
+ return applyRepositoryDeclaration(settings, originGithubRepository(root), force);
1190
+ }
1191
+ function projectSettingsAfterUninstall(settings, root) {
1192
+ return removeRepositoryDeclaration(settings, originGithubRepository(root));
1193
+ }
1194
+ function isPlainObject(value) {
1195
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1196
+ }
1109
1197
  function applyInstall(settings, options = {}) {
1110
1198
  const hooks = { ...settings.hooks ?? {} };
1111
- for (const reg of REGISTRATIONS) {
1199
+ for (const registration of REGISTRATIONS) {
1200
+ const reg = options.wrapCommand ? { ...registration, command: options.wrapCommand(registration.command, registration.bin) } : registration;
1112
1201
  hooks[reg.event] = ensureRegistration(hooks[reg.event] ?? [], reg, options.force ?? false);
1113
1202
  }
1114
1203
  return applyPermissions(
@@ -1130,7 +1219,7 @@ function applyUninstall(settings) {
1130
1219
  hooks[event] = list;
1131
1220
  }
1132
1221
  }
1133
- const next = { ...settings, hooks };
1222
+ const next = settings.hooks === void 0 ? { ...settings } : { ...settings, hooks };
1134
1223
  if (isPrimStatusLine(next)) {
1135
1224
  next.statusLine = void 0;
1136
1225
  }
@@ -1171,19 +1260,24 @@ function atomicWrite(path, content) {
1171
1260
  function userStatuslineBlocksProjectInstall(scope, userSettings) {
1172
1261
  return scope === "project" && statuslineState(userSettings) === "custom";
1173
1262
  }
1174
- function performInstall(scope, force) {
1263
+ function performInstall(scope, force, options = {}) {
1175
1264
  stageHookRuntime();
1176
1265
  const path = settingsPathFor(scope);
1177
1266
  const before = readSettings(path);
1267
+ const cloud = scope === "user" && (options.cloud === true || usesProjectDeferral(before));
1178
1268
  const blockedByUserStatusline = userStatuslineBlocksProjectInstall(
1179
1269
  scope,
1180
1270
  scope === "project" ? readSettings(USER_SCOPE_PATH) : {}
1181
1271
  );
1182
- const after = applyInstall(before, {
1272
+ const committed = scope === "project";
1273
+ const installed = applyInstall(before, {
1183
1274
  force,
1184
- statuslineCommand: STATUSLINE_COMMAND,
1185
- installStatusline: !blockedByUserStatusline
1275
+ statuslineCommand: committed ? quietWithoutLauncher(STATUSLINE_COMMAND) : STATUSLINE_COMMAND,
1276
+ // Cloud sessions have no terminal footer to render a statusline.
1277
+ installStatusline: !blockedByUserStatusline && !cloud,
1278
+ wrapCommand: cloud ? deferToProjectInstall : committed ? quietWithoutLauncher : void 0
1186
1279
  });
1280
+ const after = scope === "project" ? projectSettingsAfterInstall(installed, projectRoot(), force) : installed;
1187
1281
  const changed = JSON.stringify(before) !== JSON.stringify(after);
1188
1282
  if (changed) {
1189
1283
  atomicWrite(path, after);
@@ -1199,10 +1293,32 @@ function performInstall(scope, force) {
1199
1293
  changed
1200
1294
  };
1201
1295
  }
1296
+ function performCloudUserInstall() {
1297
+ return performInstall("user", false, { cloud: true });
1298
+ }
1299
+ function cloudUserInstallComplete() {
1300
+ try {
1301
+ const settings = readSettings(USER_SCOPE_PATH);
1302
+ return usesProjectDeferral(settings) && hasCompleteHookRegistration(settings);
1303
+ } catch {
1304
+ return false;
1305
+ }
1306
+ }
1307
+ function hasDeveloperUserInstall() {
1308
+ let settings;
1309
+ try {
1310
+ settings = readSettings(USER_SCOPE_PATH);
1311
+ } catch {
1312
+ return false;
1313
+ }
1314
+ return statuslineInstalled(settings) || !usesProjectDeferral(settings) && (isGateInstalled(settings) || captureInstalled(settings));
1315
+ }
1202
1316
  function performUninstall(scope) {
1203
1317
  const path = settingsPathFor(scope);
1204
1318
  const before = readSettings(path);
1205
- const after = applyUninstall(before);
1319
+ const uninstalled = applyUninstall(before);
1320
+ if (scope === "user") clearCloudPrepared();
1321
+ const after = scope === "project" ? projectSettingsAfterUninstall(uninstalled, projectRoot()) : uninstalled;
1206
1322
  const changed = JSON.stringify(before) !== JSON.stringify(after);
1207
1323
  if (changed) {
1208
1324
  atomicWrite(path, after);
@@ -1265,7 +1381,10 @@ function registerClaudeCommands(program) {
1265
1381
  claude.command("install").description("Register the prim hooks + statusline in Claude Code's settings.json").option(
1266
1382
  "--scope <scope>",
1267
1383
  "project (default, the repo's .claude/settings.json) or user (~/.claude/settings.json)"
1268
- ).option("--force", "Replace any drifted prim hook entries").action((opts) => {
1384
+ ).option(
1385
+ "--force",
1386
+ "Replace any drifted prim hook entries and a stale PRIM_REPOSITORY declaration"
1387
+ ).action((opts) => {
1269
1388
  const scope = resolveScope(opts.scope);
1270
1389
  const result = performInstall(scope, opts.force ?? false);
1271
1390
  const failureProtection = reportFailureProtection("claude");
@@ -1457,7 +1576,7 @@ function applyCursorUninstall(settings) {
1457
1576
  const retained = entries.filter((entry) => !isOwnedCursorHookCommand(entry.command));
1458
1577
  if (retained.length > 0) hooks[event] = retained;
1459
1578
  }
1460
- return { ...settings, hooks };
1579
+ return settings.hooks === void 0 ? settings : { ...settings, hooks };
1461
1580
  }
1462
1581
  function ownedEntries(settings) {
1463
1582
  return Object.entries(settings.hooks ?? {}).flatMap(
@@ -1641,7 +1760,11 @@ export {
1641
1760
  stripCommand,
1642
1761
  ensureRegistration,
1643
1762
  inspectHookRuntimeResolutions,
1763
+ planProjectInactiveDeclaration,
1644
1764
  atomicWrite,
1765
+ performCloudUserInstall,
1766
+ cloudUserInstallComplete,
1767
+ hasDeveloperUserInstall,
1645
1768
  performStatus,
1646
1769
  registerClaudeCommands,
1647
1770
  cursorConfigDirectory,
@@ -2,10 +2,10 @@ import {
2
2
  cursorHooksPath,
3
3
  hasExactCursorHandler,
4
4
  readCursorHooks
5
- } from "./chunk-L32WYFJT.js";
5
+ } from "./chunk-PRJ7P6J5.js";
6
6
  import {
7
7
  resolveRepositoryContext
8
- } from "./chunk-NJBN3WXF.js";
8
+ } from "./chunk-6QAXVFRJ.js";
9
9
 
10
10
  // src/hooks/cursor-coexistence.ts
11
11
  var CURSOR_EVENTS = /* @__PURE__ */ new Set([
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  atomicWriteFile,
3
3
  repoActiveFlag
4
- } from "./chunk-NJBN3WXF.js";
4
+ } from "./chunk-6QAXVFRJ.js";
5
5
 
6
6
  // src/lib/commit-heartbeat.ts
7
7
  import { execFileSync } from "child_process";
@@ -1,17 +1,19 @@
1
1
  import {
2
2
  daemonRequest
3
- } from "./chunk-YP4OXKNX.js";
3
+ } from "./chunk-WEGZGF3K.js";
4
4
  import {
5
5
  getClient,
6
- getSiteUrl,
7
- terminalSafeLine
8
- } from "./chunk-ZKXNJB6U.js";
6
+ getSiteUrl
7
+ } from "./chunk-3KPTVK4N.js";
9
8
  import {
10
9
  canonicalGitRoot,
11
10
  canonicalRepositoryPath,
11
+ cloudSetupPointer,
12
12
  currentBranch,
13
- repoSyncId
14
- } from "./chunk-NJBN3WXF.js";
13
+ isClaudeCloudSession,
14
+ repoSyncId,
15
+ terminalSafeLine
16
+ } from "./chunk-6QAXVFRJ.js";
15
17
 
16
18
  // src/daemon/proxy.ts
17
19
  var DAEMON_HTTP_TIMEOUT_MS = 1e4;
@@ -86,7 +88,7 @@ async function checkAffectedDecisions(filePaths, deps = defaultDeps) {
86
88
  return {
87
89
  decisions: [],
88
90
  truncated: false,
89
- unavailable: "this checkout has no current Primitive repository binding; run prim enable"
91
+ unavailable: isClaudeCloudSession() ? cloudSetupPointer("this checkout has no current Primitive repository binding") : "this checkout has no current Primitive repository binding; run prim enable"
90
92
  };
91
93
  }
92
94
  const canonical = filePaths.map(