carrick 0.3.154 → 0.3.155

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 (150) hide show
  1. package/bin/carrick.mjs +26 -4
  2. package/dist/cli.d.ts +6 -0
  3. package/dist/cli.js +1 -0
  4. package/dist/cli.js.map +1 -1
  5. package/dist/contract.d.ts +10 -0
  6. package/dist/contract.js.map +1 -1
  7. package/dist/facts/diff.d.ts +27 -0
  8. package/dist/facts/diff.js +134 -0
  9. package/dist/facts/diff.js.map +1 -0
  10. package/dist/facts/enabled.d.ts +2 -0
  11. package/dist/facts/enabled.js +9 -0
  12. package/dist/facts/enabled.js.map +1 -0
  13. package/dist/facts/fetch.d.ts +48 -0
  14. package/dist/facts/fetch.js +235 -0
  15. package/dist/facts/fetch.js.map +1 -0
  16. package/dist/facts/files.d.ts +21 -0
  17. package/dist/facts/files.js +58 -0
  18. package/dist/facts/files.js.map +1 -0
  19. package/dist/facts/lines.d.ts +70 -0
  20. package/dist/facts/lines.js +335 -0
  21. package/dist/facts/lines.js.map +1 -0
  22. package/dist/facts/match.d.ts +91 -0
  23. package/dist/facts/match.js +1122 -0
  24. package/dist/facts/match.js.map +1 -0
  25. package/dist/facts/peers.d.ts +48 -0
  26. package/dist/facts/peers.js +143 -0
  27. package/dist/facts/peers.js.map +1 -0
  28. package/dist/facts/refresh-run.d.ts +2 -0
  29. package/dist/facts/refresh-run.js +18 -0
  30. package/dist/facts/refresh-run.js.map +1 -0
  31. package/dist/facts/rules/packages.d.ts +16 -0
  32. package/dist/facts/rules/packages.js +157 -0
  33. package/dist/facts/rules/packages.js.map +1 -0
  34. package/dist/facts/rules/same-name.d.ts +28 -0
  35. package/dist/facts/rules/same-name.js +131 -0
  36. package/dist/facts/rules/same-name.js.map +1 -0
  37. package/dist/facts/store.d.ts +119 -0
  38. package/dist/facts/store.js +341 -0
  39. package/dist/facts/store.js.map +1 -0
  40. package/dist/git-remote.d.ts +6 -0
  41. package/dist/git-remote.js +37 -0
  42. package/dist/git-remote.js.map +1 -0
  43. package/dist/hook/apply-patch.d.ts +23 -0
  44. package/dist/hook/apply-patch.js +92 -0
  45. package/dist/hook/apply-patch.js.map +1 -1
  46. package/dist/hook/bash-targets.d.ts +8 -0
  47. package/dist/hook/bash-targets.js +23 -11
  48. package/dist/hook/bash-targets.js.map +1 -1
  49. package/dist/hook/edit-flow.d.ts +29 -2
  50. package/dist/hook/edit-flow.js +80 -29
  51. package/dist/hook/edit-flow.js.map +1 -1
  52. package/dist/hook/late.d.ts +29 -0
  53. package/dist/hook/late.js +121 -26
  54. package/dist/hook/late.js.map +1 -1
  55. package/dist/hook/post-bash.js +45 -22
  56. package/dist/hook/post-bash.js.map +1 -1
  57. package/dist/hook/post-edit.d.ts +16 -1
  58. package/dist/hook/post-edit.js +177 -13
  59. package/dist/hook/post-edit.js.map +1 -1
  60. package/dist/hook/post-read.js +8 -12
  61. package/dist/hook/post-read.js.map +1 -1
  62. package/dist/hook/post-search.d.ts +2 -0
  63. package/dist/hook/post-search.js +25 -0
  64. package/dist/hook/post-search.js.map +1 -0
  65. package/dist/hook/probe.d.ts +18 -3
  66. package/dist/hook/probe.js +30 -6
  67. package/dist/hook/probe.js.map +1 -1
  68. package/dist/hook/rechecks.d.ts +66 -11
  69. package/dist/hook/rechecks.js +115 -29
  70. package/dist/hook/rechecks.js.map +1 -1
  71. package/dist/hook/refresh.d.ts +9 -0
  72. package/dist/hook/refresh.js +10 -0
  73. package/dist/hook/refresh.js.map +1 -1
  74. package/dist/hook/reuse.d.ts +16 -2
  75. package/dist/hook/reuse.js +49 -6
  76. package/dist/hook/reuse.js.map +1 -1
  77. package/dist/hook/session-key.d.ts +12 -0
  78. package/dist/hook/session-key.js +30 -0
  79. package/dist/hook/session-key.js.map +1 -0
  80. package/dist/hook/session-start.js +14 -7
  81. package/dist/hook/session-start.js.map +1 -1
  82. package/dist/hook/stop-wait.d.ts +2 -9
  83. package/dist/hook/stop-wait.js +96 -113
  84. package/dist/hook/stop-wait.js.map +1 -1
  85. package/dist/hook/stop.js +13 -8
  86. package/dist/hook/stop.js.map +1 -1
  87. package/dist/hook/subagent-stop.d.ts +2 -0
  88. package/dist/hook/subagent-stop.js +45 -0
  89. package/dist/hook/subagent-stop.js.map +1 -0
  90. package/dist/hook/timings.d.ts +72 -0
  91. package/dist/hook/timings.js +175 -0
  92. package/dist/hook/timings.js.map +1 -0
  93. package/dist/hook/user-prompt.js +17 -13
  94. package/dist/hook/user-prompt.js.map +1 -1
  95. package/dist/hook/worktree.d.ts +11 -0
  96. package/dist/hook/worktree.js +27 -1
  97. package/dist/hook/worktree.js.map +1 -1
  98. package/dist/init/repo-copies.d.ts +6 -0
  99. package/dist/init/repo-copies.js +7 -3
  100. package/dist/init/repo-copies.js.map +1 -1
  101. package/dist/init/repos.d.ts +2 -2
  102. package/dist/init/repos.js +1 -34
  103. package/dist/init/repos.js.map +1 -1
  104. package/dist/init/settings.js +25 -13
  105. package/dist/init/settings.js.map +1 -1
  106. package/dist/render.d.ts +8 -33
  107. package/dist/render.js +31 -122
  108. package/dist/render.js.map +1 -1
  109. package/package.json +6 -6
  110. package/plugin/.claude-plugin/plugin.json +1 -1
  111. package/plugin/hooks/hooks.json +44 -3
  112. package/sidecar/dist/src/capture/anchors.d.ts +12 -1
  113. package/sidecar/dist/src/capture/anchors.js +28 -47
  114. package/sidecar/dist/src/capture/api.d.ts +41 -1
  115. package/sidecar/dist/src/capture/augmentations.d.ts +2 -0
  116. package/sidecar/dist/src/capture/augmentations.js +1 -1
  117. package/sidecar/dist/src/capture/check-classify.d.ts +12 -1
  118. package/sidecar/dist/src/capture/check-classify.js +43 -0
  119. package/sidecar/dist/src/capture/check-deep.d.ts +44 -1
  120. package/sidecar/dist/src/capture/check-deep.js +161 -2
  121. package/sidecar/dist/src/capture/check.js +23 -2
  122. package/sidecar/dist/src/capture/checkout.d.ts +9 -3
  123. package/sidecar/dist/src/capture/checkout.js +12 -5
  124. package/sidecar/dist/src/capture/deep-walk.d.ts +25 -0
  125. package/sidecar/dist/src/capture/deep-walk.js +41 -0
  126. package/sidecar/dist/src/capture/deno-project.d.ts +22 -0
  127. package/sidecar/dist/src/capture/deno-project.js +48 -1
  128. package/sidecar/dist/src/capture/index.d.ts +2 -1
  129. package/sidecar/dist/src/capture/index.js +14 -4
  130. package/sidecar/dist/src/capture/machinery.d.ts +8 -53
  131. package/sidecar/dist/src/capture/machinery.js +10 -157
  132. package/sidecar/dist/src/capture/self-check.d.ts +7 -0
  133. package/sidecar/dist/src/capture/self-check.js +44 -1
  134. package/sidecar/dist/src/capture/site-node.d.ts +166 -0
  135. package/sidecar/dist/src/capture/site-node.js +570 -0
  136. package/sidecar/dist/src/capture/tool-env.d.ts +12 -0
  137. package/sidecar/dist/src/capture/tool-env.js +26 -0
  138. package/sidecar/dist/src/library-claims.js +211 -20
  139. package/sidecar/dist/src/node-index.d.ts +2 -0
  140. package/sidecar/dist/src/node-index.js +5 -1
  141. package/sidecar/dist/src/position-rows.d.ts +39 -4
  142. package/sidecar/dist/src/position-rows.js +233 -16
  143. package/sidecar/dist/src/project-loader.js +13 -5
  144. package/sidecar/dist/src/retype.d.ts +13 -0
  145. package/sidecar/dist/src/retype.js +126 -0
  146. package/sidecar/dist/src/type-inferrer.d.ts +33 -145
  147. package/sidecar/dist/src/type-inferrer.js +68 -524
  148. package/sidecar/dist/src/types.d.ts +55 -2
  149. package/sidecar/dist/src/validators.d.ts +800 -142
  150. package/sidecar/dist/src/validators.js +11 -1
package/bin/carrick.mjs CHANGED
@@ -39,9 +39,11 @@ const HOOKS = {
39
39
  "post-edit": "../dist/hook/post-edit.js",
40
40
  "post-bash": "../dist/hook/post-bash.js",
41
41
  "post-read": "../dist/hook/post-read.js",
42
+ "post-search": "../dist/hook/post-search.js",
42
43
  "recheck-run": "../dist/hook/recheck-run.js",
43
44
  "session-start": "../dist/hook/session-start.js",
44
45
  stop: "../dist/hook/stop.js",
46
+ "subagent-stop": "../dist/hook/subagent-stop.js",
45
47
  "user-prompt": "../dist/hook/user-prompt.js",
46
48
  };
47
49
 
@@ -204,7 +206,7 @@ async function renderNative(args) {
204
206
  }
205
207
 
206
208
  /** Run the scanner binary, streaming its output and answering with its code. */
207
- async function runNative(args) {
209
+ async function runNative(args, { after } = {}) {
208
210
  const { resolveNativeBinary, nativeEnv, overrideLine } = await import("../dist/native.js");
209
211
  const { relaySignals } = await import("../dist/scan.js");
210
212
  const lookup = resolveNativeBinary();
@@ -236,6 +238,16 @@ async function runNative(args) {
236
238
  process.kill(process.pid, signal);
237
239
  return;
238
240
  }
241
+ // `after` is this package's own line under the binary's answer.
242
+ if (after && code === 0) {
243
+ Promise.resolve(after())
244
+ .then((line) => {
245
+ if (line) process.stdout.write(`${line}\n`);
246
+ })
247
+ .catch(() => {})
248
+ .finally(() => process.exit(code));
249
+ return;
250
+ }
239
251
  process.exit(code ?? 1);
240
252
  });
241
253
  }
@@ -295,8 +307,8 @@ function extraHelp() {
295
307
  " depends on the file, once per file per session)",
296
308
  " hook session-start Claude Code SessionStart hook",
297
309
  " hook stop Claude Code Stop hook (delivers background",
298
- " re-checks, waits for the ones still running)",
299
- " hook user-prompt Codex UserPromptSubmit hook (finished",
310
+ " re-checks)",
311
+ " hook user-prompt UserPromptSubmit hook (finished",
300
312
  " re-checks, delivered on the next prompt)",
301
313
  " templates workflow print the GitHub Actions workflow file",
302
314
  " --version the version of this package",
@@ -423,7 +435,17 @@ switch (command) {
423
435
  }
424
436
  default: {
425
437
  const { isRendered } = await import("../dist/scan.js");
426
- if (isRendered(command, rest)) await renderNative(argv);
438
+ // The binary answers `status`; this package adds the hooks' own timing line
439
+ // under it (`hook/timings.ts`), never to `--json`, which a hook parses.
440
+ if (command === "status" && !rest.some((a) => a === "--json" || a === "--help" || a === "-h")) {
441
+ await runNative(argv, {
442
+ after: async () => {
443
+ const { statusTimingsLine } = await import("../dist/hook/timings.js");
444
+ const at = rest.indexOf("--workspace");
445
+ return statusTimingsLine((at >= 0 && rest[at + 1]) || process.cwd());
446
+ },
447
+ });
448
+ } else if (isRendered(command, rest)) await renderNative(argv);
427
449
  else await runNative(argv);
428
450
  }
429
451
  }
package/dist/cli.d.ts CHANGED
@@ -19,6 +19,12 @@ export type RunOptions = {
19
19
  * (the environment's own value always wins). Absent: five seconds.
20
20
  */
21
21
  limitMs?: number;
22
+ /**
23
+ * The signal that ends a call past its limit. Absent: SIGTERM, which lets the
24
+ * binary clean up. The hook's probe states SIGKILL, so a binary that ignores
25
+ * SIGTERM is not left running behind the edit.
26
+ */
27
+ killSignal?: NodeJS.Signals;
22
28
  };
23
29
  /**
24
30
  * What a `--recheck` call must state: its own limit. There is no default,
package/dist/cli.js CHANGED
@@ -24,6 +24,7 @@ async function run(args, options, parse) {
24
24
  cwd: options.cwd,
25
25
  env,
26
26
  timeout: env["CARRICK_TIMEOUT_MS"] ? timeoutMs(env) : (options.limitMs ?? timeoutMs(env)),
27
+ killSignal: options.killSignal ?? "SIGTERM",
27
28
  maxBuffer: 32 * 1024 * 1024,
28
29
  encoding: "utf8",
29
30
  }, (error, stdout) => {
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAE5E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAIlB,MAAM,eAAe,CAAC;AAEvB,yEAAyE;AACzE,MAAM,UAAU,MAAM,CAAC,MAAyB,OAAO,CAAC,GAAG;IACzD,OAAO,GAAG,CAAC,aAAa,CAAC,IAAI,SAAS,CAAC;AACzC,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC5D,MAAM,GAAG,GAAG,GAAG,CAAC,o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G;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,KAAe,EACf,OAAwC;IAExC,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;IAClE,IAAI,OAAO,CAAC,QAAQ;QAAE,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC/C,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAmD;IAEnD,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS;QAC5B,CAAC,CAAC,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;QACxD,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACzB,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAmB;IACpD,OAAO,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;AAClF,CAAC"}
@@ -64,6 +64,11 @@ export type CheckItem = {
64
64
  kind: "route" | "call" | string;
65
65
  method?: string;
66
66
  path?: string;
67
+ /**
68
+ * The dispatch case a row is, ready to append to `method path`:
69
+ * ` {action=start-scan}`. Absent on a plain route or call (carrick#3956).
70
+ */
71
+ dispatch_label?: string;
67
72
  line?: number;
68
73
  col?: number;
69
74
  /** R1: a row whose only source is the model is a candidate, never a fact. */
@@ -217,6 +222,11 @@ export type Recheck = {
217
222
  * indexed ones. Absent otherwise.
218
223
  */
219
224
  deferred?: boolean;
225
+ /**
226
+ * True on a `none` whose re-check started and ran past its budget: the rows
227
+ * are the indexed ones because time ran out (carrick#3860). Absent otherwise.
228
+ */
229
+ deadline?: boolean;
220
230
  /** Which services this re-check read and which it judged at another version. */
221
231
  scope?: RecheckScope;
222
232
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,yDAAyD;AACzD,+EAA+E;AAC/E,4DAA4D;AAC5D,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,0CAA0C;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AA+TxC,MAAM,CAAC,MAAM,MAAM,GAAG,iBAAiB,CAAC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAuMhD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC;AAED,SAAS,aAAa,CAAC,MAAe;IACpC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI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,CAAC"}
@@ -0,0 +1,27 @@
1
+ /** A diff with more changed lines than this is a rewrite or a generated file: no lines. */
2
+ export declare const MAX_DIFF_LINES = 2000;
3
+ /** Each git call gets this long; a slower one is a silence, not a wait. `CARRICK_FACTS_DIFF_BUDGET_MS` overrides it (tests on a busy machine). */
4
+ export declare const DIFF_BUDGET_MS = 150;
5
+ export type DiffChange = {
6
+ lines?: number[];
7
+ removed?: number[];
8
+ whole?: boolean;
9
+ };
10
+ /**
11
+ * The fact path's one git runner (R40.4): `git` in `dir` under the budget,
12
+ * the output or null on any failure or overrun. Every git call the fact path
13
+ * makes runs through it: the diff and the tracked-file check below and the
14
+ * peer proof (`peers.ts`). In a partial clone, or a folder in no checkout, it
15
+ * runs nothing and answers null.
16
+ */
17
+ export declare function gitFacts(dir: string, args: string[], env?: NodeJS.ProcessEnv): string | null;
18
+ /** Whether git, asked in the file's folder, says it does not track `file`; false when git cannot say. */
19
+ export declare function untrackedFile(file: string, env?: NodeJS.ProcessEnv): boolean;
20
+ /** How long each of the fact path's git calls may take. */
21
+ export declare function factsGitBudgetMs(env?: NodeJS.ProcessEnv): number;
22
+ /**
23
+ * Where `file` differs from `HEAD`, or null when that is not known (or there
24
+ * is no difference). An untracked file counts whole only when `created`: the
25
+ * session did not see the file before this call.
26
+ */
27
+ export declare function changesAgainstHead(file: string, created: boolean, env?: NodeJS.ProcessEnv): DiffChange | null;
@@ -0,0 +1,134 @@
1
+ // The changed lines of one file against `HEAD`, for a write whose own call
2
+ // says nothing about them: a `Write` over an existing file, a shell write
3
+ // (`sed -i`, a heredoc, a script), a patch hunk that cannot be placed.
4
+ //
5
+ // `git diff --no-ext-diff -U0 HEAD -- <file>` runs in the file's own folder
6
+ // (so a linked worktree answers for itself), and its `@@ -a,b +c,d @@` headers
7
+ // give the same shape `post-edit.ts` reads from an Edit's patch: the lines now
8
+ // in the file that were added, and where lines were removed (the line now
9
+ // sitting where they were; `facts/match.ts` `gapsOfLines` and `touched` apply
10
+ // the "strictly inside" rule to them).
11
+ //
12
+ // Limitation: the diff is against HEAD, not against the file before this
13
+ // call, so lines the session changed earlier and has not committed also
14
+ // count as changed. Each fact line is said once per session (`markFacts`),
15
+ // which stops the repeats.
16
+ //
17
+ // Which lines changed is not known, and nothing is said, when: the folder is
18
+ // not a git repository, git is missing or answers an error, the diff holds
19
+ // more than `MAX_DIFF_LINES` changed lines, or git takes longer than
20
+ // `DIFF_BUDGET_MS`. Never throws.
21
+ import fs from "node:fs";
22
+ import path from "node:path";
23
+ import { cooldownMs } from "../hook/refresh.js";
24
+ import { checkoutOf, commonGitDir } from "../hook/worktree.js";
25
+ import { git } from "../init/repo-copies.js";
26
+ /** A diff with more changed lines than this is a rewrite or a generated file: no lines. */
27
+ export const MAX_DIFF_LINES = 2000;
28
+ /** Each git call gets this long; a slower one is a silence, not a wait. `CARRICK_FACTS_DIFF_BUDGET_MS` overrides it (tests on a busy machine). */
29
+ export const DIFF_BUDGET_MS = 150;
30
+ /**
31
+ * The fact path's one git runner (R40.4): `git` in `dir` under the budget,
32
+ * the output or null on any failure or overrun. Every git call the fact path
33
+ * makes runs through it: the diff and the tracked-file check below and the
34
+ * peer proof (`peers.ts`). In a partial clone, or a folder in no checkout, it
35
+ * runs nothing and answers null.
36
+ */
37
+ export function gitFacts(dir, args, env = process.env) {
38
+ const checkout = checkoutOf(dir);
39
+ if (checkout === null || isPartialClone(checkout.top))
40
+ return null;
41
+ // Four fixed variables, set after both spreads so neither the process env
42
+ // nor the caller's can override them (R42.1): no replace ref answering for
43
+ // another tree, no lazy fetch of a missing object, no transport of any kind,
44
+ // and no credential prompt. A hook never uses the network. An explicit
45
+ // `core.useReplaceRefs=true` (repo, global or env config) outranks
46
+ // GIT_NO_REPLACE_OBJECTS, so the command line, read last, turns it off (R42.2).
47
+ return git(dir, ["-c", "core.useReplaceRefs=false", ...args], factsGitBudgetMs(env), {
48
+ ...process.env,
49
+ ...env,
50
+ GIT_NO_REPLACE_OBJECTS: "1",
51
+ GIT_ALLOW_PROTOCOL: "none",
52
+ GIT_NO_LAZY_FETCH: "1",
53
+ GIT_TERMINAL_PROMPT: "0",
54
+ });
55
+ }
56
+ /** Whether each checkout is a partial clone, by its top, decided once per process. */
57
+ const partialClones = new Map();
58
+ /**
59
+ * Whether the checkout at `top` is a partial clone (or not known not to be,
60
+ * R40.3): its shared git dir holds a promisor pack (`objects/pack/*.promisor`),
61
+ * or its config includes another file (`[include]`, `[includeIf]`: what that
62
+ * file says is not read) or has any `promisor`, `partialclonefilter` or
63
+ * `partialclone` key, whatever its value. Git there could fetch a missing
64
+ * object over the network, which a hook never does on any git version. Read
65
+ * as files, no git run. A git dir, pack folder or config that cannot be read
66
+ * counts as partial.
67
+ */
68
+ function isPartialClone(top) {
69
+ const known = partialClones.get(top);
70
+ if (known !== undefined)
71
+ return known;
72
+ const answer = (() => {
73
+ const common = commonGitDir(top);
74
+ if (common === null)
75
+ return true;
76
+ try {
77
+ if (fs.readdirSync(path.join(common, "objects", "pack")).some((name) => name.endsWith(".promisor")))
78
+ return true;
79
+ const config = fs.readFileSync(path.join(common, "config"), "utf8");
80
+ return /^\s*\[\s*include(?:if)?\b/im.test(config) || /^\s*(?:promisor|partialclonefilter|partialclone)\s*(?:[=;#]|$)/im.test(config);
81
+ }
82
+ catch {
83
+ return true;
84
+ }
85
+ })();
86
+ partialClones.set(top, answer);
87
+ return answer;
88
+ }
89
+ /** Whether git, asked in the file's folder, says it does not track `file`; false when git cannot say. */
90
+ export function untrackedFile(file, env = process.env) {
91
+ return gitFacts(path.dirname(file), ["ls-files", "-z", "--", path.basename(file)], env) === "";
92
+ }
93
+ /** How long each of the fact path's git calls may take. */
94
+ export function factsGitBudgetMs(env = process.env) {
95
+ return cooldownMs(env, "CARRICK_FACTS_DIFF_BUDGET_MS", DIFF_BUDGET_MS);
96
+ }
97
+ /**
98
+ * Where `file` differs from `HEAD`, or null when that is not known (or there
99
+ * is no difference). An untracked file counts whole only when `created`: the
100
+ * session did not see the file before this call.
101
+ */
102
+ export function changesAgainstHead(file, created, env = process.env) {
103
+ try {
104
+ const dir = path.dirname(file);
105
+ const out = gitFacts(dir, ["diff", "--no-ext-diff", "--no-textconv", "--no-color", "-U0", "HEAD", "--", path.basename(file)], env);
106
+ if (out === null)
107
+ return null;
108
+ if (out === "") {
109
+ // No difference from HEAD: a tracked file that reads the same, or one git does not track.
110
+ return created && untrackedFile(file, env) ? { whole: true } : null;
111
+ }
112
+ const lines = [];
113
+ const removed = [];
114
+ let changed = 0;
115
+ for (const header of out.matchAll(/^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/gm)) {
116
+ const was = header[1] === undefined ? 1 : Number(header[1]);
117
+ const start = Number(header[2]);
118
+ const now = header[3] === undefined ? 1 : Number(header[3]);
119
+ changed += was + now;
120
+ if (changed > MAX_DIFF_LINES)
121
+ return null;
122
+ for (let at = 0; at < now; at += 1)
123
+ lines.push(start + at);
124
+ // With nothing added, `start` is the line before the removal.
125
+ if (was > 0)
126
+ removed.push(now > 0 ? start : start + 1);
127
+ }
128
+ return lines.length > 0 || removed.length > 0 ? { lines, removed } : null;
129
+ }
130
+ catch {
131
+ return null;
132
+ }
133
+ }
134
+ //# sourceMappingURL=diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/facts/diff.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,uEAAuE;AACvE,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,0EAA0E;AAC1E,8EAA8E;AAC9E,uCAAuC;AACvC,EAAE;AACF,yEAAyE;AACzE,wEAAwE;AACxE,2EAA2E;AAC3E,2BAA2B;AAC3B,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,qEAAqE;AACrE,kCAAkC;AAElC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE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AC;YAC1C,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,EAAE,IAAI,CAAC;gBAAE,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;YAC3D,8DAA8D;YAC9D,IAAI,GAAG,GAAG,CAAC;gBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** True unless `CARRICK_FACT_LINES` is exactly `"0"`; unset, empty or any other value is on. */
2
+ export declare function factsEnabled(env?: NodeJS.ProcessEnv): boolean;
@@ -0,0 +1,9 @@
1
+ // The off-switch for the fact file: its local reads (`lines.ts`) and its
2
+ // fetch (`fetch.ts`). On by default; off only when CARRICK_FACT_LINES is
3
+ // exactly "0". With it off no hook reads, fetches or writes anything under
4
+ // `.carrick/facts/`.
5
+ /** True unless `CARRICK_FACT_LINES` is exactly `"0"`; unset, empty or any other value is on. */
6
+ export function factsEnabled(env = process.env) {
7
+ return env["CARRICK_FACT_LINES"] !== "0";
8
+ }
9
+ //# sourceMappingURL=enabled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enabled.js","sourceRoot":"","sources":["../../src/facts/enabled.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,2EAA2E;AAC3E,qBAAqB;AAErB,gGAAgG;AAChG,MAAM,UAAU,YAAY,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC/D,OAAO,GAAG,CAAC,oBAAoB,CAAC,KAAK,GAAG,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { LocalRepo } from "./store.ts";
2
+ /** After a retriable error, the next trigger may ask again this soon. */
3
+ export declare const FACTS_BUILDING_RETRY_MS = 60000;
4
+ export declare const FACTS_MARKER = "last-facts-refresh";
5
+ /** `retry`: the cloud answered a retriable error (a build in flight). */
6
+ export type RefreshOutcome = "unchanged" | "written" | "retry" | "none";
7
+ export type FactsRefreshOptions = {
8
+ env?: NodeJS.ProcessEnv;
9
+ request?: typeof fetch;
10
+ now?: number;
11
+ };
12
+ /** Each repo of the local index and where it is checked out (`.carrick/index.json`). */
13
+ export declare function localRepos(root: string): Array<{
14
+ name: string;
15
+ path: string;
16
+ remote: string | null;
17
+ }>;
18
+ /**
19
+ * The fact file's repos matched to their checkouts here. A header repo that
20
+ * is a remote (`owner/name`, as the index stores a GitHub repo) maps only to
21
+ * the one checkout whose origin names exactly that; a bare name maps only to
22
+ * the one checkout of exactly that name. No match, or more than one, leaves
23
+ * the repo unmapped: its rows are never read. Two header repos that map to
24
+ * one checkout (`api` and `owner/api`) are both left unmapped.
25
+ */
26
+ export declare function matchRepos(repos: readonly string[], local: ReturnType<typeof localRepos>): LocalRepo[];
27
+ /** Ask the cloud for the project's fact file and bring the local one up to date. Never throws. */
28
+ export declare function refreshFacts(root: string, options?: FactsRefreshOptions): Promise<RefreshOutcome>;
29
+ /**
30
+ * Start the refresh for `root` detached, at most once per `FACTS_STALE_MS`
31
+ * across every hook and session. Returns whether it started. Never throws.
32
+ */
33
+ export declare function startFactsRefresh(root: string, options?: {
34
+ env?: NodeJS.ProcessEnv;
35
+ now?: number;
36
+ start?: (command: string, args: string[], env: NodeJS.ProcessEnv) => void;
37
+ }): boolean;
38
+ /**
39
+ * One detached refresh (`refresh-run.ts`): bring the file up to date and,
40
+ * after a retriable error only, let the next trigger ask again a minute on.
41
+ * Every other outcome waits out the cooldown.
42
+ */
43
+ export declare function runFactsRefresh(root: string, options?: FactsRefreshOptions): Promise<RefreshOutcome>;
44
+ /**
45
+ * After a retriable error, move the claim back so the next trigger, a minute
46
+ * on, asks again rather than waiting out the whole cooldown.
47
+ */
48
+ export declare function allowEarlyRetry(root: string, env?: NodeJS.ProcessEnv, now?: number): void;
@@ -0,0 +1,235 @@
1
+ // The background refresh of the fact file. Never in a hook's path: a hook
2
+ // only starts it (`startFactsRefresh`), detached, and reads whatever file the
3
+ // last refresh left.
4
+ //
5
+ // One request to `POST /mcp/facts` with the stored CLI credential, sending the
6
+ // digest and writer it already holds, so an unchanged project costs one read.
7
+ // A new digest or writer answers with a presigned URL to gzipped NDJSON, which
8
+ // is fetched (no credential, https amazonaws.com only), built into SQLite
9
+ // under a temporary name and renamed (`store.ts`). An error answer, a 404
10
+ // (route not deployed) and every other failure mean no new facts: one log
11
+ // line. Only an error marked `retriable: true` (a build in flight, whatever
12
+ // its code) moves the next ask a minute on (`runFactsRefresh`); the rest wait
13
+ // out the cooldown. The code is logged, never branched on: one code is sent
14
+ // both ways.
15
+ // Wire contract: carrick-cloud `docs/internal/reference/edit-facts-wire.md`.
16
+ import fs from "node:fs";
17
+ import path from "node:path";
18
+ import zlib from "node:zlib";
19
+ import { API_BASE, readCredential } from "../auth/credentials.js";
20
+ import { createLogger } from "../log.js";
21
+ import { hasMarker } from "../root.js";
22
+ import { claimRefresh, cooldownMs, markerPath, scriptBeside, startDetached } from "../hook/refresh.js";
23
+ import { snapshotProjectSlug } from "../hook/reuse.js";
24
+ import { splitRemote } from "../git-remote.js";
25
+ import { factsEnabled } from "./enabled.js";
26
+ import { buildFacts, closeQuietly, FACTS_STALE_MS, factsPath, loadSqlite, SCHEMA, touchFetched } from "./store.js";
27
+ const log = createLogger("carrick-facts");
28
+ /** After a retriable error, the next trigger may ask again this soon. */
29
+ export const FACTS_BUILDING_RETRY_MS = 60_000;
30
+ export const FACTS_MARKER = "last-facts-refresh";
31
+ /** Each repo of the local index and where it is checked out (`.carrick/index.json`). */
32
+ export function localRepos(root) {
33
+ try {
34
+ const index = JSON.parse(fs.readFileSync(path.join(root, ".carrick", "index.json"), "utf8"));
35
+ return (index.repos ?? [])
36
+ .filter((repo) => typeof repo.name === "string" && typeof repo.path === "string")
37
+ .map((repo) => {
38
+ const remote = (repo.services ?? []).map((service) => service.enrichment?.remote).find((value) => typeof value === "string");
39
+ return { name: repo.name, path: repo.path, remote: remote ?? null };
40
+ });
41
+ }
42
+ catch {
43
+ return [];
44
+ }
45
+ }
46
+ /**
47
+ * The fact file's repos matched to their checkouts here. A header repo that
48
+ * is a remote (`owner/name`, as the index stores a GitHub repo) maps only to
49
+ * the one checkout whose origin names exactly that; a bare name maps only to
50
+ * the one checkout of exactly that name. No match, or more than one, leaves
51
+ * the repo unmapped: its rows are never read. Two header repos that map to
52
+ * one checkout (`api` and `owner/api`) are both left unmapped.
53
+ */
54
+ export function matchRepos(repos, local) {
55
+ const out = [];
56
+ for (const repo of repos) {
57
+ const found = repo.includes("/")
58
+ ? local.filter((entry) => entry.remote !== null && ownerName(entry.remote) === repo)
59
+ : local.filter((entry) => entry.name === repo);
60
+ if (found.length === 1)
61
+ out.push({ repo, path: found[0].path });
62
+ }
63
+ return out.filter((entry) => out.filter((other) => other.path === entry.path).length === 1);
64
+ }
65
+ /** The `owner/name` an origin names, in either spelling git accepts, or the text itself. */
66
+ function ownerName(remote) {
67
+ return splitRemote(remote)?.name ?? remote;
68
+ }
69
+ /** Whether a staged URL is https on an `amazonaws.com` host (a presigned S3 URL). */
70
+ function stagedUrlAllowed(url) {
71
+ try {
72
+ const parsed = new URL(url);
73
+ return parsed.protocol === "https:" && parsed.hostname.endsWith(".amazonaws.com");
74
+ }
75
+ catch {
76
+ return false;
77
+ }
78
+ }
79
+ /**
80
+ * The digest and writer of the local fact file, or null when there is no
81
+ * readable file holding both. The cloud answers `unchanged` only when both
82
+ * match, so a wording fix (a new writer) reaches this file without a new scan.
83
+ */
84
+ async function knownFile(root) {
85
+ const file = factsPath(root);
86
+ if (!fs.existsSync(file))
87
+ return null;
88
+ const sqlite = await loadSqlite();
89
+ if (!sqlite)
90
+ return null;
91
+ let db = null;
92
+ try {
93
+ const open = new sqlite.DatabaseSync(file, { readOnly: true });
94
+ db = open;
95
+ const meta = new Map(open.prepare("SELECT key, value FROM meta WHERE key IN ('digest', 'writer')").all().map((raw) => [String(raw["key"]), String(raw["value"])]));
96
+ const digest = meta.get("digest");
97
+ const writer = Number(meta.get("writer"));
98
+ return digest && Number.isInteger(writer) ? { digest, writer } : null;
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ finally {
104
+ closeQuietly(db);
105
+ }
106
+ }
107
+ /** Ask the cloud for the project's fact file and bring the local one up to date. Never throws. */
108
+ export async function refreshFacts(root, options = {}) {
109
+ const env = options.env ?? process.env;
110
+ if (!factsEnabled(env))
111
+ return "none";
112
+ const request = options.request ?? fetch;
113
+ const now = new Date(options.now ?? Date.now()).toISOString();
114
+ try {
115
+ const credential = readCredential(env);
116
+ if (!credential) {
117
+ log("not signed in; no fact file");
118
+ return "none";
119
+ }
120
+ const project = snapshotProjectSlug(root);
121
+ if (!project) {
122
+ log("no single project for this workspace; no fact file");
123
+ return "none";
124
+ }
125
+ const known = await knownFile(root);
126
+ const response = await request(`${API_BASE}/mcp/facts`, {
127
+ method: "POST",
128
+ redirect: "error",
129
+ signal: AbortSignal.timeout(30_000),
130
+ headers: { Authorization: `Bearer ${credential.token}`, "Content-Type": "application/json" },
131
+ body: JSON.stringify({ project, schema: SCHEMA, ...(known ? { known_digest: known.digest, known_writer: known.writer } : {}) }),
132
+ });
133
+ if (response.status === 404) {
134
+ log("facts route not found; no fact file");
135
+ return "none";
136
+ }
137
+ let answer;
138
+ try {
139
+ answer = (await response.json());
140
+ }
141
+ catch {
142
+ log(`facts answer not JSON (HTTP ${response.status})`);
143
+ return "none";
144
+ }
145
+ const error = answer["error"];
146
+ if (answer["success"] === false || !response.ok) {
147
+ const code = typeof error?.code === "string" ? error.code : `HTTP ${response.status}`;
148
+ const retriable = error?.retriable === true;
149
+ log(`facts not available: ${code}${retriable ? " (retriable)" : ""}`);
150
+ return retriable ? "retry" : "none";
151
+ }
152
+ if (answer["unchanged"] === true) {
153
+ await touchFetched(root, now);
154
+ return "unchanged";
155
+ }
156
+ const url = answer["staged_url"];
157
+ if (typeof url !== "string") {
158
+ log("facts answer carries no staged_url");
159
+ return "none";
160
+ }
161
+ // The staged file is fetched with no credential, so only from where the cloud stages it.
162
+ if (!stagedUrlAllowed(url)) {
163
+ log("facts staged_url is not an https amazonaws.com URL; not fetched");
164
+ return "none";
165
+ }
166
+ const staged = await request(url, { redirect: "error", signal: AbortSignal.timeout(60_000) });
167
+ if (!staged.ok) {
168
+ log(`staged fact file not fetched (HTTP ${staged.status})`);
169
+ return "none";
170
+ }
171
+ const bytes = Buffer.from(await staged.arrayBuffer());
172
+ const gzipped = bytes.length >= 2 && bytes[0] === 0x1f && bytes[1] === 0x8b;
173
+ const text = (gzipped ? zlib.gunzipSync(bytes) : bytes).toString("utf8");
174
+ const header = JSON.parse(text.slice(0, text.indexOf("\n") >>> 0));
175
+ const names = (header.repos ?? []).map((repo) => repo.repo).filter((repo) => typeof repo === "string");
176
+ const built = await buildFacts(text, factsPath(root), matchRepos(names, localRepos(root)), now);
177
+ return built ? "written" : "none";
178
+ }
179
+ catch (error) {
180
+ log("fact refresh failed", String(error));
181
+ return "none";
182
+ }
183
+ }
184
+ /**
185
+ * Start the refresh for `root` detached, at most once per `FACTS_STALE_MS`
186
+ * across every hook and session. Returns whether it started. Never throws.
187
+ */
188
+ export function startFactsRefresh(root, options = {}) {
189
+ const env = options.env ?? process.env;
190
+ if (!factsEnabled(env))
191
+ return false;
192
+ if (env["CARRICK_NO_FACTS_REFRESH"])
193
+ return false;
194
+ // A folder Carrick was never set up in gets nothing, not even a marker directory.
195
+ if (!hasMarker(root))
196
+ return false;
197
+ try {
198
+ const cooldown = cooldownMs(env, "CARRICK_FACTS_COOLDOWN_MS", FACTS_STALE_MS);
199
+ if (!claimRefresh(markerPath(root, FACTS_MARKER), options.now ?? Date.now(), cooldown))
200
+ return false;
201
+ const { command, args } = scriptBeside(import.meta.url, "refresh-run", root);
202
+ (options.start ?? startDetached)(command, args, { ...env, CARRICK_NO_KEEP_AWAKE: "1" });
203
+ return true;
204
+ }
205
+ catch (error) {
206
+ log("fact refresh not started", String(error));
207
+ return false;
208
+ }
209
+ }
210
+ /**
211
+ * One detached refresh (`refresh-run.ts`): bring the file up to date and,
212
+ * after a retriable error only, let the next trigger ask again a minute on.
213
+ * Every other outcome waits out the cooldown.
214
+ */
215
+ export async function runFactsRefresh(root, options = {}) {
216
+ const outcome = await refreshFacts(root, options);
217
+ log(`fact refresh: ${outcome}`);
218
+ if (outcome === "retry")
219
+ allowEarlyRetry(root, options.env ?? process.env, options.now ?? Date.now());
220
+ return outcome;
221
+ }
222
+ /**
223
+ * After a retriable error, move the claim back so the next trigger, a minute
224
+ * on, asks again rather than waiting out the whole cooldown.
225
+ */
226
+ export function allowEarlyRetry(root, env = process.env, now = Date.now()) {
227
+ const cooldown = cooldownMs(env, "CARRICK_FACTS_COOLDOWN_MS", FACTS_STALE_MS);
228
+ try {
229
+ fs.writeFileSync(markerPath(root, FACTS_MARKER), `${new Date(now - cooldown + FACTS_BUILDING_RETRY_MS).toISOString()}\n`);
230
+ }
231
+ catch {
232
+ // The next trigger after the full cooldown asks instead.
233
+ }
234
+ }
235
+ //# sourceMappingURL=fetch.js.map