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,235 @@
|
|
|
1
|
+
// The background refresh of the fact file. Never in a hook's path: a hook
|
|
2
|
+
// only starts it (`startFactsRefresh`), detached, and reads whatever file the
|
|
3
|
+
// last refresh left.
|
|
4
|
+
//
|
|
5
|
+
// One request to `POST /mcp/facts` with the stored CLI credential, sending the
|
|
6
|
+
// digest and writer it already holds, so an unchanged project costs one read.
|
|
7
|
+
// A new digest or writer answers with a presigned URL to gzipped NDJSON, which
|
|
8
|
+
// is fetched (no credential, https amazonaws.com only), built into SQLite
|
|
9
|
+
// under a temporary name and renamed (`store.ts`). An error answer, a 404
|
|
10
|
+
// (route not deployed) and every other failure mean no new facts: one log
|
|
11
|
+
// line. Only an error marked `retriable: true` (a build in flight, whatever
|
|
12
|
+
// its code) moves the next ask a minute on (`runFactsRefresh`); the rest wait
|
|
13
|
+
// out the cooldown. The code is logged, never branched on: one code is sent
|
|
14
|
+
// both ways.
|
|
15
|
+
// Wire contract: carrick-cloud `docs/internal/reference/edit-facts-wire.md`.
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import zlib from "node:zlib";
|
|
19
|
+
import { API_BASE, readCredential } from "../auth/credentials.js";
|
|
20
|
+
import { createLogger } from "../log.js";
|
|
21
|
+
import { hasMarker } from "../root.js";
|
|
22
|
+
import { claimRefresh, cooldownMs, markerPath, scriptBeside, startDetached } from "../hook/refresh.js";
|
|
23
|
+
import { snapshotProjectSlug } from "../hook/reuse.js";
|
|
24
|
+
import { splitRemote } from "../git-remote.js";
|
|
25
|
+
import { factsEnabled } from "./enabled.js";
|
|
26
|
+
import { buildFacts, closeQuietly, FACTS_STALE_MS, factsPath, loadSqlite, SCHEMA, touchFetched } from "./store.js";
|
|
27
|
+
const log = createLogger("carrick-facts");
|
|
28
|
+
/** After a retriable error, the next trigger may ask again this soon. */
|
|
29
|
+
export const FACTS_BUILDING_RETRY_MS = 60_000;
|
|
30
|
+
export const FACTS_MARKER = "last-facts-refresh";
|
|
31
|
+
/** Each repo of the local index and where it is checked out (`.carrick/index.json`). */
|
|
32
|
+
export function localRepos(root) {
|
|
33
|
+
try {
|
|
34
|
+
const index = JSON.parse(fs.readFileSync(path.join(root, ".carrick", "index.json"), "utf8"));
|
|
35
|
+
return (index.repos ?? [])
|
|
36
|
+
.filter((repo) => typeof repo.name === "string" && typeof repo.path === "string")
|
|
37
|
+
.map((repo) => {
|
|
38
|
+
const remote = (repo.services ?? []).map((service) => service.enrichment?.remote).find((value) => typeof value === "string");
|
|
39
|
+
return { name: repo.name, path: repo.path, remote: remote ?? null };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The fact file's repos matched to their checkouts here. A header repo that
|
|
48
|
+
* is a remote (`owner/name`, as the index stores a GitHub repo) maps only to
|
|
49
|
+
* the one checkout whose origin names exactly that; a bare name maps only to
|
|
50
|
+
* the one checkout of exactly that name. No match, or more than one, leaves
|
|
51
|
+
* the repo unmapped: its rows are never read. Two header repos that map to
|
|
52
|
+
* one checkout (`api` and `owner/api`) are both left unmapped.
|
|
53
|
+
*/
|
|
54
|
+
export function matchRepos(repos, local) {
|
|
55
|
+
const out = [];
|
|
56
|
+
for (const repo of repos) {
|
|
57
|
+
const found = repo.includes("/")
|
|
58
|
+
? local.filter((entry) => entry.remote !== null && ownerName(entry.remote) === repo)
|
|
59
|
+
: local.filter((entry) => entry.name === repo);
|
|
60
|
+
if (found.length === 1)
|
|
61
|
+
out.push({ repo, path: found[0].path });
|
|
62
|
+
}
|
|
63
|
+
return out.filter((entry) => out.filter((other) => other.path === entry.path).length === 1);
|
|
64
|
+
}
|
|
65
|
+
/** The `owner/name` an origin names, in either spelling git accepts, or the text itself. */
|
|
66
|
+
function ownerName(remote) {
|
|
67
|
+
return splitRemote(remote)?.name ?? remote;
|
|
68
|
+
}
|
|
69
|
+
/** Whether a staged URL is https on an `amazonaws.com` host (a presigned S3 URL). */
|
|
70
|
+
function stagedUrlAllowed(url) {
|
|
71
|
+
try {
|
|
72
|
+
const parsed = new URL(url);
|
|
73
|
+
return parsed.protocol === "https:" && parsed.hostname.endsWith(".amazonaws.com");
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The digest and writer of the local fact file, or null when there is no
|
|
81
|
+
* readable file holding both. The cloud answers `unchanged` only when both
|
|
82
|
+
* match, so a wording fix (a new writer) reaches this file without a new scan.
|
|
83
|
+
*/
|
|
84
|
+
async function knownFile(root) {
|
|
85
|
+
const file = factsPath(root);
|
|
86
|
+
if (!fs.existsSync(file))
|
|
87
|
+
return null;
|
|
88
|
+
const sqlite = await loadSqlite();
|
|
89
|
+
if (!sqlite)
|
|
90
|
+
return null;
|
|
91
|
+
let db = null;
|
|
92
|
+
try {
|
|
93
|
+
const open = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
94
|
+
db = open;
|
|
95
|
+
const meta = new Map(open.prepare("SELECT key, value FROM meta WHERE key IN ('digest', 'writer')").all().map((raw) => [String(raw["key"]), String(raw["value"])]));
|
|
96
|
+
const digest = meta.get("digest");
|
|
97
|
+
const writer = Number(meta.get("writer"));
|
|
98
|
+
return digest && Number.isInteger(writer) ? { digest, writer } : null;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
closeQuietly(db);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** Ask the cloud for the project's fact file and bring the local one up to date. Never throws. */
|
|
108
|
+
export async function refreshFacts(root, options = {}) {
|
|
109
|
+
const env = options.env ?? process.env;
|
|
110
|
+
if (!factsEnabled(env))
|
|
111
|
+
return "none";
|
|
112
|
+
const request = options.request ?? fetch;
|
|
113
|
+
const now = new Date(options.now ?? Date.now()).toISOString();
|
|
114
|
+
try {
|
|
115
|
+
const credential = readCredential(env);
|
|
116
|
+
if (!credential) {
|
|
117
|
+
log("not signed in; no fact file");
|
|
118
|
+
return "none";
|
|
119
|
+
}
|
|
120
|
+
const project = snapshotProjectSlug(root);
|
|
121
|
+
if (!project) {
|
|
122
|
+
log("no single project for this workspace; no fact file");
|
|
123
|
+
return "none";
|
|
124
|
+
}
|
|
125
|
+
const known = await knownFile(root);
|
|
126
|
+
const response = await request(`${API_BASE}/mcp/facts`, {
|
|
127
|
+
method: "POST",
|
|
128
|
+
redirect: "error",
|
|
129
|
+
signal: AbortSignal.timeout(30_000),
|
|
130
|
+
headers: { Authorization: `Bearer ${credential.token}`, "Content-Type": "application/json" },
|
|
131
|
+
body: JSON.stringify({ project, schema: SCHEMA, ...(known ? { known_digest: known.digest, known_writer: known.writer } : {}) }),
|
|
132
|
+
});
|
|
133
|
+
if (response.status === 404) {
|
|
134
|
+
log("facts route not found; no fact file");
|
|
135
|
+
return "none";
|
|
136
|
+
}
|
|
137
|
+
let answer;
|
|
138
|
+
try {
|
|
139
|
+
answer = (await response.json());
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
log(`facts answer not JSON (HTTP ${response.status})`);
|
|
143
|
+
return "none";
|
|
144
|
+
}
|
|
145
|
+
const error = answer["error"];
|
|
146
|
+
if (answer["success"] === false || !response.ok) {
|
|
147
|
+
const code = typeof error?.code === "string" ? error.code : `HTTP ${response.status}`;
|
|
148
|
+
const retriable = error?.retriable === true;
|
|
149
|
+
log(`facts not available: ${code}${retriable ? " (retriable)" : ""}`);
|
|
150
|
+
return retriable ? "retry" : "none";
|
|
151
|
+
}
|
|
152
|
+
if (answer["unchanged"] === true) {
|
|
153
|
+
await touchFetched(root, now);
|
|
154
|
+
return "unchanged";
|
|
155
|
+
}
|
|
156
|
+
const url = answer["staged_url"];
|
|
157
|
+
if (typeof url !== "string") {
|
|
158
|
+
log("facts answer carries no staged_url");
|
|
159
|
+
return "none";
|
|
160
|
+
}
|
|
161
|
+
// The staged file is fetched with no credential, so only from where the cloud stages it.
|
|
162
|
+
if (!stagedUrlAllowed(url)) {
|
|
163
|
+
log("facts staged_url is not an https amazonaws.com URL; not fetched");
|
|
164
|
+
return "none";
|
|
165
|
+
}
|
|
166
|
+
const staged = await request(url, { redirect: "error", signal: AbortSignal.timeout(60_000) });
|
|
167
|
+
if (!staged.ok) {
|
|
168
|
+
log(`staged fact file not fetched (HTTP ${staged.status})`);
|
|
169
|
+
return "none";
|
|
170
|
+
}
|
|
171
|
+
const bytes = Buffer.from(await staged.arrayBuffer());
|
|
172
|
+
const gzipped = bytes.length >= 2 && bytes[0] === 0x1f && bytes[1] === 0x8b;
|
|
173
|
+
const text = (gzipped ? zlib.gunzipSync(bytes) : bytes).toString("utf8");
|
|
174
|
+
const header = JSON.parse(text.slice(0, text.indexOf("\n") >>> 0));
|
|
175
|
+
const names = (header.repos ?? []).map((repo) => repo.repo).filter((repo) => typeof repo === "string");
|
|
176
|
+
const built = await buildFacts(text, factsPath(root), matchRepos(names, localRepos(root)), now);
|
|
177
|
+
return built ? "written" : "none";
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
log("fact refresh failed", String(error));
|
|
181
|
+
return "none";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Start the refresh for `root` detached, at most once per `FACTS_STALE_MS`
|
|
186
|
+
* across every hook and session. Returns whether it started. Never throws.
|
|
187
|
+
*/
|
|
188
|
+
export function startFactsRefresh(root, options = {}) {
|
|
189
|
+
const env = options.env ?? process.env;
|
|
190
|
+
if (!factsEnabled(env))
|
|
191
|
+
return false;
|
|
192
|
+
if (env["CARRICK_NO_FACTS_REFRESH"])
|
|
193
|
+
return false;
|
|
194
|
+
// A folder Carrick was never set up in gets nothing, not even a marker directory.
|
|
195
|
+
if (!hasMarker(root))
|
|
196
|
+
return false;
|
|
197
|
+
try {
|
|
198
|
+
const cooldown = cooldownMs(env, "CARRICK_FACTS_COOLDOWN_MS", FACTS_STALE_MS);
|
|
199
|
+
if (!claimRefresh(markerPath(root, FACTS_MARKER), options.now ?? Date.now(), cooldown))
|
|
200
|
+
return false;
|
|
201
|
+
const { command, args } = scriptBeside(import.meta.url, "refresh-run", root);
|
|
202
|
+
(options.start ?? startDetached)(command, args, { ...env, CARRICK_NO_KEEP_AWAKE: "1" });
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
log("fact refresh not started", String(error));
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* One detached refresh (`refresh-run.ts`): bring the file up to date and,
|
|
212
|
+
* after a retriable error only, let the next trigger ask again a minute on.
|
|
213
|
+
* Every other outcome waits out the cooldown.
|
|
214
|
+
*/
|
|
215
|
+
export async function runFactsRefresh(root, options = {}) {
|
|
216
|
+
const outcome = await refreshFacts(root, options);
|
|
217
|
+
log(`fact refresh: ${outcome}`);
|
|
218
|
+
if (outcome === "retry")
|
|
219
|
+
allowEarlyRetry(root, options.env ?? process.env, options.now ?? Date.now());
|
|
220
|
+
return outcome;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* After a retriable error, move the claim back so the next trigger, a minute
|
|
224
|
+
* on, asks again rather than waiting out the whole cooldown.
|
|
225
|
+
*/
|
|
226
|
+
export function allowEarlyRetry(root, env = process.env, now = Date.now()) {
|
|
227
|
+
const cooldown = cooldownMs(env, "CARRICK_FACTS_COOLDOWN_MS", FACTS_STALE_MS);
|
|
228
|
+
try {
|
|
229
|
+
fs.writeFileSync(markerPath(root, FACTS_MARKER), `${new Date(now - cooldown + FACTS_BUILDING_RETRY_MS).toISOString()}\n`);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
// The next trigger after the full cooldown asks instead.
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/facts/fetch.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,qBAAqB;AACrB,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,0EAA0E;AAC1E,0EAA0E;AAC1E,0EAA0E;AAC1E,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,aAAa;AACb,6EAA6E;AAE7E,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC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AC,GAAG,EAAE,MAAc,IAAI,CAAC,GAAG,EAAE;IAC1G,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE,2BAA2B,EAAE,cAAc,CAAC,CAAC;IAC9E,IAAI,CAAC;QACH,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,QAAQ,GAAG,uBAAuB,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAC5H,CAAC;IAAC,MAAM,CAAC;QACP,yDAAyD;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Scan } from "./match.ts";
|
|
2
|
+
/** A file larger than this gets no fact lines (and is not read). */
|
|
3
|
+
export declare const MAX_FACT_FILE_BYTES: number;
|
|
4
|
+
/** The files the declaration scanner reads. */
|
|
5
|
+
export declare const SCANNED: RegExp;
|
|
6
|
+
export declare function isJsx(file: string): boolean;
|
|
7
|
+
/** A file's text and its clean declaration scan. */
|
|
8
|
+
export type ScannedFile = {
|
|
9
|
+
text: string;
|
|
10
|
+
scan: Scan;
|
|
11
|
+
};
|
|
12
|
+
export type FileMemo = {
|
|
13
|
+
/** The file's bytes, or null when missing, unreadable or over `MAX_FACT_FILE_BYTES`. */
|
|
14
|
+
bytes: (file: string) => Buffer | null;
|
|
15
|
+
/** The file's text (UTF-8), with the same nulls as `bytes`. */
|
|
16
|
+
text: (file: string) => string | null;
|
|
17
|
+
/** The file's text and declaration scan, or null when it is not a file the scanner reads, has no text, or does not scan cleanly. */
|
|
18
|
+
scanned: (file: string) => ScannedFile | null;
|
|
19
|
+
};
|
|
20
|
+
/** A fresh memo, for one `factLines` call. */
|
|
21
|
+
export declare function fileMemo(): FileMemo;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// The files one `factLines` call reads, each read and scanned at most once
|
|
2
|
+
// (plan section 33, R33.5): the edited file, the files a name line points at,
|
|
3
|
+
// the peer files an op or fn line's proof hashes, the manifests a pkg line
|
|
4
|
+
// checks. Every read is capped at `MAX_FACT_FILE_BYTES`; a larger file, a
|
|
5
|
+
// missing one or an unreadable one is null, and the rule asking says nothing.
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import { scanSource } from "./match.js";
|
|
8
|
+
/** A file larger than this gets no fact lines (and is not read). */
|
|
9
|
+
export const MAX_FACT_FILE_BYTES = 512 * 1024;
|
|
10
|
+
/** The files the declaration scanner reads. */
|
|
11
|
+
export const SCANNED = /\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/;
|
|
12
|
+
export function isJsx(file) {
|
|
13
|
+
return /\.(tsx|jsx)$/.test(file);
|
|
14
|
+
}
|
|
15
|
+
/** A fresh memo, for one `factLines` call. */
|
|
16
|
+
export function fileMemo() {
|
|
17
|
+
const bytes = new Map();
|
|
18
|
+
const texts = new Map();
|
|
19
|
+
const scans = new Map();
|
|
20
|
+
const readBytes = (file) => {
|
|
21
|
+
if (bytes.has(file))
|
|
22
|
+
return bytes.get(file);
|
|
23
|
+
let out = null;
|
|
24
|
+
try {
|
|
25
|
+
if (fs.statSync(file).size <= MAX_FACT_FILE_BYTES)
|
|
26
|
+
out = fs.readFileSync(file);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
out = null;
|
|
30
|
+
}
|
|
31
|
+
bytes.set(file, out);
|
|
32
|
+
return out;
|
|
33
|
+
};
|
|
34
|
+
const readText = (file) => {
|
|
35
|
+
if (texts.has(file))
|
|
36
|
+
return texts.get(file);
|
|
37
|
+
const out = readBytes(file)?.toString("utf8") ?? null;
|
|
38
|
+
texts.set(file, out);
|
|
39
|
+
return out;
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
bytes: readBytes,
|
|
43
|
+
text: readText,
|
|
44
|
+
scanned: (file) => {
|
|
45
|
+
if (scans.has(file))
|
|
46
|
+
return scans.get(file);
|
|
47
|
+
let out = null;
|
|
48
|
+
const text = SCANNED.test(file) ? readText(file) : null;
|
|
49
|
+
if (text !== null) {
|
|
50
|
+
const scan = scanSource(text, isJsx(file));
|
|
51
|
+
out = scan.ok ? { text, scan } : null;
|
|
52
|
+
}
|
|
53
|
+
scans.set(file, out);
|
|
54
|
+
return out;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/facts/files.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,2EAA2E;AAC3E,0EAA0E;AAC1E,8EAA8E;AAE9E,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,oEAAoE;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,CAAC;AAE9C,+CAA+C;AAC/C,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAE5D,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAcD,8CAA8C;AAC9C,MAAM,UAAU,QAAQ;IACtB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC/C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC/C,MAAM,KAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IACpD,MAAM,SAAS,GAAG,CAAC,IAAY,EAAiB,EAAE;QAChD,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;QAC7C,IAAI,GAAG,GAAkB,IAAI,CAAC;QAC9B,IAAI,CAAC;YACH,IAAI,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,mBAAmB;gBA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G,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { LocalRepo } from "./store.ts";
|
|
2
|
+
/** At most this many fact lines for one action. */
|
|
3
|
+
export declare const MAX_FACT_LINES = 3;
|
|
4
|
+
/**
|
|
5
|
+
* One edited file and where the edit changed it: the 1-based lines of the
|
|
6
|
+
* file as it is now that it added (`lines`) and the lines it removed lines
|
|
7
|
+
* just above (`removed`), else the text the edit put in (`snippets`), else
|
|
8
|
+
* `whole` for a file the call created (every named thing in it counts). With
|
|
9
|
+
* none of them the changed lines are not known, and nothing is said.
|
|
10
|
+
* `removedText` is the text of each `removed` line, in order, when the
|
|
11
|
+
* patch's other lines were checked against the file: with it the file before
|
|
12
|
+
* the edit can be rebuilt.
|
|
13
|
+
*/
|
|
14
|
+
export type FactEdit = {
|
|
15
|
+
file: string;
|
|
16
|
+
lines?: number[] | null;
|
|
17
|
+
removed?: number[] | null;
|
|
18
|
+
removedText?: string[] | null;
|
|
19
|
+
snippets?: string[] | null;
|
|
20
|
+
whole?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type FactOutcome = {
|
|
23
|
+
lines: string[];
|
|
24
|
+
/** Row key -> delivery stamp and the absolute paths the line pointed at; claim with `markFacts` once printed. */
|
|
25
|
+
claims: Record<string, {
|
|
26
|
+
at: number;
|
|
27
|
+
named: string[];
|
|
28
|
+
}>;
|
|
29
|
+
/** Time spent opening the fact file and matching. */
|
|
30
|
+
ms: number;
|
|
31
|
+
/** The fact file is missing, unreadable or older than `FACTS_STALE_MS`: start a background refresh. */
|
|
32
|
+
stale: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The edited files (as given) whose callers the fact lines answered: an fn
|
|
35
|
+
* line for the file printed in this action, or was said earlier in this
|
|
36
|
+
* session. Only for these is the probe's uses-count line left out, at edit
|
|
37
|
+
* time and in a late answer (carrick#4017; plan section 33, R33.6).
|
|
38
|
+
*/
|
|
39
|
+
callersRead: string[];
|
|
40
|
+
/**
|
|
41
|
+
* The fact file opened for this root: there, readable, this project's.
|
|
42
|
+
* With it the edit hook asks no probe and queues the edit (T12-2).
|
|
43
|
+
*/
|
|
44
|
+
present: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A line one rule found, before the cap: its once-per-session key and the
|
|
48
|
+
* paths it points at. `holds`, when set, is a costlier check run only for a
|
|
49
|
+
* line about to print within the cap; false drops the line.
|
|
50
|
+
*/
|
|
51
|
+
export type Candidate = {
|
|
52
|
+
key: string;
|
|
53
|
+
text: string;
|
|
54
|
+
named: string[];
|
|
55
|
+
holds?: () => boolean;
|
|
56
|
+
/** An fn line's edited file (as given), for `callersRead`. */
|
|
57
|
+
file?: string;
|
|
58
|
+
};
|
|
59
|
+
/** The repo `file` belongs to, its path in that repo, and the checkout it sits in. */
|
|
60
|
+
export declare function locate(file: string, repos: readonly LocalRepo[]): {
|
|
61
|
+
repo: string;
|
|
62
|
+
rel: string;
|
|
63
|
+
top: string;
|
|
64
|
+
} | null;
|
|
65
|
+
/** Open the fact file and the lines for `edits`. */
|
|
66
|
+
export declare function factLines(root: string, edits: readonly FactEdit[], session: string | undefined, options?: {
|
|
67
|
+
home?: string;
|
|
68
|
+
now?: number;
|
|
69
|
+
env?: NodeJS.ProcessEnv;
|
|
70
|
+
}): Promise<FactOutcome>;
|