Skip to content

Commit 57d3f6e

Browse files
committed
fix(guardrails): allow solo read-only team runs #32
1 parent 06f0ef3 commit 57d3f6e

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

‎packages/guardrails/profile/plugins/team.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,10 @@ export default async function team(input: { client: Client; worktree: string; di
472472
},
473473
async execute(args, ctx) {
474474
defs(args.tasks)
475-
if (args.tasks.length < 2) throw new Error("team requires at least two tasks")
475+
if (!args.tasks.length) throw new Error("team requires at least one task")
476+
if (args.tasks.length < 2 && args.tasks.some((item) => write(item.prompt, item.write))) {
477+
throw new Error("team requires at least two tasks when any task can mutate files")
478+
}
476479
ctx.metadata({
477480
title: "team run",
478481
metadata: {

‎packages/opencode/test/scenario/guardrails.test.ts‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Filesystem } from "../../src/util/filesystem"
1717
import { tmpdir } from "../fixture/fixture"
1818
import { assertReplay, it, run } from "./harness"
1919
import { replays } from "./replay"
20+
import TeamPlugin from "../../../guardrails/profile/plugins/team"
2021

2122
const managed = process.env.OPENCODE_TEST_MANAGED_CONFIG_DIR!
2223
const profile = path.resolve(import.meta.dir, "../../../guardrails/profile")
@@ -699,6 +700,85 @@ test("guardrail profile blocks write-capable background workers until team runs"
699700
})
700701
})
701702

703+
test("project-specific bash allows beat profile wildcard asks", async () => {
704+
await withProfile(async () => {
705+
await using tmp = await tmpdir({
706+
git: true,
707+
init: async (dir) => {
708+
await write(dir, "opencode.json", {
709+
$schema: "https://opencode.ai/config.json",
710+
permission: {
711+
bash: {
712+
"*": "ask",
713+
"supabase *": "allow",
714+
},
715+
},
716+
})
717+
},
718+
})
719+
720+
await Instance.provide({
721+
directory: tmp.path,
722+
fn: async () => {
723+
const agent = await Agent.get("build")
724+
expect(perm(agent, "bash", "supabase db query")).toBe("allow")
725+
expect(perm(agent, "bash", "unknown cmd")).toBe("ask")
726+
},
727+
})
728+
})
729+
})
730+
731+
test("team tool allows a single read-only task", async () => {
732+
await withProfile(async () => {
733+
await using tmp = await tmpdir({ git: true, config: { share: "auto" } })
734+
735+
const plugin = await TeamPlugin({
736+
client: {
737+
session: {
738+
create: async () => ({ data: { id: "child" } }),
739+
promptAsync: async () => ({}),
740+
prompt: async () => ({}),
741+
status: async () => ({ data: { child: { type: "idle" } } }),
742+
messages: async () => ({
743+
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "ok" }] }],
744+
}),
745+
abort: async () => ({}),
746+
},
747+
},
748+
worktree: tmp.path,
749+
directory: tmp.path,
750+
})
751+
752+
const result = await plugin.tool.team.execute(
753+
{
754+
strategy: "parallel",
755+
limit: 1,
756+
tasks: [
757+
{
758+
id: "inspect",
759+
description: "inspect only",
760+
prompt: "Inspect src/index.ts and report findings without editing files.",
761+
write: false,
762+
worktree: false,
763+
},
764+
],
765+
},
766+
{
767+
sessionID: "session_team_single",
768+
messageID: "",
769+
agent: "build",
770+
directory: tmp.path,
771+
worktree: tmp.path,
772+
abort: AbortSignal.any([]),
773+
metadata: () => {},
774+
ask: async () => {},
775+
},
776+
)
777+
778+
expect(result).toContain("run_id:")
779+
})
780+
})
781+
702782
test("guardrail profile plugin records factcheck and review freshness state", async () => {
703783
await withProfile(async () => {
704784
await using tmp = await tmpdir({

0 commit comments

Comments
 (0)