Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Fix long automation instruction reads and guard redacted replacements
Local contributorf53f1d4b1452
diff --git a/docs/verification/routines.md b/docs/verification/routines.mdindex 7dd88a41c4..9c051709d8 100644--- a/docs/verification/routines.md+++ b/docs/verification/routines.md@@ -28,6 +28,27 @@ pnpm exec vitest run shared/routine-schedule.test.ts server/routine-cron.e2e.tesOMB_UI_E2E=1 pnpm exec vitest run scripts/testing/cron-routines-ui.e2e.test.ts```+## Editing long automation instructions++`trigger_info action=list` keeps bounded instruction previews. Pass `trigger_id`+to read one automation's complete instructions before editing; this applies to+schedules, app events and webhooks. `instructionsTruncated` then reports false.+Secrets remain redacted, and `instructionsRedacted` reports whether the saved+text contains hidden content, including beyond a listing's preview. When true,+a bot instruction replacement fails with HTTP 409 before any field or receipt+changes. Ask the person to edit those instructions on the Automations page;+other updates work when instructions are omitted.++The disposable fake-engine fixture reads a long schedule and webhook through+the real MCP tools, changes one sentence, and checks the full saved text and+readback. It also checks hidden credentials, refused mixed-field replacements,+and renames that preserve instructions. App-event coverage uses its real+manager and a loopback broker stand-in; no real connected account is used.++```sh+pnpm exec vitest run server/trigger-instructions.e2e.test.ts server/trigger-tools.test.ts server/automation-instructions.test.ts server/routine-requests.test.ts server/webhook-requests.test.ts server/app-triggers.test.ts+```+## Launch the isolated rendererRun the launcher directly so Ctrl-C reaches the fixture owner:diff --git a/server/app-trigger-requests.ts b/server/app-trigger-requests.tsindex 708ed9b673..7e0c2503a2 100644--- a/server/app-trigger-requests.ts+++ b/server/app-trigger-requests.ts@@ -5,6 +5,7 @@ import { z } from "zod";import type { AppTrigger, AppTriggerRequestCardData, AppTriggerRequestOperation } from "../shared/app-triggers.ts";import { appLabel } from "./app-event-catalog.ts";import { AppTriggerError, type AppTriggerManager } from "./app-triggers.ts";+import { instructionsUpdateRefusal } from "./automation-instructions.ts";import { newId } from "./contracts.ts";import { UNDO_STALE } from "./direct-apply.ts";import { redactSecretsInText } from "./redact.ts";@@ -48,7 +49,8 @@ const definitionSchema = z.object({runOn: z.enum(["maus", "cloud"]).optional(),sameConversation: z.boolean().optional(),}).strict();-const changesSchema = definitionSchema.pick({ name: true, instructions: true, filter: true, config: true, runOn: true, sameConversation: true }).partial().strict()+const changesSchema = definitionSchema.pick({ name: true, instructions: true, filter: true, config: true, runOn: true, sameConversation: true }).partial()+ .extend({ instructions: definitionSchema.shape.instructions.removeDefault().optional() }).strict().refine((changes) => Object.keys(changes).length > 0, "The update action needs at least one field in changes");const idSchema = z.string().trim().min(1).max(200);const targetSchema = z.object({ botId: z.string(), name: z.string() }).optional();@@ -122,6 +124,10 @@ 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);+ if (operation.action === "update") {+ const refusal = instructionsUpdateRefusal(before!.prompt, operation.changes.instructions);+ if (refusal) throw new AppTriggerError(refusal, 409);+ }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;diff --git a/server/app-triggers.test.ts b/server/app-triggers.test.tsindex 291f123d8c..50df36955b 100644--- a/server/app-triggers.test.ts+++ b/server/app-triggers.test.ts@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";import { join } from "node:path";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { AppTriggerRequestService } from "./app-trigger-requests.ts";import { appEventCatalog } from "./app-event-catalog.ts";import { eventCount } from "./app-events.ts";import { brokerClient } from "./app-trigger-broker.ts";@@ -72,6 +73,24 @@ async function gmailTrigger(triggers: AppTriggerManager, filter = { from: "acme.}describe("AppTriggerManager", () => {+ it("refuses replacing redacted app instructions before changing local or remote state", async () => {+ const triggers = manager();+ const prompt = "Review the queue.\n".repeat(180) + "Use token=fixture-secret-value.";+ const saved = await triggers.create({ botId: "bot-1", name: "Private instructions", prompt, app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE" });+ const store = { messagesFor: () => [], appendMessage: vi.fn(() => ({ id: "message-1" })), patchMessage: vi.fn() };+ const service = new AppTriggerRequestService({ triggers, store, botName: () => "Fixture" });+ const submit = (changes: unknown) => service.submit({ botId: "bot-1", threadId: "thread-a", operation: { action: "update", triggerId: saved.id, changes } });+ const before = structuredClone(triggers.list());+ const remote = structuredClone([...broker.harness.composio.instances.entries()]);+ await expect(submit({ name: "Must not apply", instructions: "Only the visible text.", filter: { from: "changed.example" } }))+ .rejects.toMatchObject({ status: 409 });+ expect(triggers.list()).toEqual(before);+ expect([...broker.harness.composio.instances.entries()]).toEqual(remote);+ expect(store.appendMessage).not.toHaveBeenCalled();+ await submit({ name: "Safe rename" });+ expect(triggers.get(saved.id)).toMatchObject({ name: "Safe rename", prompt });+ });+it("creates the service copy with a Gmail filter folded into Gmail's own search", async () => {const triggers = manager();const trigger = await gmailTrigger(triggers);diff --git a/server/automation-instructions.test.ts b/server/automation-instructions.test.tsnew file mode 100644index 0000000000..093f438ea0--- /dev/null+++ b/server/automation-instructions.test.ts@@ -0,0 +1,18 @@+import { expect, it } from "vitest";+import { instructionsUpdateRefusal } from "./automation-instructions.ts";+import { addHeldSecretScrubber } from "./redact.ts";++it("allows replacing ordinary instructions, including long instructions", () => {+ expect(instructionsUpdateRefusal("Check the queue.\n".repeat(500), "Check the queue twice.")).toBeNull();+});++it("protects held secrets as well as recognizable credentials, while allowing other updates", () => {+ const remove = addHeldSecretScrubber(text => text.replaceAll("fixture-passphrase", "••••••"));+ try {+ for (const secret of ["fixture-passphrase", "sk-ant-api03-abcdefghijklmnopqrstuvwxyz0123456789"]) {+ const prompt = `Use ${secret}.`;+ expect(instructionsUpdateRefusal(prompt, "Replacement")).not.toBeNull();+ expect(instructionsUpdateRefusal(prompt, undefined)).toBeNull();+ }+ } finally { remove(); }+});diff --git a/server/automation-instructions.ts b/server/automation-instructions.tsnew file mode 100644index 0000000000..7953f9cadf--- /dev/null+++ b/server/automation-instructions.ts@@ -0,0 +1,6 @@+import { redactSecretsInText } from "./redact.ts";++export function instructionsUpdateRefusal(prompt: string, instructions: string | undefined): string | null {+ if (instructions === undefined || redactSecretsInText(prompt) === prompt) return null;+ return "These instructions contain hidden credentials, so the bot cannot safely replace them. Ask the person to edit the instructions on the Automations page. Other fields can be changed by omitting instructions.";+}diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.jsonindex 23bb73b616..27f4241fc0 100644--- a/server/drivers/agents-catalog-goldens/full.tools-list.json+++ b/server/drivers/agents-catalog-goldens/full.tools-list.json@@ -1469,7 +1469,7 @@},"trigger_id": {"type": "string",- "description": "list: one trigger's details and recent fires."+ "description": "Full instructions and fires; edit redactions in Automations."},"include_address": {"type": "boolean",diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.jsonindex 32a9afa5c2..120b46e611 100644--- a/server/drivers/agents-catalog-goldens/profiles.json+++ b/server/drivers/agents-catalog-goldens/profiles.json@@ -1,7 +1,7 @@{"default": {- "bytes": 64546,- "sha256": "6fa209da7ace224545f0b43828d0a1f567fd8d77f37d33343aa130567483cd73",+ "bytes": 64561,+ "sha256": "ce345044c23af9a117c03b665dee74753458bca31909ed847cd9554301de19e6","tools": ["tool_result_read","list_room_targets",@@ -55,8 +55,8 @@]},"voice": {- "bytes": 65327,- "sha256": "db093fb2877a3597e465d98f274148b18327386aa6fbe9b75f2817d704b77738",+ "bytes": 65342,+ "sha256": "2099d2a70bc32047b1562077f5d817e6aa5b650b29d63e9e06bbce8cf70bc1bc","tools": ["tool_result_read","list_room_targets",@@ -111,8 +111,8 @@]},"shared": {- "bytes": 66811,- "sha256": "a70baefd6d29b03d67a6d856e18bceb53b9a08afdbc4c32d98782582f947711b",+ "bytes": 66826,+ "sha256": "c1afbf250fa6514c4ae421b16705d3d7ebe916456fc6c63a9a205366f3b17043","tools": ["tool_result_read","list_shared_computers",@@ -168,8 +168,8 @@]},"shared+voice": {- "bytes": 67592,- "sha256": "18de9d9ac96d6727211af85daca28ad332080a1f2c89c0ad41c7ed49aa360899",+ "bytes": 67607,+ "sha256": "1b89cebe1f3118a9e9f2e27556440a2b67e120a8deb46620cbe074952b7c853d","tools": ["tool_result_read","list_shared_computers",@@ -226,8 +226,8 @@]},"skills": {- "bytes": 67622,- "sha256": "c7e6691f5bf992932f7ed83b225cc70460ba469a2edac6672de75b76e6432704",+ "bytes": 67637,+ "sha256": "fddef046bc10b7de60932cc0e861bf625b9c45b053d7d6d9a9edf34058965ae7","tools": ["tool_result_read","list_room_targets",@@ -283,8 +283,8 @@]},"skills+voice": {- "bytes": 68403,- "sha256": "acd160edc7a0a86031ce92f824b2da9adeeaa073c4408c27e3195372abc21358",+ "bytes": 68418,+ "sha256": "a4d6b70a6ceb360c0b574bd36b2c13a6c4d2d5a9b0538f5227782f4121fb7b7d","tools": ["tool_result_read","list_room_targets",@@ -341,8 +341,8 @@]},"skills+shared": {- "bytes": 69887,- "sha256": "d79beed2fedd35a5c785501bc98ead1add7796672dd7925968ef2be9785120f6",+ "bytes": 69902,+ "sha256": "2bf44aed3c580befa1122a0f5f67f20c8915c4031a918cf6521071309aef40bb","tools": ["tool_result_read","list_shared_computers",@@ -400,8 +400,8 @@]},"skills+shared+voice": {- "bytes": 70668,- "sha256": "77895b5ff9822c0e38091bc54216c12b4fb5a4f35990232d3a67533f5176c1d5",+ "bytes": 70683,+ "sha256": "0699e14b09d769d1f2c358a594d44bd3a9f3fedb86ffd0b64ee9674d76240b0b","tools": ["tool_result_read","list_shared_computers",@@ -460,8 +460,8 @@]},"non-chief": {- "bytes": 55049,- "sha256": "5a5fafe103f4d4835e39affb0225da676b2d02598b9683ded7cb5f71eb797606",+ "bytes": 55064,+ "sha256": "ac5740adc940320c19b053b8ed79a931c57292481a35922d47d229b13996cbd3","tools": ["tool_result_read","list_room_targets",@@ -508,8 +508,8 @@]},"voice+non-chief": {- "bytes": 55830,- "sha256": "3113ca0431d5022d940c33c7cb7e4e1d6e3248a7fa375375a25c80b83b8c19b1",+ "bytes": 55845,+ "sha256": "c0463c541b060db511dee21419cfb8bd49284a95fd05444fd8e1ab69fff48a16","tools": ["tool_result_read","list_room_targets",@@ -557,8 +557,8 @@]},"shared+non-chief": {- "bytes": 57314,- "sha256": "aac05fa5c239cbb57da0032d33faeca81dfaa7e4b5ed37afb1fcb6888906a0d1",+ "bytes": 57329,+ "sha256": "f046492fc42cccd5c32bbbb77b7a4e803fb88d5d2f14be3c64576ebc89221a9c","tools": ["tool_result_read","list_shared_computers",@@ -607,8 +607,8 @@]},"shared+voice+non-chief": {- "bytes": 58095,- "sha256": "b3f65f52fc1dd15f04e264597ff81f01e1bbeee1e539124c638e572bf8730e7e",+ "bytes": 58110,+ "sha256": "4d46b1df618e682bf74e6c7af6e63db9836b065f97e024005e8b6d082166907f","tools": ["tool_result_read","list_shared_computers",@@ -658,8 +658,8 @@]},"skills+non-chief": {- "bytes": 58125,- "sha256": "905d2b0a170067bb8a111170df7847c69ba287febeb752ccc6f3a1cf2dd31cf3",+ "bytes": 58140,+ "sha256": "f550a3dadefaef05db7f266cfc52b4e188c3fce4b90f13e1d2b095e771c38873","tools": ["tool_result_read","list_room_targets",@@ -708,8 +708,8 @@]},"skills+voice+non-chief": {- "bytes": 58906,- "sha256": "c17df46c80f2701f6353004e48e384e494e9072b3811d4e1dbd6da55c7f70bba",+ "bytes": 58921,+ "sha256": "00d20164d64905f45b770e72b5a4df59d70926aa9be34c7080779e19a830c1ed","tools": ["tool_result_read","list_room_targets",@@ -759,8 +759,8 @@]},"skills+shared+non-chief": {- "bytes": 60390,- "sha256": "f1ff2476c3f62b67aa4e3e8963cab5166c06fa174a85168a0469d304e715a21a",+ "bytes": 60405,+ "sha256": "42e5ababb1c6c8eee90824d178cdc640d2db39de21559e2353589b58dff27f17","tools": ["tool_result_read","list_shared_computers",@@ -811,8 +811,8 @@]},"skills+shared+voice+non-chief": {- "bytes": 61171,- "sha256": "4581d21d5e79009040c45ddbaccdbd5cafb381ad06f8354e9717424851f05316",+ "bytes": 61186,+ "sha256": "3fb24f7758d3c977a8d931307faa7c7350d84f791f311feece8b5728e79d2eea","tools": ["tool_result_read","list_shared_computers",@@ -864,8 +864,8 @@]},"skills+shared+voice+cloud-home": {- "bytes": 70434,- "sha256": "052540ae938b962dbcd30af5385e98722885b4e4b940130f1add7941ff09776e",+ "bytes": 70449,+ "sha256": "7ac3e46248068f63011ae4a9aeed63311e5d9aa162f87bd5b3b16f29c3f074b3","tools": ["tool_result_read","list_shared_computers",@@ -924,8 +924,8 @@]},"skills+shared+voice+non-chief+cloud-home": {- "bytes": 60937,- "sha256": "2714dc8208f3c0fd7e888d1f89f3cc4211b0488a8287a83016cdea82369e15dd",+ "bytes": 60952,+ "sha256": "393ee2e19c562c7a96dbf50a93a5a937dfef79a28a6fa1071e178ff7b47f71aa","tools": ["tool_result_read","list_shared_computers",@@ -977,8 +977,8 @@]},"skills+shared+voice+x": {- "bytes": 74507,- "sha256": "95164e11d6ab252da36084b738573a6dc95c711e33800a61cf80de8e9456026c",+ "bytes": 74522,+ "sha256": "6f0d78c2e0adcfddad3ac787b164309c24da04eb25f121d0897fc20854c81ea7","tools": ["tool_result_read","list_shared_computers",@@ -1041,8 +1041,8 @@]},"skills+shared+voice+x+team": {- "bytes": 74507,- "sha256": "95164e11d6ab252da36084b738573a6dc95c711e33800a61cf80de8e9456026c",+ "bytes": 74522,+ "sha256": "6f0d78c2e0adcfddad3ac787b164309c24da04eb25f121d0897fc20854c81ea7","tools": ["tool_result_read","list_shared_computers",@@ -1105,8 +1105,8 @@]},"skills+shared+voice+x+team+images": {- "bytes": 75280,- "sha256": "2c51b94221112d5a9353ad1a584c26b5835fc77f438aa2813503b62fb73e7971",+ "bytes": 75295,+ "sha256": "b23988adc30e7c75cdfb101c451c64061bede3108ec31326574a6602a074cb4f","tools": ["tool_result_read","list_shared_computers",@@ -1170,8 +1170,8 @@]},"default+legacy-switches": {- "bytes": 64546,- "sha256": "6fa209da7ace224545f0b43828d0a1f567fd8d77f37d33343aa130567483cd73",+ "bytes": 64561,+ "sha256": "ce345044c23af9a117c03b665dee74753458bca31909ed847cd9554301de19e6","tools": ["tool_result_read","list_room_targets",@@ -1225,8 +1225,8 @@]},"default+mausbot": {- "bytes": 65197,- "sha256": "d1881b21ab418cdd09b7b53373eba4b5421e9f3c8eb11e47cc31609c67351ae9",+ "bytes": 65212,+ "sha256": "5a8278d695bd0e0e4965b640f674ee2dc705192a29a1d77bdf971e381d2385e4","tools": ["tool_result_read","list_room_targets",@@ -1282,8 +1282,8 @@]},"skills+shared+voice+mausbot": {- "bytes": 71319,- "sha256": "2105d633aeb9c344c63d95d8f3f5d42800893028b078b6b417550b7815a1bd01",+ "bytes": 71334,+ "sha256": "53f94eea001a01857df197ebeb6597e883b347403cee3d8fee3063d9d35f463f","tools": ["tool_result_read","list_shared_computers",@@ -1344,8 +1344,8 @@]},"default+no-computer-pick": {- "bytes": 63334,- "sha256": "360567413471e3043b34494da3c5244cb145697824c75f28627e87ea50fc1af7",+ "bytes": 63349,+ "sha256": "40b4706901c58785a6f1a7e37ccbb4b138e7eb7cb11003f42814a8e29a5ad602","tools": ["tool_result_read","list_room_targets",@@ -1398,8 +1398,8 @@]},"default+room": {- "bytes": 60836,- "sha256": "7757709d2412ceb5865ea8a8106800dfb52fabb11db694ecd33d8977c6de4ad6",+ "bytes": 60851,+ "sha256": "4be3f9bd75d65415a9c450bf2a96351218ac80cac4b857ea09c0f0624218d403","tools": ["tool_result_read","list_room_targets",@@ -1448,8 +1448,8 @@]},"non-chief+room": {- "bytes": 51339,- "sha256": "78e86b4b3e76c8dbed4d18c1fe77f1f4065853339052de2a48411051e647255f",+ "bytes": 51354,+ "sha256": "2ed075cfbd3661dea430e40350216b935d087401e32700b92361a3dd3d2e7e0f","tools": ["tool_result_read","list_room_targets",@@ -1491,8 +1491,8 @@]},"default+images": {- "bytes": 65319,- "sha256": "6f63863bac84703fae8b19cb2fcde318dce8ae4b2522e6c3e9dd7549df477774",+ "bytes": 65334,+ "sha256": "77493a94d25638e0bc62201454502b33a76547badb11842e7143b744bd99a2c1","tools": ["tool_result_read","list_room_targets",@@ -1547,8 +1547,8 @@]},"skills+shared+voice+x+team+images+hosting": {- "bytes": 77143,- "sha256": "11098b91d5351d71aaa563bef5dda71cc51ec8b709263f9ab45c8c50b9e753bf",+ "bytes": 77158,+ "sha256": "9a5ab2c51d7abc53d5341714a1233f388639f8c1be6360b5834a1cd7c03e3646","tools": ["tool_result_read","list_shared_computers",@@ -1614,8 +1614,8 @@]},"default+hosting": {- "bytes": 66409,- "sha256": "10a07daa7cdaeaaa15e0410db0d154023408267d746edebced69126a0e12f117",+ "bytes": 66424,+ "sha256": "4ff75aa4a670029a1431f069ba576eb3b598c424e5ddf00af4b29144ed7f7245","tools": ["tool_result_read","list_room_targets",diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.tsindex c2c858d340..784cd2dada 100644--- a/server/drivers/agents-catalog.ts+++ b/server/drivers/agents-catalog.ts@@ -659,7 +659,7 @@ const TOOL_DEFINITIONS = [additionalProperties: false,properties: {action: { type: "string", enum: ["list", "events"] },- trigger_id: { type: "string", description: "list: one trigger's details and recent fires." },+ trigger_id: { type: "string", description: "Full instructions and fires; edit redactions in Automations." },include_address: { type: "boolean", description: "list, with a webhook's trigger_id: also its private address. For the bot that owns it, or a Chief of Staff." },for_bot_id: { type: "string", description: "list: ANOTHER bot's triggers in your section, from list_bots." },app: { type: "string", description: "events: optional app slug, e.g. gmail." },diff --git a/server/routine-requests.test.ts b/server/routine-requests.test.tsindex b11458fd37..ebb22467bf 100644--- a/server/routine-requests.test.ts+++ b/server/routine-requests.test.ts@@ -115,6 +115,20 @@ function cardFingerprint(card: RoutineRequestOptionCard, messageId: string): str}describe("RoutineRequestService", () => {+ it("refuses instruction replacement after redaction without saving a card or changing other fields", async () => {+ const { routines, service, store } = harness();+ const prompt = "Review the queue.\n".repeat(180) + "Use sk-ant-api03-abcdefghijklmnopqrstuvwxyz0123456789.";+ const saved = routines.create({ name: "Private instructions", prompt, botId: "bot-a", target: "bot", runOn: "maus", enabled: false,+ durationMinutes: 30, schedule: { type: "interval", everyMinutes: 60, anchorAt: Date.now() + 3_600_000 } });+ const submit = (changes: unknown) => service.submit({ botId: "bot-a", threadId: "thread-a", proposal: { action: "update", routineId: saved.id, changes } });+ const before = structuredClone(routines.listRoutines());+ await expect(submit({ name: "Must not apply", instructions: "Only the visible text." })).rejects.toMatchObject({ status: 409 });+ expect(routines.listRoutines()).toEqual(before);+ expect(store.messagesFor("thread-a")).toHaveLength(0);+ await submit({ name: "Safe rename" });+ expect(routines.listRoutines()[0]).toMatchObject({ name: "Safe rename", prompt });+ });+describe("duplicate creation", () => {const existingInput: RoutineInput = {botId: "bot-a", name: "Already scheduled", prompt: "Summarize the overnight support queue.",diff --git a/server/routine-requests.ts b/server/routine-requests.tsindex aea2a2bdaf..45c0732387 100644--- a/server/routine-requests.ts+++ b/server/routine-requests.ts@@ -1,3 +1,4 @@+import { instructionsUpdateRefusal } from "./automation-instructions.ts";import { createHash } from "node:crypto";import { isDeepStrictEqual } from "node:util";@@ -15,7 +16,7 @@ import {type RoutineToolScheduleInput,} from "./routine-request-schemas.ts";import { runsOnce } from "../shared/limit-reset.ts";-import { limitResetOccurrence } from "./routine-schedules.ts";+import { limitResetOccurrence, noFutureResumeMessage } from "./routine-schedules.ts";import {intervalHasRestrictions,nextOccurrence,@@ -398,16 +399,6 @@ function ownedRoutine(manager: RoutineManager, id: string, botId: string): Routireturn manager.listRoutines().find((routine) => routine.id === id && routine.botId === botId) ?? null;}-function noFutureResumeMessage(schedule: RoutineSchedule): string {- if (schedule.type === "interval") {- return "That interval routine has no future runs. Choose a later end time or remove the end restriction before resuming.";- }- if (schedule.type === "once") {- return "That one-time routine's scheduled time has passed. Update it to a new future time before resuming.";- }- return "That routine has no future runs. Update its schedule before resuming.";-}-function normalizedOperation(manager: RoutineManager,botId: string,@@ -430,11 +421,14 @@ function normalizedOperation(const current = ownedRoutine(manager, id, ownerBotId);if (!current) throw new RoutineRequestError("That routine does not exist", 404);if (validated.action === "update") {+ const changes = normalizeChanges(validated.changes, now, ownEngine);+ const refusal = instructionsUpdateRefusal(current.prompt, changes.instructions);+ if (refusal) throw new RoutineRequestError(refusal, 409);return {action: "update",routineId: id,expectedUpdatedAt: current.updatedAt,- changes: normalizeChanges(validated.changes, now, ownEngine),+ changes,...(validated.forBot ? { forBot: validated.forBot } : {}),};}diff --git a/server/routine-schedules.ts b/server/routine-schedules.tsindex 80a880a4c8..f1a93f1ffa 100644--- a/server/routine-schedules.ts+++ b/server/routine-schedules.ts@@ -223,3 +223,13 @@ export function limitResetOccurrence(resetsAt: number | null, lastRunFor?: numbeconst at = resetsAt + AFTER_RESET_MS;return lastRunFor !== undefined && at <= lastRunFor ? null : at;}++export function noFutureResumeMessage(schedule: RoutineSchedule): string {+ if (schedule.type === "interval") {+ return "That interval routine has no future runs. Choose a later end time or remove the end restriction before resuming.";+ }+ if (schedule.type === "once") {+ return "That one-time routine's scheduled time has passed. Update it to a new future time before resuming.";+ }+ return "That routine has no future runs. Update its schedule before resuming.";+}diff --git a/server/trigger-instructions.e2e.test.ts b/server/trigger-instructions.e2e.test.tsnew file mode 100644index 0000000000..a9eaeefc19--- /dev/null+++ b/server/trigger-instructions.e2e.test.ts@@ -0,0 +1,75 @@+import { existsSync, readFileSync, writeFileSync } from "node:fs";+import { join } from "node:path";+import { expect, it } from "vitest";+import { launchVerificationServer, runControlOmb } from "../scripts/control-omb.ts";++it("reads, edits and verifies long automation instructions through the real MCP tools without losing the tail or hidden credentials", async () => {+ const fixture = await launchVerificationServer(process.env, undefined, undefined, undefined, undefined, { scripted: true });+ const planPath = join(fixture.info.dataDir, "room-plan.json");+ const evidencePath = `${planPath}.evidence.jsonl`;+ const api = async (method: string, path: string, body?: unknown) => {+ const response = await fetch(fixture.info.url + path, { method,+ headers: { "content-type": "application/json", origin: fixture.info.url },+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),+ });+ const value = await response.json() as any;+ expect(response.ok, JSON.stringify(value)).toBe(true);+ return value;+ };+ const control = (...args: string[]) => runControlOmb([...args, "--url", fixture.info.url]) as Promise<any>;+ const turns = () => existsSync(evidencePath)+ ? readFileSync(evidencePath, "utf8").trim().split("\n").filter(Boolean).map(line => JSON.parse(line)) : [];+ try {+ const { bot } = await control("new-bot", "--name", "Instruction fixture");+ const tool = async (name: string, args: unknown, expectError = false) => {+ const count = turns().length;+ writeFileSync(planPath, JSON.stringify({ [bot.id]: { steps: [{ tool: name, arguments: args, expectError }], reply: "Fixture complete." } }));+ await control("send", "--bot", bot.id, "--task", bot.activeTaskId, "--text", "Check this fixture automation.");+ await expect.poll(() => turns().length, { timeout: 20_000 }).toBe(count + 1);+ await control("wait", "--bot", bot.id, "--task", bot.activeTaskId, "--timeout", "20");+ const response = turns().at(-1).evidence.find((entry: any) => entry.step?.tool === name).response;+ expect(response.error).toBeUndefined();+ expect(Boolean(response.result.isError)).toBe(expectError);+ return response.result.content[0].text as string;+ };+ const detail = async (id: string) => {+ const text = await tool("trigger_info", { action: "list", trigger_id: id });+ return JSON.parse(text.slice(text.indexOf("\n") + 1));+ };+ const prompt = "Review the queue.\n".repeat(220) + "Keep this final instruction.";+ const routine = (await api("POST", "/api/routines", { name: "Long schedule", botId: bot.id, prompt, enabled: false,+ schedule: { type: "interval", everyMinutes: 60, anchorAt: Date.now() + 3_600_000 } })).routine;+ const webhook = (await api("POST", "/api/webhooks", { name: "Long webhook", botId: bot.id, prompt, enabled: false })).webhook;+ const listing = await tool("trigger_info", { action: "list" });+ const previews = JSON.parse(listing.slice(listing.indexOf("\n") + 1));+ for (const saved of [routine, webhook]) {+ expect(previews.find((row: any) => row.id === saved.id)).toMatchObject({ instructionsTruncated: true });+ const full = await detail(saved.id);+ expect(full).toMatchObject({ instructions: prompt, instructionsTruncated: false, instructionsRedacted: false });+ const revised = full.instructions.replace("Review the queue.", "Review the queue twice.");+ await tool("trigger", { action: "update", trigger_id: saved.id, instructions: revised });+ expect((await detail(saved.id)).instructions).toBe(revised);+ const path = saved.id === routine.id ? "/api/routines" : "/api/webhooks";+ const rows = (await api("GET", path))[saved.id === routine.id ? "routines" : "webhooks"];+ expect(rows.find((row: any) => row.id === saved.id).prompt).toBe(revised);+ const secret = "sk-ant-api03-abcdefghijklmnopqrstuvwxyz0123456789";+ const protectedPrompt = `${prompt}\nUse ${secret}.`;+ await api("PATCH", `${path}/${saved.id}`, { prompt: protectedPrompt });+ const hidden = await detail(saved.id);+ expect(hidden.instructionsRedacted).toBe(true);+ expect(hidden.instructionsTruncated).toBe(false);+ expect(JSON.stringify(hidden)).not.toContain(secret);+ const refusal = await tool("trigger", { action: "update", trigger_id: saved.id, name: "Must not apply", instructions: hidden.instructions }, true);+ expect(refusal).not.toContain(secret);+ expect((await api("GET", path))[saved.id === routine.id ? "routines" : "webhooks"].find((row: any) => row.id === saved.id))+ .toMatchObject({ name: saved.name, prompt: protectedPrompt });+ await tool("trigger", { action: "update", trigger_id: saved.id, name: "Safe rename" });+ expect((await api("GET", path))[saved.id === routine.id ? "routines" : "webhooks"].find((row: any) => row.id === saved.id))+ .toMatchObject({ name: "Safe rename", prompt: protectedPrompt });+ }+ } finally {+ if (existsSync(evidencePath)) writeFileSync(`${fixture.info.logPath}.trigger-instructions.jsonl`, readFileSync(evidencePath));+ console.info(JSON.stringify({ logPath: fixture.info.logPath }));+ await fixture.close();+ }+}, 180_000);diff --git a/server/trigger-tools.test.ts b/server/trigger-tools.test.tsindex 7f8026cac7..fd25dc783c 100644--- a/server/trigger-tools.test.ts+++ b/server/trigger-tools.test.ts@@ -3,6 +3,8 @@ import { describe, expect, it } from "vitest";import { listTriggers, parseTriggerRequest, triggerTarget } from "./trigger-tools.ts";import type { Routine, RoutineRun } from "./routines.ts";import type { WebhookTrigger } from "./webhooks.ts";+import type { AppTrigger } from "../shared/app-triggers.ts";+import { addHeldSecretScrubber, redactSecretsInText } from "./redact.ts";const now = Date.parse("2026-10-17T10:00:00Z");const routine = (id: string, botId: string, prompt = "Summarize the inbox."): Routine => ({@@ -18,6 +20,37 @@ const run = (id: string, routineId: string, botId: string, output = "done"): Rou});describe("listTriggers", () => {+ it.each(["schedule", "webhook", "app_event"])("reads complete %s instructions only for an owned trigger id", (kind) => {+ const prompt = "Review the queue.\n".repeat(250) + "Keep this final instruction.";+ const input = {+ botId: "bot-a", routines: kind === "schedule" ? [routine("r1", "bot-a", prompt)] : [],+ webhooks: kind === "webhook" ? [{ ...webhook("r1", "bot-a"), prompt }] : [],+ appTriggers: kind === "app_event" ? [{ id: "r1", botId: "bot-a", prompt, name: "Mail", app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE", delivery: "poll" } as AppTrigger] : [],+ runs: [], timeZone: "UTC", now,+ };+ const preview = listTriggers(input).triggers![0]!;+ expect(preview.instructionsTruncated).toBe(true);+ expect(prompt.startsWith(preview.instructions)).toBe(true);+ expect(preview.instructions.length).toBeLessThan(prompt.length);+ const full = listTriggers({ ...input, triggerId: "r1" }).trigger!;+ expect(full).toMatchObject({ instructions: prompt, instructionsTruncated: false, instructionsRedacted: false });+ expect(listTriggers({ ...input, triggerId: "r1", botId: "bot-b" })).not.toHaveProperty("trigger");+ });++ it("redacts the entire detailed instruction text, including held secrets beyond the preview", () => {+ const secret = "sk-ant-api03-abcdefghijklmnopqrstuvwxyz0123456789";+ const prompt = "Keep checking.\n".repeat(250) + `Use ${secret} and fixture-password.`;+ const remove = addHeldSecretScrubber(text => text.replaceAll("fixture-password", "••••••"));+ try {+ const input = { botId: "bot-a", routines: [routine("r1", "bot-a", prompt)], webhooks: [], runs: [], timeZone: "UTC", now };+ const full = listTriggers({ ...input, triggerId: "r1" }).trigger!;+ expect(full).toMatchObject({ instructions: redactSecretsInText(prompt), instructionsTruncated: false, instructionsRedacted: true });+ expect(JSON.stringify(full)).not.toContain(secret);+ expect(JSON.stringify(full)).not.toContain("fixture-password");+ expect(listTriggers(input).triggers![0]!.instructionsRedacted).toBe(true);+ } finally { remove(); }+ });+it("lists only the bot's own schedules and webhooks, each with its kind, and scrubs credentials", () => {const listed = listTriggers({botId: "bot-a", routines: [routine("r1", "bot-a", "Use token sk-ant-api03-abcdefghijklmnopqrstuvwxyz0123456789 to check."), routine("r2", "bot-b")],diff --git a/server/trigger-tools.ts b/server/trigger-tools.tsindex 86846fdba8..c61706c90b 100644--- a/server/trigger-tools.ts+++ b/server/trigger-tools.ts@@ -31,10 +31,14 @@ function agentRun(run: RoutineRun) {};}-function instructionsOf(text: string) {+function instructionsOf(text: string, full = false) {// Instructions may hold a credential and the result goes back to the model: scrub the whole value before previewing.const safe = redactSecretsInText(text);- return { instructions: safe.slice(0, INSTRUCTIONS_SHOWN), instructionsTruncated: safe.length > INSTRUCTIONS_SHOWN };+ return {+ instructions: full ? safe : safe.slice(0, INSTRUCTIONS_SHOWN),+ instructionsTruncated: !full && safe.length > INSTRUCTIONS_SHOWN,+ instructionsRedacted: safe !== text,+ };}function agentSchedule(schedule: Routine["schedule"]) {@@ -157,7 +161,8 @@ export function listTriggers(input: {if (!routine && !webhook && !app) return { ...header, error: "No trigger with that id belongs to this bot. Call trigger_info without trigger_id to see its ids." };const fires = input.runs.filter((run) => run.routineId === input.triggerId).slice(0, FIRES_SHOWN).map(agentRun);const shown = routine ? agentRoutine(routine, latest.get(routine.id)) : webhook ? agentWebhook(webhook, latest.get(webhook.id)) : agentAppTrigger(app!, latest.get(app!.id));- return { ...header, trigger: { ...shown, recentFires: fires } };+ const prompt = (routine ?? webhook ?? app)!.prompt;+ return { ...header, trigger: { ...shown, ...instructionsOf(prompt, true), recentFires: fires } };}return {...header,diff --git a/server/webhook-requests.test.ts b/server/webhook-requests.test.tsindex 4e1abdc471..e74fd149bb 100644--- a/server/webhook-requests.test.ts+++ b/server/webhook-requests.test.ts@@ -50,6 +50,19 @@ function harness() {const create = { action: "create", webhook: { name: "Interested replies", instructions: "Draft a follow-up for the lead in the payload." } };describe("WebhookRequestService", () => {+ it("refuses replacing redacted instructions atomically but allows a rename", () => {+ const { service, webhooks, store } = harness();+ const prompt = "Review the queue.\n".repeat(180) + "Use token=fixture-secret-value.";+ const saved = webhooks.create({ name: "Private instructions", prompt, botId: "bot-a", runOn: "cloud", enabled: false }).webhook;+ const submit = (changes: unknown) => service.submit({ botId: "bot-a", threadId: "thread-a", operation: { action: "update", webhookId: saved.id, changes } });+ const before = structuredClone(webhooks.list());+ expect(() => submit({ name: "Must not apply", instructions: "Only the visible text." })).toThrow(expect.objectContaining({ status: 409 }));+ expect(webhooks.list()).toEqual(before);+ expect(store.messagesFor("thread-a")).toHaveLength(0);+ submit({ name: "Safe rename" });+ expect(webhooks.list()[0]).toMatchObject({ name: "Safe rename", prompt, runOn: saved.runOn });+ });+it("creates a bot's webhook at once, with a receipt card that never carries its secret, and keeps its address", () => {const { service, webhooks, store, dir } = harness();const applied = service.submit({ botId: "bot-a", threadId: "thread-a", operation: create });diff --git a/server/webhook-requests.ts b/server/webhook-requests.tsindex 45dec2cccd..b15fc97bd8 100644--- a/server/webhook-requests.ts+++ b/server/webhook-requests.ts@@ -3,6 +3,7 @@import { z } from "zod";import type { WebhookRequestCardData, WebhookRequestDefinition, WebhookRequestOperation, WebhookRequestSnapshot } from "../shared/webhook-request.ts";+import { instructionsUpdateRefusal } from "./automation-instructions.ts";import { newId } from "./contracts.ts";import { UNDO_STALE } from "./direct-apply.ts";import { redactSecretsInText } from "./redact.ts";@@ -49,7 +50,10 @@ const definitionSchema = z.object({payloadFilter: z.record(z.string().trim().min(1).max(200), z.string().trim().max(200)).optional(),sameConversation: z.boolean().optional(),}).strict();-const changesSchema = definitionSchema.partial().strict()+const changesSchema = definitionSchema.partial().extend({+ instructions: definitionSchema.shape.instructions.removeDefault().optional(),+ runOn: definitionSchema.shape.runOn.removeDefault().optional(),+}).strict().refine((changes) => Object.keys(changes).length > 0, "The update action needs at least one field in changes");const webhookIdSchema = z.string().trim().min(1).max(200);const targetSchema = z.object({ botId: z.string(), name: z.string() }).optional();@@ -154,6 +158,10 @@ export class WebhookRequestService {const owner = operation.forBot?.botId ?? args.botId;const webhooks = this.options.webhooks;const before = operation.action === "create" ? undefined : this.owned(operation.webhookId, owner);+ if (operation.action === "update") {+ const refusal = instructionsUpdateRefusal(before!.prompt, operation.changes.instructions);+ if (refusal) throw new WebhookRequestError(refusal, 409);+ }if (operation.action === "create") {const duplicate = webhooks.list().find((webhook) => webhook.botId === owner && webhook.enabled &&webhook.name === operation.webhook.name && webhook.prompt === operation.webhook.instructions);