deictic 0.5.0 → 0.6.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/API.md CHANGED
@@ -20,12 +20,13 @@ adds it to the bundler's config, and offers the agent skill (`--dry-run`, `--no-
20
20
  For Bun it writes `deictic.plugin.ts`, names it in `bunfig.toml` and spreads its routes into `Bun.serve`'s, where a
21
21
  server of the project's has Bun bundle an HTML page (a Bun project that runs Vite or Next.js is theirs). This is what
22
22
  it adds, and what to add by hand where it can't (a config it can't read). Every integration takes the same options
23
- and runs in the dev server only.
23
+ and runs in the dev server only. deictic goes first among the plugins: one before it that changes a module would have
24
+ the page point at that plugin's code, not the file.
24
25
 
25
26
  ```ts
26
27
  // Vite, and anything on it (React Router, TanStack Start…): vite.config.ts
27
28
  import { deictic } from 'deictic/vite';
28
- export default defineConfig({ plugins: [react(), deictic({ plugins: recommended() })] });
29
+ export default defineConfig({ plugins: [deictic({ plugins: recommended() }), react()] });
29
30
 
30
31
  // Next.js (`next dev`, Turbopack or webpack): next.config.ts
31
32
  import { withDeictic } from 'deictic/next';
@@ -128,12 +129,15 @@ recommended({ tasks: { board: local({ port: 4200 }) } }); // the one on your mac
128
129
 
129
130
  In the Task tab a task's dot says its state, and who holds it while it's claimed (`claimed by claude`).
130
131
 
131
- A task is the words typed and its attachments. The rest is labels: `deictic.project`, `deictic.at` (the element's
132
- `file:line:column`), `deictic.file`, `deictic.url`, `deictic.viewport` and more, with your own beside them. After the
133
- words comes what a label can't hold: the chain of source it rendered through, as
134
- `src/ui/label.tsx:6 ← Field (src/Field.tsx:20) ← Panel` (a shared component's line is the same wherever it's
135
- used; the rest say where: with React in development the components that use it, three at most, and otherwise the
136
- files around it). The element's HTML as it rendered is attached as `element.html`,
132
+ A task's text is the words typed, and nothing else. The rest is its attachments and labels: `deictic.project`,
133
+ `deictic.at` (the element's `file:line:column`), `deictic.file`, `deictic.url`, `deictic.viewport` and more, with your
134
+ own beside them. What the attached files don't say is numbered from 1: `deictic.screenshot.1.position` and `.size`
135
+ are where the element is in the first PNG attached, and `.note.1` a note drawn on it; `deictic.note.1` is a note drawn
136
+ on the page; `deictic.recording.1.replay` is where the first recording plays back; `deictic.pointed` is the path to
137
+ what was pointed at inside the element; `deictic.dropped.1` is something attached that wasn't kept any more.
138
+ `deictic.source` is what it rendered through, out from its own place, as `Field (src/Field.tsx:20) ← Panel` (a shared
139
+ component's line is the same wherever it's used; these say where: with React in development the components that use
140
+ it, three at most, and otherwise the files around it). The element's HTML as it rendered is attached as `element.html`,
137
141
  masked as screenshots are, for whoever can't open the page as you had it: a file, so the task stays short.
138
142
  Untick **Attach HTML snapshot** for a task without it; `html: false` takes the box away. A screenshot attached by the box has the element outlined in it; one you annotated is as you drew it.
139
143
 
@@ -302,6 +306,9 @@ export default defineClientPlugin<Model, Op>({
302
306
  screenshots and recordings.
303
307
  - A change that isn't to a file answers `{ done: record }`, and the plugin's `undo` and `redo` get the record back.
304
308
  - Throw a `Refusal` for an op the plugin won't make. The panel shows its message.
309
+ - `read` and `apply` get the element's source, or a `Refusal` saying why it isn't to be found (the file doesn't parse,
310
+ or the page runs other code than the file has): throw it where the plugin needs the source, or go on without, as
311
+ tasks do. Text edits without it are refused.
305
312
  - A panel leaves the popup for something on the page with `away(state, task)`, and is mounted again with `resumed`.
306
313
  Where the task outlasts a page load, as a recording does, the page half's `resume` answers it on the next page, and
307
314
  the popup comes back there: on the element, or without it (`element.isConnected` is false) where that page has none.
@@ -24,14 +24,21 @@ function readSource(root, file) {
24
24
  throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });
25
25
  }
26
26
  }
27
- /** The target's file and element, as they are on disk now. */
27
+ /**
28
+ * The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the
29
+ * only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.
30
+ */
28
31
  function sourceAt(root, target) {
29
32
  const { file, line, column } = target.loc;
30
33
  const code = readSource(root, file);
31
- const offset = offsetOf(lineStarts(code), line, column);
34
+ const lines = lineStarts(code);
35
+ const offset = offsetOf(lines, line, column);
32
36
  const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);
33
- const element = elements.find((el) => el.start === offset && isHost(el));
34
- if (element === void 0 || element.name.type === "JSXIdentifier" && element.name.name !== target.tag) throw new Refusal(`no <${target.tag}> at ${file}:${line}:${column} any more: the file changed since the page loaded, so reload it`);
37
+ const tagged = elements.filter((el) => isHost(el) && el.name.type === "JSXIdentifier" && el.name.name === target.tag);
38
+ const start = lines[line - 1];
39
+ const onLine = start === void 0 ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? 1e400));
40
+ const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : void 0);
41
+ if (element === void 0) throw new Refusal(notThere(target, code, lines, onLine.length));
35
42
  return {
36
43
  file,
37
44
  code,
@@ -40,6 +47,12 @@ function sourceAt(root, target) {
40
47
  read: (other) => readSource(root, other)
41
48
  };
42
49
  }
50
+ /** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */
51
+ function notThere({ loc: { file, line, column }, tag }, code, lines, onLine) {
52
+ const start = lines[line - 1];
53
+ return `${start === void 0 ? `${file} has no line ${line}` : onLine === 0 ? `line ${line} of ${file} has no <${tag}>: it reads \`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\`` : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;
54
+ }
55
+ const clip = (text) => text.length > 80 ? `${text.slice(0, 79)}…` : text;
43
56
  function jsx(file, code) {
44
57
  const { program, errors } = parse(file, code);
45
58
  if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0].message})`);
@@ -258,13 +271,18 @@ function endpoints({ root, plugins, base = "/", open, history = new History(root
258
271
  apply: async ({ plugin: name, target, op }) => {
259
272
  const plugin = pluginOf(name);
260
273
  if (plugin.apply === void 0) throw new Refusal(`${name} changes nothing from its panel: it has no \`apply\``);
261
- const source = sourceAt(root, target);
262
- const before = await readOf(plugin, target);
274
+ const source = sourceOf(target);
275
+ const before = await readOf(plugin, target, source);
263
276
  const { file, line } = target.loc;
264
277
  const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? "edit"}`;
265
278
  const result = await plugin.apply(source, target, op);
266
279
  const scope = scopeOf(name, target.loc);
267
- const change = Array.isArray(result) ? history.commit(label, applyEdits(source, result), scope) : history.record(label, name, result.done, scope);
280
+ if (!Array.isArray(result)) return {
281
+ change: history.record(label, name, result.done, scope),
282
+ model: await readOf(plugin, target)
283
+ };
284
+ if (source instanceof Refusal) throw source;
285
+ const change = history.commit(label, applyEdits(source, result), scope);
268
286
  return {
269
287
  model: await readOf(plugin, target),
270
288
  change
@@ -273,7 +291,15 @@ function endpoints({ root, plugins, base = "/", open, history = new History(root
273
291
  undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),
274
292
  redo: async (body) => ({ change: await history.redo(scopeIn(body)) })
275
293
  };
276
- const readOf = (plugin, target) => plugin.read === void 0 ? null : plugin.read(sourceAt(root, target), target);
294
+ const sourceOf = (target) => {
295
+ try {
296
+ return sourceAt(root, target);
297
+ } catch (e) {
298
+ if (e instanceof Refusal) return e;
299
+ throw e;
300
+ }
301
+ };
302
+ const readOf = (plugin, target, source) => plugin.read === void 0 ? null : plugin.read(source ?? sourceOf(target), target);
277
303
  let queue = Promise.resolve();
278
304
  const serially = (run) => {
279
305
  const next = queue.then(run, run);
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.js","names":[],"sources":["../../src/tools/source.ts","../../src/tools/history.ts","../../src/tools/endpoints.ts"],"sourcesContent":["/**\n * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute\n * points at. Files are only ever read and written under the project's root, outside `node_modules`.\n */\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nimport { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';\n\nimport { ASTRO, parseAstro, type Parsed } from './astro.ts';\nimport { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';\n\n/** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */\nexport function resolveFile(root: string, file: string): string {\n const path = resolve(root, file);\n const from = relative(root, path);\n // `relative` gives an absolute path for another drive.\n if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))\n throw new Refusal(`${file} is not a file of this project's own`);\n return path;\n}\n\nexport function readSource(root: string, file: string): string {\n try {\n return readFileSync(resolveFile(root, file), 'utf8');\n } catch (e) {\n if (e instanceof Refusal) throw e;\n throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });\n }\n}\n\n/** The target's file and element, as they are on disk now. */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const offset = offsetOf(lineStarts(code), line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const element = elements.find((el) => el.start === offset && isHost(el));\n if (element === undefined || (element.name.type === 'JSXIdentifier' && element.name.name !== target.tag))\n throw new Refusal(`no <${target.tag}> at ${file}:${line}:${column} any more: the file changed since the page loaded, so reload it`);\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\nfunction jsx(file: string, code: string): Parsed {\n const { program, errors } = parse(file, code);\n if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);\n return { program, elements: openingsIn(program) };\n}\n\nfunction astro(root: string, file: string, code: string): Parsed {\n const parsed = parseAstro(root, code);\n if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);\n return parsed;\n}\n\n/** Each file's text after its edits, which must not overlap. */\nexport function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {\n const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);\n const out = new Map<string, string>();\n for (const [file, list] of byFile) {\n const sorted = list.toSorted((a, b) => b.start - a.start);\n let code = file === source.file ? source.code : source.read(file);\n let floor = Infinity;\n for (const edit of sorted) {\n if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);\n code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);\n floor = edit.start;\n }\n out.set(file, code);\n }\n return out;\n}\n","/**\n * Every change deictic made, to undo and redo. A change to files holds each file's whole text\n * before and after: source files are small, and the texts make undo exact without a diff to go stale.\n * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the\n * plugin's `undo`.\n *\n * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes\n * within its own: the latest change of this tab on this element, not the latest of all. So a change\n * is taken back out of order, with later ones to the same file still in it. Then only the lines the\n * change wrote go back to what they were, where they're still in the file as it wrote them, once.\n *\n * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo\n * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it\n * outlives a restart of the dev server and stays out of git.\n */\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { Refusal, type ServerPlugin } from '#src/index.ts';\n\nimport { keptIn } from './kept.ts';\nimport { resolveFile } from './source.ts';\n\nexport interface FileChange {\n file: string;\n /** The text before, or nothing for a file the change made. */\n before: string | null;\n after: string;\n}\n\n/** Whose a change is: the plugin whose tab made it, and the element it was open on, as `file:line:column`. */\nexport interface Scope {\n plugin: string;\n target: string;\n}\n\ninterface Base {\n id: number;\n at: string;\n label: string;\n /** None on a change made without one, which only an undo of the whole history reaches. */\n scope?: Scope;\n}\n\nexport type Change = Base & ({ files: FileChange[] } | { plugin: string; record: unknown });\n\n/** A change as the page lists it. `files` is empty for one a plugin made itself. */\nexport interface Summary {\n id: number;\n at: string;\n label: string;\n files: string[];\n}\n\nexport interface HistoryOptions {\n /** Whose `undo` and `redo` take back the changes they made themselves. */\n plugins?: ServerPlugin[];\n store?: string;\n}\n\nconst LIMIT = 200;\n\n/** Whether a change is in a scope: any is in none. */\nconst within = (scope: Scope | undefined) => (c: Change) =>\n scope === undefined || (c.scope?.plugin === scope.plugin && c.scope.target === scope.target);\n\nconst summary = (c: Change): Summary => ({ id: c.id, at: c.at, label: c.label, files: 'files' in c ? c.files.map((f) => f.file) : [] });\n\nexport class History {\n #done: Change[] = [];\n #undone: Change[] = [];\n readonly #root: string;\n readonly #store: string;\n readonly #plugins: Map<string, ServerPlugin>;\n\n constructor(root: string, { plugins = [], store = keptIn(root, 'history.json') }: HistoryOptions = {}) {\n this.#root = root;\n this.#store = store;\n this.#plugins = new Map(plugins.map((p) => [p.name, p]));\n if (!existsSync(store)) return;\n try {\n ({ done: this.#done, undone: this.#undone } = JSON.parse(readFileSync(store, 'utf8')) as { done: Change[]; undone: Change[] });\n } catch {\n // A history that doesn't read is one we start over, not one to stop the dev server for.\n }\n }\n\n /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */\n commit(label: string, texts: Map<string, string>, scope?: Scope): Summary {\n const files: FileChange[] = [];\n for (const [file, after] of texts) {\n const path = resolveFile(this.#root, file);\n const before = existsSync(path) ? readFileSync(path, 'utf8') : null;\n if (before !== after) files.push({ file, before, after });\n }\n if (files.length === 0) throw new Refusal('nothing to change: the source already says that');\n for (const f of files) write(resolveFile(this.#root, f.file), f.after);\n return this.#push({ label, files }, scope);\n }\n\n /** Records a change `plugin` made itself, with what its `undo` needs. */\n record(label: string, plugin: string, record: unknown, scope?: Scope): Summary {\n return this.#push({ label, plugin, record }, scope);\n }\n\n /** Takes back the latest change, of a scope where one is given. */\n async undo(scope?: Scope): Promise<Summary> {\n const change = this.#done.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to undo' : 'nothing to undo here');\n if ('files' in change) this.#put(change, 'after', 'before');\n else change.record = (await this.#pluginOf(change, 'undo').undo!(change.record)) ?? change.record;\n this.#done = this.#done.filter((c) => c !== change);\n this.#undone.push(change);\n this.#save();\n return summary(change);\n }\n\n /** Makes the change last undone again, of a scope where one is given. */\n async redo(scope?: Scope): Promise<Summary> {\n const change = this.#undone.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to redo' : 'nothing to redo here');\n if ('files' in change) this.#put(change, 'before', 'after');\n else change.record = await this.#pluginOf(change, 'redo').redo!(change.record);\n this.#undone = this.#undone.filter((c) => c !== change);\n this.#done.push(change);\n this.#save();\n return summary(change);\n }\n\n list(scope?: Scope): { done: Summary[]; undone: Summary[] } {\n return { done: this.#done.filter(within(scope)).map(summary), undone: this.#undone.filter(within(scope)).map(summary) };\n }\n\n #push(change: Omit<Base, 'id' | 'at'> & ({ files: FileChange[] } | { plugin: string; record: unknown }), scope?: Scope): Summary {\n const id = Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1;\n const made = { id, at: new Date().toISOString(), ...change, ...(scope === undefined ? {} : { scope }) };\n this.#done = [...this.#done, made].slice(-LIMIT);\n // What was undone in this scope can't be redone over the new change; another scope's still can.\n this.#undone = this.#undone.filter((c) => !within(scope)(c));\n this.#save();\n return summary(made);\n }\n\n #pluginOf(change: { label: string; plugin: string }, step: 'undo' | 'redo'): ServerPlugin {\n const plugin = this.#plugins.get(change.plugin);\n if (plugin?.[step] === undefined) {\n throw new Refusal(\n `can't ${step} \"${change.label}\": the ${change.plugin} plugin that made it isn't loaded, so add it back to \\`plugins\\``,\n );\n }\n return plugin;\n }\n\n /**\n * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the\n * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.\n */\n #put(change: Base & { files: FileChange[] }, from: 'before' | 'after', to: 'before' | 'after'): void {\n const paths = change.files.map((f) => resolveFile(this.#root, f.file));\n const texts = change.files.map((f, i) => {\n const now = existsSync(paths[i]!) ? readFileSync(paths[i]!, 'utf8') : null;\n if (now === f[from]) return f[to];\n const text = now === null || f[from] === null || f[to] === null ? undefined : swapped(now, f[from], f[to]);\n if (text === undefined) {\n throw new Refusal(\n `${f.file} changed since \"${change.label}\" ${from === 'after' ? 'was made' : 'was undone'}: use the editor's undo there`,\n );\n }\n return text;\n });\n texts.forEach((text, i) => {\n if (text === null) rmSync(paths[i]!);\n else write(paths[i]!, text);\n });\n }\n\n #save(): void {\n write(this.#store, JSON.stringify({ done: this.#done, undone: this.#undone }));\n }\n}\n\n/**\n * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as\n * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or\n * where `from` has no such lines to find (the change only removed some).\n */\nfunction swapped(now: string, from: string, to: string): string | undefined {\n const [a, b, lines] = [from.split('\\n'), to.split('\\n'), now.split('\\n')];\n let head = 0;\n while (head < a.length && head < b.length && a[head] === b[head]) head++;\n let tail = 0;\n while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;\n const theirs = a.slice(head, a.length - tail);\n if (theirs.length === 0) return undefined;\n const found = lines.flatMap((_, i) => (theirs.every((line, j) => lines[i + j] === line) ? [i] : []));\n if (found.length !== 1) return undefined;\n return [...lines.slice(0, found[0]), ...b.slice(head, b.length - tail), ...lines.slice(found[0]! + theirs.length)].join('\\n');\n}\n\nfunction write(path: string, text: string): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, text);\n}\n","/**\n * The dev server's half of deictic, under `/__deictic/`: `read` and `apply` an op through a\n * plugin, `undo`, `redo` and `history`, and `open`, which opens a place in the editor. Written over\n * `Request` and `Response`, so each integration mounts them its own way (Vite as middleware), and\n * served from the page's own origin, so no token travels to the page. `undo`, `redo` and `history` are a\n * plugin's on an element where the request names them (as the popup does: its tab, its element), and\n * the whole history's where it doesn't.\n *\n * Everything but `open` and `history` writes or may, so only the page itself may send it: a POST of\n * JSON from the same origin, which a form or a script on another site can't send without asking first.\n *\n * Each plugin's own `routes` are under `plugins/<name>/`. A `GET` there reaches the plugin as it\n * comes; anything else only from the page's own origin, in whatever type it sends (an image, say).\n * Nothing is answered before every plugin's `setup` has run.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\n\nimport { type Loc, Refusal, type ServerPlugin, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { missingMessage } from './packages.ts';\nimport { setUp } from './plugins.ts';\nimport { applyEdits, resolveFile, sourceAt } from './source.ts';\n\nexport interface EndpointOptions {\n root: string;\n plugins: ServerPlugin[];\n /** The path the endpoints sit under, ending in `/`: `/` by default. */\n base?: string;\n /** Opens a place in the editor: a redirect to the dev server's own launcher. */\n open: (path: string, loc: Loc) => Response | Promise<Response>;\n history?: History;\n}\n\ninterface Body {\n plugin: string;\n target: Target;\n op?: unknown;\n}\n\nconst scopeOf = (plugin: string, { file, line, column }: Loc): Scope => ({ plugin, target: `${file}:${line}:${column}` });\n/** The scope an undo or a redo names, or none for the whole history. */\nconst scopeIn = ({ plugin, target }: Partial<Body>) =>\n plugin === undefined || target === undefined ? undefined : scopeOf(plugin, target.loc);\n\n/** Answers deictic's requests, and nothing for any other path. */\nexport function endpoints({ root, plugins, base = '/', open, history = new History(root, { plugins }) }: EndpointOptions) {\n const byName = new Map(plugins.map((p) => [p.name, p]));\n const prefix = `${base}__deictic/`;\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins);\n const gone = missingMessage(root, plugins);\n if (gone !== undefined) console.warn(gone);\n\n const pluginOf = (name: string) => {\n const plugin = byName.get(name);\n if (plugin === undefined) throw new Refusal(`no plugin \"${name}\" on the server: is it in the bundler plugin's \\`plugins\\`?`);\n return plugin;\n };\n\n const routes: Record<string, (body: Body) => Promise<unknown>> = {\n read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),\n apply: async ({ plugin: name, target, op }) => {\n const plugin = pluginOf(name);\n if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \\`apply\\``);\n const source = sourceAt(root, target);\n const before = await readOf(plugin, target);\n const { file, line } = target.loc;\n const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;\n const result = await plugin.apply(source, target, op);\n const scope = scopeOf(name, target.loc);\n const change = Array.isArray(result)\n ? history.commit(label, applyEdits(source, result), scope)\n : history.record(label, name, result.done, scope);\n return { model: await readOf(plugin, target), change };\n },\n undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),\n redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),\n };\n // A plugin without `read` has no model, and no need for its element to be where the page says.\n const readOf = (plugin: ServerPlugin, target: Target) => (plugin.read === undefined ? null : plugin.read(sourceAt(root, target), target));\n // One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must\n // take back that change, not the one before it.\n let queue: Promise<unknown> = Promise.resolve();\n const serially = <T>(run: () => Promise<T>): Promise<T> => {\n const next = queue.then(run, run);\n queue = next.catch(() => {});\n return next;\n };\n\n return async (req: Request): Promise<Response | undefined> => {\n const url = new URL(req.url);\n if (!url.pathname.startsWith(prefix)) return undefined;\n const route = url.pathname.slice(prefix.length);\n const origin = req.headers.get('origin');\n const sameOrigin = origin !== null && new URL(origin).host === url.host;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n const handle = byName.get(name)?.routes?.[first];\n if (handle === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'GET' && req.method !== 'HEAD' && !sameOrigin)\n return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });\n return await handle(req, context);\n }\n const loc = {\n file: url.searchParams.get('file') ?? '',\n line: Number(url.searchParams.get('line')),\n column: Number(url.searchParams.get('column')),\n };\n if (route === 'history') {\n const plugin = url.searchParams.get('plugin');\n return Response.json(history.list(plugin === null ? undefined : scopeOf(plugin, loc)));\n }\n if (route === 'open') return await open(resolveFile(root, loc.file), loc);\n const handler = routes[route];\n if (handler === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'POST' || !sameOrigin || req.headers.get('content-type')?.startsWith('application/json') !== true)\n return Response.json({ problem: 'edits come from the page, as JSON' }, { status: 403 });\n const body = (await req.json()) as Body;\n return Response.json(await (route === 'read' ? handler(body) : serially(() => handler(body))));\n } catch (e) {\n if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });\n return Response.json({ problem: e instanceof Error ? (e.stack ?? e.message) : String(e) }, { status: 500 });\n }\n };\n}\n\n/** A redirect within the page's origin, to a launcher the dev server answers itself. */\nexport const redirect = (path: string) => new Response(null, { status: 307, headers: { Location: path } });\n\n/**\n * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was\n * served from: a proxy's `x-forwarded-host` before its own.\n */\nexport function nodeMiddleware(\n handle: (req: Request) => Promise<Response | undefined>,\n): (req: IncomingMessage, res: ServerResponse, next: () => void) => void {\n return (req, res, next) => {\n // Before reading the body, which a request for anything else leaves to whoever answers it.\n if (req.url?.includes('/__deictic/') !== true) return next();\n const forwarded = req.headers['x-forwarded-host'];\n const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? 'localhost';\n const headers = new Headers();\n for (const [name, value] of Object.entries(req.headers))\n for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(name, v);\n\n const chunks: Buffer[] = [];\n req.on('data', (chunk: Buffer) => chunks.push(chunk));\n req.on('end', () => {\n const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : Buffer.concat(chunks);\n handle(new Request(`http://${host}${req.url}`, { method: req.method, headers, body }))\n .then(async (response) => {\n if (response === undefined) return next();\n res.statusCode = response.status;\n response.headers.forEach((value, name) => res.setHeader(name, value));\n res.end(Buffer.from(await response.arrayBuffer()));\n })\n .catch((e: unknown) => {\n res.statusCode = 500;\n res.end(e instanceof Error ? e.message : String(e));\n });\n });\n };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,MAAM,OAAO,QAAQ,MAAM,IAAI;CAC/B,MAAM,OAAO,SAAS,MAAM,IAAI;CAEhC,IAAI,SAAS,MAAM,KAA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AI,OAAO,GACpD,KAAK,MAAM,KAAK,MAAM,QAAQ,KAAK,IAAI,QAAQ,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,OAAO,MAAM,CAAC;EAE3G,MAAM,SAAmB,CAAC;EAC1B,IAAI,GAAG,SAAS,UAAkB,OAAO,KAAK,KAAK,CAAC;EACpD,IAAI,GAAG,aAAa;GAClB,MAAM,OAAO,IAAI,WAAW,SAAS,IAAI,WAAW,SAAS,KAAA,IAAY,OAAO,OAAO,MAAM;GAC7F,OAAO,IAAI,QAAQ,UAAU,OAAO,IAAI,OAAO;IAAE,QAAQ,IAAI;IAAQ;IAAS;GAAK,CAAC,CAAC,CAAC,CACnF,KAAK,OAAO,aAAa;IACxB,IAAI,aAAa,KAAA,GAAW,OAAO,KAAK;IACxC,IAAI,aAAa,SAAS;IAC1B,SAAS,QAAQ,SAAS,OAAO,SAAS,IAAI,UAAU,MAAM,KAAK,CAAC;IACpE,IAAI,IAAI,OAAO,KAAK,MAAM,SAAS,YAAY,CAAC,CAAC;GACnD,CAAC,CAAC,CACD,OAAO,MAAe;IACrB,IAAI,aAAa;IACjB,IAAI,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;GACpD,CAAC;EACL,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"endpoints.js","names":[],"sources":["../../src/tools/source.ts","../../src/tools/history.ts","../../src/tools/endpoints.ts"],"sourcesContent":["/**\n * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute\n * points at. Files are only ever read and written under the project's root, outside `node_modules`.\n */\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nimport { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';\n\nimport { ASTRO, parseAstro, type Parsed } from './astro.ts';\nimport { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';\n\n/** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */\nexport function resolveFile(root: string, file: string): string {\n const path = resolve(root, file);\n const from = relative(root, path);\n // `relative` gives an absolute path for another drive.\n if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))\n throw new Refusal(`${file} is not a file of this project's own`);\n return path;\n}\n\nexport function readSource(root: string, file: string): string {\n try {\n return readFileSync(resolveFile(root, file), 'utf8');\n } catch (e) {\n if (e instanceof Refusal) throw e;\n throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });\n }\n}\n\n/**\n * The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the\n * only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.\n */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const lines = lineStarts(code);\n const offset = offsetOf(lines, line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const tagged = elements.filter((el) => isHost(el) && el.name.type === 'JSXIdentifier' && el.name.name === target.tag);\n const start = lines[line - 1];\n const onLine = start === undefined ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? Infinity));\n const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : undefined);\n if (element === undefined) throw new Refusal(notThere(target, code, lines, onLine.length));\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\n/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */\nfunction notThere({ loc: { file, line, column }, tag }: Target, code: string, lines: number[], onLine: number): string {\n const start = lines[line - 1];\n const found =\n start === undefined\n ? `${file} has no line ${line}`\n : onLine === 0\n ? `line ${line} of ${file} has no <${tag}>: it reads \\`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\\``\n : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`;\n return `${found}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;\n}\n\nconst clip = (text: string) => (text.length > 80 ? `${text.slice(0, 79)}…` : text);\n\nfunction jsx(file: string, code: string): Parsed {\n const { program, errors } = parse(file, code);\n if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);\n return { program, elements: openingsIn(program) };\n}\n\nfunction astro(root: string, file: string, code: string): Parsed {\n const parsed = parseAstro(root, code);\n if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);\n return parsed;\n}\n\n/** Each file's text after its edits, which must not overlap. */\nexport function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {\n const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);\n const out = new Map<string, string>();\n for (const [file, list] of byFile) {\n const sorted = list.toSorted((a, b) => b.start - a.start);\n let code = file === source.file ? source.code : source.read(file);\n let floor = Infinity;\n for (const edit of sorted) {\n if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);\n code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);\n floor = edit.start;\n }\n out.set(file, code);\n }\n return out;\n}\n","/**\n * Every change deictic made, to undo and redo. A change to files holds each file's whole text\n * before and after: source files are small, and the texts make undo exact without a diff to go stale.\n * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the\n * plugin's `undo`.\n *\n * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes\n * within its own: the latest change of this tab on this element, not the latest of all. So a change\n * is taken back out of order, with later ones to the same file still in it. Then only the lines the\n * change wrote go back to what they were, where they're still in the file as it wrote them, once.\n *\n * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo\n * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it\n * outlives a restart of the dev server and stays out of git.\n */\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { Refusal, type ServerPlugin } from '#src/index.ts';\n\nimport { keptIn } from './kept.ts';\nimport { resolveFile } from './source.ts';\n\nexport interface FileChange {\n file: string;\n /** The text before, or nothing for a file the change made. */\n before: string | null;\n after: string;\n}\n\n/** Whose a change is: the plugin whose tab made it, and the element it was open on, as `file:line:column`. */\nexport interface Scope {\n plugin: string;\n target: string;\n}\n\ninterface Base {\n id: number;\n at: string;\n label: string;\n /** None on a change made without one, which only an undo of the whole history reaches. */\n scope?: Scope;\n}\n\nexport type Change = Base & ({ files: FileChange[] } | { plugin: string; record: unknown });\n\n/** A change as the page lists it. `files` is empty for one a plugin made itself. */\nexport interface Summary {\n id: number;\n at: string;\n label: string;\n files: string[];\n}\n\nexport interface HistoryOptions {\n /** Whose `undo` and `redo` take back the changes they made themselves. */\n plugins?: ServerPlugin[];\n store?: string;\n}\n\nconst LIMIT = 200;\n\n/** Whether a change is in a scope: any is in none. */\nconst within = (scope: Scope | undefined) => (c: Change) =>\n scope === undefined || (c.scope?.plugin === scope.plugin && c.scope.target === scope.target);\n\nconst summary = (c: Change): Summary => ({ id: c.id, at: c.at, label: c.label, files: 'files' in c ? c.files.map((f) => f.file) : [] });\n\nexport class History {\n #done: Change[] = [];\n #undone: Change[] = [];\n readonly #root: string;\n readonly #store: string;\n readonly #plugins: Map<string, ServerPlugin>;\n\n constructor(root: string, { plugins = [], store = keptIn(root, 'history.json') }: HistoryOptions = {}) {\n this.#root = root;\n this.#store = store;\n this.#plugins = new Map(plugins.map((p) => [p.name, p]));\n if (!existsSync(store)) return;\n try {\n ({ done: this.#done, undone: this.#undone } = JSON.parse(readFileSync(store, 'utf8')) as { done: Change[]; undone: Change[] });\n } catch {\n // A history that doesn't read is one we start over, not one to stop the dev server for.\n }\n }\n\n /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */\n commit(label: string, texts: Map<string, string>, scope?: Scope): Summary {\n const files: FileChange[] = [];\n for (const [file, after] of texts) {\n const path = resolveFile(this.#root, file);\n const before = existsSync(path) ? readFileSync(path, 'utf8') : null;\n if (before !== after) files.push({ file, before, after });\n }\n if (files.length === 0) throw new Refusal('nothing to change: the source already says that');\n for (const f of files) write(resolveFile(this.#root, f.file), f.after);\n return this.#push({ label, files }, scope);\n }\n\n /** Records a change `plugin` made itself, with what its `undo` needs. */\n record(label: string, plugin: string, record: unknown, scope?: Scope): Summary {\n return this.#push({ label, plugin, record }, scope);\n }\n\n /** Takes back the latest change, of a scope where one is given. */\n async undo(scope?: Scope): Promise<Summary> {\n const change = this.#done.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to undo' : 'nothing to undo here');\n if ('files' in change) this.#put(change, 'after', 'before');\n else change.record = (await this.#pluginOf(change, 'undo').undo!(change.record)) ?? change.record;\n this.#done = this.#done.filter((c) => c !== change);\n this.#undone.push(change);\n this.#save();\n return summary(change);\n }\n\n /** Makes the change last undone again, of a scope where one is given. */\n async redo(scope?: Scope): Promise<Summary> {\n const change = this.#undone.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to redo' : 'nothing to redo here');\n if ('files' in change) this.#put(change, 'before', 'after');\n else change.record = await this.#pluginOf(change, 'redo').redo!(change.record);\n this.#undone = this.#undone.filter((c) => c !== change);\n this.#done.push(change);\n this.#save();\n return summary(change);\n }\n\n list(scope?: Scope): { done: Summary[]; undone: Summary[] } {\n return { done: this.#done.filter(within(scope)).map(summary), undone: this.#undone.filter(within(scope)).map(summary) };\n }\n\n #push(change: Omit<Base, 'id' | 'at'> & ({ files: FileChange[] } | { plugin: string; record: unknown }), scope?: Scope): Summary {\n const id = Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1;\n const made = { id, at: new Date().toISOString(), ...change, ...(scope === undefined ? {} : { scope }) };\n this.#done = [...this.#done, made].slice(-LIMIT);\n // What was undone in this scope can't be redone over the new change; another scope's still can.\n this.#undone = this.#undone.filter((c) => !within(scope)(c));\n this.#save();\n return summary(made);\n }\n\n #pluginOf(change: { label: string; plugin: string }, step: 'undo' | 'redo'): ServerPlugin {\n const plugin = this.#plugins.get(change.plugin);\n if (plugin?.[step] === undefined) {\n throw new Refusal(\n `can't ${step} \"${change.label}\": the ${change.plugin} plugin that made it isn't loaded, so add it back to \\`plugins\\``,\n );\n }\n return plugin;\n }\n\n /**\n * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the\n * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.\n */\n #put(change: Base & { files: FileChange[] }, from: 'before' | 'after', to: 'before' | 'after'): void {\n const paths = change.files.map((f) => resolveFile(this.#root, f.file));\n const texts = change.files.map((f, i) => {\n const now = existsSync(paths[i]!) ? readFileSync(paths[i]!, 'utf8') : null;\n if (now === f[from]) return f[to];\n const text = now === null || f[from] === null || f[to] === null ? undefined : swapped(now, f[from], f[to]);\n if (text === undefined) {\n throw new Refusal(\n `${f.file} changed since \"${change.label}\" ${from === 'after' ? 'was made' : 'was undone'}: use the editor's undo there`,\n );\n }\n return text;\n });\n texts.forEach((text, i) => {\n if (text === null) rmSync(paths[i]!);\n else write(paths[i]!, text);\n });\n }\n\n #save(): void {\n write(this.#store, JSON.stringify({ done: this.#done, undone: this.#undone }));\n }\n}\n\n/**\n * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as\n * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or\n * where `from` has no such lines to find (the change only removed some).\n */\nfunction swapped(now: string, from: string, to: string): string | undefined {\n const [a, b, lines] = [from.split('\\n'), to.split('\\n'), now.split('\\n')];\n let head = 0;\n while (head < a.length && head < b.length && a[head] === b[head]) head++;\n let tail = 0;\n while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;\n const theirs = a.slice(head, a.length - tail);\n if (theirs.length === 0) return undefined;\n const found = lines.flatMap((_, i) => (theirs.every((line, j) => lines[i + j] === line) ? [i] : []));\n if (found.length !== 1) return undefined;\n return [...lines.slice(0, found[0]), ...b.slice(head, b.length - tail), ...lines.slice(found[0]! + theirs.length)].join('\\n');\n}\n\nfunction write(path: string, text: string): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, text);\n}\n","/**\n * The dev server's half of deictic, under `/__deictic/`: `read` and `apply` an op through a\n * plugin, `undo`, `redo` and `history`, and `open`, which opens a place in the editor. Written over\n * `Request` and `Response`, so each integration mounts them its own way (Vite as middleware), and\n * served from the page's own origin, so no token travels to the page. `undo`, `redo` and `history` are a\n * plugin's on an element where the request names them (as the popup does: its tab, its element), and\n * the whole history's where it doesn't.\n *\n * Everything but `open` and `history` writes or may, so only the page itself may send it: a POST of\n * JSON from the same origin, which a form or a script on another site can't send without asking first.\n *\n * Each plugin's own `routes` are under `plugins/<name>/`. A `GET` there reaches the plugin as it\n * comes; anything else only from the page's own origin, in whatever type it sends (an image, say).\n * Nothing is answered before every plugin's `setup` has run.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\n\nimport { type Loc, Refusal, type ServerPlugin, type Source, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { missingMessage } from './packages.ts';\nimport { setUp } from './plugins.ts';\nimport { applyEdits, resolveFile, sourceAt } from './source.ts';\n\nexport interface EndpointOptions {\n root: string;\n plugins: ServerPlugin[];\n /** The path the endpoints sit under, ending in `/`: `/` by default. */\n base?: string;\n /** Opens a place in the editor: a redirect to the dev server's own launcher. */\n open: (path: string, loc: Loc) => Response | Promise<Response>;\n history?: History;\n}\n\ninterface Body {\n plugin: string;\n target: Target;\n op?: unknown;\n}\n\nconst scopeOf = (plugin: string, { file, line, column }: Loc): Scope => ({ plugin, target: `${file}:${line}:${column}` });\n/** The scope an undo or a redo names, or none for the whole history. */\nconst scopeIn = ({ plugin, target }: Partial<Body>) =>\n plugin === undefined || target === undefined ? undefined : scopeOf(plugin, target.loc);\n\n/** Answers deictic's requests, and nothing for any other path. */\nexport function endpoints({ root, plugins, base = '/', open, history = new History(root, { plugins }) }: EndpointOptions) {\n const byName = new Map(plugins.map((p) => [p.name, p]));\n const prefix = `${base}__deictic/`;\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins);\n const gone = missingMessage(root, plugins);\n if (gone !== undefined) console.warn(gone);\n\n const pluginOf = (name: string) => {\n const plugin = byName.get(name);\n if (plugin === undefined) throw new Refusal(`no plugin \"${name}\" on the server: is it in the bundler plugin's \\`plugins\\`?`);\n return plugin;\n };\n\n const routes: Record<string, (body: Body) => Promise<unknown>> = {\n read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),\n apply: async ({ plugin: name, target, op }) => {\n const plugin = pluginOf(name);\n if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \\`apply\\``);\n const source = sourceOf(target);\n const before = await readOf(plugin, target, source);\n const { file, line } = target.loc;\n const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;\n const result = await plugin.apply(source, target, op);\n const scope = scopeOf(name, target.loc);\n if (!Array.isArray(result)) return { change: history.record(label, name, result.done, scope), model: await readOf(plugin, target) };\n // Edits to a file whose element isn't found would go who knows where: refused, as only they need it.\n if (source instanceof Refusal) throw source;\n const change = history.commit(label, applyEdits(source, result), scope);\n return { model: await readOf(plugin, target), change };\n },\n undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),\n redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),\n };\n // The source or why it can't be had, for the plugin to decide: only an edit to the file needs it, not a task.\n const sourceOf = (target: Target): Source | Refusal => {\n try {\n return sourceAt(root, target);\n } catch (e) {\n if (e instanceof Refusal) return e;\n throw e;\n }\n };\n // A plugin without `read` has no model, and no need for its element to be where the page says.\n const readOf = (plugin: ServerPlugin, target: Target, source?: Source | Refusal) =>\n plugin.read === undefined ? null : plugin.read(source ?? sourceOf(target), target);\n // One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must\n // take back that change, not the one before it.\n let queue: Promise<unknown> = Promise.resolve();\n const serially = <T>(run: () => Promise<T>): Promise<T> => {\n const next = queue.then(run, run);\n queue = next.catch(() => {});\n return next;\n };\n\n return async (req: Request): Promise<Response | undefined> => {\n const url = new URL(req.url);\n if (!url.pathname.startsWith(prefix)) return undefined;\n const route = url.pathname.slice(prefix.length);\n const origin = req.headers.get('origin');\n const sameOrigin = origin !== null && new URL(origin).host === url.host;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n const handle = byName.get(name)?.routes?.[first];\n if (handle === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'GET' && req.method !== 'HEAD' && !sameOrigin)\n return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });\n return await handle(req, context);\n }\n const loc = {\n file: url.searchParams.get('file') ?? '',\n line: Number(url.searchParams.get('line')),\n column: Number(url.searchParams.get('column')),\n };\n if (route === 'history') {\n const plugin = url.searchParams.get('plugin');\n return Response.json(history.list(plugin === null ? undefined : scopeOf(plugin, loc)));\n }\n if (route === 'open') return await open(resolveFile(root, loc.file), loc);\n const handler = routes[route];\n if (handler === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'POST' || !sameOrigin || req.headers.get('content-type')?.startsWith('application/json') !== true)\n return Response.json({ problem: 'edits come from the page, as JSON' }, { status: 403 });\n const body = (await req.json()) as Body;\n return Response.json(await (route === 'read' ? handler(body) : serially(() => handler(body))));\n } catch (e) {\n if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });\n return Response.json({ problem: e instanceof Error ? (e.stack ?? e.message) : String(e) }, { status: 500 });\n }\n };\n}\n\n/** A redirect within the page's origin, to a launcher the dev server answers itself. */\nexport const redirect = (path: string) => new Response(null, { status: 307, headers: { Location: path } });\n\n/**\n * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was\n * served from: a proxy's `x-forwarded-host` before its own.\n */\nexport function nodeMiddleware(\n handle: (req: Request) => Promise<Response | undefined>,\n): (req: IncomingMessage, res: ServerResponse, next: () => void) => void {\n return (req, res, next) => {\n // Before reading the body, which a request for anything else leaves to whoever answers it.\n if (req.url?.includes('/__deictic/') !== true) return next();\n const forwarded = req.headers['x-forwarded-host'];\n const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? 'localhost';\n const headers = new Headers();\n for (const [name, value] of Object.entries(req.headers))\n for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(name, v);\n\n const chunks: Buffer[] = [];\n req.on('data', (chunk: Buffer) => chunks.push(chunk));\n req.on('end', () => {\n const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : Buffer.concat(chunks);\n handle(new Request(`http://${host}${req.url}`, { method: req.method, headers, body }))\n .then(async (response) => {\n if (response === undefined) return next();\n res.statusCode = response.status;\n response.headers.forEach((value, name) => res.setHeader(name, value));\n res.end(Buffer.from(await response.arrayBuffer()));\n })\n .catch((e: unknown) => {\n res.statusCode = 500;\n res.end(e instanceof Error ? e.message : String(e));\n });\n });\n };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,MAAM,OAAO,QAAQ,MAAM,IAAI;CAC/B,MAAM,OAAO,SAAS,MAAM,IAAI;CAEhC,IAAI,SAAS,MAAM,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,GACrG,MAAM,IAAI,QAAQ,GAAG,KAAK,qCAAqC;CACjE,OAAO;AACT;AAEA,SAAgB,WAAW,MAAc,MAAsB;CAC7D,IAAI;EACF,OAAO,aAAa,YAAY,MAAM,IAAI,GAAG,MAAM;CACrD,SAAS,GAAG;EACV,IAAI,aAAa,SAAS,MAAM;EAChC,MAAM,IAAI,QAAQ,cAAc,KAAK,wCAAwC,EAAE,OAAO,EAAE,CAAC;CAC3F;AACF;;;;;AAMA,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,EAAE,MAAM,MAAM,WAAW,OAAO;CACtC,MAAM,OAAO,WAAW,MAAM,IAAI;CAClC,MAAM,QAAQ,WAAW,IAAI;CAC7B,MAAM,SAAS,SAAS,OAAO,MAAM,MAAM;CAC3C,MAAM,EA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ref, nth = 1) {
33
33
  const file = files[nth - 1];
34
34
  if (file === void 0) fail(`Task #${root.id} has ${files.length} recording(s), not a ${nth}th.`);
35
35
  const id = file.name.slice(10, -5);
36
- const replay = new RegExp(`https?://\\S+/replay/${id}`).exec(root.text)?.[0];
36
+ const where = (text) => new RegExp(`https?://\\S+/replay/${id}`).exec(text)?.[0];
37
+ const replay = Object.values(root.labels).map(where).find(Boolean) ?? where(root.text);
37
38
  return {
38
39
  kept: parsed(fetched(root, file.name)),
39
40
  id,
@@ -1 +1 @@
1
- {"version":3,"file":"find.js","names":[],"sources":["../../src/cli/find.ts"],"sourcesContent":["/**\n * Finding what a task carries: a recording or a voice clip, by a task's ID, a recording's ID, a replay URL or a path,\n * kept under a `.deictic/` near here or downloaded from the board. And the tools outside deictic some commands run\n * (ffmpeg, the project's Playwright).\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { Kept } from '#src/plugins/recordings/index.ts';\n\nimport { deicticDirs, download, fail, type Message, task } from './board.ts';\n\nconst TASK = /^#?\\d+$/;\n\nexport interface Found {\n kept: Kept;\n id: string;\n /** Where it replays, where that's known. */\n replay?: string;\n /** The task it's attached to, where it was found by one. */\n task?: Message;\n}\n\nconst parsed = (path: string) => JSON.parse(readFileSync(path, 'utf8')) as Kept;\n\n/** An attachment of a task, written to a temporary folder: its path. */\nfunction fetched(root: Message, name: string): string {\n const file = root.attachments.find((a) => a.name === name);\n if (file === undefined) fail(`Task #${root.id} has no ${name}.`);\n const path = join(mkdtempSync(join(tmpdir(), 'deictic-')), file.name);\n download(file, path);\n return path;\n}\n\n/**\n * A recording, with where it came from. `ref` is a task's ID (its first recording, or the `nth`), a replay or\n * recording URL, a recording's ID kept under a `.deictic/`, or a path.\n */\nexport async function loadRecording(ref: string | undefined, nth = 1): Promise<Found> {\n if (ref === undefined) fail('Name a recording: a task (68), a replay URL, a recording ID or a JSON file.');\n if (TASK.test(ref)) {\n const root = task(ref);\n const files = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const file = files[nth - 1];\n if (file === undefined) fail(`Task #${root.id} has ${files.length} recording(s), not a ${nth}th.`);\n const id = file.name.slice('recording-'.length, -'.json'.length);\n const replay = new RegExp(`https?://\\\\S+/replay/${id}`).exec(root.text)?.[0];\n return { kept: parsed(fetched(root, file.name)), id, replay, task: root };\n }\n if (/^https?:/.test(ref)) {\n const url = new URL(ref);\n const id = url.pathname.split('/').at(-1) ?? '';\n const json = new URL(url.pathname.replace(/\\/(replay|recording)\\/[^/]+$/, `/recording/${id}`), url);\n const res = await fetch(json);\n if (!res.ok) fail(`${json.href}: ${res.status} ${await res.text()}`);\n return { kept: (await res.json()) as Kept, id, replay: new URL(json.pathname.replace(/\\/recording\\//, '/replay/'), url).href };\n }\n if (existsSync(ref)) return { kept: parsed(ref), id: ref.replace(/^.*[\\\\/]|\\.json$/g, '') };\n for (const dir of deicticDirs()) {\n const path = join(dir, 'recordings', `${ref}.json`);\n if (existsSync(path)) return { kept: parsed(path), id: ref };\n }\n return fail(`No recording ${ref} in ${deicticDirs().join(', ') || 'any .deictic/ near here'}: name its task or replay URL instead.`);\n}\n\n/** A voice clip kept under a `.deictic/` near here, by its ID. */\nfunction keptClip(id: string): string | undefined {\n for (const dir of deicticDirs()) {\n const voice = join(dir, 'voice');\n const name = existsSync(voice) ? readdirSync(voice).find((f) => f.startsWith(`${id}.`)) : undefined;\n if (name !== undefined) return join(voice, name);\n }\n return undefined;\n}\n\n/** A voice clip's audio as a file: kept under a `.deictic/`, or downloaded from `from`. */\nfunction voiceFile(id: string, from?: Message): string {\n const kept = keptClip(id);\n if (kept !== undefined) return kept;\n const file = from?.attachments.find((a) => a.name.startsWith(`voice-${id}.`));\n if (from === undefined || file === undefined) fail(`No voice clip ${id} here${from ? ` or on task #${from.id}` : ''}.`);\n return fetched(from, file.name);\n}\n\nexport interface Clip {\n id: string;\n file: string;\n /** Where it starts in its recording, or 0 for a voice note on its own. */\n at: number;\n recording?: string;\n}\n\n/**\n * The voice clips `ref` names: a task (every recording's clips and its voice notes), a recording as `loadRecording`\n * takes one, or a clip's ID.\n */\nexport async function voiceClips(ref: string | undefined): Promise<Clip[]> {\n if (ref === undefined) fail('Name a task, a recording or a voice clip.');\n const clips: Clip[] = [];\n if (TASK.test(ref)) {\n const root = task(ref);\n const recordings = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const inRecordings = new Set<string>();\n for (let n = 1; n <= recordings.length; n++) {\n const { kept, id } = await loadRecording(ref, n);\n for (const c of kept.voice ?? []) {\n inRecordings.add(c.id);\n clips.push({ id: c.id, file: voiceFile(c.id, root), at: c.at, recording: id });\n }\n }\n for (const a of root.attachments) {\n const id = /^voice-(.+)\\.\\w+$/.exec(a.name)?.[1];\n if (id !== undefined && !inRecordings.has(id)) clips.push({ id, file: voiceFile(id, root), at: 0 });\n }\n } else if (!/^https?:/.test(ref) && !existsSync(ref) && keptClip(ref) !== undefined) {\n clips.push({ id: ref, file: voiceFile(ref), at: 0 });\n } else {\n const { kept, id } = await loadRecording(ref);\n for (const c of kept.voice ?? []) clips.push({ id: c.id, file: voiceFile(c.id), at: c.at, recording: id });\n }\n if (clips.length === 0) fail(`No voice on ${ref}.`);\n return clips;\n}\n\n/** Runs ffmpeg, which reads what MediaRecorder makes, and answers its log (stderr) and what it wrote to stdout. */\nexport function ffmpeg(args: string[]): { stdout: Buffer; log: string } {\n const run = spawnSync('ffmpeg', ['-hide_banner', '-nostats', ...args], { maxBuffer: 1 << 30 });\n if (run.error) fail('Needs ffmpeg on the PATH (https://ffmpeg.org/download.html).');\n return { stdout: run.stdout, log: run.stderr.toString('utf8') };\n}\n\n/** The project's own copy of a package deictic doesn't bring (Playwright, either of its names), from here. */\nexport async function fromProject<T>(...names: string[]): Promise<T> {\n const project = createRequire(join(process.cwd(), 'package.json'));\n for (const name of names) {\n try {\n return (await import(pathToFileURL(project.resolve(name)).href)) as T;\n } catch {\n // Not this one: the next name.\n }\n }\n return fail(`Needs ${names.join(' or ')} in the project: npm install -D ${names[0]}`);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,OAAO;AAWb,MAAM,UAAU,SAAiB,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC;;AAGtE,SAAS,QAAQ,MAAe,MAAsB;CACpD,MAAM,OAAO,KAAK,YAAY,MAAM,MAAM,EAAE,SAAS,IAAI;CACzD,IAAI,SAAS,KAAA,GAAW,KAAK,SAAS,KAAK,GAAG,UAAU,KAAK,EAAE;CAC/D,MAAM,OAAO,KAAK,YAAY,KAAK,OAAO,GAAG,UAAU,CAAC,GAAG,KAAK,IAAI;CACpE,SAAS,MAAM,IAAI;CACnB,OAAO;AACT;;;;;AAMA,eAAsB,cAAc,KAAyB,MAAM,GAAmB;CACpF,IAAI,QAAQ,KAAA,GAAW,KAAK,6EAA6E;CACzG,IAAI,KAAK,KAAK,GAAG,GAAG;EAClB,MAAM,OAAO,KAAK,GAAG;EACrB,MAAM,QAAQ,KAAK,YAAY,QAAQ,MAAM,uBAAuB,KAAK,EAAE,IAAI,CAAC;EAChF,MAAM,OAAO,MAAM,MAAM;EACzB,IAAI,SAAS,KAAA,GAAW,KAAK,SAAS,KAAK,GAAG,OAAO,MAAM,OAAO,uBAAuB,IAAI,IAAI;EACjG,MAAM,KAAK,KAAK,KAAK,MAAM,IAAqB,EAAe;EAC/D,MAAM,SAAS,IAAI,OAAO,wBAAwB,IAAI,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,GAAG;EAC1E,OAAO;GAAE,MAAM,OAAO,QAAQ,MAAM,KAAK,IAAI,CAAC;GAAG;GAAI;GAAQ,MAAM;EAAK;CAC1E;CACA,IAAI,WAAW,KAAK,GAAG,GAAG;EACxB,MAAM,MAAM,IAAI,IAAI,GAAG;EACvB,MAAM,KAAK,IAAI,SAAS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,GAAG;EAC5C,KAAK,MAAM,KAAK,KAAK,SAAS,CAAC,GAAG,MAAM,KAAK;GAAE,IAAI,EAAE;GAAI,MAAM,UAAU,EAAE,EAAE;GAAG,IAAI,EAAE;GAAI,WAAW;EAAG,CAAC;CAC3G;CACA,IAAI,MAAM,WAAW,GAAG,KAAK,eAAe,IAAI,EAAE;CAClD,OAAO;AACT;;AAGA,SAAgB,OAAO,MAAiD;CACtE,MAAM,MAAM,UAAU,UAAU;EAAC;EAAgB;EAAY,GAAG;CAAI,GAAG,EAAE,WAAW,KAAK,GAAG,CAAC;CAC7F,IAAI,IAAI,OAAO,KAAK,8DAA8D;CAClF,OAAO;EAAE,QAAQ,IAAI;EAAQ,KAAK,IAAI,OAAO,SAAS,MAAM;CAAE;AAChE;;AAGA,eAAsB,YAAe,GAAG,OAA6B;CACnE,MAAM,UAAU,cAAc,KAAK,QAAQ,IAAI,GAAG,cAAc,CAAC;CACjE,KAAK,MAAM,QAAQ,OACjB,IAAI;EACF,OAAQ,MAAM,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAC,CAAC,CAAC;CAC5D,QAAQ,CAER;CAEF,OAAO,KAAK,SAAS,MAAM,KAAK,MAAM,EAAE,kCAAkC,MAAM,IAAI;AACtF"}
1
+ {"version":3,"file":"find.js","names":[],"sources":["../../src/cli/find.ts"],"sourcesContent":["/**\n * Finding what a task carries: a recording or a voice clip, by a task's ID, a recording's ID, a replay URL or a path,\n * kept under a `.deictic/` near here or downloaded from the board. And the tools outside deictic some commands run\n * (ffmpeg, the project's Playwright).\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { Kept } from '#src/plugins/recordings/index.ts';\n\nimport { deicticDirs, download, fail, type Message, task } from './board.ts';\n\nconst TASK = /^#?\\d+$/;\n\nexport interface Found {\n kept: Kept;\n id: string;\n /** Where it replays, where that's known. */\n replay?: string;\n /** The task it's attached to, where it was found by one. */\n task?: Message;\n}\n\nconst parsed = (path: string) => JSON.parse(readFileSync(path, 'utf8')) as Kept;\n\n/** An attachment of a task, written to a temporary folder: its path. */\nfunction fetched(root: Message, name: string): string {\n const file = root.attachments.find((a) => a.name === name);\n if (file === undefined) fail(`Task #${root.id} has no ${name}.`);\n const path = join(mkdtempSync(join(tmpdir(), 'deictic-')), file.name);\n download(file, path);\n return path;\n}\n\n/**\n * A recording, with where it came from. `ref` is a task's ID (its first recording, or the `nth`), a replay or\n * recording URL, a recording's ID kept under a `.deictic/`, or a path.\n */\nexport async function loadRecording(ref: string | undefined, nth = 1): Promise<Found> {\n if (ref === undefined) fail('Name a recording: a task (68), a replay URL, a recording ID or a JSON file.');\n if (TASK.test(ref)) {\n const root = task(ref);\n const files = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const file = files[nth - 1];\n if (file === undefined) fail(`Task #${root.id} has ${files.length} recording(s), not a ${nth}th.`);\n const id = file.name.slice('recording-'.length, -'.json'.length);\n // Its `deictic.recording.N.replay` label, or in the text of a task added before that was a label.\n const where = (text: string) => new RegExp(`https?://\\\\S+/replay/${id}`).exec(text)?.[0];\n const replay = Object.values(root.labels).map(where).find(Boolean) ?? where(root.text);\n return { kept: parsed(fetched(root, file.name)), id, replay, task: root };\n }\n if (/^https?:/.test(ref)) {\n const url = new URL(ref);\n const id = url.pathname.split('/').at(-1) ?? '';\n const json = new URL(url.pathname.replace(/\\/(replay|recording)\\/[^/]+$/, `/recording/${id}`), url);\n const res = await fetch(json);\n if (!res.ok) fail(`${json.href}: ${res.status} ${await res.text()}`);\n return { kept: (await res.json()) as Kept, id, replay: new URL(json.pathname.replace(/\\/recording\\//, '/replay/'), url).href };\n }\n if (existsSync(ref)) return { kept: parsed(ref), id: ref.replace(/^.*[\\\\/]|\\.json$/g, '') };\n for (const dir of deicticDirs()) {\n const path = join(dir, 'recordings', `${ref}.json`);\n if (existsSync(path)) return { kept: parsed(path), id: ref };\n }\n return fail(`No recording ${ref} in ${deicticDirs().join(', ') || 'any .deictic/ near here'}: name its task or replay URL instead.`);\n}\n\n/** A voice clip kept under a `.deictic/` near here, by its ID. */\nfunction keptClip(id: string): string | undefined {\n for (const dir of deicticDirs()) {\n const voice = join(dir, 'voice');\n const name = existsSync(voice) ? readdirSync(voice).find((f) => f.startsWith(`${id}.`)) : undefined;\n if (name !== undefined) return join(voice, name);\n }\n return undefined;\n}\n\n/** A voice clip's audio as a file: kept under a `.deictic/`, or downloaded from `from`. */\nfunction voiceFile(id: string, from?: Message): string {\n const kept = keptClip(id);\n if (kept !== undefined) return kept;\n const file = from?.attachments.find((a) => a.name.startsWith(`voice-${id}.`));\n if (from === undefined || file === undefined) fail(`No voice clip ${id} here${from ? ` or on task #${from.id}` : ''}.`);\n return fetched(from, file.name);\n}\n\nexport interface Clip {\n id: string;\n file: string;\n /** Where it starts in its recording, or 0 for a voice note on its own. */\n at: number;\n recording?: string;\n}\n\n/**\n * The voice clips `ref` names: a task (every recording's clips and its voice notes), a recording as `loadRecording`\n * takes one, or a clip's ID.\n */\nexport async function voiceClips(ref: string | undefined): Promise<Clip[]> {\n if (ref === undefined) fail('Name a task, a recording or a voice clip.');\n const clips: Clip[] = [];\n if (TASK.test(ref)) {\n const root = task(ref);\n const recordings = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const inRecordings = new Set<string>();\n for (let n = 1; n <= recordings.length; n++) {\n const { kept, id } = await loadRecording(ref, n);\n for (const c of kept.voice ?? []) {\n inRecordings.add(c.id);\n clips.push({ id: c.id, file: voiceFile(c.id, root), at: c.at, recording: id });\n }\n }\n for (const a of root.attachments) {\n const id = /^voice-(.+)\\.\\w+$/.exec(a.name)?.[1];\n if (id !== undefined && !inRecordings.has(id)) clips.push({ id, file: voiceFile(id, root), at: 0 });\n }\n } else if (!/^https?:/.test(ref) && !existsSync(ref) && keptClip(ref) !== undefined) {\n clips.push({ id: ref, file: voiceFile(ref), at: 0 });\n } else {\n const { kept, id } = await loadRecording(ref);\n for (const c of kept.voice ?? []) clips.push({ id: c.id, file: voiceFile(c.id), at: c.at, recording: id });\n }\n if (clips.length === 0) fail(`No voice on ${ref}.`);\n return clips;\n}\n\n/** Runs ffmpeg, which reads what MediaRecorder makes, and answers its log (stderr) and what it wrote to stdout. */\nexport function ffmpeg(args: string[]): { stdout: Buffer; log: string } {\n const run = spawnSync('ffmpeg', ['-hide_banner', '-nostats', ...args], { maxBuffer: 1 << 30 });\n if (run.error) fail('Needs ffmpeg on the PATH (https://ffmpeg.org/download.html).');\n return { stdout: run.stdout, log: run.stderr.toString('utf8') };\n}\n\n/** The project's own copy of a package deictic doesn't bring (Playwright, either of its names), from here. */\nexport async function fromProject<T>(...names: string[]): Promise<T> {\n const project = createRequire(join(process.cwd(), 'package.json'));\n for (const name of names) {\n try {\n return (await import(pathToFileURL(project.resolve(name)).href)) as T;\n } catch {\n // Not this one: the next name.\n }\n }\n return fail(`Needs ${names.join(' or ')} in the project: npm install -D ${names[0]}`);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,OAAO;AAWb,MAAM,UAAU,SAAiB,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC;;AAGtE,SAAS,QAAQ,MAAe,MAAsB;CACpD,MAAM,OAAO,KAAK,YAAY,MAAM,MAAM,EAAE,SAAS,IAAI;CACzD,IAAI,SAAS,KAAA,GAAW,KAAK,SAAS,KAAK,GAAG,UAAU,KAAK,EAAE;CAC/D,MAAM,OAAO,KAAK,YAAY,KAAK,OAAO,GAAG,UAAU,CAAC,GAAG,KAAK,IAAI;CACpE,SAAS,MAAM,IAAI;CACnB,OAAO;AACT;;;;;AAMA,eAAsB,cAAc,KAAyB,MAAM,GAAmB;CACpF,IAAI,QAAQ,KAAA,GAAW,KAAK,6EAA6E;CACzG,IAAI,KAAK,KAAK,GAAG,GAAG;EAClB,MAAM,OAAO,KAAK,GAAG;EACr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AAK,MAAM,QAAQ,OACjB,IAAI;EACF,OAAQ,MAAM,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAC,CAAC,CAAC;CAC5D,QAAQ,CAER;CAEF,OAAO,KAAK,SAAS,MAAM,KAAK,MAAM,EAAE,kCAAkC,MAAM,IAAI;AACtF"}
@@ -108,10 +108,14 @@ interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = un
108
108
  routes?: {
109
109
  [route: string]: Route;
110
110
  };
111
- /** The model its panel shows for an element. Without it, the panel gets none. */
112
- read?(source: Source, target: Target): Maybe<Model>;
113
- /** Text edits for deictic to write, or a change the plugin made itself. */
114
- apply?(source: Source, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;
111
+ /**
112
+ * The model its panel shows for an element. Without it, the panel gets none. `source` is a `Refusal` where the
113
+ * element isn't to be found in its file (it doesn't parse, or the page runs other code than it has): throw it where
114
+ * the plugin needs the source, or go on without it, as a task does.
115
+ */
116
+ read?(source: Source | Refusal, target: Target): Maybe<Model>;
117
+ /** Text edits for deictic to write, which it refuses without the source, or a change the plugin made itself. */
118
+ apply?(source: Source | Refusal, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;
115
119
  /**
116
120
  * Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may
117
121
  * answer what the next redo needs, where that differs (what it put back has a new ID).
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/shortcut.ts","../../src/index.ts"],"mappings":";;;;;;;;;;KAUY;UAEK;;EAEf,YAAY;;EAEZ;;;UCYe;EACf;EACA;EACA;;;UAIe;EACf,KAAK;EACL;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;;EAEf;EACA;;EAEA,SAAS;;EAET,SAAS;;EAET,KAAK;;;;;;;KAQK,cAAc,SAAS,YAAY,WAAW,QAAQ;;cAGrD,gBAAgB;EAClB;;;;;;UAOM,KAAK;EACpB,MAAM;;KAGH,MAAM,KAAK,IAAI,QAAQ;;;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7D,aAAa,OAAO,IAAI,QAAQ,SACvC,aAAa,OAAO,IAAI,QAAQ;UAElB;;EAEf;;EAEA,MAAM;;EAEN;;EAEA,MAAM,qBAAqB,MAAM,SAAS,MAAM,YAAY;;EAE5D,UAAU,eAAe,OAAO,gBAAgB,QAAQ;;;;;;EAMxD,OAAO,gBAAgB,SAAS;;;;;EAKhC,WAAW,OAAO,gBAAgB,UAAU;IAAsB;;;;KAIxD;;EAEV;;EAEA,UAAU;;EACL;EAAe;;EAAkB;EAAc;;EAAkB;EAAe;;UAEtE;EACf;EACA;EACA;;UAGe;;EAEf;;EAEA,OAAO;;UAGQ,aAAa,OAAO,YAAY;;;;;;EAM/C,SAAS;;;;;EAKT,UAAU;;EAEV,UAAU;EACV,QAAQ;EACR,OAAO;;EAEP,MAAM,IAAI,KAAK,QAAQ;EACvB;;;;;;EAMA,UAAU,QAAQ;;;;;;;;;EASlB,OAAO,GAAG,gBAAgB,YAAY,QAAQ;;EAE9C,UAAU;;;UAIK;EACf;EACA;;EAEA;;UAGe,aAAa,iBAAiB,cAAc;;EAE3D;;EAEA;;;;;EAKA,OAAO,SAAS,gBAAgB;;;;;;EAMhC,QAAQ,SAAS,gBAAgB;;EAEjC,SAAS,OAAO,aAAa,SAAS,aAAa,OAAO;;cAG/C,qBAAsB,OAAO,IAAI,eAAa,QAAU,aAAa,OAAO,IAAI,SAAO,aAAa,OAAO,IAAI"}
@@ -73,6 +73,8 @@ interface Task {
73
73
  open: boolean;
74
74
  /** Its page on the board, when there's one to link to. */
75
75
  link?: string;
76
+ /** What was attached to it but not kept by the time it was sent, so it went without: `a screenshot`. */
77
+ dropped?: string;
76
78
  /**
77
79
  * Where it was added, where that isn't the element's place: for one of `tasks`, where the element was before
78
80
  * it moved; for one of `elsewhere`, the element it's about.
@@ -1 +1 @@
1
- {"version":3,"file":"index7.d.ts","names":[],"sources":["../../src/plugins/tasks/local.ts","../../src/plugins/tasks/index.ts"],"mappings":";;;UAkBiB;;;;;EAKf;;EA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;;UAGI;EACf;;EAEA;;EAEA;EACA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;EAKA,KAAK;;;UAIU;EACf;EACA;EACA;;UAGe;EACf;;EAEA;;EAEA,OAAO;;EAEP,WAAW;;;;;;;EAOX;;;;;;KAOU,SAAS;EAAO;EAAc;;EAAmB;;;UAG5C;EACf;;EAEA;EACA;IAAY;IAAe;;;;;;EAK3B;IAAY;IAAc;;;EAE1B;;;;;;;EAOA;;EAEA;;;;;;EAMA;IAAgB;IAAY,KAAK;IAAK;IAAoB,QAAQ;;;;;;EAKlE;IAAe;IAAY;IAAkB;IAAgB;;;EAE7D;IAAU;IAAY;;;EAEtB,cAAc;;;;;;UAOC;EACf;;EAEA;EACA;EACA;;EAEA,QAAQ;;EAER;;EAEA;IAAY;IAAqB;IAAoB;IAAe;;;;UAIrD;EACf;EACA;;UAGe;EACf;EACA;EACA;EACA,QAAQ;;EAER;;;UAIe;EACf;EACA;EACA;EACA;;;;;;UAOe,gBAAgB;EAC/B;;;KAIU,OAAO,QAAQ,SAAS;iBAUpB,MAAM,UAAS,iCAAiB,aAAA,OAAA,QAAA"}
@@ -193,7 +193,7 @@ const SETUPS = {
193
193
  name: "deictic",
194
194
  list: "plugins",
195
195
  value: `deictic(${PLUGINS})`,
196
- snippet: `export default defineConfig({ plugins: [react(), deictic(${PLUGINS})] });`
196
+ snippet: `export default defineConfig({ plugins: [deictic(${PLUGINS}), react()] });`
197
197
  },
198
198
  rspack: {
199
199
  files: extensions("rspack.config"),
@@ -294,7 +294,7 @@ function exportedOf(program) {
294
294
  }
295
295
  /**
296
296
  * The config with deictic added, or nothing where it can't tell where: deictic's import beside the config's, and its
297
- * plugin last in the list (`plugins`, `integrations`), or the config wrapped (Next's). Written in the config's quotes,
297
+ * plugin first in the list (`plugins`, `integrations`), as its marks count lines and columns in the code it's given, or the config wrapped (Next's). Written in the config's quotes,
298
298
  * semicolons and line endings.
299
299
  */
300
300
  function addToConfig(bundler, file, code) {
@@ -303,33 +303,35 @@ function addToConfig(bundler, file, code) {
303
303
  if (errors.length > 0) return void 0;
304
304
  const exported = exportedOf(program);
305
305
  if (exported === void 0) return void 0;
306
- const eol = eolOf(code);
307
306
  const out = new MagicString(code);
308
307
  if (setup.wrap) {
309
308
  out.appendLeft(exported.value.start, `${setup.name}(`);
310
309
  out.appendRight(exported.value.end, `, ${setup.value})`);
311
310
  } else {
312
311
  const object = objectOf(exported.value, program);
313
- if (object === void 0 || !addTo(out, code, object, setup.list, setup.value, eol)) return void 0;
312
+ if (object === void 0 || !addTo(out, code, object, setup.list, setup.value)) return void 0;
314
313
  }
315
314
  addImports(out, program, code, [["{ recommended }", "deictic/recommended"], [`{ ${setup.name} }`, setup.from]], exported.commonjs);
316
315
  return out.toString();
317
316
  }
318
- /** Adds `value` last in the object's array `list`, or the list with it, as the object is laid out. False where `list` isn't an array. */
319
- function addTo(out, code, object, list, value, eol) {
317
+ /**
318
+ * Adds `value` first in the object's array `list`, or the list with it, as the object is laid out. False where `list`
319
+ * isn't an array. First, since a plugin before deictic's that changes a module (both `pre` under Vite) leaves the
320
+ * page's marks pointing at its code, not the file.
321
+ */
322
+ function addTo(out, code, object, list, value) {
320
323
  const property = object.properties.find((p) => p.type === "Property" && !p.computed && (p.key.type === "Identifier" && p.key.name === list || p.key.type === "Literal" && p.key.value === list));
321
324
  if (property !== void 0) {
322
325
  if (property.type !== "Property") return false;
323
326
  let array = property.value;
324
327
  while (array.type === "TSAsExpression" || array.type === "TSSatisfiesExpression") array = array.expression;
325
328
  if (array.type !== "ArrayExpression") return false;
326
- const last = array.elements.findLast((e) => e !== null);
327
- if (last == null) {
329
+ const first = array.elements.find((e) => e !== null);
330
+ if (first == null) {
328
331
  out.appendLeft(array.start + 1, value);
329
332
  return true;
330
333
  }
331
- const multiline = code.slice(array.start, array.end).includes("\n");
332
- out.appendLeft(last.end, multiline ? `,${eol}${indentAt(code, last.start)}${value}` : `, ${value}`);
334
+ addFirst(out, code, array.start, first, value);
333
335
  return true;
334
336
  }
335
337
  addFirst(out, code, object.start, object.properties[0], `${list}: [${value}]`);