@mthines/reaper-mcp 0.103.0 → 0.104.1
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/README.md +45 -45
- package/bridge-ui/mcp_bridge.html +42 -42
- package/main.js +996 -525
- package/package.json +1 -1
- package/reaper/CLAUDE.md +1 -1
- package/reaper/mcp_bridge.lua +67 -28
- package/reaper/mcp_mixing_lib.lua +6 -1
package/main.js
CHANGED
|
@@ -108,7 +108,7 @@ function createUi(opts = {}) {
|
|
|
108
108
|
return chars.map((ch, i) => ch === " " ? ch : `\x1B[${rgb(lerp(BRAND, from + (to - from) * i / Math.max(chars.length - 1, 1)))}m${ch}`).join("") + "\x1B[0m";
|
|
109
109
|
};
|
|
110
110
|
const fancy = tty && columns >= LOGO_WIDTH + 2;
|
|
111
|
-
const
|
|
111
|
+
const ui3 = {
|
|
112
112
|
level,
|
|
113
113
|
columns,
|
|
114
114
|
tty,
|
|
@@ -137,7 +137,7 @@ ${sgr("1", title)}`,
|
|
|
137
137
|
return ["", ...logo, "", wave, ""].join("\n");
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
|
-
return
|
|
140
|
+
return ui3;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
// apps/reaper-mcp-server/src/telemetry-consent.ts
|
|
@@ -149,17 +149,17 @@ var DEFAULT_DESTINATION = {
|
|
|
149
149
|
};
|
|
150
150
|
var CONSENT_SERVICE_NAME = "reaper-mcp-consent";
|
|
151
151
|
var TELEMETRY_DOC_URL = "https://github.com/mthines/reaper-mcp/blob/main/TELEMETRY.md";
|
|
152
|
-
function renderTelemetryNotice(
|
|
153
|
-
return `${
|
|
152
|
+
function renderTelemetryNotice(ui3 = createUi({ level: 0, tty: false })) {
|
|
153
|
+
return `${ui3.bold("Pseudonymous usage telemetry is ON by default.")}
|
|
154
154
|
reaper-mcp is built by one developer. To see which tools people use, which fail,
|
|
155
155
|
and how fast they are, it sends pseudonymous usage data: tool names, error types,
|
|
156
156
|
timings, and app/OS versions, tagged with a random install id.
|
|
157
157
|
It never sends your projects, track names, parameters, file paths or error text.
|
|
158
158
|
Your answer below is counted once, anonymously (on or off, no install id).
|
|
159
159
|
|
|
160
|
-
Opt out any time: ${
|
|
161
|
-
${
|
|
162
|
-
Details: ${
|
|
160
|
+
Opt out any time: ${ui3.cmd("reaper-mcp telemetry off")}
|
|
161
|
+
${ui3.dim("(or set REAPER_MCP_TELEMETRY=0 or DO_NOT_TRACK=1)")}
|
|
162
|
+
Details: ${ui3.link(TELEMETRY_DOC_URL)}`;
|
|
163
163
|
}
|
|
164
164
|
var TELEMETRY_NOTICE = renderTelemetryNotice();
|
|
165
165
|
var FALSY = /* @__PURE__ */ new Set(["0", "false", "off", "no"]);
|
|
@@ -207,6 +207,9 @@ function resolveTelemetry(env = process.env, config = readTelemetryConfig(), des
|
|
|
207
207
|
if (!forcedOn && config.telemetry === false) {
|
|
208
208
|
return { mode: "off", reason: "turned off with `reaper-mcp telemetry off`" };
|
|
209
209
|
}
|
|
210
|
+
if (env["REAPER_MCP_DISTRIBUTION"] === "plugin" && !forcedOn && config.telemetry !== true) {
|
|
211
|
+
return { mode: "off", reason: "the Claude plugin is opt-in: turn on its telemetry option to share anonymous usage" };
|
|
212
|
+
}
|
|
210
213
|
if (!destination.token) return { mode: "off", reason: "this build has no built-in telemetry destination" };
|
|
211
214
|
return {
|
|
212
215
|
mode: "default",
|
|
@@ -235,13 +238,13 @@ function lineReader(input) {
|
|
|
235
238
|
close: () => rl.close()
|
|
236
239
|
};
|
|
237
240
|
}
|
|
238
|
-
async function confirmOptOut(lines, output,
|
|
241
|
+
async function confirmOptOut(lines, output, ui3) {
|
|
239
242
|
output.write(`
|
|
240
|
-
${
|
|
243
|
+
${ui3.bold("Totally your call, no hard feelings \u{1F64F}")}
|
|
241
244
|
reaper-mcp is just me: one developer, building it in my spare time. These counts help me a ton,
|
|
242
245
|
they show me what to fix next. I can't see your music, projects, track names or files. Ever.
|
|
243
246
|
|
|
244
|
-
${
|
|
247
|
+
${ui3.bold("Turn telemetry off anyway?")} ${ui3.dim("[y/N]")} `);
|
|
245
248
|
const answer = (await lines.next()).trim().toLowerCase();
|
|
246
249
|
return answer === "y" || answer === "yes";
|
|
247
250
|
}
|
|
@@ -257,20 +260,20 @@ async function confirmOptOutPrompt(io) {
|
|
|
257
260
|
async function firstRunTelemetryNotice(io, dir = defaultConfigDir(), env = process.env, destination = DEFAULT_DESTINATION) {
|
|
258
261
|
const config = readTelemetryConfig(dir);
|
|
259
262
|
if (config.telemetryNoticeShown || resolveTelemetry(env, config, destination).mode !== "default") return void 0;
|
|
260
|
-
const
|
|
263
|
+
const ui3 = io.ui ?? createUi({ level: 0, tty: false });
|
|
261
264
|
io.output.write(`
|
|
262
|
-
${renderTelemetryNotice(
|
|
265
|
+
${renderTelemetryNotice(ui3)}
|
|
263
266
|
|
|
264
267
|
`);
|
|
265
268
|
let keep = true;
|
|
266
269
|
if (io.interactive) {
|
|
267
270
|
const lines = lineReader(io.input);
|
|
268
|
-
io.output.write(`${
|
|
271
|
+
io.output.write(`${ui3.bold("Keep usage telemetry on?")} ${ui3.dim("[Y/n]")} `);
|
|
269
272
|
const answer = (await lines.next()).trim().toLowerCase();
|
|
270
|
-
keep = !(answer === "n" || answer === "no") || !await confirmOptOut(lines, io.output,
|
|
273
|
+
keep = !(answer === "n" || answer === "no") || !await confirmOptOut(lines, io.output, ui3);
|
|
271
274
|
lines.close();
|
|
272
|
-
io.output.write(keep ? `${
|
|
273
|
-
` : `${
|
|
275
|
+
io.output.write(keep ? `${ui3.mark("ok")} Thanks \u2014 telemetry stays on.
|
|
276
|
+
` : `${ui3.mark("ok")} Telemetry is off. Turn it back on with \`${ui3.cmd("reaper-mcp telemetry on")}\`.
|
|
274
277
|
`);
|
|
275
278
|
}
|
|
276
279
|
writeTelemetryConfig({ telemetry: keep, telemetryNoticeShown: true }, dir);
|
|
@@ -1135,12 +1138,12 @@ async function sendCommand(type, params = {}, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
|
1135
1138
|
span.setAttribute("reaper.bridge.poll_attempts", pollAttempts);
|
|
1136
1139
|
span.setStatus({ code: SpanStatusCode.ERROR, message: timeoutMsg });
|
|
1137
1140
|
emitLog(
|
|
1138
|
-
"error",
|
|
1141
|
+
untraced ? "warn" : "error",
|
|
1139
1142
|
`Bridge command ${type} timed out after ${timeoutMs}ms`,
|
|
1140
1143
|
{ "rpc.method": type, "reaper.bridge.command.id": id, "error.type": "timeout", "reaper.bridge.timeout_ms": timeoutMs },
|
|
1141
1144
|
{ eventName: "reaper.bridge.command.timeout" }
|
|
1142
1145
|
);
|
|
1143
|
-
noteLoggedFailure(
|
|
1146
|
+
noteLoggedFailure(!untraced);
|
|
1144
1147
|
finish("timeout");
|
|
1145
1148
|
return {
|
|
1146
1149
|
id,
|
|
@@ -1555,10 +1558,10 @@ function noteScratchTrack(name, now = Date.now()) {
|
|
|
1555
1558
|
}
|
|
1556
1559
|
function runSeconds(tag, now = Date.now()) {
|
|
1557
1560
|
const key = tag?.trim();
|
|
1558
|
-
const
|
|
1561
|
+
const start2 = key ? runStarts.get(key) : void 0;
|
|
1559
1562
|
if (key) runStarts.delete(key);
|
|
1560
|
-
if (
|
|
1561
|
-
return Math.round((now -
|
|
1563
|
+
if (start2 === void 0 || now < start2 || now - start2 > MAX_RUN_MS) return void 0;
|
|
1564
|
+
return Math.round((now - start2) / 1e3);
|
|
1562
1565
|
}
|
|
1563
1566
|
function given(value) {
|
|
1564
1567
|
return value?.trim() ? value : void 0;
|
|
@@ -1984,10 +1987,10 @@ function registerTrackTools(server) {
|
|
|
1984
1987
|
tracks2 = tracks2.filter((t) => String(t.name ?? "").toLowerCase().includes(needle));
|
|
1985
1988
|
}
|
|
1986
1989
|
const total = tracks2.length;
|
|
1987
|
-
const
|
|
1988
|
-
const page = tracks2.slice(
|
|
1990
|
+
const start2 = offset ?? 0;
|
|
1991
|
+
const page = tracks2.slice(start2, limit != null ? start2 + limit : void 0);
|
|
1989
1992
|
const out2 = compact ? page.map(compactTrack) : page;
|
|
1990
|
-
const body = { total, offset:
|
|
1993
|
+
const body = { total, offset: start2, returned: out2.length, hasMore: start2 + out2.length < total, tracks: out2 };
|
|
1991
1994
|
return { content: [{ type: "text", text: JSON.stringify(body, null, 2) }] };
|
|
1992
1995
|
}
|
|
1993
1996
|
);
|
|
@@ -3288,12 +3291,12 @@ function registerSelectionTools(server) {
|
|
|
3288
3291
|
start: z15.coerce.number().min(0).describe("Start position in seconds"),
|
|
3289
3292
|
end: z15.coerce.number().min(0).describe("End position in seconds")
|
|
3290
3293
|
},
|
|
3291
|
-
async ({ start, end }) => {
|
|
3292
|
-
const res = await sendCommand("set_time_selection", { start, end });
|
|
3294
|
+
async ({ start: start2, end }) => {
|
|
3295
|
+
const res = await sendCommand("set_time_selection", { start: start2, end });
|
|
3293
3296
|
if (!res.success) {
|
|
3294
3297
|
return { content: [{ type: "text", text: `Error: ${res.error}` }], isError: true };
|
|
3295
3298
|
}
|
|
3296
|
-
return { content: [{ type: "text", text: `Time selection set: ${
|
|
3299
|
+
return { content: [{ type: "text", text: `Time selection set: ${start2}s - ${end}s` }] };
|
|
3297
3300
|
}
|
|
3298
3301
|
);
|
|
3299
3302
|
const selectionMode = z15.enum(["replace", "add"]).optional().describe("replace (default): select exactly these; add: keep the current selection");
|
|
@@ -3558,8 +3561,8 @@ function registerMarkerTools(server) {
|
|
|
3558
3561
|
name: z17.string().optional().describe("Region name"),
|
|
3559
3562
|
color: z17.coerce.number().optional().describe("REAPER native color int (0 = default)")
|
|
3560
3563
|
},
|
|
3561
|
-
async ({ start, end, name, color }) => {
|
|
3562
|
-
const res = await sendCommand("add_region", { start, end, name, color });
|
|
3564
|
+
async ({ start: start2, end, name, color }) => {
|
|
3565
|
+
const res = await sendCommand("add_region", { start: start2, end, name, color });
|
|
3563
3566
|
if (!res.success) {
|
|
3564
3567
|
return { content: [{ type: "text", text: `Error: ${res.error}` }], isError: true };
|
|
3565
3568
|
}
|
|
@@ -4126,9 +4129,9 @@ function recordEdit(command2, args, data) {
|
|
|
4126
4129
|
const operation = command2 === "process_items" ? String(args["operation"]) : OPERATION[command2];
|
|
4127
4130
|
const items = itemsChanged(command2, args, d);
|
|
4128
4131
|
const num3 = (k) => typeof d[k] === "number" ? d[k] : void 0;
|
|
4129
|
-
const
|
|
4132
|
+
const start2 = num3("start");
|
|
4130
4133
|
const end = num3("end");
|
|
4131
|
-
const length = num3("length") ?? num3("span") ?? (
|
|
4134
|
+
const length = num3("length") ?? num3("span") ?? (start2 !== void 0 && end !== void 0 ? end - start2 : void 0);
|
|
4132
4135
|
trace5.getActiveSpan()?.setAttributes({
|
|
4133
4136
|
"reaper.arrange.operation": operation,
|
|
4134
4137
|
"reaper.arrange.items_changed": items,
|
|
@@ -4971,18 +4974,18 @@ function ensureWebInterface(ini, port) {
|
|
|
4971
4974
|
}
|
|
4972
4975
|
const eol = ini.includes("\r\n") ? "\r\n" : "\n";
|
|
4973
4976
|
const lines = ini.split(/\r?\n/);
|
|
4974
|
-
let
|
|
4975
|
-
if (
|
|
4977
|
+
let start2 = lines.findIndex((l) => l.trim() === "[REAPER]");
|
|
4978
|
+
if (start2 === -1) {
|
|
4976
4979
|
lines.unshift("[REAPER]");
|
|
4977
|
-
|
|
4980
|
+
start2 = 0;
|
|
4978
4981
|
}
|
|
4979
|
-
let end = lines.findIndex((l, i) => i >
|
|
4982
|
+
let end = lines.findIndex((l, i) => i > start2 && l.startsWith("["));
|
|
4980
4983
|
if (end === -1) end = lines.length;
|
|
4981
|
-
while (end - 1 >
|
|
4982
|
-
const cntIdx = lines.findIndex((l, i) => i >
|
|
4984
|
+
while (end - 1 > start2 && lines[end - 1].trim() === "") end--;
|
|
4985
|
+
const cntIdx = lines.findIndex((l, i) => i > start2 && i < end && l.startsWith("csurf_cnt="));
|
|
4983
4986
|
const count = cntIdx === -1 ? 0 : Number(lines[cntIdx].slice("csurf_cnt=".length)) || 0;
|
|
4984
4987
|
const entry = `csurf_${count}=HTTP 0 ${port} '' '${BRIDGE_UI_FILE}' 0 ''`;
|
|
4985
|
-
const staleIdx = lines.findIndex((l, i) => i >
|
|
4988
|
+
const staleIdx = lines.findIndex((l, i) => i > start2 && i < end && l.startsWith(`csurf_${count}=`));
|
|
4986
4989
|
if (staleIdx !== -1) lines[staleIdx] = entry;
|
|
4987
4990
|
if (cntIdx === -1) {
|
|
4988
4991
|
lines.splice(end, 0, `csurf_cnt=${count + 1}`, ...staleIdx === -1 ? [entry] : []);
|
|
@@ -5561,10 +5564,10 @@ function parseSetupArgs(argv, env = process.env, tty = Boolean(process.stdin.isT
|
|
|
5561
5564
|
if (has("--without-aesthetics")) picks.aesthetics = false;
|
|
5562
5565
|
const ci = Boolean(env["CI"]) && env["CI"] !== "false" && env["CI"] !== "0";
|
|
5563
5566
|
const yes = has("--yes") || has("-y") || has("--non-interactive");
|
|
5564
|
-
const
|
|
5567
|
+
const list3 = has("--list");
|
|
5565
5568
|
return {
|
|
5566
|
-
interactive: tty && !ci && !yes && !
|
|
5567
|
-
list:
|
|
5569
|
+
interactive: tty && !ci && !yes && !list3 && Object.keys(picks).length === 0,
|
|
5570
|
+
list: list3,
|
|
5568
5571
|
json: has("--json"),
|
|
5569
5572
|
picks,
|
|
5570
5573
|
unknown: argv.filter((a) => a.startsWith("-") && !SETUP_FLAGS.has(a))
|
|
@@ -6236,13 +6239,13 @@ function registerOfflineTools(server) {
|
|
|
6236
6239
|
const startedAt = Date.now();
|
|
6237
6240
|
const sidecar = getSidecarClient();
|
|
6238
6241
|
if (!sidecar.isAvailable()) return error(SIDECAR_NOT_INSTALLED_MSG);
|
|
6239
|
-
const
|
|
6240
|
-
const end = endTime ??
|
|
6241
|
-
if (end <=
|
|
6242
|
-
if (end -
|
|
6242
|
+
const start2 = startTime ?? 0;
|
|
6243
|
+
const end = endTime ?? start2 + (durationSeconds ?? DEFAULT_OFFLINE_SECONDS);
|
|
6244
|
+
if (end <= start2) return error("endTime must be greater than startTime");
|
|
6245
|
+
if (end - start2 > MAX_OFFLINE_SECONDS) return error(`Range too long: max ${MAX_OFFLINE_SECONDS} s per call`);
|
|
6243
6246
|
let wav;
|
|
6244
6247
|
try {
|
|
6245
|
-
wav = await renderTrack(trackIndex5,
|
|
6248
|
+
wav = await renderTrack(trackIndex5, start2, end);
|
|
6246
6249
|
} catch (err) {
|
|
6247
6250
|
return error(err instanceof Error ? err.message : String(err));
|
|
6248
6251
|
}
|
|
@@ -6252,12 +6255,12 @@ function registerOfflineTools(server) {
|
|
|
6252
6255
|
...sectionSeconds ? { sectionSeconds } : {},
|
|
6253
6256
|
...referencePath ? { referencePath, referenceStartTime, referenceEndTime } : {}
|
|
6254
6257
|
});
|
|
6255
|
-
const data = toProjectTime(result,
|
|
6258
|
+
const data = toProjectTime(result, start2);
|
|
6256
6259
|
logToolResult("analyze_track_offline", args, startedAt, offlineSummary(wav.trackName ?? `Track ${trackIndex5 + 1}`, data));
|
|
6257
6260
|
return text({
|
|
6258
6261
|
trackIndex: trackIndex5,
|
|
6259
6262
|
trackName: wav.trackName,
|
|
6260
|
-
startTime:
|
|
6263
|
+
startTime: start2,
|
|
6261
6264
|
endTime: end,
|
|
6262
6265
|
...data
|
|
6263
6266
|
});
|
|
@@ -6470,9 +6473,9 @@ function pulsePoints(hits, o, rangeStart) {
|
|
|
6470
6473
|
});
|
|
6471
6474
|
return points;
|
|
6472
6475
|
}
|
|
6473
|
-
function sections(hits,
|
|
6476
|
+
function sections(hits, start2, end, seconds2) {
|
|
6474
6477
|
const out2 = [];
|
|
6475
|
-
for (let s =
|
|
6478
|
+
for (let s = start2; s < end; s += seconds2) {
|
|
6476
6479
|
const e = Math.min(end, s + seconds2);
|
|
6477
6480
|
const inside = hits.filter((h) => h.time >= s && h.time < e);
|
|
6478
6481
|
out2.push({
|
|
@@ -6507,31 +6510,31 @@ async function detect(args) {
|
|
|
6507
6510
|
minGapMs: args.minGapMs ?? 50
|
|
6508
6511
|
};
|
|
6509
6512
|
let result;
|
|
6510
|
-
let
|
|
6513
|
+
let start2;
|
|
6511
6514
|
let end;
|
|
6512
6515
|
let source;
|
|
6513
6516
|
if (path != null) {
|
|
6514
6517
|
const position = args.filePosition ?? 0;
|
|
6515
|
-
|
|
6518
|
+
start2 = args.startTime ?? position;
|
|
6516
6519
|
end = args.endTime ?? null;
|
|
6517
|
-
if (
|
|
6518
|
-
if (end != null && end <=
|
|
6520
|
+
if (start2 < position) return `startTime ${start2} is before the file starts (filePosition ${position})`;
|
|
6521
|
+
if (end != null && end <= start2) return "endTime must be greater than startTime";
|
|
6519
6522
|
result = await sidecar.transients({
|
|
6520
6523
|
path,
|
|
6521
|
-
...
|
|
6524
|
+
...start2 > position ? { startTime: start2 - position } : {},
|
|
6522
6525
|
...end != null ? { endTime: end - position } : {},
|
|
6523
6526
|
...options
|
|
6524
6527
|
});
|
|
6525
6528
|
for (const t of result["transients"] ?? []) t.time = round(t.time + position);
|
|
6526
6529
|
source = { path, filePosition: position };
|
|
6527
6530
|
} else {
|
|
6528
|
-
|
|
6529
|
-
end = args.endTime ??
|
|
6530
|
-
if (end <=
|
|
6531
|
-
if (end -
|
|
6531
|
+
start2 = args.startTime ?? 0;
|
|
6532
|
+
end = args.endTime ?? start2 + DEFAULT_TRACK_SECONDS;
|
|
6533
|
+
if (end <= start2) return "endTime must be greater than startTime";
|
|
6534
|
+
if (end - start2 > MAX_OFFLINE_SECONDS) return `Range too long: max ${MAX_OFFLINE_SECONDS} s per call`;
|
|
6532
6535
|
let wav;
|
|
6533
6536
|
try {
|
|
6534
|
-
wav = await renderTrack(trackIndex5,
|
|
6537
|
+
wav = await renderTrack(trackIndex5, start2, end, { dry: true });
|
|
6535
6538
|
} catch (err) {
|
|
6536
6539
|
return err instanceof Error ? err.message : String(err);
|
|
6537
6540
|
}
|
|
@@ -6540,7 +6543,7 @@ async function detect(args) {
|
|
|
6540
6543
|
} finally {
|
|
6541
6544
|
await discardRender(wav);
|
|
6542
6545
|
}
|
|
6543
|
-
for (const t of result["transients"] ?? []) t.time = round(t.time +
|
|
6546
|
+
for (const t of result["transients"] ?? []) t.time = round(t.time + start2);
|
|
6544
6547
|
source = { trackIndex: trackIndex5, trackName: wav.trackName };
|
|
6545
6548
|
}
|
|
6546
6549
|
const all = result["transients"] ?? [];
|
|
@@ -6549,8 +6552,8 @@ async function detect(args) {
|
|
|
6549
6552
|
const durationSeconds = Number(result["durationSeconds"] ?? 0);
|
|
6550
6553
|
return {
|
|
6551
6554
|
source,
|
|
6552
|
-
start,
|
|
6553
|
-
end: end ?? round(
|
|
6555
|
+
start: start2,
|
|
6556
|
+
end: end ?? round(start2 + durationSeconds, 3),
|
|
6554
6557
|
durationSeconds,
|
|
6555
6558
|
tempo: result["tempo"],
|
|
6556
6559
|
detected: all.length,
|
|
@@ -6753,20 +6756,20 @@ async function detect2(args) {
|
|
|
6753
6756
|
minNoteMs: args.minNoteMs ?? 80
|
|
6754
6757
|
};
|
|
6755
6758
|
const position = args.filePosition ?? 0;
|
|
6756
|
-
const
|
|
6757
|
-
const end = args.endTime ??
|
|
6758
|
-
if (end <=
|
|
6759
|
-
if (end -
|
|
6759
|
+
const start2 = args.startTime ?? position;
|
|
6760
|
+
const end = args.endTime ?? start2 + DEFAULT_TRACK_SECONDS2;
|
|
6761
|
+
if (end <= start2) return "endTime must be greater than startTime";
|
|
6762
|
+
if (end - start2 > MAX_OFFLINE_SECONDS) return `Range too long: max ${MAX_OFFLINE_SECONDS} s per call`;
|
|
6760
6763
|
let result;
|
|
6761
6764
|
let offset;
|
|
6762
6765
|
if (path != null) {
|
|
6763
|
-
if (
|
|
6764
|
-
result = await sidecar.detectPitch({ path, startTime:
|
|
6766
|
+
if (start2 < position) return `startTime ${start2} is before the file starts (filePosition ${position})`;
|
|
6767
|
+
result = await sidecar.detectPitch({ path, startTime: start2 - position, endTime: end - position, ...options });
|
|
6765
6768
|
offset = position;
|
|
6766
6769
|
} else {
|
|
6767
6770
|
let wav;
|
|
6768
6771
|
try {
|
|
6769
|
-
wav = await renderTrack(trackIndex5,
|
|
6772
|
+
wav = await renderTrack(trackIndex5, start2, end, { dry: true });
|
|
6770
6773
|
} catch (err) {
|
|
6771
6774
|
return err instanceof Error ? err.message : String(err);
|
|
6772
6775
|
}
|
|
@@ -6775,7 +6778,7 @@ async function detect2(args) {
|
|
|
6775
6778
|
} finally {
|
|
6776
6779
|
await discardRender(wav);
|
|
6777
6780
|
}
|
|
6778
|
-
offset =
|
|
6781
|
+
offset = start2;
|
|
6779
6782
|
}
|
|
6780
6783
|
const notes = (result["notes"] ?? []).map((n) => ({
|
|
6781
6784
|
...n,
|
|
@@ -6783,30 +6786,30 @@ async function detect2(args) {
|
|
|
6783
6786
|
end: round2(n.end + offset)
|
|
6784
6787
|
}));
|
|
6785
6788
|
const { notes: _notes, ...summary } = result;
|
|
6786
|
-
return { start, end, notes, summary };
|
|
6789
|
+
return { start: start2, end, notes, summary };
|
|
6787
6790
|
}
|
|
6788
6791
|
async function listItems(trackIndex5) {
|
|
6789
6792
|
const res = await sendCommand("list_media_items", { trackIndex: trackIndex5 });
|
|
6790
6793
|
if (!res.success) return res.error ?? "list_media_items failed";
|
|
6791
6794
|
return (res.data.items ?? []).filter((i) => !i.isMidi);
|
|
6792
6795
|
}
|
|
6793
|
-
async function isolate(trackIndex5,
|
|
6796
|
+
async function isolate(trackIndex5, start2, end) {
|
|
6794
6797
|
let items = await listItems(trackIndex5);
|
|
6795
6798
|
if (typeof items === "string") return items;
|
|
6796
|
-
const holds = (i) => i.position <=
|
|
6799
|
+
const holds = (i) => i.position <= start2 + EPS && i.position + i.length >= end - EPS;
|
|
6797
6800
|
let item = items.find(holds);
|
|
6798
6801
|
if (!item) return "the note is not inside one item";
|
|
6799
6802
|
if (end < item.position + item.length - EPS) {
|
|
6800
6803
|
const res = await sendCommand("split_media_item", { trackIndex: trackIndex5, itemIndex: item.itemIndex, position: end });
|
|
6801
6804
|
if (!res.success) return res.error ?? "split failed";
|
|
6802
6805
|
}
|
|
6803
|
-
if (
|
|
6804
|
-
const res = await sendCommand("split_media_item", { trackIndex: trackIndex5, itemIndex: item.itemIndex, position:
|
|
6806
|
+
if (start2 > item.position + EPS) {
|
|
6807
|
+
const res = await sendCommand("split_media_item", { trackIndex: trackIndex5, itemIndex: item.itemIndex, position: start2 });
|
|
6805
6808
|
if (!res.success) return res.error ?? "split failed";
|
|
6806
6809
|
}
|
|
6807
6810
|
items = await listItems(trackIndex5);
|
|
6808
6811
|
if (typeof items === "string") return items;
|
|
6809
|
-
item = items.find((i) => Math.abs(i.position -
|
|
6812
|
+
item = items.find((i) => Math.abs(i.position - start2) < EPS && i.position + i.length <= end + EPS);
|
|
6810
6813
|
return item ? item.itemIndex : "could not find the piece after splitting";
|
|
6811
6814
|
}
|
|
6812
6815
|
var { path: _path, filePosition: _filePosition, ...trackSchema } = {
|
|
@@ -6925,28 +6928,28 @@ async function resolveSource(args, maxSeconds, defaultSeconds = DEFAULT_TRACK_SE
|
|
|
6925
6928
|
const { trackIndex: trackIndex5, path, startTime, endTime } = args;
|
|
6926
6929
|
if (trackIndex5 == null === (path == null)) return "Give either trackIndex or path";
|
|
6927
6930
|
if (startTime != null && endTime != null && endTime <= startTime) return "endTime must be greater than startTime";
|
|
6928
|
-
const
|
|
6931
|
+
const start2 = startTime ?? 0;
|
|
6929
6932
|
if (path != null) {
|
|
6930
|
-
if (endTime != null && endTime -
|
|
6933
|
+
if (endTime != null && endTime - start2 > maxSeconds) return `Range too long: max ${maxSeconds} s per call`;
|
|
6931
6934
|
return {
|
|
6932
6935
|
path,
|
|
6933
6936
|
name: basename2(path, extname(path)),
|
|
6934
6937
|
offset: 0,
|
|
6935
6938
|
window: { ...startTime != null ? { startTime } : {}, ...endTime != null ? { endTime } : {} },
|
|
6936
|
-
...endTime != null ? { seconds: endTime -
|
|
6939
|
+
...endTime != null ? { seconds: endTime - start2 } : {}
|
|
6937
6940
|
};
|
|
6938
6941
|
}
|
|
6939
|
-
const end = endTime ??
|
|
6940
|
-
if (end -
|
|
6941
|
-
const wav = await renderTrack(trackIndex5,
|
|
6942
|
+
const end = endTime ?? start2 + Math.min(defaultSeconds, maxSeconds);
|
|
6943
|
+
if (end - start2 > maxSeconds) return `Range too long: max ${maxSeconds} s per call`;
|
|
6944
|
+
const wav = await renderTrack(trackIndex5, start2, end);
|
|
6942
6945
|
return {
|
|
6943
6946
|
path: wav.wavPath,
|
|
6944
6947
|
name: wav.trackName ?? (trackIndex5 === -1 ? "Master" : `Track ${trackIndex5 + 1}`),
|
|
6945
|
-
offset:
|
|
6948
|
+
offset: start2,
|
|
6946
6949
|
window: {},
|
|
6947
6950
|
temp: wav,
|
|
6948
6951
|
trackIndex: trackIndex5,
|
|
6949
|
-
seconds: end -
|
|
6952
|
+
seconds: end - start2
|
|
6950
6953
|
};
|
|
6951
6954
|
}
|
|
6952
6955
|
function shift(span, by) {
|
|
@@ -8031,14 +8034,14 @@ function parseSmf(data) {
|
|
|
8031
8034
|
for (let t = 0; t < trackCount && !r.done; t++) {
|
|
8032
8035
|
const id = r.ascii(4);
|
|
8033
8036
|
const len = r.u32();
|
|
8034
|
-
const
|
|
8037
|
+
const start2 = r.pos;
|
|
8035
8038
|
if (id !== "MTrk") {
|
|
8036
|
-
r.pos =
|
|
8039
|
+
r.pos = start2 + len;
|
|
8037
8040
|
t--;
|
|
8038
8041
|
continue;
|
|
8039
8042
|
}
|
|
8040
|
-
const tr = new Reader(data, Math.min(
|
|
8041
|
-
tr.pos =
|
|
8043
|
+
const tr = new Reader(data, Math.min(start2 + len, data.length));
|
|
8044
|
+
tr.pos = start2;
|
|
8042
8045
|
const track = { name: "", notes: [], cc: [] };
|
|
8043
8046
|
const open = /* @__PURE__ */ new Map();
|
|
8044
8047
|
let tick = 0;
|
|
@@ -8107,7 +8110,7 @@ function parseSmf(data) {
|
|
|
8107
8110
|
for (const n of track.notes) endTicks = Math.max(endTicks, Math.round((n.start + n.length) * ppq));
|
|
8108
8111
|
track.notes.sort((a, b) => a.start - b.start || a.pitch - b.pitch);
|
|
8109
8112
|
if (track.notes.length || track.cc.length) tracks2.push(track);
|
|
8110
|
-
r.pos =
|
|
8113
|
+
r.pos = start2 + len;
|
|
8111
8114
|
}
|
|
8112
8115
|
return { format, ppq, tracks: tracks2, tempo, tempoChanges, timeSignature, lengthQN: endTicks / ppq, skipped };
|
|
8113
8116
|
}
|
|
@@ -8367,8 +8370,8 @@ function registerCompositionTools(server) {
|
|
|
8367
8370
|
args.startTime = r.startTime;
|
|
8368
8371
|
args.endTime = r.endTime;
|
|
8369
8372
|
}
|
|
8370
|
-
const
|
|
8371
|
-
if (args.endTime != null && args.endTime <=
|
|
8373
|
+
const start2 = args.startTime ?? 0;
|
|
8374
|
+
if (args.endTime != null && args.endTime <= start2) return fail4("endTime must be greater than startTime");
|
|
8372
8375
|
if (trackIndex5 === -1 && args.source === "midi") return fail4('The master track holds no MIDI notes: give a track index, or source "audio"');
|
|
8373
8376
|
let profile = null;
|
|
8374
8377
|
let source;
|
|
@@ -8377,7 +8380,7 @@ function registerCompositionTools(server) {
|
|
|
8377
8380
|
if (path == null && args.source !== "audio" && trackIndex5 >= 0) {
|
|
8378
8381
|
const res = await sendCommand("_midi_pitch_profile", {
|
|
8379
8382
|
trackIndex: trackIndex5,
|
|
8380
|
-
startTime:
|
|
8383
|
+
startTime: start2,
|
|
8381
8384
|
...args.endTime != null ? { endTime: args.endTime } : {}
|
|
8382
8385
|
});
|
|
8383
8386
|
if (!res.success) return fail4(`Error: ${res.error}`);
|
|
@@ -8397,17 +8400,17 @@ function registerCompositionTools(server) {
|
|
|
8397
8400
|
return fail4(SIDECAR_NOT_INSTALLED_MSG);
|
|
8398
8401
|
}
|
|
8399
8402
|
if (path != null) {
|
|
8400
|
-
const c = await sidecar.chroma({ path, ...
|
|
8403
|
+
const c = await sidecar.chroma({ path, ...start2 > 0 ? { startTime: start2 } : {}, ...args.endTime != null ? { endTime: args.endTime } : {} });
|
|
8401
8404
|
profile = c.chroma;
|
|
8402
8405
|
source = "file";
|
|
8403
8406
|
name = basename3(path);
|
|
8404
8407
|
extra = { durationSeconds: c.durationSeconds };
|
|
8405
8408
|
} else {
|
|
8406
|
-
const end = args.endTime ??
|
|
8407
|
-
if (end -
|
|
8409
|
+
const end = args.endTime ?? start2 + DEFAULT_KEY_SECONDS;
|
|
8410
|
+
if (end - start2 > MAX_OFFLINE_SECONDS) return fail4(`Range too long: max ${MAX_OFFLINE_SECONDS} s per call`);
|
|
8408
8411
|
let wav;
|
|
8409
8412
|
try {
|
|
8410
|
-
wav = await renderTrack(trackIndex5,
|
|
8413
|
+
wav = await renderTrack(trackIndex5, start2, end, { dry: true });
|
|
8411
8414
|
} catch (err) {
|
|
8412
8415
|
return fail4(err instanceof Error ? err.message : String(err));
|
|
8413
8416
|
}
|
|
@@ -8511,41 +8514,41 @@ function registerCompositionTools(server) {
|
|
|
8511
8514
|
};
|
|
8512
8515
|
if (path != null) {
|
|
8513
8516
|
if (!sidecar.isAvailable()) return needSidecar();
|
|
8514
|
-
const
|
|
8515
|
-
const end = args.endTime ??
|
|
8516
|
-
if (end -
|
|
8517
|
-
const grid = fileGrid(end -
|
|
8517
|
+
const start2 = args.startTime ?? 0;
|
|
8518
|
+
const end = args.endTime ?? start2 + MAX_OFFLINE_SECONDS;
|
|
8519
|
+
if (end - start2 > MAX_OFFLINE_SECONDS) return fail4(`Range too long: max ${MAX_OFFLINE_SECONDS} s per call`);
|
|
8520
|
+
const grid = fileGrid(end - start2, args.bpm, args.beatsPerBar ?? 4, per, windowSeconds);
|
|
8518
8521
|
if (!grid) return fail4(`More than ${MAX_SEGMENTS} segments: use a shorter range, per "bar" or a longer windowSeconds`);
|
|
8519
8522
|
const model = await useModel();
|
|
8520
8523
|
if (typeof model === "string") return fail4(model);
|
|
8521
8524
|
if (model) {
|
|
8522
|
-
const m = await runModel(path,
|
|
8525
|
+
const m = await runModel(path, start2, args.endTime, grid, end - start2);
|
|
8523
8526
|
const dur = m.duration;
|
|
8524
8527
|
const kept = grid.map((g, i) => ({ g, p: m.picks[i] })).filter(({ g }) => g.start < dur - 1e-6);
|
|
8525
|
-
segments = kept.map(({ g }) => ({ ...g, start:
|
|
8528
|
+
segments = kept.map(({ g }) => ({ ...g, start: start2 + g.start, end: start2 + Math.min(g.end, dur), profile: [] }));
|
|
8526
8529
|
picks = kept.map(({ p }) => p);
|
|
8527
8530
|
profile = m.profile;
|
|
8528
8531
|
source = "file";
|
|
8529
8532
|
name = basename3(path);
|
|
8530
|
-
range = { startTime:
|
|
8533
|
+
range = { startTime: start2, endTime: start2 + dur };
|
|
8531
8534
|
} else {
|
|
8532
8535
|
const c = await sidecar.chroma({
|
|
8533
8536
|
path,
|
|
8534
|
-
...
|
|
8537
|
+
...start2 > 0 ? { startTime: start2 } : {},
|
|
8535
8538
|
...args.endTime != null ? { endTime: args.endTime } : {},
|
|
8536
8539
|
segments: grid.map((g) => [g.start, g.end])
|
|
8537
8540
|
});
|
|
8538
8541
|
const dur = c.durationSeconds;
|
|
8539
8542
|
segments = grid.filter((g) => g.start < dur - 1e-6).map((g, i) => ({
|
|
8540
8543
|
...g,
|
|
8541
|
-
start:
|
|
8542
|
-
end:
|
|
8544
|
+
start: start2 + g.start,
|
|
8545
|
+
end: start2 + Math.min(g.end, dur),
|
|
8543
8546
|
profile: c.segments?.[i] ?? []
|
|
8544
8547
|
}));
|
|
8545
8548
|
profile = c.chroma;
|
|
8546
8549
|
source = "file";
|
|
8547
8550
|
name = basename3(path);
|
|
8548
|
-
range = { startTime:
|
|
8551
|
+
range = { startTime: start2, endTime: start2 + dur };
|
|
8549
8552
|
}
|
|
8550
8553
|
} else {
|
|
8551
8554
|
const useMidi = args.source !== "audio" && engineArg !== "model" && trackIndex5 >= 0;
|
|
@@ -8568,20 +8571,20 @@ function registerCompositionTools(server) {
|
|
|
8568
8571
|
} else {
|
|
8569
8572
|
if (args.source === "midi") return fail4(`Track ${trackIndex5} has no MIDI notes in the range (drums on channel 10 are ignored)`);
|
|
8570
8573
|
if (!sidecar.isAvailable()) return needSidecar();
|
|
8571
|
-
const { startTime:
|
|
8572
|
-
if (end -
|
|
8574
|
+
const { startTime: start2, endTime: end } = range;
|
|
8575
|
+
if (end - start2 > MAX_OFFLINE_SECONDS) return fail4(`Range too long: max ${MAX_OFFLINE_SECONDS} s per call (give startTime/endTime)`);
|
|
8573
8576
|
const model = await useModel();
|
|
8574
8577
|
if (typeof model === "string") return fail4(model);
|
|
8575
8578
|
let wav;
|
|
8576
8579
|
try {
|
|
8577
|
-
wav = await renderTrack(trackIndex5,
|
|
8580
|
+
wav = await renderTrack(trackIndex5, start2, end, { dry: true });
|
|
8578
8581
|
} catch (err) {
|
|
8579
8582
|
return fail4(err instanceof Error ? err.message : String(err));
|
|
8580
8583
|
}
|
|
8581
8584
|
try {
|
|
8582
|
-
const relative2 = g.segments.map((s) => ({ start: s.start -
|
|
8585
|
+
const relative2 = g.segments.map((s) => ({ start: s.start - start2, end: s.end - start2 }));
|
|
8583
8586
|
if (model) {
|
|
8584
|
-
const m = await runModel(wav.wavPath, 0, void 0, relative2, end -
|
|
8587
|
+
const m = await runModel(wav.wavPath, 0, void 0, relative2, end - start2);
|
|
8585
8588
|
segments = g.segments.map((s) => ({ ...s, profile: [] }));
|
|
8586
8589
|
picks = m.picks;
|
|
8587
8590
|
profile = m.profile;
|
|
@@ -8654,9 +8657,9 @@ function arrangeVoiceSketch(source, options) {
|
|
|
8654
8657
|
const motifBeats = Math.max(4, Math.ceil(endBeat / 4) * 4);
|
|
8655
8658
|
const length = bars * 4;
|
|
8656
8659
|
const tempos = [];
|
|
8657
|
-
for (let
|
|
8660
|
+
for (let start2 = 0; start2 < length; start2 += motifBeats) {
|
|
8658
8661
|
for (const segment of segments) {
|
|
8659
|
-
const beat =
|
|
8662
|
+
const beat = start2 + segment.beat;
|
|
8660
8663
|
if (beat < length && tempos.at(-1)?.bpm !== segment.bpm) tempos.push({ beat, bpm: segment.bpm });
|
|
8661
8664
|
}
|
|
8662
8665
|
}
|
|
@@ -8667,12 +8670,12 @@ function arrangeVoiceSketch(source, options) {
|
|
|
8667
8670
|
{ name: "melody", channel: 0, program: 11, gain: 0.8, origin: "detected motif repeated", notes: [], cc: [] }
|
|
8668
8671
|
];
|
|
8669
8672
|
const [drums, bass, harmony, melody] = tracks2;
|
|
8670
|
-
const add2 = (track,
|
|
8671
|
-
if (
|
|
8672
|
-
track.notes.push({ start, length: Math.min(duration, length -
|
|
8673
|
+
const add2 = (track, start2, duration, pitch, velocity) => {
|
|
8674
|
+
if (start2 >= length || start2 < 0) return;
|
|
8675
|
+
track.notes.push({ start: start2, length: Math.min(duration, length - start2), pitch, velocity, channel: track.channel });
|
|
8673
8676
|
};
|
|
8674
|
-
for (let
|
|
8675
|
-
for (const n of source.melody) add2(melody,
|
|
8677
|
+
for (let start2 = 0; start2 < length; start2 += motifBeats) {
|
|
8678
|
+
for (const n of source.melody) add2(melody, start2 + n.beat, n.lengthBeats, n.pitch, n.velocity);
|
|
8676
8679
|
}
|
|
8677
8680
|
const edgeBars = bars >= 8 ? 2 : 1;
|
|
8678
8681
|
const chorusBar = Math.floor(bars / 2);
|
|
@@ -9917,6 +9920,82 @@ function registerPluginBuildTools(server) {
|
|
|
9917
9920
|
);
|
|
9918
9921
|
}
|
|
9919
9922
|
|
|
9923
|
+
// apps/reaper-mcp-server/src/tool-annotations.ts
|
|
9924
|
+
var READ_PREFIXES = ["get_", "list_", "read_", "analyze_", "search_", "detect_", "measure_"];
|
|
9925
|
+
var READ_EXTRA = /* @__PURE__ */ new Set([
|
|
9926
|
+
"measure_masking",
|
|
9927
|
+
"measure_track_alignment",
|
|
9928
|
+
"verify_edit",
|
|
9929
|
+
"snapshot_list",
|
|
9930
|
+
// Category tools only change which tools are described, never the project
|
|
9931
|
+
"enable_tool_category",
|
|
9932
|
+
"disable_tool_category"
|
|
9933
|
+
]);
|
|
9934
|
+
var DESTRUCTIVE_PREFIXES = ["delete_", "remove_"];
|
|
9935
|
+
var DESTRUCTIVE_EXTRA = /* @__PURE__ */ new Set([
|
|
9936
|
+
"clear_envelope",
|
|
9937
|
+
"undo_project",
|
|
9938
|
+
"redo_project",
|
|
9939
|
+
"run_action",
|
|
9940
|
+
"run_plan",
|
|
9941
|
+
"save_project",
|
|
9942
|
+
"render_project",
|
|
9943
|
+
"render_versions",
|
|
9944
|
+
"snapshot_restore",
|
|
9945
|
+
"snapshot_delete",
|
|
9946
|
+
"load_fx_chain",
|
|
9947
|
+
"process_items",
|
|
9948
|
+
"freeze_tracks",
|
|
9949
|
+
"unfreeze_tracks",
|
|
9950
|
+
"apply_fx_to_items",
|
|
9951
|
+
// replace a saved file (`overwrite`) or existing points / stretch markers wholesale
|
|
9952
|
+
"save_fx_chain",
|
|
9953
|
+
"save_track_template",
|
|
9954
|
+
"create_transient_automation",
|
|
9955
|
+
"quantize_audio",
|
|
9956
|
+
"align_audio_to_guide",
|
|
9957
|
+
"edit_stretch_markers"
|
|
9958
|
+
]);
|
|
9959
|
+
var WORDS = {
|
|
9960
|
+
fx: "FX",
|
|
9961
|
+
midi: "MIDI",
|
|
9962
|
+
cc: "CC",
|
|
9963
|
+
pc: "PC",
|
|
9964
|
+
lufs: "LUFS",
|
|
9965
|
+
jsfx: "JSFX",
|
|
9966
|
+
rfx: "RfxChain",
|
|
9967
|
+
fxchain: "FX chain",
|
|
9968
|
+
pcm: "PCM",
|
|
9969
|
+
rpp: "RPP",
|
|
9970
|
+
hlx: "HLX"
|
|
9971
|
+
};
|
|
9972
|
+
function toolTitle(name) {
|
|
9973
|
+
const words = name.split("_").map((w) => WORDS[w] ?? w);
|
|
9974
|
+
const text9 = words.join(" ");
|
|
9975
|
+
return text9.charAt(0).toUpperCase() + text9.slice(1);
|
|
9976
|
+
}
|
|
9977
|
+
var OPEN_WORLD = /* @__PURE__ */ new Set(["list_builtin_knowledge", "get_builtin_knowledge"]);
|
|
9978
|
+
function toolKind(name) {
|
|
9979
|
+
const kind = baseKind(name);
|
|
9980
|
+
return OPEN_WORLD.has(name) ? { ...kind, openWorldHint: true } : kind;
|
|
9981
|
+
}
|
|
9982
|
+
function baseKind(name) {
|
|
9983
|
+
if (DESTRUCTIVE_EXTRA.has(name) || DESTRUCTIVE_PREFIXES.some((p) => name.startsWith(p))) {
|
|
9984
|
+
return { readOnlyHint: false, destructiveHint: true, openWorldHint: false };
|
|
9985
|
+
}
|
|
9986
|
+
if (READ_EXTRA.has(name) || READ_PREFIXES.some((p) => name.startsWith(p))) {
|
|
9987
|
+
return { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
9988
|
+
}
|
|
9989
|
+
return { readOnlyHint: false, destructiveHint: false, openWorldHint: false };
|
|
9990
|
+
}
|
|
9991
|
+
function annotateTools(server) {
|
|
9992
|
+
const tools = server._registeredTools;
|
|
9993
|
+
for (const [name, tool] of Object.entries(tools)) {
|
|
9994
|
+
tool.title ??= toolTitle(name);
|
|
9995
|
+
tool.annotations = { title: tool.title, ...toolKind(name), ...tool.annotations };
|
|
9996
|
+
}
|
|
9997
|
+
}
|
|
9998
|
+
|
|
9920
9999
|
// apps/reaper-mcp-server/src/server.ts
|
|
9921
10000
|
var MAX_STATUS_MESSAGE = 256;
|
|
9922
10001
|
var TOOL_ERROR_MESSAGE = "reaper.tool.error.message";
|
|
@@ -10072,6 +10151,7 @@ function createServer(profile = resolveProfile()) {
|
|
|
10072
10151
|
registerPluginResearchTools(server);
|
|
10073
10152
|
registerJsfxTools(server);
|
|
10074
10153
|
registerPluginBuildTools(server);
|
|
10154
|
+
annotateTools(server);
|
|
10075
10155
|
return server;
|
|
10076
10156
|
}
|
|
10077
10157
|
|
|
@@ -10640,10 +10720,523 @@ Try it: reaper-mcp extension link ${basename4(r.dir)}`);
|
|
|
10640
10720
|
}
|
|
10641
10721
|
}
|
|
10642
10722
|
|
|
10723
|
+
// apps/reaper-mcp-server/src/instance-cli.ts
|
|
10724
|
+
import { execFileSync as execFileSync2, spawn as spawn2, spawnSync } from "node:child_process";
|
|
10725
|
+
import { existsSync as existsSync10, realpathSync, statSync as statSync3 } from "node:fs";
|
|
10726
|
+
import { homedir as homedir11, platform as platform6 } from "node:os";
|
|
10727
|
+
import { join as join15 } from "node:path";
|
|
10728
|
+
|
|
10729
|
+
// apps/reaper-mcp-server/src/harnesses.ts
|
|
10730
|
+
import { execFileSync } from "node:child_process";
|
|
10731
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync7, readFileSync as readFileSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
10732
|
+
import { delimiter, dirname as dirname8, isAbsolute as isAbsolute3, join as join13 } from "node:path";
|
|
10733
|
+
import { homedir as homedir9, platform as platform4 } from "node:os";
|
|
10734
|
+
var HARNESSES = [
|
|
10735
|
+
{ id: "claude", name: "Claude Code", binary: "claude", installHint: "https://claude.com/claude-code", skillsHome: "claude" },
|
|
10736
|
+
{ id: "codex", name: "Codex CLI", binary: "codex", installHint: "npm install -g @openai/codex (or: brew install codex)", skillsHome: "agents" },
|
|
10737
|
+
{ id: "gemini", name: "Gemini CLI", binary: "gemini", installHint: "npm install -g @google/gemini-cli", skillsHome: "agents" },
|
|
10738
|
+
{ id: "cursor", name: "Cursor", binary: null, installHint: "https://cursor.com", skillsHome: "agents" }
|
|
10739
|
+
];
|
|
10740
|
+
var SERVER_NAME = "reaper";
|
|
10741
|
+
var DEFAULT_SERVER = { name: SERVER_NAME, env: {} };
|
|
10742
|
+
function onPath(name, pathVar = process.env.PATH ?? "", win = platform4() === "win32") {
|
|
10743
|
+
const exts = win ? ["", ".exe", ".cmd", ".bat"] : [""];
|
|
10744
|
+
return pathVar.split(delimiter).filter(Boolean).some((dir) => exts.some((ext) => existsSync8(join13(dir, name + ext))));
|
|
10745
|
+
}
|
|
10746
|
+
function realEnv() {
|
|
10747
|
+
return { home: homedir9(), codexHome: process.env.CODEX_HOME || void 0, hasBinary: (name) => onPath(name) };
|
|
10748
|
+
}
|
|
10749
|
+
var configPath = (id, env) => ({
|
|
10750
|
+
claude: join13(env.home, ".claude.json"),
|
|
10751
|
+
codex: join13(env.codexHome ?? join13(env.home, ".codex"), "config.toml"),
|
|
10752
|
+
gemini: join13(env.home, ".gemini", "settings.json"),
|
|
10753
|
+
cursor: join13(env.home, ".cursor", "mcp.json")
|
|
10754
|
+
})[id];
|
|
10755
|
+
function detectHarnesses(env = realEnv()) {
|
|
10756
|
+
return HARNESSES.filter((h) => h.binary ? env.hasBinary(h.binary) : existsSync8(join13(env.home, ".cursor")));
|
|
10757
|
+
}
|
|
10758
|
+
function registeredServer(id, env = realEnv(), name = SERVER_NAME) {
|
|
10759
|
+
let text9;
|
|
10760
|
+
try {
|
|
10761
|
+
text9 = readFileSync6(configPath(id, env), "utf-8");
|
|
10762
|
+
} catch {
|
|
10763
|
+
return null;
|
|
10764
|
+
}
|
|
10765
|
+
if (id === "codex") return codexServer(text9, name);
|
|
10766
|
+
try {
|
|
10767
|
+
const server = JSON.parse(text9)?.mcpServers?.[name];
|
|
10768
|
+
if (!server || typeof server.command !== "string") return null;
|
|
10769
|
+
return { command: server.command, args: Array.isArray(server.args) ? server.args.filter((a) => typeof a === "string") : [] };
|
|
10770
|
+
} catch {
|
|
10771
|
+
return null;
|
|
10772
|
+
}
|
|
10773
|
+
}
|
|
10774
|
+
function codexServer(toml, name) {
|
|
10775
|
+
const header = new RegExp(`^\\[mcp_servers\\.(?:${name}|"${name}")\\]\\s*$`, "m").exec(toml);
|
|
10776
|
+
if (!header) return null;
|
|
10777
|
+
const rest = toml.slice(header.index + header[0].length);
|
|
10778
|
+
const next = /^\[/m.exec(rest);
|
|
10779
|
+
const section = next ? rest.slice(0, next.index) : rest;
|
|
10780
|
+
const command2 = /^command\s*=\s*("(?:[^"\\]|\\.)*"|'[^']*')/m.exec(section)?.[1];
|
|
10781
|
+
if (!command2) return null;
|
|
10782
|
+
const args = /^args\s*=\s*\[([^\]]*)\]/m.exec(section)?.[1] ?? "";
|
|
10783
|
+
const strings = (s) => [...s.matchAll(/"((?:[^"\\]|\\.)*)"|'([^']*)'/g)].map((m) => m[1] !== void 0 ? JSON.parse(`"${m[1]}"`) : m[2]);
|
|
10784
|
+
return { command: strings(command2)[0], args: strings(args) };
|
|
10785
|
+
}
|
|
10786
|
+
function isStale(server) {
|
|
10787
|
+
return [server.command, ...server.args].filter(isAbsolute3).some((p) => !existsSync8(p));
|
|
10788
|
+
}
|
|
10789
|
+
var envFlags = (env, flag) => Object.entries(env).flatMap(([k, v]) => [flag, `${k}=${v}`]);
|
|
10790
|
+
function addCommand(id, node, mainJs, server = DEFAULT_SERVER) {
|
|
10791
|
+
switch (id) {
|
|
10792
|
+
case "claude":
|
|
10793
|
+
return { bin: "claude", args: ["mcp", "add", "--scope", "user", ...envFlags(server.env, "--env"), server.name, "--", node, mainJs, "serve"] };
|
|
10794
|
+
case "codex":
|
|
10795
|
+
return { bin: "codex", args: ["mcp", "add", server.name, ...envFlags(server.env, "--env"), "--", node, mainJs, "serve"] };
|
|
10796
|
+
case "gemini":
|
|
10797
|
+
return { bin: "gemini", args: ["mcp", "add", "--scope", "user", ...envFlags(server.env, "-e"), server.name, node, mainJs, "serve"] };
|
|
10798
|
+
case "cursor":
|
|
10799
|
+
return null;
|
|
10800
|
+
}
|
|
10801
|
+
}
|
|
10802
|
+
function removeCommand(id, name) {
|
|
10803
|
+
switch (id) {
|
|
10804
|
+
case "claude":
|
|
10805
|
+
return { bin: "claude", args: ["mcp", "remove", "--scope", "user", name] };
|
|
10806
|
+
case "codex":
|
|
10807
|
+
return { bin: "codex", args: ["mcp", "remove", name] };
|
|
10808
|
+
case "gemini":
|
|
10809
|
+
return { bin: "gemini", args: ["mcp", "remove", "--scope", "user", name] };
|
|
10810
|
+
case "cursor":
|
|
10811
|
+
return null;
|
|
10812
|
+
}
|
|
10813
|
+
}
|
|
10814
|
+
function manualCommand(id, node, mainJs, env = realEnv(), server = DEFAULT_SERVER) {
|
|
10815
|
+
const add2 = addCommand(id, node, mainJs, server);
|
|
10816
|
+
if (add2) return [add2.bin, ...add2.args].join(" ");
|
|
10817
|
+
const envPart = Object.keys(server.env).length ? `, "env": ${JSON.stringify(server.env)}` : "";
|
|
10818
|
+
return `add "${server.name}": { "command": "${node}", "args": ["${mainJs}", "serve"]${envPart} } under "mcpServers" in ${configPath(id, env)}`;
|
|
10819
|
+
}
|
|
10820
|
+
function quoteForCmd(arg) {
|
|
10821
|
+
return /[\s"]/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg;
|
|
10822
|
+
}
|
|
10823
|
+
var realRunner = (bin, args) => {
|
|
10824
|
+
if (platform4() === "win32") execFileSync(quoteForCmd(bin), args.map(quoteForCmd), { stdio: "pipe", shell: true });
|
|
10825
|
+
else execFileSync(bin, args, { stdio: "pipe" });
|
|
10826
|
+
};
|
|
10827
|
+
function writeJsonServer(path, node, mainJs, server) {
|
|
10828
|
+
let config = {};
|
|
10829
|
+
if (existsSync8(path)) config = JSON.parse(readFileSync6(path, "utf-8"));
|
|
10830
|
+
const servers = config.mcpServers && typeof config.mcpServers === "object" ? config.mcpServers : {};
|
|
10831
|
+
servers[server.name] = { command: node, args: [mainJs, "serve"], ...Object.keys(server.env).length ? { env: server.env } : {} };
|
|
10832
|
+
config.mcpServers = servers;
|
|
10833
|
+
mkdirSync7(dirname8(path), { recursive: true });
|
|
10834
|
+
writeFileSync6(path, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
10835
|
+
}
|
|
10836
|
+
function connectHarness(id, node, mainJs, env = realEnv(), run5 = realRunner, server = DEFAULT_SERVER) {
|
|
10837
|
+
const existing = registeredServer(id, env, server.name);
|
|
10838
|
+
if (existing && !isStale(existing)) return { id, status: "already" };
|
|
10839
|
+
const manual = manualCommand(id, node, mainJs, env, server);
|
|
10840
|
+
try {
|
|
10841
|
+
const add2 = addCommand(id, node, mainJs, server);
|
|
10842
|
+
if (!add2) {
|
|
10843
|
+
writeJsonServer(configPath(id, env), node, mainJs, server);
|
|
10844
|
+
} else {
|
|
10845
|
+
const remove2 = removeCommand(id, server.name);
|
|
10846
|
+
if (existing && remove2) run5(remove2.bin, remove2.args);
|
|
10847
|
+
run5(add2.bin, add2.args);
|
|
10848
|
+
}
|
|
10849
|
+
} catch (err) {
|
|
10850
|
+
const missing = err.code === "ENOENT";
|
|
10851
|
+
const first = String(err.message).split("\n")[0];
|
|
10852
|
+
return { id, status: "failed", detail: missing ? "its command was not found" : first, manual };
|
|
10853
|
+
}
|
|
10854
|
+
return { id, status: existing ? "replaced" : "connected" };
|
|
10855
|
+
}
|
|
10856
|
+
function parseHarnessFlag(argv) {
|
|
10857
|
+
if (argv.includes("--all")) return HARNESSES.map((h) => h.id);
|
|
10858
|
+
const i = argv.findIndex((a) => a === "--harness" || a.startsWith("--harness="));
|
|
10859
|
+
if (i < 0) return null;
|
|
10860
|
+
const value = argv[i].includes("=") ? argv[i].split("=")[1] : argv[i + 1];
|
|
10861
|
+
const ids = (value ?? "").split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
10862
|
+
const known = HARNESSES.map((h) => h.id);
|
|
10863
|
+
const bad = ids.filter((s) => !known.includes(s));
|
|
10864
|
+
if (!ids.length || bad.length) {
|
|
10865
|
+
throw new Error(`Unknown harness${bad.length > 1 ? "es" : ""}: ${bad.join(", ") || "(none given)"}. Use one or more of: ${known.join(", ")}, or --all.`);
|
|
10866
|
+
}
|
|
10867
|
+
return [...new Set(ids)];
|
|
10868
|
+
}
|
|
10869
|
+
function skillsHomes(ids) {
|
|
10870
|
+
const chosen = HARNESSES.filter((h) => ids.includes(h.id));
|
|
10871
|
+
return { claude: chosen.some((h) => h.skillsHome === "claude"), agents: chosen.some((h) => h.skillsHome === "agents") };
|
|
10872
|
+
}
|
|
10873
|
+
|
|
10874
|
+
// apps/reaper-mcp-server/src/instance.ts
|
|
10875
|
+
import { copyFileSync as copyFileSync4, existsSync as existsSync9, mkdirSync as mkdirSync8, readdirSync as readdirSync2, readFileSync as readFileSync7, rmSync as rmSync2, statSync as statSync2, symlinkSync, writeFileSync as writeFileSync7 } from "node:fs";
|
|
10876
|
+
import { homedir as homedir10, platform as platform5 } from "node:os";
|
|
10877
|
+
import { join as join14 } from "node:path";
|
|
10878
|
+
var INSTANCE_NAME = /^[a-z][a-z0-9-]{0,29}$/;
|
|
10879
|
+
function instancesRoot() {
|
|
10880
|
+
return process.env["REAPER_MCP_INSTANCES_DIR"] || join14(homedir10(), ".reaper-mcp", "instances");
|
|
10881
|
+
}
|
|
10882
|
+
function validateInstanceName(name) {
|
|
10883
|
+
if (!name || !INSTANCE_NAME.test(name)) {
|
|
10884
|
+
throw new Error(`Instance names are lowercase letters, digits and dashes, starting with a letter (got ${JSON.stringify(name ?? "")}), for example: background`);
|
|
10885
|
+
}
|
|
10886
|
+
if (name === "default") throw new Error('"default" is your own REAPER: pick another name');
|
|
10887
|
+
return name;
|
|
10888
|
+
}
|
|
10889
|
+
var instanceDir = (name, root = instancesRoot()) => join14(root, name);
|
|
10890
|
+
var infoPath = (name, root = instancesRoot()) => join14(instanceDir(name, root), "instance.json");
|
|
10891
|
+
function iniForInstance(mainIni, port) {
|
|
10892
|
+
const eol = mainIni.includes("\r\n") ? "\r\n" : "\n";
|
|
10893
|
+
const kept = mainIni.split(/\r?\n/).filter((line) => !/^csurf_(?:cnt|\d+)=/.test(line) && !/^loadlastproj=/.test(line));
|
|
10894
|
+
const header = kept.findIndex((l) => l.trim() === "[REAPER]");
|
|
10895
|
+
if (header === -1) kept.unshift("[REAPER]", "loadlastproj=0");
|
|
10896
|
+
else kept.splice(header + 1, 0, "loadlastproj=0");
|
|
10897
|
+
return ensureWebInterface(kept.join(eol), port).ini;
|
|
10898
|
+
}
|
|
10899
|
+
var SHARED_FILES = [/^reaper-vstplugins.*\.ini$/, /^reaper-auplugins.*\.ini$/, /^reaper-clap-.*\.ini$/, /^reaper-jsfx\.ini$/, /^reaper-fxfolders\.ini$/, /^reaper-fxtags\.ini$/, /^reaper-license\.rk$/];
|
|
10900
|
+
var SHARED_DIRS = ["UserPlugins", "FXChains", "TrackTemplates", "MIDINoteNames", "ProjectTemplates"];
|
|
10901
|
+
var SPLIT_DIRS = {
|
|
10902
|
+
Effects: /^reaper-mcp$/,
|
|
10903
|
+
"Effects/reaper-mcp-generated": /^examples$/,
|
|
10904
|
+
presets: /^js-reaper-mcp-generated_examples_/
|
|
10905
|
+
};
|
|
10906
|
+
function link(target, path, isDir) {
|
|
10907
|
+
try {
|
|
10908
|
+
symlinkSync(target, path, isDir ? platform5() === "win32" ? "junction" : "dir" : "file");
|
|
10909
|
+
} catch (err) {
|
|
10910
|
+
if (isDir) throw err;
|
|
10911
|
+
copyFileSync4(target, path);
|
|
10912
|
+
}
|
|
10913
|
+
}
|
|
10914
|
+
function linkSplit(main, instance, rel, linked) {
|
|
10915
|
+
const src = join14(main, rel);
|
|
10916
|
+
if (!existsSync9(src) || !statSync2(src).isDirectory()) return;
|
|
10917
|
+
const dest = join14(instance, rel);
|
|
10918
|
+
mkdirSync8(dest, { recursive: true });
|
|
10919
|
+
for (const entry of readdirSync2(src)) {
|
|
10920
|
+
const entryRel = `${rel}/${entry}`;
|
|
10921
|
+
if (SPLIT_DIRS[rel].test(entry)) continue;
|
|
10922
|
+
if (entryRel in SPLIT_DIRS) {
|
|
10923
|
+
linkSplit(main, instance, entryRel, linked);
|
|
10924
|
+
continue;
|
|
10925
|
+
}
|
|
10926
|
+
if (existsSync9(join14(dest, entry))) continue;
|
|
10927
|
+
link(join14(src, entry), join14(dest, entry), statSync2(join14(src, entry)).isDirectory());
|
|
10928
|
+
linked.push(entryRel);
|
|
10929
|
+
}
|
|
10930
|
+
}
|
|
10931
|
+
function linkShared(mainResource, instanceResource) {
|
|
10932
|
+
const linked = [];
|
|
10933
|
+
if (!existsSync9(mainResource)) return linked;
|
|
10934
|
+
for (const entry of readdirSync2(mainResource)) {
|
|
10935
|
+
if (SHARED_FILES.some((re) => re.test(entry)) || SHARED_DIRS.includes(entry)) {
|
|
10936
|
+
const dest = join14(instanceResource, entry);
|
|
10937
|
+
if (existsSync9(dest)) continue;
|
|
10938
|
+
link(join14(mainResource, entry), dest, SHARED_DIRS.includes(entry));
|
|
10939
|
+
linked.push(entry);
|
|
10940
|
+
}
|
|
10941
|
+
}
|
|
10942
|
+
for (const top of ["Effects", "presets"]) linkSplit(mainResource, instanceResource, top, linked);
|
|
10943
|
+
return linked;
|
|
10944
|
+
}
|
|
10945
|
+
function seedReaPack(mainResource, instanceResource) {
|
|
10946
|
+
const src = join14(mainResource, "reapack.ini");
|
|
10947
|
+
const dest = join14(instanceResource, "reapack.ini");
|
|
10948
|
+
if (!existsSync9(src) || existsSync9(dest)) return false;
|
|
10949
|
+
copyFileSync4(src, dest);
|
|
10950
|
+
return true;
|
|
10951
|
+
}
|
|
10952
|
+
function nextFreePort(used, from = DEFAULT_WEB_PORT + 1) {
|
|
10953
|
+
let port = from;
|
|
10954
|
+
while (used.includes(port)) port++;
|
|
10955
|
+
return port;
|
|
10956
|
+
}
|
|
10957
|
+
function listInstances(root = instancesRoot()) {
|
|
10958
|
+
if (!existsSync9(root)) return [];
|
|
10959
|
+
const out2 = [];
|
|
10960
|
+
for (const name of readdirSync2(root).sort()) {
|
|
10961
|
+
const info = readInstance(name, root);
|
|
10962
|
+
if (info) out2.push(info);
|
|
10963
|
+
}
|
|
10964
|
+
return out2;
|
|
10965
|
+
}
|
|
10966
|
+
function readInstance(name, root = instancesRoot()) {
|
|
10967
|
+
try {
|
|
10968
|
+
return JSON.parse(readFileSync7(infoPath(name, root), "utf-8"));
|
|
10969
|
+
} catch {
|
|
10970
|
+
return null;
|
|
10971
|
+
}
|
|
10972
|
+
}
|
|
10973
|
+
function createInstanceFiles(options) {
|
|
10974
|
+
const name = validateInstanceName(options.name);
|
|
10975
|
+
const root = options.root ?? instancesRoot();
|
|
10976
|
+
if (readInstance(name, root)) throw new Error(`Instance "${name}" exists already (reaper-mcp instance remove ${name} first, or pick another name)`);
|
|
10977
|
+
const mainIni = join14(options.mainResource, "reaper.ini");
|
|
10978
|
+
if (!existsSync9(mainIni)) throw new Error(`${mainIni} not found: start REAPER once, quit it, then create the instance (or set REAPER_RESOURCE_PATH to REAPER's resource folder)`);
|
|
10979
|
+
const taken = listInstances(root).map((i) => i.port);
|
|
10980
|
+
const port = options.port ?? nextFreePort([...taken, Number(process.env["REAPER_WEB_PORT"]) || DEFAULT_WEB_PORT]);
|
|
10981
|
+
if (taken.includes(port)) throw new Error(`Port ${port} is used by another instance (reaper-mcp instance list)`);
|
|
10982
|
+
const resourcePath = join14(instanceDir(name, root), "REAPER");
|
|
10983
|
+
mkdirSync8(join14(resourcePath, "Scripts"), { recursive: true });
|
|
10984
|
+
writeFileSync7(join14(resourcePath, "reaper.ini"), iniForInstance(readFileSync7(mainIni, "utf-8"), port), "utf-8");
|
|
10985
|
+
linkShared(options.mainResource, resourcePath);
|
|
10986
|
+
seedReaPack(options.mainResource, resourcePath);
|
|
10987
|
+
const info = {
|
|
10988
|
+
name,
|
|
10989
|
+
resourcePath,
|
|
10990
|
+
port,
|
|
10991
|
+
app: null,
|
|
10992
|
+
bundleId: null,
|
|
10993
|
+
appSourceMtimeMs: null,
|
|
10994
|
+
visible: options.visible ?? false,
|
|
10995
|
+
created: (/* @__PURE__ */ new Date()).toISOString()
|
|
10996
|
+
};
|
|
10997
|
+
saveInstance(info, root);
|
|
10998
|
+
return info;
|
|
10999
|
+
}
|
|
11000
|
+
function saveInstance(info, root = instancesRoot()) {
|
|
11001
|
+
writeFileSync7(infoPath(info.name, root), JSON.stringify(info, null, 2) + "\n", "utf-8");
|
|
11002
|
+
}
|
|
11003
|
+
function removeInstance(name, root = instancesRoot()) {
|
|
11004
|
+
validateInstanceName(name);
|
|
11005
|
+
if (!readInstance(name, root)) return false;
|
|
11006
|
+
rmSync2(instanceDir(name, root), { recursive: true, force: true });
|
|
11007
|
+
return true;
|
|
11008
|
+
}
|
|
11009
|
+
function launchCommand(info, project, os, reaperExe) {
|
|
11010
|
+
const reaperArgs = ["-newinst", "-nosplash", "-cfgfile", join14(info.resourcePath, "reaper.ini"), ...project ? [project] : []];
|
|
11011
|
+
if (os === "darwin" && info.app) return { bin: "open", args: ["-n", "-g", "-a", info.app, "--args", ...reaperArgs], detached: false };
|
|
11012
|
+
return { bin: reaperExe, args: reaperArgs, detached: true };
|
|
11013
|
+
}
|
|
11014
|
+
function bridgeAlive(resourcePath, now = Date.now()) {
|
|
11015
|
+
try {
|
|
11016
|
+
const ts = JSON.parse(readFileSync7(join14(resourcePath, "Scripts", "mcp_bridge_data", "heartbeat.json"), "utf-8")).timestamp;
|
|
11017
|
+
return typeof ts === "number" && Math.abs(now - ts) < 5e3;
|
|
11018
|
+
} catch {
|
|
11019
|
+
return false;
|
|
11020
|
+
}
|
|
11021
|
+
}
|
|
11022
|
+
function serverSpecFor(info) {
|
|
11023
|
+
return {
|
|
11024
|
+
name: `reaper-${info.name}`,
|
|
11025
|
+
env: { REAPER_RESOURCE_PATH: info.resourcePath, REAPER_WEB_PORT: String(info.port), REAPER_MCP_INSTANCE: info.name }
|
|
11026
|
+
};
|
|
11027
|
+
}
|
|
11028
|
+
function buildAppCopy(source, dest, bundleId, visible2, run5) {
|
|
11029
|
+
rmSync2(dest, { recursive: true, force: true });
|
|
11030
|
+
mkdirSync8(join14(dest, ".."), { recursive: true });
|
|
11031
|
+
run5("ditto", [source, dest]);
|
|
11032
|
+
const plist = join14(dest, "Contents", "Info.plist");
|
|
11033
|
+
const buddy = "/usr/libexec/PlistBuddy";
|
|
11034
|
+
run5(buddy, ["-c", `Set :CFBundleIdentifier ${bundleId}`, plist]);
|
|
11035
|
+
if (!visible2) {
|
|
11036
|
+
try {
|
|
11037
|
+
run5(buddy, ["-c", "Set :LSUIElement true", plist]);
|
|
11038
|
+
} catch {
|
|
11039
|
+
run5(buddy, ["-c", "Add :LSUIElement bool true", plist]);
|
|
11040
|
+
}
|
|
11041
|
+
}
|
|
11042
|
+
run5("xattr", ["-cr", dest]);
|
|
11043
|
+
run5("codesign", ["--force", "--deep", "--sign", "-", dest]);
|
|
11044
|
+
}
|
|
11045
|
+
function appCopyIsStale(info, sourceMtimeMs) {
|
|
11046
|
+
return Boolean(info.app) && info.appSourceMtimeMs !== sourceMtimeMs;
|
|
11047
|
+
}
|
|
11048
|
+
|
|
11049
|
+
// apps/reaper-mcp-server/src/instance-cli.ts
|
|
11050
|
+
var ui = createUi();
|
|
11051
|
+
function findReaper(os) {
|
|
11052
|
+
const fromEnv = process.env["REAPER_APP"];
|
|
11053
|
+
if (fromEnv) return existsSync10(fromEnv) ? fromEnv : null;
|
|
11054
|
+
const candidates = os === "darwin" ? ["/Applications/REAPER.app", join15(homedir11(), "Applications", "REAPER.app")] : os === "win32" ? ["C:\\Program Files\\REAPER (x64)\\reaper.exe", "C:\\Program Files\\REAPER\\reaper.exe"] : ["/opt/REAPER/reaper", "/usr/local/bin/reaper", "/usr/bin/reaper"];
|
|
11055
|
+
return candidates.find((c) => existsSync10(c)) ?? null;
|
|
11056
|
+
}
|
|
11057
|
+
function realInstanceDeps() {
|
|
11058
|
+
const os = platform6();
|
|
11059
|
+
return {
|
|
11060
|
+
mainResource: getReaperResourcePath(),
|
|
11061
|
+
runSetup: (info) => {
|
|
11062
|
+
const r = spawnSync(process.execPath, [realpathSync(process.argv[1]), "setup", "--no-init"], {
|
|
11063
|
+
env: { ...process.env, REAPER_RESOURCE_PATH: info.resourcePath, REAPER_WEB_PORT: String(info.port), REAPER_MCP_SKIP_SIDECAR_OFFER: "1" },
|
|
11064
|
+
encoding: "utf-8"
|
|
11065
|
+
});
|
|
11066
|
+
if (r.status !== 0) console.error(`${r.stdout ?? ""}${r.stderr ?? ""}`);
|
|
11067
|
+
return r.status === 0;
|
|
11068
|
+
},
|
|
11069
|
+
findReaper: () => findReaper(os),
|
|
11070
|
+
runner: (bin, args) => void execFileSync2(bin, args, { stdio: "pipe" }),
|
|
11071
|
+
launch: (bin, args, detached) => {
|
|
11072
|
+
const child = spawn2(bin, args, { detached, stdio: "ignore" });
|
|
11073
|
+
child.on("error", () => void 0);
|
|
11074
|
+
child.unref();
|
|
11075
|
+
},
|
|
11076
|
+
mtimeMs: (path) => {
|
|
11077
|
+
try {
|
|
11078
|
+
return statSync3(path).mtimeMs;
|
|
11079
|
+
} catch {
|
|
11080
|
+
return null;
|
|
11081
|
+
}
|
|
11082
|
+
},
|
|
11083
|
+
os,
|
|
11084
|
+
log: (line) => console.log(line)
|
|
11085
|
+
};
|
|
11086
|
+
}
|
|
11087
|
+
function flagValue(args, flag) {
|
|
11088
|
+
const i = args.findIndex((a) => a === flag || a.startsWith(`${flag}=`));
|
|
11089
|
+
if (i < 0) return void 0;
|
|
11090
|
+
return args[i].includes("=") ? args[i].split("=")[1] : args[i + 1];
|
|
11091
|
+
}
|
|
11092
|
+
var USAGE = `Usage: reaper-mcp instance <command>
|
|
11093
|
+
|
|
11094
|
+
create <name> [--port N] [--visible] make a second REAPER (own settings, bridge and status page port)
|
|
11095
|
+
start <name> [project.rpp] start it, optionally with a project
|
|
11096
|
+
stop <name> ask it to quit (macOS; elsewhere quit it from its window)
|
|
11097
|
+
connect <name> [--harness claude,...] let your agent use it as the "reaper-<name>" server
|
|
11098
|
+
list the instances, their port and whether their bridge answers
|
|
11099
|
+
remove <name> delete an instance's folder (it must not be running)`;
|
|
11100
|
+
async function instanceCommand(args, deps = realInstanceDeps()) {
|
|
11101
|
+
const [sub, ...rest] = args;
|
|
11102
|
+
const say = deps.log;
|
|
11103
|
+
try {
|
|
11104
|
+
switch (sub) {
|
|
11105
|
+
case "create":
|
|
11106
|
+
return create(rest, deps);
|
|
11107
|
+
case "start":
|
|
11108
|
+
return start(rest, deps);
|
|
11109
|
+
case "stop":
|
|
11110
|
+
return stop(rest, deps);
|
|
11111
|
+
case "connect":
|
|
11112
|
+
return connect(rest, deps);
|
|
11113
|
+
case "list":
|
|
11114
|
+
return list2(deps);
|
|
11115
|
+
case "remove":
|
|
11116
|
+
return remove(rest, deps);
|
|
11117
|
+
default:
|
|
11118
|
+
say(USAGE);
|
|
11119
|
+
return sub === void 0 || sub === "--help" || sub === "help" ? 0 : 1;
|
|
11120
|
+
}
|
|
11121
|
+
} catch (err) {
|
|
11122
|
+
console.error(`${ui.mark("fail")} ${err.message}`);
|
|
11123
|
+
return 1;
|
|
11124
|
+
}
|
|
11125
|
+
}
|
|
11126
|
+
function need(name) {
|
|
11127
|
+
const valid = validateInstanceName(name);
|
|
11128
|
+
const info = readInstance(valid);
|
|
11129
|
+
if (!info) throw new Error(`No instance "${valid}" (reaper-mcp instance list)`);
|
|
11130
|
+
return info;
|
|
11131
|
+
}
|
|
11132
|
+
function create(args, deps) {
|
|
11133
|
+
const name = args.find((a) => !a.startsWith("-") && a !== flagValue(args, "--port"));
|
|
11134
|
+
const portText = flagValue(args, "--port");
|
|
11135
|
+
const port = portText === void 0 ? void 0 : Number(portText);
|
|
11136
|
+
if (port !== void 0 && (!Number.isInteger(port) || port < 1024 || port > 65535)) throw new Error(`--port needs a number from 1024 to 65535 (got ${portText})`);
|
|
11137
|
+
const visible2 = args.includes("--visible");
|
|
11138
|
+
const reaper = deps.findReaper();
|
|
11139
|
+
if (!reaper) throw new Error("Could not find REAPER (set REAPER_APP to REAPER.app on macOS, or to the reaper executable)");
|
|
11140
|
+
const info = createInstanceFiles({ name: validateInstanceName(name), port, visible: visible2, mainResource: deps.mainResource });
|
|
11141
|
+
deps.log(`${ui.mark("ok")} Made ${ui.bold(info.name)}: ${ui.dim(info.resourcePath)}`);
|
|
11142
|
+
try {
|
|
11143
|
+
if (deps.os === "darwin") {
|
|
11144
|
+
const bundleId = `com.cockos.reaper.mcp-${info.name}`;
|
|
11145
|
+
const app = join15(info.resourcePath, "..", "REAPER.app");
|
|
11146
|
+
deps.log(ui.dim(" Copying REAPER.app (about 160 MB) so this instance has its own identity\u2026"));
|
|
11147
|
+
buildAppCopy(reaper, app, bundleId, visible2, deps.runner);
|
|
11148
|
+
Object.assign(info, { app, bundleId, appSourceMtimeMs: deps.mtimeMs(join15(reaper, "Contents", "MacOS", "REAPER")) });
|
|
11149
|
+
saveInstance(info);
|
|
11150
|
+
}
|
|
11151
|
+
if (!deps.runSetup(info)) throw new Error("Installing the bridge into the instance failed (output above)");
|
|
11152
|
+
} catch (err) {
|
|
11153
|
+
removeInstance(info.name);
|
|
11154
|
+
throw err;
|
|
11155
|
+
}
|
|
11156
|
+
deps.log(`${ui.mark("ok")} Bridge installed. Status page: ${ui.link(`http://localhost:${info.port}/mcp_bridge.html`)}`);
|
|
11157
|
+
deps.log(`
|
|
11158
|
+
Next: ${ui.cmd(`reaper-mcp instance connect ${info.name}`)}, then ${ui.cmd(`reaper-mcp instance start ${info.name} <project.rpp>`)}`);
|
|
11159
|
+
return 0;
|
|
11160
|
+
}
|
|
11161
|
+
function start(args, deps) {
|
|
11162
|
+
const info = need(args[0]);
|
|
11163
|
+
const reaper = deps.findReaper();
|
|
11164
|
+
if (!reaper) throw new Error("Could not find REAPER (set REAPER_APP)");
|
|
11165
|
+
if (bridgeAlive(info.resourcePath)) {
|
|
11166
|
+
deps.log(`${ui.mark("info")} ${info.name} is running already.`);
|
|
11167
|
+
return 0;
|
|
11168
|
+
}
|
|
11169
|
+
if (deps.os === "darwin" && info.app) {
|
|
11170
|
+
const source = deps.mtimeMs(join15(reaper, "Contents", "MacOS", "REAPER"));
|
|
11171
|
+
if (!existsSync10(info.app) || appCopyIsStale(info, source)) {
|
|
11172
|
+
deps.log(ui.dim(" REAPER was updated: refreshing this instance's copy of it\u2026"));
|
|
11173
|
+
buildAppCopy(reaper, info.app, info.bundleId ?? `com.cockos.reaper.mcp-${info.name}`, info.visible, deps.runner);
|
|
11174
|
+
saveInstance({ ...info, appSourceMtimeMs: source });
|
|
11175
|
+
}
|
|
11176
|
+
}
|
|
11177
|
+
const project = args[1];
|
|
11178
|
+
if (project && !existsSync10(project)) throw new Error(`Project not found: ${project}`);
|
|
11179
|
+
const cmd = launchCommand(info, project ? realpathSync(project) : void 0, deps.os, reaper);
|
|
11180
|
+
deps.launch(cmd.bin, cmd.args, cmd.detached);
|
|
11181
|
+
deps.log(`${ui.mark("ok")} Starting ${ui.bold(info.name)}${project ? ` with ${project}` : ""}. Its bridge comes up with REAPER: ${ui.link(`http://localhost:${info.port}/mcp_bridge.html`)}`);
|
|
11182
|
+
return 0;
|
|
11183
|
+
}
|
|
11184
|
+
function stop(args, deps) {
|
|
11185
|
+
const info = need(args[0]);
|
|
11186
|
+
if (deps.os === "darwin" && info.bundleId) {
|
|
11187
|
+
deps.runner("osascript", ["-e", `tell application id "${info.bundleId}" to quit`]);
|
|
11188
|
+
deps.log(`${ui.mark("ok")} Asked ${ui.bold(info.name)} to quit. If it holds unsaved changes it waits for you to answer.`);
|
|
11189
|
+
return 0;
|
|
11190
|
+
}
|
|
11191
|
+
deps.log(`${ui.mark("info")} Quit ${info.name} from its own window (REAPER asks about unsaved changes there).`);
|
|
11192
|
+
return 0;
|
|
11193
|
+
}
|
|
11194
|
+
function connect(args, deps) {
|
|
11195
|
+
const info = need(args.find((a) => !a.startsWith("-")));
|
|
11196
|
+
const env = realEnv();
|
|
11197
|
+
const ids = parseHarnessFlag(["", "", ...args]) ?? detectHarnesses(env).map((h) => h.id);
|
|
11198
|
+
if (ids.length === 0) throw new Error("No supported harness found (install Claude Code, Codex CLI, Gemini CLI or Cursor, or pass --harness)");
|
|
11199
|
+
const server = serverSpecFor(info);
|
|
11200
|
+
const mainJs = realpathSync(process.argv[1]);
|
|
11201
|
+
let failed = false;
|
|
11202
|
+
for (const id of ids) {
|
|
11203
|
+
const h = HARNESSES.find((x) => x.id === id);
|
|
11204
|
+
const r = connectHarness(id, process.execPath, mainJs, env, void 0, server);
|
|
11205
|
+
if (r.status === "failed") {
|
|
11206
|
+
failed = true;
|
|
11207
|
+
deps.log(`${ui.mark("fail")} Could not connect ${h?.name ?? id}: ${r.detail}
|
|
11208
|
+
${ui.dim("To connect it yourself:")} ${ui.cmd(r.manual ?? "")}`);
|
|
11209
|
+
} else {
|
|
11210
|
+
deps.log(`${ui.mark("ok")} ${h?.name ?? id}: ${r.status === "already" ? "already has" : "now has"} the "${server.name}" server`);
|
|
11211
|
+
}
|
|
11212
|
+
}
|
|
11213
|
+
if (!failed) deps.log(ui.dim(` Restart the agent, then tell it which REAPER to use: "${server.name}" is the background one, "reaper" is yours.`));
|
|
11214
|
+
return failed ? 1 : 0;
|
|
11215
|
+
}
|
|
11216
|
+
function list2(deps) {
|
|
11217
|
+
const all = listInstances();
|
|
11218
|
+
if (all.length === 0) {
|
|
11219
|
+
deps.log(`No instances yet (they live in ${instancesRoot()}). Make one: ${ui.cmd("reaper-mcp instance create background")}`);
|
|
11220
|
+
return 0;
|
|
11221
|
+
}
|
|
11222
|
+
for (const i of all) {
|
|
11223
|
+
const state = bridgeAlive(i.resourcePath) ? ui.mark("ok") + " bridge answers" : ui.mark("info") + " not running";
|
|
11224
|
+
deps.log(`${ui.bold(i.name.padEnd(16))} port ${i.port} ${state} ${ui.dim(i.visible ? "visible" : "background")}`);
|
|
11225
|
+
}
|
|
11226
|
+
return 0;
|
|
11227
|
+
}
|
|
11228
|
+
function remove(args, deps) {
|
|
11229
|
+
const info = need(args[0]);
|
|
11230
|
+
if (bridgeAlive(info.resourcePath)) throw new Error(`${info.name} is running: stop it first (reaper-mcp instance stop ${info.name})`);
|
|
11231
|
+
removeInstance(info.name);
|
|
11232
|
+
deps.log(`${ui.mark("ok")} Removed ${info.name}. Projects you saved are wherever you saved them; only the instance's settings and bridge went.`);
|
|
11233
|
+
return 0;
|
|
11234
|
+
}
|
|
11235
|
+
|
|
10643
11236
|
// apps/reaper-mcp-server/src/flags.ts
|
|
10644
|
-
import { mkdirSync as
|
|
10645
|
-
import { homedir as
|
|
10646
|
-
import { join as
|
|
11237
|
+
import { mkdirSync as mkdirSync9, readFileSync as readFileSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
11238
|
+
import { homedir as homedir12 } from "node:os";
|
|
11239
|
+
import { join as join16 } from "node:path";
|
|
10647
11240
|
|
|
10648
11241
|
// libs/feature-flags/src/bucketing.ts
|
|
10649
11242
|
function fnv1aHash(input) {
|
|
@@ -10902,10 +11495,10 @@ async function evaluateDefinition(client, def, context = {}) {
|
|
|
10902
11495
|
// apps/reaper-mcp-server/src/flags.ts
|
|
10903
11496
|
var FLAGS_FILE = "flags.json";
|
|
10904
11497
|
var FLAGS_ENV = "REAPER_MCP_FLAGS";
|
|
10905
|
-
function defaultFlagsDir(env = process.env,
|
|
10906
|
-
if (env.XDG_CONFIG_HOME) return
|
|
10907
|
-
if (
|
|
10908
|
-
return
|
|
11498
|
+
function defaultFlagsDir(env = process.env, platform9 = process.platform) {
|
|
11499
|
+
if (env.XDG_CONFIG_HOME) return join16(env.XDG_CONFIG_HOME, "reaper-mcp");
|
|
11500
|
+
if (platform9 === "win32" && env.APPDATA) return join16(env.APPDATA, "reaper-mcp");
|
|
11501
|
+
return join16(homedir12(), ".config", "reaper-mcp");
|
|
10909
11502
|
}
|
|
10910
11503
|
function parseJson(raw) {
|
|
10911
11504
|
try {
|
|
@@ -10917,7 +11510,7 @@ function parseJson(raw) {
|
|
|
10917
11510
|
function readFlagOverrides(dir = defaultFlagsDir(), env = process.env, registry = FLAG_REGISTRY) {
|
|
10918
11511
|
let fromFile;
|
|
10919
11512
|
try {
|
|
10920
|
-
fromFile = parseJson(
|
|
11513
|
+
fromFile = parseJson(readFileSync8(join16(dir, FLAGS_FILE), "utf-8"));
|
|
10921
11514
|
} catch {
|
|
10922
11515
|
fromFile = void 0;
|
|
10923
11516
|
}
|
|
@@ -10925,8 +11518,8 @@ function readFlagOverrides(dir = defaultFlagsDir(), env = process.env, registry
|
|
|
10925
11518
|
return { ...sanitizeFlagOverrides(fromFile, registry), ...sanitizeFlagOverrides(fromEnv, registry) };
|
|
10926
11519
|
}
|
|
10927
11520
|
function writeFlagOverrides(overrides, dir = defaultFlagsDir()) {
|
|
10928
|
-
|
|
10929
|
-
|
|
11521
|
+
mkdirSync9(dir, { recursive: true });
|
|
11522
|
+
writeFileSync8(join16(dir, FLAGS_FILE), JSON.stringify(overrides, null, 2) + "\n", "utf-8");
|
|
10930
11523
|
}
|
|
10931
11524
|
function createServerFlags(options = {}) {
|
|
10932
11525
|
const registry = options.registry ?? FLAG_REGISTRY;
|
|
@@ -10978,7 +11571,7 @@ function flagOverrideCheck(options = {}) {
|
|
|
10978
11571
|
};
|
|
10979
11572
|
}
|
|
10980
11573
|
var defaultFlags = createServerFlags();
|
|
10981
|
-
var
|
|
11574
|
+
var USAGE2 = [
|
|
10982
11575
|
"Usage:",
|
|
10983
11576
|
" reaper-mcp flags list Every flag, how it resolves for this install, and why",
|
|
10984
11577
|
" reaper-mcp flags set <key> <variant> Force a variant on this install only",
|
|
@@ -11005,7 +11598,7 @@ function flagsCommand(args, options = {}) {
|
|
|
11005
11598
|
}
|
|
11006
11599
|
if (sub === "set") {
|
|
11007
11600
|
if (!key || !variant) {
|
|
11008
|
-
io.error(
|
|
11601
|
+
io.error(USAGE2.join("\n"));
|
|
11009
11602
|
return 1;
|
|
11010
11603
|
}
|
|
11011
11604
|
const def = registry.find((f) => f.key === key);
|
|
@@ -11035,22 +11628,22 @@ function flagsCommand(args, options = {}) {
|
|
|
11035
11628
|
}
|
|
11036
11629
|
return 0;
|
|
11037
11630
|
}
|
|
11038
|
-
io.error(
|
|
11631
|
+
io.error(USAGE2.join("\n"));
|
|
11039
11632
|
return 1;
|
|
11040
11633
|
}
|
|
11041
11634
|
|
|
11042
11635
|
// apps/reaper-mcp-server/src/main.ts
|
|
11043
|
-
import { existsSync as
|
|
11044
|
-
import { join as
|
|
11636
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync14, readFileSync as readFileSync16, realpathSync as realpathSync3, rmSync as rmSync5, writeFileSync as writeFileSync13 } from "node:fs";
|
|
11637
|
+
import { join as join23, dirname as dirname13, resolve as resolve3 } from "node:path";
|
|
11045
11638
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
11046
|
-
import { homedir as
|
|
11047
|
-
import { exec as execCb, spawn as
|
|
11639
|
+
import { homedir as homedir14, platform as platform8 } from "node:os";
|
|
11640
|
+
import { exec as execCb, spawn as spawn4 } from "node:child_process";
|
|
11048
11641
|
import { promisify as promisifyUtil } from "node:util";
|
|
11049
11642
|
|
|
11050
11643
|
// apps/reaper-mcp-server/src/update.ts
|
|
11051
|
-
import { spawn as
|
|
11052
|
-
import { dirname as dirname10, join as
|
|
11053
|
-
import { existsSync as
|
|
11644
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
11645
|
+
import { dirname as dirname10, join as join18 } from "node:path";
|
|
11646
|
+
import { existsSync as existsSync11, readFileSync as readFileSync10 } from "node:fs";
|
|
11054
11647
|
|
|
11055
11648
|
// apps/reaper-mcp-server/src/version.ts
|
|
11056
11649
|
function compareVersions(a, b) {
|
|
@@ -11064,14 +11657,14 @@ function compareVersions(a, b) {
|
|
|
11064
11657
|
}
|
|
11065
11658
|
|
|
11066
11659
|
// apps/reaper-mcp-server/src/update-check.ts
|
|
11067
|
-
import { mkdirSync as
|
|
11068
|
-
import { dirname as
|
|
11069
|
-
import { homedir as
|
|
11660
|
+
import { mkdirSync as mkdirSync10, readFileSync as readFileSync9, rmSync as rmSync3, writeFileSync as writeFileSync9 } from "node:fs";
|
|
11661
|
+
import { dirname as dirname9, join as join17 } from "node:path";
|
|
11662
|
+
import { homedir as homedir13 } from "node:os";
|
|
11070
11663
|
var NPM_PACKAGE = "@mthines/reaper-mcp";
|
|
11071
11664
|
var PACKAGE_URL = "https://registry.npmjs.org/@mthines%2Freaper-mcp";
|
|
11072
11665
|
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
11073
11666
|
function defaultUpdateStatePath() {
|
|
11074
|
-
return
|
|
11667
|
+
return join17(homedir13(), ".reaper-mcp", "update-check.json");
|
|
11075
11668
|
}
|
|
11076
11669
|
function updateCheckDisabled(env = process.env) {
|
|
11077
11670
|
const setting = (env["REAPER_MCP_UPDATE_CHECK"] ?? "").trim().toLowerCase();
|
|
@@ -11096,7 +11689,7 @@ function updateNotice(current, latest) {
|
|
|
11096
11689
|
}
|
|
11097
11690
|
function readState(path) {
|
|
11098
11691
|
try {
|
|
11099
|
-
const s = JSON.parse(
|
|
11692
|
+
const s = JSON.parse(readFileSync9(path, "utf-8"));
|
|
11100
11693
|
return s && typeof s === "object" ? s : {};
|
|
11101
11694
|
} catch {
|
|
11102
11695
|
return {};
|
|
@@ -11104,8 +11697,8 @@ function readState(path) {
|
|
|
11104
11697
|
}
|
|
11105
11698
|
function writeState(path, state) {
|
|
11106
11699
|
try {
|
|
11107
|
-
|
|
11108
|
-
|
|
11700
|
+
mkdirSync10(dirname9(path), { recursive: true });
|
|
11701
|
+
writeFileSync9(path, JSON.stringify(state) + "\n", "utf-8");
|
|
11109
11702
|
} catch {
|
|
11110
11703
|
}
|
|
11111
11704
|
}
|
|
@@ -11132,172 +11725,30 @@ function cachedUpdateAvailable(current, statePath = defaultUpdateStatePath()) {
|
|
|
11132
11725
|
return compareVersions(latest, current) > 0;
|
|
11133
11726
|
}
|
|
11134
11727
|
function defaultUpdateMarkerPath() {
|
|
11135
|
-
return
|
|
11728
|
+
return join17(homedir13(), ".reaper-mcp", "last-update.json");
|
|
11136
11729
|
}
|
|
11137
11730
|
function writeUpdateMarker(path, marker) {
|
|
11138
11731
|
try {
|
|
11139
|
-
|
|
11140
|
-
|
|
11732
|
+
mkdirSync10(dirname9(path), { recursive: true });
|
|
11733
|
+
writeFileSync9(path, JSON.stringify(marker) + "\n", "utf-8");
|
|
11141
11734
|
} catch {
|
|
11142
11735
|
}
|
|
11143
11736
|
}
|
|
11144
11737
|
function takeUpdateMarker(path, current) {
|
|
11145
11738
|
let marker;
|
|
11146
11739
|
try {
|
|
11147
|
-
marker = JSON.parse(
|
|
11740
|
+
marker = JSON.parse(readFileSync9(path, "utf-8"));
|
|
11148
11741
|
} catch {
|
|
11149
11742
|
return void 0;
|
|
11150
11743
|
}
|
|
11151
11744
|
if (marker?.to !== current) return void 0;
|
|
11152
11745
|
try {
|
|
11153
|
-
|
|
11746
|
+
rmSync3(path, { force: true });
|
|
11154
11747
|
} catch {
|
|
11155
11748
|
}
|
|
11156
11749
|
return marker.via === "bridge_page" || marker.via === "cli" ? marker.via : void 0;
|
|
11157
11750
|
}
|
|
11158
11751
|
|
|
11159
|
-
// apps/reaper-mcp-server/src/harnesses.ts
|
|
11160
|
-
import { execFileSync } from "node:child_process";
|
|
11161
|
-
import { existsSync as existsSync8, mkdirSync as mkdirSync9, readFileSync as readFileSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
11162
|
-
import { delimiter, dirname as dirname9, isAbsolute as isAbsolute3, join as join15 } from "node:path";
|
|
11163
|
-
import { homedir as homedir11, platform as platform4 } from "node:os";
|
|
11164
|
-
var HARNESSES = [
|
|
11165
|
-
{ id: "claude", name: "Claude Code", binary: "claude", installHint: "https://claude.com/claude-code", skillsHome: "claude" },
|
|
11166
|
-
{ id: "codex", name: "Codex CLI", binary: "codex", installHint: "npm install -g @openai/codex (or: brew install codex)", skillsHome: "agents" },
|
|
11167
|
-
{ id: "gemini", name: "Gemini CLI", binary: "gemini", installHint: "npm install -g @google/gemini-cli", skillsHome: "agents" },
|
|
11168
|
-
{ id: "cursor", name: "Cursor", binary: null, installHint: "https://cursor.com", skillsHome: "agents" }
|
|
11169
|
-
];
|
|
11170
|
-
var SERVER_NAME = "reaper";
|
|
11171
|
-
function onPath(name, pathVar = process.env.PATH ?? "", win = platform4() === "win32") {
|
|
11172
|
-
const exts = win ? ["", ".exe", ".cmd", ".bat"] : [""];
|
|
11173
|
-
return pathVar.split(delimiter).filter(Boolean).some((dir) => exts.some((ext) => existsSync8(join15(dir, name + ext))));
|
|
11174
|
-
}
|
|
11175
|
-
function realEnv() {
|
|
11176
|
-
return { home: homedir11(), codexHome: process.env.CODEX_HOME || void 0, hasBinary: (name) => onPath(name) };
|
|
11177
|
-
}
|
|
11178
|
-
var configPath = (id, env) => ({
|
|
11179
|
-
claude: join15(env.home, ".claude.json"),
|
|
11180
|
-
codex: join15(env.codexHome ?? join15(env.home, ".codex"), "config.toml"),
|
|
11181
|
-
gemini: join15(env.home, ".gemini", "settings.json"),
|
|
11182
|
-
cursor: join15(env.home, ".cursor", "mcp.json")
|
|
11183
|
-
})[id];
|
|
11184
|
-
function detectHarnesses(env = realEnv()) {
|
|
11185
|
-
return HARNESSES.filter((h) => h.binary ? env.hasBinary(h.binary) : existsSync8(join15(env.home, ".cursor")));
|
|
11186
|
-
}
|
|
11187
|
-
function registeredServer(id, env = realEnv()) {
|
|
11188
|
-
let text9;
|
|
11189
|
-
try {
|
|
11190
|
-
text9 = readFileSync8(configPath(id, env), "utf-8");
|
|
11191
|
-
} catch {
|
|
11192
|
-
return null;
|
|
11193
|
-
}
|
|
11194
|
-
if (id === "codex") return codexServer(text9);
|
|
11195
|
-
try {
|
|
11196
|
-
const server = JSON.parse(text9)?.mcpServers?.[SERVER_NAME];
|
|
11197
|
-
if (!server || typeof server.command !== "string") return null;
|
|
11198
|
-
return { command: server.command, args: Array.isArray(server.args) ? server.args.filter((a) => typeof a === "string") : [] };
|
|
11199
|
-
} catch {
|
|
11200
|
-
return null;
|
|
11201
|
-
}
|
|
11202
|
-
}
|
|
11203
|
-
function codexServer(toml) {
|
|
11204
|
-
const header = new RegExp(`^\\[mcp_servers\\.(?:${SERVER_NAME}|"${SERVER_NAME}")\\]\\s*$`, "m").exec(toml);
|
|
11205
|
-
if (!header) return null;
|
|
11206
|
-
const rest = toml.slice(header.index + header[0].length);
|
|
11207
|
-
const next = /^\[/m.exec(rest);
|
|
11208
|
-
const section = next ? rest.slice(0, next.index) : rest;
|
|
11209
|
-
const command2 = /^command\s*=\s*("(?:[^"\\]|\\.)*"|'[^']*')/m.exec(section)?.[1];
|
|
11210
|
-
if (!command2) return null;
|
|
11211
|
-
const args = /^args\s*=\s*\[([^\]]*)\]/m.exec(section)?.[1] ?? "";
|
|
11212
|
-
const strings = (s) => [...s.matchAll(/"((?:[^"\\]|\\.)*)"|'([^']*)'/g)].map((m) => m[1] !== void 0 ? JSON.parse(`"${m[1]}"`) : m[2]);
|
|
11213
|
-
return { command: strings(command2)[0], args: strings(args) };
|
|
11214
|
-
}
|
|
11215
|
-
function isStale(server) {
|
|
11216
|
-
return [server.command, ...server.args].filter(isAbsolute3).some((p) => !existsSync8(p));
|
|
11217
|
-
}
|
|
11218
|
-
function addCommand(id, node, mainJs) {
|
|
11219
|
-
switch (id) {
|
|
11220
|
-
case "claude":
|
|
11221
|
-
return { bin: "claude", args: ["mcp", "add", "--scope", "user", SERVER_NAME, "--", node, mainJs, "serve"] };
|
|
11222
|
-
case "codex":
|
|
11223
|
-
return { bin: "codex", args: ["mcp", "add", SERVER_NAME, "--", node, mainJs, "serve"] };
|
|
11224
|
-
case "gemini":
|
|
11225
|
-
return { bin: "gemini", args: ["mcp", "add", "--scope", "user", SERVER_NAME, node, mainJs, "serve"] };
|
|
11226
|
-
case "cursor":
|
|
11227
|
-
return null;
|
|
11228
|
-
}
|
|
11229
|
-
}
|
|
11230
|
-
function removeCommand(id) {
|
|
11231
|
-
switch (id) {
|
|
11232
|
-
case "claude":
|
|
11233
|
-
return { bin: "claude", args: ["mcp", "remove", "--scope", "user", SERVER_NAME] };
|
|
11234
|
-
case "codex":
|
|
11235
|
-
return { bin: "codex", args: ["mcp", "remove", SERVER_NAME] };
|
|
11236
|
-
case "gemini":
|
|
11237
|
-
return { bin: "gemini", args: ["mcp", "remove", "--scope", "user", SERVER_NAME] };
|
|
11238
|
-
case "cursor":
|
|
11239
|
-
return null;
|
|
11240
|
-
}
|
|
11241
|
-
}
|
|
11242
|
-
function manualCommand(id, node, mainJs, env = realEnv()) {
|
|
11243
|
-
const add2 = addCommand(id, node, mainJs);
|
|
11244
|
-
if (add2) return [add2.bin, ...add2.args].join(" ");
|
|
11245
|
-
return `add "${SERVER_NAME}": { "command": "${node}", "args": ["${mainJs}", "serve"] } under "mcpServers" in ${configPath(id, env)}`;
|
|
11246
|
-
}
|
|
11247
|
-
function quoteForCmd(arg) {
|
|
11248
|
-
return /[\s"]/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg;
|
|
11249
|
-
}
|
|
11250
|
-
var realRunner = (bin, args) => {
|
|
11251
|
-
if (platform4() === "win32") execFileSync(quoteForCmd(bin), args.map(quoteForCmd), { stdio: "pipe", shell: true });
|
|
11252
|
-
else execFileSync(bin, args, { stdio: "pipe" });
|
|
11253
|
-
};
|
|
11254
|
-
function writeJsonServer(path, node, mainJs) {
|
|
11255
|
-
let config = {};
|
|
11256
|
-
if (existsSync8(path)) config = JSON.parse(readFileSync8(path, "utf-8"));
|
|
11257
|
-
const servers = config.mcpServers && typeof config.mcpServers === "object" ? config.mcpServers : {};
|
|
11258
|
-
servers[SERVER_NAME] = { command: node, args: [mainJs, "serve"] };
|
|
11259
|
-
config.mcpServers = servers;
|
|
11260
|
-
mkdirSync9(dirname9(path), { recursive: true });
|
|
11261
|
-
writeFileSync8(path, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
11262
|
-
}
|
|
11263
|
-
function connectHarness(id, node, mainJs, env = realEnv(), run5 = realRunner) {
|
|
11264
|
-
const existing = registeredServer(id, env);
|
|
11265
|
-
if (existing && !isStale(existing)) return { id, status: "already" };
|
|
11266
|
-
const manual = manualCommand(id, node, mainJs, env);
|
|
11267
|
-
try {
|
|
11268
|
-
const add2 = addCommand(id, node, mainJs);
|
|
11269
|
-
if (!add2) {
|
|
11270
|
-
writeJsonServer(configPath(id, env), node, mainJs);
|
|
11271
|
-
} else {
|
|
11272
|
-
const remove = removeCommand(id);
|
|
11273
|
-
if (existing && remove) run5(remove.bin, remove.args);
|
|
11274
|
-
run5(add2.bin, add2.args);
|
|
11275
|
-
}
|
|
11276
|
-
} catch (err) {
|
|
11277
|
-
const missing = err.code === "ENOENT";
|
|
11278
|
-
const first = String(err.message).split("\n")[0];
|
|
11279
|
-
return { id, status: "failed", detail: missing ? "its command was not found" : first, manual };
|
|
11280
|
-
}
|
|
11281
|
-
return { id, status: existing ? "replaced" : "connected" };
|
|
11282
|
-
}
|
|
11283
|
-
function parseHarnessFlag(argv) {
|
|
11284
|
-
if (argv.includes("--all")) return HARNESSES.map((h) => h.id);
|
|
11285
|
-
const i = argv.findIndex((a) => a === "--harness" || a.startsWith("--harness="));
|
|
11286
|
-
if (i < 0) return null;
|
|
11287
|
-
const value = argv[i].includes("=") ? argv[i].split("=")[1] : argv[i + 1];
|
|
11288
|
-
const ids = (value ?? "").split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
11289
|
-
const known = HARNESSES.map((h) => h.id);
|
|
11290
|
-
const bad = ids.filter((s) => !known.includes(s));
|
|
11291
|
-
if (!ids.length || bad.length) {
|
|
11292
|
-
throw new Error(`Unknown harness${bad.length > 1 ? "es" : ""}: ${bad.join(", ") || "(none given)"}. Use one or more of: ${known.join(", ")}, or --all.`);
|
|
11293
|
-
}
|
|
11294
|
-
return [...new Set(ids)];
|
|
11295
|
-
}
|
|
11296
|
-
function skillsHomes(ids) {
|
|
11297
|
-
const chosen = HARNESSES.filter((h) => ids.includes(h.id));
|
|
11298
|
-
return { claude: chosen.some((h) => h.skillsHome === "claude"), agents: chosen.some((h) => h.skillsHome === "agents") };
|
|
11299
|
-
}
|
|
11300
|
-
|
|
11301
11752
|
// apps/reaper-mcp-server/src/update.ts
|
|
11302
11753
|
async function runUpdate(deps) {
|
|
11303
11754
|
const { current, log } = deps;
|
|
@@ -11361,13 +11812,13 @@ async function fetchLatestRelease(fetchImpl = fetch, timeoutMs = 3e3) {
|
|
|
11361
11812
|
}
|
|
11362
11813
|
function realUpdateDeps(current, cli, force = false, bridge = false) {
|
|
11363
11814
|
const nodeDir = dirname10(process.execPath);
|
|
11364
|
-
const npmBeside =
|
|
11815
|
+
const npmBeside = join18(nodeDir, process.platform === "win32" ? "npm.cmd" : "npm");
|
|
11365
11816
|
return {
|
|
11366
11817
|
current,
|
|
11367
11818
|
latest: () => fetchLatestVersion(fetch, 1e4),
|
|
11368
11819
|
run: (command2, args) => new Promise((resolve4) => {
|
|
11369
11820
|
const win = process.platform === "win32";
|
|
11370
|
-
const child =
|
|
11821
|
+
const child = spawn3(win ? quoteForCmd(command2) : command2, win ? args.map(quoteForCmd) : args, {
|
|
11371
11822
|
shell: win,
|
|
11372
11823
|
stdio: ["ignore", "inherit", "inherit"],
|
|
11373
11824
|
// The node that runs this first on PATH: npm's own shebang and the child reaper-mcp find it
|
|
@@ -11379,13 +11830,13 @@ function realUpdateDeps(current, cli, force = false, bridge = false) {
|
|
|
11379
11830
|
released: () => fetchLatestRelease(fetch, 1e4),
|
|
11380
11831
|
installed: () => {
|
|
11381
11832
|
try {
|
|
11382
|
-
const version = JSON.parse(
|
|
11833
|
+
const version = JSON.parse(readFileSync10(join18(dirname10(cli), "package.json"), "utf-8")).version;
|
|
11383
11834
|
return typeof version === "string" ? version : void 0;
|
|
11384
11835
|
} catch {
|
|
11385
11836
|
return void 0;
|
|
11386
11837
|
}
|
|
11387
11838
|
},
|
|
11388
|
-
npm:
|
|
11839
|
+
npm: existsSync11(npmBeside) ? npmBeside : "npm",
|
|
11389
11840
|
node: process.execPath,
|
|
11390
11841
|
cli,
|
|
11391
11842
|
log: (line) => console.log(line),
|
|
@@ -11397,14 +11848,14 @@ function realUpdateDeps(current, cli, force = false, bridge = false) {
|
|
|
11397
11848
|
|
|
11398
11849
|
// apps/reaper-mcp-server/src/claude-assets.ts
|
|
11399
11850
|
import { createHash as createHash2 } from "node:crypto";
|
|
11400
|
-
import { existsSync as
|
|
11401
|
-
import { dirname as dirname11, join as
|
|
11851
|
+
import { existsSync as existsSync12, lstatSync, mkdirSync as mkdirSync11, readFileSync as readFileSync11, readdirSync as readdirSync3, writeFileSync as writeFileSync10 } from "node:fs";
|
|
11852
|
+
import { dirname as dirname11, join as join19, relative } from "node:path";
|
|
11402
11853
|
var CLAUDE_MANIFEST = ".reaper-mcp-installed.json";
|
|
11403
11854
|
var sha = (buf) => createHash2("sha256").update(buf).digest("hex");
|
|
11404
11855
|
function listFiles(dir) {
|
|
11405
11856
|
const out2 = [];
|
|
11406
|
-
for (const entry of
|
|
11407
|
-
const p =
|
|
11857
|
+
for (const entry of readdirSync3(dir, { withFileTypes: true })) {
|
|
11858
|
+
const p = join19(dir, entry.name);
|
|
11408
11859
|
if (entry.isDirectory()) out2.push(...listFiles(p));
|
|
11409
11860
|
else if (entry.isFile()) out2.push(p);
|
|
11410
11861
|
}
|
|
@@ -11419,7 +11870,7 @@ function isSymlink(path) {
|
|
|
11419
11870
|
}
|
|
11420
11871
|
function readManifest2(path) {
|
|
11421
11872
|
try {
|
|
11422
|
-
const m = JSON.parse(
|
|
11873
|
+
const m = JSON.parse(readFileSync11(path, "utf-8"));
|
|
11423
11874
|
if (m && m.version === 1 && m.files && typeof m.files === "object") return m;
|
|
11424
11875
|
} catch {
|
|
11425
11876
|
}
|
|
@@ -11428,28 +11879,28 @@ function readManifest2(path) {
|
|
|
11428
11879
|
function installClaudeAssets(packageClaudeDir, claudeDir, opts = {}) {
|
|
11429
11880
|
const wants = (part) => !opts.include || opts.include.includes(part);
|
|
11430
11881
|
const result = { installed: [], updated: [], unchanged: 0, skipped: [] };
|
|
11431
|
-
const manifestPath =
|
|
11882
|
+
const manifestPath = join19(claudeDir, CLAUDE_MANIFEST);
|
|
11432
11883
|
const manifest = readManifest2(manifestPath);
|
|
11433
11884
|
const plan = [];
|
|
11434
|
-
const skillsSrc =
|
|
11435
|
-
if (wants("skills") &&
|
|
11885
|
+
const skillsSrc = join19(packageClaudeDir, "skills");
|
|
11886
|
+
if (wants("skills") && existsSync12(skillsSrc)) {
|
|
11436
11887
|
for (const f of listFiles(skillsSrc)) {
|
|
11437
11888
|
const rel = relative(skillsSrc, f);
|
|
11438
|
-
if (
|
|
11439
|
-
plan.push([f,
|
|
11889
|
+
if (existsSync12(join19(skillsSrc, rel.split(/[\\/]/)[0], ".repo-only"))) continue;
|
|
11890
|
+
plan.push([f, join19(claudeDir, "skills", rel), join19(claudeDir, "skills", rel.split(/[\\/]/)[0])]);
|
|
11440
11891
|
}
|
|
11441
11892
|
}
|
|
11442
|
-
const agentsSrc =
|
|
11443
|
-
if (wants("agents") &&
|
|
11893
|
+
const agentsSrc = join19(packageClaudeDir, "agents");
|
|
11894
|
+
if (wants("agents") && existsSync12(agentsSrc)) {
|
|
11444
11895
|
for (const f of listFiles(agentsSrc)) {
|
|
11445
|
-
const dest =
|
|
11896
|
+
const dest = join19(claudeDir, "agents", relative(agentsSrc, f));
|
|
11446
11897
|
plan.push([f, dest, dest]);
|
|
11447
11898
|
}
|
|
11448
11899
|
}
|
|
11449
|
-
const knowledgeSrc =
|
|
11450
|
-
if (wants("knowledge") &&
|
|
11900
|
+
const knowledgeSrc = join19(packageClaudeDir, "knowledge");
|
|
11901
|
+
if (wants("knowledge") && existsSync12(knowledgeSrc)) {
|
|
11451
11902
|
for (const f of listFiles(knowledgeSrc)) {
|
|
11452
|
-
plan.push([f,
|
|
11903
|
+
plan.push([f, join19(claudeDir, "knowledge", relative(knowledgeSrc, f)), join19(claudeDir, "knowledge")]);
|
|
11453
11904
|
}
|
|
11454
11905
|
}
|
|
11455
11906
|
const skippedSymlinks = /* @__PURE__ */ new Set();
|
|
@@ -11457,29 +11908,29 @@ function installClaudeAssets(packageClaudeDir, claudeDir, opts = {}) {
|
|
|
11457
11908
|
if (isSymlink(linkRoot)) {
|
|
11458
11909
|
if (!skippedSymlinks.has(linkRoot)) {
|
|
11459
11910
|
skippedSymlinks.add(linkRoot);
|
|
11460
|
-
result.skipped.push({ path: linkRoot, reason:
|
|
11911
|
+
result.skipped.push({ path: linkRoot, reason: existsSync12(linkRoot) ? "symlink" : "broken-symlink" });
|
|
11461
11912
|
}
|
|
11462
11913
|
continue;
|
|
11463
11914
|
}
|
|
11464
11915
|
const key = relative(claudeDir, dest);
|
|
11465
|
-
const content =
|
|
11916
|
+
const content = readFileSync11(src);
|
|
11466
11917
|
const hash = sha(content);
|
|
11467
|
-
if (!
|
|
11918
|
+
if (!existsSync12(dest)) {
|
|
11468
11919
|
if (!opts.dryRun) {
|
|
11469
|
-
|
|
11470
|
-
|
|
11920
|
+
mkdirSync11(dirname11(dest), { recursive: true });
|
|
11921
|
+
writeFileSync10(dest, content);
|
|
11471
11922
|
manifest.files[key] = hash;
|
|
11472
11923
|
}
|
|
11473
11924
|
result.installed.push(key);
|
|
11474
11925
|
continue;
|
|
11475
11926
|
}
|
|
11476
|
-
const current = sha(
|
|
11927
|
+
const current = sha(readFileSync11(dest));
|
|
11477
11928
|
if (current === hash) {
|
|
11478
11929
|
if (!opts.dryRun) manifest.files[key] = hash;
|
|
11479
11930
|
result.unchanged++;
|
|
11480
11931
|
} else if (manifest.files[key] === current) {
|
|
11481
11932
|
if (!opts.dryRun) {
|
|
11482
|
-
|
|
11933
|
+
writeFileSync10(dest, content);
|
|
11483
11934
|
manifest.files[key] = hash;
|
|
11484
11935
|
}
|
|
11485
11936
|
result.updated.push(key);
|
|
@@ -11488,70 +11939,70 @@ function installClaudeAssets(packageClaudeDir, claudeDir, opts = {}) {
|
|
|
11488
11939
|
}
|
|
11489
11940
|
}
|
|
11490
11941
|
if (!opts.dryRun && (result.installed.length || result.updated.length || result.unchanged)) {
|
|
11491
|
-
|
|
11492
|
-
|
|
11942
|
+
mkdirSync11(claudeDir, { recursive: true });
|
|
11943
|
+
writeFileSync10(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
|
|
11493
11944
|
}
|
|
11494
11945
|
return result;
|
|
11495
11946
|
}
|
|
11496
11947
|
|
|
11497
11948
|
// apps/reaper-mcp-server/src/jsfx/examples.ts
|
|
11498
11949
|
import { createHash as createHash3 } from "node:crypto";
|
|
11499
|
-
import { existsSync as
|
|
11500
|
-
import { join as
|
|
11950
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync12, readFileSync as readFileSync12, readdirSync as readdirSync4, writeFileSync as writeFileSync11 } from "node:fs";
|
|
11951
|
+
import { join as join20 } from "node:path";
|
|
11501
11952
|
var MANIFEST = ".installed.json";
|
|
11502
11953
|
var sha2 = (text9) => createHash3("sha256").update(text9).digest("hex");
|
|
11503
11954
|
function installExamplePlugins(examplesDir, outDir, toolkit, presetsDir2) {
|
|
11504
11955
|
const result = { installed: [], kept: [], presets: {}, presetErrors: [] };
|
|
11505
|
-
if (!
|
|
11506
|
-
|
|
11507
|
-
const manifestPath =
|
|
11956
|
+
if (!existsSync13(examplesDir)) return result;
|
|
11957
|
+
mkdirSync12(outDir, { recursive: true });
|
|
11958
|
+
const manifestPath = join20(outDir, MANIFEST);
|
|
11508
11959
|
let manifest = {};
|
|
11509
11960
|
try {
|
|
11510
|
-
manifest = JSON.parse(
|
|
11961
|
+
manifest = JSON.parse(readFileSync12(manifestPath, "utf8"));
|
|
11511
11962
|
} catch {
|
|
11512
11963
|
}
|
|
11513
|
-
for (const file of
|
|
11514
|
-
const dest =
|
|
11515
|
-
const next = inlineToolkit(
|
|
11516
|
-
const current =
|
|
11964
|
+
for (const file of readdirSync4(examplesDir).filter((f) => f.endsWith(".jsfx")).sort()) {
|
|
11965
|
+
const dest = join20(outDir, file);
|
|
11966
|
+
const next = inlineToolkit(readFileSync12(join20(examplesDir, file), "utf8"), { toolkit, version: 1, request: "a plugin that ships with reaper-mcp", slug: file.replace(/\.jsfx$/, ""), example: true });
|
|
11967
|
+
const current = existsSync13(dest) ? readFileSync12(dest, "utf8") : void 0;
|
|
11517
11968
|
if (current !== void 0 && current !== next && sha2(current) !== manifest[file]) {
|
|
11518
11969
|
result.kept.push(file);
|
|
11519
11970
|
continue;
|
|
11520
11971
|
}
|
|
11521
|
-
if (current !== next)
|
|
11972
|
+
if (current !== next) writeFileSync11(dest, next);
|
|
11522
11973
|
manifest[file] = sha2(next);
|
|
11523
11974
|
result.installed.push(file);
|
|
11524
11975
|
}
|
|
11525
11976
|
if (presetsDir2) {
|
|
11526
11977
|
const folder = outDir.split(/[/\\]/).slice(-2).join("/");
|
|
11527
|
-
for (const file of
|
|
11528
|
-
const presetsPath =
|
|
11529
|
-
if (!
|
|
11530
|
-
const input = JSON.parse(
|
|
11531
|
-
const { values, errors } = resolvePresets(input, parseSliders(
|
|
11978
|
+
for (const file of readdirSync4(examplesDir).filter((f) => f.endsWith(".jsfx")).sort()) {
|
|
11979
|
+
const presetsPath = join20(examplesDir, file.replace(/\.jsfx$/, ".presets.json"));
|
|
11980
|
+
if (!existsSync13(presetsPath)) continue;
|
|
11981
|
+
const input = JSON.parse(readFileSync12(presetsPath, "utf8"));
|
|
11982
|
+
const { values, errors } = resolvePresets(input, parseSliders(readFileSync12(join20(examplesDir, file), "utf8")).sliders);
|
|
11532
11983
|
if (errors.length) {
|
|
11533
11984
|
result.presetErrors.push(`${file}: ${errors.join(" ")}`);
|
|
11534
11985
|
continue;
|
|
11535
11986
|
}
|
|
11536
11987
|
const encoded = input.map((p, i) => encodePreset(p.name.trim(), values[i]));
|
|
11537
|
-
result.presets[file] = writePresetFile(presetsDir2, `${folder}/${file}`, encoded,
|
|
11988
|
+
result.presets[file] = writePresetFile(presetsDir2, `${folder}/${file}`, encoded, join20(outDir, ".presets", `${file}.json`)).written;
|
|
11538
11989
|
}
|
|
11539
11990
|
}
|
|
11540
|
-
|
|
11991
|
+
writeFileSync11(manifestPath, JSON.stringify(manifest, null, 2));
|
|
11541
11992
|
return result;
|
|
11542
11993
|
}
|
|
11543
11994
|
|
|
11544
11995
|
// apps/reaper-mcp-server/src/doctor-report.ts
|
|
11545
11996
|
function renderDoctor(sections3, opts = {}) {
|
|
11546
|
-
const
|
|
11547
|
-
const { bold, dim } =
|
|
11997
|
+
const ui3 = createUi({ level: opts.color ? 1 : 0, tty: false });
|
|
11998
|
+
const { bold, dim } = ui3;
|
|
11548
11999
|
const width = Math.max(...sections3.flatMap((s) => s.checks.map((c) => c.label.length)));
|
|
11549
12000
|
const out2 = opts.header === false ? [] : ["", ` ${bold("REAPER MCP")} ${dim("doctor")}${opts.version ? dim(` v${opts.version}`) : ""}`];
|
|
11550
12001
|
for (const section of sections3) {
|
|
11551
|
-
const state = section.state ? ` ${
|
|
12002
|
+
const state = section.state ? ` ${ui3.status(section.state.status, section.state.text)}` : "";
|
|
11552
12003
|
out2.push("", ` ${bold(section.title)}${section.note ? dim(` ${section.note}`) : ""}${state}`);
|
|
11553
12004
|
for (const c of section.checks) {
|
|
11554
|
-
out2.push(` ${
|
|
12005
|
+
out2.push(` ${ui3.mark(c.status)} ${c.label.padEnd(width)} ${c.status === "info" ? dim(c.detail) : c.detail}`);
|
|
11555
12006
|
if (c.fix && c.status !== "ok") out2.push(` ${" ".repeat(width)}${dim("\u2192")} ${c.fix}`);
|
|
11556
12007
|
}
|
|
11557
12008
|
}
|
|
@@ -11559,71 +12010,78 @@ function renderDoctor(sections3, opts = {}) {
|
|
|
11559
12010
|
out2.push("");
|
|
11560
12011
|
if (problems.length) {
|
|
11561
12012
|
const fixes = [...new Set(problems.map((c) => c.fix).filter((f) => Boolean(f)))];
|
|
11562
|
-
out2.push(` ${
|
|
12013
|
+
out2.push(` ${ui3.fail(`${problems.length} problem${problems.length === 1 ? "" : "s"}`)}${fixes.length ? dim(` \xB7 fix with: ${fixes.join(", then ")}`) : ""}`);
|
|
11563
12014
|
} else {
|
|
11564
|
-
out2.push(` ${
|
|
12015
|
+
out2.push(` ${ui3.ok("All good.")}`);
|
|
11565
12016
|
}
|
|
11566
12017
|
out2.push("");
|
|
11567
12018
|
return out2.join("\n");
|
|
11568
12019
|
}
|
|
11569
12020
|
|
|
11570
12021
|
// apps/reaper-mcp-server/src/bridge-repair.ts
|
|
11571
|
-
import { existsSync as
|
|
11572
|
-
import { join as
|
|
12022
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync13, readFileSync as readFileSync13, rmSync as rmSync4, writeFileSync as writeFileSync12 } from "node:fs";
|
|
12023
|
+
import { dirname as dirname12, join as join21 } from "node:path";
|
|
11573
12024
|
var BRIDGE_VERSION_FILE = "mcp_bridge_version.txt";
|
|
11574
12025
|
function readBridgeVersion(scriptsDir) {
|
|
11575
12026
|
try {
|
|
11576
|
-
const v =
|
|
12027
|
+
const v = readFileSync13(join21(scriptsDir, BRIDGE_VERSION_FILE), "utf-8").trim();
|
|
11577
12028
|
return /^\d+\.\d+\.\d+/.test(v) ? v : void 0;
|
|
11578
12029
|
} catch {
|
|
11579
12030
|
return void 0;
|
|
11580
12031
|
}
|
|
11581
12032
|
}
|
|
11582
12033
|
function writeBridgeVersion(scriptsDir, version) {
|
|
11583
|
-
|
|
12034
|
+
writeFileSync12(join21(scriptsDir, BRIDGE_VERSION_FILE), `${version}
|
|
11584
12035
|
`, "utf-8");
|
|
11585
12036
|
}
|
|
11586
12037
|
function sameContent(a, b) {
|
|
11587
12038
|
try {
|
|
11588
|
-
return
|
|
12039
|
+
return readFileSync13(a).equals(readFileSync13(b));
|
|
11589
12040
|
} catch {
|
|
11590
12041
|
return false;
|
|
11591
12042
|
}
|
|
11592
12043
|
}
|
|
11593
|
-
function installReaperFiles(paths) {
|
|
12044
|
+
function installReaperFiles(paths, withPage = true) {
|
|
11594
12045
|
let luaChanged = false;
|
|
11595
12046
|
for (const asset of REAPER_ASSETS) {
|
|
11596
|
-
const src =
|
|
11597
|
-
if (!
|
|
12047
|
+
const src = join21(paths.assetsDir, asset);
|
|
12048
|
+
if (!existsSync14(src)) continue;
|
|
11598
12049
|
const lua = asset.endsWith(".lua");
|
|
11599
|
-
const destDir = lua ? paths.scriptsDir :
|
|
11600
|
-
|
|
11601
|
-
const dest =
|
|
12050
|
+
const destDir = lua ? paths.scriptsDir : join21(paths.effectsDir, "reaper-mcp");
|
|
12051
|
+
mkdirSync13(destDir, { recursive: true });
|
|
12052
|
+
const dest = join21(destDir, asset);
|
|
11602
12053
|
if (lua && !sameContent(src, dest)) luaChanged = true;
|
|
11603
12054
|
installFile(src, dest);
|
|
11604
12055
|
}
|
|
11605
|
-
for (const asset of RETIRED_ASSETS)
|
|
11606
|
-
if (
|
|
12056
|
+
for (const asset of RETIRED_ASSETS) rmSync4(join21(paths.scriptsDir, asset), { force: true });
|
|
12057
|
+
if (withPage && existsSync14(join21(paths.wwwSrcDir, BRIDGE_UI_FILE))) copyDirSync(paths.wwwSrcDir, paths.wwwDir);
|
|
11607
12058
|
return luaChanged;
|
|
11608
12059
|
}
|
|
11609
12060
|
function repairBridgeInstall(paths, version, opts) {
|
|
11610
12061
|
const none = { bridgeChanged: false, autostartAdded: false };
|
|
11611
12062
|
if (opts.inClone) return { skipped: "clone", ...none };
|
|
11612
|
-
const reapack =
|
|
11613
|
-
const ours =
|
|
11614
|
-
|
|
12063
|
+
const reapack = existsSync14(join21(paths.scriptsDir, "reaper-mcp", "MCP Bridge", "mcp_bridge.lua"));
|
|
12064
|
+
const ours = existsSync14(join21(paths.scriptsDir, "mcp_bridge.lua"));
|
|
12065
|
+
const first = !reapack && !ours && opts.firstInstall === true && existsSync14(dirname12(paths.scriptsDir));
|
|
12066
|
+
if (!reapack && !ours && !first) return { skipped: "not_installed", ...none };
|
|
11615
12067
|
const from = readBridgeVersion(paths.scriptsDir);
|
|
11616
12068
|
if (from && compareVersions(from, version) >= 0) return { skipped: "current", from, ...none };
|
|
11617
|
-
const
|
|
11618
|
-
const
|
|
11619
|
-
const
|
|
11620
|
-
const
|
|
11621
|
-
|
|
12069
|
+
const withPage = !opts.firstInstall || existsSync14(join21(paths.wwwDir, BRIDGE_UI_FILE));
|
|
12070
|
+
const bridgeChanged = reapack ? false : installReaperFiles(paths, withPage);
|
|
12071
|
+
const startupPath = join21(paths.scriptsDir, "__startup.lua");
|
|
12072
|
+
const startup = existsSync14(startupPath) ? readFileSync13(startupPath, "utf-8") : "";
|
|
12073
|
+
const keepOff = opts.firstInstall === true && !first && !startup.includes(AUTOSTART_MARKER);
|
|
12074
|
+
const { text: text9, changed } = keepOff ? { text: startup, changed: false } : ensureBridgeAutostart(startup);
|
|
12075
|
+
if (changed) writeFileSync12(startupPath, text9, "utf-8");
|
|
11622
12076
|
writeBridgeVersion(paths.scriptsDir, version);
|
|
11623
|
-
return { from, bridgeChanged, autostartAdded: !startup.includes(AUTOSTART_MARKER) };
|
|
12077
|
+
return { from, bridgeChanged, autostartAdded: !keepOff && !startup.includes(AUTOSTART_MARKER), ...first && { firstInstalled: true } };
|
|
11624
12078
|
}
|
|
11625
12079
|
function repairNotices(repair, version, bridgeRunning) {
|
|
11626
12080
|
const notices = [];
|
|
12081
|
+
if (repair.firstInstalled) {
|
|
12082
|
+
notices.push(`reaper-mcp installed its bridge ${version} into REAPER (a script in Scripts/, the analyzers in Effects/reaper-mcp/ and a start-with-REAPER block in Scripts/__startup.lua). Restart REAPER and the bridge starts with it; to start it now, load Scripts/mcp_bridge.lua with Actions \u2192 Load ReaScript\u2026. To turn the autostart off, delete the block marked "reaper-mcp: start the bridge with REAPER" from Scripts/__startup.lua.`);
|
|
12083
|
+
return notices;
|
|
12084
|
+
}
|
|
11627
12085
|
if (repair.bridgeChanged) {
|
|
11628
12086
|
notices.push(bridgeRunning ? `reaper-mcp updated the REAPER bridge to ${version}, but REAPER is still running the old one: restart REAPER, or click Restart bridge in the bridge window, so it loads the new bridge.` : `reaper-mcp updated the REAPER bridge to ${version}; REAPER loads it the next time the bridge starts.`);
|
|
11629
12087
|
}
|
|
@@ -11667,9 +12125,9 @@ ${SIDECAR_OFFER_TEXT}
|
|
|
11667
12125
|
|
|
11668
12126
|
// apps/reaper-mcp-server/src/setup-health.ts
|
|
11669
12127
|
import { execFile as execFile2 } from "node:child_process";
|
|
11670
|
-
import { readFileSync as
|
|
11671
|
-
import { join as
|
|
11672
|
-
import { platform as
|
|
12128
|
+
import { readFileSync as readFileSync14 } from "node:fs";
|
|
12129
|
+
import { join as join22 } from "node:path";
|
|
12130
|
+
import { platform as platform7 } from "node:os";
|
|
11673
12131
|
function heartbeatAgeBucket(ms) {
|
|
11674
12132
|
const min = 6e4;
|
|
11675
12133
|
if (ms < min) return "<1m";
|
|
@@ -11679,7 +12137,7 @@ function heartbeatAgeBucket(ms) {
|
|
|
11679
12137
|
return ">7d";
|
|
11680
12138
|
}
|
|
11681
12139
|
function isReaperProcessRunning(timeoutMs = 2e3) {
|
|
11682
|
-
const win =
|
|
12140
|
+
const win = platform7() === "win32";
|
|
11683
12141
|
const [cmd, args] = win ? ["tasklist", ["/FI", "IMAGENAME eq reaper.exe", "/NH"]] : ["pgrep", ["-xi", "reaper"]];
|
|
11684
12142
|
return new Promise((resolve4) => {
|
|
11685
12143
|
execFile2(cmd, args, { timeout: timeoutMs, windowsHide: true }, (err, stdout) => {
|
|
@@ -11691,7 +12149,7 @@ function isReaperProcessRunning(timeoutMs = 2e3) {
|
|
|
11691
12149
|
}
|
|
11692
12150
|
function autostartInstalled(scriptsDir) {
|
|
11693
12151
|
try {
|
|
11694
|
-
return
|
|
12152
|
+
return readFileSync14(join22(scriptsDir, "__startup.lua"), "utf-8").includes(AUTOSTART_MARKER);
|
|
11695
12153
|
} catch {
|
|
11696
12154
|
return false;
|
|
11697
12155
|
}
|
|
@@ -11706,13 +12164,13 @@ function setupHealthAttributes(h) {
|
|
|
11706
12164
|
}
|
|
11707
12165
|
|
|
11708
12166
|
// apps/reaper-mcp-server/src/install-info.ts
|
|
11709
|
-
import { readFileSync as
|
|
12167
|
+
import { readFileSync as readFileSync15, realpathSync as realpathSync2 } from "node:fs";
|
|
11710
12168
|
import { posix, win32 } from "node:path";
|
|
11711
|
-
function pathApi(
|
|
11712
|
-
return
|
|
12169
|
+
function pathApi(platform9) {
|
|
12170
|
+
return platform9 === "win32" ? win32 : posix;
|
|
11713
12171
|
}
|
|
11714
|
-
function npxRoot(dir,
|
|
11715
|
-
const p = pathApi(
|
|
12172
|
+
function npxRoot(dir, platform9) {
|
|
12173
|
+
const p = pathApi(platform9);
|
|
11716
12174
|
const parts = dir.split(p.sep);
|
|
11717
12175
|
const i = parts.lastIndexOf("_npx");
|
|
11718
12176
|
return i >= 0 && i + 1 < parts.length ? parts.slice(0, i + 2).join(p.sep) : void 0;
|
|
@@ -11743,7 +12201,7 @@ function classifySpec(spec) {
|
|
|
11743
12201
|
if (/^[\^~<>=*xX\d]/.test(version) || version.includes("||") || / - /.test(version)) return "range";
|
|
11744
12202
|
return "tag";
|
|
11745
12203
|
}
|
|
11746
|
-
function installPin(ctx, method, readFile6 = (path) =>
|
|
12204
|
+
function installPin(ctx, method, readFile6 = (path) => readFileSync15(path, "utf-8")) {
|
|
11747
12205
|
if (method !== "npx") return "none";
|
|
11748
12206
|
const specs = [];
|
|
11749
12207
|
const root = npxRoot(ctx.dir, ctx.platform);
|
|
@@ -11772,7 +12230,7 @@ function installAttributes(info) {
|
|
|
11772
12230
|
function readInstallInfo(codeDir, current, env = process.env, paths = { statePath: defaultUpdateStatePath(), markerPath: defaultUpdateMarkerPath() }) {
|
|
11773
12231
|
let dir = codeDir;
|
|
11774
12232
|
try {
|
|
11775
|
-
dir =
|
|
12233
|
+
dir = realpathSync2(codeDir);
|
|
11776
12234
|
} catch {
|
|
11777
12235
|
}
|
|
11778
12236
|
const ctx = { dir, isClone: findCloneRoot(dir) !== null, env, execPath: process.execPath, platform: process.platform };
|
|
@@ -11789,125 +12247,126 @@ function readInstallInfo(codeDir, current, env = process.env, paths = { statePat
|
|
|
11789
12247
|
|
|
11790
12248
|
// apps/reaper-mcp-server/src/main.ts
|
|
11791
12249
|
var execAsync = promisifyUtil(execCb);
|
|
11792
|
-
var
|
|
11793
|
-
var __dirname2 =
|
|
12250
|
+
var ui2 = createUi();
|
|
12251
|
+
var __dirname2 = dirname13(fileURLToPath6(import.meta.url));
|
|
11794
12252
|
async function setup() {
|
|
11795
12253
|
const verbose = process.argv.includes("--verbose");
|
|
11796
12254
|
const installedLine = (what, files) => {
|
|
11797
|
-
if (verbose) for (const f of files) console.log(
|
|
11798
|
-
else if (files.length) console.log(
|
|
12255
|
+
if (verbose) for (const f of files) console.log(ui2.item("ok", `Installed: ${f}`));
|
|
12256
|
+
else if (files.length) console.log(ui2.item("ok", `${files.length} ${what} installed`));
|
|
11799
12257
|
};
|
|
11800
|
-
console.log(
|
|
12258
|
+
console.log(ui2.banner("Setup", readServiceVersion()));
|
|
11801
12259
|
const bridgeDir = await ensureBridgeDir();
|
|
11802
|
-
console.log(`Bridge directory: ${
|
|
12260
|
+
console.log(`Bridge directory: ${ui2.dim(bridgeDir)}
|
|
11803
12261
|
`);
|
|
11804
12262
|
const scriptsDir = getReaperScriptsPath();
|
|
11805
|
-
|
|
12263
|
+
mkdirSync14(scriptsDir, { recursive: true });
|
|
11806
12264
|
const reaperDir = resolveAssetDir(__dirname2, "reaper");
|
|
11807
|
-
const filesPlan = setupFilesPlan(
|
|
12265
|
+
const filesPlan = setupFilesPlan(existsSync15(join23(scriptsDir, "reaper-mcp", "MCP Bridge", "mcp_bridge.lua")), findCloneRoot(__dirname2) !== null);
|
|
11808
12266
|
if (filesPlan === "leave") {
|
|
11809
|
-
console.log(`${
|
|
11810
|
-
console.log(`${
|
|
12267
|
+
console.log(`${ui2.mark("info")} The bridge is installed by ReaPack: leaving its scripts, JSFX and status page to ReaPack.`);
|
|
12268
|
+
console.log(`${ui2.dim("Setup only turns on starting with REAPER and the web interface.")}
|
|
11811
12269
|
`);
|
|
11812
12270
|
installBridgeAutostart(scriptsDir);
|
|
11813
12271
|
writeBridgeVersion(scriptsDir, readServiceVersion());
|
|
11814
12272
|
const port = await enableWebInterface();
|
|
11815
12273
|
console.log(`
|
|
11816
|
-
${
|
|
11817
|
-
if (await chainAfterSetup(port,
|
|
12274
|
+
${ui2.mark("ok")} ${ui2.bold("Setup complete!")}`);
|
|
12275
|
+
if (await chainAfterSetup(port, join23(scriptsDir, "reaper-mcp", "MCP Bridge", "mcp_bridge.lua"))) return;
|
|
11818
12276
|
console.log(`
|
|
11819
|
-
Restart REAPER (or run the bridge once from the Action List) and add reaper-mcp to your harness: ${
|
|
11820
|
-
if (port) console.log(`The bridge opens its status window on start: ${
|
|
12277
|
+
Restart REAPER (or run the bridge once from the Action List) and add reaper-mcp to your harness: ${ui2.cmd("reaper-mcp doctor")}`);
|
|
12278
|
+
if (port) console.log(`The bridge opens its status window on start: ${ui2.link(`http://localhost:${port}/${BRIDGE_UI_FILE}`)}`);
|
|
11821
12279
|
await offerSidecar();
|
|
11822
12280
|
return;
|
|
11823
12281
|
}
|
|
11824
12282
|
if (filesPlan === "install-with-warning") {
|
|
11825
|
-
console.log(`${
|
|
12283
|
+
console.log(`${ui2.warn("WARNING:")} ReaPack has installed the bridge too, and REAPER prefers its copy (Scripts/reaper-mcp/MCP Bridge/ and`);
|
|
11826
12284
|
console.log("Effects/reaper-mcp/Meters/) over the files this checkout installs. Your local changes will not run until you");
|
|
11827
12285
|
console.log("uninstall the reaper-mcp packages in ReaPack (Manage repositories > reaper-mcp > Uninstall packages),");
|
|
11828
12286
|
console.log("then run setup again: this run also overwrote the status page ReaPack installed, which uninstalling removes.\n");
|
|
11829
12287
|
}
|
|
11830
|
-
console.log(`${
|
|
12288
|
+
console.log(`${ui2.bold("Installing Lua scripts...")}`);
|
|
11831
12289
|
const luaInstalled = [];
|
|
11832
12290
|
for (const asset of REAPER_ASSETS) {
|
|
11833
12291
|
if (!asset.endsWith(".lua")) continue;
|
|
11834
|
-
const src =
|
|
11835
|
-
const dest =
|
|
12292
|
+
const src = join23(reaperDir, asset);
|
|
12293
|
+
const dest = join23(scriptsDir, asset);
|
|
11836
12294
|
if (installFile(src, dest)) luaInstalled.push(asset);
|
|
11837
|
-
else console.log(
|
|
12295
|
+
else console.log(ui2.item("fail", `Not found: ${src}`));
|
|
11838
12296
|
}
|
|
11839
12297
|
installedLine("scripts", luaInstalled);
|
|
11840
12298
|
for (const asset of RETIRED_ASSETS) {
|
|
11841
|
-
const dest =
|
|
11842
|
-
if (
|
|
11843
|
-
|
|
11844
|
-
console.log(
|
|
12299
|
+
const dest = join23(scriptsDir, asset);
|
|
12300
|
+
if (existsSync15(dest)) {
|
|
12301
|
+
rmSync5(dest);
|
|
12302
|
+
console.log(ui2.item("info", `Removed: ${asset} (retired)`));
|
|
11845
12303
|
}
|
|
11846
12304
|
}
|
|
11847
12305
|
const cloneRoot = findCloneRoot(__dirname2);
|
|
11848
12306
|
if (cloneRoot) {
|
|
11849
12307
|
const dev = isDevClone(await cloneState(cloneRoot));
|
|
11850
|
-
|
|
11851
|
-
console.log(
|
|
12308
|
+
writeFileSync13(join23(scriptsDir, "mcp_update.conf"), updateConfigText(cloneRoot, process.execPath, dev));
|
|
12309
|
+
console.log(ui2.item("ok", `Installed: mcp_update.conf (${dev ? "developer clone: Rebuild & reload" : "one-click updates"} from the status page)`));
|
|
11852
12310
|
} else {
|
|
11853
|
-
|
|
12311
|
+
writeFileSync13(join23(scriptsDir, "mcp_update.conf"), npmUpdateConfigText(process.execPath, join23(__dirname2, "main.js")));
|
|
11854
12312
|
}
|
|
11855
|
-
const effectsDir =
|
|
11856
|
-
|
|
11857
|
-
console.log(
|
|
12313
|
+
const effectsDir = join23(getReaperEffectsPath(), "reaper-mcp");
|
|
12314
|
+
mkdirSync14(effectsDir, { recursive: true });
|
|
12315
|
+
console.log(ui2.section("Installing JSFX analyzers..."));
|
|
11858
12316
|
const jsfxInstalled = [];
|
|
11859
12317
|
for (const asset of REAPER_ASSETS) {
|
|
11860
12318
|
if (asset.endsWith(".lua")) continue;
|
|
11861
|
-
const src =
|
|
11862
|
-
const dest =
|
|
12319
|
+
const src = join23(reaperDir, asset);
|
|
12320
|
+
const dest = join23(effectsDir, asset);
|
|
11863
12321
|
if (installFile(src, dest)) jsfxInstalled.push(`reaper-mcp/${asset}`);
|
|
11864
|
-
else console.log(
|
|
12322
|
+
else console.log(ui2.item("fail", `Not found: ${src}`));
|
|
11865
12323
|
}
|
|
11866
12324
|
installedLine("JSFX files", jsfxInstalled);
|
|
11867
|
-
console.log(
|
|
11868
|
-
const examplesDir =
|
|
11869
|
-
const examples = installExamplePlugins(examplesDir,
|
|
12325
|
+
console.log(ui2.section("Installing example plugins..."));
|
|
12326
|
+
const examplesDir = join23(resolveAssetDir(__dirname2, "claude"), "skills", "make-plugin", "examples");
|
|
12327
|
+
const examples = installExamplePlugins(examplesDir, join23(generatedDir(), "examples"), loadToolkit(), presetsDir());
|
|
11870
12328
|
installedLine("example plugins", examples.installed.map((f) => `reaper-mcp-generated/examples/${f}`));
|
|
11871
|
-
for (const f of examples.kept) console.log(
|
|
12329
|
+
for (const f of examples.kept) console.log(ui2.item("info", `Kept your edited copy: reaper-mcp-generated/examples/${f}`));
|
|
11872
12330
|
if (verbose) {
|
|
11873
|
-
for (const [f, names] of Object.entries(examples.presets)) if (names.length) console.log(
|
|
12331
|
+
for (const [f, names] of Object.entries(examples.presets)) if (names.length) console.log(ui2.item("info", `Presets for ${f}: ${names.join(", ")}`));
|
|
11874
12332
|
}
|
|
11875
|
-
for (const e of examples.presetErrors) console.log(
|
|
11876
|
-
if (!examples.installed.length && !examples.kept.length) console.log(
|
|
12333
|
+
for (const e of examples.presetErrors) console.log(ui2.item("warn", `Skipped presets (invalid): ${e}`));
|
|
12334
|
+
if (!examples.installed.length && !examples.kept.length) console.log(ui2.item("fail", `Not found: ${examplesDir}`));
|
|
11877
12335
|
const wwwSrc = resolveAssetDir(__dirname2, "bridge-ui");
|
|
11878
|
-
console.log(
|
|
11879
|
-
if (
|
|
12336
|
+
console.log(ui2.section("Installing bridge status UI..."));
|
|
12337
|
+
if (existsSync15(join23(wwwSrc, BRIDGE_UI_FILE))) {
|
|
11880
12338
|
const count = copyDirSync(wwwSrc, getReaperWwwPath());
|
|
11881
|
-
console.log(
|
|
12339
|
+
console.log(ui2.item("ok", verbose ? `Installed: reaper_www_root/${BRIDGE_UI_FILE} (+${count - 1} PWA files)` : "Status page installed"));
|
|
11882
12340
|
} else {
|
|
11883
|
-
console.log(
|
|
12341
|
+
console.log(ui2.item("fail", `Not found: ${join23(wwwSrc, BRIDGE_UI_FILE)} (build bridge-ui first)`));
|
|
11884
12342
|
}
|
|
11885
12343
|
installBridgeAutostart(scriptsDir);
|
|
11886
12344
|
writeBridgeVersion(scriptsDir, readServiceVersion());
|
|
11887
12345
|
const webPort = await enableWebInterface();
|
|
11888
12346
|
await registerSnapshotActions();
|
|
11889
12347
|
console.log(`
|
|
11890
|
-
${
|
|
11891
|
-
if (await chainAfterSetup(webPort,
|
|
12348
|
+
${ui2.mark("ok")} ${ui2.bold("Setup complete!")}`);
|
|
12349
|
+
if (await chainAfterSetup(webPort, join23(scriptsDir, "mcp_bridge.lua"))) return;
|
|
11892
12350
|
console.log("");
|
|
11893
|
-
console.log(
|
|
11894
|
-
console.log(` ${
|
|
12351
|
+
console.log(ui2.heading("Next steps:"));
|
|
12352
|
+
console.log(` ${ui2.bold("1.")} Start REAPER: the bridge starts with it. If REAPER is already open, restart it,`);
|
|
11895
12353
|
console.log(" or run the bridge once by hand: Actions > Show action list > Load ReaScript,");
|
|
11896
|
-
console.log(` select ${
|
|
11897
|
-
console.log(` ${
|
|
12354
|
+
console.log(` select ${ui2.dim(join23(scriptsDir, "mcp_bridge.lua"))} and click Run.`);
|
|
12355
|
+
console.log(` ${ui2.bold("2.")} Connect your AI harness: ${ui2.cmd("reaper-mcp init")}, then check it with ${ui2.cmd("reaper-mcp doctor")}`);
|
|
11898
12356
|
if (webPort) {
|
|
11899
12357
|
console.log(`
|
|
11900
|
-
The bridge opens its status window on start: ${
|
|
12358
|
+
The bridge opens its status window on start: ${ui2.link(`http://localhost:${webPort}/${BRIDGE_UI_FILE}`)}`);
|
|
11901
12359
|
}
|
|
11902
12360
|
await offerSidecar();
|
|
11903
12361
|
}
|
|
11904
12362
|
async function offerSidecar() {
|
|
12363
|
+
if (process.env["REAPER_MCP_SKIP_SIDECAR_OFFER"]) return;
|
|
11905
12364
|
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY) && !process.env["CI"];
|
|
11906
12365
|
await offerSidecarSetup({ input: process.stdin, output: process.stdout, interactive }, getSidecarClient().isAvailable(), () => setupSidecar([]));
|
|
11907
12366
|
}
|
|
11908
12367
|
async function askYesNo(question, defaultYes = true) {
|
|
11909
12368
|
process.stdout.write(`
|
|
11910
|
-
${
|
|
12369
|
+
${ui2.bold(question)} ${ui2.dim(defaultYes ? "[Y/n]" : "[y/N]")} `);
|
|
11911
12370
|
let answer = "";
|
|
11912
12371
|
if (!streamEnded(process.stdin)) {
|
|
11913
12372
|
const rl = createInterface5({ input: process.stdin, output: process.stdout, terminal: false });
|
|
@@ -11920,6 +12379,7 @@ ${ui.bold(question)} ${ui.dim(defaultYes ? "[Y/n]" : "[y/N]")} `);
|
|
|
11920
12379
|
return answer === "" ? defaultYes : answer === "y" || answer === "yes";
|
|
11921
12380
|
}
|
|
11922
12381
|
async function chainAfterSetup(port, bridgeScript) {
|
|
12382
|
+
if (process.argv.includes("--no-init")) return false;
|
|
11923
12383
|
const yes = process.argv.includes("--yes") || process.argv.includes("-y");
|
|
11924
12384
|
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
11925
12385
|
if (!yes && !interactive) return false;
|
|
@@ -11928,18 +12388,18 @@ async function chainAfterSetup(port, bridgeScript) {
|
|
|
11928
12388
|
if (yes || await askYesNo("Check that everything is in place?")) {
|
|
11929
12389
|
console.log("");
|
|
11930
12390
|
await doctor();
|
|
11931
|
-
console.log(
|
|
12391
|
+
console.log(ui2.dim("The bridge shows as not detected until REAPER has started it: that is the one step left."));
|
|
11932
12392
|
}
|
|
11933
12393
|
} else {
|
|
11934
12394
|
console.log(`
|
|
11935
|
-
Whenever you are ready: ${
|
|
12395
|
+
Whenever you are ready: ${ui2.cmd("reaper-mcp init")}, then ${ui2.cmd("reaper-mcp doctor")}`);
|
|
11936
12396
|
}
|
|
11937
12397
|
await offerSidecar();
|
|
11938
12398
|
console.log(`
|
|
11939
|
-
${
|
|
11940
|
-
console.log(` ${
|
|
12399
|
+
${ui2.heading("One step left:")} start REAPER (restart it if it is open): the bridge starts with it.`);
|
|
12400
|
+
console.log(` ${ui2.dim("Rather not restart? Actions > Show action list > Load ReaScript, select")} ${ui2.dim(bridgeScript)} ${ui2.dim("and click Run.")}`);
|
|
11941
12401
|
if (port) console.log(`
|
|
11942
|
-
The bridge opens its status window on start: ${
|
|
12402
|
+
The bridge opens its status window on start: ${ui2.link(`http://localhost:${port}/${BRIDGE_UI_FILE}`)}`);
|
|
11943
12403
|
return true;
|
|
11944
12404
|
}
|
|
11945
12405
|
async function cloneState(repo) {
|
|
@@ -11956,57 +12416,57 @@ async function isReaperRunning() {
|
|
|
11956
12416
|
return await isReaperProcessRunning(1e4) ?? false;
|
|
11957
12417
|
}
|
|
11958
12418
|
async function enableWebInterface() {
|
|
11959
|
-
console.log(
|
|
11960
|
-
const iniPath =
|
|
11961
|
-
if (!
|
|
11962
|
-
console.log(
|
|
12419
|
+
console.log(ui2.section("Enabling REAPER web interface..."));
|
|
12420
|
+
const iniPath = join23(getReaperResourcePath(), "reaper.ini");
|
|
12421
|
+
if (!existsSync15(iniPath)) {
|
|
12422
|
+
console.log(ui2.item("warn", `Skipped: ${iniPath} not found (start REAPER once, quit it, then re-run setup)`));
|
|
11963
12423
|
return null;
|
|
11964
12424
|
}
|
|
11965
12425
|
const requested = Number(process.env["REAPER_WEB_PORT"]) || DEFAULT_WEB_PORT;
|
|
11966
|
-
const result = ensureWebInterface(
|
|
12426
|
+
const result = ensureWebInterface(readFileSync16(iniPath, "utf-8"), requested);
|
|
11967
12427
|
if (!result.changed) {
|
|
11968
|
-
console.log(
|
|
12428
|
+
console.log(ui2.item("ok", `Already enabled on port ${result.port}`));
|
|
11969
12429
|
return result.port;
|
|
11970
12430
|
}
|
|
11971
12431
|
if (await isReaperRunning()) {
|
|
11972
12432
|
if (!process.stdout.isTTY) {
|
|
11973
|
-
console.log(
|
|
11974
|
-
console.log(` Quit REAPER and run ${
|
|
12433
|
+
console.log(ui2.item("warn", "Skipped: REAPER is running and would overwrite reaper.ini on exit."));
|
|
12434
|
+
console.log(` Quit REAPER and run ${ui2.cmd("reaper-mcp setup")} again.`);
|
|
11975
12435
|
return null;
|
|
11976
12436
|
}
|
|
11977
|
-
console.log(
|
|
12437
|
+
console.log(ui2.item("warn", "REAPER is running and would overwrite reaper.ini on exit."));
|
|
11978
12438
|
console.log(" Quit REAPER to finish (Ctrl+C to skip)...");
|
|
11979
12439
|
while (await isReaperRunning()) await new Promise((r) => setTimeout(r, 1e3));
|
|
11980
12440
|
}
|
|
11981
|
-
|
|
11982
|
-
console.log(
|
|
12441
|
+
writeFileSync13(iniPath, ensureWebInterface(readFileSync16(iniPath, "utf-8"), requested).ini, "utf-8");
|
|
12442
|
+
console.log(ui2.item("ok", `Enabled on port ${result.port} (override with REAPER_WEB_PORT)`));
|
|
11983
12443
|
return result.port;
|
|
11984
12444
|
}
|
|
11985
12445
|
function installBridgeAutostart(scriptsDir) {
|
|
11986
|
-
console.log(
|
|
11987
|
-
const path =
|
|
11988
|
-
const { text: text9, changed } = ensureBridgeAutostart(
|
|
11989
|
-
if (changed)
|
|
11990
|
-
console.log(
|
|
11991
|
-
console.log(
|
|
12446
|
+
console.log(ui2.section("Starting the bridge with REAPER..."));
|
|
12447
|
+
const path = join23(scriptsDir, "__startup.lua");
|
|
12448
|
+
const { text: text9, changed } = ensureBridgeAutostart(existsSync15(path) ? readFileSync16(path, "utf-8") : "");
|
|
12449
|
+
if (changed) writeFileSync13(path, text9, "utf-8");
|
|
12450
|
+
console.log(ui2.item("ok", changed ? "Added to Scripts/__startup.lua (REAPER runs it at launch)" : "Already in Scripts/__startup.lua"));
|
|
12451
|
+
console.log(ui2.dim(" Turn it off in the bridge window: Settings > Start with REAPER."));
|
|
11992
12452
|
}
|
|
11993
12453
|
async function registerSnapshotActions() {
|
|
11994
|
-
console.log(
|
|
11995
|
-
const kbPath =
|
|
11996
|
-
const kb =
|
|
12454
|
+
console.log(ui2.section("Registering snapshot actions (quick save, next, previous)..."));
|
|
12455
|
+
const kbPath = join23(getReaperResourcePath(), "reaper-kb.ini");
|
|
12456
|
+
const kb = existsSync15(kbPath) ? readFileSync16(kbPath, "utf-8") : "";
|
|
11997
12457
|
const { added } = ensureSnapshotActions(kb);
|
|
11998
12458
|
if (!added.length) {
|
|
11999
|
-
console.log(
|
|
12459
|
+
console.log(ui2.item("ok", "Already in the Action List"));
|
|
12000
12460
|
} else if (await isReaperRunning()) {
|
|
12001
|
-
console.log(
|
|
12461
|
+
console.log(ui2.item("info", "REAPER is running: the bridge adds them when it next starts (re-run mcp_bridge.lua)."));
|
|
12002
12462
|
} else {
|
|
12003
|
-
|
|
12004
|
-
console.log(
|
|
12463
|
+
writeFileSync13(kbPath, ensureSnapshotActions(kb).kb, "utf-8");
|
|
12464
|
+
console.log(ui2.item("ok", `Added: ${added.join(", ")}`));
|
|
12005
12465
|
}
|
|
12006
|
-
console.log(`${
|
|
12466
|
+
console.log(`${ui2.dim(" Bind keys in Actions > Show action list: search")} ${ui2.cmd('"mcp_snapshot"')}${ui2.dim(".")}`);
|
|
12007
12467
|
}
|
|
12008
|
-
function installHint(
|
|
12009
|
-
return /^https?:\/\/\S+$/.test(hint) ?
|
|
12468
|
+
function installHint(ui3, hint) {
|
|
12469
|
+
return /^https?:\/\/\S+$/.test(hint) ? ui3.link(hint) : hint;
|
|
12010
12470
|
}
|
|
12011
12471
|
async function init(chained = false) {
|
|
12012
12472
|
let chosen;
|
|
@@ -12016,66 +12476,66 @@ async function init(chained = false) {
|
|
|
12016
12476
|
console.error(err.message);
|
|
12017
12477
|
process.exit(1);
|
|
12018
12478
|
}
|
|
12019
|
-
console.log(
|
|
12479
|
+
console.log(ui2.banner("Connect your AI harness", readServiceVersion()));
|
|
12020
12480
|
const env = realEnv();
|
|
12021
12481
|
const found = detectHarnesses(env).map((h) => h.id);
|
|
12022
12482
|
const ids = chosen ?? found;
|
|
12023
12483
|
for (const h of HARNESSES) {
|
|
12024
|
-
console.log(found.includes(h.id) ? ` ${
|
|
12484
|
+
console.log(found.includes(h.id) ? ` ${ui2.mark("ok")} ${ui2.dim("found")} ${ui2.bold(h.name)}` : ` ${ui2.mark("info")} ${ui2.dim("not found")} ${h.name}: ${ui2.dim(installHint(ui2, h.installHint))}`);
|
|
12025
12485
|
}
|
|
12026
12486
|
console.log("");
|
|
12027
12487
|
if (ids.length === 0) {
|
|
12028
|
-
console.log(`None of the supported harnesses is installed yet. Install one (see above), then run: ${
|
|
12488
|
+
console.log(`None of the supported harnesses is installed yet. Install one (see above), then run: ${ui2.cmd("reaper-mcp init")}`);
|
|
12029
12489
|
return;
|
|
12030
12490
|
}
|
|
12031
|
-
const mainJs =
|
|
12491
|
+
const mainJs = realpathSync3(process.argv[1]);
|
|
12032
12492
|
const inClone = findCloneRoot(__dirname2) !== null;
|
|
12033
12493
|
for (const id of ids) {
|
|
12034
12494
|
const h = HARNESSES.find((x) => x.id === id);
|
|
12035
12495
|
if (id === "claude") {
|
|
12036
|
-
const settingsPath =
|
|
12037
|
-
|
|
12038
|
-
console.log(`${
|
|
12496
|
+
const settingsPath = join23(homedir14(), ".claude", "settings.json");
|
|
12497
|
+
mkdirSync14(dirname13(settingsPath), { recursive: true });
|
|
12498
|
+
console.log(`${ui2.mark("ok")} Claude settings (${MCP_TOOL_NAMES.length} REAPER tools allow-listed): ${ensureClaudeSettings(settingsPath)} \u2192 ${ui2.dim(settingsPath.replace(homedir14(), "~"))}`);
|
|
12039
12499
|
if (inClone) {
|
|
12040
|
-
const mcpJsonPath =
|
|
12041
|
-
console.log(createMcpJson(mcpJsonPath, resolve3(process.argv[1])) ? `${
|
|
12500
|
+
const mcpJsonPath = join23(process.cwd(), ".mcp.json");
|
|
12501
|
+
console.log(createMcpJson(mcpJsonPath, resolve3(process.argv[1])) ? `${ui2.mark("ok")} Created: ${ui2.dim(mcpJsonPath)}` : `${ui2.mark("ok")} .mcp.json already exists \u2014 leaving it untouched.`);
|
|
12042
12502
|
continue;
|
|
12043
12503
|
}
|
|
12044
12504
|
}
|
|
12045
12505
|
const r = connectHarness(id, process.execPath, mainJs, env);
|
|
12046
12506
|
if (r.status === "failed") {
|
|
12047
|
-
console.log(`${
|
|
12048
|
-
console.log(` ${
|
|
12507
|
+
console.log(`${ui2.mark("fail")} Could not connect ${ui2.bold(h.name)}: ${r.detail}${found.includes(id) ? "" : ` ${ui2.dim(`(not installed: ${installHint(ui2, h.installHint)})`)}`}`);
|
|
12508
|
+
console.log(` ${ui2.dim("To connect it yourself:")} ${ui2.cmd(r.manual ?? "")}`);
|
|
12049
12509
|
} else {
|
|
12050
12510
|
const what = { connected: "Connected", replaced: "Reconnected (the old entry pointed at files that no longer exist)", already: "Already connected" }[r.status];
|
|
12051
|
-
console.log(`${
|
|
12511
|
+
console.log(`${ui2.mark("ok")} ${what}: ${ui2.bold(h.name)}${id === "claude" && inClone ? "" : ui2.dim(" (works from any folder)")}`);
|
|
12052
12512
|
}
|
|
12053
12513
|
}
|
|
12054
12514
|
await askTelemetryOnce();
|
|
12055
12515
|
if (inClone) {
|
|
12056
12516
|
console.log("\nIf you haven't yet, symlink the skills + knowledge and install the bridge:");
|
|
12057
|
-
console.log(` ${
|
|
12517
|
+
console.log(` ${ui2.cmd("scripts/sync-symlinks.sh")} ${ui2.dim("# mix skills + knowledge \u2192 ~/.claude, skills + agents \u2192 ~/.agents")}`);
|
|
12058
12518
|
} else {
|
|
12059
12519
|
console.log("");
|
|
12060
12520
|
installSkills(false, ids);
|
|
12061
12521
|
if (!chained) console.log("\nIf you haven't yet, install the bridge:");
|
|
12062
12522
|
}
|
|
12063
12523
|
if (!chained) {
|
|
12064
|
-
console.log(` ${
|
|
12524
|
+
console.log(` ${ui2.cmd("reaper-mcp setup")} ${ui2.dim("# Lua bridge + JSFX \u2192 REAPER")}`);
|
|
12065
12525
|
console.log("then start (or restart) REAPER: the bridge starts with it.");
|
|
12066
12526
|
}
|
|
12067
12527
|
if (!inClone) console.log(`
|
|
12068
|
-
Want it to remember plugins and your corrections? Connect LoreKit (free, about five minutes): ${
|
|
12528
|
+
Want it to remember plugins and your corrections? Connect LoreKit (free, about five minutes): ${ui2.link("https://reaper-mcp.vercel.app/docs/connect-lorekit")}`);
|
|
12069
12529
|
console.log(`
|
|
12070
|
-
Try: ${
|
|
12530
|
+
Try: ${ui2.cmd('/mixer "Please gain stage my tracks"')} \xB7 ${ui2.cmd('/critique "Roast my mix"')}`);
|
|
12071
12531
|
}
|
|
12072
12532
|
function installSkills(dryRun = false, ids) {
|
|
12073
12533
|
if (findCloneRoot(__dirname2)) {
|
|
12074
12534
|
console.log("Running from a clone: scripts/sync-symlinks.sh links the skills and knowledge into ~/.claude and ~/.agents.");
|
|
12075
12535
|
return;
|
|
12076
12536
|
}
|
|
12077
|
-
const src =
|
|
12078
|
-
if (!
|
|
12537
|
+
const src = join23(resolveAssetDir(__dirname2, "claude"));
|
|
12538
|
+
if (!existsSync15(src)) {
|
|
12079
12539
|
console.log(`Skills not found: ${src} (this build has no claude/ folder)`);
|
|
12080
12540
|
process.exitCode = 1;
|
|
12081
12541
|
return;
|
|
@@ -12093,21 +12553,21 @@ function installSkills(dryRun = false, ids) {
|
|
|
12093
12553
|
const homes = skillsHomes(targets.length ? targets : ["claude"]);
|
|
12094
12554
|
const verb = dryRun ? "Would install" : "Installed";
|
|
12095
12555
|
const jobs = [];
|
|
12096
|
-
if (homes.claude) jobs.push({ label: "~/.claude", dir:
|
|
12097
|
-
if (homes.agents) jobs.push({ label: "~/.agents", dir:
|
|
12098
|
-
if (homes.agents && !homes.claude) jobs.push({ label: "~/.claude", dir:
|
|
12556
|
+
if (homes.claude) jobs.push({ label: "~/.claude", dir: join23(homedir14(), ".claude"), what: "the mix skills, agents and knowledge" });
|
|
12557
|
+
if (homes.agents) jobs.push({ label: "~/.agents", dir: join23(homedir14(), ".agents"), include: ["skills", "agents"], what: "the mix skills and agents" });
|
|
12558
|
+
if (homes.agents && !homes.claude) jobs.push({ label: "~/.claude", dir: join23(homedir14(), ".claude"), include: ["knowledge"], what: "the knowledge base the skills read" });
|
|
12099
12559
|
for (const job of jobs) {
|
|
12100
12560
|
const r = installClaudeAssets(src, job.dir, { dryRun, include: job.include });
|
|
12101
|
-
console.log(`${
|
|
12561
|
+
console.log(`${ui2.mark("ok")} ${verb} ${job.what} in ${job.label}: ${r.installed.length} new, ${r.updated.length} updated, ${r.unchanged} already current.`);
|
|
12102
12562
|
for (const s of r.skipped) {
|
|
12103
12563
|
const why = { edited: "you changed it, left as is", "not-ours": "already exists and is yours, left as is", symlink: "linked elsewhere, left as is", "broken-symlink": "a link to a folder that no longer exists (a deleted clone?); remove it and run this again" }[s.reason];
|
|
12104
|
-
console.log(
|
|
12564
|
+
console.log(ui2.dim(` Skipped ${s.path}: ${why}`));
|
|
12105
12565
|
}
|
|
12106
12566
|
}
|
|
12107
12567
|
if (!dryRun) console.log("Try /mixer, /critique or /learn-plugin in your harness. (/learn-plugin saves what it learns to LoreKit, see the README.)");
|
|
12108
12568
|
}
|
|
12109
12569
|
function consoleConsentIO() {
|
|
12110
|
-
return { input: process.stdin, output: process.stdout, interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY), ui };
|
|
12570
|
+
return { input: process.stdin, output: process.stdout, interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY), ui: ui2 };
|
|
12111
12571
|
}
|
|
12112
12572
|
var OPT_OUT_COUNTED = 'One anonymous "opted out" count was sent (no install id). Nothing is sent after this.';
|
|
12113
12573
|
async function askTelemetryOnce() {
|
|
@@ -12118,29 +12578,29 @@ async function askTelemetryOnce() {
|
|
|
12118
12578
|
}
|
|
12119
12579
|
function describeTelemetry() {
|
|
12120
12580
|
const { mode, reason } = resolveTelemetry();
|
|
12121
|
-
const label = { default:
|
|
12122
|
-
return `${label} ${
|
|
12581
|
+
const label = { default: ui2.ok("On \u2014 pseudonymous usage data to the developer"), custom: ui2.cmd("Custom \u2014 your own OTEL_* destination"), off: ui2.dim("Off") }[mode];
|
|
12582
|
+
return `${label} ${ui2.dim(`(${reason})`)}`;
|
|
12123
12583
|
}
|
|
12124
12584
|
async function telemetryCommand(sub = "status") {
|
|
12125
12585
|
if (sub !== "on" && sub !== "off" && sub !== "setup" && sub !== "status") {
|
|
12126
|
-
console.log(`Usage: ${
|
|
12586
|
+
console.log(`Usage: ${ui2.cmd("reaper-mcp telemetry")} [status|on|off]`);
|
|
12127
12587
|
process.exitCode = 1;
|
|
12128
12588
|
return;
|
|
12129
12589
|
}
|
|
12130
|
-
if (
|
|
12590
|
+
if (ui2.fancy && sub !== "setup") console.log(ui2.banner("Telemetry", readServiceVersion()));
|
|
12131
12591
|
if (sub === "off" && resolveTelemetry().mode === "default" && !await confirmOptOutPrompt(consoleConsentIO())) return;
|
|
12132
12592
|
if (sub === "on" || sub === "off") {
|
|
12133
12593
|
const change = saveTelemetryChoice(sub === "on");
|
|
12134
12594
|
const counted = change ? await reportConsentChange(change) : false;
|
|
12135
|
-
if (sub === "on") console.log(`${
|
|
12136
|
-
else console.log(`${
|
|
12137
|
-
console.log(`${
|
|
12595
|
+
if (sub === "on") console.log(`${ui2.mark("ok")} Pseudonymous usage telemetry turned ${ui2.ok("on")} \u2014 thank you!`);
|
|
12596
|
+
else console.log(`${ui2.mark("ok")} Telemetry turned ${ui2.bold("off")}. ${counted ? OPT_OUT_COUNTED : "Nothing will be sent."}`);
|
|
12597
|
+
console.log(`${ui2.dim("Restart Claude Code (or run")} ${ui2.cmd("/mcp")}${ui2.dim(") for the running server to pick it up.")}`);
|
|
12138
12598
|
} else if (sub === "setup") {
|
|
12139
|
-
if (!await askTelemetryOnce()) console.log(`${
|
|
12599
|
+
if (!await askTelemetryOnce()) console.log(`${ui2.bold("Telemetry:")} ${describeTelemetry()}`);
|
|
12140
12600
|
return;
|
|
12141
12601
|
}
|
|
12142
|
-
console.log(`${
|
|
12143
|
-
console.log(`What is and isn't collected: ${
|
|
12602
|
+
console.log(`${ui2.bold("Telemetry:")} ${describeTelemetry()}`);
|
|
12603
|
+
console.log(`What is and isn't collected: ${ui2.link(TELEMETRY_DOC_URL)}`);
|
|
12144
12604
|
}
|
|
12145
12605
|
async function doctor() {
|
|
12146
12606
|
const core2 = [];
|
|
@@ -12148,27 +12608,27 @@ async function doctor() {
|
|
|
12148
12608
|
core2.push(
|
|
12149
12609
|
bridgeRunning ? { label: "Lua bridge", status: "ok", detail: "Connected" } : { label: "Lua bridge", status: "fail", detail: "Not detected", fix: "reaper-mcp setup, then run mcp_bridge.lua in REAPER" }
|
|
12150
12610
|
);
|
|
12151
|
-
const readIfExists = (path) =>
|
|
12611
|
+
const readIfExists = (path) => existsSync15(path) ? readFileSync16(path, "utf-8") : null;
|
|
12152
12612
|
core2.push(autostartCheck(
|
|
12153
|
-
readIfExists(
|
|
12154
|
-
readIfExists(
|
|
12613
|
+
readIfExists(join23(getReaperScriptsPath(), "__startup.lua")),
|
|
12614
|
+
readIfExists(join23(getReaperResourcePath(), "reaper-extstate.ini")),
|
|
12155
12615
|
await isReaperRunning()
|
|
12156
12616
|
));
|
|
12157
12617
|
const forcedFlags = flagOverrideCheck();
|
|
12158
12618
|
if (forcedFlags) core2.push(forcedFlags);
|
|
12159
|
-
const globalClaudeDir =
|
|
12160
|
-
const localSkills =
|
|
12161
|
-
const globalSkills =
|
|
12162
|
-
const sharedSkills =
|
|
12619
|
+
const globalClaudeDir = join23(homedir14(), ".claude");
|
|
12620
|
+
const localSkills = existsSync15(join23(process.cwd(), ".claude", "skills", "mixer", "SKILL.md"));
|
|
12621
|
+
const globalSkills = existsSync15(join23(globalClaudeDir, "skills", "mixer", "SKILL.md"));
|
|
12622
|
+
const sharedSkills = existsSync15(join23(homedir14(), ".agents", "skills", "mixer", "SKILL.md"));
|
|
12163
12623
|
core2.push(
|
|
12164
12624
|
localSkills || globalSkills || sharedSkills ? { label: "Mix skills", status: "ok", detail: localSkills ? ".claude/skills" : globalSkills ? "~/.claude/skills" : "~/.agents/skills" } : { label: "Mix skills", status: "fail", detail: "Not linked", fix: findCloneRoot(__dirname2) ? "scripts/sync-symlinks.sh (from your clone)" : "reaper-mcp install-skills" }
|
|
12165
12625
|
);
|
|
12166
|
-
const localKnowledge =
|
|
12167
|
-
const knowledgeLinked = localKnowledge ||
|
|
12626
|
+
const localKnowledge = existsSync15(join23(process.cwd(), ".claude", "knowledge"));
|
|
12627
|
+
const knowledgeLinked = localKnowledge || existsSync15(join23(globalClaudeDir, "knowledge"));
|
|
12168
12628
|
core2.push(
|
|
12169
12629
|
knowledgeLinked ? { label: "Knowledge base", status: "ok", detail: localKnowledge ? ".claude/knowledge" : "~/.claude/knowledge" } : { label: "Knowledge base", status: "fail", detail: "Not linked", fix: findCloneRoot(__dirname2) ? "scripts/sync-symlinks.sh (from your clone)" : "reaper-mcp install-skills" }
|
|
12170
12630
|
);
|
|
12171
|
-
const mcpJsonExists =
|
|
12631
|
+
const mcpJsonExists = existsSync15(join23(process.cwd(), ".mcp.json"));
|
|
12172
12632
|
const harnessEnv = realEnv();
|
|
12173
12633
|
const installed = detectHarnesses(harnessEnv);
|
|
12174
12634
|
const connected = installed.filter((h) => registeredServer(h.id, harnessEnv));
|
|
@@ -12191,11 +12651,11 @@ async function doctor() {
|
|
|
12191
12651
|
status: "info",
|
|
12192
12652
|
detail: { default: "On, pseudonymous \xB7 turn off: reaper-mcp telemetry off", custom: "Your own OTEL_* destination", off: "Off" }[telemetry]
|
|
12193
12653
|
});
|
|
12194
|
-
const sidecarVenvPath =
|
|
12195
|
-
const venvBin =
|
|
12196
|
-
const venvPythonName =
|
|
12197
|
-
const venvPython =
|
|
12198
|
-
const hfCachePath =
|
|
12654
|
+
const sidecarVenvPath = join23(homedir14(), ".reaper-mcp", "sidecar-venv");
|
|
12655
|
+
const venvBin = platform8() === "win32" ? "Scripts" : "bin";
|
|
12656
|
+
const venvPythonName = platform8() === "win32" ? "python.exe" : "python";
|
|
12657
|
+
const venvPython = join23(sidecarVenvPath, venvBin, venvPythonName);
|
|
12658
|
+
const hfCachePath = join23(homedir14(), ".cache", "huggingface", "hub");
|
|
12199
12659
|
let pythonOk = false;
|
|
12200
12660
|
let pythonDetail = "Not found";
|
|
12201
12661
|
try {
|
|
@@ -12212,9 +12672,9 @@ async function doctor() {
|
|
|
12212
12672
|
} catch {
|
|
12213
12673
|
pythonDetail = "Not found";
|
|
12214
12674
|
}
|
|
12215
|
-
const venvExists =
|
|
12675
|
+
const venvExists = existsSync15(sidecarVenvPath);
|
|
12216
12676
|
let depsOk = false;
|
|
12217
|
-
if (venvExists &&
|
|
12677
|
+
if (venvExists && existsSync15(venvPython)) {
|
|
12218
12678
|
try {
|
|
12219
12679
|
await execAsync(`"${venvPython}" -c "import audiobox_aesthetics.infer"`);
|
|
12220
12680
|
depsOk = true;
|
|
@@ -12228,14 +12688,14 @@ async function doctor() {
|
|
|
12228
12688
|
addOns.demucs = found.separation;
|
|
12229
12689
|
addOns.lv_chordia = found.chords;
|
|
12230
12690
|
}
|
|
12231
|
-
const weightsPath =
|
|
12232
|
-
const weightsExist =
|
|
12691
|
+
const weightsPath = join23(hfCachePath, "models--facebook--audiobox-aesthetics");
|
|
12692
|
+
const weightsExist = existsSync15(weightsPath);
|
|
12233
12693
|
const sidecarReady = venvExists && depsOk;
|
|
12234
12694
|
const sidecarOptedIn = venvExists;
|
|
12235
12695
|
const sidecarBroken = sidecarOptedIn && !sidecarReady;
|
|
12236
12696
|
const missing = sidecarOptedIn ? "fail" : "info";
|
|
12237
12697
|
const repair = "reaper-mcp setup-sidecar";
|
|
12238
|
-
const home = (p) => p.replace(
|
|
12698
|
+
const home = (p) => p.replace(homedir14(), "~");
|
|
12239
12699
|
const sidecar = {
|
|
12240
12700
|
title: "Python sidecar",
|
|
12241
12701
|
note: "optional \xB7 lets Claude listen to the audio",
|
|
@@ -12270,8 +12730,8 @@ async function doctor() {
|
|
|
12270
12730
|
const sections3 = [{ title: "Core", checks: core2 }, sidecar];
|
|
12271
12731
|
if (extensionChecks.length > 0) sections3.push({ title: "Extensions", checks: extensionChecks });
|
|
12272
12732
|
const extensionsBroken = extensionChecks.some((c) => c.status === "fail");
|
|
12273
|
-
if (
|
|
12274
|
-
console.log(renderDoctor(sections3, { version: readServiceVersion(), color: useColor(), header: !
|
|
12733
|
+
if (ui2.fancy) console.log(ui2.banner("Doctor", readServiceVersion()));
|
|
12734
|
+
console.log(renderDoctor(sections3, { version: readServiceVersion(), color: useColor(), header: !ui2.fancy }));
|
|
12275
12735
|
return bridgeRunning && knowledgeLinked && mcpRegistered && !sidecarBroken && !extensionsBroken ? 0 : 1;
|
|
12276
12736
|
}
|
|
12277
12737
|
function notifyNewerRelease(log) {
|
|
@@ -12290,7 +12750,7 @@ function repairReaperSide(log) {
|
|
|
12290
12750
|
wwwDir: getReaperWwwPath(),
|
|
12291
12751
|
assetsDir: resolveAssetDir(__dirname2, "reaper"),
|
|
12292
12752
|
wwwSrcDir: resolveAssetDir(__dirname2, "bridge-ui")
|
|
12293
|
-
}, readServiceVersion(), { inClone: findCloneRoot(__dirname2) !== null });
|
|
12753
|
+
}, readServiceVersion(), { inClone: findCloneRoot(__dirname2) !== null, firstInstall: process.env["REAPER_MCP_DISTRIBUTION"] === "plugin" });
|
|
12294
12754
|
} catch (err) {
|
|
12295
12755
|
log(`Could not update REAPER's reaper-mcp files: ${err instanceof Error ? err.message : String(err)}`);
|
|
12296
12756
|
return void 0;
|
|
@@ -12341,7 +12801,7 @@ async function serve() {
|
|
|
12341
12801
|
const version = readServiceVersion();
|
|
12342
12802
|
if (repair.bridgeChanged) startupSpan.setAttribute("reaper.bridge.files_updated", true);
|
|
12343
12803
|
if (repair.autostartAdded) startupSpan.setAttribute("reaper.bridge.autostart_added", true);
|
|
12344
|
-
log(`Updated REAPER's reaper-mcp files from ${repair.from ?? "an earlier release"} to ${version}`);
|
|
12804
|
+
log(repair.firstInstalled ? `Installed REAPER's reaper-mcp files (${version})` : `Updated REAPER's reaper-mcp files from ${repair.from ?? "an earlier release"} to ${version}`);
|
|
12345
12805
|
for (const text9 of repairNotices(repair, version, bridge.state === "connected")) addNotice({ text: text9 });
|
|
12346
12806
|
}
|
|
12347
12807
|
const profile = resolveProfile();
|
|
@@ -12390,12 +12850,12 @@ async function updateCommand(force, bridge) {
|
|
|
12390
12850
|
const cloneRoot = findCloneRoot(__dirname2);
|
|
12391
12851
|
if (cloneRoot) {
|
|
12392
12852
|
return new Promise((resolveCode) => {
|
|
12393
|
-
const child =
|
|
12853
|
+
const child = spawn4("bash", ["./scripts/update.sh"], { cwd: cloneRoot, stdio: "inherit" });
|
|
12394
12854
|
child.on("error", () => resolveCode(1));
|
|
12395
12855
|
child.on("close", (code) => resolveCode(code ?? 1));
|
|
12396
12856
|
});
|
|
12397
12857
|
}
|
|
12398
|
-
return runUpdate(realUpdateDeps(readServiceVersion(),
|
|
12858
|
+
return runUpdate(realUpdateDeps(readServiceVersion(), join23(__dirname2, "main.js"), force, bridge));
|
|
12399
12859
|
}
|
|
12400
12860
|
var command = process.argv[2];
|
|
12401
12861
|
switch (command) {
|
|
@@ -12441,6 +12901,15 @@ switch (command) {
|
|
|
12441
12901
|
case "flags":
|
|
12442
12902
|
process.exit(flagsCommand(process.argv.slice(3)));
|
|
12443
12903
|
break;
|
|
12904
|
+
case "instance":
|
|
12905
|
+
instanceCommand(process.argv.slice(3)).then(
|
|
12906
|
+
(code) => process.exit(code),
|
|
12907
|
+
(err) => {
|
|
12908
|
+
console.error(err instanceof Error ? err.message : err);
|
|
12909
|
+
process.exit(1);
|
|
12910
|
+
}
|
|
12911
|
+
);
|
|
12912
|
+
break;
|
|
12444
12913
|
case "extension":
|
|
12445
12914
|
case "extensions":
|
|
12446
12915
|
extensionCommand(process.argv.slice(3)).then(
|
|
@@ -12461,7 +12930,7 @@ switch (command) {
|
|
|
12461
12930
|
(async () => {
|
|
12462
12931
|
const status = await getBridgeState();
|
|
12463
12932
|
const running = status.state === "connected";
|
|
12464
|
-
console.log(`Bridge status: ${running ?
|
|
12933
|
+
console.log(`Bridge status: ${running ? ui2.ok("CONNECTED") : ui2.fail(`NOT DETECTED (${status.state})`)}`);
|
|
12465
12934
|
if (!running) console.log(bridgeDownMessage(status));
|
|
12466
12935
|
process.exit(running ? 0 : 1);
|
|
12467
12936
|
})();
|
|
@@ -12488,6 +12957,8 @@ Usage:
|
|
|
12488
12957
|
Agents/CI: --yes (core + aesthetics weights), --all, --with-separation (Demucs),
|
|
12489
12958
|
--with-chords (chord model), --without-aesthetics, --list [--json] (what is installed)
|
|
12490
12959
|
reaper-mcp extension Manage opt-in extensions: list | add <name|folder|git-url> | link <folder> | remove <name> | new <name>
|
|
12960
|
+
reaper-mcp instance A second REAPER for the agent to work in while you work in yours: create <name> | start <name> [project.rpp] |
|
|
12961
|
+
connect <name> | stop <name> | list | remove <name>
|
|
12491
12962
|
reaper-mcp init Connect the harnesses you have installed (Claude Code, Codex CLI, Gemini CLI, Cursor) and suggest the ones you don't;
|
|
12492
12963
|
--harness claude,codex or --all to pick by hand. From npm it also installs the skills
|
|
12493
12964
|
reaper-mcp install-skills Copy the mix skills, agents and knowledge into ~/.claude, and skills + agents into ~/.agents for the
|