carrick 0.3.153 → 0.3.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/carrick.mjs +26 -4
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +37 -3
- package/dist/contract.js +8 -0
- package/dist/contract.js.map +1 -1
- package/dist/facts/diff.d.ts +27 -0
- package/dist/facts/diff.js +134 -0
- package/dist/facts/diff.js.map +1 -0
- package/dist/facts/enabled.d.ts +2 -0
- package/dist/facts/enabled.js +9 -0
- package/dist/facts/enabled.js.map +1 -0
- package/dist/facts/fetch.d.ts +48 -0
- package/dist/facts/fetch.js +235 -0
- package/dist/facts/fetch.js.map +1 -0
- package/dist/facts/files.d.ts +21 -0
- package/dist/facts/files.js +58 -0
- package/dist/facts/files.js.map +1 -0
- package/dist/facts/lines.d.ts +70 -0
- package/dist/facts/lines.js +335 -0
- package/dist/facts/lines.js.map +1 -0
- package/dist/facts/match.d.ts +91 -0
- package/dist/facts/match.js +1122 -0
- package/dist/facts/match.js.map +1 -0
- package/dist/facts/peers.d.ts +48 -0
- package/dist/facts/peers.js +143 -0
- package/dist/facts/peers.js.map +1 -0
- package/dist/facts/refresh-run.d.ts +2 -0
- package/dist/facts/refresh-run.js +18 -0
- package/dist/facts/refresh-run.js.map +1 -0
- package/dist/facts/rules/packages.d.ts +16 -0
- package/dist/facts/rules/packages.js +157 -0
- package/dist/facts/rules/packages.js.map +1 -0
- package/dist/facts/rules/same-name.d.ts +28 -0
- package/dist/facts/rules/same-name.js +131 -0
- package/dist/facts/rules/same-name.js.map +1 -0
- package/dist/facts/store.d.ts +119 -0
- package/dist/facts/store.js +341 -0
- package/dist/facts/store.js.map +1 -0
- package/dist/git-remote.d.ts +6 -0
- package/dist/git-remote.js +37 -0
- package/dist/git-remote.js.map +1 -0
- package/dist/hook/apply-patch.d.ts +23 -0
- package/dist/hook/apply-patch.js +92 -0
- package/dist/hook/apply-patch.js.map +1 -1
- package/dist/hook/bash-targets.d.ts +8 -0
- package/dist/hook/bash-targets.js +23 -11
- package/dist/hook/bash-targets.js.map +1 -1
- package/dist/hook/edit-flow.d.ts +29 -2
- package/dist/hook/edit-flow.js +80 -29
- package/dist/hook/edit-flow.js.map +1 -1
- package/dist/hook/late.d.ts +29 -0
- package/dist/hook/late.js +121 -26
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/post-bash.js +45 -22
- package/dist/hook/post-bash.js.map +1 -1
- package/dist/hook/post-edit.d.ts +16 -1
- package/dist/hook/post-edit.js +177 -13
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/post-read.js +8 -12
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/post-search.d.ts +2 -0
- package/dist/hook/post-search.js +25 -0
- package/dist/hook/post-search.js.map +1 -0
- package/dist/hook/probe.d.ts +18 -3
- package/dist/hook/probe.js +30 -6
- package/dist/hook/probe.js.map +1 -1
- package/dist/hook/rechecks.d.ts +66 -11
- package/dist/hook/rechecks.js +115 -29
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/refresh.d.ts +9 -0
- package/dist/hook/refresh.js +10 -0
- package/dist/hook/refresh.js.map +1 -1
- package/dist/hook/reuse.d.ts +16 -2
- package/dist/hook/reuse.js +49 -6
- package/dist/hook/reuse.js.map +1 -1
- package/dist/hook/session-key.d.ts +12 -0
- package/dist/hook/session-key.js +30 -0
- package/dist/hook/session-key.js.map +1 -0
- package/dist/hook/session-start.js +14 -7
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/stop-wait.d.ts +2 -9
- package/dist/hook/stop-wait.js +96 -113
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/stop.js +13 -8
- package/dist/hook/stop.js.map +1 -1
- package/dist/hook/subagent-stop.d.ts +2 -0
- package/dist/hook/subagent-stop.js +45 -0
- package/dist/hook/subagent-stop.js.map +1 -0
- package/dist/hook/timings.d.ts +72 -0
- package/dist/hook/timings.js +175 -0
- package/dist/hook/timings.js.map +1 -0
- package/dist/hook/user-prompt.js +17 -13
- package/dist/hook/user-prompt.js.map +1 -1
- package/dist/hook/worktree.d.ts +11 -0
- package/dist/hook/worktree.js +27 -1
- package/dist/hook/worktree.js.map +1 -1
- package/dist/init/repo-copies.d.ts +6 -0
- package/dist/init/repo-copies.js +7 -3
- package/dist/init/repo-copies.js.map +1 -1
- package/dist/init/repos.d.ts +2 -2
- package/dist/init/repos.js +1 -34
- package/dist/init/repos.js.map +1 -1
- package/dist/init/settings.js +25 -13
- package/dist/init/settings.js.map +1 -1
- package/dist/render.d.ts +8 -33
- package/dist/render.js +42 -120
- package/dist/render.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/hooks.json +44 -3
- package/scripts/install-scanned-deps.sh +25 -2
- package/sidecar/dist/src/capture/anchors.d.ts +12 -1
- package/sidecar/dist/src/capture/anchors.js +28 -47
- package/sidecar/dist/src/capture/api.d.ts +41 -1
- package/sidecar/dist/src/capture/augmentations.d.ts +2 -0
- package/sidecar/dist/src/capture/augmentations.js +1 -1
- package/sidecar/dist/src/capture/check-classify.d.ts +12 -1
- package/sidecar/dist/src/capture/check-classify.js +43 -0
- package/sidecar/dist/src/capture/check-deep.d.ts +44 -1
- package/sidecar/dist/src/capture/check-deep.js +161 -2
- package/sidecar/dist/src/capture/check.js +23 -2
- package/sidecar/dist/src/capture/checkout.d.ts +9 -3
- package/sidecar/dist/src/capture/checkout.js +12 -5
- package/sidecar/dist/src/capture/deep-walk.d.ts +25 -0
- package/sidecar/dist/src/capture/deep-walk.js +41 -0
- package/sidecar/dist/src/capture/deno-project.d.ts +22 -0
- package/sidecar/dist/src/capture/deno-project.js +48 -1
- package/sidecar/dist/src/capture/index.d.ts +3 -1
- package/sidecar/dist/src/capture/index.js +14 -4
- package/sidecar/dist/src/capture/machinery.d.ts +8 -53
- package/sidecar/dist/src/capture/machinery.js +10 -157
- package/sidecar/dist/src/capture/node-builder.d.ts +6 -0
- package/sidecar/dist/src/capture/self-check.d.ts +7 -0
- package/sidecar/dist/src/capture/self-check.js +44 -1
- package/sidecar/dist/src/capture/site-node.d.ts +166 -0
- package/sidecar/dist/src/capture/site-node.js +570 -0
- package/sidecar/dist/src/capture/tool-env.d.ts +12 -0
- package/sidecar/dist/src/capture/tool-env.js +26 -0
- package/sidecar/dist/src/default-library.d.ts +39 -0
- package/sidecar/dist/src/default-library.js +132 -0
- package/sidecar/dist/src/definition-resolver.js +2 -0
- package/sidecar/dist/src/index.js +1 -1
- package/sidecar/dist/src/library-claims.d.ts +2 -0
- package/sidecar/dist/src/library-claims.js +387 -37
- package/sidecar/dist/src/node-index.d.ts +2 -0
- package/sidecar/dist/src/node-index.js +5 -1
- package/sidecar/dist/src/position-rows.d.ts +78 -7
- package/sidecar/dist/src/position-rows.js +343 -18
- package/sidecar/dist/src/project-loader.d.ts +3 -3
- package/sidecar/dist/src/project-loader.js +18 -9
- package/sidecar/dist/src/retype.d.ts +13 -0
- package/sidecar/dist/src/retype.js +126 -0
- package/sidecar/dist/src/type-inferrer.d.ts +47 -145
- package/sidecar/dist/src/type-inferrer.js +102 -529
- package/sidecar/dist/src/types.d.ts +64 -2
- package/sidecar/dist/src/validators.d.ts +806 -142
- package/sidecar/dist/src/validators.js +12 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// The fact lines for an edit: which rows of the fact file the edit touched,
|
|
2
|
+
// found by name in the file's current text, printed verbatim from each row's
|
|
3
|
+
// `text` (the cloud writes the sentence; this package adds none).
|
|
4
|
+
//
|
|
5
|
+
// A row is found by (repo, name): the named things the changed lines sit in
|
|
6
|
+
// (`match.ts`), declared once in the edited file. A row prints only for its
|
|
7
|
+
// own file, never for a file it might have moved from. A
|
|
8
|
+
// row with no name (an inline handler or a call at module top level) is found
|
|
9
|
+
// only by its `site`, written as a string argument of the call around the
|
|
10
|
+
// changed line, with an HTTP row's method as the callee's name; when that
|
|
11
|
+
// pair is not unique in the file, or the row has no site, nothing prints.
|
|
12
|
+
//
|
|
13
|
+
// Each row is said once per session, claimed only once delivered (the caller
|
|
14
|
+
// calls `markFacts` after printing). An op or fn line prints only while the
|
|
15
|
+
// peer files it names read as at the index commit (`peers.ts`). Never throws.
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { performance } from "node:perf_hooks";
|
|
19
|
+
import { createLogger } from "../log.js";
|
|
20
|
+
import { factsSaid } from "../hook/reuse.js";
|
|
21
|
+
import { commonGitDir, linkedCheckoutTop } from "../hook/worktree.js";
|
|
22
|
+
import { gapsOfLines, rangesOf, rangesOfLines, touched } from "./match.js";
|
|
23
|
+
import { factsEnabled } from "./enabled.js";
|
|
24
|
+
import { FACTS_STALE_MS, openFacts } from "./store.js";
|
|
25
|
+
import { fileMemo, isJsx, SCANNED } from "./files.js";
|
|
26
|
+
import { commitsOf, localCheckouts, peersUnchanged } from "./peers.js";
|
|
27
|
+
import { sameNameLines } from "./rules/same-name.js";
|
|
28
|
+
import { isManifest, packageLines } from "./rules/packages.js";
|
|
29
|
+
const log = createLogger("carrick-facts");
|
|
30
|
+
/** At most this many fact lines for one action. */
|
|
31
|
+
export const MAX_FACT_LINES = 3;
|
|
32
|
+
/** The name kind stops after this many lines whose other file failed its check (R33.5). */
|
|
33
|
+
const MAX_NAME_FAILURES = 3;
|
|
34
|
+
/** Op and fn lines stop after this many failed peer proofs in one action (R36.3). */
|
|
35
|
+
const MAX_PROOF_FAILURES = 3;
|
|
36
|
+
/** The row kinds in the order their lines print, before the cap of `MAX_FACT_LINES`. */
|
|
37
|
+
const KINDS = ["op", "fn", "name", "pkg"];
|
|
38
|
+
/** The main checkout a linked worktree belongs to, from its `.git` file. */
|
|
39
|
+
function mainCheckoutOf(worktreeTop) {
|
|
40
|
+
const common = commonGitDir(worktreeTop);
|
|
41
|
+
return common ? path.dirname(common) : null;
|
|
42
|
+
}
|
|
43
|
+
function real(dir) {
|
|
44
|
+
try {
|
|
45
|
+
return fs.realpathSync(dir);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return dir;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** The repo `file` belongs to, its path in that repo, and the checkout it sits in. */
|
|
52
|
+
export function locate(file, repos) {
|
|
53
|
+
const top = linkedCheckoutTop(file);
|
|
54
|
+
if (top !== null) {
|
|
55
|
+
const main = mainCheckoutOf(top);
|
|
56
|
+
const found = main === null ? [] : repos.filter((entry) => real(entry.path) === real(main));
|
|
57
|
+
return found.length === 1 ? { repo: found[0].repo, rel: path.relative(top, real(file)), top } : null;
|
|
58
|
+
}
|
|
59
|
+
let best = null;
|
|
60
|
+
// Two repos on one checkout (a fact file built before `matchRepos` refused them): neither.
|
|
61
|
+
let tied = false;
|
|
62
|
+
const abs = real(file);
|
|
63
|
+
for (const entry of repos) {
|
|
64
|
+
const base = real(entry.path);
|
|
65
|
+
if (!(abs === base || abs.startsWith(`${base}${path.sep}`)))
|
|
66
|
+
continue;
|
|
67
|
+
const length = best === null ? -1 : real(best.path).length;
|
|
68
|
+
if (base.length > length)
|
|
69
|
+
[best, tied] = [entry, false];
|
|
70
|
+
else if (base.length === length)
|
|
71
|
+
tied = true;
|
|
72
|
+
}
|
|
73
|
+
return best && !tied ? { repo: best.repo, rel: path.relative(real(best.path), abs), top: real(best.path) } : null;
|
|
74
|
+
}
|
|
75
|
+
/** An HTTP row's method, lower case (`POST /orders` -> `post`); null for other protocols. */
|
|
76
|
+
function methodOf(row) {
|
|
77
|
+
return row.protocol === "http" ? (row.label.split(" ")[0] ?? "").toLowerCase() : null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Whether `call` is written as `row`'s site: the site as a direct string
|
|
81
|
+
* argument, and an HTTP row's method as the callee's name. Any other
|
|
82
|
+
* protocol's producer (a listener, subscriber, resolver) also needs a
|
|
83
|
+
* function written in the call; its consumer (an emit, a publish) never
|
|
84
|
+
* fits, as the row does not say the callee's name.
|
|
85
|
+
*/
|
|
86
|
+
function callFits(call, row, method) {
|
|
87
|
+
if (!call.literals.includes(row.site))
|
|
88
|
+
return false;
|
|
89
|
+
if (method !== null)
|
|
90
|
+
return call.member?.toLowerCase() === method;
|
|
91
|
+
return row.side === "producer" && call.takesFunction;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The rows with no name (or several under one name, `holdsSeveral`) that a
|
|
95
|
+
* reached call writes: the row's `site` is a
|
|
96
|
+
* direct string argument of the call around the changed line, an HTTP row's
|
|
97
|
+
* method is the callee's name (`.post(` for `POST ...`), and that (site,
|
|
98
|
+
* method) pair belongs to one row and one call in the file. A row with no
|
|
99
|
+
* site never matches.
|
|
100
|
+
*/
|
|
101
|
+
function unnamedRows(rows, reached, fileCalls) {
|
|
102
|
+
const out = [];
|
|
103
|
+
const reachedSet = new Set(reached);
|
|
104
|
+
for (const row of rows) {
|
|
105
|
+
if (row.site === null)
|
|
106
|
+
continue;
|
|
107
|
+
const method = methodOf(row);
|
|
108
|
+
if (rows.filter((other) => other.site === row.site && methodOf(other) === method).length !== 1)
|
|
109
|
+
continue;
|
|
110
|
+
const holding = fileCalls.filter((call) => callFits(call, row, method));
|
|
111
|
+
if (holding.length === 1 && reachedSet.has(holding[0]))
|
|
112
|
+
out.push(row);
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The rows under `name` that are this file's thing. The caller has made sure
|
|
118
|
+
* the edited file declares `name` exactly once. Only a row in the edited file
|
|
119
|
+
* is its own: a row in another file, even one gone from disk, is never
|
|
120
|
+
* guessed to have moved here.
|
|
121
|
+
*/
|
|
122
|
+
function namedRows(store, repo, name, rel) {
|
|
123
|
+
return store.byName(repo, name).filter((row) => row.file === rel);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Whether one name's rows in a file are several things (R24.1): rows grouped
|
|
127
|
+
* by (side, protocol), and some group holds two or more (inline handlers
|
|
128
|
+
* named by their encloser, `registerRoutes` with five `app.get`). Then every
|
|
129
|
+
* row under the name, in every group, prints only when its own site call is
|
|
130
|
+
* reached (`unnamedRows`); a row with no site, or none reached, is silent.
|
|
131
|
+
* When every group holds one row (a resolver that also calls a route: one
|
|
132
|
+
* thing, two facts) all of them print, as for any named thing.
|
|
133
|
+
*/
|
|
134
|
+
function holdsSeveral(rows) {
|
|
135
|
+
const seen = new Set();
|
|
136
|
+
for (const row of rows) {
|
|
137
|
+
const group = `${row.side} ${row.protocol}`;
|
|
138
|
+
if (seen.has(group))
|
|
139
|
+
return true;
|
|
140
|
+
seen.add(group);
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
function rowKey(row) {
|
|
145
|
+
return `${row.repo}::${row.name ?? row.file}::${row.side}::${row.label}`;
|
|
146
|
+
}
|
|
147
|
+
/** Open the fact file and the lines for `edits`. */
|
|
148
|
+
export async function factLines(root, edits, session, options = {}) {
|
|
149
|
+
const started = performance.now();
|
|
150
|
+
const now = options.now ?? Date.now();
|
|
151
|
+
const lines = [];
|
|
152
|
+
const claims = {};
|
|
153
|
+
const callersRead = [];
|
|
154
|
+
let stale = true;
|
|
155
|
+
let present = false;
|
|
156
|
+
const done = () => ({ lines, claims, stale, callersRead, present, ms: Math.round((performance.now() - started) * 10) / 10 });
|
|
157
|
+
let store = null;
|
|
158
|
+
const found = { op: [], fn: [], name: [], pkg: [] };
|
|
159
|
+
// Off by default (`enabled.ts`): the store is not opened and nothing refreshes.
|
|
160
|
+
if (!factsEnabled(options.env)) {
|
|
161
|
+
stale = false;
|
|
162
|
+
return done();
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
store = await openFacts(root);
|
|
166
|
+
if (store === null)
|
|
167
|
+
return done();
|
|
168
|
+
present = true;
|
|
169
|
+
const facts = store;
|
|
170
|
+
const fetched = Date.parse(store.meta["fetched_at"] ?? "");
|
|
171
|
+
stale = !Number.isFinite(fetched) || now - fetched > FACTS_STALE_MS;
|
|
172
|
+
const said = session ? factsSaid(session, options.home) : new Set();
|
|
173
|
+
const where = new Map(store.repos.map((entry) => [entry.repo, entry.path]));
|
|
174
|
+
// One memo of file reads and scans for the whole call, shared by every rule.
|
|
175
|
+
const memo = fileMemo();
|
|
176
|
+
const commits = commitsOf(store.meta);
|
|
177
|
+
const proofs = new Map();
|
|
178
|
+
const missing = new Set();
|
|
179
|
+
// A peer-proof git call that ran out of time, shared across the call's edited files.
|
|
180
|
+
const git = { failed: false };
|
|
181
|
+
// Where each repo is checked out here, for every kind (R40.2).
|
|
182
|
+
const checkouts = localCheckouts(where);
|
|
183
|
+
const peersHold = (at, others) => () => {
|
|
184
|
+
const ctx = { at, checkouts, commits, memo, env: options.env, proofs, missing, gitFailed: git.failed };
|
|
185
|
+
const answer = peersUnchanged(others, ctx);
|
|
186
|
+
git.failed = ctx.gitFailed;
|
|
187
|
+
return answer;
|
|
188
|
+
};
|
|
189
|
+
const pathsOf = (others) => others.flatMap((other) => {
|
|
190
|
+
const base = where.get(other.repo);
|
|
191
|
+
return base ? [path.join(base, other.file)] : [];
|
|
192
|
+
});
|
|
193
|
+
// A candidate's check, isolated like the lookups (R36.6): one that throws
|
|
194
|
+
// is a failed check, the line silent.
|
|
195
|
+
const held = (kind, candidate) => {
|
|
196
|
+
try {
|
|
197
|
+
return candidate.holds ? candidate.holds() : true;
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
log(`${kind} fact check failed`, String(error));
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
// Each kind's lookup on its own: a row of one kind that throws (a field
|
|
205
|
+
// ingest let through) loses only that kind's lines for the file.
|
|
206
|
+
const isolated = (kind, lookup) => {
|
|
207
|
+
try {
|
|
208
|
+
found[kind].push(...lookup());
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
log(`${kind} fact lines failed`, String(error));
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
for (const edit of edits) {
|
|
215
|
+
const at = locate(edit.file, store.repos);
|
|
216
|
+
if (at === null)
|
|
217
|
+
continue;
|
|
218
|
+
if (isManifest(edit.file)) {
|
|
219
|
+
const manifest = memo.text(edit.file);
|
|
220
|
+
if (manifest !== null)
|
|
221
|
+
isolated("pkg", () => packageLines(facts, at, checkouts, manifest, edit, memo));
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (!SCANNED.test(edit.file))
|
|
225
|
+
continue;
|
|
226
|
+
const byLine = edit.lines || edit.removed;
|
|
227
|
+
// Changed lines not known (a Write over a file, a shell write, a patch
|
|
228
|
+
// hunk that cannot be placed): nothing is said.
|
|
229
|
+
if (!byLine && !edit.snippets && !edit.whole)
|
|
230
|
+
continue;
|
|
231
|
+
// A file over `MAX_FACT_FILE_BYTES` is generated or bundled: never read
|
|
232
|
+
// in a hook's time. One that does not scan cleanly says nothing.
|
|
233
|
+
const read = memo.scanned(edit.file);
|
|
234
|
+
if (read === null) {
|
|
235
|
+
log(`${at.rel} was not read cleanly; no fact lines for it`);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const { text, scan } = read;
|
|
239
|
+
const ranges = byLine
|
|
240
|
+
? rangesOfLines(text, edit.lines ?? [])
|
|
241
|
+
: edit.snippets
|
|
242
|
+
? rangesOf(text, edit.snippets)
|
|
243
|
+
: [{ start: 0, end: text.length }];
|
|
244
|
+
// A removal beside an added line is a replacement: the added line
|
|
245
|
+
// places it, and its gap (above an indented header) would name the encloser.
|
|
246
|
+
const added = new Set(edit.lines ?? []);
|
|
247
|
+
const removed = (edit.removed ?? []).filter((line) => !added.has(line) && !added.has(line - 1));
|
|
248
|
+
const gaps = byLine ? gapsOfLines(text, removed) : [];
|
|
249
|
+
if (ranges.length === 0 && gaps.length === 0)
|
|
250
|
+
continue;
|
|
251
|
+
const reach = touched(text, scan, ranges, gaps);
|
|
252
|
+
// A name declared twice in this file (a handler of one name in two
|
|
253
|
+
// components) cannot say which one the edit reached.
|
|
254
|
+
const declared = new Map();
|
|
255
|
+
for (const span of scan.spans)
|
|
256
|
+
declared.set(span.name, (declared.get(span.name) ?? 0) + 1);
|
|
257
|
+
const names = reach.names.filter((name) => declared.get(name) === 1);
|
|
258
|
+
isolated("op", () => {
|
|
259
|
+
const rows = [];
|
|
260
|
+
for (const name of names) {
|
|
261
|
+
const own = namedRows(facts, at.repo, name, at.rel);
|
|
262
|
+
if (!holdsSeveral(own)) {
|
|
263
|
+
rows.push(...own);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
// Several inline handlers or calls under one name: each row by its own site.
|
|
267
|
+
const span = scan.spans.find((one) => one.name === name);
|
|
268
|
+
rows.push(...unnamedRows(own, reach.reachedIn(span), scan.calls));
|
|
269
|
+
}
|
|
270
|
+
if (reach.calls.length > 0) {
|
|
271
|
+
const unnamed = facts.unnamed(at.repo, at.rel);
|
|
272
|
+
if (unnamed.length > 0)
|
|
273
|
+
rows.push(...unnamedRows(unnamed, reach.calls, scan.calls));
|
|
274
|
+
}
|
|
275
|
+
return rows.map((row) => ({ key: rowKey(row), text: row.text, named: pathsOf(row.others), holds: peersHold(at, row.others) }));
|
|
276
|
+
});
|
|
277
|
+
// The functions' callers in other files: only the row in this file.
|
|
278
|
+
isolated("fn", () => names.flatMap((name) => facts
|
|
279
|
+
.callers(at.repo, name)
|
|
280
|
+
.filter((fn) => fn.file === at.rel)
|
|
281
|
+
.map((fn) => ({
|
|
282
|
+
key: `fn::${fn.repo}::${fn.file}::${fn.name}`,
|
|
283
|
+
text: fn.text,
|
|
284
|
+
named: pathsOf(fn.others),
|
|
285
|
+
holds: peersHold(at, fn.others),
|
|
286
|
+
file: edit.file,
|
|
287
|
+
}))));
|
|
288
|
+
isolated("name", () => sameNameLines(facts, at, checkouts, text, scan, edit, isJsx(edit.file), memo));
|
|
289
|
+
}
|
|
290
|
+
// At most `MAX_FACT_LINES`, kind by kind, each line once per session.
|
|
291
|
+
// The name kind stops after `MAX_NAME_FAILURES` failed checks (R33.5):
|
|
292
|
+
// each one may scan a whole other file. Op and fn share a bound of
|
|
293
|
+
// `MAX_PROOF_FAILURES` failed peer proofs (R36.3): each may run git.
|
|
294
|
+
// Only a failed check counts, never a line skipped as said or capped.
|
|
295
|
+
let proofFailures = 0;
|
|
296
|
+
for (const kind of KINDS) {
|
|
297
|
+
let failed = 0;
|
|
298
|
+
const proved = kind === "op" || kind === "fn";
|
|
299
|
+
for (const candidate of found[kind]) {
|
|
300
|
+
if (lines.length >= MAX_FACT_LINES)
|
|
301
|
+
break;
|
|
302
|
+
if (kind === "name" && failed >= MAX_NAME_FAILURES)
|
|
303
|
+
break;
|
|
304
|
+
if (proved && proofFailures >= MAX_PROOF_FAILURES)
|
|
305
|
+
break;
|
|
306
|
+
if (said.has(candidate.key) || candidate.key in claims)
|
|
307
|
+
continue;
|
|
308
|
+
if (!held(kind, candidate)) {
|
|
309
|
+
failed += 1;
|
|
310
|
+
if (proved)
|
|
311
|
+
proofFailures += 1;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
lines.push(candidate.text);
|
|
315
|
+
claims[candidate.key] = { at: now, named: candidate.named };
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// A file's callers are answered only where its fn line printed now or
|
|
319
|
+
// was said earlier in this session (R33.6).
|
|
320
|
+
for (const candidate of found.fn) {
|
|
321
|
+
if (candidate.file === undefined || callersRead.includes(candidate.file))
|
|
322
|
+
continue;
|
|
323
|
+
if (said.has(candidate.key) || candidate.key in claims)
|
|
324
|
+
callersRead.push(candidate.file);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
log("fact lines failed", String(error));
|
|
329
|
+
}
|
|
330
|
+
finally {
|
|
331
|
+
store?.close();
|
|
332
|
+
}
|
|
333
|
+
return done();
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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,EAAE,SAAS,CAAC,EAAE,CAAC;oBAC3B,MAAM,IAAI,CAAC,CAAC;oBACZ,IAAI,MAAM;wBAAE,aAAa,IAAI,CAAC,CAAC;oBAC/B,SAAS;gBACX,CAAC;gBACD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC3B,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,sEAAsE;QACtE,4CAA4C;QAC5C,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;YACjC,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,IAAI,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC;gBAAE,SAAS;YACnF,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,IAAI,MAAM;gBAAE,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,mBAAmB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC;YAAS,CAAC;QACT,KAAK,EAAE,KAAK,EAAE,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
type TokenKind = "id" | "str" | "tpl" | "num" | "punc" | "regex";
|
|
2
|
+
type Token = {
|
|
3
|
+
kind: TokenKind;
|
|
4
|
+
value: string;
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
line: number;
|
|
8
|
+
};
|
|
9
|
+
/** A named function-like thing and the text span it covers. */
|
|
10
|
+
/** A named thing: its span (from its modifiers and decorators) and the 1-based line of its name token. */
|
|
11
|
+
export type NamedSpan = {
|
|
12
|
+
name: string;
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
nameLine: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A call: `from` where its callee starts (`router` in `router.post(`), `start`
|
|
19
|
+
* at its `(`, `end` after its `)`, the callee's last name (`post`), and the
|
|
20
|
+
* string literals passed to it directly, and whether a function written in
|
|
21
|
+
* place (an arrow or `function`) is one of its arguments.
|
|
22
|
+
*/
|
|
23
|
+
export type CallSpan = {
|
|
24
|
+
from: number;
|
|
25
|
+
start: number;
|
|
26
|
+
end: number;
|
|
27
|
+
member: string | null;
|
|
28
|
+
literals: string[];
|
|
29
|
+
takesFunction: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type Scan = {
|
|
32
|
+
/** False when the text did not tokenize cleanly; nothing else is set then. */
|
|
33
|
+
ok: boolean;
|
|
34
|
+
spans: NamedSpan[];
|
|
35
|
+
calls: CallSpan[];
|
|
36
|
+
/** The token reads the scan made (`SCAN_STEP_BUDGET`). */
|
|
37
|
+
steps: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The tokens of `text`, or null when a string, template, comment, regex or
|
|
41
|
+
* (with `jsx`) element does not end. An element is one opaque token; the
|
|
42
|
+
* code in its `{...}` containers is tokenized after it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function tokenize(text: string, jsx?: boolean): Token[] | null;
|
|
45
|
+
/**
|
|
46
|
+
* The token reads one scan may make. Past it the scan gives up (`ok: false`),
|
|
47
|
+
* so no file under `MAX_FACT_FILE_BYTES` keeps a hook waiting (about 10 ms
|
|
48
|
+
* of reads past the tokenizer). Measured 2026-11-12: a 2,000-line file takes
|
|
49
|
+
* about 31,000, a 12,000-line, 514 KB source file about 141,000.
|
|
50
|
+
*/
|
|
51
|
+
export declare const SCAN_STEP_BUDGET = 1000000;
|
|
52
|
+
/** Scan `text` for named spans and calls; `jsx` for a `.tsx` or `.jsx` file. */
|
|
53
|
+
export declare function scanSource(text: string, jsx?: boolean, budget?: number): Scan;
|
|
54
|
+
/** A changed region of the file, as character offsets (end exclusive). */
|
|
55
|
+
export type Range = {
|
|
56
|
+
start: number;
|
|
57
|
+
end: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Where `snippets` sit in `text`. A snippet found nowhere, or in more than one
|
|
61
|
+
* place, gives no range: which copy the edit wrote is not known.
|
|
62
|
+
*/
|
|
63
|
+
export declare function rangesOf(text: string, snippets: readonly string[]): Range[];
|
|
64
|
+
/**
|
|
65
|
+
* Where lines were removed, as offsets: a removal before the 1-based line N
|
|
66
|
+
* of the file as it is now sits at the start of line N (the end of the text
|
|
67
|
+
* when N is past the last line).
|
|
68
|
+
*/
|
|
69
|
+
export declare function gapsOfLines(text: string, removedBefore: readonly number[]): number[];
|
|
70
|
+
/** The ranges of the 1-based `lines` of `text`. */
|
|
71
|
+
export declare function rangesOfLines(text: string, lines: readonly number[]): Range[];
|
|
72
|
+
/**
|
|
73
|
+
* What an edit touched: the named things, the unnamed calls it reached, and
|
|
74
|
+
* (asked per named thing) the calls inside a named thing that it reached.
|
|
75
|
+
*/
|
|
76
|
+
export type Touched = {
|
|
77
|
+
names: string[];
|
|
78
|
+
calls: CallSpan[];
|
|
79
|
+
reachedIn: (span: NamedSpan) => CallSpan[];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The names an edit over `ranges` touched (the innermost named encloser of
|
|
83
|
+
* each changed line, and every named thing inside a changed range), and the
|
|
84
|
+
* calls outside every named thing whose text (from the callee to the
|
|
85
|
+
* closing `)`) covers part of a changed line. A removal at offset `gap`
|
|
86
|
+
* (`gapsOfLines`) touches only the innermost thing, or top-level call, it
|
|
87
|
+
* sits strictly inside: never one whose first line it is just above, and
|
|
88
|
+
* never one it follows.
|
|
89
|
+
*/
|
|
90
|
+
export declare function touched(text: string, scan: Scan, ranges: readonly Range[], gaps?: readonly number[]): Touched;
|
|
91
|
+
export {};
|