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
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { mkdir, realpath } from "node:fs/promises";
|
|
3
|
+
import { basename, resolve } from "node:path";
|
|
4
|
+
import { getRequestListener } from "@hono/node-server";
|
|
5
|
+
import { Store } from "../core/store.js";
|
|
6
|
+
import { ensureProjectIdOnce } from "../core/project.js";
|
|
7
|
+
import { createApp } from "./app.js";
|
|
8
|
+
import { removeLock, writeLock } from "./lock.js";
|
|
9
|
+
import { watchStore } from "./watch.js";
|
|
10
|
+
import { ProxyJobs, removePartials } from "./proxy.js";
|
|
11
|
+
export const DEFAULT_PORT = 4580;
|
|
12
|
+
function listen(server, port, host) {
|
|
13
|
+
return new Promise((ok, fail) => {
|
|
14
|
+
const onError = (e) => {
|
|
15
|
+
server.off("listening", onListening);
|
|
16
|
+
fail(e);
|
|
17
|
+
};
|
|
18
|
+
const onListening = () => {
|
|
19
|
+
server.off("error", onError);
|
|
20
|
+
const addr = server.address();
|
|
21
|
+
ok(typeof addr === "object" && addr ? addr.port : port);
|
|
22
|
+
};
|
|
23
|
+
server.once("error", onError);
|
|
24
|
+
server.once("listening", onListening);
|
|
25
|
+
server.listen(port, host);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Start the Rushes server for a project folder. Tries `port` and the next ten
|
|
30
|
+
* ports; pass port 0 to let the OS choose (tests do).
|
|
31
|
+
*/
|
|
32
|
+
export async function startServer(rootDir, opts = {}) {
|
|
33
|
+
// The real path is the root everywhere (store, lock, health), so a symlinked path finds the same server.
|
|
34
|
+
await mkdir(resolve(rootDir), { recursive: true });
|
|
35
|
+
const root = await realpath(resolve(rootDir));
|
|
36
|
+
const store = new Store(root);
|
|
37
|
+
await store.init(opts.name ?? basename(root));
|
|
38
|
+
let close = async () => undefined;
|
|
39
|
+
// `appOpts` is the exact object the app's closure reads `projectId` from on every request, so
|
|
40
|
+
// setting it below (once this server has won the project's lock and ensured the id) reaches
|
|
41
|
+
// the already-constructed app without recreating it.
|
|
42
|
+
// Built on this server's own store, so its progress events reach this server's SSE clients.
|
|
43
|
+
// Every running job is cancelled when the server closes.
|
|
44
|
+
const proxyJobs = new ProxyJobs(store, opts.proxy);
|
|
45
|
+
const appOpts = { webDir: opts.webDir, onShutdown: () => void close(), reveal: opts.reveal, proxyJobs };
|
|
46
|
+
const app = createApp(store, appOpts);
|
|
47
|
+
const listener = getRequestListener(app.fetch);
|
|
48
|
+
let lastRequest = Date.now();
|
|
49
|
+
const server = createServer((req, res) => {
|
|
50
|
+
lastRequest = Date.now();
|
|
51
|
+
listener(req, res);
|
|
52
|
+
});
|
|
53
|
+
const host = opts.host ?? "127.0.0.1";
|
|
54
|
+
const first = opts.port ?? DEFAULT_PORT;
|
|
55
|
+
let port = -1;
|
|
56
|
+
let lastError;
|
|
57
|
+
for (let p = first; p <= (first === 0 ? 0 : first + 10); p++) {
|
|
58
|
+
try {
|
|
59
|
+
port = await listen(server, p, host);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
lastError = e;
|
|
64
|
+
if (e.code !== "EADDRINUSE")
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (port < 0)
|
|
69
|
+
throw new Error(`No free port from ${first} to ${first + 10}: ${lastError?.message}`);
|
|
70
|
+
let token;
|
|
71
|
+
try {
|
|
72
|
+
token = (await writeLock(root, port)).token;
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
// Another server owns this project, or the lock couldn't be written: don't leave a socket open.
|
|
76
|
+
server.closeAllConnections?.();
|
|
77
|
+
await new Promise((ok) => server.close(() => ok()));
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
80
|
+
// Only the server that actually won the lock ever touches project.json here, so racing
|
|
81
|
+
// starts for the same root never collide writing it. ensureProjectIdOnce shares its one
|
|
82
|
+
// in-flight promise with the app's own lazy ensure (keyed on this same store), so a request
|
|
83
|
+
// landing before this line — however briefly a request could reach a freshly-listening
|
|
84
|
+
// socket — can never cause a second write: restarts never bump the rev either way.
|
|
85
|
+
const id = await ensureProjectIdOnce(store);
|
|
86
|
+
// Review Focus 1: a server that stopped mid-proxy left a half-written file. Nothing recorded it
|
|
87
|
+
// (a version's proxy is set only after a completed render), so it goes. Only the lock winner
|
|
88
|
+
// does this, so it can never delete a file another live server is still writing.
|
|
89
|
+
await removePartials(root);
|
|
90
|
+
appOpts.projectId = id;
|
|
91
|
+
const url = `http://${host}:${port}`;
|
|
92
|
+
const stopWatching = await watchStore(store);
|
|
93
|
+
let idleTimer;
|
|
94
|
+
let done = () => undefined;
|
|
95
|
+
const closed = new Promise((ok) => { done = ok; });
|
|
96
|
+
let closing = null;
|
|
97
|
+
close = () => {
|
|
98
|
+
closing ??= (async () => {
|
|
99
|
+
clearTimeout(idleTimer);
|
|
100
|
+
stopWatching();
|
|
101
|
+
// A running proxy's ffmpeg must not outlive the server; its partial file is deleted too.
|
|
102
|
+
// From here no new job starts either (a POST or an autoProxy cut racing the close).
|
|
103
|
+
await proxyJobs.close();
|
|
104
|
+
server.closeAllConnections?.();
|
|
105
|
+
await new Promise((ok) => server.close(() => ok()));
|
|
106
|
+
await removeLock(root, token);
|
|
107
|
+
done();
|
|
108
|
+
})();
|
|
109
|
+
return closing;
|
|
110
|
+
};
|
|
111
|
+
if (opts.idleMs && opts.idleMs > 0) {
|
|
112
|
+
const idleMs = opts.idleMs;
|
|
113
|
+
const tick = () => {
|
|
114
|
+
server.getConnections((_err, open) => {
|
|
115
|
+
if (open === 0 && Date.now() - lastRequest >= idleMs)
|
|
116
|
+
void close();
|
|
117
|
+
else
|
|
118
|
+
idleTimer = setTimeout(tick, Math.max(50, idleMs / 4));
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
idleTimer = setTimeout(tick, idleMs);
|
|
122
|
+
idleTimer.unref?.();
|
|
123
|
+
}
|
|
124
|
+
return { url, port, id, dashboardUrl: `${url}/p/${id}/`, store, close, closed };
|
|
125
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { watch } from "node:fs";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import { FILES } from "../core/schema.js";
|
|
4
|
+
import { CorruptFileError } from "../core/errors.js";
|
|
5
|
+
const BY_NAME = new Map(Object.entries(FILES).map(([key, f]) => [f.name, key]));
|
|
6
|
+
function sameSnap(a, b) {
|
|
7
|
+
if (a === null || b === null)
|
|
8
|
+
return a === b;
|
|
9
|
+
return a.mtimeMs === b.mtimeMs && a.ctimeMs === b.ctimeMs && a.size === b.size && a.ino === b.ino;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Watch .rushes/ for edits made outside the server (a person or an agent
|
|
13
|
+
* editing the JSON by hand). A valid edit with a new rev is announced like any
|
|
14
|
+
* other change; an invalid one is reported as a "corrupt" event and left alone.
|
|
15
|
+
*
|
|
16
|
+
* fs.watch is the primary signal, but it's a convenience the OS doesn't fully
|
|
17
|
+
* guarantee: under heavy filesystem load (seen on macOS when many watchers are
|
|
18
|
+
* active at once), a notification can be coalesced away and never delivered.
|
|
19
|
+
* A slow background poll is the safety net, so a hand edit is still picked up
|
|
20
|
+
* — just a little later — even if the OS drops the event for it entirely. The
|
|
21
|
+
* poll only ever `stat`s each file (cheap, no read or parse); it reads and
|
|
22
|
+
* announces or reports a file only when that stat has actually changed, so an
|
|
23
|
+
* idle project costs nothing and a file that stays broken is reported once,
|
|
24
|
+
* not on every poll tick.
|
|
25
|
+
*/
|
|
26
|
+
export async function watchStore(store, debounceMs = 80, pollMs = 500) {
|
|
27
|
+
const timers = new Map();
|
|
28
|
+
const snaps = new Map();
|
|
29
|
+
let watcher = null;
|
|
30
|
+
let stopped = false;
|
|
31
|
+
const statOf = async (key) => {
|
|
32
|
+
try {
|
|
33
|
+
const st = await stat(store.path(key));
|
|
34
|
+
return { mtimeMs: st.mtimeMs, ctimeMs: st.ctimeMs, size: st.size, ino: st.ino };
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const check = async (key) => {
|
|
41
|
+
// Stat before reading, and record that stat as the snapshot below -- not one taken after
|
|
42
|
+
// the read. An edit landing between a read-then-stat order would be invisible forever: its
|
|
43
|
+
// write could complete after the read but before the stat, so the recorded snapshot would
|
|
44
|
+
// match the file's new (already-edited) state even though the content just read was the
|
|
45
|
+
// old one, and no later poll tick would ever see a difference to re-check. Stat-first means
|
|
46
|
+
// the recorded snapshot can only be as fresh as what was actually read, so a write landing
|
|
47
|
+
// in the gap always leaves the live file's stat different from it, and the next tick retries.
|
|
48
|
+
const pre = await statOf(key);
|
|
49
|
+
try {
|
|
50
|
+
const data = await store.read(key);
|
|
51
|
+
store.announce(key, data.rev);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
if (e instanceof CorruptFileError) {
|
|
55
|
+
// Forget the rev we last announced, so a restore at the same rev still announces.
|
|
56
|
+
store.forget(key);
|
|
57
|
+
store.emit("corrupt", { file: FILES[key].name, message: e.message });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
// Record the state from before the read, whatever it was, so the poll doesn't reprocess
|
|
62
|
+
// the same unchanged (including still-broken) file.
|
|
63
|
+
snaps.set(key, pre);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
// Seed the starting rev and stat snapshot for every file, so the poll below
|
|
67
|
+
// treats "nothing has changed since the server started" as nothing changed,
|
|
68
|
+
// rather than announcing every file's current state as a fresh edit. Seeding
|
|
69
|
+
// happens after the server is already listening, not before, so a real hand
|
|
70
|
+
// edit can in principle land in that narrow gap -- but the worst case is one
|
|
71
|
+
// duplicate change event once this seed and fs.watch both notice it, and
|
|
72
|
+
// `announce` already deduplicates by rev, so nothing is lost or double-sent.
|
|
73
|
+
// A file already broken at startup is left for a later edit to surface, same
|
|
74
|
+
// as before this watcher existed.
|
|
75
|
+
await Promise.all(Object.keys(FILES).map(async (key) => {
|
|
76
|
+
snaps.set(key, await statOf(key));
|
|
77
|
+
try {
|
|
78
|
+
const data = await store.read(key);
|
|
79
|
+
store.seed(key, data.rev);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Missing or corrupt at startup: nothing to seed.
|
|
83
|
+
}
|
|
84
|
+
}));
|
|
85
|
+
try {
|
|
86
|
+
watcher = watch(store.dir, (_event, filename) => {
|
|
87
|
+
const key = filename ? BY_NAME.get(String(filename)) : undefined;
|
|
88
|
+
if (!key)
|
|
89
|
+
return;
|
|
90
|
+
clearTimeout(timers.get(key));
|
|
91
|
+
timers.set(key, setTimeout(() => void check(key), debounceMs));
|
|
92
|
+
});
|
|
93
|
+
watcher.on("error", () => undefined);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Watching is a convenience; the server works without it.
|
|
97
|
+
}
|
|
98
|
+
let pollTimer;
|
|
99
|
+
// Set for the duration of one poll tick's stat sweep, so a hung stat (a dropped network
|
|
100
|
+
// drive, say) can never cause ticks to pile up on top of each other -- the next tick is still
|
|
101
|
+
// scheduled on time below, but it sees this flag set and skips its own sweep entirely.
|
|
102
|
+
let polling = false;
|
|
103
|
+
const poll = () => {
|
|
104
|
+
if (stopped)
|
|
105
|
+
return;
|
|
106
|
+
pollTimer = setTimeout(poll, pollMs);
|
|
107
|
+
pollTimer.unref?.();
|
|
108
|
+
if (polling)
|
|
109
|
+
return;
|
|
110
|
+
polling = true;
|
|
111
|
+
void (async () => {
|
|
112
|
+
try {
|
|
113
|
+
for (const key of Object.keys(FILES)) {
|
|
114
|
+
const current = await statOf(key);
|
|
115
|
+
if (!sameSnap(current, snaps.get(key) ?? null))
|
|
116
|
+
void check(key);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
polling = false;
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
};
|
|
124
|
+
pollTimer = setTimeout(poll, pollMs);
|
|
125
|
+
pollTimer.unref?.();
|
|
126
|
+
return () => {
|
|
127
|
+
stopped = true;
|
|
128
|
+
clearTimeout(pollTimer);
|
|
129
|
+
for (const t of timers.values())
|
|
130
|
+
clearTimeout(t);
|
|
131
|
+
watcher?.close();
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
/**
|
|
4
|
+
* Runs `cmd` and collects its output. With `timeout` (doctor's checks), the command gets no stdin
|
|
5
|
+
* -- so one waiting on input finishes rather than stalling -- and is killed once the time is up,
|
|
6
|
+
* resolving with `timedOut: true` without waiting for it to exit.
|
|
7
|
+
*/
|
|
8
|
+
function run(cmd, args, cwd, opts = {}) {
|
|
9
|
+
return new Promise((ok) => {
|
|
10
|
+
let out = "";
|
|
11
|
+
let settled = false;
|
|
12
|
+
const done = (r) => {
|
|
13
|
+
if (settled)
|
|
14
|
+
return;
|
|
15
|
+
settled = true;
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
ok(r);
|
|
18
|
+
};
|
|
19
|
+
const limited = opts.timeout !== undefined;
|
|
20
|
+
const child = spawn(cmd, args, { cwd, shell: process.platform === "win32", ...(limited ? { stdio: ["ignore", "pipe", "pipe"] } : {}) });
|
|
21
|
+
const timer = limited
|
|
22
|
+
? setTimeout(() => {
|
|
23
|
+
child.kill("SIGKILL");
|
|
24
|
+
done({ code: 124, out, timedOut: true });
|
|
25
|
+
}, opts.timeout)
|
|
26
|
+
: undefined;
|
|
27
|
+
child.stdout?.on("data", (d) => (out += d));
|
|
28
|
+
child.stderr?.on("data", (d) => (out += d));
|
|
29
|
+
child.on("error", (e) => done({ code: 127, out: e.message }));
|
|
30
|
+
child.on("close", (code) => done({ code: code ?? 1, out }));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** The real machine: your home folder, PATH lookups and real commands. */
|
|
34
|
+
export function realSetupEnv() {
|
|
35
|
+
return {
|
|
36
|
+
home: homedir(),
|
|
37
|
+
platform: process.platform,
|
|
38
|
+
appData: process.env.APPDATA,
|
|
39
|
+
which: async (cmd) => (await run(process.platform === "win32" ? "where" : "which", [cmd])).code === 0,
|
|
40
|
+
exec: run,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
/** What every harness runs to start the Rushes MCP server, now that Rushes is on npm (§19.7). */
|
|
3
|
+
export const SOURCE = "rushes";
|
|
4
|
+
/**
|
|
5
|
+
* Older `npx` sources that already-registered harnesses may still be using, from before the
|
|
6
|
+
* npm publish. `setup` and `doctor` recognise these as Rushes too, and `setup` migrates a
|
|
7
|
+
* registration that uses one of them to `SOURCE` in place, rather than adding a duplicate.
|
|
8
|
+
*/
|
|
9
|
+
export const LEGACY_SOURCES = ["github:iamredmh/rushes"];
|
|
10
|
+
/** The detail `doctor` reports for a harness still registered through a legacy source. */
|
|
11
|
+
export const LEGACY_DETAIL = "registered with the older GitHub launch. Run rushes setup to switch to npm.";
|
|
12
|
+
/** The launch everywhere except Windows. */
|
|
13
|
+
export const MCP_COMMAND = "npx";
|
|
14
|
+
export const MCP_ARGS = ["-y", SOURCE, "mcp"];
|
|
15
|
+
/**
|
|
16
|
+
* How a harness should start the Rushes MCP server on this platform, from a given `npx` source.
|
|
17
|
+
* On Windows npx is a .cmd script, which harnesses can't spawn directly, so it goes through cmd /c.
|
|
18
|
+
*/
|
|
19
|
+
function launchFor(platform, source) {
|
|
20
|
+
const args = ["-y", source, "mcp"];
|
|
21
|
+
return platform === "win32" ? { command: "cmd", args: ["/c", MCP_COMMAND, ...args] } : { command: MCP_COMMAND, args };
|
|
22
|
+
}
|
|
23
|
+
/** How a harness should start the Rushes MCP server on this platform, from the current `SOURCE`. */
|
|
24
|
+
export function mcpLaunch(platform) {
|
|
25
|
+
return launchFor(platform, SOURCE);
|
|
26
|
+
}
|
|
27
|
+
/** The same launch shapes, one per `LEGACY_SOURCES` entry, for recognising an existing registration. */
|
|
28
|
+
export function legacyMcpLaunches(platform) {
|
|
29
|
+
return LEGACY_SOURCES.map((source) => launchFor(platform, source));
|
|
30
|
+
}
|
|
31
|
+
/** Does this text (e.g. `claude mcp get rushes` output) name a legacy `npx` source? */
|
|
32
|
+
export function mentionsLegacySource(text) {
|
|
33
|
+
return LEGACY_SOURCES.some((source) => text.includes(source));
|
|
34
|
+
}
|
|
35
|
+
const DEFAULT_LAUNCH = { command: MCP_COMMAND, args: MCP_ARGS };
|
|
36
|
+
export function harnesses(home, platform, appData = join(home, "AppData", "Roaming")) {
|
|
37
|
+
const desktopDir = platform === "darwin"
|
|
38
|
+
? join(home, "Library", "Application Support", "Claude")
|
|
39
|
+
: platform === "win32"
|
|
40
|
+
? join(appData, "Claude")
|
|
41
|
+
: join(home, ".config", "Claude");
|
|
42
|
+
return [
|
|
43
|
+
{ id: "claude-code", name: "Claude Code", kind: "claude-cli", marker: join(home, ".claude"), bin: "claude", skillDir: join(home, ".claude", "skills", "rushes") },
|
|
44
|
+
{ id: "codex", name: "Codex", kind: "toml", config: join(home, ".codex", "config.toml"), marker: join(home, ".codex"), bin: "codex", skillDir: join(home, ".codex", "skills", "rushes") },
|
|
45
|
+
{ id: "cursor", name: "Cursor", kind: "json", config: join(home, ".cursor", "mcp.json"), marker: join(home, ".cursor") },
|
|
46
|
+
{ id: "claude-desktop", name: "Claude Desktop", kind: "json", config: join(desktopDir, "claude_desktop_config.json"), marker: desktopDir },
|
|
47
|
+
{ id: "gemini", name: "Gemini CLI", kind: "json", config: join(home, ".gemini", "settings.json"), marker: join(home, ".gemini"), bin: "gemini" },
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Add Rushes to a JSON config's "mcpServers" without touching anything else.
|
|
52
|
+
* Throws if the existing file isn't a JSON object, so we never clobber it.
|
|
53
|
+
*/
|
|
54
|
+
export function mergeJson(existing, launch = DEFAULT_LAUNCH) {
|
|
55
|
+
const doc = existing && existing.trim() ? JSON.parse(existing) : {};
|
|
56
|
+
if (typeof doc !== "object" || doc === null || Array.isArray(doc))
|
|
57
|
+
throw new Error("config is not a JSON object");
|
|
58
|
+
const servers = (doc.mcpServers ?? {});
|
|
59
|
+
if (typeof servers !== "object" || Array.isArray(servers))
|
|
60
|
+
throw new Error('"mcpServers" is not an object');
|
|
61
|
+
const want = { command: launch.command, args: launch.args };
|
|
62
|
+
if (JSON.stringify(servers.rushes) === JSON.stringify(want))
|
|
63
|
+
return { text: existing ?? "", changed: false };
|
|
64
|
+
doc.mcpServers = { ...servers, rushes: want };
|
|
65
|
+
return { text: JSON.stringify(doc, null, 2) + "\n", changed: true };
|
|
66
|
+
}
|
|
67
|
+
const tomlBlock = (launch) => `[mcp_servers.rushes]\ncommand = ${JSON.stringify(launch.command)}\nargs = [${launch.args.map((a) => JSON.stringify(a)).join(", ")}]\n`;
|
|
68
|
+
const TOML_HEADER = /^\s*\[mcp_servers\.rushes\]\s*(#.*)?$/;
|
|
69
|
+
/**
|
|
70
|
+
* Add or replace the [mcp_servers.rushes] table in a Codex config.toml, leaving
|
|
71
|
+
* everything else as written and keeping the file's line endings. This is line
|
|
72
|
+
* surgery, not a TOML parser: it never makes a valid file invalid, and a file
|
|
73
|
+
* that was already broken gets a backup (see setup.ts) and an appended table.
|
|
74
|
+
*/
|
|
75
|
+
export function mergeToml(existing, launch = DEFAULT_LAUNCH) {
|
|
76
|
+
const text = existing ?? "";
|
|
77
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
78
|
+
const block = tomlBlock(launch).trimEnd().split("\n");
|
|
79
|
+
const lines = text.split(/\r?\n/);
|
|
80
|
+
const start = lines.findIndex((l) => TOML_HEADER.test(l));
|
|
81
|
+
if (start === -1) {
|
|
82
|
+
const body = text.replace(/(\r?\n)+$/, "");
|
|
83
|
+
return { text: (body ? body + eol + eol : "") + block.join(eol) + eol, changed: true };
|
|
84
|
+
}
|
|
85
|
+
let end = lines.findIndex((l, i) => i > start && /^\s*\[/.test(l));
|
|
86
|
+
if (end === -1)
|
|
87
|
+
end = lines.length;
|
|
88
|
+
const current = lines.slice(start + 1, end).map((l) => l.trim()).filter(Boolean);
|
|
89
|
+
if (current.join("\n") === block.slice(1).join("\n"))
|
|
90
|
+
return { text, changed: false };
|
|
91
|
+
const next = [...lines.slice(0, start), ...block, "", ...lines.slice(end)].join(eol);
|
|
92
|
+
return { text: next.replace(/(\r?\n){3,}/g, eol + eol), changed: true };
|
|
93
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { access, copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { harnesses, mcpLaunch, mentionsLegacySource, mergeJson, mergeToml } from "./harnesses.js";
|
|
5
|
+
const exists = (p) => access(p).then(() => true, () => false);
|
|
6
|
+
export function packagedSkill() {
|
|
7
|
+
return fileURLToPath(new URL("../../skills/rushes/SKILL.md", import.meta.url));
|
|
8
|
+
}
|
|
9
|
+
async function installed(h, env) {
|
|
10
|
+
return (await exists(h.marker)) || (h.bin ? await env.which(h.bin) : false);
|
|
11
|
+
}
|
|
12
|
+
async function writeConfig(path, text, existed) {
|
|
13
|
+
await mkdir(dirname(path), { recursive: true });
|
|
14
|
+
if (existed)
|
|
15
|
+
await copyFile(path, `${path}.rushes.bak`);
|
|
16
|
+
await writeFile(path, text, "utf8");
|
|
17
|
+
}
|
|
18
|
+
async function installSkill(h, env, dryRun) {
|
|
19
|
+
if (!h.skillDir)
|
|
20
|
+
return undefined;
|
|
21
|
+
const target = join(h.skillDir, "SKILL.md");
|
|
22
|
+
const source = env.skillFile ?? packagedSkill();
|
|
23
|
+
const want = await readFile(source, "utf8");
|
|
24
|
+
const have = await readFile(target, "utf8").catch(() => null);
|
|
25
|
+
if (have === want)
|
|
26
|
+
return "already";
|
|
27
|
+
if (dryRun)
|
|
28
|
+
return "would-add";
|
|
29
|
+
await mkdir(h.skillDir, { recursive: true });
|
|
30
|
+
await writeFile(target, want, "utf8");
|
|
31
|
+
return "added";
|
|
32
|
+
}
|
|
33
|
+
async function one(h, env, dryRun) {
|
|
34
|
+
const base = { harness: h.id, name: h.name };
|
|
35
|
+
if (!(await installed(h, env)))
|
|
36
|
+
return { ...base, status: "not-found", detail: "not installed" };
|
|
37
|
+
const launch = mcpLaunch(env.platform);
|
|
38
|
+
const command = [launch.command, ...launch.args];
|
|
39
|
+
try {
|
|
40
|
+
if (h.kind === "claude-cli") {
|
|
41
|
+
if (!(await env.which("claude")))
|
|
42
|
+
return { ...base, status: "failed", detail: "the claude command isn't on PATH. Run: claude mcp add --scope user rushes -- " + command.join(" ") };
|
|
43
|
+
// Run from home so a project's own .mcp.json can't make it look registered.
|
|
44
|
+
const got = await env.exec("claude", ["mcp", "get", "rushes"], env.home);
|
|
45
|
+
const skill = await installSkill(h, env, dryRun);
|
|
46
|
+
if (got.code === 0) {
|
|
47
|
+
// A server named "rushes" already exists. If it's still pointed at a legacy source
|
|
48
|
+
// (registered before the npm publish), switch it over in place rather than leaving it,
|
|
49
|
+
// since `claude mcp add` won't overwrite an existing name.
|
|
50
|
+
if (!mentionsLegacySource(got.out))
|
|
51
|
+
return { ...base, status: "already", detail: "rushes MCP server already registered", skill };
|
|
52
|
+
if (dryRun)
|
|
53
|
+
return { ...base, status: "would-add", detail: "claude mcp remove --scope user rushes && claude mcp add --scope user rushes -- " + command.join(" "), skill };
|
|
54
|
+
const removed = await env.exec("claude", ["mcp", "remove", "--scope", "user", "rushes"], env.home);
|
|
55
|
+
if (removed.code !== 0)
|
|
56
|
+
return { ...base, status: "failed", detail: removed.out.trim() || "claude mcp remove failed", skill };
|
|
57
|
+
const added = await env.exec("claude", ["mcp", "add", "--scope", "user", "rushes", "--", ...command], env.home);
|
|
58
|
+
if (added.code !== 0)
|
|
59
|
+
return { ...base, status: "failed", detail: added.out.trim() || "claude mcp add failed", skill };
|
|
60
|
+
return { ...base, status: "added", detail: "switched from the older GitHub launch to npm", skill };
|
|
61
|
+
}
|
|
62
|
+
if (dryRun)
|
|
63
|
+
return { ...base, status: "would-add", detail: "claude mcp add --scope user rushes", skill };
|
|
64
|
+
const add = await env.exec("claude", ["mcp", "add", "--scope", "user", "rushes", "--", ...command], env.home);
|
|
65
|
+
if (add.code !== 0)
|
|
66
|
+
return { ...base, status: "failed", detail: add.out.trim() || "claude mcp add failed", skill };
|
|
67
|
+
return { ...base, status: "added", detail: "registered with claude mcp add --scope user", skill };
|
|
68
|
+
}
|
|
69
|
+
const path = h.config;
|
|
70
|
+
const existed = await exists(path);
|
|
71
|
+
const before = existed ? await readFile(path, "utf8") : null;
|
|
72
|
+
const merged = h.kind === "toml" ? mergeToml(before, launch) : mergeJson(before, launch);
|
|
73
|
+
const skill = await installSkill(h, env, dryRun);
|
|
74
|
+
if (!merged.changed)
|
|
75
|
+
return { ...base, status: "already", detail: path, skill };
|
|
76
|
+
if (dryRun)
|
|
77
|
+
return { ...base, status: "would-add", detail: path, skill };
|
|
78
|
+
await writeConfig(path, merged.text, existed);
|
|
79
|
+
return { ...base, status: "added", detail: existed ? `${path} (backup: ${path}.rushes.bak)` : path, skill };
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
return { ...base, status: "failed", detail: `${h.config ?? h.name}: ${e.message}. Nothing was changed.` };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Register the Rushes MCP server (and skill, where supported) with every installed harness. */
|
|
86
|
+
export async function setup(env, opts = {}) {
|
|
87
|
+
const list = harnesses(env.home, env.platform, env.appData).filter((h) => !opts.only || opts.only.includes(h.id));
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const h of list)
|
|
90
|
+
out.push(await one(h, env, !!opts.dryRun));
|
|
91
|
+
return out;
|
|
92
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rushes",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A local review desk for video made with AI agents: timecoded notes, script edits and audio picks your agent can read and act on.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Red Morley Hewitt",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/iamredmh/rushes.git"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"rushes": "dist/cli/index.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"web-dist",
|
|
18
|
+
"skills",
|
|
19
|
+
".claude-plugin",
|
|
20
|
+
".mcp.json",
|
|
21
|
+
"README.md",
|
|
22
|
+
"AGENTS.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.build.json && vite build",
|
|
30
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.web.json",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"rushes": "tsx src/cli/index.ts",
|
|
33
|
+
"prepare": "npm run build",
|
|
34
|
+
"test:e2e": "npm run build && playwright test",
|
|
35
|
+
"prepublishOnly": "npm run build && npm run typecheck && npx vitest run"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@hono/node-server": "^2.1.3",
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.31.0",
|
|
40
|
+
"hono": "^4.12.0",
|
|
41
|
+
"zod": "^4.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@fontsource/figtree": "^5.3.0",
|
|
45
|
+
"@fontsource/jetbrains-mono": "^5.3.0",
|
|
46
|
+
"@playwright/test": "^1.63.0",
|
|
47
|
+
"@types/node": "^22.10.0",
|
|
48
|
+
"preact": "^10.29.8",
|
|
49
|
+
"tsx": "^4.20.0",
|
|
50
|
+
"typescript": "^5.9.3",
|
|
51
|
+
"vite": "^8.3.2",
|
|
52
|
+
"vitest": "^5.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rushes
|
|
3
|
+
description: Review video work with the user in Rushes, a local review desk. Use when you've rendered a cut, written a VO script, recorded voice reads, music beds or SFX passes and the user should review them, or when the user says they left notes, pressed Send to agent, or pastes a Rushes batch prompt.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Rushes
|
|
7
|
+
|
|
8
|
+
Rushes shows your work to the user stage by stage (script, picture, voiceover, music, sound effects, mix). The user leaves timecoded notes that you act on.
|
|
9
|
+
|
|
10
|
+
If the user pastes a prompt copied from a locked tab, act on it directly — it already names the project, the film and the tool to use.
|
|
11
|
+
|
|
12
|
+
1. Register what you made:
|
|
13
|
+
- `rushes_add_version` for a render. If the cut is likely to play badly in a browser, the reply carries `proxySuggested: true` and `proxyReason`; Picture offers the user a proxy. Prefer H.264 MP4 to avoid this;
|
|
14
|
+
- `rushes_set_script` for the VO script. It merges by `id`, so send only the sections you changed; sections you leave out are kept. `rushes_get_script` reads the whole script;
|
|
15
|
+
- `rushes_add_variant` for each voice read, music bed or SFX pass. Voice reads carry `stage: "voice"` and a `round` (its name — reads in one round are compared side by side; a new direction gets a new round); say what the read is, or what changed, in `description`. Music and SFX carry `meta.description` for their lane card;
|
|
16
|
+
- `rushes_set_shots` for the storyboard's shots, once you have the first cut; send new timings when a later cut moves them.
|
|
17
|
+
2. Call `rushes_open` and tell the user it's ready. Each project's dashboard lives at its own address, `/p/<id>/`.
|
|
18
|
+
3. When the user sends a batch, call `rushes_get_batch` and fix every note in it. A note carries the `shot` it falls in; on an audio stage, call `rushes_get_picks` first — on Mix it also returns `levels` (dB per lane), which you read, not set. Its `on` says what it's about: `"<lane>/<variant>"` for a bed, pass or voice read (on Voiceover the lane names the round), `"<lane>/<variant>:<cue>"` for an SFX cue, `"vo"` for the Mix VO lane, or `null` for the whole mix; older notes may carry a section id or `"<section>:<take>"`. On Music, Sound effects and Mix treat `marks` (e.g. "Fall", "Quieter 3 dB") as part of the note; Voiceover notes carry none — they're Whole (`Speaker`, `Pacing`, `Tone`, `Overall`) or Point (`Fix this`, `Keep this`) instead. Picks are set from the dashboard only — no tool or CLI command sets one.
|
|
19
|
+
4. Register the new cut with `rushes_add_version`. On a locked video the reply carries a `warning`.
|
|
20
|
+
5. Reply to all the notes in one `rushes_reply` call. For each note set `status: "done"`, a one-line `reply`, `fixT` (when the fix is visible in the new cut, in seconds) and `fixVersion`.
|
|
21
|
+
6. For script batches: when a section's `proposed` differs from `current`, adopt it with `rushes_set_script`, sending just that section with its `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.
|
|
22
|
+
7. Lock picture with `rushes_lock_picture` only when the user says picture is locked; `version: null` unlocks it.
|
|
23
|
+
|
|
24
|
+
Save renders, voice reads, beds and passes under the project's `renders/`, `audio/voiceover/`, `audio/music/` and `audio/sfx/` folders. Screenshots the user grabs with G or the camera button land in `screenshots/`. Use `rushes_list_assets` (optional `kind`) to find a file the user refers to but hasn't given you a path for, such as "use the screenshot I just took".
|
|
25
|
+
|
|
26
|
+
The **Assets** tab is a library: Screenshots, Cuts, Voiceover, Music, Sound effects, Scripts & docs, Images, Captions, Exports, Delivery, Edit files and Proxies. Top-level `.md`, `.txt`, `.pdf`, `.srt` and `.vtt` files, and anything in `exports/`, are found automatically. Register everything else with `rushes_add_file` (`kind`, `file`, optional `name`, `note`, `video`): deliverables and platform exports as `delivery`, NLE project files as `edit`, storyboards/references/logos as `image`, briefs as `doc`. When the user wants to share notes, call `rushes_export_notes` — it writes a dated Markdown file to `exports/` and returns the path.
|
|
27
|
+
|
|
28
|
+
No project to show yet? Run `npx -y rushes demo <folder> --no-browser`, then `rushes_open` with `project: "<folder>"`. The demo builds a complete working example on the user's machine, with a cut, script, voice reads, music and notes already in place. Always pass `--no-browser`: without it the command stays running as the server and never returns.
|
|
29
|
+
|
|
30
|
+
Rushes has seventeen tools: `rushes_open`, `rushes_status`, `rushes_add_version`, `rushes_add_variant`, `rushes_set_script`, `rushes_get_script`, `rushes_add_take`, `rushes_list_notes`, `rushes_list_assets`, `rushes_get_batch`, `rushes_reply`, `rushes_get_picks`, `rushes_set_shots`, `rushes_lock_picture`, `rushes_add_file`, `rushes_export_notes` and `rushes_doctor` (environment and project health check) — `rushes_add_take` stays only for compatibility and isn't used for voiceover. The full contract is in `AGENTS.md` at the package root.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|