carrick 0.3.143 → 0.3.144

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 (107) hide show
  1. package/README.md +1 -1
  2. package/bin/carrick.mjs +7 -7
  3. package/dist/auth/read.d.ts +0 -10
  4. package/dist/auth/read.js +3 -11
  5. package/dist/auth/read.js.map +1 -1
  6. package/dist/cli.d.ts +23 -20
  7. package/dist/cli.js +17 -32
  8. package/dist/cli.js.map +1 -1
  9. package/dist/contract.d.ts +54 -0
  10. package/dist/contract.js +14 -0
  11. package/dist/contract.js.map +1 -1
  12. package/dist/hook/checked.d.ts +11 -0
  13. package/dist/hook/checked.js +44 -0
  14. package/dist/hook/checked.js.map +1 -0
  15. package/dist/hook/edited.d.ts +22 -0
  16. package/dist/hook/edited.js +84 -0
  17. package/dist/hook/edited.js.map +1 -0
  18. package/dist/hook/invoker.d.ts +7 -0
  19. package/dist/hook/invoker.js +18 -0
  20. package/dist/hook/invoker.js.map +1 -0
  21. package/dist/hook/late.d.ts +8 -0
  22. package/dist/hook/late.js +60 -0
  23. package/dist/hook/late.js.map +1 -0
  24. package/dist/hook/post-edit.d.ts +0 -22
  25. package/dist/hook/post-edit.js +78 -126
  26. package/dist/hook/post-edit.js.map +1 -1
  27. package/dist/hook/post-read.js +19 -9
  28. package/dist/hook/post-read.js.map +1 -1
  29. package/dist/hook/probe.d.ts +15 -0
  30. package/dist/hook/probe.js +41 -0
  31. package/dist/hook/probe.js.map +1 -0
  32. package/dist/hook/recheck-run.d.ts +2 -0
  33. package/dist/hook/recheck-run.js +28 -0
  34. package/dist/hook/recheck-run.js.map +1 -0
  35. package/dist/hook/rechecks.d.ts +108 -0
  36. package/dist/hook/rechecks.js +537 -0
  37. package/dist/hook/rechecks.js.map +1 -0
  38. package/dist/hook/refresh.d.ts +1 -0
  39. package/dist/hook/refresh.js +1 -1
  40. package/dist/hook/refresh.js.map +1 -1
  41. package/dist/hook/reuse.d.ts +15 -3
  42. package/dist/hook/reuse.js +31 -11
  43. package/dist/hook/reuse.js.map +1 -1
  44. package/dist/hook/session-start.js +14 -0
  45. package/dist/hook/session-start.js.map +1 -1
  46. package/dist/hook/stop-wait.d.ts +17 -0
  47. package/dist/hook/stop-wait.js +120 -0
  48. package/dist/hook/stop-wait.js.map +1 -0
  49. package/dist/hook/stop.js +12 -1
  50. package/dist/hook/stop.js.map +1 -1
  51. package/dist/hook/user-prompt.js +4 -1
  52. package/dist/hook/user-prompt.js.map +1 -1
  53. package/dist/init/agents-section.js +1 -3
  54. package/dist/init/agents-section.js.map +1 -1
  55. package/dist/init/connect.d.ts +6 -107
  56. package/dist/init/connect.js +7 -318
  57. package/dist/init/connect.js.map +1 -1
  58. package/dist/init/doctor.d.ts +8 -71
  59. package/dist/init/doctor.js +37 -223
  60. package/dist/init/doctor.js.map +1 -1
  61. package/dist/init/hosted.d.ts +7 -7
  62. package/dist/init/hosted.js +8 -10
  63. package/dist/init/hosted.js.map +1 -1
  64. package/dist/init/outdated.d.ts +11 -0
  65. package/dist/init/outdated.js +1 -1
  66. package/dist/init/outdated.js.map +1 -1
  67. package/dist/init/output.d.ts +0 -55
  68. package/dist/init/output.js +0 -142
  69. package/dist/init/output.js.map +1 -1
  70. package/dist/init/projects.d.ts +3 -200
  71. package/dist/init/projects.js +22 -352
  72. package/dist/init/projects.js.map +1 -1
  73. package/dist/init/remove.js +4 -5
  74. package/dist/init/remove.js.map +1 -1
  75. package/dist/init/repos.d.ts +25 -53
  76. package/dist/init/repos.js +28 -65
  77. package/dist/init/repos.js.map +1 -1
  78. package/dist/init/run.d.ts +52 -212
  79. package/dist/init/run.js +247 -987
  80. package/dist/init/run.js.map +1 -1
  81. package/dist/init/self-update.d.ts +18 -0
  82. package/dist/init/self-update.js +147 -0
  83. package/dist/init/self-update.js.map +1 -0
  84. package/dist/init/settings.d.ts +2 -0
  85. package/dist/init/settings.js +13 -2
  86. package/dist/init/settings.js.map +1 -1
  87. package/dist/render.d.ts +24 -6
  88. package/dist/render.js +133 -42
  89. package/dist/render.js.map +1 -1
  90. package/dist/templates.d.ts +1 -6
  91. package/dist/templates.js +4 -14
  92. package/dist/templates.js.map +1 -1
  93. package/package.json +6 -6
  94. package/plugin/.claude-plugin/plugin.json +1 -1
  95. package/plugin/hooks/hooks.json +3 -2
  96. package/sidecar/dist/src/capture/api.d.ts +2 -2
  97. package/sidecar/dist/src/capture/deno-project.js +5 -1
  98. package/sidecar/dist/src/index.js +1 -1
  99. package/sidecar/dist/src/library-claims.d.ts +4 -0
  100. package/sidecar/dist/src/library-claims.js +2 -2
  101. package/sidecar/dist/src/project-loader.js +9 -2
  102. package/sidecar/dist/src/type-inferrer.d.ts +17 -2
  103. package/sidecar/dist/src/type-inferrer.js +59 -16
  104. package/sidecar/dist/src/types.d.ts +26 -0
  105. package/sidecar/dist/src/validators.d.ts +6 -0
  106. package/sidecar/dist/src/validators.js +2 -0
  107. package/templates/carrick.json +0 -7
@@ -0,0 +1,18 @@
1
+ // Who started a `carrick` process: a hook, or a person at a shell.
2
+ //
3
+ // A hook runs `carrick check` or `carrick status` on the user's machine, and
4
+ // the binary's cloud requests carry the answer in `x-carrick-invoker`, so a
5
+ // hook fire is a line in the cloud's log rather than a guess. The binary reads
6
+ // `CARRICK_INVOKER` (src/invoker.rs); absent or unknown means `cli`. A hook
7
+ // sets it once at its entry: every spawn after that, attached or detached,
8
+ // inherits the process environment.
9
+ export const INVOKER_ENV = "CARRICK_INVOKER";
10
+ /** The value the binary sends for a hook. */
11
+ export function invokerValue(hook) {
12
+ return `hook:${hook}`;
13
+ }
14
+ /** Mark this process, and every child it spawns, as started by `hook`. */
15
+ export function markInvoker(hook, env = process.env) {
16
+ env[INVOKER_ENV] = invokerValue(hook);
17
+ }
18
+ //# sourceMappingURL=invoker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoker.js","sourceRoot":"","sources":["../../src/hook/invoker.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,+EAA+E;AAC/E,4EAA4E;AAC5E,2EAA2E;AAC3E,oCAAoC;AAKpC,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE7C,6CAA6C;AAC7C,MAAM,UAAU,YAAY,CAAC,IAAiB;IAC5C,OAAO,QAAQ,IAAI,EAAE,CAAC;AACxB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,IAAiB,EAAE,MAAyB,OAAO,CAAC,GAAG;IACjF,GAAG,CAAC,WAAW,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Answer } from "./rechecks.ts";
2
+ /** The words for one finished answer, or null when there is nothing to say. */
3
+ export declare function lateContext(answer: Answer, uses: boolean, settled?: boolean): string | null;
4
+ /**
5
+ * Claim and render every finished answer this session has not been given.
6
+ * Returns the contexts to print, oldest first. Nothing here throws.
7
+ */
8
+ export declare function deliverLate(session: string | undefined, now?: number): string[];
@@ -0,0 +1,60 @@
1
+ // Late delivery: what a carrier prints for background re-checks that finished.
2
+ //
3
+ // The post-edit hook queues an edit it could not answer in hand (rechecks.ts);
4
+ // the runner writes the answer to the session's files. Every carrier (the next
5
+ // post-edit, a Read, Codex's next prompt) calls `deliverLate` before its own
6
+ // early returns, so a finished answer reaches the model at the next moment
7
+ // any hook speaks. Each answer is claimed with `claimDelivery`, so parallel
8
+ // hooks print it once.
9
+ import { createLogger } from "../log.js";
10
+ import { answersTheEdit, notRecheckedLine, renderPostToolUse } from "../render.js";
11
+ import { claimDelivery, finishedFor } from "./rechecks.js";
12
+ import { checkedSinceLastEdit } from "./checked.js";
13
+ import { markTold, toldKey, wasTold } from "./reuse.js";
14
+ const log = createLogger("carrick-late");
15
+ /** The words for one finished answer, or null when there is nothing to say. */
16
+ export function lateContext(answer, uses, settled = false) {
17
+ if (!answer.result) {
18
+ // An internal failure is logged, never shown: the reader needs the next step.
19
+ const reason = answer.state === "stopped" ? (answer.failure ?? "the background re-check stopped") : "the background re-check gave no answer";
20
+ return notRecheckedLine(answer.relative, reason, settled);
21
+ }
22
+ if (answer.result.error)
23
+ return null;
24
+ if (!answersTheEdit(answer.result)) {
25
+ return notRecheckedLine(answer.relative, answer.result.recheck?.reason, settled);
26
+ }
27
+ return renderPostToolUse(answer.result, answer.relative, { uses, late: true, settled });
28
+ }
29
+ /**
30
+ * Claim and render every finished answer this session has not been given.
31
+ * Returns the contexts to print, oldest first. Nothing here throws.
32
+ */
33
+ export function deliverLate(session, now = Date.now()) {
34
+ if (!session)
35
+ return [];
36
+ const contexts = [];
37
+ try {
38
+ for (const answer of finishedFor(session)) {
39
+ if (!claimDelivery(session, answer.seq, undefined, now))
40
+ continue;
41
+ if (answer.failure)
42
+ log("background re-check failed", answer.relative, answer.failure);
43
+ const key = answer.result ? toldKey(answer.result, answer.relative) : null;
44
+ const uses = key === null || !wasTold(session, key);
45
+ const context = lateContext(answer, uses, checkedSinceLastEdit(session, answer.root));
46
+ const seconds = Math.round((now - Date.parse(answer.enqueued_at)) / 1000);
47
+ log(`late answer ${answer.relative} delivered ${seconds} s after the edit`);
48
+ if (!context)
49
+ continue;
50
+ contexts.push(context);
51
+ if (key !== null && uses && answer.result?.uses_lines?.length)
52
+ markTold(session, [key]);
53
+ }
54
+ }
55
+ catch (error) {
56
+ log("late delivery failed", String(error));
57
+ }
58
+ return contexts;
59
+ }
60
+ //# sourceMappingURL=late.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"late.js","sourceRoot":"","sources":["../../src/hook/late.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,uBAAuB;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAA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EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,8 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import type { CheckResult } from "../contract.ts";
3
- import type { NewFunction } from "./reuse.ts";
4
- /** Whether `carrick check --changed` would judge this edited file: source, and not a test or story. */
5
- export declare function isCheckedSource(file: string): boolean;
6
2
  type Payload = {
7
3
  cwd?: string;
8
4
  session_id?: string;
@@ -16,24 +12,6 @@ type Payload = {
16
12
  command?: unknown;
17
13
  };
18
14
  };
19
- /**
20
- * What the re-check said this file declares and the index does not
21
- * (carrick#1330).
22
- *
23
- * Nothing is printed about it here. This hook fires on every edit and most
24
- * edits add no function; the one line about the ones that did belongs at the
25
- * end of the task, where it costs one model turn instead of one per edit. All
26
- * this does is put the names somewhere the Stop hook can find them.
27
- */
28
- export declare function newFunctions(result: CheckResult, file: string): NewFunction[];
29
- /**
30
- * `file` relative to the nearest checkout top at or below `root`: the nearest
31
- * directory holding `.git` (a folder, or the file a linked worktree has). An
32
- * edit inside a nested worktree is then keyed as the index keys it, not with
33
- * the worktree's own prefix (carrick#2936). With no nested checkout it is
34
- * relative to `root`, as before.
35
- */
36
- export declare function checkoutRelative(root: string, file: string): string;
37
15
  /**
38
16
  * Every file one tool call left on disk, whichever host made it.
39
17
  *
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  // PostToolUse hook for a file edit, on either host.
3
3
  //
4
- // Reads the tool payload on stdin, runs `carrick check <file> --json` from the
5
- // workspace root and prints what the edit needs acted on (`renderPostToolUse`:
6
- // its problems, or a pointer to `carrick check --changed` when the file could
7
- // not be re-checked) as `additionalContext`, which the host
8
- // attaches to the tool result. Attaching to the result rather than to the next
4
+ // Reads the tool payload on stdin and asks the binary once, from the workspace
5
+ // root, with a probe that never starts a re-scan (`probe.ts`). An answer in
6
+ // hand prints what the edit needs acted on (`renderPostToolUse`: its problems,
7
+ // or why it was not re-checked); an edit that needs a re-scan is queued for the
8
+ // background runner (`rechecks.ts`), prints one pending line, and its answer is
9
+ // delivered by the next carrier (`late.ts`). Output is `additionalContext`,
10
+ // which the host attaches to the tool result. Attaching to the result rather than to the next
9
11
  // turn is why this channel has no "the run ended on the edit" hole.
10
12
  //
11
13
  // Two payload shapes reach it, because the two hosts edit differently
@@ -16,95 +18,23 @@
16
18
  //
17
19
  // It exits 0 whatever happens. An edit never fails because Carrick had nothing
18
20
  // to say, could not find its binary, or timed out.
19
- import fs from "node:fs";
20
21
  import path from "node:path";
21
- import { check, checkEach } from "../cli.js";
22
22
  import { resolveChannel } from "../channel.js";
23
23
  import { createLogger } from "../log.js";
24
- import { answersTheEdit, notedLine, renderPostToolUse } from "../render.js";
24
+ import { answersTheEdit, notRecheckedLine, pendingLine, renderPostToolUse } from "../render.js";
25
25
  import { resolveRoot, rootNote } from "../root.js";
26
26
  import { patchedFiles } from "./apply-patch.js";
27
27
  import { throttledVersionMismatch } from "../init/outdated.js";
28
28
  import { currentVersion } from "../update.js";
29
- import { markTold, NOTED_KEY, record, toldKey, wasTold } from "./reuse.js";
29
+ import { markTold, record, recordEdit, toldKey, wasTold } from "./reuse.js";
30
+ import { checkoutRelative, newFunctions } from "./edited.js";
31
+ import { markInvoker } from "./invoker.js";
32
+ import { deliverLate } from "./late.js";
33
+ import { needsBackground, probeEdits } from "./probe.js";
34
+ import { enqueue, ensureRunner } from "./rechecks.js";
30
35
  const log = createLogger("carrick-hook");
31
- /**
32
- * The files `carrick check --changed` judges: the scanner's own source
33
- * extensions (`SOURCE_EXTENSIONS` in `src/file_finder.rs`, carrick#904). An API
34
- * spec file is not counted: the hook cannot tell a spec the scan reads from any
35
- * other `.json` or `.yaml` without reading the repo, and a config file that
36
- * moves no contract is what the line used to be wrong about.
37
- */
38
- const CHECKED_EXTENSIONS = new Set([".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"]);
39
- /** `TEST_FILE_INFIXES` in `src/file_finder.rs`: a test or story file name ends its stem in one. */
40
- const TEST_FILE_INFIXES = [".test", ".spec", ".stories"];
41
- /** `TEST_DIR_NAMES` in `src/file_finder.rs` (plus `.storybook`): trees the scan does not read. */
42
- const TEST_DIR_NAMES = new Set([
43
- "__tests__",
44
- "__mocks__",
45
- "__fixtures__",
46
- "tests",
47
- "test",
48
- "fixtures",
49
- "e2e",
50
- ".storybook",
51
- ]);
52
- /** Whether `carrick check --changed` would judge this edited file: source, and not a test or story. */
53
- export function isCheckedSource(file) {
54
- const extension = path.extname(file).toLowerCase();
55
- if (!CHECKED_EXTENSIONS.has(extension))
56
- return false;
57
- const stem = path.basename(file, extension).toLowerCase();
58
- if (TEST_FILE_INFIXES.some((infix) => stem.endsWith(infix)))
59
- return false;
60
- // Directory names above the file. The scanner reads them relative to the
61
- // scan root; the hook does not know it, so a checkout under a directory
62
- // named `test` hides its source here: the line is then missing, not wrong.
63
- const directories = path.dirname(file).split(/[\\/]/);
64
- return !directories.some((name) => TEST_DIR_NAMES.has(name.toLowerCase()));
65
- }
66
36
  /** The files the index has rows for. */
67
- const CHECKED = /\.(ts|tsx|mts|cts)$/;
68
- /**
69
- * What the re-check said this file declares and the index does not
70
- * (carrick#1330).
71
- *
72
- * Nothing is printed about it here. This hook fires on every edit and most
73
- * edits add no function; the one line about the ones that did belongs at the
74
- * end of the task, where it costs one model turn instead of one per edit. All
75
- * this does is put the names somewhere the Stop hook can find them.
76
- */
77
- export function newFunctions(result, file) {
78
- // Test, spec and story files never warrant a reuse check (carrick#2936).
79
- if (!isCheckedSource(file))
80
- return [];
81
- return (result.recheck?.new_functions ?? []).map((entry) => ({
82
- name: entry.name,
83
- // The path this hook computed, not the one the binary echoes: it is the
84
- // checkout-relative path the index holds, whatever root the edit ran from.
85
- file,
86
- indexCommit: result.index_commit ?? "",
87
- }));
88
- }
89
- /**
90
- * `file` relative to the nearest checkout top at or below `root`: the nearest
91
- * directory holding `.git` (a folder, or the file a linked worktree has). An
92
- * edit inside a nested worktree is then keyed as the index keys it, not with
93
- * the worktree's own prefix (carrick#2936). With no nested checkout it is
94
- * relative to `root`, as before.
95
- */
96
- export function checkoutRelative(root, file) {
97
- let dir = path.dirname(file);
98
- while (dir !== root && path.relative(root, dir) && !path.relative(root, dir).startsWith("..")) {
99
- if (fs.existsSync(path.join(dir, ".git")))
100
- return path.relative(dir, file);
101
- const parent = path.dirname(dir);
102
- if (parent === dir)
103
- break;
104
- dir = parent;
105
- }
106
- return path.relative(root, file);
107
- }
37
+ const CHECKED = /\.(ts|tsx|mts|cts|graphql|gql)$/;
108
38
  /**
109
39
  * Every file one tool call left on disk, whichever host made it.
110
40
  *
@@ -126,19 +56,6 @@ export function filesFromPayload(payload) {
126
56
  return [named];
127
57
  return typeof input.command === "string" ? patchedFiles(input.command) : [];
128
58
  }
129
- /**
130
- * Every edited file's answer, in order, from one binary call: the
131
- * single-file `check` for one file (what Claude Code's edits always are), and
132
- * `check --each` for a patch that touches several.
133
- */
134
- async function answersFor(relatives, cwd) {
135
- if (relatives.length === 1) {
136
- const outcome = await check(relatives[0], { cwd, recheck: true });
137
- return { results: [outcome.result], failure: outcome.failure, ms: outcome.ms };
138
- }
139
- const outcome = await checkEach(relatives, { cwd });
140
- return { results: outcome.result ?? [], failure: outcome.failure, ms: outcome.ms };
141
- }
142
59
  function emit(context) {
143
60
  process.stdout.write(JSON.stringify({
144
61
  hookSpecificOutput: {
@@ -154,6 +71,7 @@ async function readStdin() {
154
71
  return Buffer.concat(chunks).toString("utf8");
155
72
  }
156
73
  async function main() {
74
+ markInvoker("post-edit");
157
75
  // `off` stops the work as well as the printing. `lsp` stops only the
158
76
  // printing: it decides which surface delivers a verdict, and the reuse
159
77
  // record below is not a verdict — it is what the Stop hook speaks from, and
@@ -177,8 +95,17 @@ async function main() {
177
95
  const edited = filesFromPayload(payload)
178
96
  .filter((file) => CHECKED.test(file))
179
97
  .map((file) => (path.isAbsolute(file) ? file : path.resolve(cwd ?? process.cwd(), file)));
180
- if (edited.length === 0)
98
+ const session = payload.session_id;
99
+ if (edited.length === 0) {
100
+ // Nothing of ours to check in this edit, but a finished background answer
101
+ // is still owed to the model (B3: every carrier delivers).
102
+ if (channel.channel === "hook") {
103
+ const late = deliverLate(session);
104
+ if (late.length > 0)
105
+ emit(late.join("\n\n"));
106
+ }
181
107
  return;
108
+ }
182
109
  // One root for the call: every file in one patch is in the workspace the tool
183
110
  // ran in, and resolving it per file would ask the same question repeatedly.
184
111
  const choice = resolveRoot({
@@ -189,6 +116,10 @@ async function main() {
189
116
  const note = rootNote(choice);
190
117
  if (note)
191
118
  log(note);
119
+ // Stamped before any line is built: a `carrick check --changed` that began
120
+ // earlier did not read this edit (`checked.ts`).
121
+ if (session)
122
+ recordEdit(session, choice.root, Date.now());
192
123
  const found = [];
193
124
  const contexts = [];
194
125
  // Files whose uses lines this message carries, remembered only once it is
@@ -196,47 +127,68 @@ async function main() {
196
127
  const told = [];
197
128
  const relatives = edited.map((file) => path.relative(choice.root, file));
198
129
  // The edit just landed, so the index describes the file as it was before
199
- // it. This is the one surface that asks for the file to be re-judged from
200
- // the working tree; it fires once per completed edit, where the language
201
- // server fires on every save (carrick#1036). A patch of several files is
202
- // one binary call, not one per file: each call re-reads the index and, on a
203
- // repo whose re-check does not fit, would wait out a budget of its own.
204
- const answers = await answersFor(relatives, choice.root);
205
- // Files of this call the re-check did not answer for: one line names them
206
- // all, rather than the same sentence once per file of a patch.
207
- const unchecked = [];
130
+ // it. The hook asks the binary once, with a probe that never starts a
131
+ // re-scan: an answer that needs none (the file reads the same, no service
132
+ // reads it, a known miss) comes back at once and prints below. Every other
133
+ // file is queued for the background runner (carrick#3198).
134
+ const answers = await probeEdits(relatives, choice.root);
135
+ const queueable = channel.channel === "hook" && Boolean(session);
136
+ const toQueue = [];
137
+ const rendered = new Map();
208
138
  for (const [index, relative] of relatives.entries()) {
209
139
  const result = answers.results[index] ?? null;
210
140
  if (!result) {
211
- // One unreadable file in a patch of four is not a reason to say nothing
212
- // about the other three.
141
+ // A probe with no answer queues every file; one unreadable file in a
142
+ // patch of four is no reason to say nothing about the other three.
213
143
  log("no answer for", relative, answers.failure ?? "");
144
+ if (queueable)
145
+ toQueue.push(index);
214
146
  continue;
215
147
  }
216
148
  found.push(...newFunctions(result, checkoutRelative(choice.root, edited[index])));
149
+ if (queueable && needsBackground(result)) {
150
+ toQueue.push(index);
151
+ continue;
152
+ }
217
153
  const key = toldKey(result, relative);
218
- const show = !payload.session_id || !wasTold(payload.session_id, key);
154
+ const show = !session || !wasTold(session, key);
219
155
  if (show && result.uses_lines?.length)
220
156
  told.push(key);
221
- if (!result.error && !answersTheEdit(result))
222
- unchecked.push(relative);
223
- const context = renderPostToolUse(result, relative, { uses: show, noted: false });
157
+ const context = renderPostToolUse(result, relative, { uses: show });
224
158
  log(`check ${relative} -> ${context ? "context" : "nothing to say"} in ${answers.ms}ms`);
225
159
  if (context)
226
- contexts.push(context);
160
+ rendered.set(index, context);
161
+ }
162
+ if (toQueue.length > 0 && session) {
163
+ const entries = enqueue(choice.root, session, toQueue.map((index) => edited[index]), Date.now());
164
+ if (entries.length > 0)
165
+ ensureRunner(choice.root);
166
+ const queued = new Set(entries.map((entry) => entry.file));
167
+ for (const index of toQueue) {
168
+ const result = answers.results[index] ?? null;
169
+ if (queued.has(edited[index])) {
170
+ rendered.set(index, pendingLine(relatives[index], result?.service));
171
+ }
172
+ else {
173
+ // The queue refused it: say what is true rather than nothing.
174
+ rendered.set(index, notRecheckedLine(relatives[index], result?.recheck?.reason));
175
+ }
176
+ }
227
177
  }
228
- // Said once per session: the sentence is the same on every edit, and the
229
- // Stop hook asks again if the check never ran.
230
- const notedAlready = payload.session_id ? wasTold(payload.session_id, NOTED_KEY) : false;
231
- if (unchecked.length > 0 && !notedAlready) {
232
- contexts.unshift(notedLine(unchecked));
233
- told.push(NOTED_KEY);
178
+ // Delivered after this edit is queued, so an older answer for a file this
179
+ // edit queues again is skipped (the newer entry carries it).
180
+ const late = channel.channel === "hook" ? deliverLate(session) : [];
181
+ contexts.push(...late);
182
+ for (const index of relatives.keys()) {
183
+ const context = rendered.get(index);
184
+ if (context)
185
+ contexts.push(context);
234
186
  }
235
187
  // Silent and local: the names go to a file under the user's home directory
236
188
  // and nothing about them is printed here.
237
- if (found.length > 0 && payload.session_id) {
238
- record(payload.session_id, found);
239
- log(`recorded ${found.length} new function(s) for ${payload.session_id}`);
189
+ if (found.length > 0 && session) {
190
+ record(session, found);
191
+ log(`recorded ${found.length} new function(s) for ${session}`);
240
192
  }
241
193
  if (channel.channel !== "hook") {
242
194
  log(`the ${channel.channel} channel owns delivery in this install; printing nothing`);
@@ -250,8 +202,8 @@ async function main() {
250
202
  const mismatch = throttledVersionMismatch(choice.root, currentVersion());
251
203
  if (mismatch)
252
204
  contexts.push(mismatch);
253
- if (told.length > 0 && payload.session_id)
254
- markTold(payload.session_id, told);
205
+ if (told.length > 0 && session)
206
+ markTold(session, told);
255
207
  if (contexts.length > 0)
256
208
  emit(contexts.join("\n\n"));
257
209
  }
@@ -1 +1 @@
1
- {"version":3,"file":"post-edit.js","sourceRoot":"","sources":["../../src/hook/post-edit.ts"],"names":[],"mappings":";AACA,oDAAoD;AACpD,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,4DAA4D;AAC5D,+EAA+E;AAC/E,oEAAoE;AACpE,EAAE;AACF,sEAAsE;AACtE,8EAA8E;AAC9E,sEAAsE;AACtE,+EAA+E;AAC/E,4DAA4D;AAC5D,EAAE;AACF,+EAA+E;AAC/E,mDAAmD;AAEnD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,iB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,CAAC;AAED,MAAM,IAAI,EAAE,CAAC;AACb,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC"}
@@ -19,6 +19,8 @@ import { createLogger } from "../log.js";
19
19
  import { renderPostRead } from "../render.js";
20
20
  import { resolveRoot, rootNote } from "../root.js";
21
21
  import { markRead, markTold, toldKey, wasRead } from "./reuse.js";
22
+ import { markInvoker } from "./invoker.js";
23
+ import { deliverLate } from "./late.js";
22
24
  const log = createLogger("carrick-hook");
23
25
  /** The files the index has rows for. */
24
26
  const CHECKED = /\.(ts|tsx|mts|cts)$/;
@@ -30,7 +32,16 @@ async function readStdin() {
30
32
  chunks.push(Buffer.from(chunk));
31
33
  return Buffer.concat(chunks).toString("utf8");
32
34
  }
35
+ /** The one JSON object this hook prints, or nothing when there are no lines. */
36
+ function emit(contexts) {
37
+ if (contexts.length === 0)
38
+ return;
39
+ process.stdout.write(JSON.stringify({
40
+ hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: contexts.join("\n\n") },
41
+ }));
42
+ }
33
43
  async function main() {
44
+ markInvoker("post-read");
34
45
  // Only `hook` prints from here; `lsp` and `off` start nothing and write
35
46
  // nothing, so a file is not marked as asked about by a channel that said
36
47
  // nothing.
@@ -46,13 +57,16 @@ async function main() {
46
57
  log("unparseable payload", String(error));
47
58
  return;
48
59
  }
60
+ // A finished background re-check is owed to the model whatever this Read
61
+ // is: delivered before the early returns below, in the same one object.
62
+ const session = payload.session_id;
63
+ const late = deliverLate(session);
49
64
  const named = payload.tool_input?.file_path;
50
65
  if (!named || !CHECKED.test(named))
51
- return;
66
+ return emit(late);
52
67
  const file = path.isAbsolute(named) ? named : path.resolve(payload.cwd ?? process.cwd(), named);
53
- const session = payload.session_id;
54
68
  if (session && wasRead(session, file))
55
- return;
69
+ return emit(late);
56
70
  const choice = resolveRoot({
57
71
  clientRoot: payload.cwd ?? null,
58
72
  projectDir: process.env["CLAUDE_PROJECT_DIR"] ?? null,
@@ -69,15 +83,11 @@ async function main() {
69
83
  markRead(session, file);
70
84
  if (!outcome.result) {
71
85
  log("no answer for", relative, outcome.failure ?? "");
72
- return;
86
+ return emit(late);
73
87
  }
74
88
  const context = renderPostRead(outcome.result, relative);
75
89
  log(`check ${relative} -> ${context ? "context" : "nothing to say"} in ${outcome.ms}ms`);
76
- if (!context)
77
- return;
78
- process.stdout.write(JSON.stringify({
79
- hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: context },
80
- }));
90
+ emit(context ? [...late, context] : late);
81
91
  // The post-edit hook that follows prints this file's header and items but
82
92
  // not the uses lines it was just shown.
83
93
  if (session && outcome.result.uses_lines?.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"post-read.js","sourceRoot":"","sources":["../../src/hook/post-read.ts"],"names":[],"mappings":";AACA,mEAAmE;AACnE,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAC9E,sCAAsC;AACtC,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,0CAA0C;AAE1C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAElE,MAAM,GAAG,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AACzC,wCAAwC;AACxC,MAAM,OAAO,GAAG,qBAAqB,CAAC;AACtC,iEAAiE;AACjE,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAQhC,KAAK,UAAU,SAAS;IACtB,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AAI,CAAC,CAAC;IACrC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,GAAG,CAAC,eAAe,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAED,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACzD,GAAG,CAAC,SAAS,QAAQ,OAAO,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,OAAO,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IACzF,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC1C,0EAA0E;IAC1E,wCAAwC;IACxC,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;QACjD,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;AACH,CAAC;AAED,MAAM,IAAI,EAAE,CAAC;AACb,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { CheckResult } from "../contract.ts";
2
+ /** The limit on a probe: 5 s, and half a second more for each further file of a patch, to 40 s. */
3
+ export declare function probeTimeoutMs(files: number): number;
4
+ /** Whether the probe left this edit for the background re-check: no answer, or `deferred`. */
5
+ export declare function needsBackground(result: CheckResult | null): boolean;
6
+ /**
7
+ * One probe call for every edited file (a patch is one `check --each`), in the
8
+ * order given. The binary reads misses at the background cap, so a service the
9
+ * runner could not fit is answered at once instead of deferred forever.
10
+ */
11
+ export declare function probeEdits(relatives: string[], cwd: string, env?: NodeJS.ProcessEnv): Promise<{
12
+ results: Array<CheckResult | null>;
13
+ failure: string | null;
14
+ ms: number;
15
+ }>;
@@ -0,0 +1,41 @@
1
+ // The post-edit hook's one question to the binary: the probe.
2
+ //
3
+ // `check <file> --recheck --no-rescan --json` answers at once when no re-scan
4
+ // is needed (the file reads the same as the index, no service reads it, a
5
+ // known miss at the background budget) and otherwise says `recheck.deferred`.
6
+ // This file is the only place that knows that shape, so the binary's half
7
+ // (B3-R) can change its spelling in one place. A call that gives no answer,
8
+ // including a binary too old to know the flag, reads as deferred: the edit is
9
+ // queued for the background runner, which asks the full question.
10
+ import { check, checkEach } from "../cli.js";
11
+ import { backgroundCapMs } from "./rechecks.js";
12
+ /** The limit on a probe: 5 s, and half a second more for each further file of a patch, to 40 s. */
13
+ export function probeTimeoutMs(files) {
14
+ return Math.min(5000 + 500 * Math.max(files - 1, 0), 40_000);
15
+ }
16
+ /** Whether the probe left this edit for the background re-check: no answer, or `deferred`. */
17
+ export function needsBackground(result) {
18
+ return result === null || result.recheck?.deferred === true;
19
+ }
20
+ /**
21
+ * One probe call for every edited file (a patch is one `check --each`), in the
22
+ * order given. The binary reads misses at the background cap, so a service the
23
+ * runner could not fit is answered at once instead of deferred forever.
24
+ */
25
+ export async function probeEdits(relatives, cwd, env = process.env) {
26
+ const probeEnv = { ...env, CARRICK_RECHECK_BUDGET_MS: String(backgroundCapMs(env)) };
27
+ const options = {
28
+ cwd,
29
+ env: probeEnv,
30
+ recheck: true,
31
+ noRescan: true,
32
+ limitMs: probeTimeoutMs(relatives.length),
33
+ };
34
+ if (relatives.length === 1) {
35
+ const outcome = await check(relatives[0], options);
36
+ return { results: [outcome.result], failure: outcome.failure, ms: outcome.ms };
37
+ }
38
+ const outcome = await checkEach(relatives, options);
39
+ return { results: outcome.result ?? [], failure: outcome.failure, ms: outcome.ms };
40
+ }
41
+ //# sourceMappingURL=probe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.js","sourceRoot":"","sources":["../../src/hook/probe.ts"],"names":[],"mappings":"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