rushes 0.2.0 → 0.2.2
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/plugin.json +1 -1
- package/AGENTS.md +17 -3
- package/README.md +34 -2
- package/dist/cli/doctor.js +1 -1
- package/dist/cli/main.js +100 -8
- package/dist/core/found.js +333 -0
- package/dist/core/media.js +2 -0
- package/dist/core/schema.js +19 -0
- package/dist/core/store.js +13 -1
- package/dist/mcp/client.js +13 -1
- package/dist/mcp/tools.js +74 -5
- package/dist/server/app.js +159 -8
- package/dist/server/files.js +61 -2
- package/dist/server/found.js +1199 -0
- package/dist/server/peaks.js +471 -0
- package/dist/server/start.js +24 -3
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +4 -2
- package/web-dist/assets/index-DpiDziCn.js +3 -0
- package/web-dist/assets/index-DqCXH_lZ.css +1 -0
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-BjDIT_wL.css +0 -1
- package/web-dist/assets/index-DF6Rl-Ac.js +0 -3
package/dist/core/media.js
CHANGED
|
@@ -48,6 +48,8 @@ async function readProbe(file, timeout, signal) {
|
|
|
48
48
|
try {
|
|
49
49
|
const { stdout } = await run("ffprobe", [
|
|
50
50
|
"-v", "error",
|
|
51
|
+
// Local files only: a playlist or container that names a URL is never followed.
|
|
52
|
+
"-protocol_whitelist", "file",
|
|
51
53
|
"-show_entries", "format=duration:stream=codec_type,codec_name,width,height,pix_fmt,avg_frame_rate,r_frame_rate",
|
|
52
54
|
"-of", "json",
|
|
53
55
|
file,
|
package/dist/core/schema.js
CHANGED
|
@@ -211,10 +211,29 @@ export const BatchesFileSchema = z.object({
|
|
|
211
211
|
rev: z.number().int().nonnegative(),
|
|
212
212
|
batches: z.array(BatchSchema).default([]),
|
|
213
213
|
});
|
|
214
|
+
// §20.6: the found files the user dismissed ("Not these"), as manifest paths. The candidates
|
|
215
|
+
// themselves live in the server's memory; only this list is kept. Created on its first write.
|
|
216
|
+
export const FoundFileSchema = z.object({
|
|
217
|
+
schema: z.literal(1),
|
|
218
|
+
rev: z.number().int().nonnegative(),
|
|
219
|
+
dismissed: z.array(z.string().max(1024)).max(10000).default([]),
|
|
220
|
+
// §20.7: the kinds an agent's `include` settled for a cut (the anchor: its video and version
|
|
221
|
+
// ids), so the scoring never also adds a file of that kind for that cut, on any later scan,
|
|
222
|
+
// start-up or restart. Files from before this field read as empty.
|
|
223
|
+
settled: z
|
|
224
|
+
.array(z.object({
|
|
225
|
+
video: z.string().max(200),
|
|
226
|
+
version: z.string().max(200),
|
|
227
|
+
kinds: z.array(z.enum(["voice", "music", "sfx", "cut", "other"])).max(5),
|
|
228
|
+
}))
|
|
229
|
+
.max(200)
|
|
230
|
+
.default([]),
|
|
231
|
+
});
|
|
214
232
|
export const FILES = {
|
|
215
233
|
project: { name: "project.json", schema: ProjectSchema },
|
|
216
234
|
script: { name: "script.json", schema: ScriptSchema },
|
|
217
235
|
notes: { name: "notes.json", schema: NotesFileSchema },
|
|
218
236
|
picks: { name: "picks.json", schema: PicksSchema },
|
|
219
237
|
batches: { name: "batches.json", schema: BatchesFileSchema },
|
|
238
|
+
found: { name: "found.json", schema: FoundFileSchema },
|
|
220
239
|
};
|
package/dist/core/store.js
CHANGED
|
@@ -17,8 +17,15 @@ function defaults(key, name) {
|
|
|
17
17
|
return { schema: 1, rev: 0, lanes: {}, sections: {}, levels: {} };
|
|
18
18
|
case "batches":
|
|
19
19
|
return { schema: 1, rev: 0, batches: [] };
|
|
20
|
+
case "found":
|
|
21
|
+
return { schema: 1, rev: 0, dismissed: [], settled: [] };
|
|
20
22
|
}
|
|
21
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Files `init` doesn't write. Each is created by its first write, and reads as its default until
|
|
26
|
+
* then, so a project made before the file existed needs nothing done to it.
|
|
27
|
+
*/
|
|
28
|
+
const CREATED_ON_WRITE = new Set(["found"]);
|
|
22
29
|
/**
|
|
23
30
|
* The only writer of a project's .rushes folder. Every write is validated,
|
|
24
31
|
* serialised per file, written atomically (tmp + rename) and announced with
|
|
@@ -42,6 +49,8 @@ export class Store extends EventEmitter {
|
|
|
42
49
|
await mkdir(join(this.dir, "grabs"), { recursive: true });
|
|
43
50
|
await writeIfMissing(join(this.dir, ".gitignore"), GITIGNORE);
|
|
44
51
|
for (const key of Object.keys(FILES)) {
|
|
52
|
+
if (CREATED_ON_WRITE.has(key))
|
|
53
|
+
continue;
|
|
45
54
|
await writeIfMissing(this.path(key), serialise(defaults(key, name)));
|
|
46
55
|
}
|
|
47
56
|
}
|
|
@@ -52,8 +61,11 @@ export class Store extends EventEmitter {
|
|
|
52
61
|
raw = await readFile(this.path(key), "utf8");
|
|
53
62
|
}
|
|
54
63
|
catch (e) {
|
|
55
|
-
if (e.code === "ENOENT")
|
|
64
|
+
if (e.code === "ENOENT") {
|
|
65
|
+
if (CREATED_ON_WRITE.has(key))
|
|
66
|
+
return FILES[key].schema.parse(defaults(key, ""));
|
|
56
67
|
throw new CorruptFileError(file, "missing; run rushes init");
|
|
68
|
+
}
|
|
57
69
|
throw e;
|
|
58
70
|
}
|
|
59
71
|
let json;
|
package/dist/mcp/client.js
CHANGED
|
@@ -21,7 +21,19 @@ export class RushesClient {
|
|
|
21
21
|
body: json === undefined ? undefined : JSON.stringify(json),
|
|
22
22
|
});
|
|
23
23
|
const text = await res.text();
|
|
24
|
-
|
|
24
|
+
let body = {};
|
|
25
|
+
try {
|
|
26
|
+
body = text ? JSON.parse(text) : {};
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Not JSON: an older Rushes answering a route it doesn't have, or something else on the port.
|
|
30
|
+
throw new ApiError(res.status, {
|
|
31
|
+
error: "not_json",
|
|
32
|
+
message: res.status === 404
|
|
33
|
+
? "The Rushes server running for this project is older than this command and doesn't have that feature. Run `rushes stop`, then try again."
|
|
34
|
+
: `Rushes server returned ${res.status} with a body that isn't JSON`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
25
37
|
if (!res.ok)
|
|
26
38
|
throw new ApiError(res.status, body);
|
|
27
39
|
return body;
|
package/dist/mcp/tools.js
CHANGED
|
@@ -2,15 +2,33 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { ApiError, dashboardUrlFor } from "./client.js";
|
|
4
4
|
import { VERSION } from "../server/app.js";
|
|
5
|
+
import { BRING_IN_MAX } from "../server/found.js";
|
|
5
6
|
const project = z.string().optional().describe("Project folder. Defaults to the current working directory.");
|
|
6
7
|
const stage = z.enum(["script", "picture", "voice", "music", "sfx", "mix"]);
|
|
7
8
|
const fileKind = z.enum(["doc", "image", "caption", "export", "delivery", "edit"]);
|
|
8
9
|
const assetKind = z.enum(["screenshot", "cut", "proxy", "take", "music", "sfx", "voice", "doc", "image", "caption", "export", "delivery", "edit"]);
|
|
10
|
+
// §20.7: a file to bring in. The server checks everything else (inside the project, the kind, the limits).
|
|
11
|
+
const film = z.string().min(1).max(200);
|
|
12
|
+
const bringInItem = z.object({
|
|
13
|
+
path: z.string().min(1).max(1024).describe("Absolute, or relative to the project folder."),
|
|
14
|
+
kind: z.enum(["voice", "music", "sfx", "cut", "doc"]).optional(),
|
|
15
|
+
round: z.string().trim().min(1).max(64).optional().describe('Voice only: the round the read joins, e.g. "Round 2 · Gerald, tone". Defaults to its folder\'s name.'),
|
|
16
|
+
});
|
|
9
17
|
function ok(data) {
|
|
10
18
|
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
11
19
|
}
|
|
20
|
+
/** "include.0.path: Too small", for each issue the server's own validation reported. */
|
|
21
|
+
function issuesOf(body) {
|
|
22
|
+
if (!Array.isArray(body.issues) || body.issues.length === 0)
|
|
23
|
+
return "";
|
|
24
|
+
const lines = body.issues.slice(0, 5).map((i) => {
|
|
25
|
+
const where = Array.isArray(i.path) ? i.path.join(".") : "";
|
|
26
|
+
return `${where ? `${where}: ` : ""}${String(i.message ?? "invalid")}`;
|
|
27
|
+
});
|
|
28
|
+
return `: ${lines.join("; ")}`;
|
|
29
|
+
}
|
|
12
30
|
function fail(e) {
|
|
13
|
-
const message = e instanceof ApiError ? `${e.message} (${e.body.error ?? e.status})` : e.message;
|
|
31
|
+
const message = e instanceof ApiError ? (e.body.error === "not_json" ? e.message : `${e.message} (${e.body.error ?? e.status})${issuesOf(e.body)}`) : e.message;
|
|
14
32
|
return { content: [{ type: "text", text: message }], isError: true };
|
|
15
33
|
}
|
|
16
34
|
/** Wrap a handler so API errors come back as tool errors the agent can read. */
|
|
@@ -28,15 +46,66 @@ export function createMcpServer(ctx) {
|
|
|
28
46
|
const server = new McpServer({ name: "rushes", version: VERSION });
|
|
29
47
|
server.registerTool("rushes_open", {
|
|
30
48
|
title: "Open Rushes",
|
|
31
|
-
description: "
|
|
32
|
-
inputSchema: {
|
|
33
|
-
|
|
49
|
+
description: "Starts Rushes if needed, brings in the current set of files that go with the cut, and opens it. Pass `include` for files you know belong. It waits about 20 seconds for the folder to be looked through; on a big folder it returns what it has with `scanning: true` and carries on in the background (rushes_scan, or opening again, shows the rest). Returns `broughtIn` (everything brought in since Rushes started, each with its kind, lane, reasons and `origin`: auto, include or hand), `alreadyIn` (your include files that were already registered), `failed` (files that couldn't come in, with why) and `found` (what was left, counts by kind).",
|
|
50
|
+
inputSchema: {
|
|
51
|
+
project,
|
|
52
|
+
browser: z.boolean().optional().describe("Open the browser. Default true."),
|
|
53
|
+
film: film.optional().describe("The film whose newest cut the files are matched to (id or name). Defaults to the newest cut in the project."),
|
|
54
|
+
include: z
|
|
55
|
+
.array(bringInItem)
|
|
56
|
+
.max(BRING_IN_MAX)
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("Files you made for this cut or know belong to it, inside the project folder. They are brought in whatever they score, and win over the scoring: a kind you include (voice, music or sfx) is not also guessed for this cut, now or on later scans or restarts. Nothing already registered is ever removed. Each: path, and kind (voice, music, sfx, cut, doc) when the name doesn't say, and round for a voice read."),
|
|
59
|
+
},
|
|
60
|
+
}, safe(async ({ project, browser, film, include }) => {
|
|
34
61
|
const c = await ctx.client(project);
|
|
35
62
|
const url = await dashboardUrlFor(c.baseUrl);
|
|
63
|
+
// Open first: the dashboard shows the folder being looked through, and fills in as files arrive.
|
|
36
64
|
if (browser !== false)
|
|
37
65
|
ctx.openBrowser(url);
|
|
38
|
-
|
|
66
|
+
let r;
|
|
67
|
+
try {
|
|
68
|
+
r = await c.post("/api/found/scan", { wait: true, ...(film ? { film } : {}), ...(include ? { include } : {}) });
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
// A Rushes started by an older version has no such route: it's open, just not scanned.
|
|
72
|
+
if (e instanceof ApiError && e.status === 404) {
|
|
73
|
+
return { url, broughtIn: [], failed: [], found: null, note: "An older Rushes is running and can't look through the folder. Run `rushes stop`, then open again." };
|
|
74
|
+
}
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
url,
|
|
79
|
+
broughtIn: r.added ?? [],
|
|
80
|
+
alreadyIn: r.alreadyIn ?? [],
|
|
81
|
+
failed: r.failed ?? [],
|
|
82
|
+
found: r.found ?? null,
|
|
83
|
+
...(r.scanning ? { scanning: true } : {}),
|
|
84
|
+
};
|
|
39
85
|
}));
|
|
86
|
+
server.registerTool("rushes_scan", {
|
|
87
|
+
title: "Look through the project folder",
|
|
88
|
+
description: "Looks through the project folder for files that go with the cut and returns the candidates, best score first, each with its kind, folder, size, length and the reasons in plain words. It also brings in the current set, as opening does (`broughtIn`), and returns what is left, with `counts` by kind (the same as `found` from rushes_open). It waits about 20 seconds; on a big folder `scanning: true` says it is still looking. Bring a chosen file in with rushes_bring_in.",
|
|
89
|
+
inputSchema: {
|
|
90
|
+
project,
|
|
91
|
+
film: film.optional().describe("The film whose newest cut the files are matched to (id or name). Defaults to the newest cut."),
|
|
92
|
+
limit: z.number().int().min(1).max(200).default(100).describe("How many candidates to return, best first. Default 100, at most 200."),
|
|
93
|
+
},
|
|
94
|
+
}, safe(async ({ project, film, limit }) => {
|
|
95
|
+
const c = await ctx.client(project);
|
|
96
|
+
const r = await c.post("/api/found/scan", { wait: true, ...(film ? { film } : {}) });
|
|
97
|
+
const { files } = await c.get("/api/found");
|
|
98
|
+
return { files: files.slice(0, limit ?? 100), counts: r.found ?? null, broughtIn: r.added ?? [], ...(r.scanning ? { scanning: true } : {}) };
|
|
99
|
+
}));
|
|
100
|
+
server.registerTool("rushes_bring_in", {
|
|
101
|
+
title: "Bring files in",
|
|
102
|
+
description: "Registers files from inside the project folder: voice reads, music and sfx as unpicked variants, video as cuts, md, txt and pdf as docs. Nothing is picked. Returns what was added and, for each file that couldn't come in, why (a path outside the project folder is refused). Up to 60 files, 12 of a kind.",
|
|
103
|
+
inputSchema: {
|
|
104
|
+
project,
|
|
105
|
+
files: z.array(bringInItem).min(1).max(BRING_IN_MAX).describe("Each: path (absolute or relative to the project), kind when the name doesn't say, round for a voice read."),
|
|
106
|
+
film: film.optional().describe("The film a cut joins (id or name). Defaults to the newest cut's film."),
|
|
107
|
+
},
|
|
108
|
+
}, safe(async ({ project, files, film }) => (await ctx.client(project)).post("/api/found/bring-in", { files, ...(film ? { film } : {}) })));
|
|
40
109
|
server.registerTool("rushes_set_shots", {
|
|
41
110
|
title: "Set shots",
|
|
42
111
|
description: "Set the storyboard shot list for a cut. Shots are numbered by start time; a new cut copies the previous cut's shots until you send new ones.",
|
package/dist/server/app.js
CHANGED
|
@@ -11,17 +11,19 @@ import { tabStates } from "../core/tabs.js";
|
|
|
11
11
|
import { fromManifestPath, toManifestPath } from "../core/paths.js";
|
|
12
12
|
import { probe } from "../core/media.js";
|
|
13
13
|
import { PROXY_PATH, ProxyJobs } from "./proxy.js";
|
|
14
|
+
import { PeakJobs } from "./peaks.js";
|
|
14
15
|
import { lstat, mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
15
16
|
import { randomUUID } from "node:crypto";
|
|
16
17
|
import { existsSync } from "node:fs";
|
|
17
18
|
import { basename, extname, join } from "node:path";
|
|
18
19
|
import { fileURLToPath } from "node:url";
|
|
19
|
-
import { GRAB_PATH, SCREENSHOT_PATH, contentDisposition, contentType, inside, isInlineSafeType, mediaSecurityHeaders, registeredMedia, sendFile } from "./files.js";
|
|
20
|
+
import { GRAB_PATH, SCREENSHOT_PATH, contentDisposition, contentType, foundMediaFile, inside, isInlineSafeType, mediaSecurityHeaders, registeredMedia, sendFile, servableFile } from "./files.js";
|
|
21
|
+
import { BRING_IN_MAX, FoundScanner, ffprobeDuration, foundAnnouncer } from "./found.js";
|
|
20
22
|
import { candidatePaths, listAssets, fpsFor, screenshotName } from "./assets.js";
|
|
21
23
|
import { osRevealer, osOpener, OPEN_SAFE_EXT } from "./reveal.js";
|
|
22
24
|
import { LaneStageSchema, SectionStatusSchema, StageSchema, BoxSchema, FileKindSchema, MarkSchema, ProjectIdSchema, ShotSchema, LEVEL_MIN, LEVEL_MAX, LEVEL_STEP } from "../core/schema.js";
|
|
23
25
|
import { defaultRunner, measureMix } from "./loudness.js";
|
|
24
|
-
export const VERSION = "0.2.
|
|
26
|
+
export const VERSION = "0.2.2";
|
|
25
27
|
async function body(c, schema) {
|
|
26
28
|
let json;
|
|
27
29
|
try {
|
|
@@ -133,12 +135,34 @@ const AddFileBody = z.object({
|
|
|
133
135
|
note: z.string().max(500).optional(),
|
|
134
136
|
video: z.string().optional(),
|
|
135
137
|
});
|
|
138
|
+
// §20.6: the found routes. A scan may name the film whose newest cut anchors the scoring.
|
|
139
|
+
const FoundItem = z.object({
|
|
140
|
+
path: z.string().min(1).max(1024),
|
|
141
|
+
kind: z.enum(["voice", "music", "sfx", "cut", "doc"]).optional(),
|
|
142
|
+
round: z.string().trim().min(1).max(64).optional(),
|
|
143
|
+
});
|
|
144
|
+
// §20.7: `wait` makes the scan answer once it and the adoption are done, with what's in and what's
|
|
145
|
+
// left. `include` (only with `wait`) brings in files the agent knows belong, before adopting.
|
|
146
|
+
const FoundScanBody = z
|
|
147
|
+
.object({
|
|
148
|
+
film: z.string().min(1).max(200).optional(),
|
|
149
|
+
wait: z.boolean().optional(),
|
|
150
|
+
include: z.array(FoundItem).max(BRING_IN_MAX).optional(),
|
|
151
|
+
})
|
|
152
|
+
.refine((b) => b.include === undefined || b.wait === true, { message: "include needs wait: true", path: ["include"] });
|
|
153
|
+
const FoundPathsBody = z.object({ paths: z.array(z.string().min(1).max(1024)).min(1).max(500) });
|
|
154
|
+
const FoundBringInBody = z.object({
|
|
155
|
+
files: z.array(FoundItem).min(1).max(BRING_IN_MAX),
|
|
156
|
+
film: z.string().min(1).max(200).optional(),
|
|
157
|
+
});
|
|
136
158
|
// Big enough for a full-quality frame of a 4K original from the frame endpoint (§19.5), which
|
|
137
159
|
// Picture posts here as the grab: 3840×2160 RGB is 24.9 MB before PNG compression.
|
|
138
160
|
const MAX_GRAB_BYTES = 64 * 1024 * 1024;
|
|
139
161
|
const PNG_MAGIC = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
140
162
|
/** Where the built dashboard lives: <package>/web-dist, next to dist/ and src/. */
|
|
141
163
|
export const DEFAULT_WEB_DIR = fileURLToPath(new URL("../../web-dist/", import.meta.url));
|
|
164
|
+
/** How long a waiting scan (§20.7) answers at most, before it says it is still scanning. */
|
|
165
|
+
export const FOUND_WAIT_MS = 20_000;
|
|
142
166
|
const LOCAL_HOSTS = new Set(["127.0.0.1", "localhost"]);
|
|
143
167
|
/** Hostname of "host[:port]" or a full origin URL, lowercased, or null when it doesn't parse. */
|
|
144
168
|
function hostnameOf(value, isUrl) {
|
|
@@ -155,6 +179,8 @@ export function createApp(store, opts = {}) {
|
|
|
155
179
|
const reveal = opts.reveal ?? osRevealer;
|
|
156
180
|
const open = opts.open ?? osOpener;
|
|
157
181
|
const jobs = opts.proxyJobs ?? new ProxyJobs(store);
|
|
182
|
+
const peaks = opts.peakJobs ?? new PeakJobs(store, { run: jobs.run, available: () => jobs.available() });
|
|
183
|
+
const found = opts.found ?? new FoundScanner({ store, probe: ffprobeDuration, announce: foundAnnouncer(store) });
|
|
158
184
|
const app = new Hono();
|
|
159
185
|
// Every SSE client adds a change listener, so lift Node's default limit of ten.
|
|
160
186
|
store.setMaxListeners(0);
|
|
@@ -263,10 +289,32 @@ export function createApp(store, opts = {}) {
|
|
|
263
289
|
// falls through to candidatePaths, which does the readdir-backed discovery (§16.2's
|
|
264
290
|
// auto-discovered docs/captions/exports) that a registered path never needs.
|
|
265
291
|
const known = registeredMedia(project, script).has(path) || GRAB_PATH.test(path) || SCREENSHOT_PATH.test(path);
|
|
292
|
+
// The file on disk to send. For a found file it's exactly the path that was checked.
|
|
293
|
+
let file = fromManifestPath(store.root, path);
|
|
294
|
+
let viaFound = false;
|
|
266
295
|
if (!known) {
|
|
267
|
-
|
|
268
|
-
|
|
296
|
+
if (found.has(path)) {
|
|
297
|
+
// §20.5: a found file can be auditioned before it's brought in -- only one the last scan
|
|
298
|
+
// recorded (and not dismissed), only as a plain file inside the project folder, never
|
|
299
|
+
// through a symlink. Served with the same headers as everything else below.
|
|
300
|
+
const checked = await foundMediaFile(store.root, path);
|
|
301
|
+
if (!checked)
|
|
302
|
+
throw new NotFoundError("media", path);
|
|
303
|
+
file = checked;
|
|
304
|
+
viaFound = true; // already refused any symlink outright
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
const candidates = await candidatePaths(store, project, script);
|
|
308
|
+
if (!candidates.has(path))
|
|
309
|
+
throw new NotFoundError("media", path);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (!viaFound) {
|
|
313
|
+
// §15.5: a registered file reached through a symlink out of the project is served only if it is media.
|
|
314
|
+
const servable = await servableFile(store.root, file);
|
|
315
|
+
if (!servable)
|
|
269
316
|
throw new NotFoundError("media", path);
|
|
317
|
+
file = servable;
|
|
270
318
|
}
|
|
271
319
|
// C1: a type a browser could render as a document (HTML, XML, SVG -- an SVG can carry
|
|
272
320
|
// script -- or anything this server doesn't otherwise recognise) is never served inline,
|
|
@@ -282,7 +330,7 @@ export function createApp(store, opts = {}) {
|
|
|
282
330
|
}
|
|
283
331
|
const type = contentType(path);
|
|
284
332
|
const inlineSafe = isInlineSafeType(type);
|
|
285
|
-
const res = await sendFile(
|
|
333
|
+
const res = await sendFile(file, c.req.header("range"), inlineSafe ? type : "application/octet-stream");
|
|
286
334
|
res.headers.set("cross-origin-resource-policy", "same-origin");
|
|
287
335
|
for (const [name, value] of Object.entries(mediaSecurityHeaders()))
|
|
288
336
|
res.headers.set(name, value);
|
|
@@ -423,8 +471,9 @@ export function createApp(store, opts = {}) {
|
|
|
423
471
|
return c.json(c.req.query("test") === "1" ? { ...health, sse: streams } : health);
|
|
424
472
|
});
|
|
425
473
|
app.get("/api/state", async (c) => {
|
|
426
|
-
|
|
427
|
-
|
|
474
|
+
// §20.6: found is what the last scan left in memory; it never waits on a scan or a probe.
|
|
475
|
+
const [project, script, notes, picks, batches, ffmpeg, foundSummary] = await Promise.all([
|
|
476
|
+
store.read("project"), store.read("script"), store.read("notes"), store.read("picks"), store.read("batches"), jobs.available(), found.summary(),
|
|
428
477
|
]);
|
|
429
478
|
const tabs = tabStates(project, script, notes);
|
|
430
479
|
// §19.5: why each cut may play badly (or null). Never waits on a probe: an unprobed cut is
|
|
@@ -433,7 +482,85 @@ export function createApp(store, opts = {}) {
|
|
|
433
482
|
...v,
|
|
434
483
|
versions: await Promise.all(v.versions.map(async (ver) => ({ ...ver, proxyNeed: await jobs.needNow(fromManifestPath(store.root, ver.file)) }))),
|
|
435
484
|
})));
|
|
436
|
-
return c.json({ project: { ...project, videos }, script, notes, picks, batches, tabs, proxies: { ffmpeg, jobs: jobs.list() } });
|
|
485
|
+
return c.json({ project: { ...project, videos }, script, notes, picks, batches, tabs, proxies: { ffmpeg, jobs: jobs.list() }, found: foundSummary });
|
|
486
|
+
});
|
|
487
|
+
// ---- found: the project's other files (§20) ----
|
|
488
|
+
app.get("/api/found", async (c) => {
|
|
489
|
+
// `abs` stays on the server: the list speaks in manifest paths, as /media and the actions do.
|
|
490
|
+
const files = (await found.list()).map(({ abs: _abs, ...rest }) => rest);
|
|
491
|
+
// The hidden ones ride along, so Assets › Found can list them and restore any.
|
|
492
|
+
const hidden = (await found.hidden()).map(({ abs: _abs, ...rest }) => rest);
|
|
493
|
+
return c.json({ files, hidden });
|
|
494
|
+
});
|
|
495
|
+
app.post("/api/found/scan", async (c) => {
|
|
496
|
+
const b = await body(c, FoundScanBody);
|
|
497
|
+
if (b.wait) {
|
|
498
|
+
// §20.7. What the agent included wins over the scoring: its kinds are settled for the cut
|
|
499
|
+
// first (kept in found.json, ahead of any adoption), then the first pass, then the included
|
|
500
|
+
// files, then the current set. `added` is everything brought in this session, so a start-up
|
|
501
|
+
// adoption racing this request is never missed. Waiting stops at the cap: the rest carries
|
|
502
|
+
// on in the background and the answer says `scanning`.
|
|
503
|
+
const failed = [];
|
|
504
|
+
const alreadyIn = [];
|
|
505
|
+
const work = (async () => {
|
|
506
|
+
const settling = b.include?.length ? found.settleKinds(b.include, b.film) : Promise.resolve([]);
|
|
507
|
+
const [, kinds] = await Promise.all([found.scan({ film: b.film }), settling]);
|
|
508
|
+
let skipKinds = kinds;
|
|
509
|
+
if (b.include?.length) {
|
|
510
|
+
const included = await found.bringIn(b.include, { film: b.film, origin: "include" });
|
|
511
|
+
// An included cut becomes the cut the scoring is matched to, and a project with no cut
|
|
512
|
+
// had nothing to record against: settle again now that the cut exists.
|
|
513
|
+
if (included.added.some((a) => a.kind === "cut"))
|
|
514
|
+
skipKinds = await found.settleKinds(b.include, b.film);
|
|
515
|
+
for (const f of included.failed) {
|
|
516
|
+
if (f.code === "already")
|
|
517
|
+
alreadyIn.push(f.path);
|
|
518
|
+
else
|
|
519
|
+
failed.push(f);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
// The kinds are also passed on, so this adoption holds back whatever happens to the record.
|
|
523
|
+
failed.push(...(await found.adoptCurrentSet({ film: b.film, skipKinds })).failed);
|
|
524
|
+
})();
|
|
525
|
+
work.catch(() => undefined); // after the cap, a failure has nobody to tell
|
|
526
|
+
let timer;
|
|
527
|
+
const capped = await Promise.race([
|
|
528
|
+
work.then(() => false),
|
|
529
|
+
new Promise((r) => {
|
|
530
|
+
timer = setTimeout(() => r(true), opts.foundWaitMs ?? FOUND_WAIT_MS);
|
|
531
|
+
timer.unref?.();
|
|
532
|
+
}),
|
|
533
|
+
]).finally(() => clearTimeout(timer));
|
|
534
|
+
return c.json({
|
|
535
|
+
ok: true,
|
|
536
|
+
added: found.broughtInDetail(),
|
|
537
|
+
alreadyIn,
|
|
538
|
+
failed,
|
|
539
|
+
found: (await found.summary()).counts,
|
|
540
|
+
...(capped ? { scanning: true } : {}),
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
// Answers at once; the scan runs in the background and announces a change when it lands.
|
|
544
|
+
// Then §20.4's current set is adopted (a no-op without a cut, or when it's already in).
|
|
545
|
+
void found
|
|
546
|
+
.scan({ film: b.film })
|
|
547
|
+
.then(() => found.adoptCurrentSet({ film: b.film }))
|
|
548
|
+
.catch(() => undefined);
|
|
549
|
+
return c.json({ ok: true });
|
|
550
|
+
});
|
|
551
|
+
app.post("/api/found/bring-in", async (c) => {
|
|
552
|
+
const b = await body(c, FoundBringInBody);
|
|
553
|
+
return c.json(await found.bringIn(b.files, { film: b.film }));
|
|
554
|
+
});
|
|
555
|
+
app.post("/api/found/dismiss", async (c) => {
|
|
556
|
+
const b = await body(c, FoundPathsBody);
|
|
557
|
+
await found.dismiss(b.paths);
|
|
558
|
+
return c.json({ ok: true });
|
|
559
|
+
});
|
|
560
|
+
app.post("/api/found/restore", async (c) => {
|
|
561
|
+
const b = await body(c, FoundPathsBody);
|
|
562
|
+
await found.restore(b.paths);
|
|
563
|
+
return c.json({ ok: true });
|
|
437
564
|
});
|
|
438
565
|
app.get("/api/tabs", async (c) => {
|
|
439
566
|
const [project, script, notes] = await Promise.all([store.read("project"), store.read("script"), store.read("notes")]);
|
|
@@ -489,6 +616,8 @@ export function createApp(store, opts = {}) {
|
|
|
489
616
|
});
|
|
490
617
|
// §19.5: say when the cut is likely to play badly, and start its proxy straight away when the
|
|
491
618
|
// project asks for that. Without ffmpeg, nothing is offered (needFor is null).
|
|
619
|
+
// §19.9: its waveform is made in the background; nothing here waits for it.
|
|
620
|
+
void peaks.queueCut(result.video.id, result.version.id, file).catch(() => undefined);
|
|
492
621
|
const reason = await jobs.needFrom(abs, info);
|
|
493
622
|
const proxy = {};
|
|
494
623
|
if (reason) {
|
|
@@ -585,6 +714,28 @@ export function createApp(store, opts = {}) {
|
|
|
585
714
|
headers: { "content-type": "image/png", "cache-control": "no-store", "x-rushes-frame": String(frame), "content-length": String(png.length) },
|
|
586
715
|
});
|
|
587
716
|
});
|
|
717
|
+
// §19.9: the cut's own audio as about 2000 peaks, for the waveform in Picture's timeline. 200 with
|
|
718
|
+
// the peaks, 202 while they're being made (a `change` goes out when they land), 204 when the cut
|
|
719
|
+
// has no audio, 501 without ffmpeg (the dashboard then decodes a small file itself).
|
|
720
|
+
app.get("/api/videos/:video/versions/:version/peaks", async (c) => {
|
|
721
|
+
const { video, version } = await cutOf(c.req.param("video"), c.req.param("version"));
|
|
722
|
+
if (!(await peaks.available())) {
|
|
723
|
+
throw new RushesError("The waveform needs ffmpeg, which isn't installed. Run `rushes doctor` for how to add it.", 501, "no_ffmpeg");
|
|
724
|
+
}
|
|
725
|
+
const a = await peaks.answer(video.id, version.id, version.file);
|
|
726
|
+
switch (a.state) {
|
|
727
|
+
case "ready":
|
|
728
|
+
return c.json(a.data, 200, { "cache-control": "no-store" });
|
|
729
|
+
case "computing":
|
|
730
|
+
return c.json({ state: "computing" }, 202, { "cache-control": "no-store" });
|
|
731
|
+
case "silent":
|
|
732
|
+
return c.body(null, 204, { "cache-control": "no-store" });
|
|
733
|
+
case "missing":
|
|
734
|
+
throw new RushesError("The original file is missing", 404, "missing_file", { path: version.file });
|
|
735
|
+
case "failed":
|
|
736
|
+
throw new RushesError(a.reason, 422, "no_peaks");
|
|
737
|
+
}
|
|
738
|
+
});
|
|
588
739
|
app.put("/api/videos/:video/shots", async (c) => {
|
|
589
740
|
const b = await body(c, ShotsBody);
|
|
590
741
|
const { result } = await store.update("project", (p) => setShots(p, c.req.param("video"), b.version, b.shots));
|
package/dist/server/files.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createReadStream } from "node:fs";
|
|
2
|
-
import { stat } from "node:fs/promises";
|
|
3
|
-
import { extname, join, normalize, sep } from "node:path";
|
|
2
|
+
import { lstat, realpath, stat } from "node:fs/promises";
|
|
3
|
+
import { extname, isAbsolute, join, normalize, sep } from "node:path";
|
|
4
4
|
import { Readable } from "node:stream";
|
|
5
5
|
import { PROXY_PATH } from "./proxy.js";
|
|
6
6
|
export const CONTENT_TYPES = {
|
|
@@ -85,6 +85,65 @@ export function registeredMedia(project, script) {
|
|
|
85
85
|
files.add(f.file);
|
|
86
86
|
return files;
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* §15.5 and §20.5: the file on disk for a found candidate `rel` (a manifest path the scan recorded), or null
|
|
90
|
+
* when it may not be served. It must be a plain relative path (no absolute path, no `.` or `..`
|
|
91
|
+
* segment, no backslash), a plain file and not a symlink, and its real path must be exactly the
|
|
92
|
+
* root's real path plus `rel`: so no folder on the way has been swapped for a symlink since the
|
|
93
|
+
* scan, and nothing outside the project folder is ever reached.
|
|
94
|
+
*/
|
|
95
|
+
export async function foundMediaFile(root, rel) {
|
|
96
|
+
if (rel === "" || rel.includes("\\") || rel.includes("\0") || isAbsolute(rel) || /^[A-Za-z]:/.test(rel))
|
|
97
|
+
return null;
|
|
98
|
+
const parts = rel.split("/");
|
|
99
|
+
if (parts.some((p) => p === "" || p === "." || p === ".."))
|
|
100
|
+
return null;
|
|
101
|
+
try {
|
|
102
|
+
const realRoot = await realpath(root);
|
|
103
|
+
const abs = join(realRoot, ...parts);
|
|
104
|
+
const info = await lstat(abs);
|
|
105
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
106
|
+
return null;
|
|
107
|
+
if ((await realpath(abs)) !== abs)
|
|
108
|
+
return null;
|
|
109
|
+
return abs;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** §15.5: the only kinds of file /media serves when its real path lies outside the project (footage on another drive, say). */
|
|
116
|
+
export const OUTSIDE_MEDIA_EXT = new Set([
|
|
117
|
+
"wav", "mp3", "m4a", "aac", "aif", "aiff", "flac", "ogg", "opus", "mp4", "mov", "m4v", "webm", "mkv",
|
|
118
|
+
"png", "jpg", "jpeg", "gif", "webp", "pdf", "md", "txt", "srt", "vtt",
|
|
119
|
+
]);
|
|
120
|
+
/**
|
|
121
|
+
* The file /media sends for a path it has already accepted: its real path, every symlink
|
|
122
|
+
* resolved. A real path inside the project is served whatever it is, as before. Policy (§15.5):
|
|
123
|
+
* one outside the project is served only if the FINAL real file's extension is media
|
|
124
|
+
* (`OUTSIDE_MEDIA_EXT`), so a take swapped for a link to a key file is never served. Null means
|
|
125
|
+
* refuse. A file that isn't there gives back the plain path, so the send reports it missing.
|
|
126
|
+
*/
|
|
127
|
+
export async function servableFile(root, abs) {
|
|
128
|
+
let real;
|
|
129
|
+
try {
|
|
130
|
+
real = await realpath(abs);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return abs;
|
|
134
|
+
}
|
|
135
|
+
let realRoot;
|
|
136
|
+
try {
|
|
137
|
+
realRoot = await realpath(root);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (real === realRoot || real.startsWith(realRoot.endsWith(sep) ? realRoot : realRoot + sep))
|
|
143
|
+
return real;
|
|
144
|
+
const ext = extname(real).toLowerCase().replace(/^\./, "");
|
|
145
|
+
return OUTSIDE_MEDIA_EXT.has(ext) ? real : null;
|
|
146
|
+
}
|
|
88
147
|
/** Parse a single "bytes=a-b" range against a file size. Returns null for a missing or unusable range. */
|
|
89
148
|
export function parseRange(header, size) {
|
|
90
149
|
const m = header?.match(/^bytes=(\d*)-(\d*)$/);
|