@primitive.ai/prim 0.1.0-alpha.97 → 0.1.0-alpha.98

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 (31) hide show
  1. package/README.md +9 -0
  2. package/dist/{chunk-OW4GJBLW.js → chunk-2DA2B4EC.js} +2 -2
  3. package/dist/{chunk-35FMRWJH.js → chunk-2DPLT2CQ.js} +1 -1
  4. package/dist/{chunk-XEDJ5N3M.js → chunk-3X77XQGW.js} +2 -4
  5. package/dist/{chunk-DWRSEC34.js → chunk-6QK75B7G.js} +392 -15
  6. package/dist/{chunk-ZYK3TBEW.js → chunk-7IPGD6CD.js} +4 -6
  7. package/dist/{chunk-RK4ZS3HG.js → chunk-AN6XTFIN.js} +2 -2
  8. package/dist/{chunk-LY6NJ7KL.js → chunk-B6EPQ4YH.js} +1 -1
  9. package/dist/{chunk-QNPTWTBG.js → chunk-BIAWZMCK.js} +2 -2
  10. package/dist/{chunk-2MBV7ZMV.js → chunk-HUZXBJJ5.js} +1 -1
  11. package/dist/{chunk-FBPZ4YUD.js → chunk-IL443QTF.js} +2 -2
  12. package/dist/{chunk-7KABYYWG.js → chunk-JOR67B5T.js} +6 -8
  13. package/dist/{chunk-3I4GEWXQ.js → chunk-MN4X6RR6.js} +8 -10
  14. package/dist/{chunk-UO2U6IKF.js → chunk-NIQAVFP6.js} +1 -1
  15. package/dist/{chunk-AJYZB5PF.js → chunk-PPZBEOWK.js} +3 -3
  16. package/dist/{chunk-4GHANPWQ.js → chunk-QPMLAD2C.js} +2 -2
  17. package/dist/{chunk-Y5W4TZM7.js → chunk-RT7DXMTN.js} +2 -4
  18. package/dist/{chunk-27ADT6FQ.js → chunk-WKLYYT63.js} +44 -6
  19. package/dist/hook-runtime/hooks/pre-commit.js +208 -9
  20. package/dist/hook-runtime/index.js +41 -6
  21. package/dist/hooks/post-commit.js +7 -8
  22. package/dist/hooks/post-rewrite.js +6 -7
  23. package/dist/hooks/post-tool-use.js +13 -14
  24. package/dist/hooks/pre-commit.js +4 -4
  25. package/dist/hooks/pre-tool-use.js +10 -12
  26. package/dist/hooks/prim-hook.js +14 -15
  27. package/dist/hooks/session-end.js +6 -7
  28. package/dist/hooks/session-start.js +13 -14
  29. package/dist/index.js +25 -27
  30. package/package.json +1 -1
  31. package/dist/chunk-DHOQGHKQ.js +0 -379
@@ -1,28 +1,26 @@
1
1
  import {
2
2
  formatStatusline
3
- } from "./chunk-FBPZ4YUD.js";
3
+ } from "./chunk-IL443QTF.js";
4
4
  import {
5
5
  getSiteUrl,
6
6
  isSessionEnded,
7
7
  terminalSafeText
8
- } from "./chunk-LY6NJ7KL.js";
8
+ } from "./chunk-B6EPQ4YH.js";
9
9
  import {
10
10
  packageVersion
11
- } from "./chunk-Y5W4TZM7.js";
12
- import {
13
- decisionIngestionStatus,
14
- gitToplevel,
15
- repositoryBindingState
16
- } from "./chunk-DHOQGHKQ.js";
11
+ } from "./chunk-RT7DXMTN.js";
17
12
  import {
18
13
  daemonPrincipalsMatch,
19
14
  daemonRequest,
20
15
  resolveDaemonPrincipal
21
- } from "./chunk-35FMRWJH.js";
16
+ } from "./chunk-2DPLT2CQ.js";
22
17
  import {
18
+ decisionIngestionStatus,
19
+ gitToplevel,
23
20
  primConfigDirectory,
21
+ repositoryBindingState,
24
22
  withFileLock
25
- } from "./chunk-DWRSEC34.js";
23
+ } from "./chunk-6QK75B7G.js";
26
24
 
27
25
  // src/hooks/codex-context.ts
28
26
  import { createHash, randomBytes as randomBytes2 } from "crypto";
@@ -3,7 +3,7 @@ import {
3
3
  isTerminalSafeText,
4
4
  terminalSafeLine,
5
5
  terminalSafeText
6
- } from "./chunk-LY6NJ7KL.js";
6
+ } from "./chunk-B6EPQ4YH.js";
7
7
 
8
8
  // src/decisions/feedback.ts
9
9
  var FEEDBACK_PROTOCOL_VERSION = 2;
@@ -7,17 +7,17 @@ import {
7
7
  } from "./chunk-MXVCP33E.js";
8
8
  import {
9
9
  scrubEnvironmentPaths
10
- } from "./chunk-QNPTWTBG.js";
10
+ } from "./chunk-BIAWZMCK.js";
11
11
  import {
12
12
  cachedCollectScopeAdmits
13
- } from "./chunk-ZYK3TBEW.js";
13
+ } from "./chunk-7IPGD6CD.js";
14
14
  import {
15
15
  canonicalRepositoryPath,
16
16
  currentBranch,
17
17
  isRepoActiveForCapture,
18
18
  relatedWorktreeTarget,
19
19
  repoSyncId
20
- } from "./chunk-DHOQGHKQ.js";
20
+ } from "./chunk-6QK75B7G.js";
21
21
 
22
22
  // src/hooks/file-refs.ts
23
23
  var MAX_PREFLIGHT_FILE_TARGETS = 25;
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  getSiteUrl
3
- } from "./chunk-LY6NJ7KL.js";
3
+ } from "./chunk-B6EPQ4YH.js";
4
4
  import {
5
5
  atomicWriteFile,
6
6
  ensureDurableDirectory,
7
7
  jwtOrganizationId,
8
8
  primConfigDirectory,
9
9
  resolveAuthCredential
10
- } from "./chunk-DWRSEC34.js";
10
+ } from "./chunk-6QK75B7G.js";
11
11
 
12
12
  // src/journal.ts
13
13
  import {
@@ -1,13 +1,11 @@
1
- import {
2
- gitToplevel
3
- } from "./chunk-DHOQGHKQ.js";
4
1
  import {
5
2
  atomicWriteFile,
3
+ gitToplevel,
6
4
  primConfigDirectory,
7
5
  syncDirectory,
8
6
  syncFile,
9
7
  withFileLockSync
10
- } from "./chunk-DWRSEC34.js";
8
+ } from "./chunk-6QK75B7G.js";
11
9
 
12
10
  // src/lib/bin-path.ts
13
11
  import { existsSync, readFileSync } from "fs";
@@ -2,10 +2,16 @@ import {
2
2
  getClient,
3
3
  getSiteUrl,
4
4
  terminalSafeLine
5
- } from "./chunk-LY6NJ7KL.js";
5
+ } from "./chunk-B6EPQ4YH.js";
6
6
  import {
7
7
  daemonRequest
8
- } from "./chunk-35FMRWJH.js";
8
+ } from "./chunk-2DPLT2CQ.js";
9
+ import {
10
+ canonicalGitRoot,
11
+ canonicalRepositoryPath,
12
+ currentBranch,
13
+ repoSyncId
14
+ } from "./chunk-6QK75B7G.js";
9
15
 
10
16
  // src/daemon/proxy.ts
11
17
  var DAEMON_HTTP_TIMEOUT_MS = 1e4;
@@ -42,18 +48,28 @@ function chunk(items, size) {
42
48
  }
43
49
  return out;
44
50
  }
45
- async function fetchAffecting(client, batch) {
51
+ async function fetchAffecting(client, batch, repository) {
46
52
  const params = new URLSearchParams();
53
+ params.set("repoSyncId", repository.repoSyncId);
54
+ if (repository.branch) params.set("branch", repository.branch);
47
55
  for (const file of batch) {
48
56
  params.append("files", file);
49
57
  }
50
58
  try {
51
- return await daemonOrDirectGet(
59
+ const response = await daemonOrDirectGet(
52
60
  "decisions_affecting",
53
61
  `/api/cli/decisions/affecting?${params.toString()}`,
54
62
  client,
55
63
  DECISIONS_CHECK_TIMEOUT_MS
56
64
  );
65
+ if (response.repoSyncId !== repository.repoSyncId) {
66
+ return {
67
+ decisions: [],
68
+ truncated: response.truncated === true,
69
+ unavailable: response.unavailable ?? "service did not verify repository-scoped discovery"
70
+ };
71
+ }
72
+ return response;
57
73
  } catch (err) {
58
74
  const detail = err instanceof Error ? err.message : String(err);
59
75
  return { decisions: [], truncated: false, unavailable: `decision check failed: ${detail}` };
@@ -63,9 +79,31 @@ async function checkAffectedDecisions(filePaths, deps = defaultDeps) {
63
79
  if (filePaths.length === 0) {
64
80
  return { decisions: [], truncated: false };
65
81
  }
82
+ const cwd = process.cwd();
83
+ const root = canonicalGitRoot(cwd);
84
+ const binding = repoSyncId(cwd);
85
+ if (!root || !binding) {
86
+ return {
87
+ decisions: [],
88
+ truncated: false,
89
+ unavailable: "this checkout has no current Primitive repository binding; run prim enable"
90
+ };
91
+ }
92
+ const canonical = filePaths.map(
93
+ (file) => canonicalRepositoryPath(file, { repoRoot: root }, root)
94
+ );
95
+ if (canonical.some((path) => !path.ok)) {
96
+ return {
97
+ decisions: [],
98
+ truncated: false,
99
+ unavailable: "files must resolve inside this repository; use repository-relative paths"
100
+ };
101
+ }
102
+ const paths = [...new Set(canonical.flatMap((path) => path.ok ? [path.file] : []))];
103
+ const repository = { repoSyncId: binding, branch: currentBranch(cwd) };
66
104
  const client = deps.getClient();
67
105
  const responses = await Promise.all(
68
- chunk(filePaths, MAX_FILES_PER_REQUEST).map((batch) => fetchAffecting(client, batch))
106
+ chunk(paths, MAX_FILES_PER_REQUEST).map((batch) => fetchAffecting(client, batch, repository))
69
107
  );
70
108
  const byId = /* @__PURE__ */ new Map();
71
109
  let truncated = false;
@@ -113,7 +151,7 @@ function formatDecisionsWarning(result) {
113
151
  }
114
152
  if (result.truncated) {
115
153
  lines.push(
116
- "[prim] result truncated \u2014 more files than the server checks per request; not all decisions shown"
154
+ "[prim] result truncated \u2014 a discovery scan or result limit was reached; not all decisions shown"
117
155
  );
118
156
  }
119
157
  return lines.join("\n");
@@ -496,14 +496,14 @@ function throwIfAborted(signal) {
496
496
  }
497
497
  async function defaultSleep(ms, signal) {
498
498
  if (!signal) {
499
- await new Promise((resolve2) => setTimeout(resolve2, ms));
499
+ await new Promise((resolve3) => setTimeout(resolve3, ms));
500
500
  return;
501
501
  }
502
502
  throwIfAborted(signal);
503
- await new Promise((resolve2, reject) => {
503
+ await new Promise((resolve3, reject) => {
504
504
  const timer = setTimeout(() => {
505
505
  signal.removeEventListener("abort", onAbort);
506
- resolve2();
506
+ resolve3();
507
507
  }, ms);
508
508
  const onAbort = () => {
509
509
  clearTimeout(timer);
@@ -1098,7 +1098,7 @@ function daemonRequest(method, params = {}, opts = {}) {
1098
1098
  ...caller ? { caller } : {}
1099
1099
  };
1100
1100
  const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
1101
- return new Promise((resolve2) => {
1101
+ return new Promise((resolve3) => {
1102
1102
  let settled = false;
1103
1103
  let socket;
1104
1104
  let buffer = Buffer.alloc(0);
@@ -1113,7 +1113,7 @@ function daemonRequest(method, params = {}, opts = {}) {
1113
1113
  } catch {
1114
1114
  }
1115
1115
  }
1116
- resolve2(value);
1116
+ resolve3(value);
1117
1117
  };
1118
1118
  const timer = setTimeout(() => settle(null), timeoutMs);
1119
1119
  timer.unref();
@@ -1196,6 +1196,173 @@ async function daemonOrDirectGet(method, path, client, timeoutMs = DAEMON_HTTP_T
1196
1196
  );
1197
1197
  }
1198
1198
 
1199
+ // src/lib/activation.ts
1200
+ import { execFileSync as execFileSync2 } from "child_process";
1201
+ import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
1202
+ import { homedir as homedir2 } from "os";
1203
+ import { join as join6 } from "path";
1204
+
1205
+ // src/lib/git.ts
1206
+ import { execFileSync } from "child_process";
1207
+ import { createHash as createHash4 } from "crypto";
1208
+ import { lstatSync, realpathSync } from "fs";
1209
+ import { basename, dirname as dirname4, isAbsolute as isAbsolute2, relative, resolve as resolve2, sep } from "path";
1210
+ var GIT_TIMEOUT_MS = 1e3;
1211
+ var GITHUB_OWNER_PATTERN = /^(?![A-Za-z0-9-]*--)[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u;
1212
+ var GITHUB_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]{1,100}$/u;
1213
+ function gitToplevel(cwd) {
1214
+ try {
1215
+ return execFileSync("git", ["rev-parse", "--show-toplevel"], {
1216
+ cwd,
1217
+ encoding: "utf-8",
1218
+ stdio: ["ignore", "pipe", "ignore"],
1219
+ timeout: GIT_TIMEOUT_MS
1220
+ }).trim();
1221
+ } catch {
1222
+ return null;
1223
+ }
1224
+ }
1225
+ function gitValue(cwd, args) {
1226
+ try {
1227
+ const value = execFileSync("git", args, {
1228
+ cwd,
1229
+ encoding: "utf-8",
1230
+ stdio: ["ignore", "pipe", "ignore"],
1231
+ timeout: GIT_TIMEOUT_MS
1232
+ }).trim();
1233
+ return value || void 0;
1234
+ } catch {
1235
+ return void 0;
1236
+ }
1237
+ }
1238
+ function currentBranch(cwd) {
1239
+ return gitValue(cwd, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
1240
+ }
1241
+ function githubRepositoryFullName(cwd) {
1242
+ const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
1243
+ if (!remote || [...remote].some((char) => char < " " || char === "\x7F")) return null;
1244
+ const match = /^(?:git@github\.com:([^?#]+)|(?:https|ssh):\/\/(?:[^/@]+@)?github\.com(?::\d+)?\/([^?#]+))$/i.exec(
1245
+ remote
1246
+ );
1247
+ const path = match?.[1] ?? match?.[2];
1248
+ if (!path) return null;
1249
+ const parts = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "").split("/");
1250
+ if (parts.length !== 2 || !GITHUB_OWNER_PATTERN.test(parts[0] ?? "") || !GITHUB_REPOSITORY_PATTERN.test(parts[1] ?? "")) {
1251
+ return null;
1252
+ }
1253
+ return `${parts[0]}/${parts[1]}`;
1254
+ }
1255
+ function canonicalGitRoot(cwd) {
1256
+ try {
1257
+ const top = gitToplevel(cwd);
1258
+ return top ? realpathSync.native(top) : null;
1259
+ } catch {
1260
+ return null;
1261
+ }
1262
+ }
1263
+ function nearestExistingAncestor(path) {
1264
+ const suffix = [];
1265
+ let cursor = path;
1266
+ while (true) {
1267
+ try {
1268
+ lstatSync(cursor);
1269
+ break;
1270
+ } catch (error) {
1271
+ const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
1272
+ if (code !== "ENOENT" && code !== "ENOTDIR") return null;
1273
+ const parent = dirname4(cursor);
1274
+ if (parent === cursor) return null;
1275
+ suffix.unshift(cursor.slice(parent.length + (parent.endsWith(sep) ? 0 : 1)));
1276
+ cursor = parent;
1277
+ }
1278
+ }
1279
+ try {
1280
+ return { real: realpathSync.native(cursor), suffix };
1281
+ } catch {
1282
+ return null;
1283
+ }
1284
+ }
1285
+ function canonicalRepositoryPathScoped(filePath, context, baseDir) {
1286
+ if (!filePath || filePath !== filePath.trim() || filePath.includes("\0")) {
1287
+ return { ok: false, reason: "invalid_path" };
1288
+ }
1289
+ const absolute = resolve2(baseDir, filePath);
1290
+ const resolved = nearestExistingAncestor(absolute);
1291
+ if (!resolved) return { ok: false, reason: "invalid_path" };
1292
+ const target = resolve2(resolved.real, ...resolved.suffix);
1293
+ const rel = relative(context.repoRoot, target);
1294
+ if (!rel || rel === ".") return { ok: false, reason: "invalid_path" };
1295
+ if (isAbsolute2(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1296
+ return { ok: false, reason: "outside_repository" };
1297
+ }
1298
+ return { ok: true, file: sep === "/" ? rel : rel.split(sep).join("/") };
1299
+ }
1300
+ function canonicalRepositoryPathLegacy(filePath, cwd, repositoryRoot = canonicalGitRoot(cwd)) {
1301
+ if (!repositoryRoot || !filePath || [...filePath].some((char) => char < " " || char === "\x7F" || "~*?[]{}$`\\".includes(char)))
1302
+ return null;
1303
+ const absolute = resolve2(cwd, filePath);
1304
+ let target;
1305
+ try {
1306
+ const stat = lstatSync(absolute);
1307
+ if (!stat.isFile() || stat.isSymbolicLink()) return null;
1308
+ target = realpathSync.native(absolute);
1309
+ } catch (error) {
1310
+ if (!(error instanceof Error) || error.code !== "ENOENT") {
1311
+ return null;
1312
+ }
1313
+ try {
1314
+ const parent = realpathSync.native(dirname4(absolute));
1315
+ if (!lstatSync(parent).isDirectory()) return null;
1316
+ target = resolve2(parent, basename(absolute));
1317
+ } catch {
1318
+ return null;
1319
+ }
1320
+ }
1321
+ const rel = relative(repositoryRoot, target);
1322
+ if (!rel || isAbsolute2(rel) || rel === ".." || rel.startsWith(`..${sep}`)) {
1323
+ return null;
1324
+ }
1325
+ return sep === "/" ? rel : rel.split(sep).join("/");
1326
+ }
1327
+ function canonicalRepositoryPath(filePath, contextOrCwd, baseDirOrRoot) {
1328
+ if (typeof contextOrCwd === "string") {
1329
+ return canonicalRepositoryPathLegacy(filePath, contextOrCwd, baseDirOrRoot);
1330
+ }
1331
+ return canonicalRepositoryPathScoped(
1332
+ filePath,
1333
+ contextOrCwd,
1334
+ baseDirOrRoot ?? contextOrCwd.repoRoot
1335
+ );
1336
+ }
1337
+
1338
+ // src/lib/activation.ts
1339
+ var PRIM_REPO_SYNC_ID_KEY = "prim.repoSyncId";
1340
+ var PRIM_REPO_SYNC_REPOSITORY_KEY = "prim.repoSyncRepository";
1341
+ var GIT_TIMEOUT_MS2 = 1e3;
1342
+ var REPO_SYNC_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
1343
+ function isValidRepoSyncId(value) {
1344
+ return typeof value === "string" && REPO_SYNC_ID_RE.test(value);
1345
+ }
1346
+ function localGitConfigValue(cwd, key) {
1347
+ try {
1348
+ const value = execFileSync2("git", ["config", "--local", "--get", key], {
1349
+ cwd,
1350
+ encoding: "utf-8",
1351
+ stdio: ["ignore", "pipe", "ignore"],
1352
+ timeout: GIT_TIMEOUT_MS2
1353
+ }).trim();
1354
+ return value || void 0;
1355
+ } catch {
1356
+ return void 0;
1357
+ }
1358
+ }
1359
+ function repoSyncId(cwd) {
1360
+ const value = localGitConfigValue(cwd, PRIM_REPO_SYNC_ID_KEY);
1361
+ if (!isValidRepoSyncId(value)) return void 0;
1362
+ const repositoryFullName = localGitConfigValue(cwd, PRIM_REPO_SYNC_REPOSITORY_KEY);
1363
+ return repositoryFullName === githubRepositoryFullName(cwd) ? value : void 0;
1364
+ }
1365
+
1199
1366
  // src/hooks/decisions-check.ts
1200
1367
  var DECISIONS_CHECK_TIMEOUT_MS = 1e4;
1201
1368
  var MAX_FILES_PER_REQUEST = 25;
@@ -1207,18 +1374,28 @@ function chunk(items, size) {
1207
1374
  }
1208
1375
  return out;
1209
1376
  }
1210
- async function fetchAffecting(client, batch) {
1377
+ async function fetchAffecting(client, batch, repository) {
1211
1378
  const params = new URLSearchParams();
1379
+ params.set("repoSyncId", repository.repoSyncId);
1380
+ if (repository.branch) params.set("branch", repository.branch);
1212
1381
  for (const file of batch) {
1213
1382
  params.append("files", file);
1214
1383
  }
1215
1384
  try {
1216
- return await daemonOrDirectGet(
1385
+ const response = await daemonOrDirectGet(
1217
1386
  "decisions_affecting",
1218
1387
  `/api/cli/decisions/affecting?${params.toString()}`,
1219
1388
  client,
1220
1389
  DECISIONS_CHECK_TIMEOUT_MS
1221
1390
  );
1391
+ if (response.repoSyncId !== repository.repoSyncId) {
1392
+ return {
1393
+ decisions: [],
1394
+ truncated: response.truncated === true,
1395
+ unavailable: response.unavailable ?? "service did not verify repository-scoped discovery"
1396
+ };
1397
+ }
1398
+ return response;
1222
1399
  } catch (err) {
1223
1400
  const detail = err instanceof Error ? err.message : String(err);
1224
1401
  return { decisions: [], truncated: false, unavailable: `decision check failed: ${detail}` };
@@ -1228,9 +1405,31 @@ async function checkAffectedDecisions(filePaths, deps = defaultDeps) {
1228
1405
  if (filePaths.length === 0) {
1229
1406
  return { decisions: [], truncated: false };
1230
1407
  }
1408
+ const cwd = process.cwd();
1409
+ const root = canonicalGitRoot(cwd);
1410
+ const binding = repoSyncId(cwd);
1411
+ if (!root || !binding) {
1412
+ return {
1413
+ decisions: [],
1414
+ truncated: false,
1415
+ unavailable: "this checkout has no current Primitive repository binding; run prim enable"
1416
+ };
1417
+ }
1418
+ const canonical = filePaths.map(
1419
+ (file) => canonicalRepositoryPath(file, { repoRoot: root }, root)
1420
+ );
1421
+ if (canonical.some((path) => !path.ok)) {
1422
+ return {
1423
+ decisions: [],
1424
+ truncated: false,
1425
+ unavailable: "files must resolve inside this repository; use repository-relative paths"
1426
+ };
1427
+ }
1428
+ const paths = [...new Set(canonical.flatMap((path) => path.ok ? [path.file] : []))];
1429
+ const repository = { repoSyncId: binding, branch: currentBranch(cwd) };
1231
1430
  const client = deps.getClient();
1232
1431
  const responses = await Promise.all(
1233
- chunk(filePaths, MAX_FILES_PER_REQUEST).map((batch) => fetchAffecting(client, batch))
1432
+ chunk(paths, MAX_FILES_PER_REQUEST).map((batch) => fetchAffecting(client, batch, repository))
1234
1433
  );
1235
1434
  const byId = /* @__PURE__ */ new Map();
1236
1435
  let truncated = false;
@@ -1278,7 +1477,7 @@ function formatDecisionsWarning(result) {
1278
1477
  }
1279
1478
  if (result.truncated) {
1280
1479
  lines.push(
1281
- "[prim] result truncated \u2014 more files than the server checks per request; not all decisions shown"
1480
+ "[prim] result truncated \u2014 a discovery scan or result limit was reached; not all decisions shown"
1282
1481
  );
1283
1482
  }
1284
1483
  return lines.join("\n");
@@ -12955,6 +12955,9 @@ function gitValue(cwd, args) {
12955
12955
  return void 0;
12956
12956
  }
12957
12957
  }
12958
+ function currentBranch(cwd) {
12959
+ return gitValue(cwd, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
12960
+ }
12958
12961
  function githubRepositoryFullName(cwd) {
12959
12962
  const remote = gitValue(cwd, ["config", "--get", "remote.origin.url"]);
12960
12963
  if (!remote || [...remote].some((char) => char < " " || char === "\x7F")) return null;
@@ -41517,18 +41520,28 @@ function chunk(items, size) {
41517
41520
  }
41518
41521
  return out;
41519
41522
  }
41520
- async function fetchAffecting(client, batch) {
41523
+ async function fetchAffecting(client, batch, repository) {
41521
41524
  const params = new URLSearchParams();
41525
+ params.set("repoSyncId", repository.repoSyncId);
41526
+ if (repository.branch) params.set("branch", repository.branch);
41522
41527
  for (const file of batch) {
41523
41528
  params.append("files", file);
41524
41529
  }
41525
41530
  try {
41526
- return await daemonOrDirectGet(
41531
+ const response = await daemonOrDirectGet(
41527
41532
  "decisions_affecting",
41528
41533
  `/api/cli/decisions/affecting?${params.toString()}`,
41529
41534
  client,
41530
41535
  DECISIONS_CHECK_TIMEOUT_MS
41531
41536
  );
41537
+ if (response.repoSyncId !== repository.repoSyncId) {
41538
+ return {
41539
+ decisions: [],
41540
+ truncated: response.truncated === true,
41541
+ unavailable: response.unavailable ?? "service did not verify repository-scoped discovery"
41542
+ };
41543
+ }
41544
+ return response;
41532
41545
  } catch (err) {
41533
41546
  const detail = err instanceof Error ? err.message : String(err);
41534
41547
  return { decisions: [], truncated: false, unavailable: `decision check failed: ${detail}` };
@@ -41538,9 +41551,31 @@ async function checkAffectedDecisions(filePaths, deps = defaultDeps8) {
41538
41551
  if (filePaths.length === 0) {
41539
41552
  return { decisions: [], truncated: false };
41540
41553
  }
41554
+ const cwd = process.cwd();
41555
+ const root = canonicalGitRoot(cwd);
41556
+ const binding = repoSyncId(cwd);
41557
+ if (!root || !binding) {
41558
+ return {
41559
+ decisions: [],
41560
+ truncated: false,
41561
+ unavailable: "this checkout has no current Primitive repository binding; run prim enable"
41562
+ };
41563
+ }
41564
+ const canonical = filePaths.map(
41565
+ (file) => canonicalRepositoryPath(file, { repoRoot: root }, root)
41566
+ );
41567
+ if (canonical.some((path9) => !path9.ok)) {
41568
+ return {
41569
+ decisions: [],
41570
+ truncated: false,
41571
+ unavailable: "files must resolve inside this repository; use repository-relative paths"
41572
+ };
41573
+ }
41574
+ const paths = [...new Set(canonical.flatMap((path9) => path9.ok ? [path9.file] : []))];
41575
+ const repository = { repoSyncId: binding, branch: currentBranch(cwd) };
41541
41576
  const client = deps.getClient();
41542
41577
  const responses = await Promise.all(
41543
- chunk(filePaths, MAX_FILES_PER_REQUEST).map((batch) => fetchAffecting(client, batch))
41578
+ chunk(paths, MAX_FILES_PER_REQUEST).map((batch) => fetchAffecting(client, batch, repository))
41544
41579
  );
41545
41580
  const byId = /* @__PURE__ */ new Map();
41546
41581
  let truncated = false;
@@ -41588,7 +41623,7 @@ function formatDecisionsWarning(result) {
41588
41623
  }
41589
41624
  if (result.truncated) {
41590
41625
  lines.push(
41591
- "[prim] result truncated \u2014 more files than the server checks per request; not all decisions shown"
41626
+ "[prim] result truncated \u2014 a discovery scan or result limit was reached; not all decisions shown"
41592
41627
  );
41593
41628
  }
41594
41629
  return lines.join("\n");
@@ -41706,9 +41741,9 @@ function locationScopeFromOptions(options) {
41706
41741
  }
41707
41742
  function registerDecisionsCommands(program3) {
41708
41743
  const decisions = program3.command("decisions").description("Inspect the project Decision Graph");
41709
- decisions.command("check").description("Look up active decisions that reference one or more file paths").requiredOption(
41744
+ decisions.command("check").description("Look up active decisions scoped to file paths in the connected repository").requiredOption(
41710
41745
  "--files <files>",
41711
- "Comma-separated file paths to check against the Decision Graph (repeatable)",
41746
+ "Comma-separated repository-relative paths to check against the Decision Graph (repeatable)",
41712
41747
  collectPaths
41713
41748
  ).action(async (opts) => {
41714
41749
  const result = await checkAffectedDecisions(opts.files);
@@ -1,33 +1,32 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  recordPostCommitFired
4
- } from "../chunk-XEDJ5N3M.js";
4
+ } from "../chunk-3X77XQGW.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-OW4GJBLW.js";
11
+ } from "../chunk-2DA2B4EC.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-4GHANPWQ.js";
19
- import "../chunk-QNPTWTBG.js";
18
+ } from "../chunk-QPMLAD2C.js";
19
+ import "../chunk-BIAWZMCK.js";
20
20
  import {
21
21
  cachedCollectScopeAdmits
22
- } from "../chunk-ZYK3TBEW.js";
23
- import "../chunk-LY6NJ7KL.js";
22
+ } from "../chunk-7IPGD6CD.js";
23
+ import "../chunk-B6EPQ4YH.js";
24
24
  import {
25
25
  githubRepositoryFullName,
26
26
  isRepoActiveForCapture,
27
27
  repoSyncId,
28
28
  resolveRepositoryContext
29
- } from "../chunk-DHOQGHKQ.js";
30
- import "../chunk-DWRSEC34.js";
29
+ } from "../chunk-6QK75B7G.js";
31
30
 
32
31
  // src/hooks/post-commit.ts
33
32
  import { execFileSync, spawn } from "child_process";
@@ -5,26 +5,25 @@ import {
5
5
  import {
6
6
  canonicalRewritePairs,
7
7
  toRewriteMove
8
- } from "../chunk-OW4GJBLW.js";
8
+ } from "../chunk-2DA2B4EC.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-4GHANPWQ.js";
16
- import "../chunk-QNPTWTBG.js";
15
+ } from "../chunk-QPMLAD2C.js";
16
+ import "../chunk-BIAWZMCK.js";
17
17
  import {
18
18
  cachedCollectScopeAdmits
19
- } from "../chunk-ZYK3TBEW.js";
20
- import "../chunk-LY6NJ7KL.js";
19
+ } from "../chunk-7IPGD6CD.js";
20
+ import "../chunk-B6EPQ4YH.js";
21
21
  import {
22
22
  githubRepositoryFullName,
23
23
  isRepoActiveForCapture,
24
24
  repoSyncId,
25
25
  resolveRepositoryContext
26
- } from "../chunk-DHOQGHKQ.js";
27
- import "../chunk-DWRSEC34.js";
26
+ } from "../chunk-6QK75B7G.js";
28
27
 
29
28
  // src/hooks/post-rewrite.ts
30
29
  import { execFileSync, spawn } from "child_process";