@primitive.ai/prim 0.1.0-alpha.126 → 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-R6NDP7OF.js → chunk-A5VTE43F.js} +2 -2
  5. package/dist/{chunk-C5VBPHOS.js → chunk-C4QNBSWB.js} +20 -6
  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-KKUDAQQZ.js → chunk-MGKSZSTV.js} +3 -3
  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-5D2C6RCH.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 +608 -157
  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
@@ -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-HZI5PBN4.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,
@@ -1,17 +1,19 @@
1
1
  import {
2
2
  daemonRequest
3
- } from "./chunk-YP4OXKNX.js";
3
+ } from "./chunk-H6X52UVF.js";
4
4
  import {
5
5
  getClient,
6
6
  getSiteUrl,
7
7
  terminalSafeLine
8
- } from "./chunk-ZKXNJB6U.js";
8
+ } from "./chunk-NVDPKW7Z.js";
9
9
  import {
10
10
  canonicalGitRoot,
11
11
  canonicalRepositoryPath,
12
+ cloudSetupPointer,
12
13
  currentBranch,
14
+ isClaudeCloudSession,
13
15
  repoSyncId
14
- } from "./chunk-NJBN3WXF.js";
16
+ } from "./chunk-HZI5PBN4.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(
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  getClient,
3
3
  terminalSafeLine
4
- } from "./chunk-ZKXNJB6U.js";
4
+ } from "./chunk-NVDPKW7Z.js";
5
5
  import {
6
6
  localGitConfigValue,
7
7
  setLocalGitConfigValue
8
- } from "./chunk-NJBN3WXF.js";
8
+ } from "./chunk-HZI5PBN4.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,