From 78889fccca4dacac387ef69c68b5c41c3ebc3f1d Mon Sep 17 00:00:00 2001 From: Yabuku-xD <78594762+Yabuku-xD@users.noreply.github.com> Date: Tue, 1 Dec 2026 03:32:37 -0800 Subject: [PATCH 1/7] tests: find_tool ranks skill_manage first again for a reusable skill, and the guest skill card test stages four kinds of work bacb5320b left two tests red on dev. Its new skill_manage description dropped the word reusable, so find_tool ranked skills_list first for "save this procedure as a reusable skill"; the description says reusable SKILL.md again (a skill is recurring work, which that change keeps). Its duplicate check turns away a create that covers an existing skill, and the guest skill card test staged four skills with one description, the same as an earlier test's: each now has its own kind of work. --- server/cloud-personal.e2e.test.ts | 9 ++++- .../full.tools-list.json | 2 +- .../agents-catalog-goldens/profiles.json | 40 +++++++++---------- server/drivers/agents-catalog.ts | 2 +- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/server/cloud-personal.e2e.test.ts b/server/cloud-personal.e2e.test.ts index 73081ca1f2..781e7d3415 100644 --- a/server/cloud-personal.e2e.test.ts +++ b/server/cloud-personal.e2e.test.ts @@ -678,7 +678,14 @@ it("a guest's skill card enables only the exact text the owner reviewed, holds a const owner = await adminPairing(); await settleAll(owner); const botId = before.roomBot.id; - const skillMd = (name: string, body: string) => `---\nname: ${name}\ndescription: Checks the site for broken links.\n---\n\n# ${name}\n\n${body}\n`; + // kinds of work none of this file's other skills covers: a create that covers a skill already there is turned away + const work: Record = { + "reviewed-links": "Reviews pull requests for missing tests.", + "denied-links": "Drafts the weekly status email for the team.", + "lost-links": "Files expense receipts in the company portal.", + "deleted-links": "Renames vacation photos by the date taken.", + }; + const skillMd = (name: string, body: string) => `---\nname: ${name}\ndescription: ${work[name]}\n---\n\n# ${name}\n\n${body}\n`; const cards = async () => ((await api("GET", `/api/threads/${before.theirs}/messages`, { token: owner })).body.messages as any[]) .map((message) => message.card).filter((card) => card?.skillRequest); const respond = (route: "bot" | "thread", body: Record) => route === "bot" diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.json index 338d8ca056..6ebfb58711 100644 --- a/server/drivers/agents-catalog-goldens/full.tools-list.json +++ b/server/drivers/agents-catalog-goldens/full.tools-list.json @@ -2611,7 +2611,7 @@ }, { "name": "skill_manage", - "description": "Submit a new or updated SKILL.md for one kind of work. Update a learned skill when the person corrected how that work is done, asked you to revise it, or it misled you; never one the person wrote or imported unless they asked for that named skill. Create one only for recurring work with rules you'd get wrong without it, never for an automation, a one-off or a preference; omit what any model knows. If the result is pending, a create stays inactive and an update leaves the current version unchanged. Read the result: it applies immediately at every access level, and the person sees it with an Undo where possible. If applied, continue the work without another confirmation. Only a pending result (a Cloud conversation its owner did not drive) means ending the turn to wait for the owner. Never claim success without an applied result; report failures honestly. This does not elevate another bot's execution permissions.", + "description": "Submit a new or updated reusable SKILL.md for one kind of work. Update a learned skill when the person corrected how that work is done, asked you to revise it, or it misled you; never one the person wrote or imported unless they asked for that named skill. Create one only for recurring work with rules you'd get wrong without it, never for an automation, a one-off or a preference; omit what any model knows. If the result is pending, a create stays inactive and an update leaves the current version unchanged. Read the result: it applies immediately at every access level, and the person sees it with an Undo where possible. If applied, continue the work without another confirmation. Only a pending result (a Cloud conversation its owner did not drive) means ending the turn to wait for the owner. Never claim success without an applied result; report failures honestly. This does not elevate another bot's execution permissions.", "inputSchema": { "type": "object", "additionalProperties": false, diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.json index 232389816e..8da9b6b072 100644 --- a/server/drivers/agents-catalog-goldens/profiles.json +++ b/server/drivers/agents-catalog-goldens/profiles.json @@ -125,8 +125,8 @@ ] }, "skills": { - "bytes": 79704, - "sha256": "ab31ffbd342b3eff3b99849f6722cdc5002514b372e398e499d8bffcd9d5e3da", + "bytes": 79713, + "sha256": "a3ea87f686b9fc624c9aa68eaca93d2fa3d239d377854a7e788870336e8e944a", "tools": [ "set_status", "send_message", @@ -189,8 +189,8 @@ ] }, "skills+voice": { - "bytes": 80482, - "sha256": "72656e98d9324abd4a0a6fe99a0b5fd2d1cb6648b8a8789e50e7ee175bcff5c5", + "bytes": 80491, + "sha256": "5845b1830e6d0546c3f2c9ecbf0329faadd9e82c36769afad6148aa61b374b9a", "tools": [ "set_status", "send_message", @@ -369,8 +369,8 @@ ] }, "skills+non-chief": { - "bytes": 71686, - "sha256": "e033162122142bb14c5991c22b21fb182a049e75efe36f4452890496631c3e55", + "bytes": 71695, + "sha256": "0a31ffd3ed3a5803db43c317b810595a014d9f4d993e119a8b168ac620b6cceb", "tools": [ "set_status", "send_message", @@ -428,8 +428,8 @@ ] }, "skills+voice+non-chief": { - "bytes": 72464, - "sha256": "630045d61d6bdc00fd94bec0327599b38772069a9c2d6b7f982ce176d4bdbaba", + "bytes": 72473, + "sha256": "feacf12ae6edd3eb48ca5b9bc74241682851c3708e8f9a42954575c99523ed4f", "tools": [ "set_status", "send_message", @@ -488,8 +488,8 @@ ] }, "skills+voice+cloud-home": { - "bytes": 79458, - "sha256": "87046e3f1680cb3688a81e68c736e25fe4cc822a7c5c43848d57f732613d509f", + "bytes": 79467, + "sha256": "f19672a959c94ce7073ae118ce9d62172c4af6b88593191de7996a4fccb83165", "tools": [ "set_status", "send_message", @@ -552,8 +552,8 @@ ] }, "skills+voice+non-chief+cloud-home": { - "bytes": 71440, - "sha256": "158fe4d01fbb73b6f4c4a468868e7fe7dd4cd30bb92c6500fe448b0c8a8b542f", + "bytes": 71449, + "sha256": "c3be064722efa48c326150acf7529cf16993760a56bc6c3726915758b63b2e3e", "tools": [ "set_status", "send_message", @@ -611,8 +611,8 @@ ] }, "skills+voice+x": { - "bytes": 87140, - "sha256": "a57e0b4afbfa031a592ced1ab097100ec2a12f6c59535a7b2f2127e0fd3e3303", + "bytes": 87149, + "sha256": "62498a24d47f510cca1314d99605d4be581dab3c2763825ef2ecd5d0d09d79fa", "tools": [ "set_status", "send_message", @@ -684,8 +684,8 @@ ] }, "skills+voice+x+team": { - "bytes": 87556, - "sha256": "efd173cb43a931be63700ee55cf3798c55578d6603495d5353fa0391140ddf21", + "bytes": 87565, + "sha256": "e253321813dbe8fa0ea457f40401f68e92853fa5dacc5fd3f90f3323d2542563", "tools": [ "set_status", "send_message", @@ -758,8 +758,8 @@ ] }, "skills+skill-reader": { - "bytes": 80120, - "sha256": "e562baae663c0b9d238fc65d9a557019eae0e3a10c7cd986d42bec9227b9fcc9", + "bytes": 80129, + "sha256": "db617a90d6dec8a458a5678034198026d7bf2e69afd665d3bf122b4d4322cf99", "tools": [ "set_status", "send_message", @@ -949,8 +949,8 @@ ] }, "skills+voice+dusk": { - "bytes": 81133, - "sha256": "aecee531cd5dd67546525416ac925ec36db52b978777bbbb997718b51da4af69", + "bytes": 81142, + "sha256": "e48dad639cff9c24f7b605f54f443aa54c09d1081519d403df93be26de903f87", "tools": [ "set_status", "send_message", diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.ts index 324a261bec..4f0077619e 100644 --- a/server/drivers/agents-catalog.ts +++ b/server/drivers/agents-catalog.ts @@ -808,7 +808,7 @@ const TOOL_DEFINITIONS = [ { name: "skill_manage", description: - "Submit a new or updated SKILL.md for one kind of work. Update a learned skill when the person corrected how that work is done, asked you to revise it, or it misled you; never one the person wrote or imported unless they asked for that named skill. Create one only for recurring work with rules you'd get wrong without it, never for an automation, a one-off or a preference; omit what any model knows. If the result is pending, a create stays inactive and an update leaves the current version unchanged." + APPLIES_OUTCOME, + "Submit a new or updated reusable SKILL.md for one kind of work. Update a learned skill when the person corrected how that work is done, asked you to revise it, or it misled you; never one the person wrote or imported unless they asked for that named skill. Create one only for recurring work with rules you'd get wrong without it, never for an automation, a one-off or a preference; omit what any model knows. If the result is pending, a create stays inactive and an update leaves the current version unchanged." + APPLIES_OUTCOME, inputSchema: { type: "object", additionalProperties: false, From 54f5c514dc9dc2315d41cb8c7d82f00b8472fd44 Mon Sep 17 00:00:00 2001 From: Yabuku-xD <78594762+Yabuku-xD@users.noreply.github.com> Date: Tue, 1 Dec 2026 12:37:50 -0800 Subject: [PATCH 2/7] ci: the tests that failed at random in Dec 1's CI runs get the flaky list's two retries Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs #477-#483 whose changes do not reach them, a different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing VPS with $settings' failed too (PR #477, run 46623618361) but is left out: its name is made per case, and the list matches names written in the file. --- scripts/testing/ci-retry-list.json | 105 +++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/scripts/testing/ci-retry-list.json b/scripts/testing/ci-retry-list.json index 070a6c47a0..3498b1c38a 100644 --- a/scripts/testing/ci-retry-list.json +++ b/scripts/testing/ci-retry-list.json @@ -70,6 +70,111 @@ "owner": "siddharth", "reason": "Failed once in the 0.2.33 release CI (run 45993068105, ubuntu shard 5 or parallel-threads, a different test each attempt); passes locally on a quiet machine.", "since": "2026-11-27" + }, + { + "file": "server/settings-sync.e2e.test.ts", + "test": "a setting changed in any one place reaches the others, and the last change wins", + "owner": "Yabuku-xD", + "reason": "Failed on Dec 1 in CI of PRs #479 (run 46726301408, all five), #481 (run 46636209589) and #483 (run 46637592516): a loopback request with no forwarding header was answered 403 'this request came through a proxy'. Passed in the other PR runs that day; passes locally (macOS, Node 26) alone, as four copies at once and in its full ubuntu shard 7/8 with 4 workers.", + "since": "2026-12-01" + }, + { + "file": "server/settings-sync.e2e.test.ts", + "test": "what belongs to one computer stays there", + "owner": "Yabuku-xD", + "reason": "Failed on Dec 1 in CI of PRs #479 (run 46726301408, all five), #481 (run 46636209589) and #483 (run 46637592516): a loopback request with no forwarding header was answered 403 'this request came through a proxy'. Passed in the other PR runs that day; passes locally (macOS, Node 26) alone, as four copies at once and in its full ubuntu shard 7/8 with 4 workers.", + "since": "2026-12-01" + }, + { + "file": "server/settings-sync.e2e.test.ts", + "test": "keys travel only over the person's own links, and a Team Cloud keeps no person's settings", + "owner": "Yabuku-xD", + "reason": "Failed on Dec 1 in CI of PRs #479 (run 46726301408, all five), #481 (run 46636209589) and #483 (run 46637592516): a loopback request with no forwarding header was answered 403 'this request came through a proxy'. Passed in the other PR runs that day; passes locally (macOS, Node 26) alone, as four copies at once and in its full ubuntu shard 7/8 with 4 workers.", + "since": "2026-12-01" + }, + { + "file": "server/settings-sync.e2e.test.ts", + "test": "the move to My Cloud and the way home keep settings level", + "owner": "Yabuku-xD", + "reason": "Failed on Dec 1 in CI of PRs #479 (run 46726301408, all five), #481 (run 46636209589) and #483 (run 46637592516): a loopback request with no forwarding header was answered 403 'this request came through a proxy'. Passed in the other PR runs that day; passes locally (macOS, Node 26) alone, as four copies at once and in its full ubuntu shard 7/8 with 4 workers.", + "since": "2026-12-01" + }, + { + "file": "server/settings-sync.e2e.test.ts", + "test": "a computer whose bots moved to My Cloud is left as it was, with nothing failing, until they come back", + "owner": "Yabuku-xD", + "reason": "Failed on Dec 1 in CI of PRs #479 (run 46726301408, all five), #481 (run 46636209589) and #483 (run 46637592516): a loopback request with no forwarding header was answered 403 'this request came through a proxy'. Passed in the other PR runs that day; passes locally (macOS, Node 26) alone, as four copies at once and in its full ubuntu shard 7/8 with 4 workers.", + "since": "2026-12-01" + }, + { + "file": "server/steer-e2e.test.ts", + "test": "mid-turn steering e2e > a steer the CLI runs as its next native turn keeps the turn, its busy state and its internal tool pass until that reply lands", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #477 (run 46623618361, ubuntu shard 8/8) and of the diag/connector-issues branch on Dec 1; passes locally on dev and on #477.", + "since": "2026-12-01" + }, + { + "file": "server/drivers/antigravity.test.ts", + "test": "starting Google sign-in again > hands back the same link while it is live, so a code from the first page still completes", + "owner": "Yabuku-xD", + "reason": "Failed in CI of main (run 46580994542), a release (run 46616055192) and PR #478 (run 46623629685) on Dec 1; failed 1 of 3 local runs on one commit.", + "since": "2026-12-01" + }, + { + "file": "server/connected-app-tools.e2e.test.ts", + "test": "a bot given Gmail by its app switch reaches gmail.search_emails by name on Claude and on an ACP engine alike", + "owner": "Yabuku-xD", + "reason": "Failed in CI of main (run 46615872847) and PR #478 (run 46623629685) on Dec 1; passes locally on dev.", + "since": "2026-12-01" + }, + { + "file": "server/direct-coordination.e2e.test.ts", + "test": "runs the owed direct follow-up while the same bot works in another thread", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #478 (run 46623629685) and of fix-app-trigger-restore-enabled (run 46370208019); passed 3 of 3 local runs.", + "since": "2026-12-01" + }, + { + "file": "server/index.test.ts", + "test": "harness HTTP API > reports a failed routine once, not twice", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PRs #480 (run 46636190164) and #481 (run 46636209589) on Dec 1, at about 10.7 s; passes locally on dev.", + "since": "2026-12-01" + }, + { + "file": "server/setup-connect-card.e2e.test.ts", + "test": "/setup connects an app through a Connect card, against the real server > names the switch, and mounts nothing to call, when the bot's connected apps are off", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #479 (run 46636167463) on Dec 1; passes locally on dev, twice.", + "since": "2026-12-01" + }, + { + "file": "server/host-lazy-claim.e2e.test.ts", + "test": "lazy host claim and pin on use (issue #1650) > a No is an answer, not a failure: the screen stays untouched and the bot is told to finish another way", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #482 (run 46636235332, windows shard 5/8, 'Fixture wait expired') on Dec 1; that PR changes only electron/main.mjs.", + "since": "2026-12-01" + }, + { + "file": "server/copilot-engine.e2e.test.ts", + "test": "creates and updates a routine through Copilot's launcher-owned tools", + "owner": "Yabuku-xD", + "reason": "Failed in CI of main (run 46615872847) on Dec 1.", + "since": "2026-12-01" + }, + { + "file": "server/usage-trace/recorder.test.ts", + "test": "trace recorder > records 2,000 tool calls in one turn without holding up the event loop", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #479 (run 46726301408, ubuntu shard 7/8) on Dec 1 at 53 ms against its 50 ms bound; that PR changes only src/lib/live-events.ts.", + "since": "2026-12-01" + }, + { + "file": "server/teammate-follow-ups.e2e.test.ts", + "test": "F4 keeps a second assignment Clive hands Mira in the same turn its own job, though the first is already running", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #479 (run 46726301408, ubuntu shard 7/8) on Dec 1 ('the first was running when the second was sent'); that PR changes only src/lib/live-events.ts.", + "since": "2026-12-01" } ] } From 83ab615c36ac0c5452b417071d977ad702fdf35b Mon Sep 17 00:00:00 2001 From: Yabuku-xD <78594762+Yabuku-xD@users.noreply.github.com> Date: Tue, 1 Dec 2026 13:50:37 -0800 Subject: [PATCH 3/7] link chaos: the run ends once its results are written, and the storm's 60 servers link from their own addresses Every link chaos run since the per-address limit on new links (adc99d770, Nov 14) was cancelled at CI's 60-minute limit, on main pushes, the weekly run and every PR that touches the link service: the scenarios finished in about five minutes and printed their table, but a socket or timer a scenario left open held the process. The run now exits once its results are written. The storm's 60 servers set up their links over one connection, so the node's front gave them one address, which the limit refused after 30 (Too many new links from here); each now uses its own connection, as 60 machines would. Locally, --quick passes all 12 scenarios and exits in 5.6 minutes. --- apps/link-service/chaos/run.mjs | 3 ++- apps/link-service/chaos/scenarios.mjs | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/link-service/chaos/run.mjs b/apps/link-service/chaos/run.mjs index 08e9a00082..f4e235fc99 100644 --- a/apps/link-service/chaos/run.mjs +++ b/apps/link-service/chaos/run.mjs @@ -336,5 +336,6 @@ if (!process.env.DUSK_CHAOS_DIR) { } else { process.env.DUSK_CHAOS_PARENT = String(process.pid); for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, () => process.exit(130)); - main().catch((error) => { console.error(error); process.exit(2); }); + // the results are written by then; a socket or timer some scenario left open would otherwise hold the run until CI's job limit + main().then(() => process.exit(process.exitCode ?? 0), (error) => { console.error(error); process.exit(2); }); } diff --git a/apps/link-service/chaos/scenarios.mjs b/apps/link-service/chaos/scenarios.mjs index bf64921b90..db2f680e87 100644 --- a/apps/link-service/chaos/scenarios.mjs +++ b/apps/link-service/chaos/scenarios.mjs @@ -3,6 +3,7 @@ import { createHash } from "node:crypto"; import { chmodSync } from "node:fs"; import { join } from "node:path"; +import { Agent, fetch as undiciFetch } from "undici"; import { createTunnelAgent } from "../agent.mjs"; import { createRelayClient, createTunnelProxy, newLinkKeys, seal, sha256hex, vpsTokenOf } from "../../../electron/vps-link-protocol.mjs"; @@ -27,17 +28,22 @@ async function failover(world, { kill = true } = {}) { return { pass: moved !== home && moved !== null, note: `moved ${home} -> ${moved} in ${Math.round((workedAt - started) / 1000)} s`, clearedAt: started }; } -/** `count` more servers and apps on the default node, in this process: the agent's and the app's relay code each */ +/** `count` more servers and apps on the default node, in this process: the agent's and the app's relay code each. Each + * sets up its link over its own connection, so the node's front gives it its own address, as `count` machines would have: + * on one connection they would be one address, over the node's limit on new links an address may make in a minute. */ async function crowd(world, count) { - const base = world.url("contabo"), relay = createRelayClient({ base }), out = []; + const base = world.url("contabo"), out = []; for (let i = 0; i < count; i += 1) { + const own = new Agent(); + const ownFetch = (url, init) => undiciFetch(url, { ...init, dispatcher: own }); const keys = newLinkKeys(); - const made = await relay.create({ verifier: keys.verifier, appPub: keys.pub }); + const made = await createRelayClient({ base, fetch: ownFetch }).create({ verifier: keys.verifier, appPub: keys.pub }); const vps = vpsTokenOf(keys.secret); - const post = (path, body) => fetch(`${base}/v1/sessions/${made.id}/${path}`, { method: "POST", headers: { authorization: `Bearer ${vps}`, "content-type": "application/json" }, body: JSON.stringify(body) }); + const post = (path, body) => ownFetch(`${base}/v1/sessions/${made.id}/${path}`, { method: "POST", headers: { authorization: `Bearer ${vps}`, "content-type": "application/json" }, body: JSON.stringify(body) }); await post("claim", {}); const tunnel = { key: randomBytes(32).toString("base64url"), vps: randomBytes(32).toString("base64url"), app: randomBytes(32).toString("base64url") }; const done = await post("result", { sealed: seal(Buffer.alloc(32), made.id, Buffer.from("{}")), vpsPub: keys.pub, tunnel: { vps: sha256hex(tunnel.vps), app: sha256hex(tunnel.app) } }); + await own.close(); if (!done.ok) throw new Error(`crowd link ${i} answered ${done.status}`); const agent = createTunnelAgent({ base, id: made.id, key: tunnel.key, token: tunnel.vps, server: { host: "127.0.0.1", port: world.bot.port }, log: () => {} }); const running = agent.run(); From c47197f8d57186c25b8e8b9682681bdd48248486 Mon Sep 17 00:00:00 2001 From: Yabuku-xD <78594762+Yabuku-xD@users.noreply.github.com> Date: Tue, 1 Dec 2026 13:50:37 -0800 Subject: [PATCH 4/7] ci: three more tests that failed at random in Dec 1's CI get the flaky list's retries chat-mcp-tools' shutdown verdict, memory-order and the encrypted workspace restore failed in PR #479's run 46740020170, whose change does not reach them, and pass locally. --- scripts/testing/ci-retry-list.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/testing/ci-retry-list.json b/scripts/testing/ci-retry-list.json index 3498b1c38a..90b819f616 100644 --- a/scripts/testing/ci-retry-list.json +++ b/scripts/testing/ci-retry-list.json @@ -175,6 +175,27 @@ "owner": "Yabuku-xD", "reason": "Failed in CI of PR #479 (run 46726301408, ubuntu shard 7/8) on Dec 1 ('the first was running when the second was sent'); that PR changes only src/lib/live-events.ts.", "since": "2026-12-01" + }, + { + "file": "server/drivers/chat-mcp-tools.test.ts", + "test": "Chat MCP shutdown verdict > an unconfirmed shutdown still fails close when a call was in flight", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #479 (run 46740020170, ubuntu shard 3/8) on Dec 1 ('Unexpected end of JSON input'); that PR changes only src/lib/live-events.ts. Passes locally.", + "since": "2026-12-01" + }, + { + "file": "server/memory-order.e2e.test.ts", + "test": "starts the person's own line ahead of a hand-off that was already waiting for memory, and the hand-off right after", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #479 (run 46740020170, ubuntu shard 5/8) on Dec 1; that PR changes only src/lib/live-events.ts. Passes locally.", + "since": "2026-12-01" + }, + { + "file": "server/workspace-backup-workflow.test.ts", + "test": "restores an encrypted workspace through the real server and continues its original chat", + "owner": "Yabuku-xD", + "reason": "Failed in CI of PR #479 (run 46740020170, windows shard 5/8) on Dec 1; that PR changes only src/lib/live-events.ts. Passes locally.", + "since": "2026-12-01" } ] } From 3dd88bf14c05d42cf7e69472def3caca1bdb977e Mon Sep 17 00:00:00 2001 From: Yabuku-xD <78594762+Yabuku-xD@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:08:10 -0800 Subject: [PATCH 5/7] link chaos: the crowd's own connections use node:https, since the chaos job installs no packages The job runs `node apps/link-service/chaos/run.mjs` straight after checkout, so the undici import failed with ERR_MODULE_NOT_FOUND before any scenario ran. --- apps/link-service/chaos/scenarios.mjs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/link-service/chaos/scenarios.mjs b/apps/link-service/chaos/scenarios.mjs index db2f680e87..4d70cf6fa9 100644 --- a/apps/link-service/chaos/scenarios.mjs +++ b/apps/link-service/chaos/scenarios.mjs @@ -2,8 +2,8 @@ // things route around it) and answers { clearedAt, pass, note, sees }. run.mjs measures the rest. import { createHash } from "node:crypto"; import { chmodSync } from "node:fs"; +import { Agent as HttpsAgent, request as httpsRequest } from "node:https"; import { join } from "node:path"; -import { Agent, fetch as undiciFetch } from "undici"; import { createTunnelAgent } from "../agent.mjs"; import { createRelayClient, createTunnelProxy, newLinkKeys, seal, sha256hex, vpsTokenOf } from "../../../electron/vps-link-protocol.mjs"; @@ -28,14 +28,35 @@ async function failover(world, { kill = true } = {}) { return { pass: moved !== home && moved !== null, note: `moved ${home} -> ${moved} in ${Math.round((workedAt - started) / 1000)} s`, clearedAt: started }; } +/** a fetch that keeps to one connection of its own. Node's built-in fetch shares one pool for the whole process, and the + * chaos workflow runs without installing packages, so this uses node:https. `close()` ends the connection. */ +function fetchOverOwnConnection() { + const agent = new HttpsAgent({ keepAlive: true, maxSockets: 1 }); + const ownFetch = (url, { method = "GET", headers = {}, body, signal } = {}) => new Promise((resolve, reject) => { + const request = httpsRequest(url, { method, headers, agent, signal }, (answer) => { + const chunks = []; + answer.on("data", (chunk) => chunks.push(chunk)); + answer.on("error", reject); + answer.on("end", () => { + const noBody = [204, 205, 304].includes(answer.statusCode); + const answerHeaders = Object.entries(answer.headers).flatMap(([name, value]) => (Array.isArray(value) ? value.map((one) => [name, one]) : [[name, value]])); + resolve(new Response(noBody ? null : Buffer.concat(chunks), { status: answer.statusCode, headers: answerHeaders })); + }); + }); + request.on("error", reject); + request.end(body); + }); + return { fetch: ownFetch, close: () => agent.destroy() }; +} + /** `count` more servers and apps on the default node, in this process: the agent's and the app's relay code each. Each * sets up its link over its own connection, so the node's front gives it its own address, as `count` machines would have: * on one connection they would be one address, over the node's limit on new links an address may make in a minute. */ async function crowd(world, count) { const base = world.url("contabo"), out = []; for (let i = 0; i < count; i += 1) { - const own = new Agent(); - const ownFetch = (url, init) => undiciFetch(url, { ...init, dispatcher: own }); + const own = fetchOverOwnConnection(); + const ownFetch = own.fetch; const keys = newLinkKeys(); const made = await createRelayClient({ base, fetch: ownFetch }).create({ verifier: keys.verifier, appPub: keys.pub }); const vps = vpsTokenOf(keys.secret); From d103f5ddf386746b2af59915762df1aab36775d9 Mon Sep 17 00:00:00 2001 From: Yabuku-xD <78594762+Yabuku-xD@users.noreply.github.com> Date: Tue, 1 Dec 2026 22:26:57 -0800 Subject: [PATCH 6/7] link chaos: the probe dials its live stream again when a new dial sends nothing for 8 s, as the app does src/lib/live-events.ts gives up on a dial that sends nothing in LIVE_EVENTS_OPEN_MS (8 s) and dials again. The probe dropped a quiet stream only after it had sent something, so one silent dial after node-5xx's 502s held it down until the relay closed it, about 90 s, and failed the scenario in CI on five of seven runs. --- apps/link-service/chaos/run.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/link-service/chaos/run.mjs b/apps/link-service/chaos/run.mjs index f4e235fc99..b9c6e09c15 100644 --- a/apps/link-service/chaos/run.mjs +++ b/apps/link-service/chaos/run.mjs @@ -136,7 +136,7 @@ async function bringUp() { */ function createProbe(world) { const pings = [], gaps = []; - let live = null, lastEventAt = 0, stopped = false, timer = null, inFlight = 0, liveReq = null; + let live = null, lastEventAt = 0, openedAt = 0, stopped = false, timer = null, inFlight = 0, liveReq = null; const port = () => Number(new URL(world.app.origin()).port); const host = () => world.app.host(); function call(path, { method = "GET", body = null, timeoutMs = 8000, port: at = port(), host: name = host() } = {}) { @@ -180,6 +180,7 @@ function createProbe(world) { res.on("close", () => closed("closed")); }); liveReq = req; + openedAt = Date.now(); let done = false; function closed() { if (done) return; @@ -198,7 +199,10 @@ function createProbe(world) { const up = now - lastEventAt < 5000; if (!up && downSince === null) downSince = Math.max(lastEventAt, now - 5000); if (up && downSince !== null) { gaps.push({ from: downSince, to: now }); downSince = null; } - if (liveReq && now - lastEventAt > 20_000 && live) { liveReq.destroy(); } + // as the app does (src/lib/live-events.ts): a dial that sends nothing in LIVE_EVENTS_OPEN_MS (8 s) is dialled again, + // and a stream that went quiet after it sent something is dialled again after 20 s + const quietFor = now - Math.max(lastEventAt, openedAt); + if (liveReq && quietFor > (live ? 20_000 : 8_000)) { liveReq.destroy(); } }, 250); return { start() { timer = setInterval(tick, 500); openLive(); }, From a85311691954fe45c1effc0b01b7c64d6510795f Mon Sep 17 00:00:00 2001 From: Yabuku-xD <78594762+Yabuku-xD@users.noreply.github.com> Date: Tue, 1 Dec 2026 22:33:44 -0800 Subject: [PATCH 7/7] routines: a schedule that kept checking an app moves onto that app's event, paused once the event is live, with one Undo trigger create when=app_event takes replaces: the trigger_id of the bot's schedule that kept checking the same app. The server checks the schedule first and refuses one that must keep its clock (a room goal, a one-time or limit-reset schedule, the daily brief, checks or a page/feed/price/script check, a chain, an address). It pauses the schedule only once the connected-apps service confirms the event; until then the schedule keeps running and the bot is told to pause it later. The receipt's Undo deletes the automation and turns the schedule back on, unless the schedule changed after the pause. The usage report's note now offers this first for a frequent schedule that keeps checking an app. --- apps/site/pages/docs/routines.md | 2 + docs/composio.md | 7 ++ server/app-trigger-host.ts | 9 ++- server/app-trigger-requests.ts | 43 +++++++++- server/app-triggers.test.ts | 78 ++++++++++++++++++- server/drivers/agents-call-triggers.test.ts | 13 ++++ server/drivers/agents-call-triggers.ts | 10 ++- .../bridged.profiles.json | 76 +++++++++--------- .../bridged.tools-list.json | 6 +- .../full.tools-list.json | 6 +- .../agents-catalog-goldens/profiles.json | 76 +++++++++--------- server/drivers/agents-catalog.ts | 4 +- server/routine-event-switch.ts | 23 ++++++ server/routine-usage-report.ts | 2 +- server/trigger-tools.test.ts | 4 + server/trigger-tools.ts | 6 +- shared/app-triggers.ts | 5 +- 17 files changed, 273 insertions(+), 97 deletions(-) create mode 100644 server/routine-event-switch.ts diff --git a/apps/site/pages/docs/routines.md b/apps/site/pages/docs/routines.md index 58deed976f..a85fbe7a2d 100644 --- a/apps/site/pages/docs/routines.md +++ b/apps/site/pages/docs/routines.md @@ -27,6 +27,8 @@ a routine can start from an event instead of a clock: this needs the app to be [connected](/docs/files-and-apps#connected-apps). gmail is checked every 15 minutes; slack, github and most others arrive at once. +already have a routine that checks an app every few minutes? ask the bot to switch it to the app's event: "switch my applicant check to new emails." it then runs only when something happens. the old schedule is paused, not deleted, and **Undo** turns it back on. + ## good routines - **small and specific beats big and vague.** "flag invoices over €500" works better than "handle my finances". diff --git a/docs/composio.md b/docs/composio.md index 39243a836b..76b6a462aa 100644 --- a/docs/composio.md +++ b/docs/composio.md @@ -107,6 +107,13 @@ message in a channel, a HubSpot deal changing stage. It uses Composio triggers t paused) and fixes any difference by itself: a lost copy is made again, an unwanted one is removed, on/off is matched. An expired connection shows as **Needs you** with **Reconnect**. +A schedule that kept checking an app can move onto that app's event: `trigger` create with `replaces`, the +schedule's id (`server/routine-event-switch.ts`). The schedule is paused, never deleted, and only once the service +confirms the event; until then it keeps running and the bot is told to pause it later. The receipt's Undo deletes the +automation and turns the schedule back on, unless the schedule changed after the pause. A schedule that must keep its +clock is refused: a room goal, a one-time or limit-reset schedule, the daily brief, one with checks or a page, feed, +price or script check, one in a chain, and one with an address. + | | Desktop | Paid Cloud | | --- | --- | --- | | Events kept per day (UTC) | 2,000 | 10,000 | diff --git a/server/app-trigger-host.ts b/server/app-trigger-host.ts index 2a895e9ec4..9233453d17 100644 --- a/server/app-trigger-host.ts +++ b/server/app-trigger-host.ts @@ -88,7 +88,14 @@ export function createAppTriggerHost(deps: AppTriggerHostDeps) { }, emit: deps.emit, }); - const requests = new AppTriggerRequestService({ store: deps.store, triggers: manager, botName: (botId) => deps.store.bot(botId)?.name ?? "the bot" }); + const requests = new AppTriggerRequestService({ + store: deps.store, triggers: manager, botName: (botId) => deps.store.bot(botId)?.name ?? "the bot", + schedules: { + get: (id) => deps.routines().listRoutines().find((routine) => routine.id === id) ?? null, + hasAddress: (id) => deps.webhooks.list().some((webhook) => webhook.routineId === id), + setEnabled: (id, enabled) => deps.routines().update(id, { enabled }), + }, + }); const unavailableText = (_reason: "self-hosted" | "unavailable") => POLL_INSTEAD; diff --git a/server/app-trigger-requests.ts b/server/app-trigger-requests.ts index bb94c60a0d..b909ddc922 100644 --- a/server/app-trigger-requests.ts +++ b/server/app-trigger-requests.ts @@ -8,6 +8,8 @@ import { AppTriggerError, type AppTriggerManager } from "./app-triggers.ts"; import { newId } from "./contracts.ts"; import { UNDO_STALE } from "./direct-apply.ts"; import { redactSecretsInText } from "./redact.ts"; +import { whyScheduleStays, type ReplacedSchedules } from "./routine-event-switch.ts"; +import type { Routine } from "./routines.ts"; import type { JsonValue } from "./schema.ts"; export interface AppTriggerRequestCard { @@ -53,7 +55,7 @@ const changesSchema = definitionSchema.pick({ name: true, instructions: true, fi const idSchema = z.string().trim().min(1).max(200); const targetSchema = z.object({ botId: z.string(), name: z.string() }).optional(); const operationSchema = z.discriminatedUnion("action", [ - z.object({ action: z.literal("create"), trigger: definitionSchema, forBot: targetSchema }), + z.object({ action: z.literal("create"), trigger: definitionSchema, replaces: idSchema.optional(), forBot: targetSchema }), z.object({ action: z.literal("update"), triggerId: idSchema, changes: changesSchema, forBot: targetSchema }), ...(["pause", "resume", "run_now", "delete"] as const).map((action) => z.object({ action: z.literal(action), triggerId: idSchema, forBot: targetSchema })), ]); @@ -87,7 +89,8 @@ export function appTriggerSentence(trigger: Described & Pick string; + /** The routine engine's schedules, for a create that replaces one. */ + schedules?: ReplacedSchedules; now?: () => number; } +/** What became of the schedule a create replaces, for the bot to pass on. */ +function replacedDetail(schedule: Routine, paused: boolean, live: boolean): string { + const name = `“${redactSecretsInText(schedule.name)}”`; + if (paused) return `The schedule ${name} is paused: from now on this event starts the work. Its Undo turns the schedule back on. Tell the person it now runs only when the event happens, not on a clock.`; + if (!schedule.enabled) return `The schedule ${name} was already paused, so nothing else changed.`; + return live ? "" : `The schedule ${name} stays on until the event is live (the connected-apps service did not confirm it yet). Call trigger_info for this automation later; once it is active, pause ${name} with trigger action=pause.`; +} + export class AppTriggerRequestService { private readonly options: AppTriggerRequestServiceOptions; @@ -115,6 +128,17 @@ export class AppTriggerRequestService { return trigger; } + /** The schedule a create takes over, checked before anything is made. */ + private replaceable(routineId: string, owner: string): Routine { + const schedules = this.options.schedules; + if (!schedules) throw new AppTriggerError("A schedule can't be switched to an app event here."); + const routine = schedules.get(routineId); + if (!routine || routine.botId !== owner) throw new AppTriggerError("replaces must be the trigger_id of one of this bot's schedules, from trigger_info.", 404); + const stays = whyScheduleStays(routine, schedules.hasAddress(routineId)); + if (stays) throw new AppTriggerError(`${stays} Leave out replaces, or keep the schedule as it is.`, 409); + return routine; + } + async submit(args: { botId: string; threadId: string; operation: unknown; from?: { botId: string; name: string; color: string }; canCommit?: () => boolean; payload?: JsonValue }): Promise { const parsed = operationSchema.safeParse(args.operation); if (!parsed.success) throw new AppTriggerError(parsed.error.issues[0]?.message ?? "Invalid automation request"); @@ -122,13 +146,17 @@ export class AppTriggerRequestService { const owner = operation.forBot?.botId ?? args.botId; const triggers = this.options.triggers; const before = operation.action === "create" ? undefined : this.owned(operation.triggerId, owner); + const schedule = operation.action === "create" && operation.replaces ? this.replaceable(operation.replaces, owner) : undefined; if (args.canCommit && !args.canCommit()) throw new AppTriggerError("The requesting turn ended before this change could be saved", 401); let after: AppTrigger | null = null; let runId: string | undefined; + let paused: Routine | null = null; switch (operation.action) { case "create": { const { instructions, ...definition } = operation.trigger; after = await triggers.create({ ...definition, prompt: instructions, botId: owner, sourceThreadId: args.threadId }); + // Only a live event may take the work over: until the service confirms it, the schedule keeps running. + if (schedule?.enabled && after.remote.state === "active") paused = this.options.schedules!.setEnabled(schedule.id, false); break; } case "update": { @@ -150,6 +178,7 @@ export class AppTriggerRequestService { } const subject = after ?? before!; const summary = appTriggerSentence(subject, this.options.botName(owner)); + const detail = schedule ? replacedDetail(schedule, paused !== null, after?.remote.state === "active") : ""; const requestId = newId(); const payload: AppTriggerRequestCardData = { version: 1, @@ -165,6 +194,7 @@ export class AppTriggerRequestService { ...(before && (operation.action === "update" || operation.action === "delete") ? { before: { name: before.name, prompt: before.prompt, runOn: before.runOn, enabled: before.enabled, config: before.config, ...(before.filter ? { filter: before.filter } : {}) } } : {}), + ...(paused ? { replaced: { routineId: paused.id, name: redactSecretsInText(paused.name), pausedUpdatedAt: paused.updatedAt } } : {}), }, }; const message = this.options.store.appendMessage(args.threadId, { @@ -183,7 +213,7 @@ export class AppTriggerRequestService { }, ...(args.from ? { from: args.from } : {}), }); - return { requestId, messageId: message.id, state: "applied", action: operation.action, resultId: subject.id, summary, ...(runId ? { runId } : {}) }; + return { requestId, messageId: message.id, state: "applied", action: operation.action, resultId: subject.id, summary, ...(runId ? { runId } : {}), ...(detail ? { detail } : {}) }; } async undo(args: { botId: string; threadId: string; requestId: string }): Promise { @@ -205,9 +235,14 @@ export class AppTriggerRequestService { switch (operation.action) { case "run_now": return cannot("A test run can't be undone."); - case "create": + case "create": { if (!mine || !await triggers.remove(triggerId)) return stale; + // the schedule it replaced comes back, unless the person changed it after it was paused + const replaced = payload.undo?.replaced; + const schedule = replaced ? this.options.schedules?.get(replaced.routineId) : null; + if (replaced && schedule && !schedule.enabled && schedule.updatedAt === replaced.pausedUpdatedAt) this.options.schedules!.setEnabled(replaced.routineId, true); break; + } case "update": case "pause": case "resume": { diff --git a/server/app-triggers.test.ts b/server/app-triggers.test.ts index 38da7aa8db..7efb493af2 100644 --- a/server/app-triggers.test.ts +++ b/server/app-triggers.test.ts @@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { appEventCatalog } from "./app-event-catalog.ts"; import { eventCount } from "./app-events.ts"; -import { brokerClient } from "./app-trigger-broker.ts"; +import { BrokerError, brokerClient, type AppTriggerBroker } from "./app-trigger-broker.ts"; import { AppTriggerManager, type AppTriggerManagerOptions } from "./app-triggers.ts"; import { RoutineManager } from "./routines.ts"; import { startBrokerFake, type BrokerFake } from "./testing/broker-fake.ts"; @@ -273,7 +273,8 @@ describe("appEventCatalog", () => { }); describe("createAppTriggerHost", () => { - it("refuses a guest-driven Cloud turn and an app outside the bot's grants; otherwise applies with one receipt and Undo", async () => { + /** The host over the fake service, a chat store that keeps its cards, and the routines of each test. */ + async function appHost(overrides: { broker?: AppTriggerBroker; addressFor?: string } = {}) { const { createAppTriggerHost } = await import("./app-trigger-host.ts"); const messages = new Map>(); const bots: Record = { @@ -281,6 +282,7 @@ describe("createAppTriggerHost", () => { narrow: { id: "narrow", name: "Narrow", color: "#000", connectorTools: { slack: { tools: "*" } } }, }; const host = createAppTriggerHost({ + ...(overrides.broker ? { broker: overrides.broker } : {}), file: join(dir, "host-app-triggers.json"), store: { bot: (id) => bots[id], @@ -300,7 +302,7 @@ describe("createAppTriggerHost", () => { access: () => ({ url: broker.url, token: owner.token }), connectedApps: async () => connected, routines: () => routines, - webhooks: { list: () => [] } as never, + webhooks: { list: () => (overrides.addressFor ? [{ routineId: overrides.addressFor }] : []) } as never, webhookBase: () => "http://127.0.0.1:8800", botState: () => "ready", timeZone: () => "UTC", @@ -310,8 +312,13 @@ describe("createAppTriggerHost", () => { }); const answers: Array<{ status: number; body: any }> = []; const json = ((_res: unknown, status: number, body: unknown) => { answers.push({ status, body }); }) as never; - const operation = { action: "create", trigger: { name: "Acme", instructions: "Draft a reply.", app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE", filter: { from: "acme.com" } } }; const context = (from: any, guestDriven = false) => ({ from, threadId: "thread-1", ownsThread: () => true, guestDriven, outsideDriven: () => false, canCommit: () => true }); + return { host, messages, bots, answers, json, context }; + } + + it("refuses a guest-driven Cloud turn and an app outside the bot's grants; otherwise applies with one receipt and Undo", async () => { + const { host, messages, bots, answers, json, context } = await appHost(); + const operation = { action: "create", trigger: { name: "Acme", instructions: "Draft a reply.", app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE", filter: { from: "acme.com" } } }; await host.submit({} as never, json, { ...context(bots.scout, true), operation }); expect(answers.at(-1)).toMatchObject({ status: 403, body: { error: expect.stringContaining("Only the Cloud's owner") } }); await host.submit({} as never, json, { ...context(bots.narrow), operation }); @@ -335,6 +342,69 @@ describe("createAppTriggerHost", () => { expect(host.manager.list()).toEqual([]); expect(broker.harness.composio.instances.size).toBe(0); }); + + const switchTo = (replaces: string) => ({ action: "create", replaces, trigger: { name: "New applicants", instructions: "Add each applicant to the sheet.", app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE", filter: { subject: "application" } } }); + const poller = (input: Partial[0]> = {}) => + routines.create({ name: "Check for applicants", prompt: "Look for new applications in Gmail and add them to the sheet.", botId: "scout", schedule: { type: "interval", everyMinutes: 5 }, ...input }); + + it("moves a schedule that kept checking Gmail onto the event: it is paused once the event is live, and Undo turns it back on", async () => { + const { host, messages, answers, json, context, bots } = await appHost(); + const schedule = poller(); + await host.submit({} as never, json, { ...context(bots.scout), operation: switchTo(schedule.id) }); + expect(answers.at(-1)).toMatchObject({ status: 201, body: { state: "applied", detail: expect.stringContaining("“Check for applicants” is paused") } }); + expect(routines.listRoutines().find((one) => one.id === schedule.id)?.enabled).toBe(false); + const card = messages.get("thread-1")!.at(-1)!.card; + expect(card.appTriggerRequest.operation).toMatchObject({ action: "create", replaces: schedule.id }); + expect(card.appTriggerRequest.undo.replaced).toMatchObject({ routineId: schedule.id, name: "Check for applicants" }); + expect(await host.undo({ botId: "scout", threadId: "thread-1", requestId: card.requestId })).toMatchObject({ state: "undone", action: "create" }); + expect(host.manager.list()).toEqual([]); + expect(routines.listRoutines().find((one) => one.id === schedule.id)?.enabled).toBe(true); + }); + + it("Undo of a switch leaves a schedule the person changed after it was paused as they left it", async () => { + const { host, messages, json, context, bots } = await appHost(); + const schedule = poller(); + await host.submit({} as never, json, { ...context(bots.scout), operation: switchTo(schedule.id) }); + routines.update(schedule.id, { name: "Old applicant check" }); + const card = messages.get("thread-1")!.at(-1)!.card; + expect(await host.undo({ botId: "scout", threadId: "thread-1", requestId: card.requestId })).toMatchObject({ state: "undone" }); + expect(routines.listRoutines().find((one) => one.id === schedule.id)).toMatchObject({ name: "Old applicant check", enabled: false }); + }); + + it("keeps the schedule on while the service has not confirmed the event, and tells the bot to pause it later", async () => { + const down = brokerClient(() => ({ url: broker.url, token: owner.token })); + const { host, answers, json, context, bots } = await appHost({ broker: { ...down, create: async () => { throw new BrokerError("The connected-apps service could not be reached", 503); } } }); + const schedule = poller(); + await host.submit({} as never, json, { ...context(bots.scout), operation: switchTo(schedule.id) }); + expect(answers.at(-1)).toMatchObject({ status: 201, body: { detail: expect.stringContaining("stays on until the event is live") } }); + expect(host.manager.list()[0]?.remote.state).toBe("pending"); + expect(routines.listRoutines().find((one) => one.id === schedule.id)?.enabled).toBe(true); + }); + + it("refuses to move a schedule that must keep its clock, or one that is not this bot's, and makes no automation", async () => { + const once = poller({ name: "Send the deck", schedule: { type: "once", at: Date.now() + 86_400_000 } }); + // a routine that runs after another gets a plain-code check of that routine's runs + const checked = poller({ name: "After the report", chain: { after: [once.id] } } as never); + const chained = poller({ name: "Reads the report", chain: { readFrom: [once.id] } } as never); + const others = poller({ name: "Not Scout's", botId: "other" }); + const plain = poller(); + const cases: Array<[string, string | undefined, RegExp]> = [ + [once.id, undefined, /runs at one moment/], + [checked.id, undefined, /already checks in plain code/], + [chained.id, undefined, /chain of routines/], + [plain.id, plain.id, /has an address other apps call/], + [others.id, undefined, /one of this bot's schedules/], + ["missing", undefined, /one of this bot's schedules/], + ]; + for (const [id, addressFor, why] of cases) { + const { host, answers, json, context, bots } = await appHost(addressFor ? { addressFor } : {}); + await host.submit({} as never, json, { ...context(bots.scout), operation: switchTo(id) }); + expect(answers.at(-1)).toMatchObject({ body: { error: expect.stringMatching(why) } }); + expect(answers.at(-1)!.status).toBeGreaterThanOrEqual(400); + expect(host.manager.list()).toEqual([]); + } + expect(routines.listRoutines().every((one) => one.enabled)).toBe(true); + }); }); describe("instructions in the person's words", () => { diff --git a/server/drivers/agents-call-triggers.test.ts b/server/drivers/agents-call-triggers.test.ts index b0efc27df0..c7128fb37a 100644 --- a/server/drivers/agents-call-triggers.test.ts +++ b/server/drivers/agents-call-triggers.test.ts @@ -29,6 +29,19 @@ describe("app events in the trigger tools", () => { } }); }); + it("sends the schedule an app_event replaces, and passes on what became of it", async () => { + const { calls, context: ctx } = context({ response: { ok: true, status: 201, body: { resultId: "t-1", summary: "When an email arrives in Gmail, Scout follows: Add it.", detail: "The schedule “Check for applicants” is paused." } } }); + const result = await callTool("trigger", { action: "create", when: "app_event", name: "Applicants", instructions: "Add it.", app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE", replaces: " r-1 " }, ctx); + expect(calls[0]?.body).toMatchObject({ action: "create", kind: "app", replaces: "r-1" }); + expect(result.text).toContain("The schedule “Check for applicants” is paused."); + expect((await callTool("trigger", { action: "create", when: "schedule", name: "A", instructions: "B", schedule: { type: "daily", time: "09:00" }, replaces: "r-1" }, ctx)).text) + .toBe("replaces applies only to when=app_event."); + expect((await callTool("trigger", { action: "update", trigger_id: "t-1", name: "C", replaces: "r-1" }, ctx)).text).toBe("replaces applies only to action=create."); + expect((await callTool("trigger", { action: "create", when: "app_event", name: "A", instructions: "B", app: "gmail", event: "X", replaces: 7 }, ctx)).text) + .toContain("replaces must be the trigger_id of your schedule"); + expect(calls).toHaveLength(1); + }); + it("refuses fields of the other kinds and a missing app or event, before anything is sent", async () => { const { calls, context: ctx } = context(); expect((await callTool("create_trigger", { when: "app_event", name: "A", instructions: "B", app: "gmail", event: "X", schedule: { type: "daily", time: "09:00" } }, ctx)).text) diff --git a/server/drivers/agents-call-triggers.ts b/server/drivers/agents-call-triggers.ts index b91ab75bf7..606bb80503 100644 --- a/server/drivers/agents-call-triggers.ts +++ b/server/drivers/agents-call-triggers.ts @@ -19,7 +19,7 @@ const EVERY_WAIT_ROUTE = "/api/internal/waits/all"; const EVENTS_ROUTE = "/api/internal/trigger-events"; const USAGE_ROUTE = "/api/internal/trigger-usage"; const MAIL_ROUTE = "/api/internal/bot-mail"; -const APP_ONLY = ["app", "event", "account"] as const; +const APP_ONLY = ["app", "event", "account", "replaces"] as const; const REQUEST_ROUTE = "/api/internal/trigger-requests"; const SCHEDULE_ONLY = ["schedule", "timeout_minutes", "timeoutMinutes", "clear_timeout", "catch_up_minutes", "catchUpMinutes", "clear_catch_up", "continuity", "overlap", "run_on_startup", "runOnStartup", "check", "clear_check", "read_from", "after", "hand_to", "clear_chain"] as const; @@ -433,7 +433,7 @@ async function request(body: Json, context: ToolCallContext, done: string): Prom /** Everything a trigger call may carry beyond the fields it sets. */ const CALL_KEYS = new Set(["action", "trigger_id", "for_bot_id", "test", "payload"]); -const CREATE_ONLY = ["when", "app", "event", "account", "engine", "repeat"] as const; +const CREATE_ONLY = ["when", "app", "event", "account", "replaces", "engine", "repeat"] as const; export async function callTriggerTool(name: string, args: Json, context: ToolCallContext): Promise { const forBotId = typeof args.for_bot_id === "string" && args.for_bot_id.trim() ? args.for_bot_id.trim() : undefined; @@ -575,12 +575,16 @@ async function createTrigger(args: Json, forBotId: string | undefined, context: const app = typeof args.app === "string" ? args.app.trim().toLowerCase() : ""; const event = typeof args.event === "string" ? args.event.trim() : ""; if (!app || !event) return { text: "An app_event trigger needs app and event from trigger_info action=events. Call trigger_info action=events first.", isError: true }; + if (args.replaces !== undefined && args.replaces !== null && (typeof args.replaces !== "string" || !args.replaces.trim())) { + return { text: "replaces must be the trigger_id of your schedule that kept checking this app, from trigger_info.", isError: true }; + } + const replaces = typeof args.replaces === "string" ? { replaces: args.replaces.trim() } : {}; const trigger = { name: fields.name, instructions: fields.instructions, app, event, ...(typeof args.account === "string" && args.account.trim() ? { account: args.account.trim() } : {}), ...(fields.filter ? { filter: fields.filter } : {}), ...(fields.config ? { config: fields.config } : {}), ...(fields.runOn ? { runOn: fields.runOn } : {}), }; - return request({ action: "create", kind: "app", trigger, ...(forBotId ? { forBotId } : {}) }, context, `Created the app-event trigger “${String(fields.name)}”`); + return request({ action: "create", kind: "app", trigger, ...replaces, ...(forBotId ? { forBotId } : {}) }, context, `Created the app-event trigger “${String(fields.name)}”`); } if (when === "limit_reset") { const misplaced = ["schedule", "webhook_event_types", "run_on_startup", "runOnStartup"].find((key) => args[key] !== undefined && args[key] !== null); diff --git a/server/drivers/agents-catalog-goldens/bridged.profiles.json b/server/drivers/agents-catalog-goldens/bridged.profiles.json index 3d99545233..1217960cfd 100644 --- a/server/drivers/agents-catalog-goldens/bridged.profiles.json +++ b/server/drivers/agents-catalog-goldens/bridged.profiles.json @@ -1,7 +1,7 @@ { "default": { - "bytes": 36772, - "sha256": "47f595ed004b3bd86c0cdb9a23587405f017035116ac3d9e936ee3ea91a096b9", + "bytes": 37029, + "sha256": "0155318ab7b50467d05a3978fdec97d4daf25a522fc7028cc476c4be2440dbec", "tools": [ "set_status", "send_message", @@ -28,8 +28,8 @@ ] }, "voice": { - "bytes": 37550, - "sha256": "d5bce82ebb72f4dcba279ec3ce0747adedb801c4dec71f3fdb61655277977c6e", + "bytes": 37807, + "sha256": "2d695f3da31fa170c45b50ededb3a6a4ce0063de37204beb47374297cd3c80b6", "tools": [ "set_status", "send_message", @@ -57,8 +57,8 @@ ] }, "skills": { - "bytes": 36799, - "sha256": "16494576733732c510df3cd33888f9d62bba0ff14e5e228e9d5513f50493a009", + "bytes": 37056, + "sha256": "da75680686dca552f918221df03eea9179036e4b382eff262d89e18280e54156", "tools": [ "set_status", "send_message", @@ -85,8 +85,8 @@ ] }, "skills+voice": { - "bytes": 37577, - "sha256": "31eadec0373e19b3eda51c7d899e09943e9f110cec1a3224cab94abb894b9ba8", + "bytes": 37834, + "sha256": "a29db830c507b67b1aea7a3efb79acc555cf777a821b3af7d06ca6d99fdba359", "tools": [ "set_status", "send_message", @@ -114,8 +114,8 @@ ] }, "non-chief": { - "bytes": 36686, - "sha256": "d58f50347757776a4d6c8a13bec75bb8d3cb8c10b6976d9a5a3a04810196c720", + "bytes": 36943, + "sha256": "b2dc8a21ef07f69abb02efbbcf7e7a6da969de04025cf0c52f5d8d4c8e2c84a0", "tools": [ "set_status", "send_message", @@ -142,8 +142,8 @@ ] }, "voice+non-chief": { - "bytes": 37464, - "sha256": "3f8aecd4b48970219bac00fd7e38ebc0fee8b06908b6bfebac14e39272be8999", + "bytes": 37721, + "sha256": "0c20401edb0a6401e4f58ca46ac2ea52cbac6f3032ab27f4b67b008fc28a123e", "tools": [ "set_status", "send_message", @@ -171,8 +171,8 @@ ] }, "skills+non-chief": { - "bytes": 36713, - "sha256": "fe42cfb6f68e5ee9de00bf81c2a0edce0f25fa750af99784b6c9766f2268eadc", + "bytes": 36970, + "sha256": "66895b3fc0be13d6eb3c9740a1cc745f63da6a9f76d15ece5e05e341fe11c573", "tools": [ "set_status", "send_message", @@ -199,8 +199,8 @@ ] }, "skills+voice+non-chief": { - "bytes": 37491, - "sha256": "0c1b0da8e979bb93bf690b8cb6cfcad739ffc71d36a26f54a0c038e9cdb4d539", + "bytes": 37748, + "sha256": "424e155a457397e143b81e515b4b4871645df081048f37e55c96a1112b0b2074", "tools": [ "set_status", "send_message", @@ -228,8 +228,8 @@ ] }, "skills+voice+cloud-home": { - "bytes": 37594, - "sha256": "fa5ddeacf01a5f57cc0d39c08d000236ecd1afd06296359a6ea008790e124184", + "bytes": 37851, + "sha256": "35a93f408c17a071879e6ccc376336a281313babd28f94173590aaa3683cf327", "tools": [ "set_status", "send_message", @@ -257,8 +257,8 @@ ] }, "skills+voice+non-chief+cloud-home": { - "bytes": 37508, - "sha256": "01dff344fe1b345b72d2780b1914fa4a6b898831b69cf7f7f4a981f14fab4dad", + "bytes": 37765, + "sha256": "7cc2568615a15ed068b3ce327622b1632cb78a2bce2451d15a2fa0b2ba7d5d3b", "tools": [ "set_status", "send_message", @@ -286,8 +286,8 @@ ] }, "skills+voice+x": { - "bytes": 37705, - "sha256": "75292ecf0091cf1a6db0349cfa2b099a606054e66f82de34173db1681854de84", + "bytes": 37962, + "sha256": "920ee5753e40956569662aedbc369b42f1c4ec30f6cb470c3d99cdbd22c19604", "tools": [ "set_status", "send_message", @@ -315,8 +315,8 @@ ] }, "skills+voice+x+team": { - "bytes": 38121, - "sha256": "a986eef9214c00a63d7bf408fdd34ee92895bcc5324fcc8a5ae46ab56439e2e3", + "bytes": 38378, + "sha256": "a7d63539f69c2e53525f8c147f69ae778715bd661189f9e2ce3b1f294f9cf2c7", "tools": [ "set_status", "send_message", @@ -345,8 +345,8 @@ ] }, "skills+skill-reader": { - "bytes": 37215, - "sha256": "b0e59a30f77ec97ee122468173d0dbfb56489a79eb0b7a5f13348316869c98e9", + "bytes": 37472, + "sha256": "73b9c06173c6e7e8790f08ddd236e1745af5d4ce1c8bc83e94337d45378c751b", "tools": [ "set_status", "send_message", @@ -374,8 +374,8 @@ ] }, "default+legacy-switches": { - "bytes": 36772, - "sha256": "47f595ed004b3bd86c0cdb9a23587405f017035116ac3d9e936ee3ea91a096b9", + "bytes": 37029, + "sha256": "0155318ab7b50467d05a3978fdec97d4daf25a522fc7028cc476c4be2440dbec", "tools": [ "set_status", "send_message", @@ -402,8 +402,8 @@ ] }, "default+dusk": { - "bytes": 36824, - "sha256": "b33041e5e809983a7063240bc2b03cee19d8fec48d72eb826c50ff190769c086", + "bytes": 37081, + "sha256": "8071fa275f1b4082a57f1e1b1a43a85c667b656a5fa4c78e71f3e59206aec9b1", "tools": [ "set_status", "send_message", @@ -430,8 +430,8 @@ ] }, "skills+voice+dusk": { - "bytes": 37629, - "sha256": "a63b2dbf42c4ba68ae2121635e00089280b5acbdaebf16b4f53c900ea1281033", + "bytes": 37886, + "sha256": "1f4df788ddd8868f2d8d117bd953d1069a94d3e9488661b0cf857ac1d2576882", "tools": [ "set_status", "send_message", @@ -459,8 +459,8 @@ ] }, "default+no-computer-pick": { - "bytes": 35565, - "sha256": "b45a588419c201005f1c10ce3c0c8fc7b1e05ca25dd9ca94574452a49df0a7e8", + "bytes": 35822, + "sha256": "879c59d015b1068b8bd7e851676ee02b3d967b5b554e698aa99fcf3c017614b8", "tools": [ "set_status", "send_message", @@ -486,8 +486,8 @@ ] }, "default+room": { - "bytes": 35466, - "sha256": "dcfa138b86691bae56b16bdf9db86b2e31091e0d3f796452c130f130d8a78616", + "bytes": 35723, + "sha256": "ceb9e8e8c50146be20ecc107dcd4e96801b1e5f21685f878772a4f05f4db4986", "tools": [ "set_status", "send_message", @@ -513,8 +513,8 @@ ] }, "non-chief+room": { - "bytes": 35380, - "sha256": "7130ad492d2ee3e97d7550925fe8b21054ae1afdd67e8b3ad662cf6f7ce44bfa", + "bytes": 35637, + "sha256": "3a52cb840fb5e33bf000b035f79527fb6fd95c4931f0afd9407db96c33b4cf0e", "tools": [ "set_status", "send_message", diff --git a/server/drivers/agents-catalog-goldens/bridged.tools-list.json b/server/drivers/agents-catalog-goldens/bridged.tools-list.json index 4933e66cf1..0d31f26db4 100644 --- a/server/drivers/agents-catalog-goldens/bridged.tools-list.json +++ b/server/drivers/agents-catalog-goldens/bridged.tools-list.json @@ -681,7 +681,7 @@ }, { "name": "trigger", - "description": "Set up or change work that happens on its own (was create_trigger / manage_trigger): when , a bot does . create in this turn whenever the person describes recurring or event-based work (\"every morning send me…\", \"whenever I get an email from…\", \"when another app calls…\"); never ask for confirmation first. when=schedule runs on a time rule, cron included (for relative dates, the person's message carries the current time and timezone in its \"Current time when this message was sent\" line); when=app_event runs when something happens in a connected app (trigger_info action=events first; prefer it to a schedule that keeps checking); when=webhook gives an address another app sends to: paste it into that app's setup yourself, never into chat (the person copies it from the automation's card). when=limit_reset runs when an AI's usage limit resets (\"run this when my limit resets\", or to finish work your own limit stopped). A schedule watching for something new (page, feed, price, chat, build) gets check, so it costs nothing until something changed; never make the AI poll; a follow-up days later is a wait_until kind=time per item or a daily check. To come back to this chat later (\"check back in 20 min\"), use wait_until kind=time with follow_up. To the person these are automations: write name and instructions as they would say them. Something to do once, now, is not a trigger. update (only the fields to change), pause, resume and run_now (a webhook or app event runs its real steps on payload, a sample event; test one so before calling it live) act on one of the bot's routines, app events or webhooks, by its trigger_id from trigger_info. Before reporting a task finished, inspect related automations with trigger_info; pause a temporary monitor whose goal is met, then read its state back. Keep standing automations; delete_trigger deletes one only at the person's explicit request. Each applies at once; the person sees it with Edit, Pause and Undo. for_bot_id: a trigger of ANOTHER bot in your section, which keeps that bot's engine and permissions. email: your mail address; with trigger_id and email_from, their mail (to +email_alias) runs it.", + "description": "Set up or change work that happens on its own (was create_trigger / manage_trigger): when , a bot does . create in this turn whenever the person describes recurring or event-based work (\"every morning send me…\", \"whenever I get an email from…\", \"when another app calls…\"); never ask for confirmation first. when=schedule runs on a time rule, cron included (for relative dates, the person's message carries the current time and timezone in its \"Current time when this message was sent\" line); when=app_event runs when something happens in a connected app (trigger_info action=events first; prefer it to a schedule that keeps checking, and move such a schedule onto the event with replaces); when=webhook gives an address another app sends to: paste it into that app's setup yourself, never into chat (the person copies it from the automation's card). when=limit_reset runs when an AI's usage limit resets (\"run this when my limit resets\", or to finish work your own limit stopped). A schedule watching for something new (page, feed, price, chat, build) gets check, so it costs nothing until something changed; never make the AI poll; a follow-up days later is a wait_until kind=time per item or a daily check. To come back to this chat later (\"check back in 20 min\"), use wait_until kind=time with follow_up. To the person these are automations: write name and instructions as they would say them. Something to do once, now, is not a trigger. update (only the fields to change), pause, resume and run_now (a webhook or app event runs its real steps on payload, a sample event; test one so before calling it live) act on one of the bot's routines, app events or webhooks, by its trigger_id from trigger_info. Before reporting a task finished, inspect related automations with trigger_info; pause a temporary monitor whose goal is met, then read its state back. Keep standing automations; delete_trigger deletes one only at the person's explicit request. Each applies at once; the person sees it with Edit, Pause and Undo. for_bot_id: a trigger of ANOTHER bot in your section, which keeps that bot's engine and permissions. email: your mail address; with trigger_id and email_from, their mail (to +email_alias) runs it.", "inputSchema": { "type": "object", "additionalProperties": false, @@ -994,6 +994,10 @@ "type": "string", "description": "app_event: account id or alias, only when the app has several." }, + "replaces": { + "type": "string", + "description": "app_event create: trigger_id of your schedule that kept checking this app for the same work; it is paused once the event is live, and Undo turns it back on." + }, "engine": { "type": "string", "description": "limit_reset: the engine id whose limit to wait for, e.g. claude or codex. Omit for your own engine." diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.json index 6ebfb58711..1ef5ec3dd9 100644 --- a/server/drivers/agents-catalog-goldens/full.tools-list.json +++ b/server/drivers/agents-catalog-goldens/full.tools-list.json @@ -1896,7 +1896,7 @@ }, { "name": "trigger", - "description": "Set up or change work that happens on its own (was create_trigger / manage_trigger): when , a bot does . create in this turn whenever the person describes recurring or event-based work (\"every morning send me…\", \"whenever I get an email from…\", \"when another app calls…\"); never ask for confirmation first. when=schedule runs on a time rule, cron included (for relative dates, the person's message carries the current time and timezone in its \"Current time when this message was sent\" line); when=app_event runs when something happens in a connected app (trigger_info action=events first; prefer it to a schedule that keeps checking); when=webhook gives an address another app sends to: paste it into that app's setup yourself, never into chat (the person copies it from the automation's card). when=limit_reset runs when an AI's usage limit resets (\"run this when my limit resets\", or to finish work your own limit stopped). A schedule watching for something new (page, feed, price, chat, build) gets check, so it costs nothing until something changed; never make the AI poll; a follow-up days later is a wait_until kind=time per item or a daily check. To come back to this chat later (\"check back in 20 min\"), use wait_until kind=time with follow_up. To the person these are automations: write name and instructions as they would say them. Something to do once, now, is not a trigger. update (only the fields to change), pause, resume and run_now (a webhook or app event runs its real steps on payload, a sample event; test one so before calling it live) act on one of the bot's routines, app events or webhooks, by its trigger_id from trigger_info. Before reporting a task finished, inspect related automations with trigger_info; pause a temporary monitor whose goal is met, then read its state back. Keep standing automations; delete_trigger deletes one only at the person's explicit request. Each applies at once; the person sees it with Edit, Pause and Undo. for_bot_id: a trigger of ANOTHER bot in your section, which keeps that bot's engine and permissions. email: your mail address; with trigger_id and email_from, their mail (to +email_alias) runs it.", + "description": "Set up or change work that happens on its own (was create_trigger / manage_trigger): when , a bot does . create in this turn whenever the person describes recurring or event-based work (\"every morning send me…\", \"whenever I get an email from…\", \"when another app calls…\"); never ask for confirmation first. when=schedule runs on a time rule, cron included (for relative dates, the person's message carries the current time and timezone in its \"Current time when this message was sent\" line); when=app_event runs when something happens in a connected app (trigger_info action=events first; prefer it to a schedule that keeps checking, and move such a schedule onto the event with replaces); when=webhook gives an address another app sends to: paste it into that app's setup yourself, never into chat (the person copies it from the automation's card). when=limit_reset runs when an AI's usage limit resets (\"run this when my limit resets\", or to finish work your own limit stopped). A schedule watching for something new (page, feed, price, chat, build) gets check, so it costs nothing until something changed; never make the AI poll; a follow-up days later is a wait_until kind=time per item or a daily check. To come back to this chat later (\"check back in 20 min\"), use wait_until kind=time with follow_up. To the person these are automations: write name and instructions as they would say them. Something to do once, now, is not a trigger. update (only the fields to change), pause, resume and run_now (a webhook or app event runs its real steps on payload, a sample event; test one so before calling it live) act on one of the bot's routines, app events or webhooks, by its trigger_id from trigger_info. Before reporting a task finished, inspect related automations with trigger_info; pause a temporary monitor whose goal is met, then read its state back. Keep standing automations; delete_trigger deletes one only at the person's explicit request. Each applies at once; the person sees it with Edit, Pause and Undo. for_bot_id: a trigger of ANOTHER bot in your section, which keeps that bot's engine and permissions. email: your mail address; with trigger_id and email_from, their mail (to +email_alias) runs it.", "inputSchema": { "type": "object", "additionalProperties": false, @@ -2209,6 +2209,10 @@ "type": "string", "description": "app_event: account id or alias, only when the app has several." }, + "replaces": { + "type": "string", + "description": "app_event create: trigger_id of your schedule that kept checking this app for the same work; it is paused once the event is live, and Undo turns it back on." + }, "engine": { "type": "string", "description": "limit_reset: the engine id whose limit to wait for, e.g. claude or codex. Omit for your own engine." diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.json index 8da9b6b072..1d4020d241 100644 --- a/server/drivers/agents-catalog-goldens/profiles.json +++ b/server/drivers/agents-catalog-goldens/profiles.json @@ -1,7 +1,7 @@ { "default": { - "bytes": 76601, - "sha256": "025396506a221b315cc6b557a6e73ed428d99f58b256089dc6a25f7a36ec978a", + "bytes": 76858, + "sha256": "ad4979fcf8672994e999d8dee5c744ce5919d7dd83eaabde361e4e7b37926eff", "tools": [ "set_status", "send_message", @@ -62,8 +62,8 @@ ] }, "voice": { - "bytes": 77379, - "sha256": "b8d626e630375829dbcf7b8449c61c7af2cc1fd169192ad25f344b8c512085ac", + "bytes": 77636, + "sha256": "34c806711e20d04cdc06c11e37743cf151b2e0969e76c3b52be359fb7acc2396", "tools": [ "set_status", "send_message", @@ -125,8 +125,8 @@ ] }, "skills": { - "bytes": 79713, - "sha256": "a3ea87f686b9fc624c9aa68eaca93d2fa3d239d377854a7e788870336e8e944a", + "bytes": 79970, + "sha256": "e27a72b898161d00891dda476825eb482995e20ffc2e80277f5961e27f81ae87", "tools": [ "set_status", "send_message", @@ -189,8 +189,8 @@ ] }, "skills+voice": { - "bytes": 80491, - "sha256": "5845b1830e6d0546c3f2c9ecbf0329faadd9e82c36769afad6148aa61b374b9a", + "bytes": 80748, + "sha256": "64c3302b3b6638235306c9e0e34bd4ce40bf00d8da186ac670f709d490f5f3b7", "tools": [ "set_status", "send_message", @@ -254,8 +254,8 @@ ] }, "non-chief": { - "bytes": 68583, - "sha256": "c25dc524db8c3dcf73e14773ed95224c943eb54ad0a3b7de6bbd2ceb019cbbdc", + "bytes": 68840, + "sha256": "80affe41d9308cd7cfae9d631e886148822f5b310aab64fbc32f160fca4114da", "tools": [ "set_status", "send_message", @@ -311,8 +311,8 @@ ] }, "voice+non-chief": { - "bytes": 69361, - "sha256": "06bb7cec220f5888bff1f5a251d5afcfe2001c8c03af04e8fd9042eefe548680", + "bytes": 69618, + "sha256": "5a2ef992591e1bcd6c86c0e2c3e1342c888fd19dd851b23a57b7906032a8bf1d", "tools": [ "set_status", "send_message", @@ -369,8 +369,8 @@ ] }, "skills+non-chief": { - "bytes": 71695, - "sha256": "0a31ffd3ed3a5803db43c317b810595a014d9f4d993e119a8b168ac620b6cceb", + "bytes": 71952, + "sha256": "ac5633620501f95a876287daff3503e082e6178f9c3f765f72370b26f86767cb", "tools": [ "set_status", "send_message", @@ -428,8 +428,8 @@ ] }, "skills+voice+non-chief": { - "bytes": 72473, - "sha256": "feacf12ae6edd3eb48ca5b9bc74241682851c3708e8f9a42954575c99523ed4f", + "bytes": 72730, + "sha256": "5b84b730a95292606dec8da7be058f2b4f6b5addeb9c3b9df2f50cbe30e27d27", "tools": [ "set_status", "send_message", @@ -488,8 +488,8 @@ ] }, "skills+voice+cloud-home": { - "bytes": 79467, - "sha256": "f19672a959c94ce7073ae118ce9d62172c4af6b88593191de7996a4fccb83165", + "bytes": 79724, + "sha256": "4be3aa61b672ec5cbc1bb65991f1adaf20cca8abc647511e0f8242154c9849d6", "tools": [ "set_status", "send_message", @@ -552,8 +552,8 @@ ] }, "skills+voice+non-chief+cloud-home": { - "bytes": 71449, - "sha256": "c3be064722efa48c326150acf7529cf16993760a56bc6c3726915758b63b2e3e", + "bytes": 71706, + "sha256": "efebc24f60889cb1572056296b46f66093870e31a0be9384e5eb510d2855003f", "tools": [ "set_status", "send_message", @@ -611,8 +611,8 @@ ] }, "skills+voice+x": { - "bytes": 87149, - "sha256": "62498a24d47f510cca1314d99605d4be581dab3c2763825ef2ecd5d0d09d79fa", + "bytes": 87406, + "sha256": "fa5682c3f84cf68cf7c17c401b72ac2296da4164f9f2cc89d65732a8cd142474", "tools": [ "set_status", "send_message", @@ -684,8 +684,8 @@ ] }, "skills+voice+x+team": { - "bytes": 87565, - "sha256": "e253321813dbe8fa0ea457f40401f68e92853fa5dacc5fd3f90f3323d2542563", + "bytes": 87822, + "sha256": "53066620f012889915c692969a0b1a5b2a66bdf9c29c5d335dfdd87de6b2af66", "tools": [ "set_status", "send_message", @@ -758,8 +758,8 @@ ] }, "skills+skill-reader": { - "bytes": 80129, - "sha256": "db617a90d6dec8a458a5678034198026d7bf2e69afd665d3bf122b4d4322cf99", + "bytes": 80386, + "sha256": "9cb44d23e2dbb14c8cee1b1bc99ad360d9a346249c4d7c7e2e710f3ca4b43da2", "tools": [ "set_status", "send_message", @@ -823,8 +823,8 @@ ] }, "default+legacy-switches": { - "bytes": 76601, - "sha256": "025396506a221b315cc6b557a6e73ed428d99f58b256089dc6a25f7a36ec978a", + "bytes": 76858, + "sha256": "ad4979fcf8672994e999d8dee5c744ce5919d7dd83eaabde361e4e7b37926eff", "tools": [ "set_status", "send_message", @@ -885,8 +885,8 @@ ] }, "default+dusk": { - "bytes": 77252, - "sha256": "20a61e8a093d8b320922c8feb3f3cb9ae2e824cce79a81abc86f59ebae2c11cd", + "bytes": 77509, + "sha256": "01bf7152ef077118fc64bc83355ab2b762b5da0852bdc00e4e2aee5a4d6c8a73", "tools": [ "set_status", "send_message", @@ -949,8 +949,8 @@ ] }, "skills+voice+dusk": { - "bytes": 81142, - "sha256": "e48dad639cff9c24f7b605f54f443aa54c09d1081519d403df93be26de903f87", + "bytes": 81399, + "sha256": "95509d3863d7b1e9fba7f94b20399d7d3ea751e4c9ac776dd15446381e408d28", "tools": [ "set_status", "send_message", @@ -1016,8 +1016,8 @@ ] }, "default+no-computer-pick": { - "bytes": 75394, - "sha256": "dbe5ccdfaacaa1bc571164432435f887ed89af59cd9328c9bb999f7e05cf698d", + "bytes": 75651, + "sha256": "411f3f6046317992c747f73b9c0506d6c4b9fc3b5742bc5b52c968765e1eb201", "tools": [ "set_status", "send_message", @@ -1077,8 +1077,8 @@ ] }, "default+room": { - "bytes": 65704, - "sha256": "7a53ac67bb6ced84467c8e78f492bc070e4abc897ef54e87fba9da66d8f83625", + "bytes": 65961, + "sha256": "92a70e754f7912cae86798d92fe86b409e6d68df59f10fa50abdbd150e9303b3", "tools": [ "set_status", "send_message", @@ -1130,8 +1130,8 @@ ] }, "non-chief+room": { - "bytes": 57686, - "sha256": "9540cd48c3db3df7b1ff869461c5401a0e28d57427747e98b05728339547976c", + "bytes": 57943, + "sha256": "bd5c5b42558b2d8ea2dfa3906c378ec75ab9c12dce699b13967cee5acc5930a2", "tools": [ "set_status", "send_message", diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.ts index 4f0077619e..554b00d97a 100644 --- a/server/drivers/agents-catalog.ts +++ b/server/drivers/agents-catalog.ts @@ -677,7 +677,7 @@ const TOOL_DEFINITIONS = [ { name: "trigger", description: - "Set up or change work that happens on its own (was create_trigger / manage_trigger): when , a bot does . create in this turn whenever the person describes recurring or event-based work (\"every morning send me…\", \"whenever I get an email from…\", \"when another app calls…\"); never ask for confirmation first. when=schedule runs on a time rule, cron included (for relative dates, the person's message carries the current time and timezone in its \"Current time when this message was sent\" line); when=app_event runs when something happens in a connected app (trigger_info action=events first; prefer it to a schedule that keeps checking); when=webhook gives an address another app sends to: paste it into that app's setup yourself, never into chat (the person copies it from the automation's card). when=limit_reset runs when an AI's usage limit resets (\"run this when my limit resets\", or to finish work your own limit stopped). A schedule watching for something new (page, feed, price, chat, build) gets check, so it costs nothing until something changed; never make the AI poll; a follow-up days later is a wait_until kind=time per item or a daily check. To come back to this chat later (\"check back in 20 min\"), use wait_until kind=time with follow_up. To the person these are automations: write name and instructions as they would say them. Something to do once, now, is not a trigger. update (only the fields to change), pause, resume and run_now (a webhook or app event runs its real steps on payload, a sample event; test one so before calling it live) act on one of the bot's routines, app events or webhooks, by its trigger_id from trigger_info. Before reporting a task finished, inspect related automations with trigger_info; pause a temporary monitor whose goal is met, then read its state back. Keep standing automations; delete_trigger deletes one only at the person's explicit request. Each applies at once; the person sees it with Edit, Pause and Undo. for_bot_id: a trigger of ANOTHER bot in your section, which keeps that bot's engine and permissions. email: your mail address; with trigger_id and email_from, their mail (to +email_alias) runs it.", + "Set up or change work that happens on its own (was create_trigger / manage_trigger): when , a bot does . create in this turn whenever the person describes recurring or event-based work (\"every morning send me…\", \"whenever I get an email from…\", \"when another app calls…\"); never ask for confirmation first. when=schedule runs on a time rule, cron included (for relative dates, the person's message carries the current time and timezone in its \"Current time when this message was sent\" line); when=app_event runs when something happens in a connected app (trigger_info action=events first; prefer it to a schedule that keeps checking, and move such a schedule onto the event with replaces); when=webhook gives an address another app sends to: paste it into that app's setup yourself, never into chat (the person copies it from the automation's card). when=limit_reset runs when an AI's usage limit resets (\"run this when my limit resets\", or to finish work your own limit stopped). A schedule watching for something new (page, feed, price, chat, build) gets check, so it costs nothing until something changed; never make the AI poll; a follow-up days later is a wait_until kind=time per item or a daily check. To come back to this chat later (\"check back in 20 min\"), use wait_until kind=time with follow_up. To the person these are automations: write name and instructions as they would say them. Something to do once, now, is not a trigger. update (only the fields to change), pause, resume and run_now (a webhook or app event runs its real steps on payload, a sample event; test one so before calling it live) act on one of the bot's routines, app events or webhooks, by its trigger_id from trigger_info. Before reporting a task finished, inspect related automations with trigger_info; pause a temporary monitor whose goal is met, then read its state back. Keep standing automations; delete_trigger deletes one only at the person's explicit request. Each applies at once; the person sees it with Edit, Pause and Undo. for_bot_id: a trigger of ANOTHER bot in your section, which keeps that bot's engine and permissions. email: your mail address; with trigger_id and email_from, their mail (to +email_alias) runs it.", inputSchema: { type: "object", additionalProperties: false, @@ -694,7 +694,7 @@ const TOOL_DEFINITIONS = [ ...TRIGGER_FIELDS_SCHEMA, app: { type: "string", description: "app_event: app slug from trigger_info action=events." }, event: { type: "string", description: "app_event: event slug from trigger_info action=events." }, - account: { type: "string", description: "app_event: account id or alias, only when the app has several." }, + account: { type: "string", description: "app_event: account id or alias, only when the app has several." }, replaces: { type: "string", description: "app_event create: trigger_id of your schedule that kept checking this app for the same work; it is paused once the event is live, and Undo turns it back on." }, engine: { type: "string", description: "limit_reset: the engine id whose limit to wait for, e.g. claude or codex. Omit for your own engine." }, repeat: { type: "string", enum: ["once", "every_reset"], description: "limit_reset: once (default) or every_reset." }, for_bot_id: { type: "string", description: "Only for ANOTHER bot's trigger: that bot's id, from list_bots." }, diff --git a/server/routine-event-switch.ts b/server/routine-event-switch.ts new file mode 100644 index 0000000000..ac195ed659 --- /dev/null +++ b/server/routine-event-switch.ts @@ -0,0 +1,23 @@ +// A schedule that kept checking a connected app can hand its work to that app's event: the new automation starts only +// when the event happens, and the schedule is paused, never deleted, so Undo turns it back on as it was. +import type { Routine } from "./routines.ts"; + +/** What the switch needs from the routine engine. */ +export interface ReplacedSchedules { + get(id: string): Routine | null; + /** Whether a webhook address runs this schedule: other apps call it, and an app event would not answer them. */ + hasAddress(id: string): boolean; + setEnabled(id: string, enabled: boolean): Routine | null; +} + +/** Why this schedule keeps its clock, in a sentence for the bot; null when an app event may take its work. */ +export function whyScheduleStays(routine: Routine, hasAddress: boolean): string | null { + const name = `“${routine.name}”`; + if (routine.target !== "bot") return `${name} runs a room's goal, so it keeps its schedule.`; + if (routine.schedule.type === "once" || routine.schedule.type === "limit_reset") return `${name} runs at one moment, not to watch for something new, so it keeps its schedule.`; + if (routine.deliver === "brief") return `${name} writes the daily brief, so it keeps its schedule.`; + if (routine.checks?.length || routine.probe) return `${name} already checks in plain code and starts the AI only when something changed, so it keeps its schedule.`; + if (routine.chain) return `${name} is part of a chain of routines, so it keeps its schedule.`; + if (hasAddress) return `${name} has an address other apps call, so it keeps its schedule.`; + return null; +} diff --git a/server/routine-usage-report.ts b/server/routine-usage-report.ts index 6d33d4b740..dd4eabd5ac 100644 --- a/server/routine-usage-report.ts +++ b/server/routine-usage-report.ts @@ -49,7 +49,7 @@ export function routineUsageReport(input: UsageReportInput) { basis: priced ? "usd" : "tokens", automations: ranked, note: ranked.length - ? "Most used first. A frequent schedule that keeps checking for something is usually the cause: offer to run it less often, or give the routine an address (trigger_info include_address) so the app or a phone shortcut wakes it only when something happens. A person's own chats are not listed here." + ? "Most used first. A frequent schedule that keeps checking for something is usually the cause: offer to move it onto the event of the connected app it checks (trigger_info action=events, then trigger action=create when=app_event with replaces: its trigger_id), so it runs only when something happens; with no such event, run it less often or give it an address (trigger_info include_address) the app or a phone shortcut calls. A person's own chats are not listed here." : "No automation of these bots used anything in the last 30 days; the usage is from chats.", }; } diff --git a/server/trigger-tools.test.ts b/server/trigger-tools.test.ts index af1b6df80e..0678f7ea35 100644 --- a/server/trigger-tools.test.ts +++ b/server/trigger-tools.test.ts @@ -58,6 +58,10 @@ describe("parseTriggerRequest", () => { .toMatchObject({ ok: true, kind: "webhook", operation: { action: "update", webhookId: "w1", changes: { name: "y" } } }); expect(parseTriggerRequest({ ...source, action: "create", kind: "app", trigger: { name: "x" } }, isSchedule)) .toMatchObject({ ok: true, kind: "app", operation: { action: "create", trigger: { name: "x" } } }); + expect(parseTriggerRequest({ ...source, action: "create", kind: "app", trigger: { name: "x" }, replaces: "r1" }, isSchedule)) + .toMatchObject({ ok: true, kind: "app", operation: { action: "create", trigger: { name: "x" }, replaces: "r1" } }); + // only an app event takes over a schedule + expect(parseTriggerRequest({ ...source, action: "create", kind: "webhook", webhook: { name: "x" }, replaces: "r1" }, isSchedule)).toMatchObject({ ok: false }); expect(parseTriggerRequest({ ...source, action: "update", triggerId: "a1", changes: { filter: { from: "acme" } } }, isSchedule)) .toMatchObject({ ok: true, kind: "app", operation: { action: "update", triggerId: "a1", changes: { filter: { from: "acme" } } } }); }); diff --git a/server/trigger-tools.ts b/server/trigger-tools.ts index bfd5a9fd10..f2b56e25bc 100644 --- a/server/trigger-tools.ts +++ b/server/trigger-tools.ts @@ -185,7 +185,7 @@ const source = { fromBotId: z.string().min(1).max(128), fromThreadId: z.string() const triggerRequestSchema = z.union([ z.object({ ...source, action: z.literal("create"), kind: z.literal("schedule"), routine: z.unknown() }).strict(), z.object({ ...source, action: z.literal("create"), kind: z.literal("webhook"), webhook: z.unknown() }).strict(), - z.object({ ...source, action: z.literal("create"), kind: z.literal("app"), trigger: z.unknown() }).strict(), + z.object({ ...source, action: z.literal("create"), kind: z.literal("app"), trigger: z.unknown(), replaces: z.string().min(1).max(200).optional() }).strict(), z.object({ ...source, action: z.literal("update"), triggerId: z.string().min(1).max(200), changes: z.record(z.string(), z.unknown()) }).strict(), z.object({ ...source, action: z.enum(["pause", "resume", "delete"]), triggerId: z.string().min(1).max(200) }).strict(), z.object({ ...source, action: z.literal("run_now"), triggerId: z.string().min(1).max(200), test: z.literal(true).optional(), payload: z.unknown().optional() }).strict(), @@ -204,7 +204,7 @@ export type ParsedTriggerRequest = | { ok: false; error: string } | { ok: true; kind: "schedule"; forBotId: unknown; proposal: { action: string; routine?: unknown; routineId?: string; changes?: unknown; test?: boolean } } | { ok: true; kind: "webhook"; forBotId: unknown; operation: { action: string; webhook?: unknown; webhookId?: string; changes?: unknown }; payload?: JsonValue } - | { ok: true; kind: "app"; forBotId: unknown; operation: { action: string; trigger?: unknown; triggerId?: string; changes?: unknown }; payload?: JsonValue }; + | { ok: true; kind: "app"; forBotId: unknown; operation: { action: string; trigger?: unknown; replaces?: string; triggerId?: string; changes?: unknown }; payload?: JsonValue }; /** A create names its kind; a change finds it from the trigger id (routine, webhook and app-event ids never collide). */ const WEEKDAY = "monday|tuesday|wednesday|thursday|friday|saturday|sunday"; @@ -231,7 +231,7 @@ export function parseTriggerRequest(body: unknown, kindOf: (id: string) => "sche if (request.action === "create") Object.assign(request, request.kind === "schedule" ? { routine: withTimelessName(request.routine) } : request.kind === "app" ? { trigger: withTimelessName(request.trigger) } : { webhook: withTimelessName(request.webhook) }); if (request.action === "update") request.changes = withTimelessName(request.changes); if (request.action === "create") { - if (request.kind === "app") return { ok: true, kind: "app", forBotId: request.forBotId, operation: { action: "create", trigger: request.trigger } }; + if (request.kind === "app") return { ok: true, kind: "app", forBotId: request.forBotId, operation: { action: "create", trigger: request.trigger, ...(request.replaces ? { replaces: request.replaces } : {}) } }; return request.kind === "schedule" ? { ok: true, kind: "schedule", forBotId: request.forBotId, proposal: { action: "create", routine: request.routine } } : { ok: true, kind: "webhook", forBotId: request.forBotId, operation: { action: "create", webhook: request.webhook } }; diff --git a/shared/app-triggers.ts b/shared/app-triggers.ts index d12f4c049e..0b3e5d2464 100644 --- a/shared/app-triggers.ts +++ b/shared/app-triggers.ts @@ -125,7 +125,8 @@ export interface AppTriggerDefinition { export type AppTriggerChange = Partial>; export type AppTriggerRequestOperation = - | { action: "create"; trigger: AppTriggerDefinition; forBot?: { botId: string; name: string } } + /** `replaces`: the id of a schedule of the same bot that kept checking this app; it is paused once the event is live. */ + | { action: "create"; trigger: AppTriggerDefinition; replaces?: string; forBot?: { botId: string; name: string } } | { action: "update"; triggerId: string; changes: AppTriggerChange; forBot?: { botId: string; name: string } } | { action: "pause" | "resume" | "run_now" | "delete"; triggerId: string; forBot?: { botId: string; name: string } }; @@ -143,6 +144,8 @@ export interface AppTriggerRequestCardData { /** The automation's revision right after the change; Undo refuses once it moved. */ appliedUpdatedAt?: number; before?: { name: string; prompt: string; runOn: RoutineRunOn; enabled: boolean; filter?: AppTriggerFilter; config: Record }; + /** The schedule this automation took over and paused: Undo turns it back on, unless it was changed since. */ + replaced?: { routineId: string; name: string; pausedUpdatedAt: number }; }; }