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 +15 -8
- package/dist/shared/endpoints.js +34 -8
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/find.js +2 -1
- package/dist/shared/find.js.map +1 -1
- package/dist/shared/index.d.ts +8 -4
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +2 -0
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/init.js +12 -10
- package/dist/shared/init.js.map +1 -1
- package/dist/shared/packages.js +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +36 -0
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +108 -114
- package/dist/shared/tasks.js.map +1 -1
- package/dist/tailwind/index.js +6 -2
- package/dist/tailwind/index.js.map +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +4 -5
- package/dist/tasks/client.js.map +1 -1
- package/package.json +1 -1
- package/skills/deictic/references/tasks.md +6 -5
- package/src/cli/find.ts +3 -1
- package/src/cli/init.ts +13 -11
- package/src/cli/task.ts +43 -1
- package/src/index.ts +8 -4
- package/src/plugins/tailwind/index.ts +6 -2
- package/src/plugins/tasks/client.ts +4 -5
- package/src/plugins/tasks/index.ts +113 -124
- package/src/tools/endpoints.ts +18 -7
- package/src/tools/source.ts +25 -5
package/dist/shared/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","names":[],"sources":["../../src/cli/edit.ts","../../src/cli/bun.ts","../../src/cli/init.ts"],"sourcesContent":["/**\n * Editing a project's own source the way it's written: its quotes, semicolons, line endings and indentation. What\n * `init` adds to a bundler's config and to a Bun server goes through here.\n */\nimport type MagicString from 'magic-string';\nimport type { Program } from 'oxc-parser';\n\n/** The file's line ending. */\nexport const eolOf = (code: string) => (code.includes('\\r\\n') ? '\\r\\n' : '\\n');\n\n/** The whitespace a line starts with, for the line `offset` is on. */\nexport function indentAt(code: string, offset: number): string {\n const start = code.lastIndexOf('\\n', offset - 1) + 1;\n return /^[ \\t]*/.exec(code.slice(start))![0];\n}\n\n/**\n * Adds import lines after the module's last import (or `require`, in CommonJS), or at its top: written in the quotes\n * and semicolons of its first import. Each line is `[what, from]`: `import ${what} from '${from}'`, or as a `require`.\n */\nexport function addImports(out: MagicString, program: Program, code: string, lines: [string, string][], commonjs = false): void {\n const eol = eolOf(code);\n const imports = program.body.filter((s) => s.type === 'ImportDeclaration');\n const first = imports[0];\n const quote = first === undefined ? \"'\" : code[first.source.start]!;\n const semi = first === undefined || code.slice(first.start, first.end).trimEnd().endsWith(';') ? ';' : '';\n const q = (s: string) => `${quote}${s}${quote}`;\n const text = lines\n .map(([what, from]) => (commonjs ? `const ${what} = require(${q(from)})${semi}` : `import ${what} from ${q(from)}${semi}`))\n .join(eol);\n const after = imports.at(-1) ?? requiresOf(program).at(-1);\n if (after === undefined) out.prepend(`${text}${eol}${eol}`);\n else out.appendLeft(after.end, `${eol}${text}`);\n}\n\n/** The top-level `const … = require(…)` statements of a CommonJS module, to put new ones after. */\nfunction requiresOf(program: Program) {\n return program.body.filter(\n (s) =>\n s.type === 'VariableDeclaration' &&\n s.declarations.some(\n (d) => d.init?.type === 'CallExpression' && d.init.callee.type === 'Identifier' && d.init.callee.name === 'require',\n ),\n );\n}\n\n/** Inserts `text` as the first property of the object literal that starts at `open` (its `{`), as the object is laid out. */\nexport function addFirst(out: MagicString, code: string, open: number, first: { start: number } | undefined, text: string): void {\n const eol = eolOf(code);\n if (first === undefined) {\n out.appendLeft(open + 1, ` ${text} `);\n return;\n }\n const multiline = code.slice(open, first.start).includes('\\n');\n out.appendLeft(first.start, multiline ? `${text},${eol}${indentAt(code, first.start)}` : `${text}, `);\n}\n","/**\n * `init` for Bun's own dev server: `Bun.serve` with HTML imports, which bundles the page with the plugins bunfig.toml\n * names. Only that: a Bun project that runs Vite, Next.js or another bundler is that bundler's, and one with no HTML\n * imports has no page of Bun's for deictic to be in. Three steps, as the API has them: the plugin's module, bunfig's\n * `[serve.static] plugins`, and its routes spread into `Bun.serve`'s.\n */\nimport { readdirSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\n\nimport MagicString from 'magic-string';\nimport { type CallExpression, parseSync, Visitor } from 'oxc-parser';\n\nimport { addFirst, addImports, eolOf } from './edit.ts';\n\n/** The plugin's module, from the root, which bunfig names and the server imports. */\nexport const MODULE = 'deictic.plugin.ts';\n\nexport const PLUGIN = `import { deictic } from 'deictic/bun';\nimport { recommended } from 'deictic/recommended';\n\n// One module for both: bunfig.toml names it as the dev server's bundler plugin, and the server spreads its routes,\n// deictic's endpoints, into its own.\nexport default deictic({ plugins: recommended() });\n`;\n\nconst SOURCE = /\\.[cm]?[jt]sx?$/;\nconst SKIP = new Set(['node_modules', 'dist', 'build', 'out']);\nconst SERVE = /\\bBun\\.serve\\s*\\(/;\nconst HTML = /\\bfrom\\s*['\"][^'\"]+\\.html['\"]/;\n\n/**\n * The module that serves the page with Bun's bundler: it calls `Bun.serve` and imports an HTML file. Looked for under\n * the root, not in dependencies, builds or dot folders, a few folders deep.\n */\nexport function serverOf(root: string): string | undefined {\n const walk = (dir: string, depth: number): string | undefined => {\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return undefined;\n }\n for (const e of entries) {\n if (!e.isFile() || !SOURCE.test(e.name)) continue;\n const path = join(dir, e.name);\n const code = readFileSync(path, 'utf8');\n if (SERVE.test(code) && HTML.test(code)) return path;\n }\n if (depth === 0) return undefined;\n for (const e of entries) {\n if (!e.isDirectory() || e.name.startsWith('.') || SKIP.has(e.name)) continue;\n const found = walk(join(dir, e.name), depth - 1);\n if (found !== undefined) return found;\n }\n return undefined;\n };\n return walk(root, 3);\n}\n\n/**\n * bunfig.toml with the plugin's module first in `[serve.static] plugins` (first, so it sees the source as written),\n * made where there's none; unchanged where it's there already, and nothing where bunfig says it another way (a dotted\n * key, an inline table) and it can't tell where.\n */\nexport function addToBunfig(text: string | undefined, entry = `./${MODULE}`): string | undefined {\n const quoted = JSON.stringify(entry);\n if (text === undefined) return `[serve.static]\\nplugins = [${quoted}]\\n`;\n if (text.includes(entry)) return text;\n if (/serve\\.static\\.|static\\s*=\\s*\\{/.test(text)) return undefined;\n const eol = eolOf(text);\n const header = /^[ \\t]*\\[serve\\.static\\][ \\t]*(#.*)?$/m.exec(text);\n if (header === null)\n return `${text}${text === '' || text.endsWith('\\n') ? '' : eol}${eol}[serve.static]${eol}plugins = [${quoted}]${eol}`;\n const bodyStart = header.index + header[0].length;\n const next = /^[ \\t]*\\[/m.exec(text.slice(bodyStart));\n const body = text.slice(bodyStart, next === null ? text.length : bodyStart + next.index);\n const list = /^[ \\t]*plugins[ \\t]*=[ \\t]*\\[/m.exec(body);\n if (list === null) return `${text.slice(0, bodyStart)}${eol}plugins = [${quoted}]${text.slice(bodyStart)}`;\n const open = bodyStart + list.index + list[0].length;\n const rest = text.slice(open);\n const empty = /^\\s*\\]/.test(rest);\n const lineBreak = /^[ \\t]*\\r?\\n([ \\t]*)/.exec(rest);\n if (empty) return `${text.slice(0, open)}${quoted}${rest.trimStart()}`;\n if (lineBreak !== null) return `${text.slice(0, open)}${eol}${lineBreak[1]}${quoted},${rest}`;\n return `${text.slice(0, open)}${quoted}, ${rest.trimStart()}`;\n}\n\n/**\n * The server with the plugin's routes first in `Bun.serve`'s `routes`, or `routes` with them where it has none, and\n * the module imported: nothing where `Bun.serve` isn't given an object it can see, or its routes aren't one.\n */\nexport function addToServer(file: string, code: string, root: string): string | undefined {\n const { program, errors } = parseSync(file, code, { preserveParens: false });\n if (errors.length > 0) return undefined;\n const calls: CallExpression[] = [];\n new Visitor({\n CallExpression(node) {\n const { callee } = node;\n if (\n callee.type === 'MemberExpression' &&\n callee.object.type === 'Identifier' &&\n callee.object.name === 'Bun' &&\n callee.property.type === 'Identifier' &&\n callee.property.name === 'serve'\n )\n calls.push(node);\n },\n }).visit(program);\n const options = calls.length === 1 ? calls[0]!.arguments[0] : undefined;\n if (options?.type !== 'ObjectExpression') return undefined;\n\n // `tools`, as the API names it, unless the module has a `tools` of its own.\n const name = /\\btools\\b/.test(code) ? 'deicticTools' : 'tools';\n const out = new MagicString(code);\n const routes = options.properties.find(\n (p) => p.type === 'Property' && !p.computed && p.key.type === 'Identifier' && p.key.name === 'routes',\n );\n if (routes === undefined) {\n addFirst(out, code, options.start, options.properties[0], `routes: { ...${name}.routes }`);\n } else {\n if (routes.type !== 'Property' || routes.value.type !== 'ObjectExpression') return undefined;\n addFirst(out, code, routes.value.start, routes.value.properties[0], `...${name}.routes`);\n }\n const from = relative(dirname(file), join(root, MODULE)).replaceAll('\\\\', '/');\n addImports(out, program, code, [[name, from.startsWith('.') ? from : `./${from}`]]);\n return out.toString();\n}\n\n/** What to add by hand, for a server or a bunfig it can't edit. */\nexport const BY_HAND = {\n bunfig: `[serve.static]\\nplugins = [\"./${MODULE}\"]`,\n server: `import tools from './${MODULE}';\\nBun.serve({ routes: { ...tools.routes, '/*': index } });`,\n};\n","/**\n * `deictic init`: the recommended setup in a project, in one step. It installs deictic and what the recommended\n * plugins import, with the project's package manager and as the project's own dev dependencies (deictic, the\n * page's bundle and the skill all find them from the project, so they can't come in through another package), adds\n * deictic to the bundler's config where it can find the place, and offers the agent skill.\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\nimport { createInterface } from 'node:readline/promises';\n\nimport MagicString from 'magic-string';\nimport { type Expression, type ObjectExpression, parseSync, type Program } from 'oxc-parser';\n\nimport { recommended } from '#src/plugins/recommended/index.ts';\n\nimport { installCommand, packageManager, readJson, runnerOf } from '#src/tools/packages.ts';\n\nimport { fail } from './board.ts';\nimport { addToBunfig, addToServer, BY_HAND, MODULE, PLUGIN, serverOf } from './bun.ts';\nimport { addFirst, addImports, eolOf, indentAt } from './edit.ts';\n\nexport type Bundler = 'next' | 'astro' | 'vite' | 'rspack' | 'webpack' | 'bun';\n\ninterface Setup {\n /** The config files it looks for, in order. */\n files: string[];\n /** The module deictic's integration comes from, and its name there. */\n from: string;\n name: string;\n /** What goes in the config: in its `list`, or wrapped around the whole of it with `wrap`. */\n list?: string;\n value: string;\n wrap?: boolean;\n /** The snippet for a config it can't edit. */\n snippet: string;\n}\n\nconst extensions = (base: string) => ['ts', 'mts', 'js', 'mjs', 'cts', 'cjs'].map((e) => `${base}.${e}`);\nconst PLUGINS = '{ plugins: recommended() }';\n\nconst SETUPS: Record<Exclude<Bundler, 'bun'>, Setup> = {\n next: {\n files: extensions('next.config'),\n from: 'deictic/next',\n name: 'withDeictic',\n value: PLUGINS,\n wrap: true,\n snippet: `export default withDeictic(nextConfig, ${PLUGINS});`,\n },\n astro: {\n files: extensions('astro.config'),\n from: 'deictic/astro',\n name: 'deictic',\n list: 'integrations',\n value: `deictic(${PLUGINS})`,\n snippet: `export default defineConfig({ integrations: [deictic(${PLUGINS})] });`,\n },\n vite: {\n files: extensions('vite.config'),\n from: 'deictic/vite',\n name: 'deictic',\n list: 'plugins',\n value: `deictic(${PLUGINS})`,\n snippet: `export default defineConfig({ plugins: [react(), deictic(${PLUGINS})] });`,\n },\n rspack: {\n files: extensions('rspack.config'),\n from: 'deictic/webpack',\n name: 'DeicticPlugin',\n list: 'plugins',\n value: `new DeicticPlugin(${PLUGINS})`,\n snippet: `export default { plugins: [new DeicticPlugin(${PLUGINS})] };`,\n },\n webpack: {\n files: extensions('webpack.config'),\n from: 'deictic/webpack',\n name: 'DeicticPlugin',\n list: 'plugins',\n value: `new DeicticPlugin(${PLUGINS})`,\n snippet: `export default { plugins: [new DeicticPlugin(${PLUGINS})] };`,\n },\n};\n\n/** The project's root: the nearest folder with a package.json, from `dir` up. */\nexport function rootOf(dir: string): string | undefined {\n for (let at = dir; ; at = dirname(at)) {\n if (existsSync(join(at, 'package.json'))) return at;\n if (dirname(at) === at) return undefined;\n }\n}\n\n/** The project's dependencies and dev dependencies, by name. */\nfunction dependenciesOf(root: string): Set<string> {\n const manifest = readJson(join(root, 'package.json')) ?? {};\n return new Set([manifest.dependencies, manifest.devDependencies].flatMap((d) => Object.keys((d as object | undefined) ?? {})));\n}\n\n/** The bundler the project runs its dev server with, from its dependencies, or none deictic knows. */\nexport function bundlerOf(root: string): Bundler | undefined {\n const has = dependenciesOf(root);\n if (has.has('next')) return 'next';\n if (has.has('astro')) return 'astro';\n if (has.has('vite') || SETUPS.vite.files.some((f) => existsSync(join(root, f)))) return 'vite';\n if (has.has('@rspack/core') || has.has('@rspack/cli')) return 'rspack';\n if (has.has('webpack')) return 'webpack';\n // Bun's own bundler only where a server of the project's has it bundle a page: not every project Bun runs.\n if (serverOf(root) !== undefined) return 'bun';\n return undefined;\n}\n\n/** What the recommended setup imports, for the bundler: launch-editor opens files under webpack, which has no launcher. */\nexport function packagesFor(bundler: Bundler | undefined): string[] {\n const plugins = recommended().flatMap((p) => p.packages ?? []);\n return ['deictic', ...plugins, ...(bundler === 'webpack' || bundler === 'rspack' ? ['launch-editor'] : [])];\n}\n\ntype Node = Expression | ObjectExpression;\n\n/**\n * The object an expression comes to: through `defineConfig(…)`, `(…)`, `satisfies`, a function's return and a top-level\n * `const`. Not through another call: in `mergeConfig(base, {…})` or webpack-merge's `merge(common, {…})` the first\n * argument is a base the project may build with too, and the plugin isn't the base's.\n */\nfunction objectOf(node: Node | null | undefined, program: Program, depth = 0): ObjectExpression | undefined {\n if (node == null || depth > 8) return undefined;\n const next = (n: Node | null | undefined) => objectOf(n, program, depth + 1);\n if (node.type === 'ObjectExpression') return node;\n if (node.type === 'ParenthesizedExpression' || node.type === 'TSAsExpression' || node.type === 'TSSatisfiesExpression')\n return next(node.expression);\n if (node.type === 'CallExpression') {\n const { callee } = node;\n const named = (callee.type === 'Identifier' ? callee : callee.type === 'MemberExpression' ? callee.property : undefined) as\n { type: string; name?: string } | undefined;\n const [first] = node.arguments;\n if (named?.name !== 'defineConfig' || first === undefined || first.type === 'SpreadElement') return undefined;\n return next(first);\n }\n if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {\n const body = node.body;\n if (body === null) return undefined;\n if (body.type !== 'BlockStatement') return next(body);\n const returned = body.body.findLast((s) => s.type === 'ReturnStatement');\n return returned?.type === 'ReturnStatement' ? next(returned.argument) : undefined;\n }\n if (node.type !== 'Identifier') return undefined;\n for (const statement of program.body) {\n const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type !== 'VariableDeclaration') continue;\n const found = declaration.declarations.find((d) => d.id.type === 'Identifier' && d.id.name === node.name);\n if (found !== undefined) return next(found.init);\n }\n return undefined;\n}\n\n/** The config's exported value: `export default …` or `module.exports = …`, and whether it's CommonJS. */\nfunction exportedOf(program: Program): { value: Expression; commonjs: boolean } | undefined {\n for (const statement of program.body) {\n if (statement.type === 'ExportDefaultDeclaration') {\n const value = statement.declaration;\n return value.type.endsWith('Declaration') && value.type !== 'FunctionDeclaration'\n ? undefined\n : { value: value as Expression, commonjs: false };\n }\n if (statement.type !== 'ExpressionStatement' || statement.expression.type !== 'AssignmentExpression') continue;\n const { left, right } = statement.expression;\n const exports =\n left.type === 'MemberExpression' &&\n left.object.type === 'Identifier' &&\n left.object.name === 'module' &&\n left.property.type === 'Identifier' &&\n left.property.name === 'exports';\n if (exports) return { value: right, commonjs: true };\n }\n return undefined;\n}\n\n/**\n * The config with deictic added, or nothing where it can't tell where: deictic's import beside the config's, and its\n * plugin last in the list (`plugins`, `integrations`), or the config wrapped (Next's). Written in the config's quotes,\n * semicolons and line endings.\n */\nexport function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code: string): string | undefined {\n const setup = SETUPS[bundler];\n const { program, errors } = parseSync(file, code, { preserveParens: false });\n if (errors.length > 0) return undefined;\n const exported = exportedOf(program);\n if (exported === undefined) return undefined;\n const eol = eolOf(code);\n const out = new MagicString(code);\n\n if (setup.wrap) {\n out.appendLeft(exported.value.start, `${setup.name}(`);\n out.appendRight(exported.value.end, `, ${setup.value})`);\n } else {\n const object = objectOf(exported.value, program);\n if (object === undefined || !addTo(out, code, object, setup.list!, setup.value, eol)) return undefined;\n }\n\n const lines: [string, string][] = [\n ['{ recommended }', 'deictic/recommended'],\n [`{ ${setup.name} }`, setup.from],\n ];\n addImports(out, program, code, lines, exported.commonjs);\n return out.toString();\n}\n\n/** 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. */\nfunction addTo(out: MagicString, code: string, object: ObjectExpression, list: string, value: string, eol: string): boolean {\n const property = object.properties.find(\n (p) =>\n p.type === 'Property' &&\n !p.computed &&\n ((p.key.type === 'Identifier' && p.key.name === list) || (p.key.type === 'Literal' && p.key.value === list)),\n );\n if (property !== undefined) {\n if (property.type !== 'Property') return false;\n let array = property.value;\n while (array.type === 'TSAsExpression' || array.type === 'TSSatisfiesExpression') array = array.expression;\n if (array.type !== 'ArrayExpression') return false;\n const last = array.elements.findLast((e) => e !== null);\n if (last == null) {\n out.appendLeft(array.start + 1, value);\n return true;\n }\n const multiline = code.slice(array.start, array.end).includes('\\n');\n out.appendLeft(last.end, multiline ? `,${eol}${indentAt(code, last.start)}${value}` : `, ${value}`);\n return true;\n }\n addFirst(out, code, object.start, object.properties[0], `${list}: [${value}]`);\n return true;\n}\n\nexport interface InitOptions {\n /** Where it runs: the project is the nearest folder with a package.json. */\n cwd: string;\n /** Installs the packages; false only says the command. */\n install?: boolean;\n /** Adds the skill (true), says how (false), or asks (undefined, on a terminal; says how elsewhere). */\n skill?: boolean;\n /** Says what it would do, and does none of it. */\n dryRun?: boolean;\n log?: (line: string) => void;\n /** Runs a command in the project, and answers whether it succeeded. */\n run?: (command: string, cwd: string) => boolean;\n ask?: (question: string) => Promise<boolean>;\n}\n\nconst runIn = (command: string, cwd: string) => spawnSync(command, { cwd, stdio: 'inherit', shell: true }).status === 0;\n\n/** Sets the project up; throws what to do where it can't. */\nexport async function init(options: InitOptions): Promise<void> {\n const { install = true, dryRun = false, log = console.log, run = runIn } = options;\n const root = rootOf(options.cwd);\n if (root === undefined) throw new Error('deictic: no package.json here or above: run it in your project');\n const manager = packageManager(root);\n const bundler = bundlerOf(root);\n const has = dependenciesOf(root);\n\n const wanted = packagesFor(bundler).filter((p) => !has.has(p));\n const command = installCommand(manager, wanted, root);\n if (wanted.length === 0) {\n log('deictic: its packages are installed');\n } else if (!install || dryRun) {\n log(`deictic: install them with ${command}`);\n } else {\n log(`deictic: ${command}`);\n if (!run(command, root)) throw new Error(`deictic: the install failed: run ${command} yourself, then this again`);\n }\n\n configure(root, bundler, dryRun, log);\n\n const skill = `${runnerOf(manager)} skills add ${existsSync(join(root, 'node_modules', 'deictic')) ? './node_modules/deictic' : 'gkurt/deictic'}`;\n const add =\n options.skill ?? (options.ask === undefined ? false : await options.ask('deictic: add the skill, so your agent works the tasks?'));\n if (!add || dryRun) {\n log(`deictic: to have your agent work the tasks, add the skill: ${skill}`);\n } else {\n log(`deictic: ${skill}`);\n if (!run(skill, root)) log(`deictic: adding the skill failed: run ${skill} yourself`);\n }\n\n log(`deictic: screenshots render in Playwright's Chromium (${runnerOf(manager)} playwright install chromium), else Chrome or Edge`);\n log('deictic: start your dev server and Alt-click an element');\n}\n\n/** Adds deictic to the bundler's config, or says what to add where it can't. */\nfunction configure(root: string, bundler: Bundler | undefined, dryRun: boolean, log: (line: string) => void): void {\n if (bundler === undefined) {\n log('deictic: no bundler it knows in package.json (Vite, Next.js, Astro, webpack, Rspack, Bun): see API.md#bundlers to add it');\n return;\n }\n if (bundler === 'bun') {\n configureBun(root, dryRun, log);\n return;\n }\n const setup = SETUPS[bundler];\n const file = setup.files.map((f) => join(root, f)).find((f) => existsSync(f));\n const imports = `import { recommended } from 'deictic/recommended';\\nimport { ${setup.name} } from '${setup.from}';`;\n if (file === undefined) {\n log(`deictic: no ${setup.files[0]} here: add deictic to your ${bundler} config:\\n\\n${imports}\\n${setup.snippet}\\n`);\n return;\n }\n const name = relative(root, file).replaceAll('\\\\', '/');\n const code = readFileSync(file, 'utf8');\n if (/['\"]deictic\\//.test(code)) {\n log(`deictic: ${name} has it already`);\n return;\n }\n const added = addToConfig(bundler, file, code);\n if (added === undefined) {\n log(`deictic: couldn't tell where it goes in ${name}: add it yourself:\\n\\n${imports}\\n${setup.snippet}\\n`);\n return;\n }\n if (!dryRun) writeFileSync(file, added);\n log(`deictic: ${dryRun ? 'would add' : 'added'} it to ${name}`);\n}\n\n/** Bun's three steps: the plugin's module, bunfig.toml, and its routes in the server. Each says what to add where it can't. */\nfunction configureBun(root: string, dryRun: boolean, log: (line: string) => void): void {\n const write = (file: string, text: string) => !dryRun && writeFileSync(file, text);\n const did = dryRun ? 'would add' : 'added';\n const plugin = join(root, MODULE);\n if (!existsSync(plugin)) {\n write(plugin, PLUGIN);\n log(`deictic: ${dryRun ? 'would write' : 'wrote'} ${MODULE}`);\n } else if (!readFileSync(plugin, 'utf8').includes('deictic/bun')) {\n log(`deictic: ${MODULE} is a module of yours: add deictic by hand, as API.md#bundlers says for Bun`);\n return;\n }\n\n const bunfig = join(root, 'bunfig.toml');\n const before = existsSync(bunfig) ? readFileSync(bunfig, 'utf8') : undefined;\n const after = addToBunfig(before);\n if (after === undefined) {\n log(`deictic: couldn't tell where it goes in bunfig.toml: add it yourself:\\n\\n${BY_HAND.bunfig}\\n`);\n } else if (after === before) {\n log('deictic: bunfig.toml has it already');\n } else {\n write(bunfig, after);\n log(`deictic: ${did} it to bunfig.toml`);\n }\n\n const server = serverOf(root)!;\n const name = relative(root, server).replaceAll('\\\\', '/');\n const code = readFileSync(server, 'utf8');\n if (code.includes(MODULE.replace(/\\.ts$/, ''))) {\n log(`deictic: ${name} has its routes already`);\n return;\n }\n const added = addToServer(server, code, root);\n if (added === undefined) {\n log(`deictic: couldn't tell where its routes go in ${name}: add them yourself:\\n\\n${BY_HAND.server}\\n`);\n return;\n }\n write(server, added);\n log(`deictic: ${did} its routes to ${name}`);\n}\n\n/** Asks a yes-or-no question on the terminal, yes by default. */\nasync function ask(question: string): Promise<boolean> {\n const lines = createInterface({ input: process.stdin, output: process.stdout });\n try {\n return !/^n/i.test((await lines.question(`${question} (Y/n) `)).trim());\n } finally {\n lines.close();\n }\n}\n\nexport async function run(values: { dryRun?: boolean; install: boolean; skill?: boolean }): Promise<void> {\n try {\n await init({\n cwd: process.cwd(),\n install: values.install,\n skill: values.skill,\n dryRun: values.dryRun,\n ask: process.stdin.isTTY && process.stdout.isTTY ? ask : undefined,\n });\n } catch (e) {\n fail(e instanceof Error ? e.message : String(e));\n }\n}\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,SAAS,SAAkB,KAAK,SAAS,MAAM,IAAI,SAAS;;AAGzE,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,QAAQ,KAAK,YAAY,MAAM,SAAS,CAAC,IAAI;CACnD,OAAO,UAAU,KAAK,KAAK,MAAM,KAAK,CAAC,CAAC,CAAE;AAC5C;;;;;AAMA,SAAgB,WAAW,KAAkB,SAAkB,MAAc,OAA2B,WAAW,OAAa;CAC9H,MAAM,MAAM,MAAM,IAAI;CACtB,MAAM,UAAU,QAAQ,KAAK,QAAQ,MAAM,EAAE,SAAS,mBAAmB;CACzE,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,UAAU,KAAA,IAAY,MAAM,KAAK,MAAM,OAAO;CAC5D,MAAM,OAAO,UAAU,KAAA,KAAa,KAAK,MAAM,MAAM,OAAO,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,SAAS,GAAG,IAAI,MAAM;CACvG,MAAM,KAAK,MAAc,GAAG,QAAQ,IAAI;CACxC,MAAM,OAAO,MACV,KAAK,CAAC,MAAM,UAAW,WAAW,SAAS,KAAK,aAAa,EAAE,IAAI,EAAE,GAAG,SAAS,UAAU,KAAK,QAAQ,EAAE,IAAI,IAAI,MAAO,CAAC,CAC1H,KAAK,GAAG;CACX,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK,WAAW,OAA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I,KAAK,SAAA,oBAAgB,QAAQ,SAAS,EAAE,CAAC,GAAG;EAC9C,IAAI,YAAY,KAAK,wBAAwB;EAC7C;CACF;CACA,MAAM,QAAQ,YAAY,QAAQ,MAAM,IAAI;CAC5C,IAAI,UAAU,KAAA,GAAW;EACvB,IAAI,iDAAiD,KAAK,0BAA0B,QAAQ,OAAO,GAAG;EACtG;CACF;CACA,MAAM,QAAQ,KAAK;CACnB,IAAI,YAAY,IAAI,iBAAiB,MAAM;AAC7C;;AAGA,eAAe,IAAI,UAAoC;CACrD,MAAM,QAAQ,gBAAgB;EAAE,OAAO,QAAQ;EAAO,QAAQ,QAAQ;CAAO,CAAC;CAC9E,IAAI;EACF,OAAO,CAAC,MAAM,MAAM,MAAM,MAAM,SAAS,GAAG,SAAS,QAAQ,EAAA,CAAG,KAAK,CAAC;CACxE,UAAU;EACR,MAAM,MAAM;CACd;AACF;AAEA,eAAsB,IAAI,QAAgF;CACxG,IAAI;EACF,MAAM,KAAK;GACT,KAAK,QAAQ,IAAI;GACjB,SAAS,OAAO;GAChB,OAAO,OAAO;GACd,QAAQ,OAAO;GACf,KAAK,QAAQ,MAAM,SAAS,QAAQ,OAAO,QAAQ,MAAM,KAAA;EAC3D,CAAC;CACH,SAAS,GAAG;EACV,KAAK,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;CACjD;AACF"}
|
|
1
|
+
{"version":3,"file":"init.js","names":[],"sources":["../../src/cli/edit.ts","../../src/cli/bun.ts","../../src/cli/init.ts"],"sourcesContent":["/**\n * Editing a project's own source the way it's written: its quotes, semicolons, line endings and indentation. What\n * `init` adds to a bundler's config and to a Bun server goes through here.\n */\nimport type MagicString from 'magic-string';\nimport type { Program } from 'oxc-parser';\n\n/** The file's line ending. */\nexport const eolOf = (code: string) => (code.includes('\\r\\n') ? '\\r\\n' : '\\n');\n\n/** The whitespace a line starts with, for the line `offset` is on. */\nexport function indentAt(code: string, offset: number): string {\n const start = code.lastIndexOf('\\n', offset - 1) + 1;\n return /^[ \\t]*/.exec(code.slice(start))![0];\n}\n\n/**\n * Adds import lines after the module's last import (or `require`, in CommonJS), or at its top: written in the quotes\n * and semicolons of its first import. Each line is `[what, from]`: `import ${what} from '${from}'`, or as a `require`.\n */\nexport function addImports(out: MagicString, program: Program, code: string, lines: [string, string][], commonjs = false): void {\n const eol = eolOf(code);\n const imports = program.body.filter((s) => s.type === 'ImportDeclaration');\n const first = imports[0];\n const quote = first === undefined ? \"'\" : code[first.source.start]!;\n const semi = first === undefined || code.slice(first.start, first.end).trimEnd().endsWith(';') ? ';' : '';\n const q = (s: string) => `${quote}${s}${quote}`;\n const text = lines\n .map(([what, from]) => (commonjs ? `const ${what} = require(${q(from)})${semi}` : `import ${what} from ${q(from)}${semi}`))\n .join(eol);\n const after = imports.at(-1) ?? requiresOf(program).at(-1);\n if (after === undefined) out.prepend(`${text}${eol}${eol}`);\n else out.appendLeft(after.end, `${eol}${text}`);\n}\n\n/** The top-level `const … = require(…)` statements of a CommonJS module, to put new ones after. */\nfunction requiresOf(program: Program) {\n return program.body.filter(\n (s) =>\n s.type === 'VariableDeclaration' &&\n s.declarations.some(\n (d) => d.init?.type === 'CallExpression' && d.init.callee.type === 'Identifier' && d.init.callee.name === 'require',\n ),\n );\n}\n\n/** Inserts `text` as the first property of the object literal that starts at `open` (its `{`), as the object is laid out. */\nexport function addFirst(out: MagicString, code: string, open: number, first: { start: number } | undefined, text: string): void {\n const eol = eolOf(code);\n if (first === undefined) {\n out.appendLeft(open + 1, ` ${text} `);\n return;\n }\n const multiline = code.slice(open, first.start).includes('\\n');\n out.appendLeft(first.start, multiline ? `${text},${eol}${indentAt(code, first.start)}` : `${text}, `);\n}\n","/**\n * `init` for Bun's own dev server: `Bun.serve` with HTML imports, which bundles the page with the plugins bunfig.toml\n * names. Only that: a Bun project that runs Vite, Next.js or another bundler is that bundler's, and one with no HTML\n * imports has no page of Bun's for deictic to be in. Three steps, as the API has them: the plugin's module, bunfig's\n * `[serve.static] plugins`, and its routes spread into `Bun.serve`'s.\n */\nimport { readdirSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\n\nimport MagicString from 'magic-string';\nimport { type CallExpression, parseSync, Visitor } from 'oxc-parser';\n\nimport { addFirst, addImports, eolOf } from './edit.ts';\n\n/** The plugin's module, from the root, which bunfig names and the server imports. */\nexport const MODULE = 'deictic.plugin.ts';\n\nexport const PLUGIN = `import { deictic } from 'deictic/bun';\nimport { recommended } from 'deictic/recommended';\n\n// One module for both: bunfig.toml names it as the dev server's bundler plugin, and the server spreads its routes,\n// deictic's endpoints, into its own.\nexport default deictic({ plugins: recommended() });\n`;\n\nconst SOURCE = /\\.[cm]?[jt]sx?$/;\nconst SKIP = new Set(['node_modules', 'dist', 'build', 'out']);\nconst SERVE = /\\bBun\\.serve\\s*\\(/;\nconst HTML = /\\bfrom\\s*['\"][^'\"]+\\.html['\"]/;\n\n/**\n * The module that serves the page with Bun's bundler: it calls `Bun.serve` and imports an HTML file. Looked for under\n * the root, not in dependencies, builds or dot folders, a few folders deep.\n */\nexport function serverOf(root: string): string | undefined {\n const walk = (dir: string, depth: number): string | undefined => {\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return undefined;\n }\n for (const e of entries) {\n if (!e.isFile() || !SOURCE.test(e.name)) continue;\n const path = join(dir, e.name);\n const code = readFileSync(path, 'utf8');\n if (SERVE.test(code) && HTML.test(code)) return path;\n }\n if (depth === 0) return undefined;\n for (const e of entries) {\n if (!e.isDirectory() || e.name.startsWith('.') || SKIP.has(e.name)) continue;\n const found = walk(join(dir, e.name), depth - 1);\n if (found !== undefined) return found;\n }\n return undefined;\n };\n return walk(root, 3);\n}\n\n/**\n * bunfig.toml with the plugin's module first in `[serve.static] plugins` (first, so it sees the source as written),\n * made where there's none; unchanged where it's there already, and nothing where bunfig says it another way (a dotted\n * key, an inline table) and it can't tell where.\n */\nexport function addToBunfig(text: string | undefined, entry = `./${MODULE}`): string | undefined {\n const quoted = JSON.stringify(entry);\n if (text === undefined) return `[serve.static]\\nplugins = [${quoted}]\\n`;\n if (text.includes(entry)) return text;\n if (/serve\\.static\\.|static\\s*=\\s*\\{/.test(text)) return undefined;\n const eol = eolOf(text);\n const header = /^[ \\t]*\\[serve\\.static\\][ \\t]*(#.*)?$/m.exec(text);\n if (header === null)\n return `${text}${text === '' || text.endsWith('\\n') ? '' : eol}${eol}[serve.static]${eol}plugins = [${quoted}]${eol}`;\n const bodyStart = header.index + header[0].length;\n const next = /^[ \\t]*\\[/m.exec(text.slice(bodyStart));\n const body = text.slice(bodyStart, next === null ? text.length : bodyStart + next.index);\n const list = /^[ \\t]*plugins[ \\t]*=[ \\t]*\\[/m.exec(body);\n if (list === null) return `${text.slice(0, bodyStart)}${eol}plugins = [${quoted}]${text.slice(bodyStart)}`;\n const open = bodyStart + list.index + list[0].length;\n const rest = text.slice(open);\n const empty = /^\\s*\\]/.test(rest);\n const lineBreak = /^[ \\t]*\\r?\\n([ \\t]*)/.exec(rest);\n if (empty) return `${text.slice(0, open)}${quoted}${rest.trimStart()}`;\n if (lineBreak !== null) return `${text.slice(0, open)}${eol}${lineBreak[1]}${quoted},${rest}`;\n return `${text.slice(0, open)}${quoted}, ${rest.trimStart()}`;\n}\n\n/**\n * The server with the plugin's routes first in `Bun.serve`'s `routes`, or `routes` with them where it has none, and\n * the module imported: nothing where `Bun.serve` isn't given an object it can see, or its routes aren't one.\n */\nexport function addToServer(file: string, code: string, root: string): string | undefined {\n const { program, errors } = parseSync(file, code, { preserveParens: false });\n if (errors.length > 0) return undefined;\n const calls: CallExpression[] = [];\n new Visitor({\n CallExpression(node) {\n const { callee } = node;\n if (\n callee.type === 'MemberExpression' &&\n callee.object.type === 'Identifier' &&\n callee.object.name === 'Bun' &&\n callee.property.type === 'Identifier' &&\n callee.property.name === 'serve'\n )\n calls.push(node);\n },\n }).visit(program);\n const options = calls.length === 1 ? calls[0]!.arguments[0] : undefined;\n if (options?.type !== 'ObjectExpression') return undefined;\n\n // `tools`, as the API names it, unless the module has a `tools` of its own.\n const name = /\\btools\\b/.test(code) ? 'deicticTools' : 'tools';\n const out = new MagicString(code);\n const routes = options.properties.find(\n (p) => p.type === 'Property' && !p.computed && p.key.type === 'Identifier' && p.key.name === 'routes',\n );\n if (routes === undefined) {\n addFirst(out, code, options.start, options.properties[0], `routes: { ...${name}.routes }`);\n } else {\n if (routes.type !== 'Property' || routes.value.type !== 'ObjectExpression') return undefined;\n addFirst(out, code, routes.value.start, routes.value.properties[0], `...${name}.routes`);\n }\n const from = relative(dirname(file), join(root, MODULE)).replaceAll('\\\\', '/');\n addImports(out, program, code, [[name, from.startsWith('.') ? from : `./${from}`]]);\n return out.toString();\n}\n\n/** What to add by hand, for a server or a bunfig it can't edit. */\nexport const BY_HAND = {\n bunfig: `[serve.static]\\nplugins = [\"./${MODULE}\"]`,\n server: `import tools from './${MODULE}';\\nBun.serve({ routes: { ...tools.routes, '/*': index } });`,\n};\n","/**\n * `deictic init`: the recommended setup in a project, in one step. It installs deictic and what the recommended\n * plugins import, with the project's package manager and as the project's own dev dependencies (deictic, the\n * page's bundle and the skill all find them from the project, so they can't come in through another package), adds\n * deictic to the bundler's config where it can find the place, and offers the agent skill.\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\nimport { createInterface } from 'node:readline/promises';\n\nimport MagicString from 'magic-string';\nimport { type Expression, type ObjectExpression, parseSync, type Program } from 'oxc-parser';\n\nimport { recommended } from '#src/plugins/recommended/index.ts';\n\nimport { installCommand, packageManager, readJson, runnerOf } from '#src/tools/packages.ts';\n\nimport { fail } from './board.ts';\nimport { addToBunfig, addToServer, BY_HAND, MODULE, PLUGIN, serverOf } from './bun.ts';\nimport { addFirst, addImports } from './edit.ts';\n\nexport type Bundler = 'next' | 'astro' | 'vite' | 'rspack' | 'webpack' | 'bun';\n\ninterface Setup {\n /** The config files it looks for, in order. */\n files: string[];\n /** The module deictic's integration comes from, and its name there. */\n from: string;\n name: string;\n /** What goes in the config: in its `list`, or wrapped around the whole of it with `wrap`. */\n list?: string;\n value: string;\n wrap?: boolean;\n /** The snippet for a config it can't edit. */\n snippet: string;\n}\n\nconst extensions = (base: string) => ['ts', 'mts', 'js', 'mjs', 'cts', 'cjs'].map((e) => `${base}.${e}`);\nconst PLUGINS = '{ plugins: recommended() }';\n\nconst SETUPS: Record<Exclude<Bundler, 'bun'>, Setup> = {\n next: {\n files: extensions('next.config'),\n from: 'deictic/next',\n name: 'withDeictic',\n value: PLUGINS,\n wrap: true,\n snippet: `export default withDeictic(nextConfig, ${PLUGINS});`,\n },\n astro: {\n files: extensions('astro.config'),\n from: 'deictic/astro',\n name: 'deictic',\n list: 'integrations',\n value: `deictic(${PLUGINS})`,\n snippet: `export default defineConfig({ integrations: [deictic(${PLUGINS})] });`,\n },\n vite: {\n files: extensions('vite.config'),\n from: 'deictic/vite',\n name: 'deictic',\n list: 'plugins',\n value: `deictic(${PLUGINS})`,\n snippet: `export default defineConfig({ plugins: [deictic(${PLUGINS}), react()] });`,\n },\n rspack: {\n files: extensions('rspack.config'),\n from: 'deictic/webpack',\n name: 'DeicticPlugin',\n list: 'plugins',\n value: `new DeicticPlugin(${PLUGINS})`,\n snippet: `export default { plugins: [new DeicticPlugin(${PLUGINS})] };`,\n },\n webpack: {\n files: extensions('webpack.config'),\n from: 'deictic/webpack',\n name: 'DeicticPlugin',\n list: 'plugins',\n value: `new DeicticPlugin(${PLUGINS})`,\n snippet: `export default { plugins: [new DeicticPlugin(${PLUGINS})] };`,\n },\n};\n\n/** The project's root: the nearest folder with a package.json, from `dir` up. */\nexport function rootOf(dir: string): string | undefined {\n for (let at = dir; ; at = dirname(at)) {\n if (existsSync(join(at, 'package.json'))) return at;\n if (dirname(at) === at) return undefined;\n }\n}\n\n/** The project's dependencies and dev dependencies, by name. */\nfunction dependenciesOf(root: string): Set<string> {\n const manifest = readJson(join(root, 'package.json')) ?? {};\n return new Set([manifest.dependencies, manifest.devDependencies].flatMap((d) => Object.keys((d as object | undefined) ?? {})));\n}\n\n/** The bundler the project runs its dev server with, from its dependencies, or none deictic knows. */\nexport function bundlerOf(root: string): Bundler | undefined {\n const has = dependenciesOf(root);\n if (has.has('next')) return 'next';\n if (has.has('astro')) return 'astro';\n if (has.has('vite') || SETUPS.vite.files.some((f) => existsSync(join(root, f)))) return 'vite';\n if (has.has('@rspack/core') || has.has('@rspack/cli')) return 'rspack';\n if (has.has('webpack')) return 'webpack';\n // Bun's own bundler only where a server of the project's has it bundle a page: not every project Bun runs.\n if (serverOf(root) !== undefined) return 'bun';\n return undefined;\n}\n\n/** What the recommended setup imports, for the bundler: launch-editor opens files under webpack, which has no launcher. */\nexport function packagesFor(bundler: Bundler | undefined): string[] {\n const plugins = recommended().flatMap((p) => p.packages ?? []);\n return ['deictic', ...plugins, ...(bundler === 'webpack' || bundler === 'rspack' ? ['launch-editor'] : [])];\n}\n\ntype Node = Expression | ObjectExpression;\n\n/**\n * The object an expression comes to: through `defineConfig(…)`, `(…)`, `satisfies`, a function's return and a top-level\n * `const`. Not through another call: in `mergeConfig(base, {…})` or webpack-merge's `merge(common, {…})` the first\n * argument is a base the project may build with too, and the plugin isn't the base's.\n */\nfunction objectOf(node: Node | null | undefined, program: Program, depth = 0): ObjectExpression | undefined {\n if (node == null || depth > 8) return undefined;\n const next = (n: Node | null | undefined) => objectOf(n, program, depth + 1);\n if (node.type === 'ObjectExpression') return node;\n if (node.type === 'ParenthesizedExpression' || node.type === 'TSAsExpression' || node.type === 'TSSatisfiesExpression')\n return next(node.expression);\n if (node.type === 'CallExpression') {\n const { callee } = node;\n const named = (callee.type === 'Identifier' ? callee : callee.type === 'MemberExpression' ? callee.property : undefined) as\n { type: string; name?: string } | undefined;\n const [first] = node.arguments;\n if (named?.name !== 'defineConfig' || first === undefined || first.type === 'SpreadElement') return undefined;\n return next(first);\n }\n if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {\n const body = node.body;\n if (body === null) return undefined;\n if (body.type !== 'BlockStatement') return next(body);\n const returned = body.body.findLast((s) => s.type === 'ReturnStatement');\n return returned?.type === 'ReturnStatement' ? next(returned.argument) : undefined;\n }\n if (node.type !== 'Identifier') return undefined;\n for (const statement of program.body) {\n const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type !== 'VariableDeclaration') continue;\n const found = declaration.declarations.find((d) => d.id.type === 'Identifier' && d.id.name === node.name);\n if (found !== undefined) return next(found.init);\n }\n return undefined;\n}\n\n/** The config's exported value: `export default …` or `module.exports = …`, and whether it's CommonJS. */\nfunction exportedOf(program: Program): { value: Expression; commonjs: boolean } | undefined {\n for (const statement of program.body) {\n if (statement.type === 'ExportDefaultDeclaration') {\n const value = statement.declaration;\n return value.type.endsWith('Declaration') && value.type !== 'FunctionDeclaration'\n ? undefined\n : { value: value as Expression, commonjs: false };\n }\n if (statement.type !== 'ExpressionStatement' || statement.expression.type !== 'AssignmentExpression') continue;\n const { left, right } = statement.expression;\n const exports =\n left.type === 'MemberExpression' &&\n left.object.type === 'Identifier' &&\n left.object.name === 'module' &&\n left.property.type === 'Identifier' &&\n left.property.name === 'exports';\n if (exports) return { value: right, commonjs: true };\n }\n return undefined;\n}\n\n/**\n * The config with deictic added, or nothing where it can't tell where: deictic's import beside the config's, and its\n * 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,\n * semicolons and line endings.\n */\nexport function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code: string): string | undefined {\n const setup = SETUPS[bundler];\n const { program, errors } = parseSync(file, code, { preserveParens: false });\n if (errors.length > 0) return undefined;\n const exported = exportedOf(program);\n if (exported === undefined) return undefined;\n const out = new MagicString(code);\n\n if (setup.wrap) {\n out.appendLeft(exported.value.start, `${setup.name}(`);\n out.appendRight(exported.value.end, `, ${setup.value})`);\n } else {\n const object = objectOf(exported.value, program);\n if (object === undefined || !addTo(out, code, object, setup.list!, setup.value)) return undefined;\n }\n\n const lines: [string, string][] = [\n ['{ recommended }', 'deictic/recommended'],\n [`{ ${setup.name} }`, setup.from],\n ];\n addImports(out, program, code, lines, exported.commonjs);\n return out.toString();\n}\n\n/**\n * Adds `value` first in the object's array `list`, or the list with it, as the object is laid out. False where `list`\n * isn't an array. First, since a plugin before deictic's that changes a module (both `pre` under Vite) leaves the\n * page's marks pointing at its code, not the file.\n */\nfunction addTo(out: MagicString, code: string, object: ObjectExpression, list: string, value: string): boolean {\n const property = object.properties.find(\n (p) =>\n p.type === 'Property' &&\n !p.computed &&\n ((p.key.type === 'Identifier' && p.key.name === list) || (p.key.type === 'Literal' && p.key.value === list)),\n );\n if (property !== undefined) {\n if (property.type !== 'Property') return false;\n let array = property.value;\n while (array.type === 'TSAsExpression' || array.type === 'TSSatisfiesExpression') array = array.expression;\n if (array.type !== 'ArrayExpression') return false;\n const first = array.elements.find((e) => e !== null);\n if (first == null) {\n out.appendLeft(array.start + 1, value);\n return true;\n }\n addFirst(out, code, array.start, first, value);\n return true;\n }\n addFirst(out, code, object.start, object.properties[0], `${list}: [${value}]`);\n return true;\n}\n\nexport interface InitOptions {\n /** Where it runs: the project is the nearest folder with a package.json. */\n cwd: string;\n /** Installs the packages; false only says the command. */\n install?: boolean;\n /** Adds the skill (true), says how (false), or asks (undefined, on a terminal; says how elsewhere). */\n skill?: boolean;\n /** Says what it would do, and does none of it. */\n dryRun?: boolean;\n log?: (line: string) => void;\n /** Runs a command in the project, and answers whether it succeeded. */\n run?: (command: string, cwd: string) => boolean;\n ask?: (question: string) => Promise<boolean>;\n}\n\nconst runIn = (command: string, cwd: string) => spawnSync(command, { cwd, stdio: 'inherit', shell: true }).status === 0;\n\n/** Sets the project up; throws what to do where it can't. */\nexport async function init(options: InitOptions): Promise<void> {\n const { install = true, dryRun = false, log = console.log, run = runIn } = options;\n const root = rootOf(options.cwd);\n if (root === undefined) throw new Error('deictic: no package.json here or above: run it in your project');\n const manager = packageManager(root);\n const bundler = bundlerOf(root);\n const has = dependenciesOf(root);\n\n const wanted = packagesFor(bundler).filter((p) => !has.has(p));\n const command = installCommand(manager, wanted, root);\n if (wanted.length === 0) {\n log('deictic: its packages are installed');\n } else if (!install || dryRun) {\n log(`deictic: install them with ${command}`);\n } else {\n log(`deictic: ${command}`);\n if (!run(command, root)) throw new Error(`deictic: the install failed: run ${command} yourself, then this again`);\n }\n\n configure(root, bundler, dryRun, log);\n\n const skill = `${runnerOf(manager)} skills add ${existsSync(join(root, 'node_modules', 'deictic')) ? './node_modules/deictic' : 'gkurt/deictic'}`;\n const add =\n options.skill ?? (options.ask === undefined ? false : await options.ask('deictic: add the skill, so your agent works the tasks?'));\n if (!add || dryRun) {\n log(`deictic: to have your agent work the tasks, add the skill: ${skill}`);\n } else {\n log(`deictic: ${skill}`);\n if (!run(skill, root)) log(`deictic: adding the skill failed: run ${skill} yourself`);\n }\n\n log(`deictic: screenshots render in Playwright's Chromium (${runnerOf(manager)} playwright install chromium), else Chrome or Edge`);\n log('deictic: start your dev server and Alt-click an element');\n}\n\n/** Adds deictic to the bundler's config, or says what to add where it can't. */\nfunction configure(root: string, bundler: Bundler | undefined, dryRun: boolean, log: (line: string) => void): void {\n if (bundler === undefined) {\n log('deictic: no bundler it knows in package.json (Vite, Next.js, Astro, webpack, Rspack, Bun): see API.md#bundlers to add it');\n return;\n }\n if (bundler === 'bun') {\n configureBun(root, dryRun, log);\n return;\n }\n const setup = SETUPS[bundler];\n const file = setup.files.map((f) => join(root, f)).find((f) => existsSync(f));\n const imports = `import { recommended } from 'deictic/recommended';\\nimport { ${setup.name} } from '${setup.from}';`;\n if (file === undefined) {\n log(`deictic: no ${setup.files[0]} here: add deictic to your ${bundler} config:\\n\\n${imports}\\n${setup.snippet}\\n`);\n return;\n }\n const name = relative(root, file).replaceAll('\\\\', '/');\n const code = readFileSync(file, 'utf8');\n if (/['\"]deictic\\//.test(code)) {\n log(`deictic: ${name} has it already`);\n return;\n }\n const added = addToConfig(bundler, file, code);\n if (added === undefined) {\n log(`deictic: couldn't tell where it goes in ${name}: add it yourself:\\n\\n${imports}\\n${setup.snippet}\\n`);\n return;\n }\n if (!dryRun) writeFileSync(file, added);\n log(`deictic: ${dryRun ? 'would add' : 'added'} it to ${name}`);\n}\n\n/** Bun's three steps: the plugin's module, bunfig.toml, and its routes in the server. Each says what to add where it can't. */\nfunction configureBun(root: string, dryRun: boolean, log: (line: string) => void): void {\n const write = (file: string, text: string) => !dryRun && writeFileSync(file, text);\n const did = dryRun ? 'would add' : 'added';\n const plugin = join(root, MODULE);\n if (!existsSync(plugin)) {\n write(plugin, PLUGIN);\n log(`deictic: ${dryRun ? 'would write' : 'wrote'} ${MODULE}`);\n } else if (!readFileSync(plugin, 'utf8').includes('deictic/bun')) {\n log(`deictic: ${MODULE} is a module of yours: add deictic by hand, as API.md#bundlers says for Bun`);\n return;\n }\n\n const bunfig = join(root, 'bunfig.toml');\n const before = existsSync(bunfig) ? readFileSync(bunfig, 'utf8') : undefined;\n const after = addToBunfig(before);\n if (after === undefined) {\n log(`deictic: couldn't tell where it goes in bunfig.toml: add it yourself:\\n\\n${BY_HAND.bunfig}\\n`);\n } else if (after === before) {\n log('deictic: bunfig.toml has it already');\n } else {\n write(bunfig, after);\n log(`deictic: ${did} it to bunfig.toml`);\n }\n\n const server = serverOf(root)!;\n const name = relative(root, server).replaceAll('\\\\', '/');\n const code = readFileSync(server, 'utf8');\n if (code.includes(MODULE.replace(/\\.ts$/, ''))) {\n log(`deictic: ${name} has its routes already`);\n return;\n }\n const added = addToServer(server, code, root);\n if (added === undefined) {\n log(`deictic: couldn't tell where its routes go in ${name}: add them yourself:\\n\\n${BY_HAND.server}\\n`);\n return;\n }\n write(server, added);\n log(`deictic: ${did} its routes to ${name}`);\n}\n\n/** Asks a yes-or-no question on the terminal, yes by default. */\nasync function ask(question: string): Promise<boolean> {\n const lines = createInterface({ input: process.stdin, output: process.stdout });\n try {\n return !/^n/i.test((await lines.question(`${question} (Y/n) `)).trim());\n } finally {\n lines.close();\n }\n}\n\nexport async function run(values: { dryRun?: boolean; install: boolean; skill?: boolean }): Promise<void> {\n try {\n await init({\n cwd: process.cwd(),\n install: values.install,\n skill: values.skill,\n dryRun: values.dryRun,\n ask: process.stdin.isTTY && process.stdout.isTTY ? ask : undefined,\n });\n } catch (e) {\n fail(e instanceof Error ? e.message : String(e));\n }\n}\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,SAAS,SAAkB,KAAK,SAAS,MAAM,IAAI,SAAS;;AAGzE,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,QAAQ,KAAK,YAAY,MAAM,SAAS,CAAC,IAAI;CACnD,OAAO,UAAU,KAAK,KAAK,MAAM,KAAK,CAAC,CAAC,CAAE;AAC5C;;;;;AAMA,SAAgB,WAAW,KAAkB,SAAkB,MAAc,OAA2B,WAAW,OAAa;CAC9H,MAAM,MAAM,MAAM,IAAI;CACtB,MAAM,UAAU,QAAQ,KAAK,QAAQ,MAAM,EAAE,SAAS,mBAAmB;CACzE,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,UAAU,KAAA,IAAY,MAAM,KAAK,MAAM,OAAO;CAC5D,MAAM,OAAO,UAAU,KAAA,KAAa,KAAK,MAAM,MAAM,OAAO,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,SAAS,GAAG,IAAI,MAAM;CACvG,MAAM,KAAK,MAAc,GAAG,QAAQ,IAAI;CACxC,MAAM,OAAO,MACV,KAAK,CAAC,MAAM,UAAW,WAAW,SAAS,KAAK,aAAa,EAAE,IAAI,EAAE,GAAG,SAAS,UAAU,KAAK,QAAQ,EAAE,IAAI,IAAI,MAAO,CAAC,CAC1H,KAAK,GAAG;CACX,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK,WAAW,OAAO,CAAC,CAAC,GAAG,EAAE;CACzD,IAAI,UAAU,KAAA,GAAW,IAAI,QAAQ,GAAG,OAAO,MAAM,KAAK;MACrD,IAAI,WAAW,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YAAY,IAAI,iBAAiB,MAAM;AAC7C;;AAGA,eAAe,IAAI,UAAoC;CACrD,MAAM,QAAQ,gBAAgB;EAAE,OAAO,QAAQ;EAAO,QAAQ,QAAQ;CAAO,CAAC;CAC9E,IAAI;EACF,OAAO,CAAC,MAAM,MAAM,MAAM,MAAM,SAAS,GAAG,SAAS,QAAQ,EAAA,CAAG,KAAK,CAAC;CACxE,UAAU;EACR,MAAM,MAAM;CACd;AACF;AAEA,eAAsB,IAAI,QAAgF;CACxG,IAAI;EACF,MAAM,KAAK;GACT,KAAK,QAAQ,IAAI;GACjB,SAAS,OAAO;GAChB,OAAO,OAAO;GACd,QAAQ,OAAO;GACf,KAAK,QAAQ,MAAM,SAAS,QAAQ,OAAO,QAAQ,MAAM,KAAA;EAC3D,CAAC;CACH,SAAS,GAAG;EACV,KAAK,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;CACjD;AACF"}
|
package/dist/shared/packages.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
// package.json
|
|
5
5
|
var name = "deictic";
|
|
6
|
-
var version = "0.
|
|
6
|
+
var version = "0.6.0";
|
|
7
7
|
var peerDependencies = {
|
|
8
8
|
"@rrweb/rrweb-plugin-console-record": "^2.2.2",
|
|
9
9
|
"@rrweb/rrweb-plugin-network-record": "^2.2.2",
|
package/dist/shared/src.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * `deictic`: what a plugin is. Every plugin is optional: deictic itself is the glue (the\n * transform that ties elements to source, the dev server's endpoints, the history, shortcuts and the\n * overlay's panel), and each plugin adds what it does on top.\n *\n * A plugin has two halves, each optional that meet over the dev server's endpoints (`tools/endpoints.ts`). The\n * server half runs beside the bundler and is the only one that reads source: it turns the element\n * under the pointer into a model its panel can show, and an op from that panel into text edits. It\n * never writes files; deictic does, so every plugin's changes land in one history and undo the\n * same way. A change that isn't to a file (a task added to a board) the plugin makes itself and\n * answers with what it did (`Done`): the history keeps that beside the files' changes and hands it\n * back to the plugin's own `undo` and `redo`.\n * The client half is a module the page loads, named by the server half's `client`, which draws the\n * panel and previews an op on the page before it is applied.\n *\n * A plugin may have no panel at all, only an API for others (screenshots, a recording) and routes of\n * its own on the dev server. Each half's `setup` answers its API, and `use(name)` reaches another\n * plugin's, on the same side; `needs` names the plugins it can't do without.\n *\n * Both halves import from here, so the parser is imported for its types only: the browser must not load it.\n */\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport type { Shortcut } from './shortcut.ts';\n\nexport type { Modifier, Shortcut } from './shortcut.ts';\n\n/** A place in the source: the file from the project's root, with `/`, and the line and column, from 1. */\nexport interface Loc {\n file: string;\n line: number;\n column: number;\n}\n\n/** An element the pointer picked: where its opening tag starts, and the tag, which the server checks is still there. */\nexport interface Target {\n loc: Loc;\n tag: string;\n}\n\n/** Text in a file to replace, by UTF-16 offsets. `file` is the target's unless named, from the project's root. */\nexport interface TextEdit {\n file?: string;\n start: number;\n end: number;\n text: string;\n}\n\n/** What a server half reads: the target's file, parsed, and its element. */\nexport interface Source {\n /** The target's file, from the project's root. */\n file: string;\n code: string;\n /** The file's module; for an `.astro` component, its frontmatter's. */\n program: Program;\n /** The target's opening tag. */\n element: JSXOpeningElement;\n /** Another file under the project's root, for plugins whose edits go elsewhere (a locale's messages). */\n read(file: string): string;\n}\n\n/**\n * What answers the overlay's requests in a page with no dev server behind it (`deictic/vite`'s `standalone`): the\n * default export of a module of the page's. A request is one the endpoints would get, under `<base>__deictic/`;\n * the answer is theirs too (`{ model }`, `{ model, change }`, `{ problem }` with a status that isn't ok).\n */\nexport type Standalone = (request: Request) => Response | Promise<Response>;\n\n/** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */\nexport class Refusal extends Error {\n override name = 'Refusal';\n}\n\n/**\n * A change the plugin made itself, not to a file: what its `undo` and `redo` need to take it back and\n * make it again. JSON, since the history keeps it on disk across restarts of the dev server.\n */\nexport interface Done<Record = unknown> {\n done: Record;\n}\n\ntype Maybe<T> = T | Promise<T>;\n\n/**\n * Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:\n * `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.\n */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ServerApis {}\n\n/** The same, in the page: `declare module 'deictic' { interface ClientApis { screenshots: Capture } }`. */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ClientApis {}\n\n/** A plugin's API, by its name: what its package declared, or `unknown` for one that declared none. */\nexport type ApiOf<Apis, Name extends string> = Name extends keyof Apis ? Apis[Name] : unknown;\n\nexport interface ServerContext {\n /** The project's root, as an absolute path. */\n root: string;\n /**\n * Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded. One the plugin\n * `needs` always is; any other may not be, so check.\n */\n use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;\n}\n\n/**\n * A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must\n * change nothing: anything else reaches it only from the page itself, which deictic checks.\n */\nexport type Route = (request: Request, context: ServerContext) => Maybe<Response>;\n\nexport interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = unknown> {\n /** Ties the halves together; also the label of its changes in the history, and its routes' path. Lowercase, with `-`. */\n name: string;\n /** The module the page loads for this plugin's half there, which default-exports its `ClientPlugin`. */\n client?: string;\n /** What the page half gets as `context.options`: the user's options it needs there, as JSON. */\n clientOptions?: unknown;\n /** What opens its panel: its own default, which its options let the user change. A plugin with no panel has none. */\n shortcut?: Shortcut;\n /** The plugins it can't do without, by name: the dev server won't start without them. */\n needs?: string[];\n /**\n * The packages it imports that the project installs itself (optional peers), by name: as the dev server starts,\n * it says how to install any that's missing, rather than failing when first used.\n */\n packages?: string[];\n /** Runs once, as the dev server starts and before it answers anything. Answers the plugin's API to the others. */\n setup?(context: ServerContext): Maybe<Api>;\n /** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */\n routes?: { [route: string]: Route };\n /** The model its panel shows for an element. Without it, the panel gets none. */\n read?(source: Source, target: Target): Maybe<Model>;\n /** Text edits for deictic to write, or a change the plugin made itself. */\n apply?(source: Source, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;\n /**\n * Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may\n * answer what the next redo needs, where that differs (what it put back has a new ID).\n */\n undo?(record: Record): Maybe<void | Record>;\n /** Makes it again after an undo, and answers what the next undo needs, which may differ (a new ID). */\n redo?(record: Record): Maybe<Record>;\n /** Says what an op does, for the history: `className: px-2 → px-4`. */\n describe?(op: Op, before: Model): string;\n}\n\nexport const definePlugin = <Model, Op, Record = unknown, Api = unknown>(\n plugin: ServerPlugin<Model, Op, Record, Api>,\n): ServerPlugin<Model, Op, Record, Api> => plugin;\n\nexport interface ClientContext {\n /** The dev server's base URL, ending in `/`. */\n base: string;\n /** deictic's shadow root, to draw in: neither the page's styles nor the overlay's cross over. */\n root: ShadowRoot;\n /** The server half's `clientOptions`, or nothing. */\n options: unknown;\n /** Another plugin's API in the page, as its `setup` answered it, or nothing when it isn't loaded. */\n use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;\n /** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */\n request: (route: string, init?: RequestInit) => Promise<Response>;\n /**\n * Opens the popup on an element at a plugin's tab, as its shortcut would: after a recording, say. An\n * element rendered again since stands in for one no longer on the page. False when there's no such tab\n * or no such element any more. Not from `setup`, which runs before the popup can open.\n */\n open: (plugin: string, element: Element) => boolean;\n /**\n * Shows `items` in the lightbox over everything, at `at` (the first by default), stepping between them with\n * ← and →. With `from`, it grows out of that element (the chip clicked) and shrinks back into it on close.\n */\n lightbox: (items: LightboxItem[], options?: LightboxOptions) => { close: () => void };\n}\n\n/** What the lightbox shows: a picture, a page in a frame (a recording's replay), or a sound with its waveform. */\nexport type LightboxItem = {\n /** Its name, over it. */\n title: string;\n /** Buttons beside the name: each closes the lightbox and runs. */\n actions?: LightboxAction[];\n} & ({ kind: 'image'; url: string } | { kind: 'page'; url: string } | { kind: 'audio'; url: string });\n\nexport interface LightboxAction {\n label: string;\n title?: string;\n run: () => void;\n}\n\nexport interface LightboxOptions {\n /** The item it opens at. */\n at?: number;\n /** The element it grows out of, and goes back into. */\n from?: Element;\n}\n\nexport interface PanelContext<Model, Op> extends ClientContext {\n /**\n * The element clicked: the one the source marked, under the pointer or around what is. Back from `away`\n * it may be off the page (`isConnected` is false), where the page moved on without it: the element as it\n * was left, or after a page load an empty one of its tag and mark. `elements` is then empty.\n */\n element: Element;\n /**\n * What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a\n * dependency's, or in an open shadow root, as the popup's own on a page that shows it (`popupIn`).\n */\n pointed?: Element;\n /** Every element on the page from the same place in the source, the clicked one among them: the rows of a list. */\n elements: Element[];\n target: Target;\n model: Model;\n /** Applies an op on disk, and reads the model again. Rejects with the server's reason, which the panel also shows. */\n apply(op: Op): Promise<Model>;\n close: () => void;\n /**\n * Says there's something here that leaving would lose (words typed, a change tried on the page), and the button\n * that keeps it: a click outside the popup then shakes that button, where it would have closed the popup.\n * `undefined` once there's nothing to lose. Forgotten as the panel unmounts.\n */\n unsaved: (action: HTMLElement | undefined) => void;\n /**\n * Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a\n * pick of another element), and opens it again at this tab on this element. The next mount gets\n * `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why\n * it failed. The state stays in the page, as it is: no need for JSON. It's also kept for the tab's next\n * page, as a structured clone, where it can be one: after a page load, the plugin's `resume` says whether\n * the task carries on, and the popup comes back there.\n */\n away: <T>(state: unknown, task: () => Promise<T>) => void;\n /** Set when this mount is the panel coming back from `away`. */\n resumed?: Resumed;\n}\n\n/** What a panel coming back from `away` gets: the state it kept, and the task's result or problem. */\nexport interface Resumed {\n state: unknown;\n result?: unknown;\n /** Why the task failed: its error's message. */\n problem?: string;\n}\n\nexport interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {\n /** The server half's `name`. */\n name: string;\n /** Shown over the element while its shortcut's keys are held, and atop the panel. */\n label?: string;\n /**\n * Runs once, as the page starts, before any panel opens (a recording starts here). Answers the\n * plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.\n */\n setup?(context: ClientContext): Api;\n /**\n * Asked as a page starts where the page before it left this plugin's panel `away`: the task it left for,\n * where that carries on in this page (a recording does), or nothing where it ended with the page. When it's\n * done the popup opens at this tab with `resumed`, on the element where this page has it and without where not.\n */\n resume?(context: ClientContext): Promise<unknown> | undefined;\n /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */\n mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;\n}\n\nexport const defineClientPlugin = <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>): ClientPlugin<Model, Op, Api> => plugin;\n"],"mappings":";;AAqEA,IAAa,UAAb,cAA6B,MAAM;CACxB,OAAO;AAClB;AA6EA,MAAa,gBACX,WACyC;AAiH3C,MAAa,sBAAgD,WAAuE"}
|
|
1
|
+
{"version":3,"file":"src.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * `deictic`: what a plugin is. Every plugin is optional: deictic itself is the glue (the\n * transform that ties elements to source, the dev server's endpoints, the history, shortcuts and the\n * overlay's panel), and each plugin adds what it does on top.\n *\n * A plugin has two halves, each optional that meet over the dev server's endpoints (`tools/endpoints.ts`). The\n * server half runs beside the bundler and is the only one that reads source: it turns the element\n * under the pointer into a model its panel can show, and an op from that panel into text edits. It\n * never writes files; deictic does, so every plugin's changes land in one history and undo the\n * same way. A change that isn't to a file (a task added to a board) the plugin makes itself and\n * answers with what it did (`Done`): the history keeps that beside the files' changes and hands it\n * back to the plugin's own `undo` and `redo`.\n * The client half is a module the page loads, named by the server half's `client`, which draws the\n * panel and previews an op on the page before it is applied.\n *\n * A plugin may have no panel at all, only an API for others (screenshots, a recording) and routes of\n * its own on the dev server. Each half's `setup` answers its API, and `use(name)` reaches another\n * plugin's, on the same side; `needs` names the plugins it can't do without.\n *\n * Both halves import from here, so the parser is imported for its types only: the browser must not load it.\n */\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport type { Shortcut } from './shortcut.ts';\n\nexport type { Modifier, Shortcut } from './shortcut.ts';\n\n/** A place in the source: the file from the project's root, with `/`, and the line and column, from 1. */\nexport interface Loc {\n file: string;\n line: number;\n column: number;\n}\n\n/** An element the pointer picked: where its opening tag starts, and the tag, which the server checks is still there. */\nexport interface Target {\n loc: Loc;\n tag: string;\n}\n\n/** Text in a file to replace, by UTF-16 offsets. `file` is the target's unless named, from the project's root. */\nexport interface TextEdit {\n file?: string;\n start: number;\n end: number;\n text: string;\n}\n\n/** What a server half reads: the target's file, parsed, and its element. */\nexport interface Source {\n /** The target's file, from the project's root. */\n file: string;\n code: string;\n /** The file's module; for an `.astro` component, its frontmatter's. */\n program: Program;\n /** The target's opening tag. */\n element: JSXOpeningElement;\n /** Another file under the project's root, for plugins whose edits go elsewhere (a locale's messages). */\n read(file: string): string;\n}\n\n/**\n * What answers the overlay's requests in a page with no dev server behind it (`deictic/vite`'s `standalone`): the\n * default export of a module of the page's. A request is one the endpoints would get, under `<base>__deictic/`;\n * the answer is theirs too (`{ model }`, `{ model, change }`, `{ problem }` with a status that isn't ok).\n */\nexport type Standalone = (request: Request) => Response | Promise<Response>;\n\n/** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */\nexport class Refusal extends Error {\n override name = 'Refusal';\n}\n\n/**\n * A change the plugin made itself, not to a file: what its `undo` and `redo` need to take it back and\n * make it again. JSON, since the history keeps it on disk across restarts of the dev server.\n */\nexport interface Done<Record = unknown> {\n done: Record;\n}\n\ntype Maybe<T> = T | Promise<T>;\n\n/**\n * Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:\n * `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.\n */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ServerApis {}\n\n/** The same, in the page: `declare module 'deictic' { interface ClientApis { screenshots: Capture } }`. */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ClientApis {}\n\n/** A plugin's API, by its name: what its package declared, or `unknown` for one that declared none. */\nexport type ApiOf<Apis, Name extends string> = Name extends keyof Apis ? Apis[Name] : unknown;\n\nexport interface ServerContext {\n /** The project's root, as an absolute path. */\n root: string;\n /**\n * Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded. One the plugin\n * `needs` always is; any other may not be, so check.\n */\n use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;\n}\n\n/**\n * A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must\n * change nothing: anything else reaches it only from the page itself, which deictic checks.\n */\nexport type Route = (request: Request, context: ServerContext) => Maybe<Response>;\n\nexport interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = unknown> {\n /** Ties the halves together; also the label of its changes in the history, and its routes' path. Lowercase, with `-`. */\n name: string;\n /** The module the page loads for this plugin's half there, which default-exports its `ClientPlugin`. */\n client?: string;\n /** What the page half gets as `context.options`: the user's options it needs there, as JSON. */\n clientOptions?: unknown;\n /** What opens its panel: its own default, which its options let the user change. A plugin with no panel has none. */\n shortcut?: Shortcut;\n /** The plugins it can't do without, by name: the dev server won't start without them. */\n needs?: string[];\n /**\n * The packages it imports that the project installs itself (optional peers), by name: as the dev server starts,\n * it says how to install any that's missing, rather than failing when first used.\n */\n packages?: string[];\n /** Runs once, as the dev server starts and before it answers anything. Answers the plugin's API to the others. */\n setup?(context: ServerContext): Maybe<Api>;\n /** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */\n routes?: { [route: string]: Route };\n /**\n * The model its panel shows for an element. Without it, the panel gets none. `source` is a `Refusal` where the\n * 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\n * the plugin needs the source, or go on without it, as a task does.\n */\n read?(source: Source | Refusal, target: Target): Maybe<Model>;\n /** Text edits for deictic to write, which it refuses without the source, or a change the plugin made itself. */\n apply?(source: Source | Refusal, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;\n /**\n * Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may\n * answer what the next redo needs, where that differs (what it put back has a new ID).\n */\n undo?(record: Record): Maybe<void | Record>;\n /** Makes it again after an undo, and answers what the next undo needs, which may differ (a new ID). */\n redo?(record: Record): Maybe<Record>;\n /** Says what an op does, for the history: `className: px-2 → px-4`. */\n describe?(op: Op, before: Model): string;\n}\n\nexport const definePlugin = <Model, Op, Record = unknown, Api = unknown>(\n plugin: ServerPlugin<Model, Op, Record, Api>,\n): ServerPlugin<Model, Op, Record, Api> => plugin;\n\nexport interface ClientContext {\n /** The dev server's base URL, ending in `/`. */\n base: string;\n /** deictic's shadow root, to draw in: neither the page's styles nor the overlay's cross over. */\n root: ShadowRoot;\n /** The server half's `clientOptions`, or nothing. */\n options: unknown;\n /** Another plugin's API in the page, as its `setup` answered it, or nothing when it isn't loaded. */\n use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;\n /** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */\n request: (route: string, init?: RequestInit) => Promise<Response>;\n /**\n * Opens the popup on an element at a plugin's tab, as its shortcut would: after a recording, say. An\n * element rendered again since stands in for one no longer on the page. False when there's no such tab\n * or no such element any more. Not from `setup`, which runs before the popup can open.\n */\n open: (plugin: string, element: Element) => boolean;\n /**\n * Shows `items` in the lightbox over everything, at `at` (the first by default), stepping between them with\n * ← and →. With `from`, it grows out of that element (the chip clicked) and shrinks back into it on close.\n */\n lightbox: (items: LightboxItem[], options?: LightboxOptions) => { close: () => void };\n}\n\n/** What the lightbox shows: a picture, a page in a frame (a recording's replay), or a sound with its waveform. */\nexport type LightboxItem = {\n /** Its name, over it. */\n title: string;\n /** Buttons beside the name: each closes the lightbox and runs. */\n actions?: LightboxAction[];\n} & ({ kind: 'image'; url: string } | { kind: 'page'; url: string } | { kind: 'audio'; url: string });\n\nexport interface LightboxAction {\n label: string;\n title?: string;\n run: () => void;\n}\n\nexport interface LightboxOptions {\n /** The item it opens at. */\n at?: number;\n /** The element it grows out of, and goes back into. */\n from?: Element;\n}\n\nexport interface PanelContext<Model, Op> extends ClientContext {\n /**\n * The element clicked: the one the source marked, under the pointer or around what is. Back from `away`\n * it may be off the page (`isConnected` is false), where the page moved on without it: the element as it\n * was left, or after a page load an empty one of its tag and mark. `elements` is then empty.\n */\n element: Element;\n /**\n * What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a\n * dependency's, or in an open shadow root, as the popup's own on a page that shows it (`popupIn`).\n */\n pointed?: Element;\n /** Every element on the page from the same place in the source, the clicked one among them: the rows of a list. */\n elements: Element[];\n target: Target;\n model: Model;\n /** Applies an op on disk, and reads the model again. Rejects with the server's reason, which the panel also shows. */\n apply(op: Op): Promise<Model>;\n close: () => void;\n /**\n * Says there's something here that leaving would lose (words typed, a change tried on the page), and the button\n * that keeps it: a click outside the popup then shakes that button, where it would have closed the popup.\n * `undefined` once there's nothing to lose. Forgotten as the panel unmounts.\n */\n unsaved: (action: HTMLElement | undefined) => void;\n /**\n * Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a\n * pick of another element), and opens it again at this tab on this element. The next mount gets\n * `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why\n * it failed. The state stays in the page, as it is: no need for JSON. It's also kept for the tab's next\n * page, as a structured clone, where it can be one: after a page load, the plugin's `resume` says whether\n * the task carries on, and the popup comes back there.\n */\n away: <T>(state: unknown, task: () => Promise<T>) => void;\n /** Set when this mount is the panel coming back from `away`. */\n resumed?: Resumed;\n}\n\n/** What a panel coming back from `away` gets: the state it kept, and the task's result or problem. */\nexport interface Resumed {\n state: unknown;\n result?: unknown;\n /** Why the task failed: its error's message. */\n problem?: string;\n}\n\nexport interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {\n /** The server half's `name`. */\n name: string;\n /** Shown over the element while its shortcut's keys are held, and atop the panel. */\n label?: string;\n /**\n * Runs once, as the page starts, before any panel opens (a recording starts here). Answers the\n * plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.\n */\n setup?(context: ClientContext): Api;\n /**\n * Asked as a page starts where the page before it left this plugin's panel `away`: the task it left for,\n * where that carries on in this page (a recording does), or nothing where it ended with the page. When it's\n * done the popup opens at this tab with `resumed`, on the element where this page has it and without where not.\n */\n resume?(context: ClientContext): Promise<unknown> | undefined;\n /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */\n mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;\n}\n\nexport const defineClientPlugin = <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>): ClientPlugin<Model, Op, Api> => plugin;\n"],"mappings":";;AAqEA,IAAa,UAAb,cAA6B,MAAM;CACxB,OAAO;AAClB;AAiFA,MAAa,gBACX,WACyC;AAiH3C,MAAa,sBAAgD,WAAuE"}
|
package/dist/shared/task.js
CHANGED
|
@@ -23,6 +23,7 @@ function run(id, values) {
|
|
|
23
23
|
const facts = [
|
|
24
24
|
["deictic.project", (v) => `Project ${v}`],
|
|
25
25
|
["deictic.at", (v) => `${v} <${label("deictic.tag") ?? "?"}>`],
|
|
26
|
+
["deictic.source", (v) => `Source: ${at?.replace(/:\d+$/, "") ?? "?"} ← ${v}`],
|
|
26
27
|
["deictic.url", (v) => v],
|
|
27
28
|
["deictic.viewport", (v) => `Viewport ${v}`],
|
|
28
29
|
["deictic.count", (v) => v === "1" ? void 0 : `${v} elements on the page come from that line`],
|
|
@@ -33,15 +34,50 @@ function run(id, values) {
|
|
|
33
34
|
const line = value === void 0 ? void 0 : say(value);
|
|
34
35
|
if (line !== void 0) console.log(line);
|
|
35
36
|
}
|
|
37
|
+
for (const line of drawn(root)) console.log(line);
|
|
36
38
|
const told = (pointed ? where.slice(0, pointed.index) : where).trim();
|
|
37
39
|
if (told !== "") console.log(told);
|
|
38
40
|
if (pointed) console.log(`\nPointed at, inside it: ${pointed[1]}\n ${pointed[2]}`);
|
|
41
|
+
const path = label("deictic.pointed");
|
|
42
|
+
if (path !== void 0) {
|
|
43
|
+
const file = root.attachments.some((a) => a.name === "pointed.html") ? "pointed.html" : "element.html";
|
|
44
|
+
console.log(`\nPointed at, inside it: ${path} (its HTML is in ${file})`);
|
|
45
|
+
}
|
|
39
46
|
if (at !== void 0) placeOf(at, label("deictic.line"));
|
|
40
47
|
attachments(root, values.out === void 0 ? void 0 : resolve(values.out));
|
|
41
48
|
if (replies.length > 0) console.log("\nReplies:");
|
|
42
49
|
for (const r of replies) console.log(` ${r.author?.handle ?? r.by.actor}: ${r.text}`);
|
|
43
50
|
others(root);
|
|
44
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* What the attached files don't say, from the numbered labels: where the element is in each shot and the notes on it, the
|
|
54
|
+
* notes drawn on the page, where each recording replays, and what wasn't kept any more.
|
|
55
|
+
*/
|
|
56
|
+
function drawn({ labels, attachments }) {
|
|
57
|
+
const numbered = (prefix) => {
|
|
58
|
+
const out = [];
|
|
59
|
+
for (let n = 1; labels[`${prefix}.${n}`] !== void 0; n++) out.push(labels[`${prefix}.${n}`]);
|
|
60
|
+
return out;
|
|
61
|
+
};
|
|
62
|
+
const notes = (prefix) => numbered(`${prefix}.note`).map((note) => JSON.stringify(note));
|
|
63
|
+
const lines = [];
|
|
64
|
+
for (const [i, { name }] of attachments.filter((a) => a.type === "image/png").entries()) {
|
|
65
|
+
const shot = `deictic.screenshot.${i + 1}`;
|
|
66
|
+
const position = labels[`${shot}.position`];
|
|
67
|
+
if (position === void 0) continue;
|
|
68
|
+
const said = notes(shot);
|
|
69
|
+
lines.push(`${name}: the element at x,y ${position}, ${labels[`${shot}.size`] ?? "?"} (CSS pixels from its top left)${said.length === 0 ? "" : `; notes drawn on it: ${said.join(", ")}`}`);
|
|
70
|
+
}
|
|
71
|
+
const onPage = notes("deictic");
|
|
72
|
+
if (onPage.length > 0) lines.push(`Notes drawn on the page: ${onPage.join(", ")}`);
|
|
73
|
+
for (const [i, { name }] of attachments.filter((a) => a.name.startsWith("recording-")).entries()) {
|
|
74
|
+
const replay = labels[`deictic.recording.${i + 1}.replay`];
|
|
75
|
+
if (replay !== void 0) lines.push(`${name} replays at ${replay}`);
|
|
76
|
+
}
|
|
77
|
+
const dropped = numbered("deictic.dropped");
|
|
78
|
+
if (dropped.length > 0) lines.push(`Not attached, as it wasn't kept any more: ${dropped.join(", ")}`);
|
|
79
|
+
return lines;
|
|
80
|
+
}
|
|
45
81
|
/** The place as the task saw it, against the file now: the element's opening tag may have moved or changed. */
|
|
46
82
|
function placeOf(at, first) {
|
|
47
83
|
const file = at.replace(/:\d+:\d+$/, "");
|
package/dist/shared/task.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.js","names":[],"sources":["../../src/cli/task.ts"],"sourcesContent":["/**\n * `deictic task`: a task, briefly: what was asked, where (and whether that place has moved in the source since), the\n * page, what's attached with the command to look at each, the replies, and the other open tasks about the same page.\n */\nimport { existsSync, mkdirSync, readFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\n\nimport { deicticDirs, download, ME, type Message, read, vbJson } from './board.ts';\n\n/** An actor by the profile its ID ends in (`…+claude`), or the ID of one that writes as itself. */\nconst nameOf = (actor: string) => (actor.includes('+') ? actor.slice(actor.lastIndexOf('+') + 1) : actor);\n\nexport function run(id: string, values: { out?: string }): void {\n const { message: root, replies } = read(id);\n const [asked = '', where = ''] = root.text.split(/\\n---\\n/);\n const label = (key: string) => root.labels[key];\n const at = label('deictic.at');\n\n // Who asked, said as that: the line's state is beside it, and a board's record names no one for a task's end.\n console.log(`#${root.id} ${root.task?.state ?? 'not a task'}, asked by ${root.author?.handle ?? root.by.actor}, ${root.createdAt}`);\n const claim = root.task?.claim;\n if (claim) console.log(`Claimed by ${nameOf(claim.actor)} until ${claim.until}`);\n // A task not over yet has them, as null.\n if (root.task?.result != null) console.log(`Result: ${root.task.result}`);\n if (root.task?.reason != null) console.log(`Reason: ${root.task.reason}`);\n console.log(`\\nAsked:\\n${asked.trim()}\\n`);\n // The part inside the element that was pointed at, where nothing marked it: what the person means.\n const pointed = /\\nPointed at, inside it: `([^`]*)`\\n`{3,}\\w*\\n([\\s\\S]*?)\\n`{3,}/.exec(where);\n // Where, from the labels: the place, the page, and the viewport to look at it in.\n const facts: [string, (v: string) => string | undefined][] = [\n ['deictic.project', (v) => `Project ${v}`],\n ['deictic.at', (v) => `${v} <${label('deictic.tag') ?? '?'}>`],\n ['deictic.url', (v) => v],\n ['deictic.viewport', (v) => `Viewport ${v}`],\n ['deictic.count', (v) => (v === '1' ? undefined : `${v} elements on the page come from that line`)],\n ['deictic.position', (v) => `In the screenshot at x,y ${v}, ${label('deictic.size') ?? '?'} (CSS pixels from its top left)`],\n ];\n for (const [key, say] of facts) {\n const value = label(key);\n const line = value === undefined ? undefined : say(value);\n if (line !== undefined) console.log(line);\n }\n // What no label holds: what's attached and drawn on it.\n const told = (pointed ? where.slice(0, pointed.index) : where).trim();\n if (told !== '') console.log(told);\n if (pointed) console.log(`\\nPointed at, inside it: ${pointed[1]}\\n ${pointed[2]}`);\n\n if (at !== undefined) placeOf(at, label('deictic.line'));\n attachments(root, values.out === undefined ? undefined : resolve(values.out));\n\n if (replies.length > 0) console.log('\\nReplies:');\n for (const r of replies) console.log(` ${r.author?.handle ?? r.by.actor}: ${r.text}`);\n others(root);\n}\n\n/** The place as the task saw it, against the file now: the element's opening tag may have moved or changed. */\nfunction placeOf(at: string, first: string | undefined): void {\n const file = at.replace(/:\\d+:\\d+$/, '');\n const line = Number(at.split(':').at(-2));\n // Marks are from the dev server's root: here, above, or a folder with a .deictic/ of its own.\n const roots = [process.cwd(), ...deicticDirs().map(dirname)];\n const path = roots.map((r) => resolve(r, file)).find((p) => existsSync(p));\n if (path === undefined) {\n console.log(`\\n${file} isn't under ${roots.join(' or ')}: find the dev server's root.`);\n return;\n }\n const lines = readFileSync(path, 'utf8').split('\\n');\n // The tag's first line may follow other code on its line: `const App = () => <h1>`.\n const now = lines[line - 1]?.trim();\n if (first === undefined || now?.includes(first.slice(0, 40))) {\n console.log(`\\nFile: ${path}:${line}, as the task saw it.`);\n return;\n }\n const moved = lines.findIndex((l) => l.includes(first.slice(0, 40)));\n console.log(\n moved >= 0\n ? `\\nFile: moved to ${path}:${moved + 1} (the task says line ${line}).`\n : `\\nFile: ${path}:${line} no longer reads as the task saw it; it was:\\n ${first}`,\n );\n}\n\n/** What's attached, with the command to look at each, downloaded to `out` where it's given. */\nfunction attachments(root: Message, out: string | undefined): void {\n if (root.attachments.length > 0) console.log('\\nAttached:');\n if (out !== undefined) mkdirSync(out, { recursive: true });\n for (const a of root.attachments) {\n const kb = `${Math.round(a.size / 1024)} KB`;\n if (out !== undefined) download(a, join(out, a.name));\n const saved = out === undefined ? '' : ` → ${join(out, a.name)}`;\n // To a file's path: the CLI writes what it's given, and refuses a folder.\n const get = saved || `: ${ME} vb download ${a.id} ${a.name}`;\n if (a.name.startsWith('recording-')) {\n console.log(` ${a.name} (${kb})${saved}`);\n console.log(` timeline: ${ME} recording ${root.id}`);\n console.log(` frames: ${ME} frame ${root.id}`);\n } else if (a.name.startsWith('voice-')) {\n console.log(` ${a.name} (${kb}), a voice clip${saved}`);\n console.log(` speech: ${ME} voice ${root.id}`);\n } else if (a.name === 'element.html') {\n console.log(` ${a.name} (${kb}), the element's HTML as it rendered, if you need it${get}`);\n } else {\n console.log(` ${a.name} (${a.type}, ${kb})${get}`);\n }\n }\n}\n\n/** The other open tasks about the same page, of the same project: left a minute apart, they're often one change. */\nfunction others(root: Message): void {\n const page = root.labels['deictic.page'];\n if (page === undefined) return;\n const project = root.labels['deictic.project'];\n const labels = [`deictic.page=${page}`, ...(project === undefined ? [] : [`deictic.project=${project}`])];\n const { tasks } = vbJson<{ tasks: { message: Message }[] }>(['tasks', root.channel, ...labels.flatMap((l) => ['--label', l])]);\n const rest = tasks.map((t) => t.message).filter((m) => m.id !== root.id);\n if (rest.length === 0) return;\n console.log(\n `\\n${rest.length} other open task${rest.length === 1 ? '' : 's'} on ${page}: read them before you start, they may be one change.`,\n );\n for (const m of rest) {\n const title = (m.text.split(/\\n---\\n/)[0] ?? '').split('\\n')[0]?.slice(0, 100);\n console.log(` #${m.id} ${m.task?.state ?? ''}, ${m.labels['deictic.at'] ?? '?'}: ${title}`);\n }\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,UAAU,UAAmB,MAAM,SAAS,GAAG,IAAI,MAAM,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI;AAEnG,SAAgB,IAAI,IAAY,QAAgC;CAC9D,MAAM,EAAE,SAAS,MAAM,YAAY,KAAK,EAAE;CAC1C,MAAM,CAAC,QAAQ,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,SAAS;CAC1D,MAAM,SAAS,QAAgB,KAAK,OAAO;CAC3C,MAAM,KAAK,MAAM,YAAY;CAG7B,QAAQ,IAAI,IAAI,KAAK,GAAG,GAAG,KAAK,MAAM,SAAS,aAAa,aAAa,KAAK,QAAQ,UAAU,KAAK,GAAG,MAAM,IAAI,KAAK,WAAW;CAClI,MAAM,QAAQ,KAAK,MAAM;CACzB,IAAI,OAAO,QAAQ,IAAI,cAAc,OAAO,MAAM,KAAK,EAAE,SAAS,MAAM,OAAO;CAE/E,IAAI,KAAK,MAAM,UAAU,MAAM,QAAQ,IAAI,WAAW,KAAK,KAAK,QAAQ;CACxE,IAAI,KAAK,MAAM,UAAU,MAAM,QAAQ,IAAI,WAAW,KAAK,KAAK,QAAQ;CACxE,QAAQ,IAAI,aAAa,MAAM,KAAK,EAAE,GAAG;CAEzC,MAAM,UAAU,kEAAkE,KAAK,KAAK;CAE5F,MAAM,QAAuD;EAC3D,CAAC,oBAAoB,MAAM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,IAAI,MAAM,EAAE,GAAG,GAAG,EAAE,MAAM,SAAS,GAAG,IAAI,EAAE,OAAO,iBAAiB,IAAI,IAAI,OAAO;CAC7F;AACF"}
|
|
1
|
+
{"version":3,"file":"task.js","names":[],"sources":["../../src/cli/task.ts"],"sourcesContent":["/**\n * `deictic task`: a task, briefly: what was asked, where (and whether that place has moved in the source since), the\n * page, what's attached with the command to look at each, the replies, and the other open tasks about the same page.\n */\nimport { existsSync, mkdirSync, readFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\n\nimport { deicticDirs, download, ME, type Message, read, vbJson } from './board.ts';\n\n/** An actor by the profile its ID ends in (`…+claude`), or the ID of one that writes as itself. */\nconst nameOf = (actor: string) => (actor.includes('+') ? actor.slice(actor.lastIndexOf('+') + 1) : actor);\n\nexport function run(id: string, values: { out?: string }): void {\n const { message: root, replies } = read(id);\n const [asked = '', where = ''] = root.text.split(/\\n---\\n/);\n const label = (key: string) => root.labels[key];\n const at = label('deictic.at');\n\n // Who asked, said as that: the line's state is beside it, and a board's record names no one for a task's end.\n console.log(`#${root.id} ${root.task?.state ?? 'not a task'}, asked by ${root.author?.handle ?? root.by.actor}, ${root.createdAt}`);\n const claim = root.task?.claim;\n if (claim) console.log(`Claimed by ${nameOf(claim.actor)} until ${claim.until}`);\n // A task not over yet has them, as null.\n if (root.task?.result != null) console.log(`Result: ${root.task.result}`);\n if (root.task?.reason != null) console.log(`Reason: ${root.task.reason}`);\n console.log(`\\nAsked:\\n${asked.trim()}\\n`);\n // The part inside the element that was pointed at, where nothing marked it: what the person means.\n const pointed = /\\nPointed at, inside it: `([^`]*)`\\n`{3,}\\w*\\n([\\s\\S]*?)\\n`{3,}/.exec(where);\n // Where, from the labels: the place, the page, and the viewport to look at it in.\n const facts: [string, (v: string) => string | undefined][] = [\n ['deictic.project', (v) => `Project ${v}`],\n ['deictic.at', (v) => `${v} <${label('deictic.tag') ?? '?'}>`],\n // From its own line out: before the label, tasks said it in their text, which is printed below as it is.\n ['deictic.source', (v) => `Source: ${at?.replace(/:\\d+$/, '') ?? '?'} ← ${v}`],\n ['deictic.url', (v) => v],\n ['deictic.viewport', (v) => `Viewport ${v}`],\n ['deictic.count', (v) => (v === '1' ? undefined : `${v} elements on the page come from that line`)],\n // A task added before shots were numbered had its one shot's place here.\n ['deictic.position', (v) => `In the screenshot at x,y ${v}, ${label('deictic.size') ?? '?'} (CSS pixels from its top left)`],\n ];\n for (const [key, say] of facts) {\n const value = label(key);\n const line = value === undefined ? undefined : say(value);\n if (line !== undefined) console.log(line);\n }\n for (const line of drawn(root)) console.log(line);\n // A task added before these were labels says them after its words.\n const told = (pointed ? where.slice(0, pointed.index) : where).trim();\n if (told !== '') console.log(told);\n if (pointed) console.log(`\\nPointed at, inside it: ${pointed[1]}\\n ${pointed[2]}`);\n const path = label('deictic.pointed');\n if (path !== undefined) {\n const file = root.attachments.some((a) => a.name === 'pointed.html') ? 'pointed.html' : 'element.html';\n console.log(`\\nPointed at, inside it: ${path} (its HTML is in ${file})`);\n }\n\n if (at !== undefined) placeOf(at, label('deictic.line'));\n attachments(root, values.out === undefined ? undefined : resolve(values.out));\n\n if (replies.length > 0) console.log('\\nReplies:');\n for (const r of replies) console.log(` ${r.author?.handle ?? r.by.actor}: ${r.text}`);\n others(root);\n}\n\n/**\n * What the attached files don't say, from the numbered labels: where the element is in each shot and the notes on it, the\n * notes drawn on the page, where each recording replays, and what wasn't kept any more.\n */\nfunction drawn({ labels, attachments }: Message): string[] {\n const numbered = (prefix: string) => {\n const out: string[] = [];\n for (let n = 1; labels[`${prefix}.${n}`] !== undefined; n++) out.push(labels[`${prefix}.${n}`]!);\n return out;\n };\n const notes = (prefix: string) => numbered(`${prefix}.note`).map((note) => JSON.stringify(note));\n const lines: string[] = [];\n // `deictic.screenshot.N` is the Nth PNG attached, `deictic.recording.N` the Nth recording.\n for (const [i, { name }] of attachments.filter((a) => a.type === 'image/png').entries()) {\n const shot = `deictic.screenshot.${i + 1}`;\n const position = labels[`${shot}.position`];\n if (position === undefined) continue;\n const said = notes(shot);\n lines.push(\n `${name}: the element at x,y ${position}, ${labels[`${shot}.size`] ?? '?'} (CSS pixels from its top left)${said.length === 0 ? '' : `; notes drawn on it: ${said.join(', ')}`}`,\n );\n }\n const onPage = notes('deictic');\n if (onPage.length > 0) lines.push(`Notes drawn on the page: ${onPage.join(', ')}`);\n for (const [i, { name }] of attachments.filter((a) => a.name.startsWith('recording-')).entries()) {\n const replay = labels[`deictic.recording.${i + 1}.replay`];\n if (replay !== undefined) lines.push(`${name} replays at ${replay}`);\n }\n const dropped = numbered('deictic.dropped');\n if (dropped.length > 0) lines.push(`Not attached, as it wasn't kept any more: ${dropped.join(', ')}`);\n return lines;\n}\n\n/** The place as the task saw it, against the file now: the element's opening tag may have moved or changed. */\nfunction placeOf(at: string, first: string | undefined): void {\n const file = at.replace(/:\\d+:\\d+$/, '');\n const line = Number(at.split(':').at(-2));\n // Marks are from the dev server's root: here, above, or a folder with a .deictic/ of its own.\n const roots = [process.cwd(), ...deicticDirs().map(dirname)];\n const path = roots.map((r) => resolve(r, file)).find((p) => existsSync(p));\n if (path === undefined) {\n console.log(`\\n${file} isn't under ${roots.join(' or ')}: find the dev server's root.`);\n return;\n }\n const lines = readFileSync(path, 'utf8').split('\\n');\n // The tag's first line may follow other code on its line: `const App = () => <h1>`.\n const now = lines[line - 1]?.trim();\n if (first === undefined || now?.includes(first.slice(0, 40))) {\n console.log(`\\nFile: ${path}:${line}, as the task saw it.`);\n return;\n }\n const moved = lines.findIndex((l) => l.includes(first.slice(0, 40)));\n console.log(\n moved >= 0\n ? `\\nFile: moved to ${path}:${moved + 1} (the task says line ${line}).`\n : `\\nFile: ${path}:${line} no longer reads as the task saw it; it was:\\n ${first}`,\n );\n}\n\n/** What's attached, with the command to look at each, downloaded to `out` where it's given. */\nfunction attachments(root: Message, out: string | undefined): void {\n if (root.attachments.length > 0) console.log('\\nAttached:');\n if (out !== undefined) mkdirSync(out, { recursive: true });\n for (const a of root.attachments) {\n const kb = `${Math.round(a.size / 1024)} KB`;\n if (out !== undefined) download(a, join(out, a.name));\n const saved = out === undefined ? '' : ` → ${join(out, a.name)}`;\n // To a file's path: the CLI writes what it's given, and refuses a folder.\n const get = saved || `: ${ME} vb download ${a.id} ${a.name}`;\n if (a.name.startsWith('recording-')) {\n console.log(` ${a.name} (${kb})${saved}`);\n console.log(` timeline: ${ME} recording ${root.id}`);\n console.log(` frames: ${ME} frame ${root.id}`);\n } else if (a.name.startsWith('voice-')) {\n console.log(` ${a.name} (${kb}), a voice clip${saved}`);\n console.log(` speech: ${ME} voice ${root.id}`);\n } else if (a.name === 'element.html') {\n console.log(` ${a.name} (${kb}), the element's HTML as it rendered, if you need it${get}`);\n } else {\n console.log(` ${a.name} (${a.type}, ${kb})${get}`);\n }\n }\n}\n\n/** The other open tasks about the same page, of the same project: left a minute apart, they're often one change. */\nfunction others(root: Message): void {\n const page = root.labels['deictic.page'];\n if (page === undefined) return;\n const project = root.labels['deictic.project'];\n const labels = [`deictic.page=${page}`, ...(project === undefined ? [] : [`deictic.project=${project}`])];\n const { tasks } = vbJson<{ tasks: { message: Message }[] }>(['tasks', root.channel, ...labels.flatMap((l) => ['--label', l])]);\n const rest = tasks.map((t) => t.message).filter((m) => m.id !== root.id);\n if (rest.length === 0) return;\n console.log(\n `\\n${rest.length} other open task${rest.length === 1 ? '' : 's'} on ${page}: read them before you start, they may be one change.`,\n );\n for (const m of rest) {\n const title = (m.text.split(/\\n---\\n/)[0] ?? '').split('\\n')[0]?.slice(0, 100);\n console.log(` #${m.id} ${m.task?.state ?? ''}, ${m.labels['deictic.at'] ?? '?'}: ${title}`);\n }\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,UAAU,UAAmB,MAAM,SAAS,GAAG,IAAI,MAAM,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI;AAEnG,SAAgB,IAAI,IAAY,QAAgC;CAC9D,MAAM,EAAE,SAAS,MAAM,YAAY,KAAK,EAAE;C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