An open-source, faster Devin alternative
TypeScript
Keep PTO agents on managed Calendar tools (#583)
Mohamed Habib7b4fa9d3bc0b
diff --git a/cli/src/project.test.ts b/cli/src/project.test.tsindex 0cfdb8d2..0acbe85e 100644--- a/cli/src/project.test.ts+++ b/cli/src/project.test.ts@@ -104,6 +104,10 @@ test("the compiler maps flat source into an OpenCode runtime", async () => {);assert.match(runtimeInstructions, /You are an OpenComputer agent/);assert.match(runtimeInstructions, /Never direct users to OpenCode/);+ assert.match(+ runtimeInstructions,+ /Never use an interactive question tool[\s\S]*normal assistant message/,+ );assert.match(runtimeInstructions, /Email triage/);assert.equal((await stat(resolve(runtime, ".opencode", "tools", "gmail.ts"))).isFile(),@@ -138,6 +142,10 @@ test("the compiler maps flat source into an OpenCode runtime", async () => {(await stat(resolve(runtime, "opencode.json"))).isFile(),true,);+ const runtimeOpenCode = JSON.parse(+ await readFile(resolve(runtime, "opencode.json"), "utf8"),+ ) as { tools: { question: boolean } };+ assert.equal(runtimeOpenCode.tools.question, false);assert.match(runtimeInstructions, /start with the `gmail_search` tool/);assert.match(runtimeInstructions, /summary count exactly matches/);assert.equal(@@ -222,9 +230,40 @@ test("the PTO template creates Calendar tools without checked-in channel state",await readFile(resolve(root, "opencode.json"), "utf8"),/calendar_create_time_off/,);+ const opencode = JSON.parse(+ await readFile(resolve(root, "opencode.json"), "utf8"),+ ) as { permission: { bash: string }; tools: { question: boolean } };+ assert.equal(opencode.permission.bash, "deny");+ assert.equal(opencode.tools.question, false);+ assert.match(+ await readFile(resolve(root, "agent.ts"), "utf8"),+ /shell: "deny"/,+ );+ assert.match(+ await readFile(resolve(root, "instructions.md"), "utf8"),+ /Never[\s\S]*curl[\s\S]*managed connection/,+ );+ assert.match(+ await readFile(resolve(root, "skills", "manage-pto", "SKILL.md"), "utf8"),+ /Never use bash[\s\S]*direct Google API requests/,+ );await assert.rejects(stat(resolve(root, "channels", "slack.ts")));await assert.rejects(stat(resolve(root, "slack", "manifest.json")));} finally {await rm(root, { recursive: true, force: true });}});++test("an incomplete PTO project cannot be packaged without Calendar tools", async () => {+ const root = await mkdtemp(resolve(tmpdir(), "pto-calendar-incomplete-"));+ try {+ await initializeAgentProject(ptoTemplate, root);+ await rm(resolve(root, "tools", "calendar.ts"));+ await assert.rejects(+ buildAgentArtifact(root),+ /opencomputer tools add calendar/,+ );+ } finally {+ await rm(root, { recursive: true, force: true });+ }+});diff --git a/cli/src/project.ts b/cli/src/project.tsindex e5388ea1..04436037 100644--- a/cli/src/project.ts+++ b/cli/src/project.ts@@ -237,6 +237,10 @@ ${template.description}6. Report only the event details returned by Google Calendar. Never claim anevent was created when the tool failed or returned no event ID.+Use only the injected \`calendar_*\` tools for Calendar reads and writes. Never+use shell commands, \`curl\`, or direct Google API requests: they bypass the+user's managed connection and cannot authenticate as that user.+## Safety and user control- Never create, update, move, or delete a calendar event without fresh,@@ -927,7 +931,7 @@ export async function initializeAgentProject(`export default {model: process.env.OPENCOMPUTER_MODEL,permissions: {- shell: "ask",+ shell: "${template.id === "pto-calendar" ? "deny" : "ask"}",files: "allow",},};@@ -938,8 +942,11 @@ export async function initializeAgentProject(`${JSON.stringify({$schema: "https://opencode.ai/config.json",+ tools: {+ question: false,+ },permission: {- bash: "ask",+ bash: template.id === "pto-calendar" ? "deny" : "ask",...(template.integrations.includes("Gmail")? {gmail_modify: "ask",@@ -1098,6 +1105,10 @@ Use this workflow when the user asks to schedule or review time off.6. Only after confirmation, call \`calendar_create_time_off\`.7. Report the returned event ID and link. Do not claim success without them.+Use only the injected \`calendar_*\` tools. Never use bash, shell commands,+\`curl\`, or direct Google API requests for Calendar operations. Those paths do+not carry the user's managed Calendar identity.+Calendar connections are injected by OpenComputer at runtime. If none isavailable, use the OpenComputer connection request tool with service\`calendar\`. Do not inspect environment variables or repository source.@@ -1158,6 +1169,9 @@ the product or support surface presented to users.- Identify yourself and your environment as OpenComputer.- Never direct users to OpenCode commands, settings, websites, repositories,issue trackers, or support channels.+- Never use an interactive question tool. Ask clarification questions in a+ normal assistant message, then end the turn so the user can reply through+ the current OpenComputer interface.- Before saying an external account is unavailable, use the built-inOpenComputer connection tools to list or request the required connection.- When the user asks for another account of the same service, request a new@@ -1173,7 +1187,28 @@ ${await readFile(resolve(root, "instructions.md"), "utf8")}`,);const openCodeConfig = resolve(root, "opencode.json");if (await exists(openCodeConfig)) {- await cp(openCodeConfig, resolve(runtime, "opencode.json"));+ const parsed: unknown = JSON.parse(await readFile(openCodeConfig, "utf8"));+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {+ throw new Error("opencode.json must contain a JSON object");+ }+ const config = parsed as Record<string, unknown>;+ const configuredTools =+ config.tools &&+ typeof config.tools === "object" &&+ !Array.isArray(config.tools)+ ? (config.tools as Record<string, unknown>)+ : {};+ await writeFile(+ resolve(runtime, "opencode.json"),+ `${JSON.stringify(+ {+ ...config,+ tools: { ...configuredTools, question: false },+ },+ null,+ 2,+ )}\n`,+ );}for (const directory of ["skills", "tools"]) {const source = resolve(root, directory);@@ -1229,11 +1264,35 @@ async function collectFiles(return result;}+async function validateTemplateRequirements(+ root: string,+ manifest: AgentManifest,+): Promise<void> {+ if (manifest.template !== "pto-calendar") return;+ let calendarDeclared = false;+ try {+ const declaration = JSON.parse(+ await readFile(resolve(root, "connections", "google.json"), "utf8"),+ ) as { services?: unknown };+ calendarDeclared =+ Array.isArray(declaration.services) &&+ declaration.services.includes("calendar");+ } catch {+ // Report one actionable error below for an incomplete PTO project.+ }+ if (!(await exists(resolve(root, "tools", "calendar.ts"))) || !calendarDeclared) {+ throw new Error(+ "PTO calendar tools are missing. Run `opencomputer tools add calendar` before deploying.",+ );+ }+}+export async function buildAgentArtifact(root: string,): Promise<BuiltAgentArtifact> {const startedAt = performance.now();const manifest = await readManifest(root);+ await validateTemplateRequirements(root, manifest);const runtime = await prepareAgent(root);const channels = await collectNames(root, "channels");const connections = await collectNames(root, "connections");