Skip to content

Commit ac0550f

Browse files
authored
Merge pull request #162 from aictrl-dev/fix/issue-147-session-denied-tools
refactor(session): remove question and plan mode; apply session denies to requests and subagents (#147)
2 parents 7cc4b45 + d47f7a9 commit ac0550f

37 files changed

Lines changed: 577 additions & 1515 deletions

‎.opencode/agent/translator.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,6 @@ AICTRL_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS
579579
AICTRL_EXPERIMENTAL_EXA
580580
AICTRL_EXPERIMENTAL_OUTPUT_TOKEN_MAX
581581
AICTRL_EXPERIMENTAL_OXFMT
582-
AICTRL_EXPERIMENTAL_PLAN_MODE
583-
AICTRL_ENABLE_QUESTION_TOOL
584582
AICTRL_FAKE_VCS
585583
AICTRL_GIT_BASH_PATH
586584
AICTRL_MODEL
@@ -708,7 +706,6 @@ zenobi-us/aictrl-skillful
708706
.aictrl/commands/
709707
.aictrl/commands/test.md
710708
.aictrl/modes/
711-
.aictrl/plans/*.md
712709
.aictrl/plugins/
713710
.aictrl/skills/<name>/SKILL.md
714711
.aictrl/skills/git-release/SKILL.md

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ and [JSON event reference](EVENTS.md).
6868

6969
### Non-Interactive Execution
7070

71-
In headless mode, Aictrl automatically rejects all interactive permission requests (like `question` or `plan_enter`), ensuring your pipelines never hang.
71+
In headless mode, Aictrl automatically rejects all interactive permission requests, ensuring your pipelines never hang.
7272

7373
`aictrl run` does not offer the `todowrite` tool: its definition adds about 2.4k tokens to
7474
every request, and a one-shot run has nobody following a todo list. To track a plan, instruct

‎packages/cli/src/acp/README.md‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ aictrl acp
4444
aictrl acp --cwd /path/to/project
4545
```
4646

47-
### Question Tool Opt-In
48-
49-
ACP excludes `QuestionTool` by default.
50-
51-
```bash
52-
AICTRL_ENABLE_QUESTION_TOOL=1 aictrl acp
53-
```
54-
55-
Enable this only for ACP clients that support interactive question prompts.
56-
5747
### Programmatic
5848

5949
```typescript

‎packages/cli/src/agent/agent.ts‎

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import PROMPT_SUMMARY from "./prompt/summary.txt"
1515
import PROMPT_TITLE from "./prompt/title.txt"
1616
import { PermissionNext } from "@/permission/next"
1717
import { mergeDeep, pipe, sortBy, values } from "remeda"
18-
import { Global } from "@/global"
1918
import path from "path"
2019
import { Plugin } from "@/plugin"
2120
import { Skill } from "../skill"
21+
import { Log } from "@/util/log"
2222

2323
export namespace Agent {
24+
const log = Log.create({ service: "agent" })
25+
2426
export const Info = z
2527
.object({
2628
name: z.string(),
@@ -60,9 +62,6 @@ export namespace Agent {
6062
"*": "ask",
6163
...Object.fromEntries(whitelistedDirs.map((dir) => [dir, "allow"])),
6264
},
63-
question: "deny",
64-
plan_enter: "deny",
65-
plan_exit: "deny",
6665
// mirrors github.com/github/gitignore Node.gitignore pattern for .env files
6766
read: {
6867
"*": "allow",
@@ -85,37 +84,7 @@ export namespace Agent {
8584
name: "build",
8685
description: "The default agent. Executes tools based on configured permissions.",
8786
options: {},
88-
permission: PermissionNext.merge(
89-
defaults,
90-
PermissionNext.fromConfig({
91-
question: "allow",
92-
plan_enter: "allow",
93-
}),
94-
user,
95-
),
96-
mode: "primary",
97-
native: true,
98-
},
99-
plan: {
100-
name: "plan",
101-
description: "Plan mode. Disallows all edit tools.",
102-
options: {},
103-
permission: PermissionNext.merge(
104-
defaults,
105-
PermissionNext.fromConfig({
106-
question: "allow",
107-
plan_exit: "allow",
108-
external_directory: {
109-
[path.join(Global.Path.data, "plans", "*")]: "allow",
110-
},
111-
edit: {
112-
"*": "deny",
113-
[path.join(".aictrl", "plans", "*.md")]: "allow",
114-
[path.relative(Instance.worktree, path.join(Global.Path.data, path.join("plans", "*.md")))]: "allow",
115-
},
116-
}),
117-
user,
118-
),
87+
permission: PermissionNext.merge(defaults, user),
11988
mode: "primary",
12089
native: true,
12190
},
@@ -210,6 +179,11 @@ export namespace Agent {
210179
}
211180

212181
for (const [key, value] of Object.entries(cfg.agent ?? {})) {
182+
// the plan agent was removed: an old override of it must not become a custom agent with full permissions
183+
if (key === "plan") {
184+
log.warn("ignoring config for the removed plan agent; restrict an agent through `permission` instead")
185+
continue
186+
}
213187
if (value.disable) {
214188
delete result[key]
215189
continue

‎packages/cli/src/cli/cmd/run.ts‎

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -514,23 +514,13 @@ export const RunCommand = cmd({
514514
await fail("--skill requires a skill name", "INVOCATION_INVALID_ARGUMENTS")
515515
}
516516

517-
const rules: PermissionNext.Ruleset = [
518-
{
519-
permission: "question",
520-
action: "deny",
521-
pattern: "*",
522-
},
523-
{
524-
permission: "plan_enter",
525-
action: "deny",
526-
pattern: "*",
527-
},
528-
{
529-
permission: "plan_exit",
530-
action: "deny",
531-
pattern: "*",
532-
},
533-
]
517+
// fail instead of the unknown-agent fallback: the default agent can edit files a plan run expects to stay untouched
518+
if (args.agent === "plan") {
519+
await fail(
520+
"The plan agent was removed. For a read-only run, deny edit and bash through `permission` config.",
521+
"INVOCATION_INVALID_ARGUMENTS",
522+
)
523+
}
534524

535525
function input(id?: string, body?: Record<string, unknown>) {
536526
if (!args.attach) return { ...(id ? { sessionID: id } : {}), ...body }
@@ -549,7 +539,7 @@ export const RunCommand = cmd({
549539

550540
const prompt = [...args.message, ...(args["--"] || [])].join(" ")
551541
const title = sessionTitle({ title: args.title, prompt, message, command: args.command })
552-
const result = await sdk.session.create(input(undefined, { title, permission: rules }))
542+
const result = await sdk.session.create(input(undefined, { title }))
553543
return result.data?.id
554544
}
555545

@@ -991,7 +981,7 @@ export const RunCommand = cmd({
991981
schemaVersion: SCHEMA_VERSION,
992982
model: args.model,
993983
agent: agent,
994-
permissions: PermissionNext.merge(agentInfo.permission, rules),
984+
permissions: agentInfo.permission,
995985
})
996986

997987
let aborted = false

‎packages/cli/src/config/config.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ export namespace Config {
630630
external_directory: PermissionRule.optional(),
631631
todowrite: PermissionAction.optional(),
632632
todoread: PermissionAction.optional(),
633-
question: PermissionAction.optional(),
634633
webfetch: PermissionAction.optional(),
635634
websearch: PermissionAction.optional(),
636635
codesearch: PermissionAction.optional(),
@@ -1046,15 +1045,13 @@ export namespace Config {
10461045
mode: z
10471046
.object({
10481047
build: Agent.optional(),
1049-
plan: Agent.optional(),
10501048
})
10511049
.catchall(Agent)
10521050
.optional()
10531051
.describe("@deprecated Use `agent` field instead."),
10541052
agent: z
10551053
.object({
10561054
// primary
1057-
plan: Agent.optional(),
10581055
build: Agent.optional(),
10591056
// subagent
10601057
general: Agent.optional(),

‎packages/cli/src/flag/flag.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export namespace Flag {
1818
export declare const AICTRL_DISABLE_PROJECT_CONFIG: boolean
1919
export const AICTRL_FAKE_VCS = process.env["AICTRL_FAKE_VCS"]
2020
export declare const AICTRL_CLIENT: string
21-
export const AICTRL_ENABLE_QUESTION_TOOL = truthy("AICTRL_ENABLE_QUESTION_TOOL")
2221
export declare const AICTRL_MODEL_STREAM_IDLE_TIMEOUT_MS: number
2322

2423
// Experimental
@@ -29,7 +28,6 @@ export namespace Flag {
2928
export const AICTRL_EXPERIMENTAL_OUTPUT_TOKEN_MAX = number("AICTRL_EXPERIMENTAL_OUTPUT_TOKEN_MAX")
3029
export const AICTRL_EXPERIMENTAL_OXFMT = AICTRL_EXPERIMENTAL || truthy("AICTRL_EXPERIMENTAL_OXFMT")
3130
export const AICTRL_DISABLE_FILETIME_CHECK = truthy("AICTRL_DISABLE_FILETIME_CHECK")
32-
export const AICTRL_EXPERIMENTAL_PLAN_MODE = AICTRL_EXPERIMENTAL || truthy("AICTRL_EXPERIMENTAL_PLAN_MODE")
3331
export const AICTRL_MODELS_URL = process.env["AICTRL_MODELS_URL"]
3432
export const AICTRL_MODELS_PATH = process.env["AICTRL_MODELS_PATH"]
3533

‎packages/cli/src/id/id.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export namespace Identifier {
66
session: "ses",
77
message: "msg",
88
permission: "per",
9-
question: "que",
109
user: "usr",
1110
part: "prt",
1211
tool: "tool",

‎packages/cli/src/question/index.ts‎

Lines changed: 0 additions & 171 deletions
This file was deleted.

0 commit comments

Comments
 (0)