deictic 0.4.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 +19 -8
- package/dist/cli.js +34 -28
- package/dist/cli.js.map +1 -1
- package/dist/shared/board.js +8 -19
- package/dist/shared/board.js.map +1 -1
- package/dist/shared/clean.js +105 -0
- package/dist/shared/clean.js.map +1 -0
- package/dist/shared/endpoints.js +35 -9
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/find.js +3 -2
- package/dist/shared/find.js.map +1 -1
- package/dist/shared/frame.js +4 -18
- package/dist/shared/frame.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 +17 -24
- package/dist/shared/init.js.map +1 -1
- package/dist/shared/local.js +2 -1
- package/dist/shared/local.js.map +1 -1
- package/dist/shared/packages.js +9 -2
- package/dist/shared/packages.js.map +1 -1
- package/dist/shared/recording.js +4 -27
- package/dist/shared/recording.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +43 -10
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +109 -115
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/transcribe.js +1 -128
- package/dist/shared/transcribe2.js +119 -0
- package/dist/shared/transcribe2.js.map +1 -0
- package/dist/shared/vb.js +2 -3
- package/dist/shared/vb.js.map +1 -1
- package/dist/shared/voice2.js +4 -17
- package/dist/shared/voice2.js.map +1 -1
- package/dist/shared/watch.js +56 -39
- package/dist/shared/watch.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/dist/tasks/index.js +1 -1
- package/package.json +2 -1
- package/skills/deictic/SKILL.md +5 -3
- package/skills/deictic/references/tasks.md +6 -5
- package/src/cli/board.ts +7 -13
- package/src/cli/clean.ts +104 -0
- package/src/cli/find.ts +3 -1
- package/src/cli/frame.ts +3 -13
- package/src/cli/init.ts +16 -20
- package/src/cli/recording.ts +15 -21
- package/src/cli/task.ts +49 -10
- package/src/cli/transcribe.ts +13 -16
- package/src/cli/vb.ts +0 -2
- package/src/cli/voice.ts +3 -12
- package/src/cli/watch.ts +58 -29
- package/src/cli.ts +130 -31
- 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/plugins/tasks/local.ts +2 -1
- package/src/tools/endpoints.ts +18 -7
- package/src/tools/packages.ts +3 -0
- package/src/tools/source.ts +25 -5
- package/dist/shared/transcribe.js.map +0 -1
package/API.md
CHANGED
|
@@ -20,12 +20,13 @@ adds it to the bundler's config, and offers the agent skill (`--dry-run`, `--no-
|
|
|
20
20
|
For Bun it writes `deictic.plugin.ts`, names it in `bunfig.toml` and spreads its routes into `Bun.serve`'s, where a
|
|
21
21
|
server of the project's has Bun bundle an HTML page (a Bun project that runs Vite or Next.js is theirs). This is what
|
|
22
22
|
it adds, and what to add by hand where it can't (a config it can't read). Every integration takes the same options
|
|
23
|
-
and runs in the dev server only.
|
|
23
|
+
and runs in the dev server only. deictic goes first among the plugins: one before it that changes a module would have
|
|
24
|
+
the page point at that plugin's code, not the file.
|
|
24
25
|
|
|
25
26
|
```ts
|
|
26
27
|
// Vite, and anything on it (React Router, TanStack Start…): vite.config.ts
|
|
27
28
|
import { deictic } from 'deictic/vite';
|
|
28
|
-
export default defineConfig({ plugins: [
|
|
29
|
+
export default defineConfig({ plugins: [deictic({ plugins: recommended() }), react()] });
|
|
29
30
|
|
|
30
31
|
// Next.js (`next dev`, Turbopack or webpack): next.config.ts
|
|
31
32
|
import { withDeictic } from 'deictic/next';
|
|
@@ -89,6 +90,10 @@ options under its name, and `false` leaves it out (`recommended({ logs: false, n
|
|
|
89
90
|
to pick them one by one.
|
|
90
91
|
|
|
91
92
|
What a project keeps (the history, shots, recordings, voice notes) is in `.deictic/`, which ignores itself in git.
|
|
93
|
+
Each plugin keeps only its latest (`keep`), so it doesn't grow for ever. `npx deictic clean` deletes the shots,
|
|
94
|
+
recordings and voice notes after saying how much they take and asking (tasks carry theirs on the board); name
|
|
95
|
+
`history`, `board` (the local board's tasks) or `all` for the rest, with the dev server stopped, and `transcribe` for
|
|
96
|
+
the transcription model, which is outside the project. With no terminal to ask on, it lists them, and deletes with `--yes`.
|
|
92
97
|
|
|
93
98
|
## Tasks
|
|
94
99
|
|
|
@@ -124,12 +129,15 @@ recommended({ tasks: { board: local({ port: 4200 }) } }); // the one on your mac
|
|
|
124
129
|
|
|
125
130
|
In the Task tab a task's dot says its state, and who holds it while it's claimed (`claimed by claude`).
|
|
126
131
|
|
|
127
|
-
A task is the words typed and
|
|
128
|
-
`file:line:column`), `deictic.file`, `deictic.url`, `deictic.viewport` and more, with your
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
A task's text is the words typed, and nothing else. The rest is its attachments and labels: `deictic.project`,
|
|
133
|
+
`deictic.at` (the element's `file:line:column`), `deictic.file`, `deictic.url`, `deictic.viewport` and more, with your
|
|
134
|
+
own beside them. What the attached files don't say is numbered from 1: `deictic.screenshot.1.position` and `.size`
|
|
135
|
+
are where the element is in the first PNG attached, and `.note.1` a note drawn on it; `deictic.note.1` is a note drawn
|
|
136
|
+
on the page; `deictic.recording.1.replay` is where the first recording plays back; `deictic.pointed` is the path to
|
|
137
|
+
what was pointed at inside the element; `deictic.dropped.1` is something attached that wasn't kept any more.
|
|
138
|
+
`deictic.source` is what it rendered through, out from its own place, as `Field (src/Field.tsx:20) ← Panel` (a shared
|
|
139
|
+
component's line is the same wherever it's used; these say where: with React in development the components that use
|
|
140
|
+
it, three at most, and otherwise the files around it). The element's HTML as it rendered is attached as `element.html`,
|
|
133
141
|
masked as screenshots are, for whoever can't open the page as you had it: a file, so the task stays short.
|
|
134
142
|
Untick **Attach HTML snapshot** for a task without it; `html: false` takes the box away. A screenshot attached by the box has the element outlined in it; one you annotated is as you drew it.
|
|
135
143
|
|
|
@@ -298,6 +306,9 @@ export default defineClientPlugin<Model, Op>({
|
|
|
298
306
|
screenshots and recordings.
|
|
299
307
|
- A change that isn't to a file answers `{ done: record }`, and the plugin's `undo` and `redo` get the record back.
|
|
300
308
|
- Throw a `Refusal` for an op the plugin won't make. The panel shows its message.
|
|
309
|
+
- `read` and `apply` get the element's source, or a `Refusal` saying why it isn't to be found (the file doesn't parse,
|
|
310
|
+
or the page runs other code than the file has): throw it where the plugin needs the source, or go on without, as
|
|
311
|
+
tasks do. Text edits without it are refused.
|
|
301
312
|
- A panel leaves the popup for something on the page with `away(state, task)`, and is mounted again with `resumed`.
|
|
302
313
|
Where the task outlasts a page load, as a recording does, the page half's `resume` answers it on the next page, and
|
|
303
314
|
the popup comes back there: on the element, or without it (`element.isConnected` is false) where that page has none.
|
package/dist/cli.js
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { Argument, Command } from "commander";
|
|
2
3
|
// src/cli.ts
|
|
3
4
|
/**
|
|
4
|
-
* The `deictic` command. `init` sets a project up, for the person; the rest are for
|
|
5
|
-
* as the skill says: the board, a watch, a task, and what a task carries. Each
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The `deictic` command. `init` sets a project up and `clean` deletes what it kept, for the person; the rest are for
|
|
6
|
+
* the agent that works the tasks, as the skill says: the board, a watch, a task, and what a task carries. Each is
|
|
7
|
+
* declared here, its arguments and options with what they do, which is all `--help` needs; what it runs is in `cli/`,
|
|
8
|
+
* imported only when it's run, so `deictic task` doesn't load the parser `init` edits configs with. Run in the
|
|
9
|
+
* project, where its board and `.deictic/` are: `npx deictic <command>`.
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
/** A repeatable option's values, in order. */
|
|
12
|
+
const all = (value, previous) => [...previous ?? [], value];
|
|
13
|
+
const RECORDING = "a task (68), a replay URL, a recording ID or a JSON file";
|
|
14
|
+
const CLIP = "a task, a replay URL, a recording ID, an audio file or a clip ID";
|
|
15
|
+
const program = new Command("deictic").usage("<command> [options]").enablePositionalOptions().helpOption("-h, --help", "says what a command takes").showHelpAfterError("(add --help for what it takes)").addHelpText("after", "\nRun in the project. deictic help <command>, or <command> --help, says what it takes.");
|
|
16
|
+
program.commandsGroup("Setting up and cleaning up:");
|
|
17
|
+
program.helpCommand("help [command]", "says what a command takes");
|
|
18
|
+
program.command("init").description("sets deictic up in this project").option("--dry-run", "says what it would do, and does none of it").option("--no-install", "doesn't install: says the command instead").option("--skill", "adds the agent skill without asking").option("--no-skill", "doesn't add the agent skill: says the command instead").action(async (options) => (await import("./shared/init.js")).run(options));
|
|
19
|
+
program.command("clean").description("deletes what deictic kept, after saying what and how big and asking").addArgument(new Argument("[parts...]", "what to delete: shots, recordings and voice clips by default").choices([
|
|
20
|
+
"screenshots",
|
|
21
|
+
"recordings",
|
|
22
|
+
"voice",
|
|
23
|
+
"history",
|
|
24
|
+
"board",
|
|
25
|
+
"all",
|
|
26
|
+
"transcribe"
|
|
27
|
+
])).option("-y, --yes", "deletes without asking: with no terminal to ask on, it doesn't delete without it").addHelpText("after", "\nhistory (undo) and board (the local board, its tasks) only with the dev server stopped. all is everything in\nthe project's .deictic/; transcribe is the transcription model, outside it, which every project shares.").action(async (parts, options) => (await import("./shared/clean.js")).run(parts, options));
|
|
28
|
+
program.commandsGroup("For the agent that works the tasks (the skill):");
|
|
29
|
+
program.command("vb").description("the board on the dev server: deictic vb whoami, deictic vb tasks claim 68 --lease 30m").argument("[args...]", "anything vb takes").helpOption(false).allowUnknownOption().passThroughOptions().action(async (args) => (await import("./shared/vb.js")).run(args));
|
|
30
|
+
program.command("watch").description("a line per new task, reply and cancellation").argument("[channel]", "the channel", "deictic").option("--idle <time>", "ends once the channel has had nothing for this long: 30m, 45s, 1h", "20m").option("--once", "ends at the first thing to act on").option("--label <key=value>", "only tasks with this label (repeatable)", all).action(async (channel, options) => (await import("./shared/watch.js")).run(channel, options));
|
|
31
|
+
program.command("task").description("a task briefly: what was asked, by whom, who holds it, what is attached").argument("<id>", "the task: 68 or #68").option("--out <dir>", "downloads what is attached here").action(async (id, options) => (await import("./shared/task.js")).run(id, options));
|
|
32
|
+
program.command("recording").description("a recording as a timeline, or the part of it asked for").argument("<recording>", RECORDING).option("--nth <n>", "a task's nth recording", "1").option("--only <kinds>", "these kinds of line: console, request, page, click, input, scroll, resize, marks, voice (repeatable)", all).option("--problems", "errors, warnings and requests that failed").option("--from <seconds>", "from this far in").option("--to <seconds>", "to this far in").option("--around <seconds>", "the 3 seconds either side of this").option("--grep <text>", "lines with this in them, in any case").option("--full", "all of each line: where it was logged from, a request's headers and bodies").option("--json", "as JSON").action(async (ref, options) => (await import("./shared/recording.js")).run(ref, options));
|
|
33
|
+
program.command("frame").description("PNGs of a recording, as the replay draws it, marks and all (needs the dev server)").argument("<recording>", RECORDING).option("--nth <n>", "a task's nth recording", "1").option("--at <seconds>", "a frame this far in (repeatable); by default after each change to the marks, and the end", all).option("--every <seconds>", "a frame this often").option("--out <dir>", "where the PNGs go, a temporary folder by default").option("--base <url>", "the dev server, where it's not the recorded page's origin").action(async (ref, options) => (await import("./shared/frame.js")).run(ref, options));
|
|
34
|
+
program.command("voice").description("when speech happens in voice clips, in the recording's time").argument("<clip>", CLIP).option("--noise <dB>", "what counts as silence; lower hears quieter speech", "-35").option("--gap <seconds>", "the shortest silence between stretches of speech", "0.4").option("--wav <dir>", "also writes each clip here as 16 kHz WAV").option("--json", "as JSON").action(async (ref, options) => (await import("./shared/voice2.js")).run(ref, options));
|
|
35
|
+
program.command("transcribe").description("what was said in voice clips, on this machine, with when").argument("[clip]", CLIP).option("--setup", "installs it, outside the project: ask the person first").option("--model <size>", "tiny, base, small, large-v3-turbo, or a model ID", "base").option("--language <code>", "the language spoken (en), rather than guessed").option("--json", "as JSON").action(async (ref, options) => (await import("./shared/transcribe.js")).run(ref, options));
|
|
36
|
+
if (process.argv.length <= 2) {
|
|
37
|
+
program.outputHelp();
|
|
32
38
|
process.exit(0);
|
|
33
39
|
}
|
|
34
|
-
await
|
|
40
|
+
await program.parseAsync();
|
|
35
41
|
export {};
|
|
36
42
|
|
|
37
43
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * The `deictic` command. `init` sets a project up, for the person; the rest are for the agent that works the tasks
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * The `deictic` command. `init` sets a project up and `clean` deletes what it kept, for the person; the rest are for\n * the agent that works the tasks, as the skill says: the board, a watch, a task, and what a task carries. Each is\n * declared here, its arguments and options with what they do, which is all `--help` needs; what it runs is in `cli/`,\n * imported only when it's run, so `deictic task` doesn't load the parser `init` edits configs with. Run in the\n * project, where its board and `.deictic/` are: `npx deictic <command>`.\n */\nimport { Argument, Command } from 'commander';\n\n/** A repeatable option's values, in order. */\nconst all = (value: string, previous: string[] | undefined) => [...(previous ?? []), value];\nconst RECORDING = 'a task (68), a replay URL, a recording ID or a JSON file';\nconst CLIP = 'a task, a replay URL, a recording ID, an audio file or a clip ID';\n\nconst program = new Command('deictic')\n .usage('<command> [options]')\n .enablePositionalOptions()\n .helpOption('-h, --help', 'says what a command takes')\n .showHelpAfterError('(add --help for what it takes)')\n .addHelpText('after', '\\nRun in the project. deictic help <command>, or <command> --help, says what it takes.');\n\nprogram.commandsGroup('Setting up and cleaning up:');\n// Here, not under a heading of its own, which a lone `help` would get.\nprogram.helpCommand('help [command]', 'says what a command takes');\n\nprogram\n .command('init')\n .description('sets deictic up in this project')\n .option('--dry-run', 'says what it would do, and does none of it')\n .option('--no-install', \"doesn't install: says the command instead\")\n .option('--skill', 'adds the agent skill without asking')\n .option('--no-skill', \"doesn't add the agent skill: says the command instead\")\n .action(async (options) => (await import('./cli/init.ts')).run(options));\n\nprogram\n .command('clean')\n .description('deletes what deictic kept, after saying what and how big and asking')\n .addArgument(\n new Argument('[parts...]', 'what to delete: shots, recordings and voice clips by default').choices([\n 'screenshots',\n 'recordings',\n 'voice',\n 'history',\n 'board',\n 'all',\n 'transcribe',\n ]),\n )\n .option('-y, --yes', \"deletes without asking: with no terminal to ask on, it doesn't delete without it\")\n .addHelpText(\n 'after',\n '\\nhistory (undo) and board (the local board, its tasks) only with the dev server stopped. all is everything in' +\n \"\\nthe project's .deictic/; transcribe is the transcription model, outside it, which every project shares.\",\n )\n .action(async (parts: string[], options) => (await import('./cli/clean.ts')).run(parts, options));\n\nprogram.commandsGroup('For the agent that works the tasks (the skill):');\n\nprogram\n .command('vb')\n .description('the board on the dev server: deictic vb whoami, deictic vb tasks claim 68 --lease 30m')\n .argument('[args...]', 'anything vb takes')\n // All of it is vb's, --help too.\n .helpOption(false)\n .allowUnknownOption()\n .passThroughOptions()\n .action(async (args: string[]) => (await import('./cli/vb.ts')).run(args));\n\nprogram\n .command('watch')\n .description('a line per new task, reply and cancellation')\n .argument('[channel]', 'the channel', 'deictic')\n .option('--idle <time>', 'ends once the channel has had nothing for this long: 30m, 45s, 1h', '20m')\n .option('--once', 'ends at the first thing to act on')\n .option('--label <key=value>', 'only tasks with this label (repeatable)', all)\n .action(async (channel: string, options) => (await import('./cli/watch.ts')).run(channel, options));\n\nprogram\n .command('task')\n .description('a task briefly: what was asked, by whom, who holds it, what is attached')\n .argument('<id>', 'the task: 68 or #68')\n .option('--out <dir>', 'downloads what is attached here')\n .action(async (id: string, options) => (await import('./cli/task.ts')).run(id, options));\n\nprogram\n .command('recording')\n .description('a recording as a timeline, or the part of it asked for')\n .argument('<recording>', RECORDING)\n .option('--nth <n>', \"a task's nth recording\", '1')\n .option('--only <kinds>', 'these kinds of line: console, request, page, click, input, scroll, resize, marks, voice (repeatable)', all)\n .option('--problems', 'errors, warnings and requests that failed')\n .option('--from <seconds>', 'from this far in')\n .option('--to <seconds>', 'to this far in')\n .option('--around <seconds>', 'the 3 seconds either side of this')\n .option('--grep <text>', 'lines with this in them, in any case')\n .option('--full', \"all of each line: where it was logged from, a request's headers and bodies\")\n .option('--json', 'as JSON')\n .action(async (ref: string, options) => (await import('./cli/recording.ts')).run(ref, options));\n\nprogram\n .command('frame')\n .description('PNGs of a recording, as the replay draws it, marks and all (needs the dev server)')\n .argument('<recording>', RECORDING)\n .option('--nth <n>', \"a task's nth recording\", '1')\n .option('--at <seconds>', 'a frame this far in (repeatable); by default after each change to the marks, and the end', all)\n .option('--every <seconds>', 'a frame this often')\n .option('--out <dir>', 'where the PNGs go, a temporary folder by default')\n .option('--base <url>', \"the dev server, where it's not the recorded page's origin\")\n .action(async (ref: string, options) => (await import('./cli/frame.ts')).run(ref, options));\n\nprogram\n .command('voice')\n .description(\"when speech happens in voice clips, in the recording's time\")\n .argument('<clip>', CLIP)\n .option('--noise <dB>', 'what counts as silence; lower hears quieter speech', '-35')\n .option('--gap <seconds>', 'the shortest silence between stretches of speech', '0.4')\n .option('--wav <dir>', 'also writes each clip here as 16 kHz WAV')\n .option('--json', 'as JSON')\n .action(async (ref: string, options) => (await import('./cli/voice.ts')).run(ref, options));\n\nprogram\n .command('transcribe')\n .description('what was said in voice clips, on this machine, with when')\n .argument('[clip]', CLIP)\n .option('--setup', 'installs it, outside the project: ask the person first')\n .option('--model <size>', 'tiny, base, small, large-v3-turbo, or a model ID', 'base')\n .option('--language <code>', 'the language spoken (en), rather than guessed')\n .option('--json', 'as JSON')\n .action(async (ref: string | undefined, options) => (await import('./cli/transcribe.ts')).run(ref, options));\n\nif (process.argv.length <= 2) {\n program.outputHelp();\n process.exit(0);\n}\nawait program.parseAsync();\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,OAAO,OAAe,aAAmC,CAAC,GAAI,YAAY,CAAC,GAAI,KAAK;AAC1F,MAAM,YAAY;AAClB,MAAM,OAAO;AAEb,MAAM,UAAU,IAAI,QAAQ,SAAS,CAAC,CACnC,MAAM,qBAAqB,CAAC,CAC5B,wBAAwB,CAAC,CACzB,WAAW,cAAc,2BAA2B,CAAC,CACrD,mBAAmB,gCAAgC,CAAC,CACpD,YAAY,SAAS,wFAAwF;AAEhH,QAAQ,cAAc,6BAA6B;AAEnD,QAAQ,YAAY,kBAAkB,2BAA2B;AAEjE,QACG,QAAQ,MAAM,CAAC,CACf,YAAY,iCAAiC,CAAC,CAC9C,OAAO,aAAa,4CAA4C,CAAC,CACjE,OAAO,gBAAgB,2CAA2C,CAAC,CACnE,OAAO,WAAW,qCAAqC,CAAC,CACxD,OAAO,cAAc,uDAAuD,CAAC,CAC7E,OAAO,OAAO,aAAa,MAAM,OAAO,oBAAA,CAAkB,IAAI,OAAO,CAAC;AAEzE,QACG,QAAQ,OAAO,CAAC,CAChB,YAAY,qEAAqE,CAAC,CAClF,YACC,IAAI,SAAS,cAAc,8DAA8D,CAAC,CAAC,QAAQ;CACjG;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CACH,CAAC,CACA,OAAO,aAAa,kFAAkF,CAAC,CACvG,YACC,SACA,yNAEF,CAAC,CACA,OAAO,OAAO,OAAiB,aAAa,MAAM,OAAO,qBAAA,CAAmB,IAAI,OAAO,OAAO,CAAC;AAElG,QAAQ,cAAc,iDAAiD;AAEvE,QACG,QAAQ,IAAI,CAAC,CACb,YAAY,uF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AS,eAAe,SAAS,CAAC,CAClC,OAAO,aAAa,0BAA0B,GAAG,CAAC,CAClD,OAAO,kBAAkB,4FAA4F,GAAG,CAAC,CACzH,OAAO,qBAAqB,oBAAoB,CAAC,CACjD,OAAO,eAAe,kDAAkD,CAAC,CACzE,OAAO,gBAAgB,2DAA2D,CAAC,CACnF,OAAO,OAAO,KAAa,aAAa,MAAM,OAAO,qBAAA,CAAmB,IAAI,KAAK,OAAO,CAAC;AAE5F,QACG,QAAQ,OAAO,CAAC,CAChB,YAAY,6DAA6D,CAAC,CAC1E,SAAS,UAAU,IAAI,CAAC,CACxB,OAAO,gBAAgB,sDAAsD,KAAK,CAAC,CACnF,OAAO,mBAAmB,oDAAoD,KAAK,CAAC,CACpF,OAAO,eAAe,0CAA0C,CAAC,CACjE,OAAO,UAAU,SAAS,CAAC,CAC3B,OAAO,OAAO,KAAa,aAAa,MAAM,OAAO,sBAAA,CAAmB,IAAI,KAAK,OAAO,CAAC;AAE5F,QACG,QAAQ,YAAY,CAAC,CACrB,YAAY,0DAA0D,CAAC,CACvE,SAAS,UAAU,IAAI,CAAC,CACxB,OAAO,WAAW,wDAAwD,CAAC,CAC3E,OAAO,kBAAkB,oDAAoD,MAAM,CAAC,CACpF,OAAO,qBAAqB,+CAA+C,CAAC,CAC5E,OAAO,UAAU,SAAS,CAAC,CAC3B,OAAO,OAAO,KAAyB,aAAa,MAAM,OAAO,0BAAA,CAAwB,IAAI,KAAK,OAAO,CAAC;AAE7G,IAAI,QAAQ,KAAK,UAAU,GAAG;CAC5B,QAAQ,WAAW;CACnB,QAAQ,KAAK,CAAC;AAChB;AACA,MAAM,QAAQ,WAAW"}
|
package/dist/shared/board.js
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { existsSync, readdirSync } from "node:fs";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import {
|
|
5
|
-
import { i as
|
|
4
|
+
import { a as vbScript, i as runningAt } from "./local.js";
|
|
5
|
+
import { i as packageManager, t as execOf } from "./packages.js";
|
|
6
6
|
// src/cli/board.ts
|
|
7
7
|
/**
|
|
8
8
|
* What the agent's commands share: the board's CLI (`vb`, the project's `@vercel/board`) on the board the dev server
|
|
9
9
|
* uses, the project's `.deictic/` folders, and failing with what to do.
|
|
10
10
|
*/
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* How the commands name each other in what they print, for an agent to run: with the project's own runner, as npm
|
|
13
|
+
* adds notices of its own to what each command prints, which an agent's monitor takes for the command's.
|
|
14
|
+
*/
|
|
15
|
+
const ME = `${execOf(packageManager(process.cwd()))} deictic`;
|
|
13
16
|
function fail(message) {
|
|
14
17
|
console.error(message);
|
|
15
18
|
process.exit(1);
|
|
16
19
|
}
|
|
17
|
-
/** A command's options and arguments, or a failure saying what's wrong with them. */
|
|
18
|
-
function parseArgs(args, options) {
|
|
19
|
-
try {
|
|
20
|
-
return parseArgs$1({
|
|
21
|
-
args,
|
|
22
|
-
options,
|
|
23
|
-
allowPositionals: true,
|
|
24
|
-
allowNegative: true,
|
|
25
|
-
strict: true
|
|
26
|
-
});
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return fail(e.message);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
20
|
/** `1:02.5`, from milliseconds. */
|
|
32
21
|
function clock(ms) {
|
|
33
22
|
const s = Math.max(0, ms) / 1e3;
|
|
@@ -185,6 +174,6 @@ const download = (attachment, path) => vb([
|
|
|
185
174
|
attachment.id,
|
|
186
175
|
path
|
|
187
176
|
]);
|
|
188
|
-
export {
|
|
177
|
+
export { clock as a, duration as c, task as d, vb as f, whoami as g, vbJson as h, boardUrl as i, fail as l, vbHere as m, answers as n, deicticDirs as o, vbCommand as p, boardIn as r, download as s, ME as t, read as u };
|
|
189
178
|
|
|
190
179
|
//# sourceMappingURL=board.js.map
|
package/dist/shared/board.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board.js","names":["parse"],"sources":["../../src/cli/board.ts"],"sourcesContent":["/**\n * What the agent's commands share: the board's CLI (`vb`, the project's `@vercel/board`) on the board the dev server\n * uses, the project's `.deictic/` folders, and failing with what to do.\n */\nimport { spawnSync, type SpawnSyncOptions } from 'node:child_process';\nimport { existsSync, readdirSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { parseArgs as parse, type ParseArgsConfig } from 'node:util';\n\nimport { runningAt, vbScript } from '#src/plugins/tasks/local.ts';\n\n/** How the commands name each other in what they print, for an agent to run. */\nexport const ME = 'npx deictic';\n\nexport function fail(message: string): never {\n console.error(message);\n process.exit(1);\n}\n\n/** A command's options and arguments, or a failure saying what's wrong with them. */\nexport function parseArgs<T extends NonNullable<ParseArgsConfig['options']>>(args: string[], options: T) {\n try {\n return parse({ args, options, allowPositionals: true, allowNegative: true, strict: true });\n } catch (e) {\n return fail((e as Error).message);\n }\n}\n\n/** `1:02.5`, from milliseconds. */\nexport function clock(ms: number): string {\n const s = Math.max(0, ms) / 1000;\n return `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart(4, '0')}`;\n}\n\n/** `30m`, `45s`, `1h` or a bare number of seconds, as milliseconds. */\nexport function duration(text: string): number {\n const [, n, unit = 's'] = /^(\\d+(?:\\.\\d+)?)([smh])?$/.exec(text) ?? [];\n if (n === undefined) fail(`\"${text}\" isn't a duration: 30m, 45s, 1h, or seconds as a number.`);\n return Number(n) * { s: 1000, m: 60_000, h: 3_600_000 }[unit as 's' | 'm' | 'h'];\n}\n\n/** This directory and each above it. */\nfunction* upFrom(dir = process.cwd()) {\n for (let at = resolve(dir); ; at = dirname(at)) {\n yield at;\n if (dirname(at) === at) return;\n }\n}\n\n/** Every `.deictic/` near here: in this directory or above, or in a folder of it (a site/, an app/). */\nexport function deicticDirs(): string[] {\n const found = [...upFrom()].map((d) => join(d, '.deictic')).filter((p) => existsSync(p));\n const walk = (dir: string, depth: number) => {\n if (depth === 0) return;\n for (const e of readdirSync(dir, { withFileTypes: true })) {\n if (!e.isDirectory() || e.name === 'node_modules' || (e.name.startsWith('.') && e.name !== '.deictic')) continue;\n const path = join(dir, e.name);\n if (e.name === '.deictic') found.push(path);\n else walk(path, depth - 1);\n }\n };\n walk(process.cwd(), 3);\n return [...new Set(found)];\n}\n\n/** The board a `.deictic/` names: the one its dev server started. */\nexport const boardIn = (dir: string) => runningAt(join(dir, 'board.json'))?.url;\n\n/**\n * The board's URL: `BOARD_URL`, or with none, the board the dev server started for the project, which\n * `.deictic/board.json` names. Nothing where there's neither: `vb` then finds the team's board.\n */\nexport function boardUrl(): string | undefined {\n const given = process.env.BOARD_URL;\n if (given !== undefined && given !== '') return given;\n return deicticDirs()\n .map(boardIn)\n .find((url) => url !== undefined);\n}\n\n/**\n * The coding agents a shell of theirs says it is, by a variable each sets only there. Not one a person's terminal has\n * too (Replit's `REPL_ID`, a `TERM_PROGRAM`): a person writes as themselves.\n */\nconst AGENTS: [name: string, variables: string[]][] = [\n ['claude', ['CLAUDECODE', 'CLAUDE_CODE']],\n ['codex', ['CODEX_SANDBOX', 'CODEX_THREAD_ID']],\n ['gemini', ['GEMINI_CLI']],\n ['cursor', ['CURSOR_AGENT']],\n ['copilot', ['COPILOT_AGENT', 'COPILOT_CLI']],\n ['opencode', ['OPENCODE']],\n ['auggie', ['AUGMENT_AGENT']],\n ['goose', ['GOOSE_PROVIDER']],\n ['junie', ['JUNIE_DATA', 'JUNIE_SHIM_PATH']],\n];\n\n/** A board's profile name: a letter, then up to 31 letters, digits and hyphens. */\nconst PROFILE = /^[A-Za-z][A-Za-z0-9-]{0,31}$/;\n\n/**\n * Who the board's CLI writes as: `BOARD_PROFILE` where it's set, or else the coding agent this runs in, so its claims,\n * replies and results are its own, not the person's, without its setting anything on each command. By the variable\n * its harness sets, then by `AI_AGENT` (`claude-code_2-1-330_agent` is `claude`). Nothing at a person's terminal.\n */\nexport function profileOf(env: NodeJS.ProcessEnv = process.env): string | undefined {\n if (env.BOARD_PROFILE !== undefined && env.BOARD_PROFILE !== '') return env.BOARD_PROFILE;\n const known = AGENTS.find(([, variables]) => variables.some((v) => env[v] !== undefined && env[v] !== ''));\n if (known !== undefined) return known[0];\n const named = env.AI_AGENT?.toLowerCase();\n if (named === undefined || named === '') return undefined;\n if (named.startsWith('github_copilot')) return 'copilot';\n // The agent's name, without its version, its kind or what it is (`-code`, `-cli`).\n const name = (named.split('_')[0] ?? '').replace(/-(code|cli|agent)$/, '');\n return PROFILE.test(name) ? name : undefined;\n}\n\n/**\n * How to run the board's CLI, as `spawn`'s command, arguments and options, on the environment's board or the\n * project's own, as the agent running it (`profileOf`): the project's `@vercel/board`, run by this runtime, so it\n * needn't be on the PATH and no shell reads the arguments; with none installed, `vb` from the PATH.\n */\nexport function vbCommand(args: string[]): [string, string[], SpawnSyncOptions] {\n const url = boardUrl();\n const profile = profileOf();\n const env = {\n ...process.env,\n ...(url === undefined ? {} : { BOARD_URL: url }),\n ...(profile === undefined ? {} : { BOARD_PROFILE: profile }),\n };\n const script = vbScript();\n if (script !== undefined) return [process.execPath, [script, ...args], { env }];\n // npm's shims on Windows are .cmd files, which only a shell runs; the arguments here are IDs and names.\n if (process.platform === 'win32') return [`vb ${args.map((a) => `\"${a}\"`).join(' ')}`, [], { env, shell: true }];\n return ['vb', args, { env }];\n}\n\nconst unreachable = (message: string) => fail(`vb: ${message}. Install @vercel/board in the project (${ME} init), or put vb on the PATH.`);\n\n/** Runs the board's CLI and answers what it printed. */\nexport function vb(args: string[]): string {\n const [command, argv, options] = vbCommand(args);\n const run = spawnSync(command, argv, { ...options, encoding: 'utf8', maxBuffer: 1 << 28 });\n if (run.error) unreachable(run.error.message);\n if (run.status !== 0) fail(`vb ${args.join(' ')}: ${run.stderr.trim() || `exit ${run.status}`}`);\n return run.stdout;\n}\n\n/** The board's CLI's answer as JSON. */\nexport const vbJson = <T>(args: string[]): T => JSON.parse(vb([...args, '--json'])) as T;\n\n/** Runs the board's CLI on this terminal, and answers its exit code. */\nexport function vbHere(args: string[]): number {\n const [command, argv, options] = vbCommand(args);\n const run = spawnSync(command, argv, { ...options, stdio: 'inherit' });\n if (run.error) unreachable(run.error.message);\n return run.status ?? 1;\n}\n\n/** Whether the board answers now, as whoever the CLI writes as: asked of one that may be starting again. */\nexport function answers(): boolean {\n const [command, argv, options] = vbCommand(['whoami', '--json']);\n return spawnSync(command, argv, { ...options, encoding: 'utf8' }).status === 0;\n}\n\n/**\n * Who the CLI writes as. `profile` is the name `BOARD_PROFILE` (or `--as`) gave, and `null` without one: then what's\n * written is the person's own, as the board sees it.\n */\nexport interface Me {\n actor: string;\n handle?: string;\n name?: string;\n profile: string | null;\n}\n\nexport const whoami = () => vbJson<Me>(['whoami']);\n\nexport interface Attachment {\n id: string;\n name: string;\n type: string;\n size: number;\n}\n\nexport interface Message {\n id: number;\n channel: string;\n text: string;\n labels: Record<string, string>;\n attachments: Attachment[];\n createdAt: string;\n by: { actor: string };\n author?: { handle?: string };\n task?: { state: string; claim?: { actor: string; until: string }; result?: string; reason?: string };\n}\n\n/** A task's root message and its replies, by its ID (`68` or `#68`). */\nexport const read = (id: string) => vbJson<{ message: Message; replies: Message[] }>(['read', id.replace(/^#/, '')]);\n\n/** A task's root message. */\nexport const task = (id: string) => read(id).message;\n\n/** Writes an attachment to a file. */\nexport const download = (attachment: Attachment, path: string) => vb(['download', attachment.id, path]);\n"],"mappings":";;;;;;;;;;;AAYA,MAAa,KAAK;AAElB,SAAgB,KAAK,SAAwB;CAC3C,QAAQ,MAAM,OAAO;CACrB,QAAQ,KAAK,CAAC;AAChB;;AAGA,SAAgB,UAA6D,MAAgB,SAAY;CACvG,IAAI;EACF,OAAOA,YAAM;GAAE;GAAM;GAAS,kBAAkB;GAAM,eAAe;GAAM,QAAQ;EAAK,CAAC;CAC3F,SAAS,GAAG;EACV,OAAO,KAAM,EAAY,OAAO;CAClC;AACF;;AAGA,SAAgB,MAAM,IAAoB;CACxC,MAAM,IAAI,KAAK,IA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AAI,MAAM,OAAO;CAC5C,OAAO,IAAI,UAAU;AACvB;;AAGA,SAAgB,UAAmB;CACjC,MAAM,CAAC,SAAS,MAAM,WAAW,UAAU,CAAC,UAAU,QAAQ,CAAC;CAC/D,OAAO,UAAU,SAAS,MAAM;EAAE,GAAG;EAAS,UAAU;CAAO,CAAC,CAAC,CAAC,WAAW;AAC/E;AAaA,MAAa,eAAe,OAAW,CAAC,QAAQ,CAAC;;AAsBjD,MAAa,QAAQ,OAAe,OAAiD,CAAC,QAAQ,GAAG,QAAQ,MAAM,EAAE,CAAC,CAAC;;AAGnH,MAAa,QAAQ,OAAe,KAAK,EAAE,CAAC,CAAC;;AAG7C,MAAa,YAAY,YAAwB,SAAiB,GAAG;CAAC;CAAY,WAAW;CAAI;AAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"board.js","names":[],"sources":["../../src/cli/board.ts"],"sourcesContent":["/**\n * What the agent's commands share: the board's CLI (`vb`, the project's `@vercel/board`) on the board the dev server\n * uses, the project's `.deictic/` folders, and failing with what to do.\n */\nimport { spawnSync, type SpawnSyncOptions } from 'node:child_process';\nimport { existsSync, readdirSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\n\nimport { runningAt, vbScript } from '#src/plugins/tasks/local.ts';\nimport { execOf, packageManager } from '#src/tools/packages.ts';\n\n/**\n * How the commands name each other in what they print, for an agent to run: with the project's own runner, as npm\n * adds notices of its own to what each command prints, which an agent's monitor takes for the command's.\n */\nexport const ME = `${execOf(packageManager(process.cwd()))} deictic`;\n\nexport function fail(message: string): never {\n console.error(message);\n process.exit(1);\n}\n\n/** `1:02.5`, from milliseconds. */\nexport function clock(ms: number): string {\n const s = Math.max(0, ms) / 1000;\n return `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart(4, '0')}`;\n}\n\n/** `30m`, `45s`, `1h` or a bare number of seconds, as milliseconds. */\nexport function duration(text: string): number {\n const [, n, unit = 's'] = /^(\\d+(?:\\.\\d+)?)([smh])?$/.exec(text) ?? [];\n if (n === undefined) fail(`\"${text}\" isn't a duration: 30m, 45s, 1h, or seconds as a number.`);\n return Number(n) * { s: 1000, m: 60_000, h: 3_600_000 }[unit as 's' | 'm' | 'h'];\n}\n\n/** This directory and each above it. */\nfunction* upFrom(dir = process.cwd()) {\n for (let at = resolve(dir); ; at = dirname(at)) {\n yield at;\n if (dirname(at) === at) return;\n }\n}\n\n/** Every `.deictic/` near here: in this directory or above, or in a folder of it (a site/, an app/). */\nexport function deicticDirs(): string[] {\n const found = [...upFrom()].map((d) => join(d, '.deictic')).filter((p) => existsSync(p));\n const walk = (dir: string, depth: number) => {\n if (depth === 0) return;\n for (const e of readdirSync(dir, { withFileTypes: true })) {\n if (!e.isDirectory() || e.name === 'node_modules' || (e.name.startsWith('.') && e.name !== '.deictic')) continue;\n const path = join(dir, e.name);\n if (e.name === '.deictic') found.push(path);\n else walk(path, depth - 1);\n }\n };\n walk(process.cwd(), 3);\n return [...new Set(found)];\n}\n\n/** The board a `.deictic/` names: the one its dev server started. */\nexport const boardIn = (dir: string) => runningAt(join(dir, 'board.json'))?.url;\n\n/**\n * The board's URL: `BOARD_URL`, or with none, the board the dev server started for the project, which\n * `.deictic/board.json` names. Nothing where there's neither: `vb` then finds the team's board.\n */\nexport function boardUrl(): string | undefined {\n const given = process.env.BOARD_URL;\n if (given !== undefined && given !== '') return given;\n return deicticDirs()\n .map(boardIn)\n .find((url) => url !== undefined);\n}\n\n/**\n * The coding agents a shell of theirs says it is, by a variable each sets only there. Not one a person's terminal has\n * too (Replit's `REPL_ID`, a `TERM_PROGRAM`): a person writes as themselves.\n */\nconst AGENTS: [name: string, variables: string[]][] = [\n ['claude', ['CLAUDECODE', 'CLAUDE_CODE']],\n ['codex', ['CODEX_SANDBOX', 'CODEX_THREAD_ID']],\n ['gemini', ['GEMINI_CLI']],\n ['cursor', ['CURSOR_AGENT']],\n ['copilot', ['COPILOT_AGENT', 'COPILOT_CLI']],\n ['opencode', ['OPENCODE']],\n ['auggie', ['AUGMENT_AGENT']],\n ['goose', ['GOOSE_PROVIDER']],\n ['junie', ['JUNIE_DATA', 'JUNIE_SHIM_PATH']],\n];\n\n/** A board's profile name: a letter, then up to 31 letters, digits and hyphens. */\nconst PROFILE = /^[A-Za-z][A-Za-z0-9-]{0,31}$/;\n\n/**\n * Who the board's CLI writes as: `BOARD_PROFILE` where it's set, or else the coding agent this runs in, so its claims,\n * replies and results are its own, not the person's, without its setting anything on each command. By the variable\n * its harness sets, then by `AI_AGENT` (`claude-code_2-1-330_agent` is `claude`). Nothing at a person's terminal.\n */\nexport function profileOf(env: NodeJS.ProcessEnv = process.env): string | undefined {\n if (env.BOARD_PROFILE !== undefined && env.BOARD_PROFILE !== '') return env.BOARD_PROFILE;\n const known = AGENTS.find(([, variables]) => variables.some((v) => env[v] !== undefined && env[v] !== ''));\n if (known !== undefined) return known[0];\n const named = env.AI_AGENT?.toLowerCase();\n if (named === undefined || named === '') return undefined;\n if (named.startsWith('github_copilot')) return 'copilot';\n // The agent's name, without its version, its kind or what it is (`-code`, `-cli`).\n const name = (named.split('_')[0] ?? '').replace(/-(code|cli|agent)$/, '');\n return PROFILE.test(name) ? name : undefined;\n}\n\n/**\n * How to run the board's CLI, as `spawn`'s command, arguments and options, on the environment's board or the\n * project's own, as the agent running it (`profileOf`): the project's `@vercel/board`, run by this runtime, so it\n * needn't be on the PATH and no shell reads the arguments; with none installed, `vb` from the PATH.\n */\nexport function vbCommand(args: string[]): [string, string[], SpawnSyncOptions] {\n const url = boardUrl();\n const profile = profileOf();\n const env = {\n ...process.env,\n ...(url === undefined ? {} : { BOARD_URL: url }),\n ...(profile === undefined ? {} : { BOARD_PROFILE: profile }),\n };\n const script = vbScript();\n if (script !== undefined) return [process.execPath, [script, ...args], { env }];\n // npm's shims on Windows are .cmd files, which only a shell runs; the arguments here are IDs and names.\n if (process.platform === 'win32') return [`vb ${args.map((a) => `\"${a}\"`).join(' ')}`, [], { env, shell: true }];\n return ['vb', args, { env }];\n}\n\nconst unreachable = (message: string) => fail(`vb: ${message}. Install @vercel/board in the project (${ME} init), or put vb on the PATH.`);\n\n/** Runs the board's CLI and answers what it printed. */\nexport function vb(args: string[]): string {\n const [command, argv, options] = vbCommand(args);\n const run = spawnSync(command, argv, { ...options, encoding: 'utf8', maxBuffer: 1 << 28 });\n if (run.error) unreachable(run.error.message);\n if (run.status !== 0) fail(`vb ${args.join(' ')}: ${run.stderr.trim() || `exit ${run.status}`}`);\n return run.stdout;\n}\n\n/** The board's CLI's answer as JSON. */\nexport const vbJson = <T>(args: string[]): T => JSON.parse(vb([...args, '--json'])) as T;\n\n/** Runs the board's CLI on this terminal, and answers its exit code. */\nexport function vbHere(args: string[]): number {\n const [command, argv, options] = vbCommand(args);\n const run = spawnSync(command, argv, { ...options, stdio: 'inherit' });\n if (run.error) unreachable(run.error.message);\n return run.status ?? 1;\n}\n\n/** Whether the board answers now, as whoever the CLI writes as: asked of one that may be starting again. */\nexport function answers(): boolean {\n const [command, argv, options] = vbCommand(['whoami', '--json']);\n return spawnSync(command, argv, { ...options, encoding: 'utf8' }).status === 0;\n}\n\n/**\n * Who the CLI writes as. `profile` is the name `BOARD_PROFILE` (or `--as`) gave, and `null` without one: then what's\n * written is the person's own, as the board sees it.\n */\nexport interface Me {\n actor: string;\n handle?: string;\n name?: string;\n profile: string | null;\n}\n\nexport const whoami = () => vbJson<Me>(['whoami']);\n\nexport interface Attachment {\n id: string;\n name: string;\n type: string;\n size: number;\n}\n\nexport interface Message {\n id: number;\n channel: string;\n text: string;\n labels: Record<string, string>;\n attachments: Attachment[];\n createdAt: string;\n by: { actor: string };\n author?: { handle?: string };\n task?: { state: string; claim?: { actor: string; until: string }; result?: string | null; reason?: string | null };\n}\n\n/** A task's root message and its replies, by its ID (`68` or `#68`). */\nexport const read = (id: string) => vbJson<{ message: Message; replies: Message[] }>(['read', id.replace(/^#/, '')]);\n\n/** A task's root message. */\nexport const task = (id: string) => read(id).message;\n\n/** Writes an attachment to a file. */\nexport const download = (attachment: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;AAGA,MAAa,UAAa,SAAsB,KAAK,MAAM,GAAG,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC;;AAGlF,SAAgB,OAAO,MAAwB;CAC7C,MAAM,CAAC,SAAS,MAAM,WAAW,UAAU,IAAI;CAC/C,MAAM,MAAM,UAAU,SAAS,MAAM;EAAE,GAAG;EAAS,OAAO;CAAU,CAAC;CACrE,IAAI,IAAI,OAAO,YAAY,IAAI,MAAM,OAAO;CAC5C,OAAO,IAAI,UAAU;AACvB;;AAGA,SAAgB,UAAmB;CACjC,MAAM,CAAC,SAAS,MAAM,WAAW,UAAU,CAAC,UAAU,QAAQ,CAAC;CAC/D,OAAO,UAAU,SAAS,MAAM;EAAE,GAAG;EAAS,UAAU;CAAO,CAAC,CAAC,CAAC,WAAW;AAC/E;AAaA,MAAa,eAAe,OAAW,CAAC,QAAQ,CAAC;;AAsBjD,MAAa,QAAQ,OAAe,OAAiD,CAAC,QAAQ,GAAG,QAAQ,MAAM,EAAE,CAAC,CAAC;;AAGnH,MAAa,QAAQ,OAAe,KAAK,EAAE,CAAC,CAAC;;AAG7C,MAAa,YAAY,YAAwB,SAAiB,GAAG;CAAC;CAAY,WAAW;CAAI;AAAI,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { existsSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
import { i as runningAt, t as alive } from "./local.js";
|
|
5
|
+
import { l as fail, o as deicticDirs, t as ME } from "./board.js";
|
|
6
|
+
import { n as transcribeDir } from "./transcribe2.js";
|
|
7
|
+
// src/cli/clean.ts
|
|
8
|
+
/**
|
|
9
|
+
* `deictic clean`: deletes what deictic kept, for a person who'd rather not delete `.deictic/` by hand. It says what
|
|
10
|
+
* it found and how big, then asks; with no terminal to ask on, it deletes only with `--yes`, so an agent sees the list
|
|
11
|
+
* first. By default the shots, recordings and voice clips, which tasks carry on the board anyway; the history (undo)
|
|
12
|
+
* and the local board (its tasks) only when named, and only with the dev server stopped, as a running one holds both.
|
|
13
|
+
* Transcription's install is outside the project, shared by every project on the machine, so only when named.
|
|
14
|
+
*/
|
|
15
|
+
const CAPTURES = [
|
|
16
|
+
"screenshots",
|
|
17
|
+
"recordings",
|
|
18
|
+
"voice"
|
|
19
|
+
];
|
|
20
|
+
const PROJECT = [
|
|
21
|
+
...CAPTURES,
|
|
22
|
+
"history",
|
|
23
|
+
"board"
|
|
24
|
+
];
|
|
25
|
+
/** What one part of a `.deictic/` is on disk: the paths to delete. */
|
|
26
|
+
function pathsOf(dir, part) {
|
|
27
|
+
if (part === "history") return [join(dir, "history.json")].filter((p) => existsSync(p));
|
|
28
|
+
if (part === "board") return [join(dir, "board"), join(dir, "board.json")].filter((p) => existsSync(p));
|
|
29
|
+
const folder = join(dir, part);
|
|
30
|
+
if (!existsSync(folder)) return [];
|
|
31
|
+
return readdirSync(folder).filter((f) => !f.endsWith(".part")).map((f) => join(folder, f));
|
|
32
|
+
}
|
|
33
|
+
function sizeOf(path) {
|
|
34
|
+
const stat = statSync(path);
|
|
35
|
+
if (!stat.isDirectory()) return stat.size;
|
|
36
|
+
return readdirSync(path).reduce((sum, f) => sum + sizeOf(join(path, f)), 0);
|
|
37
|
+
}
|
|
38
|
+
const UNITS = [
|
|
39
|
+
["GB", 1e9],
|
|
40
|
+
["MB", 1e6],
|
|
41
|
+
["KB", 1e3]
|
|
42
|
+
];
|
|
43
|
+
function bytes(n) {
|
|
44
|
+
const unit = UNITS.find(([, size]) => n >= size);
|
|
45
|
+
return unit === void 0 ? `${n} bytes` : `${(n / unit[1]).toFixed(1)} ${unit[0]}`;
|
|
46
|
+
}
|
|
47
|
+
async function ask(question) {
|
|
48
|
+
const lines = createInterface({
|
|
49
|
+
input: process.stdin,
|
|
50
|
+
output: process.stdout
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
return /^y/i.test((await lines.question(`${question} (y/N) `)).trim());
|
|
54
|
+
} finally {
|
|
55
|
+
lines.close();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function run(asked, values) {
|
|
59
|
+
const named = asked.filter((p) => p !== "all");
|
|
60
|
+
const parts = asked.length === 0 ? [...CAPTURES] : [.../* @__PURE__ */ new Set([...asked.includes("all") ? PROJECT : [], ...named])];
|
|
61
|
+
const found = [];
|
|
62
|
+
for (const dir of deicticDirs()) {
|
|
63
|
+
const running = runningAt(join(dir, "board.json"));
|
|
64
|
+
const serving = running !== void 0 && alive(running.pid);
|
|
65
|
+
for (const part of parts.filter((p) => p !== "transcribe")) {
|
|
66
|
+
const paths = pathsOf(dir, part);
|
|
67
|
+
if (paths.length === 0) continue;
|
|
68
|
+
const file = join(dir, part === "history" ? "history.json" : part);
|
|
69
|
+
const where = relative(process.cwd(), file) || file;
|
|
70
|
+
if (serving && (part === "history" || part === "board")) fail(`clean: ${where} is the running dev server's: stop it, then clean again.`);
|
|
71
|
+
found.push({
|
|
72
|
+
label: where,
|
|
73
|
+
paths,
|
|
74
|
+
size: paths.reduce((s, p) => s + sizeOf(p), 0)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const machine = transcribeDir();
|
|
79
|
+
if (parts.includes("transcribe") && existsSync(machine)) found.push({
|
|
80
|
+
label: machine,
|
|
81
|
+
paths: [machine],
|
|
82
|
+
size: sizeOf(machine)
|
|
83
|
+
});
|
|
84
|
+
if (found.length === 0) {
|
|
85
|
+
console.log(`Nothing to clean near here${asked.length === 0 ? ` (no shots, recordings or voice clips; ${ME} clean all for the rest)` : ""}.`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const width = Math.max(...found.map((f) => f.label.length));
|
|
89
|
+
for (const f of found) console.log(` ${f.label.padEnd(width)} ${bytes(f.size)}`);
|
|
90
|
+
const total = bytes(found.reduce((s, f) => s + f.size, 0));
|
|
91
|
+
const yes = values.yes === true || (process.stdin.isTTY && process.stdout.isTTY ? await ask(`Delete these, ${total}?`) : void 0);
|
|
92
|
+
if (yes === void 0) {
|
|
93
|
+
console.log(`Nothing deleted. ${ME} clean ${[...asked, "--yes"].join(" ")} deletes these (${total}).`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!yes) return;
|
|
97
|
+
for (const f of found) for (const p of f.paths) rmSync(p, {
|
|
98
|
+
recursive: true,
|
|
99
|
+
force: true
|
|
100
|
+
});
|
|
101
|
+
console.log(`Deleted ${total}.`);
|
|
102
|
+
}
|
|
103
|
+
export { run };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=clean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean.js","names":[],"sources":["../../src/cli/clean.ts"],"sourcesContent":["/**\n * `deictic clean`: deletes what deictic kept, for a person who'd rather not delete `.deictic/` by hand. It says what\n * it found and how big, then asks; with no terminal to ask on, it deletes only with `--yes`, so an agent sees the list\n * first. By default the shots, recordings and voice clips, which tasks carry on the board anyway; the history (undo)\n * and the local board (its tasks) only when named, and only with the dev server stopped, as a running one holds both.\n * Transcription's install is outside the project, shared by every project on the machine, so only when named.\n */\nimport { existsSync, readdirSync, rmSync, statSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport { createInterface } from 'node:readline/promises';\n\nimport { alive, runningAt } from '#src/plugins/tasks/local.ts';\n\nimport { deicticDirs, fail, ME } from './board.ts';\nimport { transcribeDir } from './transcribe.ts';\n\nconst CAPTURES = ['screenshots', 'recordings', 'voice'] as const;\nconst PROJECT = [...CAPTURES, 'history', 'board'] as const;\ntype Part = (typeof PROJECT)[number] | 'transcribe';\n\n/** What one part of a `.deictic/` is on disk: the paths to delete. */\nfunction pathsOf(dir: string, part: Part): string[] {\n if (part === 'history') return [join(dir, 'history.json')].filter((p) => existsSync(p));\n if (part === 'board') return [join(dir, 'board'), join(dir, 'board.json')].filter((p) => existsSync(p));\n const folder = join(dir, part);\n if (!existsSync(folder)) return [];\n // A recording still going is its `.part`: the plugin drops one nobody ended a day on.\n return readdirSync(folder)\n .filter((f) => !f.endsWith('.part'))\n .map((f) => join(folder, f));\n}\n\nfunction sizeOf(path: string): number {\n const stat = statSync(path);\n if (!stat.isDirectory()) return stat.size;\n return readdirSync(path).reduce((sum, f) => sum + sizeOf(join(path, f)), 0);\n}\n\nconst UNITS = [\n ['GB', 1e9],\n ['MB', 1e6],\n ['KB', 1e3],\n] as const;\n\nfunction bytes(n: number): string {\n const unit = UNITS.find(([, size]) => n >= size);\n return unit === undefined ? `${n} bytes` : `${(n / unit[1]).toFixed(1)} ${unit[0]}`;\n}\n\ninterface Found {\n label: string;\n paths: string[];\n size: number;\n}\n\nasync function ask(question: string): Promise<boolean> {\n const lines = createInterface({ input: process.stdin, output: process.stdout });\n try {\n return /^y/i.test((await lines.question(`${question} (y/N) `)).trim());\n } finally {\n lines.close();\n }\n}\n\nexport async function run(asked: string[], values: { yes?: boolean }): Promise<void> {\n const named = asked.filter((p): p is Part => p !== 'all');\n const parts = asked.length === 0 ? [...CAPTURES] : [...new Set([...(asked.includes('all') ? PROJECT : []), ...named])];\n\n const found: Found[] = [];\n for (const dir of deicticDirs()) {\n const running = runningAt(join(dir, 'board.json'));\n const serving = running !== undefined && alive(running.pid);\n for (const part of parts.filter((p) => p !== 'transcribe')) {\n const paths = pathsOf(dir, part);\n if (paths.length === 0) continue;\n const file = join(dir, part === 'history' ? 'history.json' : part);\n const where = relative(process.cwd(), file) || file;\n if (serving && (part === 'history' || part === 'board'))\n fail(`clean: ${where} is the running dev server's: stop it, then clean again.`);\n found.push({ label: where, paths, size: paths.reduce((s, p) => s + sizeOf(p), 0) });\n }\n }\n const machine = transcribeDir();\n if (parts.includes('transcribe') && existsSync(machine)) found.push({ label: machine, paths: [machine], size: sizeOf(machine) });\n\n if (found.length === 0) {\n console.log(\n `Nothing to clean near here${asked.length === 0 ? ` (no shots, recordings or voice clips; ${ME} clean all for the rest)` : ''}.`,\n );\n return;\n }\n const width = Math.max(...found.map((f) => f.label.length));\n for (const f of found) console.log(` ${f.label.padEnd(width)} ${bytes(f.size)}`);\n const total = bytes(found.reduce((s, f) => s + f.size, 0));\n\n const yes = values.yes === true || (process.stdin.isTTY && process.stdout.isTTY ? await ask(`Delete these, ${total}?`) : undefined);\n if (yes === undefined) {\n console.log(`Nothing deleted. ${ME} clean ${[...asked, '--yes'].join(' ')} deletes these (${total}).`);\n return;\n }\n if (!yes) return;\n for (const f of found) for (const p of f.paths) rmSync(p, { recursive: true, force: true });\n console.log(`Deleted ${total}.`);\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,WAAW;CAAC;CAAe;CAAc;AAAO;AACtD,MAAM,UAAU;CAAC,GAAG;CAAU;CAAW;AAAO;;AAIhD,SAAS,QAAQ,KAAa,MAAsB;CAClD,IAAI,SAAS,WAAW,OAAO,CAAC,KAAK,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,MAAM,WAAW,CAAC,CAAC;CACtF,IAAI,SAAS,SAAS,OAAO,CAAC,KAAK,KAAK,OAAO,GAAG,KAAK,KAAK,YAAY,CAAC,CAAC,CAAC,QAAQ,MAAM,WAAW,CAAC,CAAC;CACtG,MAAM,SAAS,KAAK,KAAK,IAAI;CAC7B,IAAI,CAAC,WAAW,MAAM,GAAG,OAAO,CAAC;CAEjC,OAAO,YAAY,MAAM,CAAC,CACvB,QAAQ,MAAM,CAAC,EAAE,SAAS,OAAO,CAAC,CAAC,CACnC,KAAK,MAAM,KAAK,QAAQ,CAAC,CAAC;AAC/B;AAEA,SAAS,OAAO,MAAsB;CACpC,MAAM,OAAO,SAAS,IAAI;CAC1B,IAAI,CAAC,KAAK,YAAY,GAAG,OAAO,KAAK;CACrC,OAAO,YAAY,IAAI,CAAC,CAAC,QAAQ,KAAK,MAAM,MAAM,OAAO,KAAK,MAAM,CAAC,CAAC,GAAG,CAAC;AAC5E;AAEA,MAAM,QAAQ;CACZ,CAAC,MAAM,GAAG;CACV,CAAC,MAAM,GAAG;CACV,CA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from "node:path";
|
|
4
4
|
import { t as keptIn } from "./kept.js";
|
|
5
5
|
import { c as setUp, f as isHost, g as parse, h as openingsIn, l as ASTRO, m as offsetOf, p as lineStarts, u as parseAstro } from "./integration.js";
|
|
6
|
-
import {
|
|
6
|
+
import { r as missingMessage } from "./packages.js";
|
|
7
7
|
// src/tools/source.ts
|
|
8
8
|
/**
|
|
9
9
|
* The source a server half reads: a target's file, parsed, and the opening tag the page's attribute
|
|
@@ -24,14 +24,21 @@ function readSource(root, file) {
|
|
|
24
24
|
throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the
|
|
29
|
+
* only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.
|
|
30
|
+
*/
|
|
28
31
|
function sourceAt(root, target) {
|
|
29
32
|
const { file, line, column } = target.loc;
|
|
30
33
|
const code = readSource(root, file);
|
|
31
|
-
const
|
|
34
|
+
const lines = lineStarts(code);
|
|
35
|
+
const offset = offsetOf(lines, line, column);
|
|
32
36
|
const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);
|
|
33
|
-
const
|
|
34
|
-
|
|
37
|
+
const tagged = elements.filter((el) => isHost(el) && el.name.type === "JSXIdentifier" && el.name.name === target.tag);
|
|
38
|
+
const start = lines[line - 1];
|
|
39
|
+
const onLine = start === void 0 ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? 1e400));
|
|
40
|
+
const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : void 0);
|
|
41
|
+
if (element === void 0) throw new Refusal(notThere(target, code, lines, onLine.length));
|
|
35
42
|
return {
|
|
36
43
|
file,
|
|
37
44
|
code,
|
|
@@ -40,6 +47,12 @@ function sourceAt(root, target) {
|
|
|
40
47
|
read: (other) => readSource(root, other)
|
|
41
48
|
};
|
|
42
49
|
}
|
|
50
|
+
/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */
|
|
51
|
+
function notThere({ loc: { file, line, column }, tag }, code, lines, onLine) {
|
|
52
|
+
const start = lines[line - 1];
|
|
53
|
+
return `${start === void 0 ? `${file} has no line ${line}` : onLine === 0 ? `line ${line} of ${file} has no <${tag}>: it reads \`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\`` : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;
|
|
54
|
+
}
|
|
55
|
+
const clip = (text) => text.length > 80 ? `${text.slice(0, 79)}…` : text;
|
|
43
56
|
function jsx(file, code) {
|
|
44
57
|
const { program, errors } = parse(file, code);
|
|
45
58
|
if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0].message})`);
|
|
@@ -258,13 +271,18 @@ function endpoints({ root, plugins, base = "/", open, history = new History(root
|
|
|
258
271
|
apply: async ({ plugin: name, target, op }) => {
|
|
259
272
|
const plugin = pluginOf(name);
|
|
260
273
|
if (plugin.apply === void 0) throw new Refusal(`${name} changes nothing from its panel: it has no \`apply\``);
|
|
261
|
-
const source =
|
|
262
|
-
const before = await readOf(plugin, target);
|
|
274
|
+
const source = sourceOf(target);
|
|
275
|
+
const before = await readOf(plugin, target, source);
|
|
263
276
|
const { file, line } = target.loc;
|
|
264
277
|
const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? "edit"}`;
|
|
265
278
|
const result = await plugin.apply(source, target, op);
|
|
266
279
|
const scope = scopeOf(name, target.loc);
|
|
267
|
-
|
|
280
|
+
if (!Array.isArray(result)) return {
|
|
281
|
+
change: history.record(label, name, result.done, scope),
|
|
282
|
+
model: await readOf(plugin, target)
|
|
283
|
+
};
|
|
284
|
+
if (source instanceof Refusal) throw source;
|
|
285
|
+
const change = history.commit(label, applyEdits(source, result), scope);
|
|
268
286
|
return {
|
|
269
287
|
model: await readOf(plugin, target),
|
|
270
288
|
change
|
|
@@ -273,7 +291,15 @@ function endpoints({ root, plugins, base = "/", open, history = new History(root
|
|
|
273
291
|
undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),
|
|
274
292
|
redo: async (body) => ({ change: await history.redo(scopeIn(body)) })
|
|
275
293
|
};
|
|
276
|
-
const
|
|
294
|
+
const sourceOf = (target) => {
|
|
295
|
+
try {
|
|
296
|
+
return sourceAt(root, target);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
if (e instanceof Refusal) return e;
|
|
299
|
+
throw e;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
const readOf = (plugin, target, source) => plugin.read === void 0 ? null : plugin.read(source ?? sourceOf(target), target);
|
|
277
303
|
let queue = Promise.resolve();
|
|
278
304
|
const serially = (run) => {
|
|
279
305
|
const next = queue.then(run, run);
|