openmausbot 0.1.73 → 0.1.74
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/dist/assets/index-BRLHsQ5g.js +298 -0
- package/dist/assets/index-ByLQ7a3F.css +1 -0
- package/dist/assets/{index-BYbK7ber.js → index-CwoQdM0z.js} +1 -1
- package/dist/index.html +2 -2
- package/dist-server/container-mcp.js +9 -0
- package/dist-server/index.js +592 -453
- package/dist-server/mcp-gate.js +58 -16
- package/dist-server/openmausbot.js +186 -64
- package/dist-server/pair-cli.js +186 -64
- package/dist-server/server/auto-approve.js +30 -206
- package/dist-server/server/channel-queue.js +20 -2
- package/dist-server/server/config.js +36 -1
- package/dist-server/server/drivers/acp/core.js +56 -3
- package/dist-server/server/drivers/acp/grok.js +3 -1
- package/dist-server/server/drivers/antigravity-acp.js +5 -4
- package/dist-server/server/drivers/antigravity.js +9 -4
- package/dist-server/server/drivers/claude.js +54 -11
- package/dist-server/server/drivers/codex.js +22 -11
- package/dist-server/server/engine-install.js +9 -5
- package/dist-server/server/index.js +185 -223
- package/dist-server/server/message-db.js +70 -3
- package/dist-server/server/procs.js +82 -23
- package/dist-server/server/routines.js +67 -8
- package/dist-server/server/steer-queue.js +27 -7
- package/dist-server/server/team-manifest.js +1 -1
- package/dist-server/server/webhooks.js +4 -1
- package/dist-server/server/workspace-backup.js +24 -9
- package/dist-server/shared/approval-mode.js +11 -10
- package/dist-server/vps-container-mcp.js +9 -0
- package/package.json +1 -1
- package/dist/assets/index-BLJ7byG3.js +0 -296
- package/dist/assets/index-De2TRLxu.css +0 -1
- package/dist-server/server/auto-review.js +0 -79
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// Legacy JSON thread files import lazily: the first read of a thread with
|
|
11
11
|
// no rows pulls the old file in, after which the DB is the source of
|
|
12
12
|
// truth (the JSON file is left behind as a one-time backup).
|
|
13
|
-
import { chmodSync, closeSync, existsSync, openSync, readFileSync, renameSync } from "node:fs";
|
|
13
|
+
import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync } from "node:fs";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import { DatabaseSync } from "node:sqlite";
|
|
16
16
|
import { DATA_DIR } from "./config.js";
|
|
@@ -19,6 +19,7 @@ const DB_FILE = () => join(DATA_DIR, "messages.db");
|
|
|
19
19
|
let handle = null;
|
|
20
20
|
let handlePath = null;
|
|
21
21
|
function open() {
|
|
22
|
+
mkdirSync(DATA_DIR, { recursive: true, mode: 0o700 });
|
|
22
23
|
const file = DB_FILE();
|
|
23
24
|
// Transcripts can contain private conversations and tool output. Create
|
|
24
25
|
// the database with owner-only permissions and also repair an existing
|
|
@@ -47,6 +48,16 @@ function open() {
|
|
|
47
48
|
thread_id TEXT PRIMARY KEY,
|
|
48
49
|
active_leaf_id TEXT
|
|
49
50
|
);
|
|
51
|
+
CREATE TABLE IF NOT EXISTS chat_followups (
|
|
52
|
+
id TEXT PRIMARY KEY,
|
|
53
|
+
kind TEXT NOT NULL,
|
|
54
|
+
owner_id TEXT NOT NULL,
|
|
55
|
+
thread_id TEXT NOT NULL,
|
|
56
|
+
send_id TEXT,
|
|
57
|
+
status TEXT NOT NULL,
|
|
58
|
+
payload TEXT NOT NULL
|
|
59
|
+
);
|
|
60
|
+
CREATE INDEX IF NOT EXISTS chat_followups_receipt ON chat_followups(kind, owner_id, thread_id, send_id);
|
|
50
61
|
`);
|
|
51
62
|
ensureRecallIndex(db);
|
|
52
63
|
ensureMemoryIndex(db);
|
|
@@ -153,6 +164,59 @@ function db() {
|
|
|
153
164
|
handlePath = DB_FILE();
|
|
154
165
|
return handle;
|
|
155
166
|
}
|
|
167
|
+
/** A 202/cancel/dispatch claim must reach disk before publishing its result.
|
|
168
|
+
* Use the existing transcript DB (and backup path), with FULL sync for these
|
|
169
|
+
* small transactions only; ordinary transcript writes keep their policy. */
|
|
170
|
+
function writeFollowups(write) {
|
|
171
|
+
const connection = db();
|
|
172
|
+
connection.exec("PRAGMA synchronous = FULL");
|
|
173
|
+
try {
|
|
174
|
+
connection.exec("BEGIN IMMEDIATE");
|
|
175
|
+
try {
|
|
176
|
+
write(connection);
|
|
177
|
+
connection.exec("COMMIT");
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
connection.exec("ROLLBACK");
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
connection.exec("PRAGMA synchronous = NORMAL");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export function saveChatFollowup(followup) {
|
|
189
|
+
writeFollowups((connection) => connection.prepare("INSERT INTO chat_followups(id, kind, owner_id, thread_id, send_id, status, payload) VALUES (?, ?, ?, ?, ?, 'pending', ?)").run(followup.id, followup.kind, followup.ownerId, followup.threadId, followup.payload.sendId ?? null, JSON.stringify(followup.payload)));
|
|
190
|
+
}
|
|
191
|
+
/** Null retires a dispatch whose canonical transcript is already durable.
|
|
192
|
+
* Cancellation tombstones remain so a retried sendId cannot resurrect it. */
|
|
193
|
+
export function settleChatFollowups(ids, status) {
|
|
194
|
+
if (!ids.length)
|
|
195
|
+
return;
|
|
196
|
+
writeFollowups((connection) => {
|
|
197
|
+
const statement = connection.prepare(status === null
|
|
198
|
+
? "DELETE FROM chat_followups WHERE id = ?"
|
|
199
|
+
: status === "cancelled"
|
|
200
|
+
? "UPDATE chat_followups SET status = ?, payload = '{\"text\":\"\"}' WHERE id = ?"
|
|
201
|
+
: "UPDATE chat_followups SET status = ? WHERE id = ?");
|
|
202
|
+
for (const id of ids) {
|
|
203
|
+
if (status === null)
|
|
204
|
+
statement.run(id);
|
|
205
|
+
else
|
|
206
|
+
statement.run(status, id);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
export function chatFollowups(kind) {
|
|
211
|
+
const rows = (kind
|
|
212
|
+
? db().prepare("SELECT * FROM chat_followups WHERE kind = ? ORDER BY rowid").all(kind)
|
|
213
|
+
: db().prepare("SELECT * FROM chat_followups ORDER BY rowid").all());
|
|
214
|
+
return rows.map((row) => ({ id: row.id, kind: row.kind, ownerId: row.owner_id, threadId: row.thread_id,
|
|
215
|
+
status: row.status, payload: JSON.parse(row.payload) }));
|
|
216
|
+
}
|
|
217
|
+
export function cancelledChatFollowup(kind, ownerId, threadId, sendId) {
|
|
218
|
+
return Boolean(db().prepare("SELECT 1 FROM chat_followups WHERE kind = ? AND owner_id = ? AND thread_id = ? AND send_id = ? AND status = 'cancelled'").get(kind, ownerId, threadId, sendId));
|
|
219
|
+
}
|
|
156
220
|
const rowToMessage = (row) => JSON.parse(row.json);
|
|
157
221
|
/** Read one thread, importing its legacy JSON file on first touch. */
|
|
158
222
|
export function readThread(threadId, legacyFile) {
|
|
@@ -268,8 +332,11 @@ export function setActiveLeaf(threadId, leafId) {
|
|
|
268
332
|
.run(threadId, leafId);
|
|
269
333
|
}
|
|
270
334
|
export function deleteThread(threadId) {
|
|
271
|
-
|
|
272
|
-
|
|
335
|
+
writeFollowups((connection) => {
|
|
336
|
+
connection.prepare("DELETE FROM chat_followups WHERE thread_id = ?").run(threadId);
|
|
337
|
+
connection.prepare("DELETE FROM messages WHERE thread_id = ?").run(threadId);
|
|
338
|
+
connection.prepare("DELETE FROM thread_state WHERE thread_id = ?").run(threadId);
|
|
339
|
+
});
|
|
273
340
|
}
|
|
274
341
|
/** Case-insensitive substring search over text messages, newest first.
|
|
275
342
|
* A LIKE scan, deliberately: local transcripts are megabytes at most, a
|
|
@@ -34,6 +34,10 @@ export function assertSafeCliArgv(resolved, platform = process.platform) {
|
|
|
34
34
|
error.code = "ENAMETOOLONG";
|
|
35
35
|
throw error;
|
|
36
36
|
}
|
|
37
|
+
// Only spawnCli establishes a private POSIX group. A plain spawned child
|
|
38
|
+
// (for example inside an MCP gate) may share our own group: never signal it.
|
|
39
|
+
const cliGroups = new WeakSet();
|
|
40
|
+
const stopping = new WeakMap();
|
|
37
41
|
export function spawnCli(cli, args, opts) {
|
|
38
42
|
const resolved = resolveCli(cli, args);
|
|
39
43
|
assertSafeCliArgv(resolved);
|
|
@@ -43,6 +47,8 @@ export function spawnCli(cli, args, opts) {
|
|
|
43
47
|
// win32: taskkill /T does the reaping instead (see killCliTree)
|
|
44
48
|
...(process.platform === "win32" ? { windowsHide: true } : { detached: true }),
|
|
45
49
|
}); // callers always pipe all three
|
|
50
|
+
if (process.platform !== "win32")
|
|
51
|
+
cliGroups.add(child);
|
|
46
52
|
// A write to a dying child's stdin fails differently per platform, and one
|
|
47
53
|
// of the ways is fatal. On POSIX the kill is synchronous, the stream is
|
|
48
54
|
// already destroyed by the time anything writes, and the write throws into
|
|
@@ -80,11 +86,78 @@ export function describeSpawnFailure(err, cli) {
|
|
|
80
86
|
};
|
|
81
87
|
return { message: `spawn failed: ${err.message}`, setup: false };
|
|
82
88
|
}
|
|
83
|
-
/** Stop
|
|
89
|
+
/** Stop an owned CLI group, including helpers after its root exits. timeoutMs
|
|
90
|
+
* is the TERM grace period; SIGKILL gets one further second to settle. Helpers
|
|
91
|
+
* that deliberately detach into another group are outside this ownership. */
|
|
84
92
|
export function killCliTree(child, timeoutMs = 5_000) {
|
|
93
|
+
const existing = stopping.get(child);
|
|
94
|
+
if (existing)
|
|
95
|
+
return existing;
|
|
85
96
|
const pid = child.pid;
|
|
86
|
-
if (!pid
|
|
97
|
+
if (!pid)
|
|
87
98
|
return Promise.resolve(true);
|
|
99
|
+
if (!Number.isInteger(pid) || pid <= 1 || pid === process.pid)
|
|
100
|
+
return Promise.resolve(false);
|
|
101
|
+
const run = stopCliTree(child, pid, Number.isFinite(timeoutMs) ? Math.max(0, timeoutMs) : 5_000);
|
|
102
|
+
stopping.set(child, run);
|
|
103
|
+
// A failed attempt may be retried. Remember success so a delayed caller
|
|
104
|
+
// cannot signal a reused PID/group after this child's group disappeared.
|
|
105
|
+
void run.then((stopped) => { if (!stopped)
|
|
106
|
+
stopping.delete(child); });
|
|
107
|
+
return run;
|
|
108
|
+
}
|
|
109
|
+
async function stopCliTree(child, pid, timeoutMs) {
|
|
110
|
+
const exited = () => child.exitCode !== null || child.signalCode !== null;
|
|
111
|
+
if (process.platform !== "win32") {
|
|
112
|
+
const group = cliGroups.has(child);
|
|
113
|
+
const settled = () => {
|
|
114
|
+
if (!exited())
|
|
115
|
+
return false;
|
|
116
|
+
if (!group)
|
|
117
|
+
return true;
|
|
118
|
+
try {
|
|
119
|
+
process.kill(-pid, 0);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
// EPERM and other failures do not prove that the group is gone.
|
|
124
|
+
return error.code === "ESRCH";
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const signal = (value) => {
|
|
128
|
+
try {
|
|
129
|
+
if (group)
|
|
130
|
+
process.kill(-pid, value);
|
|
131
|
+
else
|
|
132
|
+
child.kill(value);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
try {
|
|
136
|
+
child.kill(value);
|
|
137
|
+
}
|
|
138
|
+
catch { /* report uncertainty below */ }
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const wait = async (ms) => {
|
|
142
|
+
const deadline = Date.now() + ms;
|
|
143
|
+
while (!settled()) {
|
|
144
|
+
const remaining = deadline - Date.now();
|
|
145
|
+
if (remaining <= 0)
|
|
146
|
+
return false;
|
|
147
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(25, remaining)));
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
};
|
|
151
|
+
if (settled())
|
|
152
|
+
return true;
|
|
153
|
+
signal("SIGTERM");
|
|
154
|
+
if (await wait(timeoutMs))
|
|
155
|
+
return true;
|
|
156
|
+
signal("SIGKILL");
|
|
157
|
+
return wait(1_000);
|
|
158
|
+
}
|
|
159
|
+
if (exited())
|
|
160
|
+
return true;
|
|
88
161
|
return new Promise((resolve) => {
|
|
89
162
|
let timer;
|
|
90
163
|
const done = (stopped) => {
|
|
@@ -96,32 +169,18 @@ export function killCliTree(child, timeoutMs = 5_000) {
|
|
|
96
169
|
child.once("close", closed);
|
|
97
170
|
timer = setTimeout(() => done(false), timeoutMs);
|
|
98
171
|
timer.unref?.();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return;
|
|
103
|
-
try {
|
|
104
|
-
// taskkill is unavailable or the tree lookup failed. At least stop
|
|
105
|
-
// the process we own instead of leaving the entire turn running.
|
|
106
|
-
child.kill();
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
/* already gone */
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
try {
|
|
115
|
-
process.kill(-pid, "SIGTERM");
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
172
|
+
execFile("taskkill", ["/PID", String(pid), "/T", "/F"], { windowsHide: true }, (err) => {
|
|
173
|
+
if (!err)
|
|
174
|
+
return;
|
|
118
175
|
try {
|
|
119
|
-
|
|
176
|
+
// taskkill is unavailable or the tree lookup failed. At least stop
|
|
177
|
+
// the process we own instead of leaving the entire turn running.
|
|
178
|
+
child.kill();
|
|
120
179
|
}
|
|
121
180
|
catch {
|
|
122
181
|
/* already gone */
|
|
123
182
|
}
|
|
124
|
-
}
|
|
183
|
+
});
|
|
125
184
|
});
|
|
126
185
|
}
|
|
127
186
|
/** Per-turn broker channel: unix socket on POSIX, named pipe on Windows
|
|
@@ -6,6 +6,14 @@ import { DATA_DIR } from "./config.js";
|
|
|
6
6
|
import { writeFileAtomic } from "./atomic.js";
|
|
7
7
|
import { redactSecretsInText } from "./redact.js";
|
|
8
8
|
const persistedSourceThreadId = z.string().trim().min(1).optional().catch(undefined);
|
|
9
|
+
const webhookRunReceiptSchema = z.object({
|
|
10
|
+
webhookId: z.string().min(1).max(200),
|
|
11
|
+
deliveryId: z.string().min(1).max(200),
|
|
12
|
+
runId: z.string().min(1),
|
|
13
|
+
acceptedAt: z.number().finite().nonnegative(),
|
|
14
|
+
});
|
|
15
|
+
const WEBHOOK_RETRY_WINDOW_MS = 7 * 24 * 60 * 60_000;
|
|
16
|
+
const MAX_WEBHOOK_RECEIPTS = 20_000;
|
|
9
17
|
function routineRequestOwnerKey(owner) {
|
|
10
18
|
return JSON.stringify([owner.requestId, owner.messageId, owner.botId, owner.threadId]);
|
|
11
19
|
}
|
|
@@ -426,6 +434,7 @@ export class RoutineManager {
|
|
|
426
434
|
routines = [];
|
|
427
435
|
runs = [];
|
|
428
436
|
routineRequestReceipts = [];
|
|
437
|
+
webhookRunReceipts = [];
|
|
429
438
|
timer = null;
|
|
430
439
|
ticking = false;
|
|
431
440
|
constructor(options) {
|
|
@@ -486,11 +495,29 @@ export class RoutineManager {
|
|
|
486
495
|
typeof receipt?.resultId === "string" &&
|
|
487
496
|
Number.isFinite(receipt?.appliedAt))
|
|
488
497
|
: [];
|
|
498
|
+
this.webhookRunReceipts = Array.isArray(disk.webhookRunReceipts)
|
|
499
|
+
? disk.webhookRunReceipts.flatMap((receipt) => {
|
|
500
|
+
const parsed = webhookRunReceiptSchema.safeParse(receipt);
|
|
501
|
+
return parsed.success ? [parsed.data] : [];
|
|
502
|
+
})
|
|
503
|
+
: [];
|
|
504
|
+
// Upgrade old run logs before history pruning can discard their IDs.
|
|
505
|
+
const known = new Set(this.webhookRunReceipts.map((r) => JSON.stringify([r.webhookId, r.deliveryId])));
|
|
506
|
+
for (const run of this.runs) {
|
|
507
|
+
if (!run.webhookId || !run.deliveryId || run.createdAt < this.now() - WEBHOOK_RETRY_WINDOW_MS)
|
|
508
|
+
continue;
|
|
509
|
+
const key = JSON.stringify([run.webhookId, run.deliveryId]);
|
|
510
|
+
if (known.has(key))
|
|
511
|
+
continue;
|
|
512
|
+
this.webhookRunReceipts.push({ webhookId: run.webhookId, deliveryId: run.deliveryId, runId: run.id, acceptedAt: run.createdAt });
|
|
513
|
+
known.add(key);
|
|
514
|
+
}
|
|
489
515
|
}
|
|
490
516
|
catch {
|
|
491
517
|
this.routines = [];
|
|
492
518
|
this.runs = [];
|
|
493
519
|
this.routineRequestReceipts = [];
|
|
520
|
+
this.webhookRunReceipts = [];
|
|
494
521
|
}
|
|
495
522
|
// A local process cannot still own these turns after a full restart.
|
|
496
523
|
const recovered = [];
|
|
@@ -828,11 +855,22 @@ export class RoutineManager {
|
|
|
828
855
|
queueMicrotask(() => void this.tick());
|
|
829
856
|
return cloneRun(run);
|
|
830
857
|
}
|
|
831
|
-
/**
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
858
|
+
/** Look up an accepted delivery independently of run-log retention. */
|
|
859
|
+
webhookRunReceipt(webhookId, deliveryId) {
|
|
860
|
+
const receipt = this.webhookRunReceipts.find((candidate) => candidate.webhookId === webhookId && candidate.deliveryId === deliveryId &&
|
|
861
|
+
candidate.acceptedAt >= this.now() - WEBHOOK_RETRY_WINDOW_MS);
|
|
862
|
+
if (receipt)
|
|
863
|
+
return { id: receipt.runId };
|
|
864
|
+
// Never duplicate work that is still pending, even beyond the retry window.
|
|
865
|
+
const active = this.runs.find((run) => run.webhookId === webhookId && run.deliveryId === deliveryId &&
|
|
866
|
+
["queued", "running", "waiting"].includes(run.status));
|
|
867
|
+
return active ? { id: active.id } : null;
|
|
868
|
+
}
|
|
869
|
+
/** Queue webhook work through the same dispatcher as scheduled routines. */
|
|
835
870
|
enqueueWebhook(input) {
|
|
871
|
+
const existing = this.webhookRunReceipt(input.webhookId, input.deliveryId);
|
|
872
|
+
if (existing)
|
|
873
|
+
return existing;
|
|
836
874
|
if (this.options.botState(input.botId) === "missing") {
|
|
837
875
|
throw Object.assign(new Error("The assigned MAUS no longer exists"), { status: 410 });
|
|
838
876
|
}
|
|
@@ -853,8 +891,26 @@ export class RoutineManager {
|
|
|
853
891
|
attachments: [],
|
|
854
892
|
createdAt: this.now(),
|
|
855
893
|
};
|
|
894
|
+
const previousReceipts = this.webhookRunReceipts;
|
|
895
|
+
const receipts = previousReceipts.filter((receipt) => receipt.acceptedAt >= this.now() - WEBHOOK_RETRY_WINDOW_MS);
|
|
896
|
+
// Never evict a promised retry identity to admit fresh work.
|
|
897
|
+
if (receipts.length >= MAX_WEBHOOK_RECEIPTS) {
|
|
898
|
+
throw Object.assign(new Error("Webhook retry history is full; try again later"), { status: 429 });
|
|
899
|
+
}
|
|
900
|
+
receipts.push({ webhookId: input.webhookId, deliveryId: input.deliveryId, runId: run.id, acceptedAt: this.now() });
|
|
901
|
+
const previousRuns = this.runs.slice();
|
|
856
902
|
this.runs.push(run);
|
|
857
|
-
this.
|
|
903
|
+
this.webhookRunReceipts = receipts;
|
|
904
|
+
try {
|
|
905
|
+
this.save();
|
|
906
|
+
}
|
|
907
|
+
catch (error) {
|
|
908
|
+
// Restore pruned history too, retaining the live run objects that tick()
|
|
909
|
+
// may be awaiting rather than replacing them with cloned snapshots.
|
|
910
|
+
this.runs = previousRuns;
|
|
911
|
+
this.webhookRunReceipts = previousReceipts;
|
|
912
|
+
throw error;
|
|
913
|
+
}
|
|
858
914
|
this.emitRun(run);
|
|
859
915
|
queueMicrotask(() => void this.tick());
|
|
860
916
|
return cloneRun(run);
|
|
@@ -1044,9 +1100,11 @@ export class RoutineManager {
|
|
|
1044
1100
|
}
|
|
1045
1101
|
// Oldest queued requests have priority. New manual/webhook arrivals
|
|
1046
1102
|
// must not continually overtake work that has already waited. Snapshot
|
|
1047
|
-
//
|
|
1048
|
-
|
|
1049
|
-
|
|
1103
|
+
// IDs retain order across awaits without holding stale objects after
|
|
1104
|
+
// another request rolls back a failed routine-definition write.
|
|
1105
|
+
for (const id of this.runs.map((run) => run.id)) {
|
|
1106
|
+
const run = this.runs.find((candidate) => candidate.id === id);
|
|
1107
|
+
if (!run || run.status !== "queued")
|
|
1050
1108
|
continue;
|
|
1051
1109
|
// A queued interval represents the latest useful check, not a backlog
|
|
1052
1110
|
// item. If the bot stayed busy across later occurrences, align this
|
|
@@ -1430,6 +1488,7 @@ export class RoutineManager {
|
|
|
1430
1488
|
routines: this.routines,
|
|
1431
1489
|
runs: this.runs,
|
|
1432
1490
|
routineRequestReceipts: this.routineRequestReceipts,
|
|
1491
|
+
webhookRunReceipts: this.webhookRunReceipts,
|
|
1433
1492
|
}, null, 2), { mode: 0o600 });
|
|
1434
1493
|
}
|
|
1435
1494
|
}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
// here until the bot settles, then lands in the thread and runs as ONE
|
|
5
5
|
// follow-up turn whose prompt is the queued texts separated by a blank line.
|
|
6
6
|
//
|
|
7
|
-
// The queue is
|
|
7
|
+
// The durable queue is NOT in `messages[]` while the current
|
|
8
8
|
// turn is running: appending immediately would make the queued line the
|
|
9
9
|
// active leaf, so remaining tool/assistant events of *this* turn would
|
|
10
|
-
// hang off a user line the model has not seen. Restart
|
|
11
|
-
//
|
|
10
|
+
// hang off a user line the model has not seen. Restart restores only sends
|
|
11
|
+
// whose dispatch has not begun. The composer shows a pending chip
|
|
12
12
|
// until drain appends the words.
|
|
13
13
|
//
|
|
14
14
|
// Unlike the delegation drain, an interrupted or failed turn does NOT
|
|
@@ -17,7 +17,20 @@
|
|
|
17
17
|
// stop-then-steer (queue a correction, hit Stop, the correction runs) is
|
|
18
18
|
// the feature.
|
|
19
19
|
import { newId } from "./contracts.js";
|
|
20
|
+
import { chatFollowups, saveChatFollowup, settleChatFollowups } from "./message-db.js";
|
|
20
21
|
const queues = new Map(); // threadId → waiting sends
|
|
22
|
+
export function restoreSteeredMessages() {
|
|
23
|
+
queues.clear();
|
|
24
|
+
for (const row of chatFollowups("bot")) {
|
|
25
|
+
if (row.status !== "pending")
|
|
26
|
+
continue;
|
|
27
|
+
const entry = queues.get(row.threadId) ?? { botId: row.ownerId, items: [] };
|
|
28
|
+
if (entry.botId !== row.ownerId)
|
|
29
|
+
throw new Error("queued task belongs to another bot");
|
|
30
|
+
entry.items.push({ ...row.payload, messageId: row.id, prompt: row.payload.prompt ?? row.payload.text });
|
|
31
|
+
queues.set(row.threadId, entry);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
21
34
|
const listeners = new Set();
|
|
22
35
|
const changed = () => {
|
|
23
36
|
for (const listener of listeners) {
|
|
@@ -50,7 +63,7 @@ export function queueSteeredMessage(botId, threadId, text, options = {}) {
|
|
|
50
63
|
// queues even if a corrupt caller reuses a thread id.
|
|
51
64
|
if (entry.botId !== botId)
|
|
52
65
|
throw new Error("queued task belongs to another bot");
|
|
53
|
-
|
|
66
|
+
const item = {
|
|
54
67
|
messageId: id,
|
|
55
68
|
text,
|
|
56
69
|
prompt: options.prompt ?? text,
|
|
@@ -58,7 +71,9 @@ export function queueSteeredMessage(botId, threadId, text, options = {}) {
|
|
|
58
71
|
sendId: options.sendId,
|
|
59
72
|
reason: options.reason,
|
|
60
73
|
unattended: options.unattended,
|
|
61
|
-
}
|
|
74
|
+
};
|
|
75
|
+
saveChatFollowup({ id, kind: "bot", ownerId: botId, threadId, payload: item });
|
|
76
|
+
entry.items.push(item);
|
|
62
77
|
queues.set(threadId, entry);
|
|
63
78
|
changed();
|
|
64
79
|
return { id };
|
|
@@ -93,6 +108,7 @@ export function drainSteeredMessages(store, run, isBlocked) {
|
|
|
93
108
|
: store.bot(entry.botId);
|
|
94
109
|
if (!bot) {
|
|
95
110
|
// the bot or task was deleted while messages waited
|
|
111
|
+
settleChatFollowups(entry.items.map((item) => item.messageId), "cancelled");
|
|
96
112
|
queues.delete(threadId);
|
|
97
113
|
changed();
|
|
98
114
|
continue;
|
|
@@ -101,6 +117,8 @@ export function drainSteeredMessages(store, run, isBlocked) {
|
|
|
101
117
|
continue;
|
|
102
118
|
// committed to draining: the entry leaves the map before anything runs,
|
|
103
119
|
// so a settle racing another settle can never fire the same queue twice
|
|
120
|
+
const ids = entry.items.map((item) => item.messageId);
|
|
121
|
+
settleChatFollowups(ids, "dispatching");
|
|
104
122
|
queues.delete(threadId);
|
|
105
123
|
changed();
|
|
106
124
|
const appended = [];
|
|
@@ -124,10 +142,11 @@ export function drainSteeredMessages(store, run, isBlocked) {
|
|
|
124
142
|
// message into one HTML block, which makes that attachment stop being a
|
|
125
143
|
// native image when the combined follow-up is dispatched.
|
|
126
144
|
const prompt = entry.items.map((item) => item.prompt).join("\n\n");
|
|
127
|
-
|
|
145
|
+
const running = run(entry.botId, threadId, prompt, last, appended.map((message) => message.id),
|
|
128
146
|
// one unattended line makes the whole drained turn unattended: a
|
|
129
147
|
// person's words in the same queue cannot re-attend a bot's own
|
|
130
148
|
entry.items.some((item) => item.unattended === true));
|
|
149
|
+
void Promise.resolve(running).then(() => settleChatFollowups(ids, null), () => settleChatFollowups(ids, "interrupted")).catch((error) => console.warn("steer-queue: could not settle durable follow-up", error));
|
|
131
150
|
}
|
|
132
151
|
}
|
|
133
152
|
/** Find the receipt for a retry whose message is still waiting to drain. */
|
|
@@ -141,7 +160,7 @@ export function queuedSteeredMessage(botId, threadId, sendId) {
|
|
|
141
160
|
/** Drop one waiting send owned by this bot so it never drains. The queue id
|
|
142
161
|
* is stable even if the bot switches away from the task while the request is
|
|
143
162
|
* in flight. Returns false when it was already drained, belongs to another
|
|
144
|
-
* bot, or
|
|
163
|
+
* bot, or dispatch has already started. */
|
|
145
164
|
export function cancelSteeredMessage(botId, messageId, expectedThreadId) {
|
|
146
165
|
for (const [threadId, entry] of queues) {
|
|
147
166
|
if (entry.botId !== botId || (expectedThreadId !== undefined && threadId !== expectedThreadId))
|
|
@@ -149,6 +168,7 @@ export function cancelSteeredMessage(botId, messageId, expectedThreadId) {
|
|
|
149
168
|
const items = entry.items.filter((item) => item.messageId !== messageId);
|
|
150
169
|
if (items.length === entry.items.length)
|
|
151
170
|
continue;
|
|
171
|
+
settleChatFollowups([messageId], "cancelled");
|
|
152
172
|
if (items.length === 0)
|
|
153
173
|
queues.delete(threadId);
|
|
154
174
|
else
|
|
@@ -139,7 +139,7 @@ export function parseTeamManifest(value) {
|
|
|
139
139
|
*
|
|
140
140
|
* 1. Allowlist, not blocklist. The returned object is built field by field
|
|
141
141
|
* from the parsed member, so every privilege-bearing BotRecord field —
|
|
142
|
-
* approvalMode, autoApprove,
|
|
142
|
+
* approvalMode, autoApprove, alwaysAllow, chiefOfStaff, approvePeerComms, composio,
|
|
143
143
|
* computer, cloudBackend, cwd — is structurally absent, whatever the
|
|
144
144
|
* file claimed. parseTeamManifest already drops unknown member keys;
|
|
145
145
|
* this keeps the guarantee even if the schema grows a field later,
|
|
@@ -370,7 +370,10 @@ export class WebhookManager {
|
|
|
370
370
|
const requestedDeliveryId = String(event.deliveryId ?? "").trim().slice(0, 200);
|
|
371
371
|
if (requestedDeliveryId) {
|
|
372
372
|
const key = `${trigger.endpointId}:${requestedDeliveryId}`;
|
|
373
|
-
const
|
|
373
|
+
const committed = this.options.findRun?.(trigger.id, requestedDeliveryId);
|
|
374
|
+
const duplicate = committed
|
|
375
|
+
? { runId: committed.id }
|
|
376
|
+
: this.deliveries.find((delivery) => delivery.key === key);
|
|
374
377
|
if (duplicate) {
|
|
375
378
|
this.appendAttempt(trigger, event, {
|
|
376
379
|
outcome: "duplicate",
|
|
@@ -32,7 +32,7 @@ const EXCLUSION_NOTES = [
|
|
|
32
32
|
"External project folders, CLI login homes, browser session homes, OS keychains, companion devices and other servers.",
|
|
33
33
|
"VM/container disk layers and remote cloud data; durable files inside this workspace are included.",
|
|
34
34
|
];
|
|
35
|
-
const RESTORE_WARNING = "Restoring pauses routines, webhooks and calendar calls, and does not resume pending delegations or queued runs. Definitions and historical receipts are retained; review before enabling them again.";
|
|
35
|
+
const RESTORE_WARNING = "Restoring pauses routines, webhooks and calendar calls, and does not resume pending delegations, queued chat messages or queued runs. Definitions and historical receipts are retained; review before enabling them again.";
|
|
36
36
|
function excluded(name) {
|
|
37
37
|
return EXCLUDED.has(name) || excludedWorkspaceAuthPath(name) || name.startsWith("openmausbot-server.lease.") || name.startsWith("box-create-requests.lock.") || /^perm-[A-Za-z0-9_-]+\.sock$/.test(name);
|
|
38
38
|
}
|
|
@@ -887,17 +887,32 @@ function prepareRestore(dataDir, id, manifest) {
|
|
|
887
887
|
});
|
|
888
888
|
}
|
|
889
889
|
const dbPath = join(prepared, "messages.db");
|
|
890
|
-
if (existsSync(dbPath)
|
|
890
|
+
if (existsSync(dbPath)) {
|
|
891
891
|
const db = new DatabaseSync(dbPath);
|
|
892
892
|
try {
|
|
893
|
-
const update = db.prepare("UPDATE messages SET json = ?, text = ? WHERE thread_id = ? AND id = ?");
|
|
894
893
|
db.exec("BEGIN");
|
|
895
|
-
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
894
|
+
if (manifest.sourceDataDir !== resolve(dataDir)) {
|
|
895
|
+
const update = db.prepare("UPDATE messages SET json = ?, text = ? WHERE thread_id = ? AND id = ?");
|
|
896
|
+
for (const row of db.prepare("SELECT thread_id, id, json FROM messages").iterate()) {
|
|
897
|
+
const message = JSON.parse(String(row.json));
|
|
898
|
+
rebaseMessage(message, manifest.sourceDataDir, resolve(dataDir));
|
|
899
|
+
const json = JSON.stringify(message);
|
|
900
|
+
if (json !== row.json)
|
|
901
|
+
update.run(json, record(message) && typeof message.text === "string" ? message.text : null, row.thread_id, row.id);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
// Import is not a server restart: the source may still be running.
|
|
905
|
+
// Keep accepted words/receipts for review, but never execute a copy of
|
|
906
|
+
// its pending work (including when restoring to the original home).
|
|
907
|
+
if (db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'chat_followups'").get()) {
|
|
908
|
+
const pause = db.prepare("UPDATE chat_followups SET status = 'interrupted', payload = ? WHERE id = ?");
|
|
909
|
+
for (const row of db.prepare("SELECT id, payload FROM chat_followups WHERE status IN ('pending', 'dispatching', 'interrupted')").iterate()) {
|
|
910
|
+
const payload = JSON.parse(String(row.payload));
|
|
911
|
+
rebaseMessage(payload, manifest.sourceDataDir, resolve(dataDir));
|
|
912
|
+
if (record(payload))
|
|
913
|
+
delete payload.prompt;
|
|
914
|
+
pause.run(JSON.stringify(payload), row.id);
|
|
915
|
+
}
|
|
901
916
|
}
|
|
902
917
|
db.exec("COMMIT");
|
|
903
918
|
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
/** The
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/** The approval levels exposed by the app. Each one is a provider's own
|
|
2
|
+
* permission mode, passed through: OpenMausBot never decides a permission
|
|
3
|
+
* itself (Full access aside, which answers residual prompts because that is
|
|
4
|
+
* what the person granted). The order is the order the selector shows. */
|
|
5
|
+
export const APPROVAL_MODES = ["ask", "edits", "auto", "full", "custom"];
|
|
6
|
+
/** Only providers with an implemented permission mapping may expose a level.
|
|
7
|
+
* `edits` (auto-accept edits) exists where the engine has such a mode:
|
|
8
|
+
* Claude and Grok `acceptEdits`, Antigravity `auto_edit`. Codex's Ask already
|
|
9
|
+
* runs `workspace-write`, so an edits level would change nothing there. */
|
|
4
10
|
export function supportsApprovalMode(driverKind, mode) {
|
|
5
11
|
if (mode === "custom")
|
|
6
12
|
return driverKind === "codex";
|
|
13
|
+
if (mode === "edits")
|
|
14
|
+
return ["claudeAgent", "grokAgent", "antigravityAgent"].includes(driverKind ?? "");
|
|
7
15
|
if (mode !== "full")
|
|
8
16
|
return true;
|
|
9
17
|
return ["codex", "claudeAgent", "antigravityAgent", "cursorAgent", "grokAgent", "opencodeGo"].includes(driverKind ?? "");
|
|
@@ -11,13 +19,6 @@ export function supportsApprovalMode(driverKind, mode) {
|
|
|
11
19
|
export function hasNativeAutoReview(driverKind) {
|
|
12
20
|
return ["codex", "claudeAgent", "cursorAgent", "grokAgent"].includes(driverKind ?? "");
|
|
13
21
|
}
|
|
14
|
-
/** A native reviewer has already declined to decide, or Auto has no native
|
|
15
|
-
* equivalent. Never second-guess that request with the app's heuristic rules.
|
|
16
|
-
* Antigravity and OpenCode Full approve residual ACP tool-permission requests
|
|
17
|
-
* through the app's explicit Full-access grant. Questions remain interactive. */
|
|
18
|
-
export function requiresNativeApproval(driverKind, mode) {
|
|
19
|
-
return mode === "auto" || (mode === "full" && ["claudeAgent", "cursorAgent", "grokAgent"].includes(driverKind));
|
|
20
|
-
}
|
|
21
22
|
export function isApprovalMode(value) {
|
|
22
23
|
return typeof value === "string" && APPROVAL_MODES.includes(value);
|
|
23
24
|
}
|
|
@@ -15114,6 +15114,14 @@ var featureConfigSchema = external_exports.object({
|
|
|
15114
15114
|
* also has its own switch. */
|
|
15115
15115
|
browser: external_exports.boolean().optional()
|
|
15116
15116
|
});
|
|
15117
|
+
var onboardingConfigSchema = external_exports.object({
|
|
15118
|
+
/** ISO timestamp of finishing (or skipping to the end of) the welcome flow. */
|
|
15119
|
+
completedAt: external_exports.string().trim().max(40).optional(),
|
|
15120
|
+
/** Which welcome flow was completed; a newer flow may re-show itself. */
|
|
15121
|
+
version: external_exports.number().int().min(0).max(1e3).optional(),
|
|
15122
|
+
reelSeen: external_exports.boolean().optional(),
|
|
15123
|
+
hintsSeen: external_exports.array(external_exports.string().trim().min(1).max(60)).max(100).optional()
|
|
15124
|
+
}).strict();
|
|
15117
15125
|
var instanceConfigSchema = external_exports.object({
|
|
15118
15126
|
driver: external_exports.string().min(1),
|
|
15119
15127
|
displayName: optionalText,
|
|
@@ -15207,6 +15215,7 @@ var appConfigSchema = external_exports.object({
|
|
|
15207
15215
|
threads: external_exports.object({ maxConcurrentPerBot: external_exports.number().int().min(1).max(MAX_CONCURRENT_BOT_THREADS) }).strict().optional(),
|
|
15208
15216
|
localVm: localVmConfigSchema.optional(),
|
|
15209
15217
|
features: featureConfigSchema.optional(),
|
|
15218
|
+
onboarding: onboardingConfigSchema.optional(),
|
|
15210
15219
|
browserProfiles: browserProfilesSchema.optional(),
|
|
15211
15220
|
instances: instanceConfigMapSchema.optional(),
|
|
15212
15221
|
/** User-configured MCP servers, mounted into every capable engine. Kept
|