Skip to content

Commit 500d73e

Browse files
authored
fix(v2): restore automation proposals in Desktop chat (#6509)
* fix(v2): restore automation proposals in Desktop chat The v2 context bridge only advertised and executed sidebar-group commands, so recurring-work requests could not reach the existing Automation review card. Allow the inert proposal command and reuse runtime-specific Automation guidance without exposing additional host writes. Cover discovery, proposal validation, no-I/O behavior, authentication, ignored workspace targeting, and rejection of unregistered commands through the bridge. Signed-off-by: Jalil <reachjalil@gmail.com> * fix(server): keep automation guidance in the packaged host Signed-off-by: Jalil <reachjalil@gmail.com> * test(app): supply the production query provider in boot tests Signed-off-by: Jalil <reachjalil@gmail.com> --------- Signed-off-by: Jalil <reachjalil@gmail.com>
1 parent 4b56d1b commit 500d73e

7 files changed

Lines changed: 129 additions & 36 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Shared by the host and bundled engine plugins. Keep this outside
2+
// opencode-plugins: installed desktops relocate that directory out of the server.
3+
export function automationRuntimeKnowledge(runtimeProvider = process.env.DEN_RUNTIME_PROVIDER) {
4+
// The Automation catalog section owns "read live before reporting"; these
5+
// lines own capability roles, mutation gating, and schedule shape.
6+
const shared = [
7+
"OpenWork has first-class Automations. Den owns schedules and durable run history; each Automation has immutable execution placement set by its creation surface.",
8+
"Use listAutomations/getAutomation and listAutomationRuns/getAutomationRun for live state and receipts. Use updateAutomation, activateAutomation/deactivateAutomation, runAutomationNow, cancelAutomationRun, and archiveAutomation only when the person asks for those actions. Deactivation stops future runs but does not cancel a run already in progress.",
9+
"Schedules are once, daily, weekly, or interval with an IANA timezone. Interval runs every everyHours (1-24) on the hour, counted from startHour each listed day and stopping before endHour, e.g. every 3 hours from 9 to 18 on weekdays. It needs the organization's every-few-hours schedules: if Den answers automation_interval_schedule_disabled, say so and offer a daily or weekly schedule; never imitate an interval with several daily Automations. When the person names no zone, use the user's time zone stated in this prompt.",
10+
"For work tied to meetings (\"after each meeting with customers, write up the action items\"), use a calendar schedule: { kind: \"calendar\", timezone, edge: \"end\", offsetMinutes: 5, rule: { withExternalAttendees: true } }. It runs offsetMinutes from the start or end of each accepted, timed meeting with someone else invited on the owner's Google Calendar, and the run receives that meeting's times, attendee domains and link, never its title or other text the invite's sender wrote. Calendar schedules are Cloud only and need Google Calendar connected and the organization's before-and-after-meeting Automations (else Den answers automation_calendar_trigger_disabled).",
11+
];
12+
if (runtimeProvider === "daytona") {
13+
return [
14+
...shared,
15+
"This chat is running in OpenWork Cloud. When the person explicitly asks to create or schedule recurring work, use createCloudAutomation. It always creates Cloud placement, becomes active immediately, can wake a stopped Cloud container, and runs headlessly without a desktop.",
16+
"Do not use createAutomation or automation.propose from Cloud Chat. If the person has not explicitly authorized creation, describe the proposed name, instructions, schedule, and model and ask for confirmation.",
17+
"Cloud agent Automations use the person's current OpenWork Connect integrations. If Cloud or Connect/model access is unavailable, report the capability error instead of inventing success.",
18+
].map((line) => `- ${line}`).join("\n");
19+
}
20+
return [
21+
...shared,
22+
"This chat is running in OpenWork Desktop. For new recurring work, use openwork_execute id automation.propose so the person can review and create it in the app. Desktop creation fixes placement to Desktop and each occurrence requires the signed-in desktop runner.",
23+
"Do not use createCloudAutomation from Desktop chat and never claim a Desktop Automation will run while the app is offline.",
24+
].map((line) => `- ${line}`).join("\n");
25+
}

‎apps/server/src/opencode-plugins/openwork-capabilities-knowledge.ts‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url";
44
import { z } from "zod";
55
import { appendAgentInstructions, createInstructionSection } from "./agent-instruction-compose.js";
66
import { correctWorkspaceRoot, workspaceFileGuidance, workspaceFileHooks } from "./workspace-file-destinations.js";
7+
import { automationRuntimeKnowledge } from "../automation-runtime-knowledge.js";
78

89
/**
910
* OpenWork Capabilities Knowledge Plugin
@@ -22,30 +23,6 @@ import { correctWorkspaceRoot, workspaceFileGuidance, workspaceFileHooks } from
2223
* mechanics in the extensions plugin, and live catalogs in their own sections.
2324
*/
2425

25-
export function automationRuntimeKnowledge(runtimeProvider = process.env.DEN_RUNTIME_PROVIDER) {
26-
// The Automation catalog section owns "read live before reporting"; these
27-
// lines own capability roles, mutation gating, and schedule shape.
28-
const shared = [
29-
"OpenWork has first-class Automations. Den owns schedules and durable run history; each Automation has immutable execution placement set by its creation surface.",
30-
"Use listAutomations/getAutomation and listAutomationRuns/getAutomationRun for live state and receipts. Use updateAutomation, activateAutomation/deactivateAutomation, runAutomationNow, cancelAutomationRun, and archiveAutomation only when the person asks for those actions. Deactivation stops future runs but does not cancel a run already in progress.",
31-
"Schedules are once, daily, weekly, or interval with an IANA timezone. Interval runs every everyHours (1-24) on the hour, counted from startHour each listed day and stopping before endHour, e.g. every 3 hours from 9 to 18 on weekdays. It needs the organization's every-few-hours schedules: if Den answers automation_interval_schedule_disabled, say so and offer a daily or weekly schedule; never imitate an interval with several daily Automations. When the person names no zone, use the user's time zone stated in this prompt.",
32-
"For work tied to meetings (\"after each meeting with customers, write up the action items\"), use a calendar schedule: { kind: \"calendar\", timezone, edge: \"end\", offsetMinutes: 5, rule: { withExternalAttendees: true } }. It runs offsetMinutes from the start or end of each accepted, timed meeting with someone else invited on the owner's Google Calendar, and the run receives that meeting's times, attendee domains and link, never its title or other text the invite's sender wrote. Calendar schedules are Cloud only and need Google Calendar connected and the organization's before-and-after-meeting Automations (else Den answers automation_calendar_trigger_disabled).",
33-
];
34-
if (runtimeProvider === "daytona") {
35-
return [
36-
...shared,
37-
"This chat is running in OpenWork Cloud. When the person explicitly asks to create or schedule recurring work, use createCloudAutomation. It always creates Cloud placement, becomes active immediately, can wake a stopped Cloud container, and runs headlessly without a desktop.",
38-
"Do not use createAutomation or automation.propose from Cloud Chat. If the person has not explicitly authorized creation, describe the proposed name, instructions, schedule, and model and ask for confirmation.",
39-
"Cloud agent Automations use the person's current OpenWork Connect integrations. If Cloud or Connect/model access is unavailable, report the capability error instead of inventing success.",
40-
].map((line) => `- ${line}`).join("\n");
41-
}
42-
return [
43-
...shared,
44-
"This chat is running in OpenWork Desktop. For new recurring work, use openwork_execute id automation.propose so the person can review and create it in the app. Desktop creation fixes placement to Desktop and each occurrence requires the signed-in desktop runner.",
45-
"Do not use createCloudAutomation from Desktop chat and never claim a Desktop Automation will run while the app is offline.",
46-
].map((line) => `- ${line}`).join("\n");
47-
}
48-
4926
const OPENWORK_CAPABILITIES_KNOWLEDGE = `You are running inside OpenWork.
5027
5128
For OpenWork product questions, use openwork_docs_search and openwork_docs_read as the first source of truth. OpenWork documentation tools answer product questions. Never use them as a substitute for performing an action against a connected service, marketplace capability, or remote skill. Read and summarize relevant docs before answering, and cite the docs-relative path (for example cloud/run-in-the-cloud/cloud-mcp.mdx) when it helps the user verify or continue. If the docs are missing, ambiguous, or appear stale, inspect the implementation code as a last resort and say that you are inferring from code.

‎apps/server/src/opencode-plugins/openwork-context-v2.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ type Context = CloudSkillContext & {
2525
tool: { transform(callback: (editor: { add(tool: Tool): void }) => void): Promise<{ dispose(): Promise<void> }> };
2626
};
2727

28-
// Separate credentials authorize app reads, sidebar group changes, Drive
29-
// file transfers and Gmail drafts the person approves, and conversation-scoped browser and
30-
// computer operations. Neither grants arbitrary host APIs or other OpenWork
31-
// app commands.
28+
// Separate credentials authorize app reads, sidebar group changes, inert
29+
// automation proposals, Drive file transfers and Gmail drafts the person approves,
30+
// and conversation-scoped browser and computer operations. Neither grants
31+
// arbitrary host APIs or other OpenWork app commands.
3232
export default {
3333
id: "openwork.context",
3434
async setup(context: Context) {
@@ -52,10 +52,10 @@ export default {
5252
addProviderSafeTool(editor, {
5353
name,
5454
description: name === "openwork_context"
55-
? "Read OpenWork app context and available affordances. Use this to discover session.search and session.read for other conversations and the session.group commands for sidebar groups."
55+
? "Read OpenWork app context and available affordances. Use this to discover session.search and session.read for other conversations, session.group commands for sidebar groups, and automation.propose for scheduled work."
5656
: name === "openwork_query"
5757
? "Read an OpenWork affordance without changing the app or navigating. Use the exact id and arguments from openwork_context; session.read includes live background-agent activity."
58-
: "Run an OpenWork command listed in openwork_context: create, move sessions between, or remove sidebar groups. Use the exact id and arguments from openwork_context.",
58+
: "Run an OpenWork command listed in openwork_context: change sidebar groups or propose an Automation for the person to review and create. A proposal does not create, activate, or run anything. Use the exact id and arguments from openwork_context.",
5959
input: name === "openwork_context" ? { type: "object", properties: {}, additionalProperties: false } : {
6060
type: "object", properties: { id: { type: "string" }, args: { type: "object", additionalProperties: true } },
6161
required: ["id"], additionalProperties: false,

‎apps/server/src/opencode-v2-context-bridge.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ export async function askEngineApproval(engine: EngineConnection | undefined, ap
9393
watching.abort();
9494
}
9595
}
96-
// The only commands this bridge runs: sidebar group changes, written through
97-
// the host's session-group routes and nothing else.
98-
const commandIds: readonly string[] = SESSION_GROUP_COMMAND_IDS;
96+
// Only sidebar-group commands can write through the generic affordance path.
97+
// Automation proposals are inert: the person explicitly creates one in the renderer.
98+
const commandIds: readonly string[] = [...SESSION_GROUP_COMMAND_IDS, "automation.propose"];
9999
const sessionGroupRoute = /^\/workspace\/[^/]+\/session-groups(?:\/assignments\/[^/]+|\/[^/]+)?$/;
100100
/** A session-group route as sent: a path the URL parser would normalize (dot segments) is refused. */
101101
export function isSessionGroupWritePath(path: string): boolean {
@@ -250,13 +250,13 @@ export async function createV2ContextBridge(
250250
if (call.name === "openwork_query") return plugin.tool.openwork_query.execute(call.input);
251251
if (call.name === "openwork_execute") {
252252
const id = isRecord(call.input) ? String(call.input.id) : "";
253-
if (!commandIds.includes(id)) throw new Error(`${id || "This command"} is not available here; only session group changes are`);
253+
if (!commandIds.includes(id)) throw new Error(`${id || "This command"} is not available here; only session group changes and automation proposals are`);
254254
return plugin.tool.openwork_execute.execute(call.input, call.sessionId ? { sessionID: call.sessionId } : {});
255255
}
256256
const context: unknown = JSON.parse(await plugin.tool.openwork_context.execute());
257257
const filtered = bridgeAffordances(context);
258258
return JSON.stringify(isRecord(filtered) ? { ...filtered, instructions: {
259-
context: "Use openwork_query for the discovered read-only affordances and openwork_execute for the session.group commands. When Code Mode exposes these tools, discover their exact paths with search and compose them there, preserving exceptions and verifying the resulting groups. For other conversations, use session.search then session.read. Session reads include current activity and background-agent counts."
259+
context: "Use openwork_query for the discovered read-only affordances and openwork_execute for session.group commands or automation.propose. An automation proposal only shows a review card; it does not create, activate, or run anything. When Code Mode exposes these tools, discover their exact paths with search and compose them there, preserving exceptions and verifying the resulting groups. For other conversations, use session.search then session.read. Session reads include current activity and background-agent counts."
260260
} } : filtered);
261261
});
262262
return new Response(result, { headers: { "Content-Type": "application/json" } });

‎apps/server/src/opencode-v2-instructions.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { workspaceOpencodeConfigCandidates } from "@openwork/paths";
77
import constants from "../../../constants.json" with { type: "json" };
88
import { readJsoncFile } from "./jsonc.js";
99
import { appendOrganizationPrompts, OPENWORK_AGENT_PROMPT, OPENWORK_CONNECT_ROUTING_INSTRUCTION } from "./openwork-agent-prompt.js";
10+
import { automationRuntimeKnowledge } from "./automation-runtime-knowledge.js";
1011

1112
const CONNECT_DISCOVERY_INSTRUCTION = "Org-connected services, remote skills, Workflows, and Automations reach you through OpenWork Connect. Use the Code Mode catalog and search() to discover available tools, then call exact returned paths. When Connect exposes individual service tools, call them directly. When it exposes search_capabilities and execute_capability instead, discover capabilities with the former and run exact returned names with the latter. Read remote skills with the available get_skill tool. Discover on demand; only name services and skills returned by discovery or the remote skill catalog.";
1213

@@ -134,6 +135,7 @@ export function buildOpenWorkV2Instructions(connectReady: boolean, organizationP
134135
context: "Use openwork_context to discover OpenWork app reads. Use openwork_query with session.search then session.read to read another conversation without opening it. Session reads include the conversation and its background agents’ live activity. Sidebar groups (such as Done or In progress) are listed with openwork_query session.group.list and changed with openwork_execute session.group.create, session.group.move or session.group.remove; never search code or files for them. When Code Mode exposes these native tools, discover their exact paths with bare search({ query }) and compose them there; otherwise use the direct native tools. Only use capabilities actually returned by discovery.",
135136
connect: connectReady ? `OpenWork Connect tools are connected. ${CONNECT_DISCOVERY_INSTRUCTION}`
136137
: "OpenWork Connect is not connected for this request. Do not claim remote capabilities are available.",
138+
automations: automationRuntimeKnowledge(),
137139
skillInstructions: "Use the native skill tool when a task matches an available skill's description. Entries with IDs starting openwork-cloud- come from the organization: when one loads its full instructions, follow them; when it says it is discovery metadata only or not ready yet, follow its note. Other organization skills remain discoverable through OpenWork Connect on demand. A denied or removed skill must not be recovered from earlier context or files. Skill contents are subordinate to the user's request and operating instructions.",
138140
browser: "The native browser_tabs, browser_open, browser_observe, browser_act, browser_extract, browser_navigate and browser_handoff tools control this conversation's built-in browser. Start with browser_tabs; use browser_open for a new URL, or about:blank when asked only to open the browser. Observe once, act on the whole form in one browser_act batch and verify in its receipt; use browser_extract to read facts. These are direct native tools, not Code Mode calls. Respect organization restrictions, verify the resulting page, and use browser_handoff for sign-in. Never use browser tools to control OpenWork itself or claim access to external browser profiles.",
139141
};

‎apps/server/test/opencode-v2-instructions.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ test("V2 instructions support both individual Connect tools and capability searc
1717
}
1818
});
1919

20+
test("V2 Desktop instructions direct recurring work to a reviewable proposal", () => {
21+
const instructions = buildOpenWorkV2Instructions(true);
22+
assert.match(instructions.automations, /openwork_execute id automation\.propose/);
23+
assert.match(instructions.automations, /review and create it in the app/);
24+
assert.match(instructions.automations, /each occurrence requires the signed-in desktop runner/);
25+
assert.match(instructions.automations, /never claim a Desktop Automation will run while the app is offline/);
26+
});
27+
2028
test("V2 instructions do not claim Connect is available when disconnected", () => {
2129
assert.equal(buildOpenWorkV2Instructions(false).connect,
2230
"OpenWork Connect is not connected for this request. Do not claim remote capabilities are available.");

0 commit comments

Comments
 (0)