rushes 0.11.0 → 0.12.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 +13 -3
- package/README.md +14 -8
- package/dist/cli/demo.js +3 -2
- package/dist/cli/main.js +3 -1
- package/dist/core/agentRules.js +7 -0
- package/dist/core/batches.js +29 -11
- package/dist/core/exportNotes.js +4 -2
- package/dist/core/films.js +114 -0
- package/dist/core/log.js +35 -3
- package/dist/core/logEvents.js +7 -7
- package/dist/core/notes.js +19 -1
- package/dist/core/schema.js +57 -11
- package/dist/core/script.js +67 -0
- package/dist/core/tabs.js +15 -7
- package/dist/core/takes.js +1 -1
- package/dist/mcp/tools.js +90 -23
- package/dist/server/agent/adapters.js +39 -8
- package/dist/server/agent/rules.js +106 -9
- package/dist/server/agent/runner.js +135 -35
- package/dist/server/agent/setupOnce.js +44 -0
- package/dist/server/app.js +267 -66
- package/dist/server/assets.js +40 -14
- package/dist/server/brief.js +9 -7
- package/dist/server/files.js +3 -2
- package/dist/server/films.js +43 -0
- package/dist/server/found.js +2 -1
- package/dist/server/logbook.js +28 -2
- package/dist/server/plans.js +68 -0
- package/dist/server/record.js +31 -13
- package/dist/server/start.js +13 -7
- package/dist/server/storyboard.js +8 -6
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +4 -4
- package/web-dist/assets/{index-4XwD6xWV.css → index-BCYA0Awp.css} +1 -1
- package/web-dist/assets/index-LPvsS2vO.js +70 -0
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-CgX28Bgv.js +0 -70
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// R10: what the agent may do without asking (permissions and Always rules) is kept per user, outside the project,
|
|
2
|
-
// so an agent working in the project can never grant itself a rule by editing a file there.
|
|
2
|
+
// so an agent working in the project can never grant itself a rule by editing a file there. §33: that includes the
|
|
3
|
+
// Auto and Bypass rows, in which the agent's own mode decides and Rushes no longer guards .rushes and .git: they are
|
|
4
|
+
// chosen only by the user, in the agent menu or the first-Send sheet, never from anything in the project. So are the user's answer to
|
|
3
5
|
// the first-Send sheet (I1, `setUp`) and the agent they chose (`agent`): a project folder from someone else, or anything
|
|
4
6
|
// that writes the project, can't turn Send to AI on for an agent.
|
|
5
7
|
//
|
|
@@ -8,12 +10,17 @@
|
|
|
8
10
|
// key: the first 16 hex characters of sha256(realpath.native(project root)), the name as the volume stores it
|
|
9
11
|
//
|
|
10
12
|
// The folder is 0700 and the file 0600. Writes are serialised and atomic (tmp + rename), like the project's own files.
|
|
13
|
+
//
|
|
14
|
+
// §32: Send to AI is set up once per Mac. Beside that folder is the Mac-wide default, <user config dir>/rushes/agent-
|
|
15
|
+
// defaults.json: `{ agent, permissions }`, the user's last choice in the first-Send sheet, the agent menu or the switch
|
|
16
|
+
// turned on. A project with no rules file yet starts from it (AgentRulesFile.adopt). It is the user's own file, outside
|
|
17
|
+
// every project, so R10 holds: nothing inside a project can write it, or grant itself anything through it.
|
|
11
18
|
import { createHash } from "node:crypto";
|
|
12
19
|
import { realpathSync } from "node:fs";
|
|
13
|
-
import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
20
|
+
import { chmod, mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
14
21
|
import { homedir } from "node:os";
|
|
15
22
|
import { dirname, isAbsolute, join } from "node:path";
|
|
16
|
-
import { AgentRulesReadSchema, AgentRulesSchema } from "../../core/schema.js";
|
|
23
|
+
import { AgentDefaultsSchema, AgentRulesReadSchema, AgentRulesSchema } from "../../core/schema.js";
|
|
17
24
|
import { InvalidError } from "../../core/errors.js";
|
|
18
25
|
/** $XDG_CONFIG_HOME when set to an absolute path (as the XDG spec asks), else ~/.config. Tests point it at a temp folder. */
|
|
19
26
|
export function userConfigDir(env = process.env) {
|
|
@@ -81,17 +88,107 @@ export class AgentRulesFile {
|
|
|
81
88
|
const checked = AgentRulesSchema.safeParse(draft);
|
|
82
89
|
if (!checked.success)
|
|
83
90
|
throw new InvalidError("Change to the agent's rules is invalid", checked.error.issues);
|
|
84
|
-
|
|
85
|
-
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
86
|
-
await chmod(dir, 0o700);
|
|
87
|
-
const tmp = `${this.path}.${process.pid}.${Date.now()}.${++writes}.tmp`;
|
|
88
|
-
await writeFile(tmp, JSON.stringify(checked.data, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
89
|
-
await rename(tmp, this.path);
|
|
91
|
+
await writePrivate(this.path, checked.data);
|
|
90
92
|
return { data: checked.data, result };
|
|
91
93
|
});
|
|
92
94
|
this.queue = run;
|
|
93
95
|
return run;
|
|
94
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* §32: a project with no rules file yet starts from the Mac-wide default: set up, the default agent (none after Copy
|
|
99
|
+
* a prompt), the default permissions and no Always rules. Written in the queue and only while there is still no file,
|
|
100
|
+
* so it never overwrites rules made meanwhile. Null when the file was there already, or there is no default.
|
|
101
|
+
*/
|
|
102
|
+
adopt(defaults) {
|
|
103
|
+
const run = this.queue.catch(() => undefined).then(async () => {
|
|
104
|
+
if (!defaults || (await exists(this.path)))
|
|
105
|
+
return null;
|
|
106
|
+
// §33: Bypass is never adopted: a new project whose default is Bypass starts in Accept edits. Auto is adopted.
|
|
107
|
+
const permissions = defaults.permissions === "bypass" ? "project-edits" : defaults.permissions;
|
|
108
|
+
const rules = AgentRulesSchema.parse({ setUp: true, agent: defaults.agent, permissions, always: [] });
|
|
109
|
+
await writePrivate(this.path, rules);
|
|
110
|
+
return rules;
|
|
111
|
+
});
|
|
112
|
+
this.queue = run;
|
|
113
|
+
return run;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function exists(path) {
|
|
117
|
+
try {
|
|
118
|
+
await stat(path);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
if (e.code === "ENOENT")
|
|
123
|
+
return false;
|
|
124
|
+
throw e;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Writes JSON the user's own way: its folder 0700, the file 0600, atomically (tmp + rename). */
|
|
128
|
+
async function writePrivate(path, data) {
|
|
129
|
+
const dir = dirname(path);
|
|
130
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
131
|
+
await chmod(dir, 0o700);
|
|
132
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.${++writes}.tmp`;
|
|
133
|
+
await writeFile(tmp, JSON.stringify(data, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
134
|
+
await rename(tmp, path);
|
|
135
|
+
}
|
|
136
|
+
/** §32: where the Mac-wide default is: <user config dir>/rushes/agent-defaults.json. */
|
|
137
|
+
export function defaultsPath(configDir = userConfigDir()) {
|
|
138
|
+
return join(configDir, "rushes", "agent-defaults.json");
|
|
139
|
+
}
|
|
140
|
+
/** §32: Send to AI's Mac-wide default. One per config dir, so every project's writes to it queue together. */
|
|
141
|
+
export class AgentDefaultsFile {
|
|
142
|
+
path;
|
|
143
|
+
queue = Promise.resolve();
|
|
144
|
+
constructor(configDir = userConfigDir()) {
|
|
145
|
+
this.path = defaultsPath(configDir);
|
|
146
|
+
}
|
|
147
|
+
/** The default, or null when there is none yet (the sheet asks once). A damaged file is no default: the sheet asks. */
|
|
148
|
+
async read() {
|
|
149
|
+
let raw;
|
|
150
|
+
try {
|
|
151
|
+
raw = await readFile(this.path, "utf8");
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
if (e.code !== "ENOENT")
|
|
155
|
+
console.error(`Rushes: couldn't read Send to AI's default at ${this.path}: ${e.message}.`);
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
const parsed = AgentDefaultsSchema.safeParse(JSON.parse(raw));
|
|
160
|
+
if (parsed.success)
|
|
161
|
+
return parsed.data;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
/* damaged: below */
|
|
165
|
+
}
|
|
166
|
+
console.error(`Rushes: Send to AI's default at ${this.path} is damaged. A new project asks who gets the notes until it is saved again.`);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Last choice wins: writes what the user just chose (an agent, null after Copy a prompt, or the permissions) and keeps
|
|
171
|
+
* the rest. With no default yet, the rest comes from `base` (the project's rules as they are now).
|
|
172
|
+
*/
|
|
173
|
+
set(change, base) {
|
|
174
|
+
const run = this.queue.catch(() => undefined).then(async () => {
|
|
175
|
+
const next = AgentDefaultsSchema.parse({ ...((await this.read()) ?? base), ...change });
|
|
176
|
+
await writePrivate(this.path, next);
|
|
177
|
+
return next;
|
|
178
|
+
});
|
|
179
|
+
this.queue = run;
|
|
180
|
+
return run;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const defaultFiles = new Map();
|
|
184
|
+
/** The Mac-wide default's file for the user config dir now (tests point XDG_CONFIG_HOME at a temp folder). */
|
|
185
|
+
export function agentDefaultsFile(configDir = userConfigDir()) {
|
|
186
|
+
let f = defaultFiles.get(configDir);
|
|
187
|
+
if (!f) {
|
|
188
|
+
f = new AgentDefaultsFile(configDir);
|
|
189
|
+
defaultFiles.set(configDir, f);
|
|
190
|
+
}
|
|
191
|
+
return f;
|
|
95
192
|
}
|
|
96
193
|
const files = new WeakMap();
|
|
97
194
|
/** The one rules file for `store`'s project, shared by the runner and the routes so their writes queue together. */
|
|
@@ -17,16 +17,17 @@ import { alwaysLabel, decide } from "../../core/agentRules.js";
|
|
|
17
17
|
import { NotFoundError, RushesError } from "../../core/errors.js";
|
|
18
18
|
import { oneLine } from "../../core/labels.js";
|
|
19
19
|
import { lineEvent } from "../../core/logEvents.js";
|
|
20
|
+
import { byFilm } from "../../core/notes.js";
|
|
20
21
|
import { needsYou, noteState, recallNote, recallNotes } from "../../core/noteState.js";
|
|
21
22
|
import { logBookFor } from "../logbook.js";
|
|
22
23
|
import { AcpConnection } from "./acp.js";
|
|
23
|
-
import {
|
|
24
|
+
import { AUTO_FALLBACK, adapterSpec, clientMeta, modeFor, rushesMcp, sessionSetup } from "./adapters.js";
|
|
24
25
|
import { noteToolCall, withSeen } from "./seenCalls.js";
|
|
25
26
|
import { isOwnRushesTool, noteMcpCall } from "./ownTools.js";
|
|
26
27
|
import { PermissionBroker, addRule, allowOutcome, dropRule, toRequest } from "./broker.js";
|
|
27
28
|
import { detectAgents } from "./detect.js";
|
|
28
29
|
import { agentRulesFor } from "./rules.js";
|
|
29
|
-
import { batchJob, followUpFor } from "./followUp.js";
|
|
30
|
+
import { batchJob, batchLabel, followUpFor } from "./followUp.js";
|
|
30
31
|
/** How long the adapter stays up after its last turn (§5.2). */
|
|
31
32
|
export const AGENT_IDLE_MS = 600_000;
|
|
32
33
|
/** How long an adapter may take to start, from spawn to a ready session (a first `npx -y` fetch included). */
|
|
@@ -108,6 +109,8 @@ export class AgentRunner {
|
|
|
108
109
|
* last reported (round 2, item 3).
|
|
109
110
|
*/
|
|
110
111
|
adapters = new WeakMap();
|
|
112
|
+
/** §33: the row the last batch was sent under. A follow-up that has to start the agent again starts it in this one. */
|
|
113
|
+
lastLevel = null;
|
|
111
114
|
mcp;
|
|
112
115
|
idleMs;
|
|
113
116
|
startMs;
|
|
@@ -116,8 +119,6 @@ export class AgentRunner {
|
|
|
116
119
|
/** The user's rules for this project, kept outside it (R10). `rules` is the last read, for the status. */
|
|
117
120
|
rulesFile;
|
|
118
121
|
rules = { permissions: "project-edits", always: [], setUp: false, agent: null };
|
|
119
|
-
/** I3: batches whose hand-over was refused while Send to AI was on (not signed in, not set up…); resend takes each once. */
|
|
120
|
-
refused = new Set();
|
|
121
122
|
ruleReads = 0;
|
|
122
123
|
rulesApplied = 0;
|
|
123
124
|
/** agent.json reads started, and the newest one applied (a write counts as one). */
|
|
@@ -223,24 +224,43 @@ export class AgentRunner {
|
|
|
223
224
|
return this.noteRefusal(batch.id, "park" in r ? { handedTo: null, why: r.why } : r);
|
|
224
225
|
}
|
|
225
226
|
/**
|
|
226
|
-
* I3: hands over a batch whose hand-over was refused, once (the copy dialog's Set up
|
|
227
|
-
* is taken
|
|
228
|
-
* has gone already.
|
|
227
|
+
* I3: hands over a batch whose hand-over was refused, once (Send again, or the copy dialog's Set up through the setup
|
|
228
|
+
* route). The mark is taken off the batch in batches.json under the send lock, so two at once hand it over once, and a
|
|
229
|
+
* restart in between loses nothing. Null when it wasn't refused, or has gone already.
|
|
229
230
|
*/
|
|
230
231
|
async resend(batch) {
|
|
231
|
-
const r = await this.hand(async () =>
|
|
232
|
+
const r = await this.hand(async () => {
|
|
233
|
+
const { result: took } = await this.store.update("batches", (f) => {
|
|
234
|
+
const b = f.batches.find((x) => x.id === batch.id);
|
|
235
|
+
if (!b?.undelivered)
|
|
236
|
+
return false;
|
|
237
|
+
b.undelivered = null;
|
|
238
|
+
return true;
|
|
239
|
+
});
|
|
240
|
+
return took ? batchJob(batch) : null;
|
|
241
|
+
});
|
|
232
242
|
if (r === null)
|
|
233
243
|
return null;
|
|
234
244
|
return this.noteRefusal(batch.id, "park" in r ? { handedTo: null, why: r.why } : r);
|
|
235
245
|
}
|
|
236
246
|
/**
|
|
237
|
-
*
|
|
238
|
-
* still waiting with it (not signed in, not installed), for
|
|
239
|
-
* up, no agent chosen) or was off: the desk offers no Set up for those, and the user may have copied the prompt.
|
|
247
|
+
* Marks a batch refused while Send to AI really was on (the user's agent, switched on) and nothing started, its notes
|
|
248
|
+
* still waiting with it (not signed in, not installed), for Send again. Not one refused because it only looked on (not
|
|
249
|
+
* set up, no agent chosen) or was off: the desk offers no Set up for those, and the user may have copied the prompt.
|
|
250
|
+
* The mark is written to batches.json, so it outlives this server. A failed write is logged, not thrown: the answer to
|
|
251
|
+
* the desk still says why the batch didn't go.
|
|
240
252
|
*/
|
|
241
|
-
noteRefusal(id, r) {
|
|
242
|
-
if (r.handedTo === null && !r.stopped && !r.recalled && r.why !== CLOSING && this.switchedOn(this.settings, this.rules))
|
|
243
|
-
this.
|
|
253
|
+
async noteRefusal(id, r) {
|
|
254
|
+
if (r.handedTo === null && !r.stopped && !r.recalled && r.why !== CLOSING && this.switchedOn(this.settings, this.rules)) {
|
|
255
|
+
const at = this.now().toISOString();
|
|
256
|
+
await this.store
|
|
257
|
+
.update("batches", (f) => {
|
|
258
|
+
const b = f.batches.find((x) => x.id === id);
|
|
259
|
+
if (b)
|
|
260
|
+
b.undelivered = { at, why: r.why };
|
|
261
|
+
})
|
|
262
|
+
.catch((e) => console.error(`Rushes: couldn't mark batch ${id} for Send again: ${messageOf(e)}`));
|
|
263
|
+
}
|
|
244
264
|
return r;
|
|
245
265
|
}
|
|
246
266
|
/**
|
|
@@ -354,6 +374,9 @@ export class AgentRunner {
|
|
|
354
374
|
}
|
|
355
375
|
if (!agent)
|
|
356
376
|
return { why: "No agent chosen" };
|
|
377
|
+
// §33: a Send runs in the row chosen when it was sent. One already running keeps its own.
|
|
378
|
+
if (job.kind === "batch")
|
|
379
|
+
job.level = rules.permissions;
|
|
357
380
|
const info = (await this.detect()).find((a) => a.id === agent);
|
|
358
381
|
if (!info?.installed)
|
|
359
382
|
return park(`${info?.name ?? NAMES[agent]} is not installed`, info?.name ?? NAMES[agent]);
|
|
@@ -374,7 +397,7 @@ export class AgentRunner {
|
|
|
374
397
|
if (!queued && this.conn) {
|
|
375
398
|
// An idle adapter for another agent or another conversation is replaced.
|
|
376
399
|
const kept = settings.session?.id ?? null;
|
|
377
|
-
if (this.info?.id !== info.id || this.sessionId !== kept)
|
|
400
|
+
if (this.info?.id !== info.id || this.sessionId !== kept || this.levelChanged(this.conn, job))
|
|
378
401
|
this.dropConn();
|
|
379
402
|
}
|
|
380
403
|
if (!queued)
|
|
@@ -422,8 +445,9 @@ export class AgentRunner {
|
|
|
422
445
|
let timedOut = false;
|
|
423
446
|
let timer;
|
|
424
447
|
try {
|
|
425
|
-
|
|
426
|
-
this.
|
|
448
|
+
const level = this.startLevel();
|
|
449
|
+
conn = AcpConnection.start(this.specFor(info, root, level));
|
|
450
|
+
this.attach(conn, info.id, level);
|
|
427
451
|
const c = conn;
|
|
428
452
|
const deadline = new Promise((_, reject) => {
|
|
429
453
|
timer = setTimeout(() => {
|
|
@@ -466,7 +490,8 @@ export class AgentRunner {
|
|
|
466
490
|
const settings = await this.loadSettings();
|
|
467
491
|
check();
|
|
468
492
|
const mcp = [this.mcp(root)];
|
|
469
|
-
const
|
|
493
|
+
const level = this.adapters.get(c)?.level ?? "project-edits";
|
|
494
|
+
const setup = sessionSetup(info.id, level);
|
|
470
495
|
const kept = settings.session;
|
|
471
496
|
let sessionId = null;
|
|
472
497
|
let modes = [];
|
|
@@ -498,23 +523,26 @@ export class AgentRunner {
|
|
|
498
523
|
this.applySettings(data);
|
|
499
524
|
}
|
|
500
525
|
check();
|
|
501
|
-
await this.
|
|
526
|
+
await this.agentMode(c, info, sessionId, modes, current, level);
|
|
502
527
|
check();
|
|
503
528
|
if (c.hasExited)
|
|
504
529
|
throw new Error("the adapter exited as it started");
|
|
505
530
|
this.sessionId = sessionId;
|
|
506
531
|
}
|
|
507
532
|
/**
|
|
508
|
-
* R14/R15: every opened or loaded session goes into the mode
|
|
509
|
-
*
|
|
533
|
+
* R14/R15: every opened or loaded session goes into the mode for the row it was started under (§33: ASK_MODE for
|
|
534
|
+
* Manual and Accept edits, in which the agent asks Rushes before it acts; the agent's own for Auto and Bypass), before
|
|
535
|
+
* the first prompt. Fails closed (round 2, item 3): the start fails with a ModeError, and its
|
|
510
536
|
* notes go back, when the mode isn't offered (or no modes are reported), when set_mode throws, or when the
|
|
511
537
|
* session's mode isn't the ask mode afterwards. That mode is the setup response's currentModeId, then the
|
|
512
538
|
* ask mode once set_mode succeeds, unless a current_mode_update during set_mode reports another one (as
|
|
513
539
|
* claude-agent-acp's setSessionMode does when it falls back).
|
|
514
540
|
*/
|
|
515
|
-
async
|
|
516
|
-
const want =
|
|
517
|
-
const refused = new ModeError(`${info.name} could not be put in
|
|
541
|
+
async agentMode(c, info, sessionId, modes, current, level) {
|
|
542
|
+
const want = modeFor(info.id, level);
|
|
543
|
+
const refused = new ModeError(level === "auto" ? `${info.name} could not be put in Auto mode`
|
|
544
|
+
: level === "bypass" ? `${info.name} could not be put in Bypass mode`
|
|
545
|
+
: `${info.name} could not be put in a mode where Rushes approves actions`);
|
|
518
546
|
const adapter = this.adapters.get(c);
|
|
519
547
|
if (!adapter || !modes.includes(want))
|
|
520
548
|
throw refused;
|
|
@@ -530,11 +558,47 @@ export class AgentRunner {
|
|
|
530
558
|
}
|
|
531
559
|
if (!adapter.modeReported)
|
|
532
560
|
adapter.mode = want;
|
|
561
|
+
// Claude's adapter falls back from auto to acceptEdits for a model that can't run auto: commands still ask Rushes.
|
|
562
|
+
const fallback = level === "auto" ? AUTO_FALLBACK[info.id] : undefined;
|
|
563
|
+
if (fallback !== undefined && adapter.mode === fallback) {
|
|
564
|
+
this.addLine(`${info.name} can't use Auto with this model: file edits go through, commands ask here`, null);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
533
567
|
if (adapter.mode !== want)
|
|
534
568
|
throw refused;
|
|
535
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* §33: the row the agent starts in: the next batch's (its row when it was sent), else the last batch's, else the rules'
|
|
572
|
+
* row now. A follow-up never starts the agent in Auto or Bypass on its own: only a Send made under that row does.
|
|
573
|
+
*/
|
|
574
|
+
startLevel() {
|
|
575
|
+
const batch = [...(this.turn ? [this.turn.job] : []), ...this.queue].find((j) => j.kind === "batch" && j.level);
|
|
576
|
+
const level = batch?.level ?? this.lastLevel ?? this.rules.permissions;
|
|
577
|
+
if (batch?.level === undefined && this.lastLevel === null && (level === "auto" || level === "bypass"))
|
|
578
|
+
return "project-edits";
|
|
579
|
+
return level;
|
|
580
|
+
}
|
|
581
|
+
/** §33: `job` is a Send made under another row than the one `conn` runs in. */
|
|
582
|
+
levelChanged(conn, job) {
|
|
583
|
+
if (!conn || job?.kind !== "batch" || job.level === undefined)
|
|
584
|
+
return false;
|
|
585
|
+
const running = this.adapters.get(conn)?.level;
|
|
586
|
+
return running !== undefined && running !== job.level;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* §33: the row an ask is decided by. A batch keeps the row it started in: in Auto or Bypass the agent's own mode
|
|
590
|
+
* already decided, so that row holds. In Manual or Accept edits the row now holds (so a switch to Manual asks at once),
|
|
591
|
+
* except a switch to Auto or Bypass, which applies from the next Send.
|
|
592
|
+
*/
|
|
593
|
+
askLevel(running, now) {
|
|
594
|
+
if (running === "auto" || running === "bypass")
|
|
595
|
+
return running;
|
|
596
|
+
if (now === "auto" || now === "bypass")
|
|
597
|
+
return running ?? "project-edits";
|
|
598
|
+
return now;
|
|
599
|
+
}
|
|
536
600
|
/** Makes `conn` the runner's adapter and listens to it. */
|
|
537
|
-
attach(conn, agent) {
|
|
601
|
+
attach(conn, agent, level) {
|
|
538
602
|
this.conn = conn;
|
|
539
603
|
this.sessionId = null;
|
|
540
604
|
this.live.add(conn);
|
|
@@ -543,7 +607,7 @@ export class AgentRunner {
|
|
|
543
607
|
// Task 10 (3): each adapter's tool calls are followed from announced to run, so a command says it ran only then.
|
|
544
608
|
// Task 10 round 2 (1): every tool call's kind, input and paths, so an ask that lacks them (Codex under AIR) gets them.
|
|
545
609
|
const seen = new Map();
|
|
546
|
-
const adapter = { agent, calls, seen, mode: null, modeReported: false, activity: new ActivityTracker(this.store.root) };
|
|
610
|
+
const adapter = { agent, level, calls, seen, mode: null, modeReported: false, activity: new ActivityTracker(this.store.root) };
|
|
547
611
|
this.adapters.set(conn, adapter);
|
|
548
612
|
conn.on("update", (u) => {
|
|
549
613
|
if (agent === "codex")
|
|
@@ -587,7 +651,8 @@ export class AgentRunner {
|
|
|
587
651
|
const rules = await this.loadRules();
|
|
588
652
|
if (!live())
|
|
589
653
|
return CANCELLED;
|
|
590
|
-
|
|
654
|
+
const level = this.askLevel(adapter?.level, rules.permissions);
|
|
655
|
+
if (decide(toRequest(p, this.store.root), { permissions: level, always: rules.always }, this.store.root) === "allow")
|
|
591
656
|
return allowOutcome(p.options);
|
|
592
657
|
return this.broker.ask(p);
|
|
593
658
|
}
|
|
@@ -636,7 +701,16 @@ export class AgentRunner {
|
|
|
636
701
|
this.ensureStarted().then(() => this.pump(), () => undefined);
|
|
637
702
|
return;
|
|
638
703
|
}
|
|
704
|
+
if (this.levelChanged(conn, this.queue[0])) {
|
|
705
|
+
// §33: the next Send was made under another row. Its mode is set as a session opens, so the agent starts again
|
|
706
|
+
// (the conversation is loaded, as after any restart) before it begins.
|
|
707
|
+
this.dropConn();
|
|
708
|
+
this.ensureStarted().then(() => this.pump(), () => undefined);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
639
711
|
const job = this.queue.shift();
|
|
712
|
+
if (job.kind === "batch" && job.level)
|
|
713
|
+
this.lastLevel = job.level;
|
|
640
714
|
const gen = this.gen;
|
|
641
715
|
const name = this.info?.name ?? "The agent";
|
|
642
716
|
this.clearIdle();
|
|
@@ -645,7 +719,7 @@ export class AgentRunner {
|
|
|
645
719
|
this.phase = "working";
|
|
646
720
|
this.error = null;
|
|
647
721
|
this.current = { note: null, doing: null };
|
|
648
|
-
this.milestone(job.kind === "batch" ? `${name} started on ${job.label}` : `${name} picked up ${job.label}`);
|
|
722
|
+
this.milestone(job.kind === "batch" ? `${name} started on ${job.label}` : `${name} picked up ${job.label}`, job, (label) => `${name} started on ${label}`);
|
|
649
723
|
this.announce();
|
|
650
724
|
this.track(conn.prompt(sessionId, job.prompt).then((r) => {
|
|
651
725
|
done();
|
|
@@ -662,7 +736,8 @@ export class AgentRunner {
|
|
|
662
736
|
const name = this.info?.name ?? "The agent";
|
|
663
737
|
this.turn = null;
|
|
664
738
|
this.ending = true;
|
|
665
|
-
|
|
739
|
+
const ended = (label) => (stopReason === "end_turn" ? `${name} finished ${label}` : `${name} ended ${label} (${stopReason})`);
|
|
740
|
+
this.milestone(ended(job.label), job, ended);
|
|
666
741
|
this.announce();
|
|
667
742
|
// Still busy while the notes are read, so a send now queues and is picked up below. The phase follows
|
|
668
743
|
// the batch this turn worked on: a question on one of its notes makes it "question".
|
|
@@ -731,7 +806,7 @@ export class AgentRunner {
|
|
|
731
806
|
this.ending = true;
|
|
732
807
|
const queued = this.queue;
|
|
733
808
|
this.queue = [];
|
|
734
|
-
this.milestone(`${name} couldn't finish: ${why}
|
|
809
|
+
this.milestone(`${name} couldn't finish: ${why}`, job);
|
|
735
810
|
this.announce();
|
|
736
811
|
let back = 0;
|
|
737
812
|
try {
|
|
@@ -1004,14 +1079,39 @@ export class AgentRunner {
|
|
|
1004
1079
|
})
|
|
1005
1080
|
.then(() => undefined, (e) => console.error(`Rushes: couldn't give back the notes of ${[...back.batches, ...back.notes.map((n) => n.id)].join(", ")}: ${messageOf(e)}`));
|
|
1006
1081
|
}
|
|
1007
|
-
/**
|
|
1008
|
-
|
|
1082
|
+
/**
|
|
1083
|
+
* An Activity line and a Change Log line, for a run starting, finishing, stopping or failing. §30: with the run's
|
|
1084
|
+
* `job`, the Change Log line is written once per film its notes are on, each with that film, so a film's Activity
|
|
1085
|
+
* never tells another film's work; `say` words a batch's line from that film's own count ("2 notes").
|
|
1086
|
+
*/
|
|
1087
|
+
milestone(text, job, say) {
|
|
1009
1088
|
this.addLine(text, null);
|
|
1010
|
-
this.track(this.writeMilestone(text));
|
|
1089
|
+
this.track(this.writeMilestone(text, job, say));
|
|
1011
1090
|
}
|
|
1012
|
-
writeMilestone(text) {
|
|
1091
|
+
async writeMilestone(text, job, say) {
|
|
1092
|
+
const at = this.now();
|
|
1013
1093
|
// LogBook.add never throws: a line it can't write is reported and counted.
|
|
1014
|
-
|
|
1094
|
+
const book = logBookFor(this.store);
|
|
1095
|
+
const parts = job ? await this.filmParts(job).catch(() => []) : [];
|
|
1096
|
+
if (parts.length === 0)
|
|
1097
|
+
return book.add(lineEvent(text, "notes"), "rushes", at);
|
|
1098
|
+
for (const p of parts)
|
|
1099
|
+
await book.add(lineEvent(say && job?.kind === "batch" ? say(p.label) : text, "notes", { video: p.film }), "rushes", at);
|
|
1100
|
+
return undefined;
|
|
1101
|
+
}
|
|
1102
|
+
/** §30: the films a turn's notes are on, each with the label of its own share of them ("2 notes"). */
|
|
1103
|
+
async filmParts(job) {
|
|
1104
|
+
const notes = await this.store.read("notes");
|
|
1105
|
+
if (job.kind === "followUp")
|
|
1106
|
+
return [{ film: notes.notes.find((n) => n.id === job.note)?.video ?? null, label: job.label }];
|
|
1107
|
+
const b = (await this.store.read("batches")).batches.find((x) => x.id === job.batchId);
|
|
1108
|
+
if (!b)
|
|
1109
|
+
return [];
|
|
1110
|
+
const filmOf = new Map(notes.notes.map((n) => [n.id, n.video ?? null]));
|
|
1111
|
+
const groups = byFilm(b.noteIds, (id) => filmOf.get(id));
|
|
1112
|
+
if (groups.length === 0 || (b.sectionIds.length > 0 && !groups.some(([f]) => f === null)))
|
|
1113
|
+
groups.push([null, []]);
|
|
1114
|
+
return groups.map(([film, ids]) => ({ film, label: batchLabel({ noteIds: ids, sectionIds: film === null ? b.sectionIds : [] }) }));
|
|
1015
1115
|
}
|
|
1016
1116
|
addLine(text, note) {
|
|
1017
1117
|
this.lines.push({ at: this.now().toISOString(), text, note });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { agentDefaultsFile, agentRulesFor } from "./rules.js";
|
|
2
|
+
const adopted = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* Starts a new project from the Mac-wide default, once per store. Resolves to the rules it wrote, or null when the
|
|
5
|
+
* project had rules already, or there is no default. Never rejects: a failure is logged and the sheet asks as before.
|
|
6
|
+
*/
|
|
7
|
+
export function adoptAgentDefaultsOnce(store) {
|
|
8
|
+
let run = adopted.get(store);
|
|
9
|
+
if (!run) {
|
|
10
|
+
run = adopt(store).catch((e) => {
|
|
11
|
+
console.error(`Rushes: couldn't start Send to AI from your default: ${e.message}`);
|
|
12
|
+
return null;
|
|
13
|
+
});
|
|
14
|
+
adopted.set(store, run);
|
|
15
|
+
}
|
|
16
|
+
return run;
|
|
17
|
+
}
|
|
18
|
+
async function adopt(store) {
|
|
19
|
+
const rules = await agentRulesFor(store).adopt(await agentDefaultsFile().read());
|
|
20
|
+
const id = rules?.agent;
|
|
21
|
+
if (!id)
|
|
22
|
+
return rules;
|
|
23
|
+
await store.update("agent", (f) => {
|
|
24
|
+
// Another agent can't continue this one's conversation.
|
|
25
|
+
if (f.agent !== id) {
|
|
26
|
+
f.agent = id;
|
|
27
|
+
f.session = null;
|
|
28
|
+
}
|
|
29
|
+
f.on = true;
|
|
30
|
+
});
|
|
31
|
+
return rules;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* §32: keeps the user's choice as the Mac-wide default (last choice wins). Never fails the change it follows: the
|
|
35
|
+
* project's own rules are already written, so a default that can't be saved only means the next new project asks.
|
|
36
|
+
*/
|
|
37
|
+
export async function rememberDefault(change, now) {
|
|
38
|
+
try {
|
|
39
|
+
await agentDefaultsFile().set(change, { agent: now.agent, permissions: now.permissions });
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.error(`Rushes: couldn't save Send to AI as your default for new projects: ${e.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|