carrick 0.3.155 → 0.3.157

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 (125) hide show
  1. package/dist/contract.d.ts +22 -23
  2. package/dist/contract.js.map +1 -1
  3. package/dist/facts/enabled.d.ts +28 -0
  4. package/dist/facts/enabled.js +36 -0
  5. package/dist/facts/enabled.js.map +1 -1
  6. package/dist/facts/fetch.js +20 -8
  7. package/dist/facts/fetch.js.map +1 -1
  8. package/dist/facts/lines.d.ts +75 -2
  9. package/dist/facts/lines.js +302 -46
  10. package/dist/facts/lines.js.map +1 -1
  11. package/dist/facts/match.d.ts +2 -0
  12. package/dist/facts/match.js +189 -28
  13. package/dist/facts/match.js.map +1 -1
  14. package/dist/facts/peers.d.ts +2 -0
  15. package/dist/facts/peers.js +7 -2
  16. package/dist/facts/peers.js.map +1 -1
  17. package/dist/facts/store.d.ts +98 -2
  18. package/dist/facts/store.js +110 -12
  19. package/dist/facts/store.js.map +1 -1
  20. package/dist/held/client.d.ts +34 -0
  21. package/dist/held/client.js +85 -0
  22. package/dist/held/client.js.map +1 -0
  23. package/dist/held/daemon.d.ts +106 -0
  24. package/dist/held/daemon.js +307 -0
  25. package/dist/held/daemon.js.map +1 -0
  26. package/dist/held/engine.d.ts +50 -0
  27. package/dist/held/engine.js +166 -0
  28. package/dist/held/engine.js.map +1 -0
  29. package/dist/held/paths.d.ts +9 -0
  30. package/dist/held/paths.js +27 -0
  31. package/dist/held/paths.js.map +1 -0
  32. package/dist/held/place.d.ts +84 -0
  33. package/dist/held/place.js +198 -0
  34. package/dist/held/place.js.map +1 -0
  35. package/dist/held/registry.d.ts +22 -0
  36. package/dist/held/registry.js +72 -0
  37. package/dist/held/registry.js.map +1 -0
  38. package/dist/held/run.d.ts +2 -0
  39. package/dist/held/run.js +60 -0
  40. package/dist/held/run.js.map +1 -0
  41. package/dist/hook/bash-targets.d.ts +7 -2
  42. package/dist/hook/bash-targets.js +82 -27
  43. package/dist/hook/bash-targets.js.map +1 -1
  44. package/dist/hook/edit-flow.js +11 -7
  45. package/dist/hook/edit-flow.js.map +1 -1
  46. package/dist/hook/late.d.ts +1 -1
  47. package/dist/hook/late.js +3 -3
  48. package/dist/hook/late.js.map +1 -1
  49. package/dist/hook/lock.d.ts +26 -0
  50. package/dist/hook/lock.js +122 -0
  51. package/dist/hook/lock.js.map +1 -0
  52. package/dist/hook/post-bash.js +22 -7
  53. package/dist/hook/post-bash.js.map +1 -1
  54. package/dist/hook/post-read.js +9 -4
  55. package/dist/hook/post-read.js.map +1 -1
  56. package/dist/hook/probe.js +4 -2
  57. package/dist/hook/probe.js.map +1 -1
  58. package/dist/hook/read-answer.d.ts +23 -4
  59. package/dist/hook/read-answer.js +74 -19
  60. package/dist/hook/read-answer.js.map +1 -1
  61. package/dist/hook/rechecks.d.ts +2 -5
  62. package/dist/hook/rechecks.js +23 -130
  63. package/dist/hook/rechecks.js.map +1 -1
  64. package/dist/hook/similar.d.ts +13 -0
  65. package/dist/hook/similar.js +60 -0
  66. package/dist/hook/similar.js.map +1 -0
  67. package/dist/hook/stop-wait.d.ts +1 -0
  68. package/dist/hook/stop-wait.js +19 -24
  69. package/dist/hook/stop-wait.js.map +1 -1
  70. package/dist/hook/timings.d.ts +17 -3
  71. package/dist/hook/timings.js +10 -2
  72. package/dist/hook/timings.js.map +1 -1
  73. package/dist/lsp-frame.d.ts +20 -0
  74. package/dist/lsp-frame.js +47 -0
  75. package/dist/lsp-frame.js.map +1 -0
  76. package/dist/render.js +9 -3
  77. package/dist/render.js.map +1 -1
  78. package/dist/scan.d.ts +9 -0
  79. package/dist/scan.js +39 -8
  80. package/dist/scan.js.map +1 -1
  81. package/dist/server.js +4 -28
  82. package/dist/server.js.map +1 -1
  83. package/package.json +6 -6
  84. package/plugin/.claude-plugin/plugin.json +1 -1
  85. package/sidecar/dist/src/bundler.d.ts +5 -0
  86. package/sidecar/dist/src/bundler.js +20 -0
  87. package/sidecar/dist/src/capture/anchors.js +19 -4
  88. package/sidecar/dist/src/capture/api.d.ts +52 -4
  89. package/sidecar/dist/src/capture/check-probe.d.ts +17 -1
  90. package/sidecar/dist/src/capture/check-probe.js +39 -2
  91. package/sidecar/dist/src/capture/index.d.ts +12 -4
  92. package/sidecar/dist/src/capture/index.js +19 -3
  93. package/sidecar/dist/src/capture/result-label.js +3 -1
  94. package/sidecar/dist/src/capture/self-check.js +12 -31
  95. package/sidecar/dist/src/capture/serialised-arms.d.ts +27 -0
  96. package/sidecar/dist/src/capture/serialised-arms.js +76 -0
  97. package/sidecar/dist/src/capture/site-node.d.ts +17 -0
  98. package/sidecar/dist/src/capture/site-node.js +36 -0
  99. package/sidecar/dist/src/capture/stub-resolution.d.ts +63 -0
  100. package/sidecar/dist/src/capture/stub-resolution.js +102 -0
  101. package/sidecar/dist/src/capture/type-reasons.json +78 -0
  102. package/sidecar/dist/src/capture/unresolved.js +8 -1
  103. package/sidecar/dist/src/definition-resolver.d.ts +18 -9
  104. package/sidecar/dist/src/definition-resolver.js +66 -42
  105. package/sidecar/dist/src/engine-stamp.json +1 -0
  106. package/sidecar/dist/src/held-shadow.d.ts +60 -0
  107. package/sidecar/dist/src/held-shadow.js +222 -0
  108. package/sidecar/dist/src/index.js +47 -1
  109. package/sidecar/dist/src/library-claims.d.ts +3 -1
  110. package/sidecar/dist/src/library-claims.js +79 -3
  111. package/sidecar/dist/src/retype.js +1 -61
  112. package/sidecar/dist/src/type-home.d.ts +42 -0
  113. package/sidecar/dist/src/type-home.js +94 -0
  114. package/sidecar/dist/src/type-inferrer.d.ts +245 -28
  115. package/sidecar/dist/src/type-inferrer.js +938 -192
  116. package/sidecar/dist/src/type-parameters.d.ts +41 -0
  117. package/sidecar/dist/src/type-parameters.js +126 -0
  118. package/sidecar/dist/src/type-structural-expander.d.ts +1 -11
  119. package/sidecar/dist/src/type-structural-expander.js +9 -1
  120. package/sidecar/dist/src/types.d.ts +132 -20
  121. package/sidecar/dist/src/validators.d.ts +450 -244
  122. package/sidecar/dist/src/validators.js +27 -1
  123. package/dist/hook/lead.d.ts +0 -13
  124. package/dist/hook/lead.js +0 -39
  125. package/dist/hook/lead.js.map +0 -1
@@ -0,0 +1,9 @@
1
+ /** The daemon touches its lock every tick; it is stale this long (plus the lock's slack) after. */
2
+ export declare const LOCK_CAP_MS = 30000;
3
+ export declare function heldDir(home?: string): string;
4
+ /** The first 12 hex characters of the sha-256 of the checkout's real path. */
5
+ export declare function rootKey(root: string): string;
6
+ export declare function socketPath(root: string, home?: string): string;
7
+ export declare function lockPath(root: string, home?: string): string;
8
+ /** One JSON line per request. */
9
+ export declare function logPath(root: string, home?: string): string;
@@ -0,0 +1,27 @@
1
+ // Where the held-compiler daemon keeps its files. Everything is under
2
+ // `~/.carrick/held/`, outside every checkout, keyed by a hash of the checkout's
3
+ // real path (a socket path is capped near 104 bytes on macOS, so no names).
4
+ import { createHash } from "node:crypto";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { realPath } from "../fs-util.js";
8
+ /** The daemon touches its lock every tick; it is stale this long (plus the lock's slack) after. */
9
+ export const LOCK_CAP_MS = 30_000;
10
+ export function heldDir(home = os.homedir()) {
11
+ return path.join(home, ".carrick", "held");
12
+ }
13
+ /** The first 12 hex characters of the sha-256 of the checkout's real path. */
14
+ export function rootKey(root) {
15
+ return createHash("sha256").update(realPath(root)).digest("hex").slice(0, 12);
16
+ }
17
+ export function socketPath(root, home) {
18
+ return path.join(heldDir(home), `${rootKey(root)}.sock`);
19
+ }
20
+ export function lockPath(root, home) {
21
+ return path.join(heldDir(home), `${rootKey(root)}.lock`);
22
+ }
23
+ /** One JSON line per request. */
24
+ export function logPath(root, home) {
25
+ return path.join(heldDir(home), `${rootKey(root)}.log`);
26
+ }
27
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/held/paths.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,gFAAgF;AAChF,4EAA4E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3
+ /** What the placer reads of a contract row (a subset of the fact store's row). */
4
+ export type PlaceRow = Pick<ContractRow, "label" | "locator"> & {
5
+ id: number;
6
+ site: string | null;
7
+ line: number | null;
8
+ groups: Array<Pick<ContractGroup, "type">>;
9
+ };
10
+ /** A compiler diagnostic: its start offset in the checked text, its code, its message. */
11
+ export type Diag = {
12
+ start: number;
13
+ code: number;
14
+ message: string;
15
+ };
16
+ export type UnplacedReason = "not_registration" | "dispatch_case" | "javascript_file" | "no_site_found" | "site_not_unique";
17
+ export type UnarmedReason = "twin_passes" | "decl_error" | "no_hono" | `clean_check_fails:TS${number}`;
18
+ /** `no_hono` is a row's own reason too (the clean check names a non-route object). */
19
+ export type RowReason = UnplacedReason | UnarmedReason;
20
+ export type Check = {
21
+ id: number;
22
+ group: number;
23
+ /** `<id>_<group>`; the check's alias is `O<k>`. */
24
+ k: string;
25
+ /** The whole check expression: `__C.reg<k>(` through `, (o) => o)`. */
26
+ span: [number, number];
27
+ /** The check's two declaration lines in the appended namespace. */
28
+ declSpan: [number, number];
29
+ };
30
+ export type Overlay = {
31
+ text: string;
32
+ checks: Check[];
33
+ unplaced: Array<{
34
+ id: number;
35
+ reason: UnplacedReason;
36
+ }>;
37
+ /** Offset where the appended namespace starts. */
38
+ bodyEnd: number;
39
+ };
40
+ /**
41
+ * D7. The call that starts on the row's line, whose callee is the label's
42
+ * method and whose first argument is the row's site literal. With none on that
43
+ * line, the unique such call in the file. Two or more is never a guess.
44
+ */
45
+ export declare function findSite(sf: ts.SourceFile, row: Pick<PlaceRow, "label" | "site" | "line">): {
46
+ node: ts.CallExpression;
47
+ } | {
48
+ reason: UnplacedReason;
49
+ };
50
+ /**
51
+ * The file with every placeable row's registration wrapped. `clean` states the
52
+ * row's type; `twin` states it intersected with a property no reply has, so it
53
+ * must fail where the check can see the reply at all.
54
+ */
55
+ export declare function overlay(file: string, text: string, rows: PlaceRow[], mode: "clean" | "twin"): Overlay;
56
+ /**
57
+ * R3. A diagnostic is a check's own line only when its start lies in the
58
+ * check's whole expression AND its message names the check's alias. Several
59
+ * checks can share an expression (two groups of one row, a chain): the
60
+ * narrowest that the message names wins. A diagnostic in a check's declaration
61
+ * lines is that check's `decl_error`. Everything else is `outside`, and never
62
+ * a line.
63
+ */
64
+ export declare function attribute(ov: Overlay, diags: Diag[]): {
65
+ lines: Map<string, Diag[]>;
66
+ declErrors: Set<string>;
67
+ outside: Diag[];
68
+ };
69
+ /**
70
+ * D6. On the current text, a check is armed only when its clean form is
71
+ * silent and its twin speaks. The gate reads the check's span, not the alias
72
+ * name: the twin's message may print the expanded intersection instead of
73
+ * `O<k>`, and the gate must not take that for silence. Only the gate is this
74
+ * broad; a line (see `attribute`) never is.
75
+ */
76
+ export declare function arm(ov: Overlay, clean: Diag[], twin: Diag[]): {
77
+ armed: string[];
78
+ unarmed: Array<{
79
+ k: string;
80
+ id: number;
81
+ group: number;
82
+ reason: UnarmedReason;
83
+ }>;
84
+ };
@@ -0,0 +1,198 @@
1
+ // Part 3, T4: place, arm and attribute. Pure functions, no engine and no disk.
2
+ //
3
+ // A producer response row says "this route's 2xx reply has type T". To ask the
4
+ // compiler whether an edit breaks that, the registration call is wrapped in a
5
+ // check, `__C.reg<k>(<call>, (o) => o)`, where `o` is the route framework's own
6
+ // record of the handler's reply and the callback must return `O<k>`, the row's
7
+ // stated type. The check text is appended to the file's end (`declare
8
+ // namespace __C`), so no line moves.
9
+ //
10
+ // Three decisions live here:
11
+ // place (D7) which call is the row's site, on the CURRENT text
12
+ // arm (D6) which checks may speak: clean passes, its twin fails
13
+ // attribute (R3) which diagnostics are a check's own, and so may be a line
14
+ import ts from "typescript";
15
+ const POST = ", (o) => o)";
16
+ const OK = "200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226";
17
+ const PREAMBLE = [
18
+ ` type Ok = ${OK};`,
19
+ " type Pick2xx<E> = E extends { status: infer St; output: infer O } ? ([Extract<St, Ok>] extends [never] ? never : O) : never;",
20
+ ' type Out<R, P extends string, M extends string> = R extends import("hono").Hono<any, infer S extends import("hono").Schema, any>',
21
+ " ? (P extends keyof S ? (`$${M}` extends keyof S[P] ? Pick2xx<S[P][`$${M}`]> : { readonly __carrick_no_method_in_route_schema: M })",
22
+ " : { readonly __carrick_no_site_in_route_schema: P }) : { readonly __carrick_not_a_route_object: R };",
23
+ ];
24
+ const methodOf = (label) => label.split(" ")[0].toLowerCase();
25
+ const scriptKind = (file) => (file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
26
+ function memberCalls(sf) {
27
+ const out = [];
28
+ const visit = (n) => {
29
+ if (ts.isCallExpression(n) && ts.isPropertyAccessExpression(n.expression)) {
30
+ const a0 = n.arguments[0];
31
+ const literal = a0 && (ts.isStringLiteral(a0) || ts.isNoSubstitutionTemplateLiteral(a0)) ? a0.text : undefined;
32
+ out.push({ node: n, name: n.expression.name.text, literal, line: sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1 });
33
+ }
34
+ ts.forEachChild(n, visit);
35
+ };
36
+ visit(sf);
37
+ return out;
38
+ }
39
+ /**
40
+ * D7. The call that starts on the row's line, whose callee is the label's
41
+ * method and whose first argument is the row's site literal. With none on that
42
+ * line, the unique such call in the file. Two or more is never a guess.
43
+ */
44
+ export function findSite(sf, row) {
45
+ if (row.site === null)
46
+ return { reason: "no_site_found" };
47
+ const method = methodOf(row.label);
48
+ const same = memberCalls(sf).filter((c) => c.name === method && c.literal === row.site);
49
+ const onLine = same.filter((c) => c.line === row.line);
50
+ if (onLine.length === 1)
51
+ return { node: onLine[0].node };
52
+ if (onLine.length > 1)
53
+ return { reason: "site_not_unique" };
54
+ if (same.length === 1)
55
+ return { node: same[0].node };
56
+ return { reason: same.length === 0 ? "no_site_found" : "site_not_unique" };
57
+ }
58
+ /**
59
+ * The file with every placeable row's registration wrapped. `clean` states the
60
+ * row's type; `twin` states it intersected with a property no reply has, so it
61
+ * must fail where the check can see the reply at all.
62
+ */
63
+ export function overlay(file, text, rows, mode) {
64
+ const unplaced = [];
65
+ const js = /\.(?:[mc]?js|jsx)$/.test(file);
66
+ const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, scriptKind(file));
67
+ const ops = [];
68
+ const checks = [];
69
+ const decls = [];
70
+ let seq = 0;
71
+ for (const row of rows) {
72
+ if (row.locator !== "registration") {
73
+ unplaced.push({ id: row.id, reason: "not_registration" });
74
+ continue;
75
+ }
76
+ if (row.label.includes("{")) {
77
+ unplaced.push({ id: row.id, reason: "dispatch_case" });
78
+ continue;
79
+ }
80
+ if (js) {
81
+ unplaced.push({ id: row.id, reason: "javascript_file" });
82
+ continue;
83
+ }
84
+ const found = findSite(sf, row);
85
+ if (!("node" in found)) {
86
+ unplaced.push({ id: row.id, reason: found.reason });
87
+ continue;
88
+ }
89
+ const start = found.node.getStart(sf);
90
+ const end = found.node.end;
91
+ const method = methodOf(row.label);
92
+ row.groups.forEach((g, group) => {
93
+ const k = `${row.id}_${group}`;
94
+ const stated = mode === "twin" ? `(${g.type}) & { readonly __carrick_never: true }` : `(${g.type})`;
95
+ decls.push(` type O${k} = ${stated};`);
96
+ decls.push(` function reg${k}<R>(r: R, c: (o: Out<R, ${JSON.stringify(row.site)}, ${JSON.stringify(method)}>) => O${k}): R;`);
97
+ ops.push({ at: start, s: `__C.reg${k}(`, side: "pre", seq, start, end });
98
+ ops.push({ at: end, s: POST, side: "post", seq, start, end });
99
+ seq += 1;
100
+ checks.push({ id: row.id, group, k, span: [0, 0], declSpan: [0, 0] });
101
+ });
102
+ }
103
+ // Wraps at one offset must nest. Opening: the wider call first, later group outside.
104
+ // Closing: the mirror image. A close at an offset comes before an open there.
105
+ ops.sort((a, b) => {
106
+ if (a.at !== b.at)
107
+ return a.at - b.at;
108
+ if (a.side !== b.side)
109
+ return a.side === "post" ? -1 : 1;
110
+ if (a.side === "pre")
111
+ return b.end - a.end || b.seq - a.seq;
112
+ return b.start - a.start || a.seq - b.seq;
113
+ });
114
+ let out = "";
115
+ let last = 0;
116
+ const pos = new Map();
117
+ for (const o of ops) {
118
+ out += text.slice(last, o.at);
119
+ pos.set(`${o.seq}:${o.side}`, out.length);
120
+ out += o.s;
121
+ last = o.at;
122
+ }
123
+ out += text.slice(last);
124
+ const bodyEnd = out.length;
125
+ out += "\n" + ["declare namespace __C {", ...PREAMBLE, ...decls, "}"].join("\n") + "\n";
126
+ checks.forEach((c, i) => {
127
+ c.span = [pos.get(`${i}:pre`), pos.get(`${i}:post`) + POST.length];
128
+ const declAt = out.indexOf(` type O${c.k} = `, bodyEnd);
129
+ c.declSpan = [declAt, out.indexOf("\n", out.indexOf(`function reg${c.k}<`, declAt))];
130
+ });
131
+ return { text: out, checks, unplaced, bodyEnd };
132
+ }
133
+ const inside = (p, s) => p >= s[0] && p <= s[1];
134
+ const names = (message, k) => new RegExp(`\\bO${k}\\b`).test(message);
135
+ /**
136
+ * R3. A diagnostic is a check's own line only when its start lies in the
137
+ * check's whole expression AND its message names the check's alias. Several
138
+ * checks can share an expression (two groups of one row, a chain): the
139
+ * narrowest that the message names wins. A diagnostic in a check's declaration
140
+ * lines is that check's `decl_error`. Everything else is `outside`, and never
141
+ * a line.
142
+ */
143
+ export function attribute(ov, diags) {
144
+ const lines = new Map();
145
+ const declErrors = new Set();
146
+ const outside = [];
147
+ for (const d of diags) {
148
+ const decl = ov.checks.find((c) => inside(d.start, c.declSpan));
149
+ if (decl) {
150
+ declErrors.add(decl.k);
151
+ continue;
152
+ }
153
+ const own = ov.checks
154
+ .filter((c) => inside(d.start, c.span) && names(d.message, c.k))
155
+ .sort((a, b) => a.span[1] - a.span[0] - (b.span[1] - b.span[0]));
156
+ if (own.length === 0) {
157
+ outside.push(d);
158
+ continue;
159
+ }
160
+ const k = own[0].k;
161
+ lines.set(k, [...(lines.get(k) ?? []), d]);
162
+ }
163
+ return { lines, declErrors, outside };
164
+ }
165
+ /** A check "speaks" at the gate when anything but a syntax error (TS1xxx) starts in it. */
166
+ function speaks(c, diags) {
167
+ return diags.find((d) => d.code >= 2000 && inside(d.start, c.span));
168
+ }
169
+ /**
170
+ * D6. On the current text, a check is armed only when its clean form is
171
+ * silent and its twin speaks. The gate reads the check's span, not the alias
172
+ * name: the twin's message may print the expanded intersection instead of
173
+ * `O<k>`, and the gate must not take that for silence. Only the gate is this
174
+ * broad; a line (see `attribute`) never is.
175
+ */
176
+ export function arm(ov, clean, twin) {
177
+ const armed = [];
178
+ const unarmed = [];
179
+ for (const c of ov.checks) {
180
+ const no = (reason) => { unarmed.push({ k: c.k, id: c.id, group: c.group, reason }); };
181
+ if (clean.some((d) => inside(d.start, c.declSpan))) {
182
+ no("decl_error");
183
+ continue;
184
+ }
185
+ const bad = speaks(c, clean);
186
+ if (bad) {
187
+ no(bad.message.includes("__carrick_not_a_route_object") ? "no_hono" : `clean_check_fails:TS${bad.code}`);
188
+ continue;
189
+ }
190
+ if (!speaks(c, twin)) {
191
+ no("twin_passes");
192
+ continue;
193
+ }
194
+ armed.push(c.k);
195
+ }
196
+ return { armed, unarmed };
197
+ }
198
+ //# sourceMappingURL=place.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place.js","sourceRoot":"","sources":["../../src/held/place.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,+EAA+E;AAC/E,sEAAsE;AACtE,qCAAqC;AACrC,EAAE;AACF,6BAA6B;AAC7B,sEAAsE;AACtE,yEAAyE;AACzE,8EAA8E;AAE9E,OAAO,EAAE,MAAM,YAAY,CAAC;AA6C5B,MAAM,IAAI,GAAG,aAAa,CAAC;AAC3B,MAAM,EAAE,GAAG,2DAA2D,CAAC;AACvE,MAAM,QAAQ,GAAG;IACf,eAAe,EAAE,GAAG;IACpB,gIAAgI;IAChI,oIAAoI;IACpI,wIAAwI;IACxI,4GAA4G;CAC7G,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,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,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;YAAC,EAAE,CAAC,aAAa,CAAC,CAAC;YAAC,SAAS;QAAC,CAAC;QACtD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,22 @@
1
+ /** What a TypeScript 7 engine was measured to settle at, and so what a new one is counted as. */
2
+ export declare const ADMISSION_MB = 2048;
3
+ /** 1.5 x the plateau: an engine above this is restarted. */
4
+ export declare const RSS_CEILING_MB = 3072;
5
+ /** An engine idle this long may be closed to make room for another. */
6
+ export declare const EVICT_IDLE_MS: number;
7
+ export type EngineEntry = {
8
+ /** The daemon that owns the engine: the entry is live while this process is. */
9
+ pid: number;
10
+ root: string;
11
+ service: string;
12
+ rss_mb: number;
13
+ last_used: number;
14
+ };
15
+ export declare function memoryBudgetMb(env?: NodeJS.ProcessEnv): number;
16
+ export declare function registryDir(home?: string): string;
17
+ export declare function writeEntry(home: string | undefined, entry: EngineEntry): void;
18
+ export declare function removeEntry(home: string | undefined, pid: number, root: string, service: string): void;
19
+ /** Every entry whose owner is alive. An entry whose owner is gone is deleted here. */
20
+ export declare function liveEntries(home?: string): EngineEntry[];
21
+ /** Whether one more engine, counted at its plateau, keeps the live total within the budget. */
22
+ export declare function admits(entries: readonly EngineEntry[], budgetMb: number): boolean;
@@ -0,0 +1,72 @@
1
+ // The machine-wide registry of held compilers (D3). Each engine a daemon holds
2
+ // has one file under `~/.carrick/held/engines/`, so a second daemon, in another
3
+ // checkout, counts the memory the first already holds before it starts one.
4
+ import { createHash } from "node:crypto";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import { alive, readJson } from "../hook/lock.js";
8
+ import { writeAtomic } from "../hook/reuse.js";
9
+ import { heldDir } from "./paths.js";
10
+ /** What a TypeScript 7 engine was measured to settle at, and so what a new one is counted as. */
11
+ export const ADMISSION_MB = 2048;
12
+ /** 1.5 x the plateau: an engine above this is restarted. */
13
+ export const RSS_CEILING_MB = 3072;
14
+ /** An engine idle this long may be closed to make room for another. */
15
+ export const EVICT_IDLE_MS = 2 * 60_000;
16
+ const DEFAULT_BUDGET_MB = 4096;
17
+ export function memoryBudgetMb(env = process.env) {
18
+ const parsed = Number.parseInt(env["CARRICK_HELD_MEMORY_MB"] ?? "", 10);
19
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_BUDGET_MB;
20
+ }
21
+ export function registryDir(home) {
22
+ return path.join(heldDir(home), "engines");
23
+ }
24
+ function entryFile(home, pid, root, service) {
25
+ const key = createHash("sha256").update(`${root}\0${service}`).digest("hex").slice(0, 8);
26
+ return path.join(registryDir(home), `${pid}-${key}.json`);
27
+ }
28
+ export function writeEntry(home, entry) {
29
+ writeAtomic(entryFile(home, entry.pid, entry.root, entry.service), `${JSON.stringify(entry)}\n`);
30
+ }
31
+ export function removeEntry(home, pid, root, service) {
32
+ try {
33
+ fs.unlinkSync(entryFile(home, pid, root, service));
34
+ }
35
+ catch {
36
+ // Already gone.
37
+ }
38
+ }
39
+ /** Every entry whose owner is alive. An entry whose owner is gone is deleted here. */
40
+ export function liveEntries(home) {
41
+ const dir = registryDir(home);
42
+ let names;
43
+ try {
44
+ names = fs.readdirSync(dir);
45
+ }
46
+ catch {
47
+ return [];
48
+ }
49
+ const out = [];
50
+ for (const name of names) {
51
+ if (!name.endsWith(".json"))
52
+ continue;
53
+ const file = path.join(dir, name);
54
+ const entry = readJson(file);
55
+ if (entry === null || typeof entry.pid !== "number" || !alive(entry.pid)) {
56
+ try {
57
+ fs.unlinkSync(file);
58
+ }
59
+ catch {
60
+ // Another process removed it first.
61
+ }
62
+ continue;
63
+ }
64
+ out.push(entry);
65
+ }
66
+ return out;
67
+ }
68
+ /** Whether one more engine, counted at its plateau, keeps the live total within the budget. */
69
+ export function admits(entries, budgetMb) {
70
+ return entries.reduce((sum, e) => sum + e.rss_mb, 0) + ADMISSION_MB <= budgetMb;
71
+ }
72
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/held/registry.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gFAAgF;AAChF,4EAA4E;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,iGAAiG;AACjG,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC;AACjC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,uEAAuE;AACvE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAG,MAAM,CAAC;AAExC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAW/B,MAAM,UAAU,cAAc,CAAC,MAAyB,OAAO,CAAC,GAAG;IACjE,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,wBAAwB,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,iBAAiB,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAa;IACvC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,SAAS,CAAC,IAAwB,EAAE,GAAW,EAAE,IAAY,EAAE,OAAe;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C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAClC,MAAM,KAAK,GAAG,QAAQ,CAAc,IAAI,CAAC,CAAC;QAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC;gBACH,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;YAAC,MAAM,CAAC;gBACP,oCAAoC;YACtC,CAAC;YACD,SAAS;QACX,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,MAAM,CAAC,OAA+B,EAAE,QAAgB;IACtE,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,YAAY,IAAI,QAAQ,CAAC;AAClF,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ // The held-compiler daemon's entry: `node run.ts <checkout root>`.
3
+ //
4
+ // Started detached by `ensureHeld` (client.ts). With CARRICK_COMPILER_LINES
5
+ // unset it exits at once and touches nothing. It prints nothing and exits 0
6
+ // whatever happens.
7
+ import { execFile } from "node:child_process";
8
+ import { compilerLinesEnabled } from "../facts/enabled.js";
9
+ import { binary } from "../cli.js";
10
+ import { createLogger } from "../log.js";
11
+ import { serve } from "./daemon.js";
12
+ const log = createLogger("carrick-held-run");
13
+ const HELD_PROGRAMS_SCHEMA = "carrick.held-programs/0";
14
+ /** Every indexed service's program init, as the scanner loads it (`carrick held-programs --json`). */
15
+ function readPrograms(root, env) {
16
+ return new Promise((resolve, reject) => {
17
+ execFile(binary(env), ["held-programs", "--json"], { cwd: root, env, maxBuffer: 16 * 1024 * 1024 }, (error, stdout) => {
18
+ if (error)
19
+ return reject(error);
20
+ try {
21
+ const parsed = JSON.parse(stdout);
22
+ if (parsed.schema !== HELD_PROGRAMS_SCHEMA || !Array.isArray(parsed.services)) {
23
+ return reject(new Error(`unexpected held-programs output (${parsed.schema ?? "no schema"})`));
24
+ }
25
+ resolve(parsed.services);
26
+ }
27
+ catch (parseError) {
28
+ reject(parseError);
29
+ }
30
+ });
31
+ });
32
+ }
33
+ /** Until the request path is wired in, no service has an engine. */
34
+ const runtime = {
35
+ start: async () => ({ state: "error", reason: "the engine for a service is not wired in yet" }),
36
+ };
37
+ async function main() {
38
+ const root = process.argv.slice(2)[0];
39
+ if (!root) {
40
+ log("no checkout root given");
41
+ return;
42
+ }
43
+ const env = process.env;
44
+ if (!compilerLinesEnabled(env))
45
+ return;
46
+ const deps = { root, env, programs: () => readPrograms(root, env), runtime };
47
+ const stop = new AbortController();
48
+ process.once("SIGTERM", () => stop.abort());
49
+ process.once("SIGINT", () => stop.abort());
50
+ const spawner = Number.parseInt(env["CARRICK_HELD_SPAWNER"] ?? "", 10);
51
+ await serve(deps, { signal: stop.signal, ...(Number.isFinite(spawner) ? { spawner } : {}) });
52
+ }
53
+ try {
54
+ await main();
55
+ }
56
+ catch (error) {
57
+ log("daemon failed", String(error));
58
+ }
59
+ process.exit(0);
60
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/held/run.ts"],"names":[],"mappings":";AACA,mEAAmE;AACnE,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,oBAAoB;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM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,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC"}
@@ -14,12 +14,17 @@ export declare const MENTIONS_FACT_SOURCE: RegExp;
14
14
  * `npm ci` ...), which changes many files the agent did not write.
15
15
  */
16
16
  export declare function movesTreeInBulk(command: string, cwd: string): boolean;
17
+ /** What the Bash hook knows about the call besides the command: how long it ran. */
18
+ export type CallInfo = {
19
+ durationMs?: number;
20
+ now?: number;
21
+ };
17
22
  /**
18
23
  * The source files `command` reads and the ones it writes, as absolute paths
19
24
  * that exist. A file the same command writes (`>`, `>>`, `sed -i`, `tee`) is
20
25
  * not in `reads`; the write is the other branch of the hook.
21
26
  */
22
- export declare function bashTargets(command: string, cwd: string): {
27
+ export declare function bashTargets(command: string, cwd: string, call?: CallInfo): {
23
28
  reads: string[];
24
29
  writes: string[];
25
30
  factWrites: string[];
@@ -31,7 +36,7 @@ export declare function bashTargets(command: string, cwd: string): {
31
36
  * identifier of at least five characters (after dropping `function`, `const`
32
37
  * ...), so a phrase or a regex with structure names nothing.
33
38
  */
34
- export declare function searchedNames(command: string, cwd: string): {
39
+ export declare function searchedNames(command: string, cwd: string, _call?: CallInfo): {
35
40
  names: string[];
36
41
  operands: string[];
37
42
  };