rushes 0.2.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/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +10 -0
- package/.mcp.json +8 -0
- package/AGENTS.md +110 -0
- package/LICENSE +21 -0
- package/README.md +204 -0
- package/dist/cli/demo.js +339 -0
- package/dist/cli/doctor.js +307 -0
- package/dist/cli/index.js +11 -0
- package/dist/cli/main.js +469 -0
- package/dist/core/batches.js +58 -0
- package/dist/core/errors.js +37 -0
- package/dist/core/exportNotes.js +132 -0
- package/dist/core/ids.js +42 -0
- package/dist/core/media.js +128 -0
- package/dist/core/notes.js +117 -0
- package/dist/core/paths.js +17 -0
- package/dist/core/project.js +200 -0
- package/dist/core/schema.js +220 -0
- package/dist/core/script.js +113 -0
- package/dist/core/store.js +132 -0
- package/dist/core/tabs.js +24 -0
- package/dist/mcp/client.js +50 -0
- package/dist/mcp/ensure.js +69 -0
- package/dist/mcp/stdio.js +47 -0
- package/dist/mcp/tools.js +191 -0
- package/dist/server/app.js +710 -0
- package/dist/server/assets.js +234 -0
- package/dist/server/files.js +170 -0
- package/dist/server/lock.js +148 -0
- package/dist/server/loudness.js +331 -0
- package/dist/server/proxy.js +575 -0
- package/dist/server/reveal.js +71 -0
- package/dist/server/start.js +125 -0
- package/dist/server/watch.js +133 -0
- package/dist/setup/env.js +42 -0
- package/dist/setup/harnesses.js +93 -0
- package/dist/setup/setup.js +92 -0
- package/package.json +54 -0
- package/skills/rushes/SKILL.md +30 -0
- package/web-dist/assets/figtree-latin-400-normal-BD4aNku5.woff +0 -0
- package/web-dist/assets/figtree-latin-400-normal-g7Dtegnw.woff2 +0 -0
- package/web-dist/assets/figtree-latin-500-normal-BWnGEVsr.woff2 +0 -0
- package/web-dist/assets/figtree-latin-500-normal-B_yy1phn.woff +0 -0
- package/web-dist/assets/figtree-latin-600-normal-BM_oTo4n.woff +0 -0
- package/web-dist/assets/figtree-latin-600-normal-Cv_xCTDl.woff2 +0 -0
- package/web-dist/assets/figtree-latin-700-normal-BCCt2T1q.woff +0 -0
- package/web-dist/assets/figtree-latin-700-normal-th6qEP7c.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-400-normal-CXAzuTZb.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-400-normal-Gbh-3PTk.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-500-normal-BOEJvrb_.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-500-normal-Du0rIuHj.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-600-normal-CQqsimlV.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-600-normal-DJlfifZj.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-700-normal-BoDi4KL2.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-700-normal-CS4sQkGV.woff2 +0 -0
- package/web-dist/assets/index-BjDIT_wL.css +1 -0
- package/web-dist/assets/index-DF6Rl-Ac.js +3 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
- package/web-dist/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
- package/web-dist/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
- package/web-dist/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
- package/web-dist/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
- package/web-dist/index.html +14 -0
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { basename, resolve } from "node:path";
|
|
4
|
+
import { Store } from "../core/store.js";
|
|
5
|
+
import { ffmpegRunner, makeDemo, sayAvailable, sayRunner } from "./demo.js";
|
|
6
|
+
import { startServer, DEFAULT_PORT } from "../server/start.js";
|
|
7
|
+
import { ensureServer, findServer } from "../mcp/ensure.js";
|
|
8
|
+
import { AlreadyRunningError, canonicalRoot } from "../server/lock.js";
|
|
9
|
+
import { ApiError, RushesClient, dashboardUrlFor } from "../mcp/client.js";
|
|
10
|
+
import { openBrowser, runStdio } from "../mcp/stdio.js";
|
|
11
|
+
import { VERSION } from "../server/app.js";
|
|
12
|
+
import { markLabel } from "../core/schema.js";
|
|
13
|
+
import { onLabel } from "../core/notes.js";
|
|
14
|
+
import { setup } from "../setup/setup.js";
|
|
15
|
+
import { realSetupEnv } from "../setup/env.js";
|
|
16
|
+
import { runDoctor, realDoctorEnv } from "./doctor.js";
|
|
17
|
+
export const HELP = `rushes ${VERSION}: a local review desk for video made with AI agents
|
|
18
|
+
|
|
19
|
+
Usage
|
|
20
|
+
rushes open [dir] [--port 4580] [--no-browser] start the review desk and open it
|
|
21
|
+
rushes serve [dir] [--port 4580] [--idle-minutes N]
|
|
22
|
+
start the server without a browser (stops after N idle minutes)
|
|
23
|
+
rushes stop [dir] stop the project's running server
|
|
24
|
+
rushes init [dir] [--name NAME] create the .rushes folder
|
|
25
|
+
rushes demo [dir] [--no-browser] create an example project with generated media (default ./rushes-demo), then open it
|
|
26
|
+
rushes setup [--only claude-code,codex,...] [--dry-run]
|
|
27
|
+
add Rushes to every agent harness on this machine
|
|
28
|
+
rushes mcp run the MCP server over stdio
|
|
29
|
+
rushes status [dir] tabs and open items
|
|
30
|
+
rushes doctor [dir] [--json] check Node, ffmpeg, agent harnesses and this project
|
|
31
|
+
rushes add version <file> --video NAME [--note TEXT]
|
|
32
|
+
rushes add variant <music|sfx|voice> <file> --name NAME [--lane ID] [--round NAME] [--description TEXT]
|
|
33
|
+
rushes add shots <file.json> --video NAME [--version V]
|
|
34
|
+
rushes add file <path> --kind K [--name NAME] [--note TEXT] [--video V]
|
|
35
|
+
register a doc, image, caption, export, delivery or edit file
|
|
36
|
+
rushes lock <video> <version> lock the picture at a cut
|
|
37
|
+
rushes unlock <video> unlock the picture
|
|
38
|
+
rushes notes [--stage S] [--status todo|done] [--batch ID] [--json]
|
|
39
|
+
rushes reply <note-id> <text> [--done] [--fix-t SECONDS] [--fix-version V]
|
|
40
|
+
rushes assets [--kind K] [--json] cuts, takes, variants, screenshots and library files
|
|
41
|
+
rushes export notes write notes to exports/<slug>-notes-<date>.md
|
|
42
|
+
|
|
43
|
+
Options
|
|
44
|
+
--dir DIR project folder for commands that talk to the server (default: current folder)
|
|
45
|
+
`;
|
|
46
|
+
const OPTIONS = {
|
|
47
|
+
port: { type: "string" },
|
|
48
|
+
"no-browser": { type: "boolean" },
|
|
49
|
+
name: { type: "string" },
|
|
50
|
+
video: { type: "string" },
|
|
51
|
+
note: { type: "string" },
|
|
52
|
+
lane: { type: "string" },
|
|
53
|
+
round: { type: "string" },
|
|
54
|
+
description: { type: "string" },
|
|
55
|
+
stage: { type: "string" },
|
|
56
|
+
status: { type: "string" },
|
|
57
|
+
batch: { type: "string" },
|
|
58
|
+
kind: { type: "string" },
|
|
59
|
+
json: { type: "boolean" },
|
|
60
|
+
done: { type: "boolean" },
|
|
61
|
+
"fix-t": { type: "string" },
|
|
62
|
+
"fix-version": { type: "string" },
|
|
63
|
+
dir: { type: "string" },
|
|
64
|
+
only: { type: "string" },
|
|
65
|
+
"dry-run": { type: "boolean" },
|
|
66
|
+
"idle-minutes": { type: "string" },
|
|
67
|
+
help: { type: "boolean", short: "h" },
|
|
68
|
+
version: { type: "boolean", short: "v" },
|
|
69
|
+
};
|
|
70
|
+
// "demo" is here too: without --no-browser it ends by running "open" (a server that keeps
|
|
71
|
+
// running), so index.ts must not process.exit() the moment main() first resolves. With
|
|
72
|
+
// --no-browser nothing is left open, so the process still exits on its own once main() resolves.
|
|
73
|
+
const LONG_RUNNING = ["open", "serve", "mcp", "demo"];
|
|
74
|
+
/** Does this command line start something that keeps running (open, serve, mcp, demo)? Flags before the command are skipped. */
|
|
75
|
+
export function longRunningCommand(argv) {
|
|
76
|
+
try {
|
|
77
|
+
const [cmd] = parseArgs({ args: argv, options: OPTIONS, allowPositionals: true }).positionals;
|
|
78
|
+
return LONG_RUNNING.includes(cmd ?? "");
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const STRING_OPTIONS = new Set(Object.entries(OPTIONS).filter(([, def]) => def.type === "string").map(([name]) => name));
|
|
85
|
+
/**
|
|
86
|
+
* The index of the first positional, tolerant of leading global flags. A hand-rolled scan
|
|
87
|
+
* rather than a `parseArgs` probe, because `--version=<value>` must be recognised here even
|
|
88
|
+
* though `version` is declared boolean (parseArgs would throw on that combination, and we need
|
|
89
|
+
* this to succeed precisely so we can strip that flag out before the real parse).
|
|
90
|
+
*/
|
|
91
|
+
function firstPositionalIndex(argv) {
|
|
92
|
+
for (let i = 0; i < argv.length; i++) {
|
|
93
|
+
const tok = argv[i];
|
|
94
|
+
if (tok === "--")
|
|
95
|
+
return i + 1 < argv.length ? i + 1 : -1;
|
|
96
|
+
if (tok.startsWith("--")) {
|
|
97
|
+
const eq = tok.indexOf("=");
|
|
98
|
+
const name = eq >= 0 ? tok.slice(2, eq) : tok.slice(2);
|
|
99
|
+
if (eq < 0 && STRING_OPTIONS.has(name))
|
|
100
|
+
i++; // takes the next token as its value
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (tok.startsWith("-") && tok.length > 1)
|
|
104
|
+
continue; // a short flag; none of ours take a value
|
|
105
|
+
return i;
|
|
106
|
+
}
|
|
107
|
+
return -1;
|
|
108
|
+
}
|
|
109
|
+
/** The command name (first positional), tolerant of leading global flags. */
|
|
110
|
+
function firstPositional(argv) {
|
|
111
|
+
const i = firstPositionalIndex(argv);
|
|
112
|
+
return i >= 0 ? argv[i] : undefined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* `rushes add shots` has its own `--version <value>` / `--version=<value>`, which takes a value
|
|
116
|
+
* and can appear in any position. That collides with the global `--version`/`-v` flag, which
|
|
117
|
+
* `node:util parseArgs` only knows how to treat as boolean (no subcommand, "print the package
|
|
118
|
+
* version"): with one flat option table, `--version v2` ahead of the file name would otherwise
|
|
119
|
+
* parse as `{version: true}` plus a stray positional, scrambling positional order. So for
|
|
120
|
+
* `add ...`, pull the flag and its value out of argv textually before parseArgs ever sees it.
|
|
121
|
+
*/
|
|
122
|
+
function extractAddVersionFlag(argv) {
|
|
123
|
+
const rest = [...argv];
|
|
124
|
+
for (let i = 0; i < rest.length; i++) {
|
|
125
|
+
const tok = rest[i];
|
|
126
|
+
if (tok === "--version" || tok === "-v") {
|
|
127
|
+
const value = rest[i + 1];
|
|
128
|
+
// A bare --version (last, or followed by another flag) has no value: say so rather than eat the next flag.
|
|
129
|
+
if (value === undefined || value.startsWith("-"))
|
|
130
|
+
return { value: undefined, rest, missing: true };
|
|
131
|
+
rest.splice(i, 2);
|
|
132
|
+
return { value, rest };
|
|
133
|
+
}
|
|
134
|
+
if (tok.startsWith("--version=")) {
|
|
135
|
+
const value = tok.slice("--version=".length);
|
|
136
|
+
if (!value)
|
|
137
|
+
return { value: undefined, rest, missing: true };
|
|
138
|
+
rest.splice(i, 1);
|
|
139
|
+
return { value, rest };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { value: undefined, rest };
|
|
143
|
+
}
|
|
144
|
+
/** Run the CLI. Returns an exit code. Long-running commands (open, serve, mcp) resolve once started. */
|
|
145
|
+
export async function main(argv, io) {
|
|
146
|
+
// The "add" command gets its own --version <value> pulled out before the real parse (see
|
|
147
|
+
// extractAddVersionFlag); every other command's --version/-v stays the global boolean flag.
|
|
148
|
+
// Only the tokens after "add" itself are scanned for it: `rushes -v add ...` has its own
|
|
149
|
+
// leading -v ahead of the positional, which must keep meaning the global version flag, not
|
|
150
|
+
// be eaten as the add command's --version value (and "add" itself mistaken for that value).
|
|
151
|
+
let addVersion;
|
|
152
|
+
const addAt = firstPositionalIndex(argv);
|
|
153
|
+
if (addAt >= 0 && argv[addAt] === "add") {
|
|
154
|
+
const extracted = extractAddVersionFlag(argv.slice(addAt + 1));
|
|
155
|
+
if (extracted.missing)
|
|
156
|
+
return usage(io, "--version needs a value, e.g. --version v2");
|
|
157
|
+
addVersion = extracted.value;
|
|
158
|
+
argv = [...argv.slice(0, addAt + 1), ...extracted.rest];
|
|
159
|
+
}
|
|
160
|
+
let parsed;
|
|
161
|
+
try {
|
|
162
|
+
parsed = parseArgs({ args: argv, options: OPTIONS, allowPositionals: true });
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
io.err(e.message);
|
|
166
|
+
io.err(HELP);
|
|
167
|
+
return 2;
|
|
168
|
+
}
|
|
169
|
+
const { values: o, positionals: p } = parsed;
|
|
170
|
+
const [cmd, ...rest] = p;
|
|
171
|
+
// A bare `--version`/`-v` prints the package version; on a subcommand (e.g. "add shots
|
|
172
|
+
// ... --version v2") the same boolean flag is set, but there's a command to run instead.
|
|
173
|
+
if (!cmd && o.version)
|
|
174
|
+
return io.out(VERSION), 0;
|
|
175
|
+
if (!cmd || o.help || cmd === "help")
|
|
176
|
+
return io.out(HELP), 0;
|
|
177
|
+
const dir = resolve(io.cwd, o.dir ?? ".");
|
|
178
|
+
const client = () => ensureServer(dir, io.ensure);
|
|
179
|
+
try {
|
|
180
|
+
switch (cmd) {
|
|
181
|
+
case "open":
|
|
182
|
+
case "serve": {
|
|
183
|
+
const root = await canonicalRoot(resolve(io.cwd, rest[0] ?? "."));
|
|
184
|
+
const show = (url) => {
|
|
185
|
+
if (cmd === "open" && !o["no-browser"])
|
|
186
|
+
(io.openBrowser ?? openBrowser)(url);
|
|
187
|
+
};
|
|
188
|
+
const already = async (url) => {
|
|
189
|
+
const dashboardUrl = await dashboardUrlFor(url);
|
|
190
|
+
io.out(`Rushes is already running for ${root}\n${dashboardUrl}`);
|
|
191
|
+
show(dashboardUrl);
|
|
192
|
+
return 0;
|
|
193
|
+
};
|
|
194
|
+
const running = await findServer(root);
|
|
195
|
+
if (running)
|
|
196
|
+
return already(running);
|
|
197
|
+
const idle = o["idle-minutes"] === undefined ? undefined : Number(o["idle-minutes"]);
|
|
198
|
+
if (idle !== undefined && !(Number.isFinite(idle) && idle > 0))
|
|
199
|
+
return usage(io, "--idle-minutes must be a number of minutes above 0");
|
|
200
|
+
let s;
|
|
201
|
+
try {
|
|
202
|
+
s = await startServer(root, { port: o.port ? Number(o.port) : DEFAULT_PORT, idleMs: idle ? idle * 60_000 : undefined });
|
|
203
|
+
}
|
|
204
|
+
catch (e) {
|
|
205
|
+
// Another server won the race between the check above and our start.
|
|
206
|
+
if (e instanceof AlreadyRunningError)
|
|
207
|
+
return already(e.url);
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
210
|
+
io.out(`Rushes is running for ${root}\n${s.dashboardUrl}`);
|
|
211
|
+
show(s.dashboardUrl);
|
|
212
|
+
if (io.onServer)
|
|
213
|
+
return io.onServer(s), 0;
|
|
214
|
+
// Exit once the server closes for any reason: a signal, `rushes stop`, or the idle timer.
|
|
215
|
+
void s.closed.then(() => process.exit(0));
|
|
216
|
+
const stopSig = () => void s.close();
|
|
217
|
+
process.once("SIGINT", stopSig);
|
|
218
|
+
process.once("SIGTERM", stopSig);
|
|
219
|
+
return 0;
|
|
220
|
+
}
|
|
221
|
+
case "stop": {
|
|
222
|
+
const root = await canonicalRoot(resolve(io.cwd, rest[0] ?? "."));
|
|
223
|
+
const url = await findServer(root);
|
|
224
|
+
if (!url)
|
|
225
|
+
return io.out(`Rushes isn't running for ${root}`), 0;
|
|
226
|
+
await new RushesClient(url).post("/api/shutdown", {});
|
|
227
|
+
io.out(`Stopped Rushes for ${root}`);
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
case "init": {
|
|
231
|
+
const root = resolve(io.cwd, rest[0] ?? ".");
|
|
232
|
+
await new Store(root).init(o.name ?? basename(root));
|
|
233
|
+
io.out(`Created ${root}/.rushes`);
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
236
|
+
case "demo": {
|
|
237
|
+
const target = resolve(io.cwd, rest[0] ?? "rushes-demo");
|
|
238
|
+
const say = (await sayAvailable(sayRunner)) ? sayRunner : null;
|
|
239
|
+
const { dir } = await makeDemo(target, { ffmpeg: ffmpegRunner, say, now: new Date() });
|
|
240
|
+
io.out(`Created ${dir}`);
|
|
241
|
+
// §19.2: opens it, same as `rushes open`, unless told not to -- "demo" is in LONG_RUNNING
|
|
242
|
+
// precisely so this nested server (when it starts) keeps the process alive.
|
|
243
|
+
if (o["no-browser"])
|
|
244
|
+
return 0;
|
|
245
|
+
return main(["open", dir], io);
|
|
246
|
+
}
|
|
247
|
+
case "setup": {
|
|
248
|
+
const only = o.only ? o.only.split(",").map((x) => x.trim()) : undefined;
|
|
249
|
+
const results = await setup(io.setupEnv ?? realSetupEnv(), { only, dryRun: o["dry-run"] });
|
|
250
|
+
const mark = { added: "+", "would-add": "~", already: "=", "not-found": "-", failed: "!" };
|
|
251
|
+
for (const r of results) {
|
|
252
|
+
const skill = r.skill ? `, skill ${r.skill}` : "";
|
|
253
|
+
io.out(`${mark[r.status]} ${r.name.padEnd(15)} ${r.status}${skill}${r.status === "not-found" ? "" : ` ${r.detail}`}`);
|
|
254
|
+
}
|
|
255
|
+
const added = results.filter((r) => r.status === "added").length;
|
|
256
|
+
if (added)
|
|
257
|
+
io.out(`\nRestart ${added === 1 ? "that app" : "those apps"} so ${added === 1 ? "it picks" : "they pick"} up the rushes tools. Then ask your agent to "open Rushes".`);
|
|
258
|
+
if (!results.some((r) => r.status !== "not-found"))
|
|
259
|
+
io.out("No supported agent harness found. See https://github.com/iamredmh/rushes#other-harnesses");
|
|
260
|
+
return results.some((r) => r.status === "failed") ? 1 : 0;
|
|
261
|
+
}
|
|
262
|
+
case "mcp":
|
|
263
|
+
await runStdio(io.cwd);
|
|
264
|
+
return 0;
|
|
265
|
+
case "status": {
|
|
266
|
+
const root = rest[0] ? resolve(io.cwd, rest[0]) : dir;
|
|
267
|
+
const { tabs } = await (await ensureServer(root, io.ensure)).get("/api/tabs");
|
|
268
|
+
for (const t of tabs) {
|
|
269
|
+
io.out(`${t.stage.padEnd(8)} ${t.unlocked ? "open " : "locked"} ${t.todo ? `${t.todo} to do` : ""}`.trimEnd());
|
|
270
|
+
}
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
case "doctor": {
|
|
274
|
+
const root = rest[0] ? resolve(io.cwd, rest[0]) : dir;
|
|
275
|
+
const checks = await runDoctor(io.doctorEnv ?? realDoctorEnv(root));
|
|
276
|
+
if (o.json) {
|
|
277
|
+
io.out(JSON.stringify(checks, null, 2));
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
for (const c of checks) {
|
|
281
|
+
const fix = !c.ok && c.fix ? ` Fix: ${c.fix}` : "";
|
|
282
|
+
io.out(`${c.ok ? "✓" : "✗"} ${c.label} — ${c.detail}${fix}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return checks.some((c) => c.required && !c.ok) ? 1 : 0;
|
|
286
|
+
}
|
|
287
|
+
case "add": {
|
|
288
|
+
const [what, a, b] = rest;
|
|
289
|
+
if (what === "version") {
|
|
290
|
+
if (!a || !o.video)
|
|
291
|
+
return usage(io, "rushes add version <file> --video NAME");
|
|
292
|
+
const r = await (await client()).post("/api/versions", { video: o.video, file: resolve(io.cwd, a), note: o.note });
|
|
293
|
+
io.out(`Added ${r.video.name} ${r.version.id}`);
|
|
294
|
+
// §19.5: the server says when this cut is likely to play badly in a browser.
|
|
295
|
+
if (r.proxySuggested)
|
|
296
|
+
io.out(`Proxy suggested: ${r.proxyReason}.${r.proxyJob ? " Making one now (autoProxy is on)." : " Create one from Picture."}`);
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
299
|
+
if (what === "variant") {
|
|
300
|
+
if (!a || !b || !o.name)
|
|
301
|
+
return usage(io, "rushes add variant <music|sfx|voice> <file> --name NAME");
|
|
302
|
+
const r = await (await client()).post("/api/variants", { stage: a, file: resolve(io.cwd, b), name: o.name, lane: o.lane, round: o.round, description: o.description });
|
|
303
|
+
io.out(`Added ${r.lane.name}: ${r.variant.name}`);
|
|
304
|
+
return 0;
|
|
305
|
+
}
|
|
306
|
+
if (what === "shots") {
|
|
307
|
+
if (!a || !o.video)
|
|
308
|
+
return usage(io, "rushes add shots <file.json> --video NAME [--version V]");
|
|
309
|
+
// Read and parse the file before touching the server, so a bad file is always exit 2,
|
|
310
|
+
// never masked by a server-reachability error.
|
|
311
|
+
let parsed;
|
|
312
|
+
try {
|
|
313
|
+
parsed = JSON.parse(await readFile(resolve(io.cwd, a), "utf8"));
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
io.err(`Couldn't read shots from "${a}": ${e.message}`);
|
|
317
|
+
return 2;
|
|
318
|
+
}
|
|
319
|
+
// Either a bare array, or an object wrapping one under "shots" (the shape rushes_set_shots
|
|
320
|
+
// takes, so a file saved from its reply round-trips straight back in).
|
|
321
|
+
const shots = Array.isArray(parsed)
|
|
322
|
+
? parsed
|
|
323
|
+
: Array.isArray(parsed?.shots)
|
|
324
|
+
? parsed.shots
|
|
325
|
+
: undefined;
|
|
326
|
+
if (shots === undefined) {
|
|
327
|
+
io.err('shots file must be a JSON array of {name, start, tag?} (or {"shots": [...]})');
|
|
328
|
+
return 2;
|
|
329
|
+
}
|
|
330
|
+
const r = await (await client()).put(`/api/videos/${encodeURIComponent(o.video)}/shots`, { version: addVersion, shots });
|
|
331
|
+
io.out(`Shots set on ${o.video} ${r.version.id}: ${r.version.shots.length}`);
|
|
332
|
+
return 0;
|
|
333
|
+
}
|
|
334
|
+
if (what === "file") {
|
|
335
|
+
if (!a || !o.kind)
|
|
336
|
+
return usage(io, "rushes add file <path> --kind K [--name NAME] [--note TEXT] [--video V]");
|
|
337
|
+
const r = await (await client()).post("/api/files", { kind: o.kind, file: resolve(io.cwd, a), name: o.name, note: o.note, video: o.video });
|
|
338
|
+
io.out(`Added ${r.kind}: ${r.name}`);
|
|
339
|
+
return 0;
|
|
340
|
+
}
|
|
341
|
+
return usage(io, "rushes add version|variant|shots|file ...");
|
|
342
|
+
}
|
|
343
|
+
case "lock": {
|
|
344
|
+
const [video, lockVersion] = rest;
|
|
345
|
+
if (!video || !lockVersion)
|
|
346
|
+
return usage(io, "rushes lock <video> <version>");
|
|
347
|
+
await (await client()).put(`/api/videos/${encodeURIComponent(video)}/lock`, { version: lockVersion });
|
|
348
|
+
io.out(`Picture locked at ${lockVersion}`);
|
|
349
|
+
return 0;
|
|
350
|
+
}
|
|
351
|
+
case "unlock": {
|
|
352
|
+
const [video] = rest;
|
|
353
|
+
if (!video)
|
|
354
|
+
return usage(io, "rushes unlock <video>");
|
|
355
|
+
await (await client()).put(`/api/videos/${encodeURIComponent(video)}/lock`, { version: null });
|
|
356
|
+
io.out("Picture unlocked");
|
|
357
|
+
return 0;
|
|
358
|
+
}
|
|
359
|
+
case "notes": {
|
|
360
|
+
const q = new URLSearchParams();
|
|
361
|
+
for (const k of ["stage", "status", "batch"])
|
|
362
|
+
if (o[k])
|
|
363
|
+
q.set(k, o[k]);
|
|
364
|
+
const c = await client();
|
|
365
|
+
const { notes } = await c.get(`/api/notes${q.size ? `?${q}` : ""}`);
|
|
366
|
+
if (o.json)
|
|
367
|
+
return io.out(JSON.stringify(notes, null, 2)), 0;
|
|
368
|
+
// What an audio note is on (M4), resolved against the project, script and picks.
|
|
369
|
+
const ctx = notes.some((n) => n.stage !== "picture" && n.stage !== "script") ? await c.get("/api/state") : null;
|
|
370
|
+
for (const n of notes) {
|
|
371
|
+
const label = ctx ? onLabel(n, ctx) : null;
|
|
372
|
+
const on = label ? `${stripControl(label)} ` : "";
|
|
373
|
+
const shot = n.shot ? `shot ${String(n.shot.n).padStart(2, "0")} ` : "";
|
|
374
|
+
const marks = n.marks?.length ? `${n.marks.map(markLabel).join(" · ")} ` : "";
|
|
375
|
+
io.out(`${n.id} ${n.status === "done" ? "done" : "todo"} ${n.stage.padEnd(7)} ${when(n).padEnd(17)} ${on}${marks}${shot}${n.text}`);
|
|
376
|
+
}
|
|
377
|
+
if (!notes.length)
|
|
378
|
+
io.out("No notes");
|
|
379
|
+
return 0;
|
|
380
|
+
}
|
|
381
|
+
case "assets": {
|
|
382
|
+
const q = o.kind ? `?kind=${encodeURIComponent(o.kind)}` : "";
|
|
383
|
+
const { assets } = await (await client()).get(`/api/assets${q}`);
|
|
384
|
+
if (o.json)
|
|
385
|
+
return io.out(JSON.stringify(assets, null, 2)), 0;
|
|
386
|
+
for (const a of assets) {
|
|
387
|
+
io.out(`${a.kind.padEnd(10)} ${stripControl(a.path)} ${a.missing ? "missing" : humanSize(a.size ?? 0)}`);
|
|
388
|
+
}
|
|
389
|
+
if (!assets.length)
|
|
390
|
+
io.out("No assets");
|
|
391
|
+
return 0;
|
|
392
|
+
}
|
|
393
|
+
case "export": {
|
|
394
|
+
const [what] = rest;
|
|
395
|
+
if (what !== "notes")
|
|
396
|
+
return usage(io, "rushes export notes");
|
|
397
|
+
const r = await (await client()).post("/api/exports/notes", {});
|
|
398
|
+
io.out(`Exported notes to ${r.path}`);
|
|
399
|
+
return 0;
|
|
400
|
+
}
|
|
401
|
+
case "reply": {
|
|
402
|
+
const [id, ...words] = rest;
|
|
403
|
+
const replyUsage = "rushes reply <note-id> <text> [--done] [--fix-t SECONDS] [--fix-version V]";
|
|
404
|
+
if (!id || !words.length)
|
|
405
|
+
return usage(io, replyUsage);
|
|
406
|
+
const fixT = o["fix-t"] === undefined ? undefined : o["fix-t"].trim() === "" ? NaN : Number(o["fix-t"]);
|
|
407
|
+
if (fixT !== undefined && !(Number.isFinite(fixT) && fixT >= 0)) {
|
|
408
|
+
io.err(`--fix-t must be a number of seconds, 0 or more (got "${o["fix-t"]}")`);
|
|
409
|
+
return usage(io, replyUsage);
|
|
410
|
+
}
|
|
411
|
+
const reply = {
|
|
412
|
+
id,
|
|
413
|
+
reply: words.join(" "),
|
|
414
|
+
...(o.done ? { status: "done" } : {}),
|
|
415
|
+
...(fixT !== undefined ? { fixT } : {}),
|
|
416
|
+
...(o["fix-version"] ? { fixVersion: o["fix-version"] } : {}),
|
|
417
|
+
};
|
|
418
|
+
await (await client()).post("/api/replies", { replies: [reply] });
|
|
419
|
+
io.out(`Replied to ${id}`);
|
|
420
|
+
return 0;
|
|
421
|
+
}
|
|
422
|
+
default:
|
|
423
|
+
io.err(`Unknown command "${cmd}"`);
|
|
424
|
+
io.err(HELP);
|
|
425
|
+
return 2;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
catch (e) {
|
|
429
|
+
io.err(e instanceof ApiError ? `${e.message}` : e.message);
|
|
430
|
+
return 1;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function usage(io, line) {
|
|
434
|
+
io.err(`Usage: ${line}`);
|
|
435
|
+
return 2;
|
|
436
|
+
}
|
|
437
|
+
function fmt(t) {
|
|
438
|
+
// Round to hundredths first, so 59.999 becomes 1:00.00 rather than 0:60.00.
|
|
439
|
+
const cs = Math.round(Math.max(0, t) * 100);
|
|
440
|
+
const m = Math.floor(cs / 6000);
|
|
441
|
+
const s = ((cs - m * 6000) / 100).toFixed(2).padStart(5, "0");
|
|
442
|
+
return `${m}:${s}`;
|
|
443
|
+
}
|
|
444
|
+
/** 1536 -> "1.5 KB". Bytes under 1 KB print as a whole number of bytes. */
|
|
445
|
+
function humanSize(bytes) {
|
|
446
|
+
if (bytes < 1024)
|
|
447
|
+
return `${bytes} B`;
|
|
448
|
+
const units = ["KB", "MB", "GB", "TB"];
|
|
449
|
+
let n = bytes / 1024;
|
|
450
|
+
let i = 0;
|
|
451
|
+
while (n >= 1024 && i < units.length - 1) {
|
|
452
|
+
n /= 1024;
|
|
453
|
+
i++;
|
|
454
|
+
}
|
|
455
|
+
return `${n.toFixed(1)} ${units[i]}`;
|
|
456
|
+
}
|
|
457
|
+
/** Drops C0 control characters (U+0000-U+001F) and DEL (U+007F) from a name or path before it
|
|
458
|
+
* reaches a terminal (M5): an odd hand-edit or agent mistake could otherwise move the cursor,
|
|
459
|
+
* clear the line, or ring the bell when `rushes assets` prints it. --json is untouched -- a
|
|
460
|
+
* consumer parsing JSON gets the real value, control characters and all. */
|
|
461
|
+
function stripControl(s) {
|
|
462
|
+
// eslint-disable-next-line no-control-regex -- the whole point is to match control characters.
|
|
463
|
+
return s.replace(/[\x00-\x1f\x7f]/g, "");
|
|
464
|
+
}
|
|
465
|
+
function when(n) {
|
|
466
|
+
if (n.scope === "whole" || n.t === null)
|
|
467
|
+
return "whole";
|
|
468
|
+
return n.scope === "range" && n.tOut !== null ? `${fmt(n.t)}–${fmt(n.tOut)}` : fmt(n.t);
|
|
469
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { EmptyBatchError } from "./errors.js";
|
|
2
|
+
import { isChanged } from "./script.js";
|
|
3
|
+
const STAGE_NAMES = {
|
|
4
|
+
script: "script",
|
|
5
|
+
picture: "picture",
|
|
6
|
+
voice: "voiceover",
|
|
7
|
+
music: "music",
|
|
8
|
+
sfx: "sound effects",
|
|
9
|
+
mix: "mix",
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Gather this tab's open, unsent items into a batch: to-do notes with no
|
|
13
|
+
* batch yet, and (on the script tab) changed or flagged sections.
|
|
14
|
+
*/
|
|
15
|
+
export function createBatch(ctx, stage, now = new Date()) {
|
|
16
|
+
const notes = ctx.notes.notes.filter((n) => n.stage === stage && n.status === "todo" && n.batch === null);
|
|
17
|
+
const sections = stage === "script" ? ctx.script.sections.filter((s) => isChanged(s) || s.status === "flagged") : [];
|
|
18
|
+
if (notes.length === 0 && sections.length === 0)
|
|
19
|
+
throw new EmptyBatchError(stage);
|
|
20
|
+
const id = `b_${ctx.batches.batches.length + 1}`;
|
|
21
|
+
for (const n of notes)
|
|
22
|
+
n.batch = id;
|
|
23
|
+
const batch = {
|
|
24
|
+
id,
|
|
25
|
+
stage,
|
|
26
|
+
noteIds: notes.map((n) => n.id),
|
|
27
|
+
sectionIds: sections.map((s) => s.id),
|
|
28
|
+
sentAt: now.toISOString(),
|
|
29
|
+
prompt: buildPrompt(ctx.project.name, stage, id, notes.length, sections.length),
|
|
30
|
+
};
|
|
31
|
+
ctx.batches.batches.push(batch);
|
|
32
|
+
return batch;
|
|
33
|
+
}
|
|
34
|
+
// §17.7: the audio tabs (Voiceover, Music, Sound effects, Mix) point the agent at the picks as
|
|
35
|
+
// well as the notes, since fixing a note there usually means registering a new take or variant
|
|
36
|
+
// and re-picking it, not just posting a new cut.
|
|
37
|
+
const AUDIO_STAGES = ["voice", "music", "sfx", "mix"];
|
|
38
|
+
export function buildPrompt(project, stage, batchId, notes, sections) {
|
|
39
|
+
const parts = [];
|
|
40
|
+
if (notes)
|
|
41
|
+
parts.push(`${notes} note${notes === 1 ? "" : "s"}`);
|
|
42
|
+
if (sections)
|
|
43
|
+
parts.push(`${sections} script section${sections === 1 ? "" : "s"}`);
|
|
44
|
+
const steps = stage === "script"
|
|
45
|
+
? "Use rushes_get_batch, take each section's proposed line, then rushes_set_script with just those sections (it merges by id). If voiceover already exists, re-record the picked voice with the corrected script and register it with rushes_add_variant as a new read in a new round."
|
|
46
|
+
: stage === "voice"
|
|
47
|
+
? "Use rushes_get_batch and rushes_get_picks. Answer the notes with new whole reads (rushes_add_variant with stage voice and round): a new round for a new direction, or the current round for a small fix to a marked word. Say in each read's description what changed. Then rushes_reply."
|
|
48
|
+
: stage === "mix"
|
|
49
|
+
? // §19.6: rushes_get_picks also carries each lane's level -- where the user wants it sitting.
|
|
50
|
+
'Use rushes_get_batch and rushes_get_picks, fix each note (marks such as "Fall" or "Quieter 3 dB" are part of the note), register the new variant, then rushes_reply. The picks\' levels say where the user wants each lane to sit.'
|
|
51
|
+
: AUDIO_STAGES.includes(stage)
|
|
52
|
+
? 'Use rushes_get_batch and rushes_get_picks, fix each note (marks such as "Fall" or "Quieter 3 dB" are part of the note), register the new variant, then rushes_reply.'
|
|
53
|
+
: "Use rushes_get_batch, fix each note, then rushes_reply with a fixT for each and rushes_add_version for the new cut.";
|
|
54
|
+
return `Work through ${STAGE_NAMES[stage]} batch ${batchId} on ${project}: ${parts.join(" and ")}.\n${steps}`;
|
|
55
|
+
}
|
|
56
|
+
export function latestBatch(file) {
|
|
57
|
+
return file.batches[file.batches.length - 1];
|
|
58
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class RushesError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
code;
|
|
4
|
+
detail;
|
|
5
|
+
constructor(message, status, code, detail = {}) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.detail = detail;
|
|
10
|
+
this.name = new.target.name;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class NotFoundError extends RushesError {
|
|
14
|
+
constructor(what, id) {
|
|
15
|
+
super(`${what} "${id}" not found`, 404, "not_found", { what, id });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class InvalidError extends RushesError {
|
|
19
|
+
constructor(message, issues = []) {
|
|
20
|
+
super(message, 400, "invalid", { issues });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class RevConflictError extends RushesError {
|
|
24
|
+
constructor(file, expected, current) {
|
|
25
|
+
super(`${file} changed (expected rev ${expected}, now ${current})`, 409, "rev_conflict", { file, expected, current });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class CorruptFileError extends RushesError {
|
|
29
|
+
constructor(file, reason) {
|
|
30
|
+
super(`${file} can't be read: ${reason}. It was not changed.`, 500, "corrupt_file", { file, reason });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class EmptyBatchError extends RushesError {
|
|
34
|
+
constructor(stage) {
|
|
35
|
+
super(`Nothing open on the ${stage} tab to send`, 409, "empty_batch", { stage });
|
|
36
|
+
}
|
|
37
|
+
}
|