rushes 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +5 -5
- package/README.md +47 -1
- package/dist/cli/main.js +4 -2
- package/dist/core/agentActivity.js +171 -0
- package/dist/core/agentRules.js +193 -0
- package/dist/core/alwaysLabel.js +8 -0
- package/dist/core/noteState.js +31 -2
- package/dist/core/notes.js +19 -3
- package/dist/core/projectFolder.js +23 -0
- package/dist/core/schema.js +60 -2
- package/dist/core/store.js +23 -3
- package/dist/mcp/stdio.js +16 -12
- package/dist/mcp/tools.js +13 -1
- package/dist/server/agent/acp.js +162 -0
- package/dist/server/agent/adapters.js +102 -0
- package/dist/server/agent/broker.js +111 -0
- package/dist/server/agent/detect.js +44 -0
- package/dist/server/agent/followUp.js +30 -0
- package/dist/server/agent/notify.js +54 -0
- package/dist/server/agent/ownTools.js +88 -0
- package/dist/server/agent/rpc.js +126 -0
- package/dist/server/agent/rules.js +105 -0
- package/dist/server/agent/runner.js +1031 -0
- package/dist/server/agent/seenCalls.js +48 -0
- package/dist/server/agent/terminal.js +27 -0
- package/dist/server/app.js +182 -5
- package/dist/server/start.js +83 -4
- package/dist/version.js +2 -0
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +4 -4
- package/web-dist/assets/{index-DebHxWrg.css → index-BIJlv6zN.css} +1 -1
- package/web-dist/assets/index-D430jOsg.js +70 -0
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-D-520-nU.js +0 -67
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { real } from "./agentRules.js";
|
|
4
|
+
/**
|
|
5
|
+
* `project` against the launch folder. A leading "~" or "~/" is the home folder, as a shell would
|
|
6
|
+
* read it: agents write paths that way, and resolve() alone would make a folder called "~" in the
|
|
7
|
+
* working directory.
|
|
8
|
+
*/
|
|
9
|
+
export function projectPath(defaultRoot, project = ".") {
|
|
10
|
+
const fromHome = project === "~" || /^~[\\/]/.test(project);
|
|
11
|
+
return resolve(defaultRoot, fromHome ? join(homedir(), project.slice(2)) : project);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* R17: true when a tool's `project` argument names `root` itself: left out, or a string that resolves to the same
|
|
15
|
+
* folder, symlinks resolved. Anything else (another folder, a non-string) is false.
|
|
16
|
+
*/
|
|
17
|
+
export function isProjectRoot(root, project) {
|
|
18
|
+
if (project === undefined)
|
|
19
|
+
return true;
|
|
20
|
+
if (typeof project !== "string")
|
|
21
|
+
return false;
|
|
22
|
+
return real(projectPath(root, project)) === real(root);
|
|
23
|
+
}
|
package/dist/core/schema.js
CHANGED
|
@@ -196,7 +196,18 @@ export function markLabel(m) {
|
|
|
196
196
|
const label = m.kind === "rise" ? "Rise" : m.kind === "fall" ? "Fall" : m.kind === "louder" ? "Louder" : "Quieter";
|
|
197
197
|
return m.db === undefined ? label : `${label} ${m.db} dB`;
|
|
198
198
|
}
|
|
199
|
-
|
|
199
|
+
/** One message in a note's thread: the agent's reply or the user's answer. No length cap here, so stored data always loads; a user's answer is capped where it comes in (addUserReply). */
|
|
200
|
+
export const ReplySchema = z.object({ by: z.enum(["agent", "user"]), text: z.string().trim().min(1), at: z.string() });
|
|
201
|
+
/** A note from before threads: its one `reply` becomes the thread's first entry, stamped with the note's createdAt. */
|
|
202
|
+
function withThread(raw) {
|
|
203
|
+
if (typeof raw !== "object" || raw === null || "replies" in raw)
|
|
204
|
+
return raw;
|
|
205
|
+
const o = raw;
|
|
206
|
+
if (typeof o.reply !== "string" || o.reply.trim() === "" || typeof o.createdAt !== "string")
|
|
207
|
+
return raw;
|
|
208
|
+
return { ...o, replies: [{ by: "agent", text: o.reply, at: o.createdAt }] };
|
|
209
|
+
}
|
|
210
|
+
export const NoteSchema = z.preprocess(withThread, z
|
|
200
211
|
.object({
|
|
201
212
|
id,
|
|
202
213
|
stage: StageSchema,
|
|
@@ -227,6 +238,7 @@ export const NoteSchema = z
|
|
|
227
238
|
format: z.string().max(16).regex(FORMAT_ID_RE).nullable().default(null),
|
|
228
239
|
status: z.enum(["todo", "done"]).default("todo"),
|
|
229
240
|
reply: z.string().default(""),
|
|
241
|
+
replies: z.array(ReplySchema).default([]),
|
|
230
242
|
fixT: seconds.nullable().default(null),
|
|
231
243
|
fixVersion: z.string().nullable().default(null),
|
|
232
244
|
batch: z.string().nullable().default(null),
|
|
@@ -268,7 +280,7 @@ export const NoteSchema = z
|
|
|
268
280
|
}
|
|
269
281
|
seenKinds.add(m.kind);
|
|
270
282
|
}
|
|
271
|
-
});
|
|
283
|
+
}));
|
|
272
284
|
export const NotesFileSchema = fileObject({
|
|
273
285
|
schema: z.literal(1),
|
|
274
286
|
rev: z.number().int().nonnegative(),
|
|
@@ -494,6 +506,51 @@ export const VisualsFileSchema = fileObject({
|
|
|
494
506
|
rev: z.number().int().nonnegative(),
|
|
495
507
|
visuals: z.array(VisualSchema).default([]),
|
|
496
508
|
});
|
|
509
|
+
// Send to AI: the agent's own settings in the project. Holds no secret: only whether it is on, which agent, and the
|
|
510
|
+
// session to resume. What the agent may do unasked (AgentRules) is kept outside the project (R10), where the agent
|
|
511
|
+
// can't change it.
|
|
512
|
+
export const AGENTS = ["claude", "codex"];
|
|
513
|
+
/** What the agent may do without asking: edit files in the project (the default), or ask for everything. */
|
|
514
|
+
export const AgentPermissionsSchema = z.enum(["project-edits", "ask-all"]);
|
|
515
|
+
export const AlwaysRuleSchema = z.object({ kind: z.string().max(32), command: z.string().max(200).nullable() });
|
|
516
|
+
/** At most this many Always rules are kept; a longer list read from disk keeps its newest ones. */
|
|
517
|
+
export const ALWAYS_KEPT = 50;
|
|
518
|
+
const AgentSettingsShape = fileObject({
|
|
519
|
+
schema: z.literal(1),
|
|
520
|
+
rev: z.number().int(),
|
|
521
|
+
on: z.boolean().default(false),
|
|
522
|
+
agent: z.enum(AGENTS).nullable().default(null),
|
|
523
|
+
session: fileObject({ id: z.string(), agent: z.enum(AGENTS), startedAt: z.string() }).nullable().default(null),
|
|
524
|
+
});
|
|
525
|
+
/**
|
|
526
|
+
* R10: `always` and `permissions` in a project's agent.json (as an older build kept them) are never read: the agent
|
|
527
|
+
* could have written them. Nor is `asked` (I1: the first-Send sheet's answer, kept by Plan 1 builds): the user's rules
|
|
528
|
+
* file keeps that now. All three are dropped on read, so the next write leaves them out.
|
|
529
|
+
*/
|
|
530
|
+
export const AgentSettingsSchema = AgentSettingsShape.transform((s) => {
|
|
531
|
+
const { always: _always, permissions: _permissions, asked: _asked, ...rest } = s;
|
|
532
|
+
return rest;
|
|
533
|
+
});
|
|
534
|
+
/** R10: what the agent may do without asking, kept per user outside the project (server/agent/rules.ts). */
|
|
535
|
+
export const AgentRulesSchema = z.object({
|
|
536
|
+
permissions: AgentPermissionsSchema.default("project-edits"),
|
|
537
|
+
always: z.array(AlwaysRuleSchema).max(ALWAYS_KEPT).default([]),
|
|
538
|
+
/** I1: the user answered the first-Send sheet for this project (an agent, or Copy a prompt), so Send doesn't ask again. */
|
|
539
|
+
setUp: z.boolean().default(false),
|
|
540
|
+
/**
|
|
541
|
+
* The consent (consent fix): the agent the user turned Send to AI on for, in the sheet, the menu or the switch. Null
|
|
542
|
+
* after Copy a prompt or switching off. Nothing is handed over, and the desk shows Send to AI off, unless the project's
|
|
543
|
+
* agent.json is on for this same agent: a project folder from someone else, or anything that writes it, can't choose.
|
|
544
|
+
*/
|
|
545
|
+
agent: z.enum(AGENTS).nullable().default(null),
|
|
546
|
+
});
|
|
547
|
+
/** Read leniently: a longer list keeps its newest ALWAYS_KEPT rules rather than failing (M8). */
|
|
548
|
+
export const AgentRulesReadSchema = z.object({
|
|
549
|
+
permissions: AgentPermissionsSchema.default("project-edits"),
|
|
550
|
+
always: z.array(AlwaysRuleSchema).default([]).transform((a) => a.slice(-ALWAYS_KEPT)),
|
|
551
|
+
setUp: z.boolean().default(false),
|
|
552
|
+
agent: z.enum(AGENTS).nullable().default(null),
|
|
553
|
+
});
|
|
497
554
|
export const FILES = {
|
|
498
555
|
project: { name: "project.json", schema: ProjectSchema },
|
|
499
556
|
script: { name: "script.json", schema: ScriptSchema },
|
|
@@ -507,4 +564,5 @@ export const FILES = {
|
|
|
507
564
|
storyboard: { name: "storyboard.json", schema: BriefStateSchema },
|
|
508
565
|
// §25.3: created by its first write, like the brief's.
|
|
509
566
|
visuals: { name: "visuals.json", schema: VisualsFileSchema },
|
|
567
|
+
agent: { name: "agent.json", schema: AgentSettingsSchema },
|
|
510
568
|
};
|
package/dist/core/store.js
CHANGED
|
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { FILES } from "./schema.js";
|
|
5
5
|
import { CorruptFileError, InvalidError, RevConflictError } from "./errors.js";
|
|
6
6
|
export const RUSHES_DIR = ".rushes";
|
|
7
|
-
const GITIGNORE = "proxies/\npeaks/\nserver.json\nserver.log\nlog.json.bad*\n*.tmp\n*.bak\n";
|
|
7
|
+
const GITIGNORE = "proxies/\npeaks/\nserver.json\nserver.log\nagent.json\nlog.json.bad*\n*.tmp\n*.bak\n";
|
|
8
8
|
function defaults(key, name) {
|
|
9
9
|
switch (key) {
|
|
10
10
|
case "project":
|
|
@@ -26,13 +26,15 @@ function defaults(key, name) {
|
|
|
26
26
|
return { schema: 1, rev: 0, baseline: "", seen: "" };
|
|
27
27
|
case "visuals":
|
|
28
28
|
return { schema: 1, rev: 0, visuals: [] };
|
|
29
|
+
case "agent":
|
|
30
|
+
return { schema: 1, rev: 0, on: false, agent: null, session: null };
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
34
|
* Files `init` doesn't write (found.json, log.json, brief.json, storyboard.json). Each is created by its first write, and reads
|
|
33
35
|
* as its default until then, so a project made before the file existed needs nothing done to it.
|
|
34
36
|
*/
|
|
35
|
-
const CREATED_ON_WRITE = new Set(["found", "log", "brief", "storyboard", "visuals"]);
|
|
37
|
+
const CREATED_ON_WRITE = new Set(["found", "log", "brief", "storyboard", "visuals", "agent"]);
|
|
36
38
|
/**
|
|
37
39
|
* The only writer of a project's .rushes folder. Every write is validated,
|
|
38
40
|
* serialised per file, written atomically (tmp + rename) and announced with
|
|
@@ -54,7 +56,7 @@ export class Store extends EventEmitter {
|
|
|
54
56
|
}
|
|
55
57
|
async init(name) {
|
|
56
58
|
await mkdir(join(this.dir, "grabs"), { recursive: true });
|
|
57
|
-
await
|
|
59
|
+
await ensureIgnoreLines(join(this.dir, ".gitignore"), GITIGNORE);
|
|
58
60
|
for (const key of Object.keys(FILES)) {
|
|
59
61
|
if (CREATED_ON_WRITE.has(key))
|
|
60
62
|
continue;
|
|
@@ -146,6 +148,24 @@ async function atomicWrite(path, text) {
|
|
|
146
148
|
await writeFile(tmp, text, "utf8");
|
|
147
149
|
await rename(tmp, path);
|
|
148
150
|
}
|
|
151
|
+
/** Write the ignore file, or append the lines an older one lacks. Other lines and their order are kept. */
|
|
152
|
+
async function ensureIgnoreLines(path, wanted) {
|
|
153
|
+
let have;
|
|
154
|
+
try {
|
|
155
|
+
have = await readFile(path, "utf8");
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
if (e.code !== "ENOENT")
|
|
159
|
+
throw e;
|
|
160
|
+
await writeFile(path, wanted, "utf8");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const present = new Set(have.split(/\r?\n/).map((l) => l.trim()));
|
|
164
|
+
const missing = wanted.split("\n").filter((l) => l && !present.has(l));
|
|
165
|
+
if (!missing.length)
|
|
166
|
+
return;
|
|
167
|
+
await writeFile(path, (have === "" || have.endsWith("\n") ? have : have + "\n") + missing.join("\n") + "\n", "utf8");
|
|
168
|
+
}
|
|
149
169
|
async function writeIfMissing(path, text) {
|
|
150
170
|
try {
|
|
151
171
|
await access(path);
|
package/dist/mcp/stdio.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import { dirname,
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { createMcpServer } from "./tools.js";
|
|
6
6
|
import { ensureServer } from "./ensure.js";
|
|
7
7
|
import { runDoctor, realDoctorEnv } from "../cli/doctor.js";
|
|
8
|
+
import { isProjectRoot, projectPath } from "../core/projectFolder.js";
|
|
8
9
|
export function openBrowser(url) {
|
|
9
10
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
10
11
|
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
@@ -33,24 +34,27 @@ export function resolveDoctorRoot(defaultRoot, project) {
|
|
|
33
34
|
return projectPath(defaultRoot, project);
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* R17: for a pinned server (the one Send to AI hands its agent, `rushes mcp <root> --pinned`), the only folder a
|
|
38
|
+
* tool may name is `root`: `project` left out, or resolving to it (symlinks resolved). Anything else throws, and the
|
|
39
|
+
* tool returns that as its error, so an auto-allowed rushes_* call can't write .rushes/ into another folder.
|
|
39
40
|
*/
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
export function pinnedRoot(root, project) {
|
|
42
|
+
if (!isProjectRoot(root, project))
|
|
43
|
+
throw new Error(`This Rushes MCP server only works on ${root}. Leave "project" out, or pass that folder.`);
|
|
44
|
+
return root;
|
|
43
45
|
}
|
|
44
46
|
/** The tool context runStdio uses. */
|
|
45
|
-
export function stdioContext(defaultRoot, ensure) {
|
|
47
|
+
export function stdioContext(defaultRoot, ensure, opts = {}) {
|
|
48
|
+
const forTool = opts.pinned ? (p) => pinnedRoot(defaultRoot, p) : (p) => resolveProjectRoot(defaultRoot, p);
|
|
49
|
+
const forDoctor = opts.pinned ? (p) => pinnedRoot(defaultRoot, p) : (p) => resolveDoctorRoot(defaultRoot, p);
|
|
46
50
|
return {
|
|
47
|
-
client: async (project) => ensureServer(
|
|
51
|
+
client: async (project) => ensureServer(forTool(project), ensure),
|
|
48
52
|
openBrowser,
|
|
49
|
-
doctor: async (project) => runDoctor(realDoctorEnv(
|
|
53
|
+
doctor: async (project) => runDoctor(realDoctorEnv(forDoctor(project))),
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
/** Run the MCP server over stdio. Projects default to the directory the agent launched it in. */
|
|
53
|
-
export async function runStdio(defaultRoot = process.cwd()) {
|
|
54
|
-
const server = createMcpServer(stdioContext(defaultRoot));
|
|
57
|
+
export async function runStdio(defaultRoot = process.cwd(), opts = {}) {
|
|
58
|
+
const server = createMcpServer(stdioContext(defaultRoot, undefined, opts));
|
|
55
59
|
await server.connect(new StdioServerTransport());
|
|
56
60
|
}
|
package/dist/mcp/tools.js
CHANGED
|
@@ -157,7 +157,7 @@ export function createMcpServer(ctx) {
|
|
|
157
157
|
project,
|
|
158
158
|
video: z.string().describe("Video id or name, e.g. \"Hero 60s\"."),
|
|
159
159
|
file: z.string().describe("Path to the rendered file, absolute or relative to the project."),
|
|
160
|
-
note: z.string().optional().describe("What changed in this cut."),
|
|
160
|
+
note: z.string().optional().describe("What changed in this cut: one short summary line, then a \"- \" line for each change (the Cut menu shows it as points)."),
|
|
161
161
|
label: z
|
|
162
162
|
.string()
|
|
163
163
|
// Counted as the route counts it: on one clean line (padding and invisible characters don't count), in characters.
|
|
@@ -346,6 +346,18 @@ export function createMcpServer(ctx) {
|
|
|
346
346
|
.min(1),
|
|
347
347
|
},
|
|
348
348
|
}, safe(async ({ project, replies }) => (await ctx.client(project)).post("/api/replies", { replies })));
|
|
349
|
+
server.registerTool("rushes_working_on", {
|
|
350
|
+
title: "Say what you are working on",
|
|
351
|
+
description: "Say which note you are working on now and what you are doing, in a few plain words, before you start on it. Only for a note that was sent to you. The user sees it on the note while you work.",
|
|
352
|
+
inputSchema: {
|
|
353
|
+
project,
|
|
354
|
+
note: z.string().min(1).describe("The note's id."),
|
|
355
|
+
doing: z.string().min(1).max(200).describe('What you are doing, e.g. "Moving the title up".'),
|
|
356
|
+
},
|
|
357
|
+
}, safe(async ({ project, note, doing }) => {
|
|
358
|
+
await (await ctx.client(project)).post("/api/agent/working-on", { note, doing });
|
|
359
|
+
return { ok: true, note, doing };
|
|
360
|
+
}));
|
|
349
361
|
server.registerTool("rushes_list_assets", {
|
|
350
362
|
title: "List assets",
|
|
351
363
|
description: "Every file in the project: cuts, voice reads, older VO takes, music, SFX and screenshots, with absolute paths. Use it to find a screenshot the user grabbed.",
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import { RpcPeer } from "./rpc.js";
|
|
4
|
+
import { VERSION } from "../../version.js";
|
|
5
|
+
const STDERR_TAIL = 4096;
|
|
6
|
+
/** A prompt response's AIR session failure (codex-acp), when it is an error with words: its title. */
|
|
7
|
+
export function sessionFailureOf(response) {
|
|
8
|
+
const f = response?._meta?.jetbrains?.air?.sessionFailure;
|
|
9
|
+
if (!f || f.severity !== "error" || typeof f.title !== "string" || f.title.trim() === "")
|
|
10
|
+
return null;
|
|
11
|
+
return f.title;
|
|
12
|
+
}
|
|
13
|
+
const KILL_GRACE_MS = 2000;
|
|
14
|
+
const CANCELLED = { outcome: "cancelled" };
|
|
15
|
+
function modeIds(result) {
|
|
16
|
+
const list = result?.modes?.availableModes;
|
|
17
|
+
return Array.isArray(list) ? list.map((m) => String(m.id)) : [];
|
|
18
|
+
}
|
|
19
|
+
/** The session's current mode as the setup response reports it, or null. */
|
|
20
|
+
function currentMode(result) {
|
|
21
|
+
const id = result?.modes?.currentModeId;
|
|
22
|
+
return typeof id === "string" ? id : null;
|
|
23
|
+
}
|
|
24
|
+
/** One running ACP adapter child process and the JSON-RPC conversation with it. */
|
|
25
|
+
export class AcpConnection extends EventEmitter {
|
|
26
|
+
child;
|
|
27
|
+
rpc;
|
|
28
|
+
stderr = "";
|
|
29
|
+
exited = false;
|
|
30
|
+
get hasExited() { return this.exited; }
|
|
31
|
+
killTimer = null;
|
|
32
|
+
permissionHandler = null;
|
|
33
|
+
openAsks = new Map();
|
|
34
|
+
constructor(child) {
|
|
35
|
+
super();
|
|
36
|
+
this.child = child;
|
|
37
|
+
this.rpc = new RpcPeer(child.stdout, child.stdin);
|
|
38
|
+
child.stderr.setEncoding("utf8");
|
|
39
|
+
child.stderr.on("data", (d) => {
|
|
40
|
+
this.stderr = (this.stderr + d).slice(-STDERR_TAIL);
|
|
41
|
+
});
|
|
42
|
+
this.rpc.onNotification("session/update", (p) => {
|
|
43
|
+
if (!p?.update)
|
|
44
|
+
return;
|
|
45
|
+
// A throwing "update" listener must never reach the host process: log once and carry on.
|
|
46
|
+
try {
|
|
47
|
+
this.emit("update", p.update);
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
console.error(`[rushes] an "update" listener threw: ${err instanceof Error ? err.message : String(err)}`);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.rpc.onRequest("session/request_permission", (p) => this.askPermission(p));
|
|
54
|
+
let done = false;
|
|
55
|
+
const finish = (code, label) => {
|
|
56
|
+
if (done)
|
|
57
|
+
return;
|
|
58
|
+
done = true;
|
|
59
|
+
this.exited = true;
|
|
60
|
+
if (this.killTimer)
|
|
61
|
+
clearTimeout(this.killTimer);
|
|
62
|
+
this.killTimer = null;
|
|
63
|
+
this.rpc.close(new Error(`Agent adapter ${label}`));
|
|
64
|
+
// Nobody is left to answer these; settle them and drop the bookkeeping.
|
|
65
|
+
for (const set of [...this.openAsks.values()])
|
|
66
|
+
for (const settle of [...set])
|
|
67
|
+
settle(CANCELLED);
|
|
68
|
+
this.openAsks.clear();
|
|
69
|
+
this.emit("exit", { code, stderr: this.stderr });
|
|
70
|
+
};
|
|
71
|
+
// "close", not "exit": stderr is fully read by then, so the tail is complete.
|
|
72
|
+
child.on("close", (code, signal) => finish(code, signal ? `was stopped by ${signal} (exit code ${code})` : `exited with code ${code}`));
|
|
73
|
+
child.on("error", (err) => finish(null, `failed to start: ${err.message} (exit code null)`));
|
|
74
|
+
}
|
|
75
|
+
static start(spec) {
|
|
76
|
+
const child = spawn(spec.command, spec.args, {
|
|
77
|
+
cwd: spec.cwd,
|
|
78
|
+
env: { ...process.env, ...spec.env },
|
|
79
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
80
|
+
detached: false,
|
|
81
|
+
});
|
|
82
|
+
return new AcpConnection(child);
|
|
83
|
+
}
|
|
84
|
+
/** `meta` goes in as clientCapabilities._meta, for an adapter's own extensions (adapters.ts clientMeta). */
|
|
85
|
+
async initialize(meta) {
|
|
86
|
+
const r = await this.rpc.request("initialize", {
|
|
87
|
+
protocolVersion: 1,
|
|
88
|
+
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false, ...(meta ? { _meta: meta } : {}) },
|
|
89
|
+
clientInfo: { name: "rushes", version: VERSION },
|
|
90
|
+
});
|
|
91
|
+
return { loadSession: r?.agentCapabilities?.loadSession === true };
|
|
92
|
+
}
|
|
93
|
+
/** `extra` is merged into the request's params (an adapter's own setup fields, such as Claude's configOptions). */
|
|
94
|
+
async newSession(cwd, mcp, extra = {}) {
|
|
95
|
+
const r = await this.rpc.request("session/new", { cwd, mcpServers: mcp, ...extra });
|
|
96
|
+
return { sessionId: String(r.sessionId), modes: modeIds(r), current: currentMode(r) };
|
|
97
|
+
}
|
|
98
|
+
async loadSession(id, cwd, mcp, extra = {}) {
|
|
99
|
+
const r = await this.rpc.request("session/load", { sessionId: id, cwd, mcpServers: mcp, ...extra });
|
|
100
|
+
return { modes: modeIds(r), current: currentMode(r) };
|
|
101
|
+
}
|
|
102
|
+
async setMode(sessionId, modeId) {
|
|
103
|
+
await this.rpc.request("session/set_mode", { sessionId, modeId });
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* `failure`: the turn failed although its stopReason says end_turn, as codex-acp 2.7.0 reports a model or service error
|
|
107
|
+
* to a client that takes AIR session failures: `_meta.jetbrains.air.sessionFailure` with severity "error" and its
|
|
108
|
+
* words as `title`. Null otherwise.
|
|
109
|
+
*/
|
|
110
|
+
async prompt(sessionId, text) {
|
|
111
|
+
const r = await this.rpc.request("session/prompt", { sessionId, prompt: [{ type: "text", text }] });
|
|
112
|
+
return { stopReason: String(r?.stopReason ?? "end_turn"), failure: sessionFailureOf(r) };
|
|
113
|
+
}
|
|
114
|
+
/** Sends session/cancel and answers every permission ask still open for that session as cancelled. */
|
|
115
|
+
cancel(sessionId) {
|
|
116
|
+
this.rpc.notify("session/cancel", { sessionId });
|
|
117
|
+
const asks = this.openAsks.get(sessionId);
|
|
118
|
+
if (asks)
|
|
119
|
+
for (const settle of [...asks])
|
|
120
|
+
settle(CANCELLED);
|
|
121
|
+
}
|
|
122
|
+
onPermission(fn) {
|
|
123
|
+
this.permissionHandler = fn;
|
|
124
|
+
}
|
|
125
|
+
/** SIGTERM now, SIGKILL after 2 s if the child is still there. */
|
|
126
|
+
kill() {
|
|
127
|
+
if (this.exited || this.killTimer)
|
|
128
|
+
return;
|
|
129
|
+
this.child.kill("SIGTERM");
|
|
130
|
+
this.killTimer = setTimeout(() => {
|
|
131
|
+
this.killTimer = null;
|
|
132
|
+
if (!this.exited)
|
|
133
|
+
this.child.kill("SIGKILL");
|
|
134
|
+
}, KILL_GRACE_MS);
|
|
135
|
+
this.killTimer.unref();
|
|
136
|
+
}
|
|
137
|
+
askPermission(params) {
|
|
138
|
+
const sessionId = params.sessionId;
|
|
139
|
+
return new Promise((resolve) => {
|
|
140
|
+
let settled = false;
|
|
141
|
+
const settle = (o) => {
|
|
142
|
+
if (settled)
|
|
143
|
+
return;
|
|
144
|
+
settled = true;
|
|
145
|
+
const open = this.openAsks.get(sessionId);
|
|
146
|
+
open?.delete(settle);
|
|
147
|
+
if (open && open.size === 0)
|
|
148
|
+
this.openAsks.delete(sessionId);
|
|
149
|
+
resolve({ outcome: o });
|
|
150
|
+
};
|
|
151
|
+
let set = this.openAsks.get(sessionId);
|
|
152
|
+
if (!set)
|
|
153
|
+
this.openAsks.set(sessionId, (set = new Set()));
|
|
154
|
+
set.add(settle);
|
|
155
|
+
const handler = this.permissionHandler;
|
|
156
|
+
if (!handler)
|
|
157
|
+
return settle(CANCELLED);
|
|
158
|
+
// A handler that throws or rejects gives the agent "cancelled", never an RPC error.
|
|
159
|
+
Promise.resolve().then(() => handler(params)).then(settle, () => settle(CANCELLED));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { searchPath } from "./detect.js";
|
|
4
|
+
import { RUSHES_SERVER } from "./ownTools.js";
|
|
5
|
+
/*
|
|
6
|
+
* Checked 17 Nov 2026 with `npm view <pkg> version`:
|
|
7
|
+
* @agentclientprotocol/claude-agent-acp 0.107.3 (used)
|
|
8
|
+
* @agentclientprotocol/codex-acp 2.7.0 (used)
|
|
9
|
+
* older names, not used: @zed-industries/claude-code-acp 0.16.2, @zed-industries/claude-agent-acp 0.23.1,
|
|
10
|
+
* @zed-industries/codex-acp 0.16.0
|
|
11
|
+
* The Claude adapter's README says to set CLAUDE_CODE_EXECUTABLE to use a Claude CLI you already have.
|
|
12
|
+
* The Codex adapter's README names CODEX_PATH for the same purpose.
|
|
13
|
+
* Pinned exactly; run through `npx -y <pkg>@<version>`.
|
|
14
|
+
*/
|
|
15
|
+
export const ADAPTERS = {
|
|
16
|
+
claude: { pkg: "@agentclientprotocol/claude-agent-acp", version: "0.107.3" },
|
|
17
|
+
codex: { pkg: "@agentclientprotocol/codex-acp", version: "2.7.0" },
|
|
18
|
+
};
|
|
19
|
+
/*
|
|
20
|
+
* R14/R15: the session mode in which the agent asks Rushes (session/request_permission) before it acts, instead of
|
|
21
|
+
* approving its own actions. The runner sends session/set_mode with it after every session/new and session/load,
|
|
22
|
+
* when the session offers it. Never acceptEdits, auto, bypassPermissions or dontAsk (Claude), nor agent or
|
|
23
|
+
* agent-full-access (Codex): in those the agent, or its own reviewer, decides.
|
|
24
|
+
*
|
|
25
|
+
* Claude (claude-agent-acp 0.107.3, read 17 Nov 2026):
|
|
26
|
+
* - dist/session-mode.js:47-48: with no permissions.defaultMode in the user's settings a session starts in `auto`
|
|
27
|
+
* ("Claude handles permission decisions", :312) when the catalog offers it. That is F1.
|
|
28
|
+
* - `default` is "Manual: Always ask before making changes" (dist/session-mode.js:290-292). In it Claude Code calls
|
|
29
|
+
* the adapter's canUseTool for every action its own rules don't already allow, and canUseTool always ends in
|
|
30
|
+
* requestPermissionFromClient, i.e. session/request_permission (dist/v1/acp-agent.js:6608-6710; :6646 "Do not
|
|
31
|
+
* auto-allow here based on the session's advertised mode"). The user's own allow rules still win (F3).
|
|
32
|
+
* - No env var or launch flag sets the initial mode (the only env the adapter reads is listed in its README and
|
|
33
|
+
* dist; none is a mode). The setup requests take `configOptions` instead (the "Session options" RFD,
|
|
34
|
+
* dist/initial-config-options.js; advertised as sessionCapabilities.options, dist/v1/acp-agent.js:531-532):
|
|
35
|
+
* session/new and session/load apply them before they answer (dist/v1/acp-agent.js:601-611, 767-783, via
|
|
36
|
+
* selectSessionConfigOption :5753, config id "mode" = MODE_CONFIG_ID, dist/session-mode.js:5). So no prompt
|
|
37
|
+
* ever runs in `auto`; the set_mode after it is the second guard.
|
|
38
|
+
*/
|
|
39
|
+
export const ASK_MODE = {
|
|
40
|
+
claude: "default",
|
|
41
|
+
/*
|
|
42
|
+
* Codex (codex-acp 2.7.0, read 17 Nov 2026; docs/permission-profiles.md is not in the published package, so this
|
|
43
|
+
* is from its README and dist/index.js):
|
|
44
|
+
* - README:76 names INITIAL_AGENT_MODE: read-only, workspace-write, agent, agent-full-access, permission-profile:<id>.
|
|
45
|
+
* dist/index.js:42225-42229 reads it at every session open; an unknown id falls back to `agent`.
|
|
46
|
+
* - The default is `agent` (dist/index.js:42151), "Auto review": approvalsReviewer "auto_review" (:42125-42140),
|
|
47
|
+
* the Guardian Review seen in F2 (:35577). `agent-full-access` has approvalPolicy "never". Neither asks Rushes.
|
|
48
|
+
* - `read-only` (:42096-42108): approvalPolicy "on-request", approvalsReviewer "user", read-only sandbox,
|
|
49
|
+
* "Requires approval to edit files and access the internet." (:42099). With reviewer "user" the app-server's
|
|
50
|
+
* approval requests reach CodexApprovalHandler (:40127), which sends session/request_permission for commands
|
|
51
|
+
* (:40138) and file changes (:40166, :40211-40216). A file change arrives as kind "edit" with its paths as
|
|
52
|
+
* locations (FileChangeReporter.permission, :35234), so Rushes allows edits inside the project under
|
|
53
|
+
* project-edits and asks under ask-all. Each turn passes the mode's own approvalPolicy and approvalsReviewer
|
|
54
|
+
* (:43888-43889), so the user's Codex config can't turn Guardian back on for a built-in mode.
|
|
55
|
+
* - Chosen over `workspace-write` (also on-request, reviewer "user", :42109-42124): there the sandbox lets Codex
|
|
56
|
+
* write anywhere in the project with no ask at all, so Rushes would never see in-project edits, even under
|
|
57
|
+
* ask-all. In read-only every write, by patch or by command, needs an approval, and that approval is Rushes's.
|
|
58
|
+
* - Limit: no built-in mode uses the `untrusted` policy. A command that only reads, inside the read-only sandbox,
|
|
59
|
+
* still runs with no ask (the sandbox lets it read outside the project).
|
|
60
|
+
*/
|
|
61
|
+
codex: "read-only",
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* clientCapabilities._meta for initialize. Codex (codex-acp 2.7.0, read 18 Nov 2026): a turn that fails on a model or
|
|
65
|
+
* service error (an unsupported model, an outage) still answers session/prompt with stopReason "end_turn". It says it
|
|
66
|
+
* failed only to a client that takes JetBrains' AIR "sessionFailure" extension, in the response's
|
|
67
|
+
* _meta.jetbrains.air.sessionFailure; any other client gets the error as plain agent text. So Rushes asks for that one
|
|
68
|
+
* capability and no other. (Advertising AIR also marks permission options and message phases with AIR _meta, which
|
|
69
|
+
* Rushes doesn't read.) Claude (claude-agent-acp 0.107.3) fails such a turn with a JSON-RPC error, so it gets nothing.
|
|
70
|
+
*/
|
|
71
|
+
export function clientMeta(agent) {
|
|
72
|
+
return agent === "codex" ? { jetbrains: { air: { version: 1, capabilities: ["sessionFailure"] } } } : undefined;
|
|
73
|
+
}
|
|
74
|
+
/** Extra params for session/new and session/load: Claude's initial mode, so the session is never in `auto` (R14). */
|
|
75
|
+
export function sessionSetup(agent) {
|
|
76
|
+
if (agent === "claude")
|
|
77
|
+
return { configOptions: [{ configId: "mode", value: ASK_MODE.claude }] };
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
/** How to start the ACP adapter for an agent, in the project folder. */
|
|
81
|
+
export function adapterSpec(agent, root) {
|
|
82
|
+
const { pkg, version } = ADAPTERS[agent.id];
|
|
83
|
+
// The same PATH detection used, so npx and node are found even when the server has a thin PATH.
|
|
84
|
+
const env = { PATH: searchPath() };
|
|
85
|
+
if (agent.id === "claude" && agent.path)
|
|
86
|
+
env.CLAUDE_CODE_EXECUTABLE = agent.path;
|
|
87
|
+
if (agent.id === "codex" && agent.path)
|
|
88
|
+
env.CODEX_PATH = agent.path;
|
|
89
|
+
// R15: Codex starts in the mode whose approvals go to Rushes, not to Codex's own reviewer (see ASK_MODE.codex).
|
|
90
|
+
if (agent.id === "codex")
|
|
91
|
+
env.INITIAL_AGENT_MODE = ASK_MODE.codex;
|
|
92
|
+
return { command: "npx", args: ["-y", `${pkg}@${version}`], env, cwd: root };
|
|
93
|
+
}
|
|
94
|
+
/** This package's built CLI. src/server/agent/ and dist/server/agent/ are both three folders below the package root. */
|
|
95
|
+
function cliPath() {
|
|
96
|
+
return resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "dist", "cli", "index.js");
|
|
97
|
+
}
|
|
98
|
+
/** dist/cli/index.js exists only after `npm run build`; callers under tsx pass RunnerOptions.mcp (Task 5). */
|
|
99
|
+
/** The Rushes MCP server, handed to the agent so it can call rushes_reply. Pinned to `root` (R17): its tools refuse any other folder. */
|
|
100
|
+
export function rushesMcp(root) {
|
|
101
|
+
return { name: RUSHES_SERVER, command: process.execPath, args: [cliPath(), "mcp", root, "--pinned"], env: [] };
|
|
102
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// §28.4: permission asks the agent makes that Rushes's rules didn't allow on their own. Each one waits for
|
|
2
|
+
// the user's answer in the desk. Nothing here has a timer: an ask is answered by the user, or cancelled by
|
|
3
|
+
// Stop, close or the adapter going away (cancelAll), never by time passing.
|
|
4
|
+
import { basename, isAbsolute, resolve } from "node:path";
|
|
5
|
+
import { NotFoundError } from "../../core/errors.js";
|
|
6
|
+
import { SHELLS, alwaysLabel, canAlways, ruleFor } from "../../core/agentRules.js";
|
|
7
|
+
import { ALWAYS_KEPT } from "../../core/schema.js";
|
|
8
|
+
const CANCELLED = { outcome: "cancelled" };
|
|
9
|
+
/**
|
|
10
|
+
* An argv as one command. A shell running a script (`["bash", "-lc", "npm run build"]`, as Codex sends commands)
|
|
11
|
+
* is the script itself, so an Always rule names the real command and never "bash -lc". Other argvs are joined.
|
|
12
|
+
* A program or subcommand element (the first two) that is empty or holds whitespace or a quote is JSON-quoted:
|
|
13
|
+
* joined bare, its words would not be the program the argv runs, and quoted it can never make an Always rule (R7).
|
|
14
|
+
*/
|
|
15
|
+
function argvCommand(argv) {
|
|
16
|
+
if (argv.length >= 3 && SHELLS.has(basename(argv[0])) && (argv[1] === "-c" || argv[1] === "-lc"))
|
|
17
|
+
return argv[2];
|
|
18
|
+
return argv.map((a, i) => (i < 2 && (a === "" || /[\s'"]/.test(a)) ? JSON.stringify(a) : a)).join(" ");
|
|
19
|
+
}
|
|
20
|
+
/** The request in Rushes's terms. Relative locations are read against the project root, as the agent means them. */
|
|
21
|
+
export function toRequest(p, root) {
|
|
22
|
+
const tc = p.toolCall;
|
|
23
|
+
const raw = (tc.rawInput ?? null);
|
|
24
|
+
const cmd = raw && typeof raw === "object" ? raw.command : undefined;
|
|
25
|
+
const command = typeof cmd === "string" ? cmd : Array.isArray(cmd) ? argvCommand(cmd.map(String)) : null;
|
|
26
|
+
const paths = (tc.locations ?? []).filter((l) => typeof l?.path === "string").map((l) => (isAbsolute(l.path) ? l.path : resolve(root, l.path)));
|
|
27
|
+
return { kind: tc.kind ?? null, title: tc.title ?? "", command, paths };
|
|
28
|
+
}
|
|
29
|
+
function pick(options, first, fallback) {
|
|
30
|
+
const o = options.find((x) => x.kind === first) ?? options.find((x) => x.kind === fallback);
|
|
31
|
+
return o ? { outcome: "selected", optionId: o.optionId } : CANCELLED;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Yes to the adapter: its allow_once option, or allow_always only when that is the one allow it offers.
|
|
35
|
+
* "Always" is Rushes's own rule, so the adapter is never told to remember anything itself.
|
|
36
|
+
*/
|
|
37
|
+
export const allowOutcome = (options) => pick(options, "allow_once", "allow_always");
|
|
38
|
+
const rejectOutcome = (options) => pick(options, "reject_once", "reject_always");
|
|
39
|
+
/** The rules file keeps at most this many Always rules (the schema's cap). */
|
|
40
|
+
export { ALWAYS_KEPT };
|
|
41
|
+
/** Adds the rule to the rules file's list unless the same kind and command is there; at the cap the oldest goes. True when added. */
|
|
42
|
+
export function addRule(always, rule) {
|
|
43
|
+
if (rule.kind === "other" || rule.kind === "switch_mode")
|
|
44
|
+
return false;
|
|
45
|
+
if (always.some((r) => r.kind === rule.kind && r.command === rule.command))
|
|
46
|
+
return false;
|
|
47
|
+
always.push({ kind: rule.kind, command: rule.command });
|
|
48
|
+
if (always.length > ALWAYS_KEPT)
|
|
49
|
+
always.splice(0, always.length - ALWAYS_KEPT);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
/** Takes the rule with this kind and command out of the list (T6); one that isn't there is not found. */
|
|
53
|
+
export function dropRule(always, rule) {
|
|
54
|
+
const at = always.findIndex((r) => r.kind === rule.kind && r.command === rule.command);
|
|
55
|
+
if (at < 0)
|
|
56
|
+
throw new NotFoundError("rule", alwaysLabel(rule));
|
|
57
|
+
always.splice(at, 1);
|
|
58
|
+
}
|
|
59
|
+
export class PermissionBroker {
|
|
60
|
+
root;
|
|
61
|
+
open = new Map();
|
|
62
|
+
count = 0;
|
|
63
|
+
now;
|
|
64
|
+
onChange;
|
|
65
|
+
constructor(root, opts = {}) {
|
|
66
|
+
this.root = root;
|
|
67
|
+
this.now = opts.now ?? (() => new Date());
|
|
68
|
+
this.onChange = opts.onChange ?? (() => undefined);
|
|
69
|
+
}
|
|
70
|
+
/** Holds the ask until answer() or cancelAll(). */
|
|
71
|
+
ask(p) {
|
|
72
|
+
const req = toRequest(p, this.root);
|
|
73
|
+
const id = `ask_${++this.count}`;
|
|
74
|
+
// "" means no Always is offered (an untyped tool call): the desk hides the button.
|
|
75
|
+
const always = canAlways(req, this.root) ? alwaysLabel(ruleFor(req)) : "";
|
|
76
|
+
const ask = { id, title: req.title, kind: req.kind, command: req.command, always, at: this.now().toISOString() };
|
|
77
|
+
const outcome = new Promise((settle) => this.open.set(id, { ask, params: p, req, settle }));
|
|
78
|
+
this.onChange();
|
|
79
|
+
return outcome;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Answers the agent. Returns the rule to keep for "always", else null: also null when no Always was offered
|
|
83
|
+
* (it acts as "once") or when the agent was answered cancelled. An unknown or answered id is not found.
|
|
84
|
+
*/
|
|
85
|
+
answer(id, choice) {
|
|
86
|
+
const o = this.open.get(id);
|
|
87
|
+
if (!o)
|
|
88
|
+
throw new NotFoundError("ask", id);
|
|
89
|
+
this.open.delete(id);
|
|
90
|
+
const outcome = choice === "no" ? rejectOutcome(o.params.options) : allowOutcome(o.params.options);
|
|
91
|
+
o.settle(outcome);
|
|
92
|
+
this.onChange();
|
|
93
|
+
return choice === "always" && o.ask.always !== "" && outcome.outcome === "selected" ? ruleFor(o.req) : null;
|
|
94
|
+
}
|
|
95
|
+
/** Stop, close or the adapter gone: every ask still open is answered cancelled. */
|
|
96
|
+
cancelAll() {
|
|
97
|
+
if (this.open.size === 0)
|
|
98
|
+
return;
|
|
99
|
+
const all = [...this.open.values()];
|
|
100
|
+
this.open.clear();
|
|
101
|
+
for (const o of all)
|
|
102
|
+
o.settle(CANCELLED);
|
|
103
|
+
this.onChange();
|
|
104
|
+
}
|
|
105
|
+
pending() {
|
|
106
|
+
return [...this.open.values()].map((o) => ({ ...o.ask }));
|
|
107
|
+
}
|
|
108
|
+
get size() {
|
|
109
|
+
return this.open.size;
|
|
110
|
+
}
|
|
111
|
+
}
|