Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

feat(cli): threads archive and unarchive

AdityaUmale79fe190011c0
diff --git a/docs/headless-cli.md b/docs/headless-cli.md
index 02ddc26c39..2a5d15e302 100644
--- a/docs/headless-cli.md
+++ b/docs/headless-cli.md
@@ -144,6 +144,7 @@ one of its conversations.
| `bots pause BOTS`, `bots resume BOTS` | Pauses bots: their work stops and nothing new starts, across restarts, until resumed. `--team` pauses the team itself, so bots added to it later are paused too; `--all` pauses every bot. |
| `stop BOTS` (or `bots stop`) | Stops the work these bots are doing now, and pauses nothing: a new message or routine starts them again. |
| `threads list BOT`, `threads clear BOT`, `threads delete BOT THREAD…` | A bot's conversations; `clear` deletes all of them and the bot starts one new, empty one. A conversation that is working is kept. |
+| `threads archive BOT THREAD…`, `threads unarchive BOT THREAD…` | Archives conversations by id, as the app's Archive does, or brings them back. `threads list` marks archived ones. |
| `computers list`, `computers start BOT`, `computers sleep BOT` | Where each bot works and its cloud computer's state; create or wake a bot's cloud computer (the bot must be set to Cloud computer), or put it to sleep. |
| `messages TARGET [--limit 30]` | The latest messages of a conversation. |
| `send TARGET TEXT` | Sends one message and returns at once, to the conversation the bot or room has open. `--task new` starts a new conversation for it (`--title` names it, else the message's first line), and `--task ID` picks one. It says which conversation it went to. `--send-id ID` makes a retry safe: the same id never sends twice. |
diff --git a/server/cli-usage.ts b/server/cli-usage.ts
index 3e07c2d419..dcfa4229a6 100644
--- a/server/cli-usage.ts
+++ b/server/cli-usage.ts
@@ -15,7 +15,7 @@ export const HEADLESS_USAGE = `Drive a running workspace (scripts, CI, other age
openmausbot status every bot at a glance: working, waiting on you, paused, failed or idle, and its computer
openmausbot bots delete|pause|resume|stop (BOT… | --team T | --all) act on bots; delete asks first (--yes, --dry-run)
openmausbot stop (BOT… | --team T | --all) stop their work now, without pausing
- openmausbot threads list|clear|delete BOT a bot's conversations
+ openmausbot threads list|clear|delete|archive|unarchive BOT a bot's conversations
openmausbot computers list|start|sleep the bots' cloud computers
openmausbot doctor check the server answers and an engine is ready
openmausbot doctor --host check this Linux machine can run a server (exit 7 if not)
diff --git a/server/headless/args.test.ts b/server/headless/args.test.ts
index 6def151dc1..8541bdb4d3 100644
--- a/server/headless/args.test.ts
+++ b/server/headless/args.test.ts
@@ -41,7 +41,7 @@ describe("parseCommand", () => {
it("knows which verbs change something", () => {
for (const verb of ["send", "run", "interrupt", "team apply", "engine set", "token create", "token revoke", "bots delete", "bots pause", "stop",
- "threads clear", "threads delete", "computers start", "computers sleep"]) expect(MUTATING_VERBS.has(verb), verb).toBe(true);
+ "threads clear", "threads delete", "threads archive", "threads unarchive", "computers start", "computers sleep"]) expect(MUTATING_VERBS.has(verb), verb).toBe(true);
for (const verb of ["doctor", "bots", "bots list", "bots get", "status", "whoami", "threads list", "computers list", "wait", "messages", "export", "events", "team export", "engine list"]) {
expect(MUTATING_VERBS.has(verb), verb).toBe(false);
}
@@ -55,7 +55,7 @@ describe("parseCommand", () => {
expect(parseCommand(["bots", "delete", "QA 1", "QA 2", "--dry-run"])).toMatchObject({ verb: "bots delete", positionals: ["QA 1", "QA 2"], flags: { "dry-run": true } });
expect(parseCommand(["bots", "pause", "--team", "Support"])).toMatchObject({ verb: "bots pause", flags: { team: "Support" } });
expect(parseCommand(["stop", "--all", "-y"])).toMatchObject({ verb: "stop", flags: { all: true, yes: true } });
- expect(usage(() => parseCommand(["threads"]))).toMatchObject({ exitCode: 2, message: "threads needs one of: list, clear, delete" });
+ expect(usage(() => parseCommand(["threads"]))).toMatchObject({ exitCode: 2, message: "threads needs one of: list, clear, delete, archive, unarchive" });
expect(usage(() => parseCommand(["bots", "pause", "x", "--yes"]))).toMatchObject({ exitCode: 2 });
// no flag skips a permission or approval of any kind
for (const verb of ["stop", "bots delete", "threads clear", "login"]) {
diff --git a/server/headless/args.ts b/server/headless/args.ts
index 3535072642..7944bf3d49 100644
--- a/server/headless/args.ts
+++ b/server/headless/args.ts
@@ -93,6 +93,8 @@ const VERBS: Record<string, { options: ParseArgsOptionsConfig; positionals: numb
"threads list": { options: {}, positionals: 1 },
"threads clear": { options: CAREFUL, positionals: 1 },
"threads delete": { options: CAREFUL, positionals: MANY },
+ "threads archive": { options: {}, positionals: MANY },
+ "threads unarchive": { options: {}, positionals: MANY },
"computers list": { options: {}, positionals: 0 },
"computers start": { options: { "dry-run": { type: "boolean" } }, positionals: 1 },
"computers sleep": { options: { "dry-run": { type: "boolean" } }, positionals: 1 },
@@ -157,7 +159,7 @@ export const HEADLESS_VERBS: ReadonlySet<string> = new Set(Object.keys(VERBS).ma
/** Verbs that change something; control-omb refuses them on a discovered server. */
export const MUTATING_VERBS: ReadonlySet<string> = new Set([
"send", "send-channel", "run", "interrupt", "new-bot", "new-channel", "set-model", "edit", "team apply", "engine set", "token create", "token revoke",
- "bots delete", "bots pause", "bots resume", "bots stop", "stop", "threads clear", "threads delete", "computers start", "computers sleep",
+ "bots delete", "bots pause", "bots resume", "bots stop", "stop", "threads clear", "threads delete", "threads archive", "threads unarchive", "computers start", "computers sleep",
]);
export type Flags = Record<string, string | boolean | string[] | undefined>;
@@ -169,7 +171,7 @@ export interface ParsedCommand {
}
const SUBCOMMANDS = new Map([["team", ["apply", "export"]], ["engine", ["set", "list"]], ["token", ["create", "list", "revoke"]],
- ["threads", ["list", "clear", "delete"]], ["computers", ["list", "start", "sleep"]]]);
+ ["threads", ["list", "clear", "delete", "archive", "unarchive"]], ["computers", ["list", "start", "sleep"]]]);
/** `bots` alone still lists them, as it always has. */
const OPTIONAL_SUBCOMMANDS = new Map([["bots", ["list", "get", "delete", "pause", "resume", "stop"]]]);
diff --git a/server/headless/fleet.ts b/server/headless/fleet.ts
index 6617a4bc95..361b855a64 100644
--- a/server/headless/fleet.ts
+++ b/server/headless/fleet.ts
@@ -282,16 +282,17 @@ async function deleteThreads(ctx: VerbContext, client: HeadlessClient, bot: Rec,
export async function threadsVerb(ctx: VerbContext): Promise<VerbOutcome> {
const [wanted, ...threadIds] = ctx.positionals.map((value) => value.trim());
- if (!wanted) throw usageError("name a bot", `openmausbot ${ctx.verb} BOT${ctx.verb === "threads delete" ? " THREAD…" : ""}`);
+ const byId = ctx.verb !== "threads list" && ctx.verb !== "threads clear";
+ if (!wanted) throw usageError("name a bot", `openmausbot ${ctx.verb} BOT${byId ? " THREAD…" : ""}`);
const client = await ctx.client();
const bot = findBot(await readBots(client), wanted);
const tasks: Rec[] = bot.tasks ?? [];
if (ctx.verb === "threads list") {
return {
- result: { bot: { id: bot.id, name: bot.name }, threads: tasks.map((task) => ({ id: task.threadId, title: task.title ?? null, busy: Boolean(task.busy), active: task.threadId === bot.threadId, createdAt: task.createdAt ?? null })) },
+ result: { bot: { id: bot.id, name: bot.name }, threads: tasks.map((task) => ({ id: task.threadId, title: task.title ?? null, busy: Boolean(task.busy), archived: task.archivedAt !== undefined, active: task.threadId === bot.threadId, createdAt: task.createdAt ?? null })) },
exitCode: EXIT.done,
human: tasks.length
- ? table([["THREAD", "TITLE", "STATE"], ...tasks.map((task) => [task.threadId, `${task.threadId === bot.threadId ? "* " : ""}${task.title || "Untitled"}`, task.busy ? "working" : "idle"])])
+ ? table([["THREAD", "TITLE", "STATE"], ...tasks.map((task) => [task.threadId, `${task.threadId === bot.threadId ? "* " : ""}${task.title || "Untitled"}`, task.busy ? "working" : task.archivedAt !== undefined ? "archived" : "idle"])])
: [`${bot.name} has no conversations.`],
};
}
@@ -300,13 +301,24 @@ export async function threadsVerb(ctx: VerbContext): Promise<VerbOutcome> {
if (!tasks.length) return { result: { ok: true, deleted: [] }, exitCode: EXIT.done, human: [`${bot.name} has no conversations.`] };
return deleteThreads(ctx, client, bot, tasks, true);
}
- if (!threadIds.length) throw usageError("name the conversations to delete", "openmausbot threads list BOT shows their ids");
- const picked = threadIds.map((id) => {
+ const action = ctx.verb.slice("threads ".length);
+ if (!threadIds.length) throw usageError(`name the conversations to ${action}`, "openmausbot threads list BOT shows their ids");
+ const picked = [...new Map(threadIds.map((id) => {
const task = tasks.find((candidate) => candidate.threadId === id);
if (!task) throw new HeadlessError(`${bot.name} has no conversation ${id}`, EXIT.notFound, `openmausbot threads list "${bot.name}" shows them`);
- return task;
- });
- return deleteThreads(ctx, client, bot, [...new Map(picked.map((task) => [task.threadId, task])).values()], false);
+ return [id, task] as const;
+ })).values()];
+ if (ctx.verb === "threads delete") return deleteThreads(ctx, client, bot, picked, false);
+ const archiving = ctx.verb === "threads archive";
+ const ids = picked.map((task) => task.threadId as string);
+ for (const id of ids) {
+ await client.json(`/api/bots/${encodeURIComponent(bot.id)}/tasks/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify({ archivedAt: archiving ? Date.now() : null }) });
+ }
+ return {
+ result: { ok: true, action, bot: { id: bot.id, name: bot.name }, [archiving ? "archived" : "unarchived"]: ids },
+ exitCode: EXIT.done,
+ human: [`${archiving ? "Archived" : "Unarchived"} ${plural(ids.length, "conversation")} of ${bot.name}.`],
+ };
}
async function computerChange(client: HeadlessClient, botId: string, action: "provision" | "sleep"): Promise<Rec> {
diff --git a/server/headless/login.e2e.test.ts b/server/headless/login.e2e.test.ts
index c940b9966b..71d29ae8d4 100644
--- a/server/headless/login.e2e.test.ts
+++ b/server/headless/login.e2e.test.ts
@@ -131,6 +131,15 @@ describe("openmausbot login, then status, bots, stop and threads against the des
const threads = await cli(["threads", "list", "Support Lead", "--json"]);
expect(JSON.parse(threads.out).threads).toHaveLength(1);
+ const threadId = JSON.parse(threads.out).threads[0].id;
+ const archived = await cli(["threads", "archive", "Support Lead", threadId, "--json"]);
+ expect(archived.code).toBe(0);
+ expect(JSON.parse(archived.out)).toMatchObject({ ok: true, action: "archive", archived: [threadId] });
+ expect(JSON.parse((await cli(["threads", "list", "Support Lead", "--json"])).out).threads[0]).toMatchObject({ id: threadId, archived: true });
+ expect(JSON.parse((await cli(["threads", "unarchive", "Support Lead", threadId, "--json"])).out)).toMatchObject({ ok: true, action: "unarchive", unarchived: [threadId] });
+ expect(JSON.parse((await cli(["threads", "list", "Support Lead", "--json"])).out).threads[0]).toMatchObject({ id: threadId, archived: false });
+ expect((await cli(["threads", "archive", "Support Lead", "no-such-thread"])).code).toBe(7);
+ expect((await cli(["threads", "archive", "Support Lead"])).code).toBe(2);
const cleared = await cli(["threads", "clear", "Support Lead", "--yes", "--json"]);
expect(cleared.code).toBe(0);
expect(JSON.parse(cleared.out).deleted).toHaveLength(1);
diff --git a/server/headless/main.ts b/server/headless/main.ts
index 8cf3e8e069..6980148c5d 100644
--- a/server/headless/main.ts
+++ b/server/headless/main.ts
@@ -64,12 +64,15 @@ openmausbot bots stop (BOT… | --team NAME | --all) [--dry-run] [--yes]
Stop the work these bots are doing now: every conversation, routine run and hand-off. Nothing is paused, so a new
message or routine starts them again. --all prints the bots working now and asks first.`,
threads: `openmausbot threads list BOT
+openmausbot threads archive|unarchive BOT THREAD… hide conversations from the list, or bring them back
openmausbot threads clear BOT [--dry-run] [--yes] delete every conversation (the bot keeps one new, empty one)
openmausbot threads delete BOT THREAD… [--dry-run] [--yes]
A conversation that is working is kept: stop it first.`,
"threads list": "openmausbot threads list BOT\n A bot's conversations; * marks the one it has open.",
"threads clear": "openmausbot threads clear BOT [--dry-run] [--yes]\n Delete all of a bot's conversations; it keeps one new, empty one. Prints the list and asks first.",
"threads delete": "openmausbot threads delete BOT THREAD… [--dry-run] [--yes]\n Delete some of a bot's conversations, by id (threads list shows them). Prints the list and asks first.",
+ "threads archive": "openmausbot threads archive BOT THREAD…\n Archive some of a bot's conversations, by id (threads list shows them); threads unarchive brings them back.",
+ "threads unarchive": "openmausbot threads unarchive BOT THREAD…\n Bring archived conversations back, by id (threads list marks them archived).",
computers: `openmausbot computers list where each bot works, and its cloud computer's state
openmausbot computers start BOT create or wake a bot's cloud computer (the bot must be set to Cloud computer)
openmausbot computers sleep BOT put it to sleep; it wakes when the bot needs it`,
@@ -171,7 +174,7 @@ const VERBS: Record<string, (ctx: VerbContext) => Promise<VerbOutcome>> = {
"token create": tokenVerb, "token list": tokenVerb, "token revoke": tokenVerb,
login: loginVerb, logout: logoutVerb, whoami: whoamiVerb, use: useVerb, servers: serversVerb, status: statusVerb,
"bots list": list, "bots get": botsVerb, "bots delete": botsVerb, "bots pause": botsVerb, "bots resume": botsVerb, "bots stop": botsVerb,
- stop: stopVerb, "threads list": threadsVerb, "threads clear": threadsVerb, "threads delete": threadsVerb,
+ stop: stopVerb, "threads list": threadsVerb, "threads clear": threadsVerb, "threads delete": threadsVerb, "threads archive": threadsVerb, "threads unarchive": threadsVerb,
"computers list": computersVerb, "computers start": computersVerb, "computers sleep": computersVerb,
};