diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51e8c7e..5f96d7c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: run: | npm exec --yes --package=@anthropic-ai/claude-code@2.1.291 -- claude plugin validate ./plugins/openorange --strict npm exec --yes --package=@anthropic-ai/claude-code@2.1.291 -- claude plugin validate . --strict - # The Buzz Desktop plugin against a stub ACP agent in place of `oo acp`: no Sunport, no network. + # The Buzz Desktop plugin against stubs in place of `oo acp` and `oo buzz hosted`: no Sunport, no network. buzz-plugin: name: Buzz plugin runs-on: ubuntu-24.04 diff --git a/README.md b/README.md index d0c7d22..b3bc569 100644 --- a/README.md +++ b/README.md @@ -194,10 +194,11 @@ on the Bot's computer. Grok Bot's computer can also run the `oo` CLI ## Buzz Desktop The Buzz plugin is in [`packages/buzz/openorange-buzz`](packages/buzz/openorange-buzz). -It makes OpenOrange an agent type in Buzz Desktop: mention your agent in a +It makes OpenOrange agent types in Buzz Desktop: mention your agent in a thread and it answers there from your Sunport, each thread one continuing -conversation. Buzz passes the messages to `oo` on your computer, which reaches -your Sunport as you. +conversation. With **OpenOrange**, Buzz passes the messages to `oo` on your +computer, which reaches your Sunport as you, while Buzz Desktop is open. With +**OpenOrange (always on)**, your Sunport answers in Buzz itself (below). You need Buzz Desktop and, on the same computer, the `oo` CLI with `oo login` done ([CLI guide](usage/references/cli.md)). @@ -211,12 +212,29 @@ done ([CLI guide](usage/references/cli.md)). Or, in Buzz, open **Settings › Plugins › Manage plugins**, choose **Add**, and enter the repository `2bb-dev/openorange-integrations` and the folder `packages/buzz/openorange-buzz`. Buzz shows the access the plugin asks for, - starting `oo acp`; choose **Install plugin**. + starting `oo acp` and `oo buzz hosted`; choose **Install plugin**. 2. Open **Agents › New agent › Custom › Harness › OpenOrange**. The agent is Clem on your Sunport. 3. Mention the agent in a thread. It answers only your own mentions, while Buzz Desktop is open. +### Always on + +An always-on agent is Clem on your Sunport, which runs it in Buzz itself: it +answers even while Buzz Desktop is closed and your computer is off. It needs a +current Sunport. The plugin and `oo` above set it up; it answers without them. + +1. Open **Agents › New agent › Custom › Harness › OpenOrange (always on)** + (under Remote), name the agent and create it. +2. Your browser opens once for you to sign in to Buzz. If the setup stops + before it finishes, choose **Finish setup** on the agent. +3. Add the agent to a channel in Buzz and mention it there. It answers only + your own mentions. + +Buzz asks for a new sign-in from time to time. Until you give it one, the agent +doesn't answer: run `oo buzz renew` in a terminal, which opens your browser to +sign in again. + ## The packages The Claude, OpenAI and Grok Bot packages use the same [MCP guide](usage/references/mcp.md) and diff --git a/packages/buzz/openorange-buzz/README.md b/packages/buzz/openorange-buzz/README.md index cbb91a2..4af6eef 100644 --- a/packages/buzz/openorange-buzz/README.md +++ b/packages/buzz/openorange-buzz/README.md @@ -12,3 +12,20 @@ conversation. and **OpenOrange**. 3. Mention the agent in a thread. It answers your own mentions while Buzz Desktop is open. + +## Always on + +Choose the harness **OpenOrange (always on)** instead, under Remote, and your +Sunport runs the agent in Buzz itself: it answers even while Buzz Desktop is +closed and this computer is off. It needs a current Sunport. + +1. With `oo` installed and signed in as above, create the agent with the + harness **OpenOrange (always on)**. +2. Your browser opens once for you to sign in to Buzz. If the setup stops + before it finishes, choose **Finish setup** on the agent. +3. Add the agent to a channel in Buzz and mention it there. It answers only + your own mentions. + +Buzz asks for a new sign-in from time to time. Until you give it one, the agent +doesn't answer: run `oo buzz renew` in a terminal, which opens your browser to +sign in again. diff --git a/packages/buzz/openorange-buzz/manifest.json b/packages/buzz/openorange-buzz/manifest.json index 5bcb484..ae1e330 100644 --- a/packages/buzz/openorange-buzz/manifest.json +++ b/packages/buzz/openorange-buzz/manifest.json @@ -2,7 +2,7 @@ "id": "openorange.agents", "name": "OpenOrange", "apiVersion": 1, - "description": "Talk to your OpenOrange agents, such as Clem, in Buzz. They keep running on your Sunport; this computer only passes messages.", + "description": "Talk to your OpenOrange agents, such as Clem, in Buzz. They run on your Sunport and answer through this computer while Buzz Desktop is open, or always on from your Sunport.", "host": { "processes": [ { @@ -11,6 +11,14 @@ "args": [ "acp" ] + }, + { + "id": "oo-buzz", + "program": "oo", + "args": [ + "buzz", + "hosted" + ] } ] } diff --git a/packages/buzz/openorange-buzz/plugin.js b/packages/buzz/openorange-buzz/plugin.js index 3b5108b..1050dc3 100644 --- a/packages/buzz/openorange-buzz/plugin.js +++ b/packages/buzz/openorange-buzz/plugin.js @@ -1,11 +1,17 @@ -// OpenOrange in Buzz: an agent type whose agents are the owner's agents on their Sunport, Clem unless the agent's -// config names another. Buzz keeps the agent's identity and posts its replies. Each thread the agent is mentioned in is -// one continuing conversation with the Sunport's agent, reached through `oo acp` (the Agent Client Protocol on stdin -// and stdout), which signs in as the person who ran `oo login`. Nothing of the agent runs on this computer, and no key -// of Buzz's ever reaches `oo`. +// OpenOrange in Buzz: two agent types whose agents are the owner's agents on their Sunport. +// +// "OpenOrange" (`agent`): Clem unless the agent's config names another. Buzz keeps the agent's identity and posts its +// replies. Each thread the agent is mentioned in is one continuing conversation with the Sunport's agent, reached +// through `oo acp` (the Agent Client Protocol on stdin and stdout), which signs in as the person who ran `oo login`. +// Nothing of the agent runs on this computer, and no key of Buzz's ever reaches `oo`. +// +// "OpenOrange (always on)" (`hosted`): an agent Buzz calls hosted. The owner's Sunport makes and keeps its key, hears +// the owner's mentions and posts the replies itself, so it answers while this computer is off. This computer only +// makes, sets up, renames and removes it, each step one `oo buzz hosted `. export const inject = ["agents", "host"]; const TYPE_ID = "agent"; +const HOSTED_TYPE_ID = "hosted"; /** The Sunport agent a Buzz agent is, when its config names none. */ const DEFAULT_AGENT = "clem"; const SAVED = "openorange.agents.sessions.v1"; @@ -39,6 +45,7 @@ export function apply(ctx) { return next; }, }); + agents.register(hostedType(host)); } /** The Sunport agent a Buzz agent's config names: an id or alias `oo acp --agent` takes. */ @@ -317,3 +324,82 @@ function createSaved(storage) { }, }; } + +/** The always-on type: Clem on the owner's Sunport, which keeps the agent's key and answers in Buzz itself. Buzz runs + * these steps one at a time for an agent and asks a failed one again, so the Sunport makes each safe to repeat. None + * has a deadline: activate waits while the owner signs in to Buzz in their browser. */ +function hostedType(host) { + return { + id: HOSTED_TYPE_ID, + title: "OpenOrange (always on)", + description: + "Clem on your OpenOrange Sunport, which runs it, so it answers your mentions even while this computer is off. oo on this computer sets it up with one sign-in to Buzz.", + defaults: () => ({ config: {} }), + remote: { + async provision({ name, picture, community, signal }) { + const { pubkey } = await hosted(host, "provision", { community, name, ...(picture && { picture }) }, signal); + // The picture it was made with, which Buzz keeps for a retried creation. + return { pubkey, ...(picture && { picture }) }; + }, + async activate({ pubkey, community, name, auth, signal }) { + await hosted(host, "activate", { pubkey, community, name, auth }, signal); + }, + async profile({ pubkey, community, name, picture, signal }) { + await hosted(host, "profile", { pubkey, community, name, ...(picture && { picture }) }, signal); + }, + async remove({ pubkey, community, signal }) { + await hosted(host, "remove", { pubkey, community }, signal); + }, + async interrupt({ pubkey, community, channelId, threadRootId, signal }) { + const { stopped } = await hosted(host, "interrupt", { pubkey, community, channel: channelId, root: threadRootId }, signal); + return stopped === true; + }, + }, + }; +} + +/** One `oo buzz hosted `: the step's input as a JSON object on its stdin, its answer one on its stdout, and on + * failure the reason as its last line on stderr. Ended when Buzz stops waiting for it. */ +async function hosted(host, step, input, signal) { + // Buzz no longer waits: start nothing, so activate opens no browser. + signal.throwIfAborted(); + let answer = ""; + let errors = ""; + let oo; + try { + oo = await host.spawn("oo-buzz", { + args: [step], + onStdout: (data) => void (answer += data), + onStderr: (data) => void (errors = (errors + data).slice(-1200)), + }); + } catch (error) { + if (/os error 2|no such file|not found/i.test(String(error?.message ?? error))) + throw new Error( + "The oo command was not found on this computer. Install it from your Sunport (Connect, then Command line), run `oo login`, and try again.", + ); + throw error; + } + // An oo that ended before reading its input is answered by its exit; one still running would wait for it forever. + oo.end(JSON.stringify(input)).catch(() => oo.kill()); + const code = await new Promise((resolve, reject) => { + const stop = () => { + void oo.kill(); + reject(signal.reason); + }; + if (signal.aborted) return stop(); + signal.addEventListener("abort", stop, { once: true }); + oo.exited.then((exit) => { + signal.removeEventListener("abort", stop); + resolve(exit); + }, reject); + }); + if (code !== 0) throw new Error(errors.trim().split("\n").pop().trim() || "oo stopped without saying why."); + let result; + try { + result = JSON.parse(answer); + } catch { + // Read as not an answer, below. + } + if (!result || typeof result !== "object") throw new Error("oo's answer could not be read. Update oo with `oo update`, then try again."); + return result; +} diff --git a/scripts/package.py b/scripts/package.py index dcc9c49..3a746ef 100644 --- a/scripts/package.py +++ b/scripts/package.py @@ -42,16 +42,18 @@ HOST_FILES = {"openai": {"assets/openorange-logo-512.png": "assets/openorange-logo-512.png"}} # Buzz Desktop installs this folder from the repository as it is, so nothing here generates or builds it: its manifest, # one self-contained plugin.js and a README. Buzz refuses a manifest with any other key, updates an installed plugin by -# its id, and shows the person the computer access it asks for at install: starting `oo acp`, nothing else. +# its id, and shows the person the computer access it asks for at install: starting `oo acp` (an agent answering while +# Buzz Desktop is open) and `oo buzz hosted` (setting up an always-on one), nothing else. BUZZ = "packages/buzz/openorange-buzz" BUZZ_FILES = ("manifest.json", "plugin.js", "README.md") BUZZ_MANIFEST = {"id", "name", "apiVersion", "description", "discovery", "host"} -BUZZ_HOST = {"processes": [{"id": "oo", "program": "oo", "args": ["acp"]}]} +BUZZ_HOST = {"processes": [{"id": "oo", "program": "oo", "args": ["acp"]}, + {"id": "oo-buzz", "program": "oo", "args": ["buzz", "hosted"]}]} SOURCE_FILES = { "README.md", "LICENSE", ".gitignore", ".claude-plugin/marketplace.json", ".cursor-plugin/marketplace.json", "assets/openorange.svg", "assets/openorange-icon-1024.png", "assets/openorange-logo-512.png", "usage/README.md", "usage/SKILL.md", "usage/references/mcp.md", "usage/references/cli.md", "usage/agent-guide.json", "scripts/package.py", "scripts/live_tools.py", "tests/test_package.py", - "tests/test_buzz_plugin.mjs", "tests/acp_stub.mjs", ".github/workflows/ci.yml", + "tests/test_buzz_plugin.mjs", "tests/acp_stub.mjs", "tests/hosted_stub.mjs", ".github/workflows/ci.yml", } # How an agent stays in touch with its Sunport comes from one source in the Layer # (packages/billing/src/contracts/agent-guide.ts). Its guideJson() export is vendored @@ -190,7 +192,7 @@ def check(root): buzz = json.loads(read_file(root, f"{BUZZ}/manifest.json")) if (not set(buzz) <= BUZZ_MANIFEST or buzz.get("id") != "openorange.agents" or buzz.get("apiVersion") != 1 or buzz.get("host") != BUZZ_HOST): - raise ValueError("Buzz plugin must keep its id, the manifest keys Buzz accepts and only oo acp") + raise ValueError("Buzz plugin must keep its id, the manifest keys Buzz accepts and only oo acp and oo buzz hosted") expected.update(f"{BUZZ}/{name}" for name in BUZZ_FILES) actual = set() for path in root.rglob("*"): diff --git a/tests/hosted_stub.mjs b/tests/hosted_stub.mjs new file mode 100644 index 0000000..af40f6b --- /dev/null +++ b/tests/hosted_stub.mjs @@ -0,0 +1,50 @@ +// A stand-in for `oo buzz hosted ` with no Sunport behind it: the step's input as one JSON object on stdin, its +// answer as one on stdout, or a line of progress and then the reason on stderr and exit 1. Each call (its arguments and +// input) and the agents made are kept in the file named by HOSTED_STUB_STATE, so a test can read them and a later call +// finds the agents an earlier one made: provision answers a repeat with the same agent. HOSTED_STUB='{"": …}' +// changes a step: "wait" (milliseconds before it answers), "hang" (never answers, until it is ended), "fail" (the +// reason it fails with), "exit" (a code it exits with, saying nothing), "answer" (raw text in place of its answer), +// "stopped" (interrupt's answer; true by default). +import { createHash } from "node:crypto"; +import { readFileSync, writeFileSync } from "node:fs"; + +const file = process.env.HOSTED_STUB_STATE; +const args = process.argv.slice(2); +const step = args.at(-1); +const how = JSON.parse(process.env.HOSTED_STUB || "{}")[step] ?? {}; +let state; +try { + state = JSON.parse(readFileSync(file, "utf8")); +} catch { + state = { calls: [], agents: {} }; +} +const save = () => writeFileSync(file, JSON.stringify(state)); + +let stdin = ""; +process.stdin.setEncoding("utf8"); +for await (const data of process.stdin) stdin += data; +const input = JSON.parse(stdin); +state.calls.push({ args, input }); +save(); + +if (how.hang) setInterval(() => undefined, 60_000); +else { + await new Promise((resolve) => setTimeout(resolve, how.wait ?? 0)); + if (how.fail) { + process.stderr.write(`Working on ${step}…\n${how.fail}\n`); + process.exit(1); + } + if (how.exit) process.exit(how.exit); + let answer = {}; + if (step === "provision") { + const key = `${input.community} ${input.name}`; + state.agents[key] ??= { + id: `agent-${Object.keys(state.agents).length + 1}`, + pubkey: createHash("sha256").update(key).digest("hex"), + }; + save(); + answer = state.agents[key]; + } else if (step === "activate") answer = { state: "active" }; + else if (step === "interrupt") answer = { stopped: how.stopped ?? true }; + process.stdout.write(how.answer ?? `${JSON.stringify(answer)}\n`); +} diff --git a/tests/test_buzz_plugin.mjs b/tests/test_buzz_plugin.mjs index eda6193..c8fa2fd 100644 --- a/tests/test_buzz_plugin.mjs +++ b/tests/test_buzz_plugin.mjs @@ -1,6 +1,7 @@ // The Buzz Desktop plugin (packages/buzz/openorange-buzz) run outside Buzz, with no Sunport and no network: a stand-in // for the plugin context Buzz gives it (agents.register, agents.harness, host.spawn, as Buzz's plugin docs give them) -// starts the stub ACP agent beside this file wherever the plugin starts `oo`. +// starts the stubs beside this file wherever the plugin starts `oo`: the stub ACP agent for `oo acp`, and the stub +// `oo buzz hosted` for the always-on type's steps. import assert from "node:assert/strict"; import { spawn } from "node:child_process"; import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; @@ -14,6 +15,9 @@ const manifest = JSON.parse(readFileSync(new URL("manifest.json", folder), "utf8 // Buzz loads plugin.js from a blob URL, where any import fails; a data URL holds it to one self-contained file alike. const plugin = await import(`data:text/javascript;base64,${readFileSync(new URL("plugin.js", folder)).toString("base64")}`); const STUB = fileURLToPath(new URL("acp_stub.mjs", import.meta.url)); +const HOSTED_STUB = fileURLToPath(new URL("hosted_stub.mjs", import.meta.url)); +/** The stub each declared process starts. */ +const STUBS = { oo: STUB, "oo-buzz": HOSTED_STUB }; const OWNER = "owner-pubkey"; const FIRST_TURN = "\n\n(Sent from Buzz, #general. Your reply is posted there as your message.)"; @@ -21,7 +25,8 @@ const FIRST_TURN = "\n\n(Sent from Buzz, #general. Your reply is posted there as function computer(t, { installed = true, env = {} } = {}) { const dir = mkdtempSync(join(tmpdir(), "buzz-plugin-")); const file = join(dir, "acp-stub.json"); - const program = installed ? [process.execPath, STUB] : [join(dir, "oo")]; + const hostedFile = join(dir, "hosted-stub.json"); + const program = installed ? (id) => [process.execPath, STUBS[id]] : () => [join(dir, "oo")]; const stored = new Map(); const runs = []; t.after(async () => { @@ -31,6 +36,8 @@ function computer(t, { installed = true, env = {} } = {}) { return { /** What the stub `oo` was started with and received, or nothing when no `oo` started. */ stub: () => (existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : undefined), + /** Each `oo buzz hosted` call's arguments and input, and the agents made, or nothing when none ran. */ + hostedStub: () => (existsSync(hostedFile) ? JSON.parse(readFileSync(hostedFile, "utf8")) : undefined), /** The Sunport no longer has this session. */ forget(session) { const state = JSON.parse(readFileSync(file, "utf8")); @@ -40,7 +47,7 @@ function computer(t, { installed = true, env = {} } = {}) { /** Buzz starting with the plugin turned on. */ start() { globalThis.localStorage = { getItem: (key) => stored.get(key) ?? null, setItem: (key, value) => void stored.set(key, value) }; - const buzz = run(program, { ...env, ACP_STUB_STATE: file }); + const buzz = run(program, { ...env, ACP_STUB_STATE: file, HOSTED_STUB_STATE: hostedFile }); runs.push(buzz); return buzz; }, @@ -52,7 +59,7 @@ function run(program, env) { const cleanups = []; const children = []; let restored = 0; - let type; + const types = []; const kit = { // Buzz's kit admits only the owner's own mentions. async conversation(delivery) { @@ -90,7 +97,7 @@ function run(program, env) { async spawn(id, options = {}) { const declared = manifest.host.processes.find((entry) => entry.id === id); if (!declared) throw new Error(`undeclared process ${id}`); - const [command, ...first] = program; + const [command, ...first] = program(id); const args = [...first, ...(declared.args ?? []), ...(options.args ?? [])]; const child = spawn(command, args, { env: { ...process.env, ...env }, stdio: "pipe" }); child.stdin.on("error", () => undefined); // a write after the process ended fails through its callback @@ -106,20 +113,22 @@ function run(program, env) { children.push({ child, exited }); return { write: (data) => new Promise((resolve, reject) => child.stdin.write(data, (error) => (error ? reject(error) : resolve()))), - end: async () => void child.stdin.end(), + end: (data = "") => new Promise((resolve, reject) => child.stdin.end(data, (error) => (error ? reject(error) : resolve()))), kill: async () => void child.kill("SIGTERM"), exited, }; }, }; plugin.apply({ - agents: { harness: kit, register: (registered) => (type = registered) }, + agents: { harness: kit, register: (registered) => types.push(registered) }, host, effect: (start) => cleanups.push(start()), }); let stopped; return { - type, + types, + type: types.find((registered) => registered.id === "agent"), + hosted: types.find((registered) => registered.id === "hosted"), replies, restored: () => restored, /** How many of the processes the plugin started are still running. */ @@ -292,3 +301,135 @@ test("an oo that fails as it starts is ended, so later mentions leave none runni for (let waited = 0; buzz.running() && waited < 50; waited++) await new Promise((resolve) => setTimeout(resolve, 100)); assert.equal(buzz.running(), 0); }); + +// The always-on type. Buzz calls its steps with these, each with the community connection's signal. +const COMMUNITY = "wss://community.example"; +const PICTURE = "https://pictures.example/clem.png"; +/** The owner's proof that the agent is theirs, as Buzz hands it to activate. */ +const AUTH = ["auth", OWNER, "kind=9", "owner-signature"]; +const HOSTED = ["buzz", "hosted"]; +const signal = () => new AbortController().signal; +const until = async (done) => { + for (let waited = 0; !done() && waited < 100; waited++) await new Promise((resolve) => setTimeout(resolve, 50)); + assert.ok(done()); +}; + +test("registers the always-on type beside the local one: hosted, with its five steps and no run", (t) => { + const here = computer(t); + const { types, type, hosted } = here.start(); + assert.deepEqual( + types.map((registered) => [registered.id, registered.title]), + [ + ["agent", "OpenOrange"], + ["hosted", "OpenOrange (always on)"], + ], + ); + // What Buzz requires of a hosted type. + assert.deepEqual(Object.keys(hosted.remote).sort(), ["activate", "interrupt", "profile", "provision", "remove"]); + for (const step of Object.values(hosted.remote)) assert.equal(typeof step, "function"); + assert.equal(hosted.run, undefined); + assert.equal(hosted.models, undefined); + assert.equal(hosted.timeoutMs, undefined); + assert.deepEqual(hosted.defaults(), { config: {} }); + // The local type is as it was. + assert.equal(typeof type.run, "function"); + assert.equal(type.timeoutMs, 30 * 60_000); + assert.equal(type.remote, undefined); + // Registering starts no oo. + assert.equal(here.hostedStub(), undefined); +}); + +test("provision hands oo the community, name and picture, and gives Buzz the key with the picture it was made with", async (t) => { + const here = computer(t); + const { remote } = here.start().hosted; + const made = await remote.provision({ name: "Clem", picture: PICTURE, community: COMMUNITY, config: {}, signal: signal() }); + const plain = await remote.provision({ name: "Scout", community: COMMUNITY, config: {}, signal: signal() }); + const { calls, agents } = here.hostedStub(); + assert.deepEqual(calls, [ + { args: [...HOSTED, "provision"], input: { community: COMMUNITY, name: "Clem", picture: PICTURE } }, + { args: [...HOSTED, "provision"], input: { community: COMMUNITY, name: "Scout" } }, + ]); + assert.match(made.pubkey, /^[0-9a-f]{64}$/); + assert.deepEqual(made, { pubkey: agents[`${COMMUNITY} Clem`].pubkey, picture: PICTURE }); + assert.deepEqual(plain, { pubkey: agents[`${COMMUNITY} Scout`].pubkey }); +}); + +test("a repeated provision, as Buzz retries one, returns the same agent", async (t) => { + const here = computer(t); + const { remote } = here.start().hosted; + const input = { name: "Clem", picture: PICTURE, community: COMMUNITY }; + const first = await remote.provision({ ...input, signal: signal() }); + const again = await remote.provision({ ...input, signal: signal() }); + assert.deepEqual(again, first); + const { calls, agents } = here.hostedStub(); + assert.equal(calls.length, 2); + assert.deepEqual(calls[1], calls[0]); + assert.equal(Object.keys(agents).length, 1); +}); + +test("activate hands oo the owner's proof and waits for the sign-in in the browser, however long it takes", async (t) => { + // Longer than the 5 s Buzz gives a declared command. + const here = computer(t, { env: { HOSTED_STUB: JSON.stringify({ activate: { wait: 6000 } }) } }); + const { remote } = here.start().hosted; + const started = Date.now(); + const input = { pubkey: "a".repeat(64), name: "Clem", community: COMMUNITY }; + assert.equal(await remote.activate({ ...input, auth: AUTH, config: {}, signal: signal() }), undefined); + assert.ok(Date.now() - started >= 6000); + assert.deepEqual(here.hostedStub().calls, [{ args: [...HOSTED, "activate"], input: { ...input, auth: AUTH } }]); +}); + +test("a step that fails shows the owner oo's reason", async (t) => { + const reason = "You did not finish signing in to Buzz. Choose Finish setup to try again."; + const steps = { activate: { fail: reason }, remove: { exit: 3 }, profile: { answer: "Done." } }; + const { remote } = computer(t, { env: { HOSTED_STUB: JSON.stringify(steps) } }).start().hosted; + const agent = { pubkey: "a".repeat(64), community: COMMUNITY }; + // Its last line on stderr, after its progress. + await assert.rejects(remote.activate({ ...agent, name: "Clem", auth: AUTH, signal: signal() }), { message: reason }); + await assert.rejects(remote.remove({ ...agent, signal: signal() }), { message: "oo stopped without saying why." }); + await assert.rejects(remote.profile({ ...agent, name: "Clem", signal: signal() }), { + message: "oo's answer could not be read. Update oo with `oo update`, then try again.", + }); +}); + +test("when Buzz stops waiting, oo is ended; a step Buzz no longer waits for starts none", async (t) => { + const here = computer(t, { env: { HOSTED_STUB: JSON.stringify({ activate: { hang: true } }) } }); + const buzz = here.start(); + const controller = new AbortController(); + const input = { pubkey: "a".repeat(64), name: "Clem", community: COMMUNITY, auth: AUTH }; + const activating = buzz.hosted.remote.activate({ ...input, signal: controller.signal }); + await until(() => here.hostedStub()?.calls.length === 1); + assert.equal(buzz.running(), 1); + controller.abort(); + await assert.rejects(activating, { name: "AbortError" }); + await until(() => buzz.running() === 0); + + await assert.rejects(buzz.hosted.remote.provision({ name: "Clem", community: COMMUNITY, signal: controller.signal }), { name: "AbortError" }); + assert.equal(here.hostedStub().calls.length, 1); +}); + +test("profile, remove and interrupt hand oo what Buzz names, in oo's words", async (t) => { + const here = computer(t); + const { remote } = here.start().hosted; + const agent = { pubkey: "a".repeat(64), community: COMMUNITY }; + assert.equal(await remote.profile({ ...agent, name: "Clementine", picture: PICTURE, signal: signal() }), undefined); + assert.equal(await remote.remove({ ...agent, signal: signal() }), undefined); + assert.equal(await remote.interrupt({ ...agent, channelId: "channel-1", threadRootId: "root-1", signal: signal() }), true); + assert.deepEqual(here.hostedStub().calls, [ + { args: [...HOSTED, "profile"], input: { ...agent, name: "Clementine", picture: PICTURE } }, + { args: [...HOSTED, "remove"], input: agent }, + { args: [...HOSTED, "interrupt"], input: { ...agent, channel: "channel-1", root: "root-1" } }, + ]); + + const idle = computer(t, { env: { HOSTED_STUB: JSON.stringify({ interrupt: { stopped: false } }) } }).start().hosted; + assert.equal(await idle.remote.interrupt({ ...agent, channelId: "channel-1", threadRootId: "root-1", signal: signal() }), false); +}); + +test("without oo on the computer, an always-on agent's setup says to install it", async (t) => { + const here = computer(t, { installed: false }); + const { remote } = here.start().hosted; + await assert.rejects(remote.provision({ name: "Clem", community: COMMUNITY, signal: signal() }), { + message: + "The oo command was not found on this computer. Install it from your Sunport (Connect, then Command line), run `oo login`, and try again.", + }); + assert.equal(here.hostedStub(), undefined); +}); diff --git a/tests/test_package.py b/tests/test_package.py index 0ac576d..d613ec9 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -230,15 +230,20 @@ def test_grok_bot_plugin_stays_in_its_apps_and_adds_nothing(self): package.check(self.root) path.write_bytes(original) - def test_buzz_plugin_keeps_its_id_and_asks_only_to_start_oo_acp(self): + def test_buzz_plugin_keeps_its_id_and_asks_only_to_start_oo_acp_and_oo_buzz_hosted(self): path = self.root / package.BUZZ / "manifest.json" original = path.read_bytes() + self.assertEqual([process["args"] for process in json.loads(original)["host"]["processes"]], [["acp"], ["buzz", "hosted"]]) changes = { "a key Buzz refuses": lambda manifest: manifest.update(version="0.6.36"), "another id": lambda manifest: manifest.update(id="openorange.buzz"), "a command": lambda manifest: manifest["host"].update(commands=[{"id": "status", "program": "git", "args": ["status"]}]), "a network origin": lambda manifest: manifest["host"].update(networkOrigins=["https://example.com"]), "another program": lambda manifest: manifest["host"]["processes"][0].update(program="sh"), + "another program for the hosted steps": lambda manifest: manifest["host"]["processes"][1].update(program="sh"), + "all of oo buzz": lambda manifest: manifest["host"]["processes"][1].update(args=["buzz"]), + "a third process": lambda manifest: manifest["host"]["processes"].append({"id": "shell", "program": "oo", "args": ["shell"]}), + "no hosted process": lambda manifest: manifest["host"]["processes"].pop(), } for label, change in changes.items(): with self.subTest(change=label):