@mapled/cli 0.10.0 → 0.12.0

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/report.js ADDED
@@ -0,0 +1,425 @@
1
+ import { ago } from "./doctor.js";
2
+ import { plural } from "./manifest.js";
3
+ import { GLYPH, paint } from "./output.js";
4
+ const STATUS_LABEL = {
5
+ awaiting_approval: "waiting for approval",
6
+ approved: "approved, not applied yet",
7
+ rejected: "rejected",
8
+ applying: "applying",
9
+ verifying: "applied, checks pending",
10
+ checks_failed: "checks failed",
11
+ completed: "completed",
12
+ completed_with_warnings: "completed with warnings",
13
+ failed: "failed",
14
+ };
15
+ const label = (status) => STATUS_LABEL[status] ?? clean(status, 40);
16
+ /** Applied runs: the ones the server checks (S-42). */
17
+ const CHECKED = ["verifying", "checks_failed", "completed", "completed_with_warnings"];
18
+ export const isChecked = (status) => CHECKED.includes(status);
19
+ /** Mapled's keys and tokens, with the length and alphabet of the random
20
+ part Mapled issues: delivery and server keys — 16 bytes in hex
21
+ (`lib/deliveryKeys.ts`); agent, OAuth and code tokens — 32 bytes in
22
+ base64url (`generateToken`); preview links, draft sessions and the
23
+ webhook secret — 24 bytes in hex. The webhook secret's prefix is the
24
+ one of Standard Webhooks, and other issuers (Polar, Svix) write it
25
+ before base64 of 24 bytes or more, `+`, `/` and the `=` padding
26
+ included: the last kind, read up to its shortest length, so a site's
27
+ own secret doesn't show either. Mapled doesn't issue that one, so
28
+ behind a prefix written wholly in look-alikes it reads as text
29
+ (`keyLike`). */
30
+ export const KEYS = [
31
+ ["mk_live_", 32, "hex"],
32
+ ["msk_live_", 32, "hex"],
33
+ ["mcp_live_", 43, "base64url"],
34
+ ["mcp_oauth_", 43, "base64url"],
35
+ ["mcp_refresh_", 43, "base64url"],
36
+ ["mcp_code_", 43, "base64url"],
37
+ ["mpv_", 48, "hex"],
38
+ ["mps_", 48, "hex"],
39
+ ["whsec_", 48, "hex"],
40
+ ["whsec_", 32, "base64"],
41
+ ];
42
+ /** A prefix, read with a blank allowed between any two of its characters. */
43
+ const PREFIX_SOURCE = [...new Set(KEYS.map(([prefix]) => prefix))].map((prefix) => [...prefix].join(" ?")).join("|");
44
+ const PREFIX = new RegExp(PREFIX_SOURCE, "g");
45
+ const PREFIX_HERE = new RegExp(PREFIX_SOURCE, "y");
46
+ /** The characters of a random part: hex and base64url, and base64 with its `+`, `/` and `=`. */
47
+ const KEY_CHAR = /[a-z0-9_-]/;
48
+ const BASE64_CHAR = /[a-z0-9_+/=-]/;
49
+ /** Code points a terminal draws as a blank or a line break: every control
50
+ character (C0, DEL, C1 — an escape sequence could rewrite the screen),
51
+ every Unicode space and line or paragraph separator, and the braille
52
+ blank. Each becomes one ordinary space: the report is one line. */
53
+ const BLANK = /[\p{Cc}\p{White_Space}\u2800]/u;
54
+ /** Code points a terminal draws as nothing: every format character (Cf —
55
+ bidirectional overrides and isolates reorder what is shown; the soft
56
+ hyphen, zero-width and invisible-operator characters hide inside a word),
57
+ every default-ignorable one (variation selectors, the combining grapheme
58
+ joiner, Hangul fillers, tags), unassigned code points and lone
59
+ surrogates. A key split by one would still read whole, so they go. */
60
+ const INVISIBLE = /[\p{Cf}\p{Default_Ignorable_Code_Point}\p{Cn}\p{Cs}]/u;
61
+ /** One line of text fit for a terminal: no control, blank-looking or
62
+ invisible characters, nothing that reads as a Mapled key. */
63
+ export function clean(text, max = 300) {
64
+ let out = "";
65
+ for (const ch of String(text ?? "")) {
66
+ if (BLANK.test(ch))
67
+ out += " ";
68
+ else if (!INVISIBLE.test(ch))
69
+ out += ch;
70
+ }
71
+ const shown = [...maskKeys(out.replace(/ {2,}/g, " ").trim())];
72
+ return shown.length > max ? `${shown.slice(0, max - 1).join("")}…` : shown.join("");
73
+ }
74
+ /** Stand-ins for a character from outside ASCII that no compatibility form
75
+ turns into ASCII. A letter or digit of another script (Cyrillic `ѕ`,
76
+ Greek `ο`, Armenian `օ`) can pass for a letter or digit; a dash, a low
77
+ line, a modifier or a math symbol (`‐`, `ˍ`, `∨`) for any character of
78
+ a key. Neither stand-in can come from the line itself: `clean` has
79
+ turned every control character into a blank. */
80
+ const LETTERLIKE = String.fromCharCode(1);
81
+ const STROKELIKE = String.fromCharCode(2);
82
+ const STROKE = /[\p{Pd}\p{Pc}\p{Sm}\p{Sk}\p{Lm}\u2017]/u;
83
+ /** What a reader takes a character for: its compatibility form (a
84
+ fullwidth letter is the letter), without accents and other marks, in
85
+ lower case, or a stand-in when that isn't ASCII. A mark alone reads as
86
+ nothing; other characters (`。`, an emoji) read as themselves. */
87
+ const skeletonOf = (ch) => {
88
+ if (ch === " ")
89
+ return " ";
90
+ const read = ch.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase();
91
+ if (/^[!-~]*$/.test(read))
92
+ return read;
93
+ if (STROKE.test(ch))
94
+ return STROKELIKE;
95
+ return /[\p{L}\p{N}]/u.test(ch) ? LETTERLIKE : read;
96
+ };
97
+ /** ASCII characters that pass for one of a prefix: 1, | and I (read in
98
+ lower case) for l, 0 for o, a hyphen for `_`. */
99
+ const TWINS = { l: "1|i", o: "0", _: "-" };
100
+ /** A prefix read with look-alikes: each letter may be itself, its ASCII
101
+ twin or a stand-in; `_` may be a hyphen or a stroke, never a letter; a
102
+ blank may stand between any two of its characters, as in `PREFIX`. */
103
+ const likeSource = (prefix) => [...prefix].map((c) => (c === "_" ? `[${STROKELIKE}_-]` : `[${c}${TWINS[c] ?? ""}${LETTERLIKE}${STROKELIKE}]`)).join(" ?");
104
+ const LIKE_SOURCE = [...new Set(KEYS.map(([prefix]) => prefix))].map((prefix) => `(?:${likeSource(prefix)})`).join("|");
105
+ const LIKE_PREFIX = new RegExp(LIKE_SOURCE, "g");
106
+ const LIKE_HERE = new RegExp(LIKE_SOURCE, "y");
107
+ /** Each kind's prefix on its own, in the order of `KEYS`: a stand-in
108
+ passes for several letters, so one prefix written in them can pass
109
+ for more than one kind (`мсрˍӏіѵеˍ` for `msk_live_` and `mcp_live_`).
110
+ Each kind is tried, and the longest key read is masked. */
111
+ const LIKE_KIND = KEYS.map(([prefix]) => new RegExp(likeSource(prefix), "y"));
112
+ const LIKE_CHAR = new RegExp(`[a-z0-9_${LETTERLIKE}${STROKELIKE}-]`);
113
+ const LIKE_BASE64_CHAR = new RegExp(`[a-z0-9_+/=${LETTERLIKE}${STROKELIKE}-]`);
114
+ /** A random part read as the hex Mapled issues: digits and `a`–`f`, or a letter of another script drawn like one; blanks between pieces. */
115
+ const HEX_READ = new RegExp(`^[0-9a-f ${LETTERLIKE}]*$`);
116
+ /** Whether a key read with look-alikes is a key, not text of another
117
+ script. `random` is its random part as long as Mapled issues it — what
118
+ is glued on after that counts for nothing — and both tests count
119
+ characters, so a blank anywhere in the key changes nothing:
120
+ - a random part with more dashes and low lines than letters and
121
+ digits is not a key (`что-либо ------ see`) — Mapled's are nearly
122
+ all letters and digits;
123
+ - one with more letters of another script than ASCII letters and
124
+ digits is text in that script (`mpv — ещё не заполнено …`);
125
+ - so is a prefix without one ASCII letter or digit (`что-`, `тьи —`),
126
+ unless the random part is one Mapled could issue: a hex one without
127
+ an ASCII letter past `f` (`Статьи — see the app page …` has one), a
128
+ base64url one without a letter of another script. Digits or none:
129
+ a token may be letters only, so `что-либо — see …` followed by as
130
+ many ASCII letters as a token has is masked with it. The base64 of
131
+ another issuer's webhook secret isn't one Mapled issues: behind such
132
+ a prefix it reads as text, or `Статьи — see …` would be a secret. */
133
+ const STROKES_NOT = new RegExp(`[^${STROKELIKE}_-]`, "g");
134
+ function keyLike(prefix, random, alphabet) {
135
+ const ascii = random.match(/[a-z0-9]/g)?.length ?? 0;
136
+ const foreign = random.split(LETTERLIKE).length - 1;
137
+ const strokes = random.replace(STROKES_NOT, "").length;
138
+ if (strokes > ascii + foreign || foreign > ascii)
139
+ return false;
140
+ if (/[a-z0-9]/.test(prefix))
141
+ return true;
142
+ if (alphabet === "hex")
143
+ return !/[g-z]/.test(random);
144
+ return alphabet === "base64url" && foreign === 0;
145
+ }
146
+ const reading = (skeleton, char, here) => {
147
+ const ends = new Int32Array(skeleton.length + 1);
148
+ ends[skeleton.length] = skeleton.length;
149
+ for (let i = skeleton.length - 1; i >= 0; i--)
150
+ ends[i] = char.test(skeleton[i]) ? ends[i + 1] : i;
151
+ return { ends, here };
152
+ };
153
+ /** Masks every Mapled key a reader could take off the line (§36.12).
154
+ Matching runs on what the characters read as, so case, fullwidth forms
155
+ and marks don't hide a key; a blank inside the prefix doesn't either,
156
+ and a key wrapped or split by blanks is read on across them while its
157
+ pieces add up to the length Mapled issues. A key written with look-
158
+ alikes — another script's letters, 1 for l, 0 for o, a dash for `_` —
159
+ is read the same way, blanks and pieces included, when it is as long
160
+ as Mapled issues it and `keyLike` doesn't take it for text of another
161
+ script. Each key, with all the pieces, becomes `[redacted]`. A key an
162
+ agent re-encodes (base64, reversed, spelled out, broken up by
163
+ punctuation) is not something a reader takes off the line, and no mask
164
+ can see it. */
165
+ function maskKeys(line) {
166
+ const chars = [...line];
167
+ let skeleton = "";
168
+ /** The character behind each UTF-16 unit of the skeleton — matching
169
+ indexes units, and an emoji reads as two. */
170
+ const owner = [];
171
+ chars.forEach((ch, i) => {
172
+ const read = skeletonOf(ch);
173
+ skeleton += read;
174
+ for (let unit = 0; unit < read.length; unit++)
175
+ owner.push(i);
176
+ });
177
+ const hidden = new Set();
178
+ const hide = (from, to) => {
179
+ let last = owner[to - 1];
180
+ while (last + 1 < chars.length && skeletonOf(chars[last + 1]) === "")
181
+ last++;
182
+ for (let i = owner[from]; i <= last; i++)
183
+ hidden.add(i);
184
+ };
185
+ /** Each alphabet's reading, found once per line: base64 reads on over
186
+ `+`, `/` and `=`. Where Mapled's own hex secret is read whole, another
187
+ issuer's base64 after the same prefix isn't, so `/x` after it in a
188
+ path stays; anywhere else the longest reading is masked. */
189
+ const plain = { narrow: reading(skeleton, KEY_CHAR, PREFIX_HERE), base64: reading(skeleton, BASE64_CHAR, PREFIX_HERE) };
190
+ PREFIX.lastIndex = 0;
191
+ for (let match = PREFIX.exec(skeleton); match; match = PREFIX.exec(skeleton)) {
192
+ const prefix = match[0].replaceAll(" ", "");
193
+ let longest = PREFIX.lastIndex;
194
+ for (const [p, length, alphabet] of KEYS) {
195
+ if (p !== prefix)
196
+ continue;
197
+ const { end, issued } = keyEnd(skeleton, PREFIX.lastIndex, length, alphabet === "base64" ? plain.base64 : plain.narrow);
198
+ longest = Math.max(longest, end);
199
+ if (issued !== null && alphabet === "hex" && HEX_READ.test(skeleton.slice(PREFIX.lastIndex, issued)))
200
+ break;
201
+ }
202
+ if (longest === PREFIX.lastIndex)
203
+ continue;
204
+ hide(match.index, longest);
205
+ PREFIX.lastIndex = longest;
206
+ }
207
+ const like = { narrow: reading(skeleton, LIKE_CHAR, LIKE_HERE), base64: reading(skeleton, LIKE_BASE64_CHAR, LIKE_HERE) };
208
+ LIKE_PREFIX.lastIndex = 0;
209
+ for (let match = LIKE_PREFIX.exec(skeleton); match; match = LIKE_PREFIX.exec(skeleton)) {
210
+ let longest = 0;
211
+ let other = 0;
212
+ let hex = false;
213
+ for (const [kind, [, length, alphabet]] of KEYS.entries()) {
214
+ const here = LIKE_KIND[kind];
215
+ here.lastIndex = match.index;
216
+ if (!here.test(skeleton))
217
+ continue;
218
+ const { end, issued } = keyEnd(skeleton, here.lastIndex, length, alphabet === "base64" ? like.base64 : like.narrow);
219
+ const random = issued === null ? "" : skeleton.slice(here.lastIndex, issued);
220
+ if (issued === null || !keyLike(skeleton.slice(match.index, here.lastIndex), random, alphabet))
221
+ continue;
222
+ if (alphabet === "base64")
223
+ other = Math.max(other, end);
224
+ else
225
+ longest = Math.max(longest, end);
226
+ hex ||= alphabet === "hex" && HEX_READ.test(random);
227
+ }
228
+ if (!hex)
229
+ longest = Math.max(longest, other);
230
+ if (longest > 0)
231
+ hide(match.index, longest);
232
+ LIKE_PREFIX.lastIndex = Math.max(longest, match.index + 1);
233
+ }
234
+ let out = "";
235
+ chars.forEach((ch, i) => {
236
+ if (!hidden.has(i))
237
+ out += ch;
238
+ else if (!hidden.has(i - 1))
239
+ out += "[redacted]";
240
+ });
241
+ return out;
242
+ }
243
+ /** Where the random part that starts at `start` ends (`start` itself when
244
+ there is none), and where it reaches the length Mapled issues (`null`
245
+ when it doesn't). It runs over key characters; when it stops short of
246
+ `length` at a blank, the pieces after it belong to the key if they
247
+ complete it — a piece that starts a key of its own doesn't. */
248
+ function keyEnd(skeleton, start, length, reading) {
249
+ let end = reading.ends[start];
250
+ let read = end - start;
251
+ let issued = read >= length ? start + length : null;
252
+ for (let at = end; read < length;) {
253
+ let next = at;
254
+ while (skeleton[next] === " ")
255
+ next++;
256
+ if (next === at)
257
+ break;
258
+ reading.here.lastIndex = next;
259
+ const to = reading.ends[next];
260
+ if (to === next || reading.here.test(skeleton))
261
+ break;
262
+ if (read + (to - next) >= length) {
263
+ issued = next + (length - read);
264
+ end = to;
265
+ }
266
+ read += to - next;
267
+ at = to;
268
+ }
269
+ return { end, issued };
270
+ }
271
+ /** The page an agent reported as its preview, without what may carry a
272
+ credential: no query, no fragment, no user info. The path is shown
273
+ decoded, so a key written in percent escapes is masked like any other;
274
+ a path that doesn't decode cleanly — malformed, or still escaped after
275
+ one decoding (encoded twice) — is dropped, and only the origin shows. */
276
+ export function reportedPage(url) {
277
+ if (typeof url !== "string")
278
+ return null;
279
+ let parsed;
280
+ try {
281
+ parsed = new URL(url);
282
+ }
283
+ catch {
284
+ return null;
285
+ }
286
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:")
287
+ return null;
288
+ const path = decodedPath(parsed.pathname);
289
+ return clean(path === null ? parsed.origin : `${parsed.origin}${path}`, 300) || null;
290
+ }
291
+ function decodedPath(path) {
292
+ let decoded;
293
+ try {
294
+ decoded = decodeURIComponent(path);
295
+ }
296
+ catch {
297
+ return null;
298
+ }
299
+ return /%[0-9a-f]{2}/i.test(decoded) ? null : decoded;
300
+ }
301
+ /** The run to report: the one applied last (an older plan can be applied
302
+ after a newer one); before any was applied, the newest there is. The
303
+ newer plan is the newest one proposed after it and not applied. */
304
+ export function pickRun(runs) {
305
+ const appliedAt = (r) => Date.parse(r.appliedAt ?? r.createdAt);
306
+ const shown = runs.filter((r) => isChecked(r.status)).reduce((last, r) => (last && !(appliedAt(r) > appliedAt(last)) ? last : r), null) ??
307
+ runs[0] ??
308
+ null;
309
+ const newer = shown ? (runs.slice(0, runs.indexOf(shown)).find((r) => !isChecked(r.status)) ?? null) : null;
310
+ return { shown, newer };
311
+ }
312
+ const STATUSES = new Set(["passed", "failed", "warning", "skipped"]);
313
+ const lines = (list, max = 50) => (Array.isArray(list) ? list : []).slice(0, max).map((s) => clean(s)).filter((s) => s.length > 0);
314
+ export function buildReport(project, run, newer) {
315
+ const result = run?.result ?? null;
316
+ const report = result?.report;
317
+ return {
318
+ project: { id: clean(project.id, 64), name: clean(project.name, 120) },
319
+ run: run
320
+ ? {
321
+ id: clean(run.id, 64),
322
+ client: clean(run.clientName, 80),
323
+ status: run.status,
324
+ summary: clean(run.summary, 500),
325
+ createdAt: run.createdAt,
326
+ appliedAt: run.appliedAt,
327
+ verifiedAt: run.verifiedAt,
328
+ }
329
+ : null,
330
+ newer: newer ? { id: clean(newer.id, 64), client: clean(newer.clientName, 80), status: newer.status, createdAt: newer.createdAt } : null,
331
+ checks: (result?.checks ?? [])
332
+ .filter((c) => STATUSES.has(c.status))
333
+ .map((c) => ({ key: clean(c.key, 40), label: clean(c.label, 80), status: c.status, detail: clean(c.detail, 500) })),
334
+ collections: (result?.collections ?? []).map((c) => ({
335
+ key: clean(c.key, 80),
336
+ displayName: clean(c.displayName, 120),
337
+ kind: clean(c.kind, 20),
338
+ fields: Array.isArray(c.fieldKeys) ? c.fieldKeys.length : 0,
339
+ records: typeof c.recordsCreated === "number" ? c.recordsCreated : 0,
340
+ })),
341
+ filesChanged: lines(report?.filesChanged),
342
+ stillHardcoded: lines(report?.stillHardcoded),
343
+ warnings: [...lines(result?.warnings), ...lines(report?.warnings, 20)],
344
+ previewUrl: reportedPage(report?.previewUrl),
345
+ };
346
+ }
347
+ function runLine(r) {
348
+ const parts = [r.client, label(r.status)];
349
+ if (r.appliedAt)
350
+ parts.push(`applied ${ago(r.appliedAt)}`);
351
+ else
352
+ parts.push(`proposed ${ago(r.createdAt)}`);
353
+ if (r.verifiedAt)
354
+ parts.push(`checked ${ago(r.verifiedAt)}`);
355
+ return parts.join(" • ");
356
+ }
357
+ /** The closing line: what to do next. */
358
+ export function reportSummary(report) {
359
+ const failed = report.checks.filter((c) => c.status === "failed").length;
360
+ const warned = report.checks.filter((c) => c.status === "warning").length;
361
+ if (!report.run)
362
+ return "";
363
+ if (report.checks.length === 0) {
364
+ return isChecked(report.run.status)
365
+ ? "The checks haven't run yet — `mapled integration report --verify` runs them."
366
+ : "Mapled checks the integration once the plan is applied.";
367
+ }
368
+ if (failed === 0 && warned === 0)
369
+ return "Integration verified. Your site is fully connected.";
370
+ const parts = [];
371
+ if (failed > 0)
372
+ parts.push(plural(failed, "problem"));
373
+ if (warned > 0)
374
+ parts.push(plural(warned, "warning"));
375
+ return `${parts.join(", ")}.${failed > 0 ? " Fix what the checks name, then `mapled integration report --verify` runs them again." : ""}`;
376
+ }
377
+ export function formatReport(report, color) {
378
+ const out = [`Integration report — ${report.project.name}`, ""];
379
+ if (!report.run) {
380
+ out.push(`No AI setup run in ${report.project.name} yet — the report comes from one. \`mapled doctor\` checks the integration from this repository.`);
381
+ return out;
382
+ }
383
+ out.push(`Setup run ${runLine(report.run)}`);
384
+ if (report.run.summary)
385
+ out.push(`Plan “${report.run.summary}”`);
386
+ if (report.newer) {
387
+ out.push(`Newer ${report.newer.client} • ${label(report.newer.status)} • proposed ${ago(report.newer.createdAt)} — the report is of the last applied run`);
388
+ }
389
+ if (report.checks.length > 0) {
390
+ out.push("", "Verification");
391
+ const width = report.checks.reduce((w, c) => Math.max(w, c.label.length), 0);
392
+ for (const c of report.checks)
393
+ out.push(`${paint(c.status, GLYPH[c.status], color)} ${c.label.padEnd(width)} ${c.detail}`);
394
+ }
395
+ if (report.collections.length > 0) {
396
+ out.push("", "Collections created");
397
+ const width = report.collections.reduce((w, c) => Math.max(w, `${c.displayName} (${c.key})`.length), 0);
398
+ for (const c of report.collections) {
399
+ out.push(` ${`${c.displayName} (${c.key})`.padEnd(width)} ${c.kind} • ${plural(c.fields, "field")} • ${plural(c.records, "record")} imported`);
400
+ }
401
+ }
402
+ const list = (title, items, glyph) => {
403
+ if (items.length === 0)
404
+ return;
405
+ out.push("", title);
406
+ for (const item of items)
407
+ out.push(glyph ? `${paint("warning", glyph, color)} ${item}` : ` ${item}`);
408
+ };
409
+ list("Files changed", report.filesChanged);
410
+ list("Still hardcoded", report.stillHardcoded);
411
+ list("Warnings", report.warnings, GLYPH.warning);
412
+ if (report.previewUrl)
413
+ out.push("", `Preview reported by the agent: ${report.previewUrl}`);
414
+ out.push("", reportSummary(report));
415
+ return out;
416
+ }
417
+ /** "5 minutes" until the link stops working, or null when unknown. */
418
+ export function linkLifetime(expiresAt, now = Date.now()) {
419
+ if (!expiresAt)
420
+ return null;
421
+ const ms = new Date(expiresAt).getTime() - now;
422
+ if (!Number.isFinite(ms) || ms <= 0)
423
+ return null;
424
+ return plural(Math.max(1, Math.round(ms / 60_000)), "minute");
425
+ }
package/dist/scan.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type * as TS from "typescript";
2
- import { type Manifest, type ManifestBinding, type ManifestPage } from "./manifest.js";
2
+ import { type Manifest, type ManifestBinding, type ManifestCapabilities, type ManifestPage } from "./manifest.js";
3
3
  import type { Schema } from "./schema.js";
4
4
  /** `mapled scan` (§19.5, §21.4 — the standalone scanner of wave 2): reads
5
5
  the site's source and writes down what the code reads from Mapled —
@@ -37,22 +37,40 @@ export type ScanResult = {
37
37
  pages: ManifestPage[];
38
38
  bindings: ManifestBinding[];
39
39
  notes: string[];
40
+ /** what the code says the site can do (live updates of a Next.js site); undefined keeps the manifest's */
41
+ capabilities?: ManifestCapabilities;
40
42
  };
41
43
  export declare const SDK_METHODS: Set<string>;
42
44
  /** The repository's TypeScript, when it has one; the CLI ships none. */
43
45
  export declare function loadTypeScript(dir: string): TypeScriptModule | null;
46
+ export declare function listFiles(dir: string, max: number): Promise<{
47
+ files: string[];
48
+ truncated: boolean;
49
+ }>;
44
50
  export type RouteMap = {
45
51
  pages: Map<string, string>;
46
52
  layouts: Map<string, string>;
47
53
  };
54
+ /** Next.js App Router segments: groups and slots vanish, params keep
55
+ the [param] form the manifest uses. */
56
+ export declare function appRoute(segments: string[]): string | null;
48
57
  export declare function detectRoutes(files: string[], framework: string | null): RouteMap;
58
+ /** `nl`: a line break comes before the token — a `return` followed by one returns nothing. */
59
+ /** `nl`: a line break stands before the token; `escaped`: a string written
60
+ with a backslash escape, or an identifier with a `\u` escape in its
61
+ name; `unclosed`: a quoted string a line break (or the end) cut off
62
+ before its closing quote — JSX lets an attribute run on. */
49
63
  export type Token = {
50
64
  kind: "ident" | "string" | "punct";
51
65
  value: string;
66
+ nl?: true;
67
+ escaped?: true;
68
+ unclosed?: true;
52
69
  };
53
70
  /** JavaScript tokens: identifiers, string literals and punctuation, with
54
71
  comments and template bodies dropped. A regex literal after an
55
- operator is skipped; JSX text is read as code, so an apostrophe in
72
+ operator is skipped — only one that closes on its line, and never the
73
+ `/>` after a JSX attribute's `}`; JSX text is read as code, so an apostrophe in
56
74
  prose can swallow a stretch — a false negative, never a crash. */
57
75
  export declare function tokenize(text: string): Token[];
58
76
  export declare function routeKey(route: string): string;
@@ -65,6 +83,8 @@ export type MergeResult = {
65
83
  /** Bindings the scan didn't produce: kept (or dropped with prune). */
66
84
  kept: string[];
67
85
  dropped: string[];
86
+ /** the scan changed what an existing manifest says the site can do */
87
+ capabilitiesChanged: boolean;
68
88
  };
69
89
  /** The scan's bindings replace the ones with the same key; bindings the
70
90
  scanner can't see (an agent's, hand-written) stay unless pruned. */