carrick 0.3.156 → 0.3.158
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.
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +8 -1
- package/dist/contract.js.map +1 -1
- package/dist/engine-ask.d.ts +21 -0
- package/dist/engine-ask.js +50 -0
- package/dist/engine-ask.js.map +1 -0
- package/dist/facts/diff.d.ts +14 -1
- package/dist/facts/diff.js +21 -8
- package/dist/facts/diff.js.map +1 -1
- package/dist/facts/enabled.d.ts +6 -0
- package/dist/facts/enabled.js +8 -0
- package/dist/facts/enabled.js.map +1 -1
- package/dist/facts/fetch.d.ts +7 -0
- package/dist/facts/fetch.js +24 -2
- package/dist/facts/fetch.js.map +1 -1
- package/dist/facts/lines.d.ts +22 -4
- package/dist/facts/lines.js +31 -9
- package/dist/facts/lines.js.map +1 -1
- package/dist/facts/peers.d.ts +13 -4
- package/dist/facts/peers.js +17 -15
- package/dist/facts/peers.js.map +1 -1
- package/dist/facts/rules/packages.js +3 -1
- package/dist/facts/rules/packages.js.map +1 -1
- package/dist/facts/rules/same-name.js +1 -1
- package/dist/facts/rules/same-name.js.map +1 -1
- package/dist/facts/store.d.ts +15 -0
- package/dist/facts/store.js +30 -0
- package/dist/facts/store.js.map +1 -1
- package/dist/held/backoff.d.ts +8 -0
- package/dist/held/backoff.js +43 -0
- package/dist/held/backoff.js.map +1 -0
- package/dist/held/build.d.ts +17 -0
- package/dist/held/build.js +62 -0
- package/dist/held/build.js.map +1 -0
- package/dist/held/client.d.ts +43 -0
- package/dist/held/client.js +200 -0
- package/dist/held/client.js.map +1 -0
- package/dist/held/daemon.d.ts +151 -0
- package/dist/held/daemon.js +399 -0
- package/dist/held/daemon.js.map +1 -0
- package/dist/held/early.d.ts +28 -0
- package/dist/held/early.js +115 -0
- package/dist/held/early.js.map +1 -0
- package/dist/held/engine.d.ts +50 -0
- package/dist/held/engine.js +166 -0
- package/dist/held/engine.js.map +1 -0
- package/dist/held/paths.d.ts +15 -0
- package/dist/held/paths.js +44 -0
- package/dist/held/paths.js.map +1 -0
- package/dist/held/place.d.ts +130 -0
- package/dist/held/place.js +236 -0
- package/dist/held/place.js.map +1 -0
- package/dist/held/registry.d.ts +22 -0
- package/dist/held/registry.js +72 -0
- package/dist/held/registry.js.map +1 -0
- package/dist/held/run.d.ts +2 -0
- package/dist/held/run.js +78 -0
- package/dist/held/run.js.map +1 -0
- package/dist/held/runtime.d.ts +22 -0
- package/dist/held/runtime.js +612 -0
- package/dist/held/runtime.js.map +1 -0
- package/dist/held/shadow.d.ts +33 -0
- package/dist/held/shadow.js +68 -0
- package/dist/held/shadow.js.map +1 -0
- package/dist/held/steps.d.ts +11 -0
- package/dist/held/steps.js +29 -0
- package/dist/held/steps.js.map +1 -0
- package/dist/hook/bash-targets.d.ts +7 -2
- package/dist/hook/bash-targets.js +82 -27
- package/dist/hook/bash-targets.js.map +1 -1
- package/dist/hook/confirm.d.ts +79 -0
- package/dist/hook/confirm.js +220 -0
- package/dist/hook/confirm.js.map +1 -0
- package/dist/hook/edit-flow.d.ts +14 -3
- package/dist/hook/edit-flow.js +113 -33
- package/dist/hook/edit-flow.js.map +1 -1
- package/dist/hook/generation.d.ts +19 -0
- package/dist/hook/generation.js +75 -0
- package/dist/hook/generation.js.map +1 -0
- package/dist/hook/late.d.ts +50 -9
- package/dist/hook/late.js +104 -24
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/lock.d.ts +26 -0
- package/dist/hook/lock.js +122 -0
- package/dist/hook/lock.js.map +1 -0
- package/dist/hook/post-bash.js +17 -8
- package/dist/hook/post-bash.js.map +1 -1
- package/dist/hook/post-edit.js +2 -2
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/post-read.js +25 -3
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/post-search.js +1 -1
- package/dist/hook/post-search.js.map +1 -1
- package/dist/hook/probe.js +1 -0
- package/dist/hook/probe.js.map +1 -1
- package/dist/hook/read-answer.d.ts +5 -0
- package/dist/hook/read-answer.js +8 -4
- package/dist/hook/read-answer.js.map +1 -1
- package/dist/hook/rechecks.d.ts +59 -2
- package/dist/hook/rechecks.js +129 -119
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/session-start.d.ts +1 -1
- package/dist/hook/session-start.js +19 -5
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/similar.d.ts +1 -1
- package/dist/hook/similar.js +21 -8
- package/dist/hook/similar.js.map +1 -1
- package/dist/hook/stop-wait.js +35 -16
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/timings.d.ts +30 -2
- package/dist/hook/timings.js +8 -2
- package/dist/hook/timings.js.map +1 -1
- package/dist/hook/user-prompt.js +2 -2
- package/dist/hook/user-prompt.js.map +1 -1
- package/dist/hosted-snapshot.d.ts +27 -0
- package/dist/hosted-snapshot.js +32 -0
- package/dist/hosted-snapshot.js.map +1 -1
- package/dist/init/hosted.js +2 -9
- package/dist/init/hosted.js.map +1 -1
- package/dist/lsp-frame.d.ts +20 -0
- package/dist/lsp-frame.js +47 -0
- package/dist/lsp-frame.js.map +1 -0
- package/dist/render.d.ts +15 -1
- package/dist/render.js +50 -4
- package/dist/render.js.map +1 -1
- package/dist/server.js +5 -29
- package/dist/server.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/capture/anchors.d.ts +8 -0
- package/sidecar/dist/src/capture/anchors.js +3 -2
- package/sidecar/dist/src/capture/api.d.ts +98 -1
- package/sidecar/dist/src/capture/check-classify.d.ts +7 -0
- package/sidecar/dist/src/capture/check-classify.js +24 -0
- package/sidecar/dist/src/capture/check-probe.d.ts +86 -11
- package/sidecar/dist/src/capture/check-probe.js +175 -22
- package/sidecar/dist/src/capture/check.js +13 -1
- package/sidecar/dist/src/capture/graphql-leaves.d.ts +46 -0
- package/sidecar/dist/src/capture/graphql-leaves.js +142 -0
- package/sidecar/dist/src/capture/index.d.ts +12 -3
- package/sidecar/dist/src/capture/index.js +11 -2
- package/sidecar/dist/src/capture/result-label.js +3 -1
- package/sidecar/dist/src/capture/type-reasons.json +78 -0
- package/sidecar/dist/src/definition-resolver.d.ts +6 -5
- package/sidecar/dist/src/definition-resolver.js +20 -15
- package/sidecar/dist/src/engine-stamp.json +1 -0
- package/sidecar/dist/src/held-shadow.d.ts +70 -0
- package/sidecar/dist/src/held-shadow.js +222 -0
- package/sidecar/dist/src/index.js +65 -2
- package/sidecar/dist/src/library-claims.d.ts +3 -1
- package/sidecar/dist/src/library-claims.js +105 -6
- package/sidecar/dist/src/retype.d.ts +47 -0
- package/sidecar/dist/src/retype.js +274 -18
- package/sidecar/dist/src/site-find.d.ts +27 -0
- package/sidecar/dist/src/site-find.js +109 -0
- package/sidecar/dist/src/type-home.d.ts +12 -0
- package/sidecar/dist/src/type-home.js +41 -1
- package/sidecar/dist/src/type-inferrer.d.ts +13 -3
- package/sidecar/dist/src/type-inferrer.js +44 -22
- package/sidecar/dist/src/type-structural-expander.d.ts +11 -11
- package/sidecar/dist/src/type-structural-expander.js +73 -4
- package/sidecar/dist/src/types.d.ts +91 -5
- package/sidecar/dist/src/validators.d.ts +621 -254
- package/sidecar/dist/src/validators.js +37 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// The held compiler's early answer (part 3, B1): the breaks the daemon found for
|
|
2
|
+
// one queued edit, as a `CheckResult` built from the fact row, so it prints
|
|
3
|
+
// through the one renderer (`renderPostToolUse`) and compares row by row with
|
|
4
|
+
// the full re-check's answer (`hook/confirm.ts`).
|
|
5
|
+
//
|
|
6
|
+
// A row in the edited file is a `CheckItem`; a row in another file is a
|
|
7
|
+
// `recheck.moved` row. The compiler's message is the verdict's detail, with the
|
|
8
|
+
// check's own alias replaced; a message that still names the check's machinery
|
|
9
|
+
// is never written.
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { realPath } from "../fs-util.js";
|
|
12
|
+
/** A quoted inline object type longer than this becomes `the reply`. */
|
|
13
|
+
const MAX_INLINE_TYPE = 80;
|
|
14
|
+
/** The check's alias in a message: `O<row>_<group>`. */
|
|
15
|
+
const ALIAS = /'O\d+_\d+'/g;
|
|
16
|
+
/** A quoted inline object type; its inner text has no quote of its own (the compiler quotes literals with double quotes). */
|
|
17
|
+
const INLINE_OBJECT = /'(\{[^']*\})'/g;
|
|
18
|
+
/** What must never reach an agent. */
|
|
19
|
+
const MACHINERY = /__C\b|\bsend\d|\bO\d+_\d+\b|__carrick_/;
|
|
20
|
+
/** At most this many characters in one detail. */
|
|
21
|
+
export const MAX_HELD_DETAIL = 240;
|
|
22
|
+
/** What the expected type is cut to, as the CLI cuts its own. */
|
|
23
|
+
const MAX_TYPE = 200;
|
|
24
|
+
/** The compiler's message for one break, in words an agent may read, or null when it still shows the check's machinery. */
|
|
25
|
+
export function heldDetail(line) {
|
|
26
|
+
const message = line.message
|
|
27
|
+
.replace(ALIAS, line.symbol ? `'${line.symbol}'` : "the type it expects")
|
|
28
|
+
.replace(INLINE_OBJECT, (whole, inner) => (inner.length > MAX_INLINE_TYPE ? "the reply" : whole))
|
|
29
|
+
.replace(/\s+/g, " ")
|
|
30
|
+
.trim();
|
|
31
|
+
if (MACHINERY.test(message))
|
|
32
|
+
return null;
|
|
33
|
+
return message.length > MAX_HELD_DETAIL ? `${message.slice(0, MAX_HELD_DETAIL - 1)}…` : message;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A contract row's label in the parts a check item carries: `METHOD path`, and
|
|
37
|
+
* the dispatch case (` {field=value}`) when the label ends in one, so that
|
|
38
|
+
* `method + " " + path + dispatch_label` is the label again.
|
|
39
|
+
*/
|
|
40
|
+
export function splitLabel(label) {
|
|
41
|
+
const space = label.indexOf(" ");
|
|
42
|
+
const method = space < 0 ? label : label.slice(0, space);
|
|
43
|
+
const rest = space < 0 ? "" : label.slice(space + 1);
|
|
44
|
+
const dispatch = / \{[^{}]*\}$/.exec(rest);
|
|
45
|
+
if (dispatch === null)
|
|
46
|
+
return { method, path: rest };
|
|
47
|
+
return { method, path: rest.slice(0, dispatch.index), dispatch_label: dispatch[0] };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The early answer for one entry: a `CheckResult` whose items are the breaks in
|
|
51
|
+
* the edited file and whose `recheck.moved` rows are the breaks in other files.
|
|
52
|
+
* Each (row, group) the daemon names is one row; a row named twice (two
|
|
53
|
+
* groups) is one row with every group's places.
|
|
54
|
+
*/
|
|
55
|
+
export function earlyResult(entry, lines) {
|
|
56
|
+
const edited = realPath(entry.file);
|
|
57
|
+
const items = new Map();
|
|
58
|
+
const moved = new Map();
|
|
59
|
+
for (const line of lines) {
|
|
60
|
+
const detail = heldDetail(line);
|
|
61
|
+
if (detail === null)
|
|
62
|
+
continue;
|
|
63
|
+
const parts = splitLabel(line.label);
|
|
64
|
+
if (realPath(line.row_path) === edited) {
|
|
65
|
+
const counterparts = line.places.map((p) => ({
|
|
66
|
+
role: "consumer",
|
|
67
|
+
service: p.service,
|
|
68
|
+
file: p.file,
|
|
69
|
+
...(p.line === null ? {} : { line: p.line }),
|
|
70
|
+
}));
|
|
71
|
+
const held = items.get(line.label);
|
|
72
|
+
if (held) {
|
|
73
|
+
held.counterparts = [...(held.counterparts ?? []), ...counterparts];
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
items.set(line.label, {
|
|
77
|
+
kind: "route",
|
|
78
|
+
...parts,
|
|
79
|
+
...(line.row_line === null ? {} : { line: line.row_line }),
|
|
80
|
+
direction: "response",
|
|
81
|
+
verdict: { state: "resolved", result: "type_mismatch", detail },
|
|
82
|
+
expected_type: line.expected.length > MAX_TYPE ? `${line.expected.slice(0, MAX_TYPE - 3)}...` : line.expected,
|
|
83
|
+
counterparts,
|
|
84
|
+
});
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const file = path.relative(realPath(entry.root), realPath(line.row_path));
|
|
88
|
+
const places = line.places.map((p) => `${p.service} ${p.file}${p.line === null ? "" : `:${p.line}`}`);
|
|
89
|
+
const key = `${file}\0${line.label}`;
|
|
90
|
+
const held = moved.get(key);
|
|
91
|
+
if (held) {
|
|
92
|
+
held.counterparts.push(...places);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
moved.set(key, {
|
|
96
|
+
file,
|
|
97
|
+
...(line.row_line === null ? {} : { line: line.row_line }),
|
|
98
|
+
role: "route",
|
|
99
|
+
method: parts.method,
|
|
100
|
+
path: parts.path + (parts.dispatch_label ?? ""),
|
|
101
|
+
before: "compatible",
|
|
102
|
+
after: "type_mismatch",
|
|
103
|
+
counterparts: places,
|
|
104
|
+
reason: detail,
|
|
105
|
+
not_judged_before: false,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
schema: "carrick.check/0",
|
|
110
|
+
file: path.relative(realPath(entry.root), edited),
|
|
111
|
+
items: [...items.values()],
|
|
112
|
+
...(moved.size > 0 ? { recheck: { ran: "extraction+types", elapsed_ms: 0, moved: [...moved.values()] } } : {}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=early.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early.js","sourceRoot":"","sources":["../../src/held/early.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,4EAA4E;AAC5E,8EAA8E;AAC9E,kDAAkD;AAClD,EAAE;AACF,wEAAwE;AACxE,gFAAgF;AAChF,+EAA+E;AAC/E,oBAAoB;AAEpB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,wEAAwE;AACxE,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,wDAAwD;AACxD,MAAM,KAAK,GAAG,aAAa,CAAC;AAC5B,6HAA6H;AAC7H,MAAM,aAAa,GAAG,gBAAgB,CAAC;AACvC,sCAAsC;AACtC,M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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type Diag = {
|
|
2
|
+
range: {
|
|
3
|
+
start: {
|
|
4
|
+
line: number;
|
|
5
|
+
character: number;
|
|
6
|
+
};
|
|
7
|
+
end: {
|
|
8
|
+
line: number;
|
|
9
|
+
character: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
severity?: number;
|
|
13
|
+
code?: number | string;
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
export interface Engine {
|
|
17
|
+
/** The file's whole text, as it is now. The first call opens it, later ones replace it. */
|
|
18
|
+
set(file: string, text: string): void;
|
|
19
|
+
/** Diagnostics for each file, asked together. Rejects when the compiler cannot answer in full. */
|
|
20
|
+
pull(files: string[]): Promise<Map<string, Diag[]>>;
|
|
21
|
+
/** Resident memory of the compiler process in MB, or null when it is not running. */
|
|
22
|
+
rss(): number | null;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare class Ts7Lsp implements Engine {
|
|
26
|
+
private readonly child;
|
|
27
|
+
private readonly framer;
|
|
28
|
+
private readonly pending;
|
|
29
|
+
private readonly versions;
|
|
30
|
+
private readonly cwd;
|
|
31
|
+
private nextId;
|
|
32
|
+
private exited;
|
|
33
|
+
/** Everything sent after `initialize` waits on this, so order is the call order. */
|
|
34
|
+
private readonly ready;
|
|
35
|
+
stderr: string;
|
|
36
|
+
/**
|
|
37
|
+
* @param command the native compiler executable (a `tsc` that speaks `--lsp`)
|
|
38
|
+
* @param cwd the shadow's `w` directory, where the generated tsconfig is
|
|
39
|
+
*/
|
|
40
|
+
constructor(command: string, cwd: string, args?: string[]);
|
|
41
|
+
private fail;
|
|
42
|
+
private consume;
|
|
43
|
+
private write;
|
|
44
|
+
private request;
|
|
45
|
+
private initialize;
|
|
46
|
+
set(file: string, text: string): void;
|
|
47
|
+
pull(files: string[]): Promise<Map<string, Diag[]>>;
|
|
48
|
+
rss(): number | null;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// The held compiler: one language server kept open over a shadow tree, so an
|
|
2
|
+
// edit is judged in hundreds of milliseconds instead of a cold compile.
|
|
3
|
+
//
|
|
4
|
+
// `Engine` is the seam: the daemon asks for diagnostics and never learns which
|
|
5
|
+
// compiler answers. `Ts7Lsp` is the TypeScript 7 implementation, spoken to over
|
|
6
|
+
// `tsc --lsp --stdio`. Another compiler swaps in behind the same interface.
|
|
7
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { Framer, frame } from "../lsp-frame.js";
|
|
11
|
+
export class Ts7Lsp {
|
|
12
|
+
child;
|
|
13
|
+
framer = new Framer();
|
|
14
|
+
pending = new Map();
|
|
15
|
+
versions = new Map();
|
|
16
|
+
cwd;
|
|
17
|
+
nextId = 1;
|
|
18
|
+
exited = false;
|
|
19
|
+
/** Everything sent after `initialize` waits on this, so order is the call order. */
|
|
20
|
+
ready;
|
|
21
|
+
stderr = "";
|
|
22
|
+
/**
|
|
23
|
+
* @param command the native compiler executable (a `tsc` that speaks `--lsp`)
|
|
24
|
+
* @param cwd the shadow's `w` directory, where the generated tsconfig is
|
|
25
|
+
*/
|
|
26
|
+
constructor(command, cwd, args = ["--lsp", "--stdio"]) {
|
|
27
|
+
this.cwd = cwd;
|
|
28
|
+
this.child = spawn(command, args, {
|
|
29
|
+
cwd,
|
|
30
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
31
|
+
env: { ...process.env, DO_NOT_TRACK: "1" },
|
|
32
|
+
});
|
|
33
|
+
this.child.stdout.on("data", (chunk) => this.consume(chunk));
|
|
34
|
+
this.child.stderr.on("data", (chunk) => {
|
|
35
|
+
this.stderr += chunk.toString("utf8");
|
|
36
|
+
});
|
|
37
|
+
this.child.on("error", (error) => this.fail(error));
|
|
38
|
+
this.child.on("exit", () => {
|
|
39
|
+
this.exited = true;
|
|
40
|
+
this.fail(new Error("compiler exited"));
|
|
41
|
+
});
|
|
42
|
+
this.ready = this.initialize();
|
|
43
|
+
// A start that fails is reported by the first `pull`; it must not also be
|
|
44
|
+
// an unhandled rejection here.
|
|
45
|
+
this.ready.catch(() => undefined);
|
|
46
|
+
}
|
|
47
|
+
fail(error) {
|
|
48
|
+
for (const pending of this.pending.values())
|
|
49
|
+
pending.reject(error);
|
|
50
|
+
this.pending.clear();
|
|
51
|
+
}
|
|
52
|
+
consume(chunk) {
|
|
53
|
+
for (const message of this.framer.push(chunk)) {
|
|
54
|
+
if (message.id !== undefined && message.method) {
|
|
55
|
+
// A request from the compiler: settings come back empty, anything else is accepted.
|
|
56
|
+
const items = message.params?.["items"] ?? [];
|
|
57
|
+
const result = message.method === "workspace/configuration" ? items.map(() => null) : null;
|
|
58
|
+
this.write({ id: message.id, result });
|
|
59
|
+
}
|
|
60
|
+
else if (typeof message.id === "number") {
|
|
61
|
+
const pending = this.pending.get(message.id);
|
|
62
|
+
this.pending.delete(message.id);
|
|
63
|
+
pending?.resolve(message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
write(message) {
|
|
68
|
+
if (this.exited)
|
|
69
|
+
return;
|
|
70
|
+
this.child.stdin.write(frame(message));
|
|
71
|
+
}
|
|
72
|
+
request(method, params) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
if (this.exited) {
|
|
75
|
+
reject(new Error("compiler exited"));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const id = this.nextId++;
|
|
79
|
+
this.pending.set(id, { resolve, reject });
|
|
80
|
+
this.write({ id, method, params });
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async initialize() {
|
|
84
|
+
const uri = pathToFileURL(this.cwd).toString();
|
|
85
|
+
const answer = await this.request("initialize", {
|
|
86
|
+
processId: process.pid,
|
|
87
|
+
rootUri: uri,
|
|
88
|
+
workspaceFolders: [{ uri, name: path.basename(path.dirname(this.cwd)) }],
|
|
89
|
+
capabilities: {
|
|
90
|
+
textDocument: {
|
|
91
|
+
diagnostic: { dynamicRegistration: false },
|
|
92
|
+
synchronization: { didSave: true },
|
|
93
|
+
},
|
|
94
|
+
workspace: { configuration: true, workspaceFolders: true },
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
if (answer.error)
|
|
98
|
+
throw new Error(`initialize failed: ${answer.error.message}`);
|
|
99
|
+
this.write({ method: "initialized", params: {} });
|
|
100
|
+
}
|
|
101
|
+
set(file, text) {
|
|
102
|
+
const uri = pathToFileURL(file).toString();
|
|
103
|
+
const version = (this.versions.get(file) ?? 0) + 1;
|
|
104
|
+
this.versions.set(file, version);
|
|
105
|
+
const message = version === 1
|
|
106
|
+
? {
|
|
107
|
+
method: "textDocument/didOpen",
|
|
108
|
+
params: { textDocument: { uri, languageId: "typescript", version, text } },
|
|
109
|
+
}
|
|
110
|
+
: {
|
|
111
|
+
method: "textDocument/didChange",
|
|
112
|
+
params: { textDocument: { uri, version }, contentChanges: [{ text }] },
|
|
113
|
+
};
|
|
114
|
+
void this.ready.then(() => this.write(message)).catch(() => undefined);
|
|
115
|
+
}
|
|
116
|
+
async pull(files) {
|
|
117
|
+
await this.ready;
|
|
118
|
+
const answers = await Promise.all(files.map((file) => this.request("textDocument/diagnostic", {
|
|
119
|
+
textDocument: { uri: pathToFileURL(file).toString() },
|
|
120
|
+
})));
|
|
121
|
+
const out = new Map();
|
|
122
|
+
files.forEach((file, i) => {
|
|
123
|
+
const answer = answers[i];
|
|
124
|
+
if (answer.error)
|
|
125
|
+
throw new Error(`diagnostic request failed: ${answer.error.message}`);
|
|
126
|
+
const result = answer.result;
|
|
127
|
+
// Anything but a full report is not "no diagnostics": it is no answer.
|
|
128
|
+
if (result?.kind !== "full") {
|
|
129
|
+
throw new Error(`diagnostic answer for ${file} is not a full report (${result?.kind ?? "null"})`);
|
|
130
|
+
}
|
|
131
|
+
out.set(file, result.items ?? []);
|
|
132
|
+
});
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
rss() {
|
|
136
|
+
const pid = this.child.pid;
|
|
137
|
+
if (this.exited || pid === undefined)
|
|
138
|
+
return null;
|
|
139
|
+
try {
|
|
140
|
+
const kb = Number.parseInt(execFileSync("ps", ["-o", "rss=", "-p", String(pid)]).toString().trim(), 10);
|
|
141
|
+
return Number.isFinite(kb) ? Math.round(kb / 1024) : null;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async close() {
|
|
148
|
+
if (this.exited)
|
|
149
|
+
return;
|
|
150
|
+
const exit = new Promise((resolve) => this.child.once("exit", () => resolve()));
|
|
151
|
+
try {
|
|
152
|
+
await Promise.race([
|
|
153
|
+
this.ready.then(() => this.request("shutdown", null)),
|
|
154
|
+
new Promise((resolve) => setTimeout(resolve, 2000)),
|
|
155
|
+
]);
|
|
156
|
+
this.write({ method: "exit" });
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Killed below.
|
|
160
|
+
}
|
|
161
|
+
const timer = setTimeout(() => this.child.kill("SIGKILL"), 3000);
|
|
162
|
+
await exit;
|
|
163
|
+
clearTimeout(timer);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/held/engine.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wEAAwE;AACxE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,4EAA4E;AAE5E,OAAO,EAAE,YAAY,EAAE,KAAK,EAAuC,MAAM,oBAAoB,CAAC;AAC9F,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAmB,MAAM,iBAAiB,CAAC;A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CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
/** D4: the service's shadow tree, `w/` (its own files) and `v/` (the vendored program). */
|
|
9
|
+
export declare function shadowDir(root: string, service: string, home?: string): string;
|
|
10
|
+
/** The rows the gate armed and the rows it saved with a reason. */
|
|
11
|
+
export declare function placedPath(root: string, service: string, home?: string): string;
|
|
12
|
+
/** One JSON line per request. */
|
|
13
|
+
export declare function logPath(root: string, home?: string): string;
|
|
14
|
+
/** One `<unix seconds> <build id>` line per daemon crash (the back-off reads it). */
|
|
15
|
+
export declare function crashesPath(root: string, home?: string): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
/** A service name as one safe path segment (a hash keeps two names that sanitise alike apart). */
|
|
24
|
+
function serviceSegment(service) {
|
|
25
|
+
const hash = createHash("sha256").update(service).digest("hex").slice(0, 6);
|
|
26
|
+
return `${service.replace(/[^A-Za-z0-9._-]/g, "_")}-${hash}`;
|
|
27
|
+
}
|
|
28
|
+
/** D4: the service's shadow tree, `w/` (its own files) and `v/` (the vendored program). */
|
|
29
|
+
export function shadowDir(root, service, home) {
|
|
30
|
+
return path.join(heldDir(home), rootKey(root), serviceSegment(service));
|
|
31
|
+
}
|
|
32
|
+
/** The rows the gate armed and the rows it saved with a reason. */
|
|
33
|
+
export function placedPath(root, service, home) {
|
|
34
|
+
return path.join(heldDir(home), rootKey(root), `${serviceSegment(service)}.placed.json`);
|
|
35
|
+
}
|
|
36
|
+
/** One JSON line per request. */
|
|
37
|
+
export function logPath(root, home) {
|
|
38
|
+
return path.join(heldDir(home), `${rootKey(root)}.log`);
|
|
39
|
+
}
|
|
40
|
+
/** One `<unix seconds> <build id>` line per daemon crash (the back-off reads it). */
|
|
41
|
+
export function crashesPath(root, home) {
|
|
42
|
+
return path.join(heldDir(home), `${rootKey(root)}.crashes`);
|
|
43
|
+
}
|
|
44
|
+
//# 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;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,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OAAe,EAAE,IAAa;IACpE,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,OAAe,EAAE,IAAa;IACrE,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AAC3F,CAAC;AAED,iCAAiC;AACjC,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,IAAa;IACjD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAa;IACrD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** One value's position: `[start, end)` in UTF-16 code units, never counting a leading BOM. */
|
|
2
|
+
export type Value = {
|
|
3
|
+
file: string;
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
};
|
|
7
|
+
/** Why a value has no check. */
|
|
8
|
+
export type ValueReason = "value_not_a_node" | "not_wrappable" | "value_edited";
|
|
9
|
+
export type UnplacedReason = ValueReason | "javascript_file";
|
|
10
|
+
/** One changed stretch of text: the old and the new bounds (BOM not counted). */
|
|
11
|
+
export type Region = {
|
|
12
|
+
oldStart: number;
|
|
13
|
+
oldEnd: number;
|
|
14
|
+
newStart: number;
|
|
15
|
+
newEnd: number;
|
|
16
|
+
};
|
|
17
|
+
/** What the compiler engine is asked: the node the old span named, in the new text. */
|
|
18
|
+
export type SiteQuery = {
|
|
19
|
+
file: string;
|
|
20
|
+
oldText: string;
|
|
21
|
+
newText: string;
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
};
|
|
25
|
+
export type SiteAnswer = {
|
|
26
|
+
start: number;
|
|
27
|
+
end: number;
|
|
28
|
+
} | {
|
|
29
|
+
reason: ValueReason;
|
|
30
|
+
};
|
|
31
|
+
/** The compiler engine's site finder (the engine action beside `site-node.ts`); a fake in tests. */
|
|
32
|
+
export type SiteFinder = (query: SiteQuery) => Promise<SiteAnswer>;
|
|
33
|
+
/** A compiler diagnostic: its start offset in the checked text, its code, its message. */
|
|
34
|
+
export type Diag = {
|
|
35
|
+
start: number;
|
|
36
|
+
code: number;
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
export type UnarmedReason = "twin_passes" | "decl_error" | `clean_check_fails:TS${number}`;
|
|
40
|
+
/** One (row, position) pair, numbered across the overlay, with one stated type per group. */
|
|
41
|
+
export type CheckInput = {
|
|
42
|
+
n: number;
|
|
43
|
+
value: Value;
|
|
44
|
+
groups: Array<{
|
|
45
|
+
type: string;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
export type Check = {
|
|
49
|
+
n: number;
|
|
50
|
+
group: number;
|
|
51
|
+
/** `<n>_<group>`; the check's alias is `O<k>`. */
|
|
52
|
+
k: string;
|
|
53
|
+
/** The whole check expression: `__C.send<k>(` through `, (o) => o)`. */
|
|
54
|
+
span: [number, number];
|
|
55
|
+
/** The check's two declaration lines in the appended namespace. */
|
|
56
|
+
declSpan: [number, number];
|
|
57
|
+
};
|
|
58
|
+
export type Overlay = {
|
|
59
|
+
text: string;
|
|
60
|
+
checks: Check[];
|
|
61
|
+
unplaced: Array<{
|
|
62
|
+
n: number;
|
|
63
|
+
reason: UnplacedReason;
|
|
64
|
+
}>;
|
|
65
|
+
/** Offset where the appended namespace starts. */
|
|
66
|
+
bodyEnd: number;
|
|
67
|
+
};
|
|
68
|
+
/** One region, from the common prefix and suffix of the two texts. */
|
|
69
|
+
export declare function regionOfEdit(oldText: string, newText: string): Region;
|
|
70
|
+
/**
|
|
71
|
+
* `git diff -U0` line hunks turned into character regions, each narrowed by
|
|
72
|
+
* common prefix and suffix inside its hunk (a hunk replaces whole lines; the
|
|
73
|
+
* change is usually a few characters of them).
|
|
74
|
+
*/
|
|
75
|
+
export declare function regionsFromHunks(oldText: string, newText: string, diffU0: string): Region[];
|
|
76
|
+
/**
|
|
77
|
+
* The text a check appends: the engine's wire declarations and its tolerance
|
|
78
|
+
* helpers (K-a: a receiver declared void states no contract; an absent body
|
|
79
|
+
* the receiver admits is dropped), composed into the one type a check's
|
|
80
|
+
* callback receives. Nothing here restates a rule: it only names the order
|
|
81
|
+
* the judge applies them in. The literal-widened tolerance reads an export
|
|
82
|
+
* of a scan's stub, so it cannot apply here.
|
|
83
|
+
*/
|
|
84
|
+
export declare function checkWire(wire: string[], tolerances: string[]): string[];
|
|
85
|
+
/**
|
|
86
|
+
* V5, the two arithmetic cases. A region meets the value when it touches
|
|
87
|
+
* `[start, end]`. None does: the value shifts by the regions before it. Every
|
|
88
|
+
* one that does lies strictly inside: the value keeps its bounds and grows or
|
|
89
|
+
* shrinks with them. Any other edit (one across a bound) is the engine's to
|
|
90
|
+
* place again: `"needs_site"`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function mapValue(value: Value, regions: Region[]): Value | "needs_site";
|
|
93
|
+
/** `mapValue`, and for an edit across a bound the compiler engine's site finder on both texts. */
|
|
94
|
+
export declare function resolveValue(value: Value, regions: Region[], oldText: string, newText: string, find: SiteFinder): Promise<Value | ValueReason>;
|
|
95
|
+
/**
|
|
96
|
+
* The file with every placeable value wrapped. `wire` is `checkWire`'s text (it holds
|
|
97
|
+
* `__carrick_Sent<S, E>`). `clean` states each
|
|
98
|
+
* group's type; `twin` states it intersected with a property no value has, so
|
|
99
|
+
* it must fail where the check can see the value at all.
|
|
100
|
+
*/
|
|
101
|
+
export declare function overlay(file: string, text: string, checks: CheckInput[], wire: string[], mode: "clean" | "twin"): Overlay;
|
|
102
|
+
/**
|
|
103
|
+
* R3. A diagnostic is a check's own line only when its start lies in the
|
|
104
|
+
* check's whole expression AND its message names the check's alias. Several
|
|
105
|
+
* checks can share an expression (two groups of one value, a nest): the
|
|
106
|
+
* narrowest that the message names wins. A diagnostic in a check's declaration
|
|
107
|
+
* lines is that check's `decl_error`. Everything else is `outside`, and never
|
|
108
|
+
* a line.
|
|
109
|
+
*/
|
|
110
|
+
export declare function attribute(ov: Overlay, diags: Diag[]): {
|
|
111
|
+
lines: Map<string, Diag[]>;
|
|
112
|
+
declErrors: Set<string>;
|
|
113
|
+
outside: Diag[];
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* D6. On the current text, a check is armed only when its clean form is
|
|
117
|
+
* silent and its twin speaks. The gate reads the check's span, not the alias
|
|
118
|
+
* name: the twin's message may print the expanded intersection instead of
|
|
119
|
+
* `O<k>`, and the gate must not take that for silence. Only the gate is this
|
|
120
|
+
* broad; a line (see `attribute`) never is.
|
|
121
|
+
*/
|
|
122
|
+
export declare function arm(ov: Overlay, clean: Diag[], twin: Diag[]): {
|
|
123
|
+
armed: string[];
|
|
124
|
+
unarmed: Array<{
|
|
125
|
+
k: string;
|
|
126
|
+
n: number;
|
|
127
|
+
group: number;
|
|
128
|
+
reason: UnarmedReason;
|
|
129
|
+
}>;
|
|
130
|
+
};
|