From b84b6ab23a9adc6e6a7e3457a4c7865efdb429a8 Mon Sep 17 00:00:00 2001 From: hermes Date: Sat, 14 Nov 2026 13:18:27 +0000 Subject: [PATCH] Gate task subagents behind permission prompt; subagents=false / --no-subagents; description: only when asked --- README.md | 2 +- crates/hx-cli/src/config.sample.toml | 1 + crates/hx-cli/src/main.rs | 12 ++++++++++-- crates/hx-core/src/approve.rs | 7 ++++++- crates/hx-core/src/permit.rs | 28 +++++++++++++++++++++++++++- crates/hx-core/src/subagent.rs | 2 +- 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ec626eb..41bcf54 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Permissions: only writes ask. `write`/`edit` and unknown `bash` commands prompt; Auto permissions (`--auto`, `permissions = "auto"`, `/auto [on|off|log]`): nothing prompts for the usual work, and dangerous calls are refused without asking. A refused call returns `blocked by auto mode: ` to the model (also over a stored "always" rule); `/auto log` lists the last 20. Per call, in order: (1) rules block `rm -rf` of home/root/project root/outside the project, `sudo`, raw disk writes and filesystem creation, download piped to a shell, force push, push to main/master, sending `.env`/keys over the network, `npm|cargo publish`, `docker push`, `kubectl delete`, `terraform destroy`, SQL `DROP`, writes to `/etc`, `~/.ssh`, shell rc files, `.git/hooks`; (2) rules allow routine work inside the project (build/test/format, local git, `mkdir`/`mv`/`cp`/`rm` in the project, `write`/`edit` of project files); (3) everything else (unknown binaries, `curl`, `python -c`, `$(..)`, redirects, paths outside the project) goes to one cheap-model request (Haiku/Luna, ~300 input tokens, 20 s timeout) that answers ALLOW or BLOCK; if that fails or is unavailable the normal prompt appears. `--yolo` / `/yolo` still skip everything. With the `claude_cli` provider claude's tools appear on the event bus (`tool_call` / `tool_result`; hx names `bash{command}`, `write|edit|read{path}`, other tools under claude's name), so extensions can block them (a `block` denies the call with its reason) and NDJSON / `hx stats` see them. Reads are asked too (`--settings` `permissions.ask`; Bash too, claude auto-runs read-only commands like `ls` without asking otherwise). In `-p` there is no prompt and everything is allowed, unless `permissions = "deny"` (every unanswered call is denied) or `permissions = "extensions-only"` (allowed only while a live `tool_call` extension exists). The same rules apply to claude's tool calls, but no model judge runs (unclear ones ask). Pattern rules are not a sandbox: combine with `[sandbox]` for confinement. -The model can call `task(prompt, kind)` (or `task(prompts=[…], kind)` to fan out: one subagent per prompt, parallel, answers returned numbered; a lone task blocks the parent, so the tool description steers the model to batches) to run a subagent with a fresh context and get back only its final answer (cut at 8 KB), so big searches don't fill the main context. `explore` (default) is read-only (`read`, `lsp`, `bash`) on the provider's cheapest model (`explore_model` in config); `general` has the parent's tools and model, and the lens runs on its edits. Up to 3 run in parallel, none can start another, a parent abort stops them. Their sessions are written to `.sub/`; `hx stats` shows `task` usage (calls, lone vs. batched turns) and lists them and the footer token counts include them. **Overview:** while any subagent exists, a list sits above the footer (bottom right: spinner/✓, id, kind, task, time, calls, tokens). `ctrl-g` focuses it (`↑↓`, `enter` opens, `esc` closes); the detail view shows that agent's live transcript. Typing there messages the agent: while it runs the text is delivered at its next turn end (like steering the main agent), after it finished it continues that agent's conversation. `ctrl-c` aborts that agent only; `ctrl-s` sends its last answer to the main chat as `[subagent N] …`. NDJSON/RPC carry no per-agent events yet. +Each `task` call asks for permission (`[a]` allows that kind for the project); `subagents = false` or `--no-subagents` removes the tool. The model can call `task(prompt, kind)` (or `task(prompts=[…], kind)` to fan out: one subagent per prompt, parallel, answers returned numbered; a lone task blocks the parent, so the tool description steers the model to batches) to run a subagent with a fresh context and get back only its final answer (cut at 8 KB), so big searches don't fill the main context. `explore` (default) is read-only (`read`, `lsp`, `bash`) on the provider's cheapest model (`explore_model` in config); `general` has the parent's tools and model, and the lens runs on its edits. Up to 3 run in parallel, none can start another, a parent abort stops them. Their sessions are written to `.sub/`; `hx stats` shows `task` usage (calls, lone vs. batched turns) and lists them and the footer token counts include them. **Overview:** while any subagent exists, a list sits above the footer (bottom right: spinner/✓, id, kind, task, time, calls, tokens). `ctrl-g` focuses it (`↑↓`, `enter` opens, `esc` closes); the detail view shows that agent's live transcript. Typing there messages the agent: while it runs the text is delivered at its next turn end (like steering the main agent), after it finished it continues that agent's conversation. `ctrl-c` aborts that agent only; `ctrl-s` sends its last answer to the main chat as `[subagent N] …`. NDJSON/RPC carry no per-agent events yet. A child starts with a cold prompt cache and costs tokens of its own: it saves *main-context* size, not total tokens. diff --git a/crates/hx-cli/src/config.sample.toml b/crates/hx-cli/src/config.sample.toml index 0bbabef..2564470 100644 --- a/crates/hx-cli/src/config.sample.toml +++ b/crates/hx-cli/src/config.sample.toml @@ -5,6 +5,7 @@ # model = "claude-sonnet-5-5" # model for the chosen provider; "auto" = pick per prompt (see [auto]) # claude_model = "claude-sonnet-5-5" # default: the account's latest Sonnet # codex_model = "gpt-5.6-sol" # default: Codex's top-listed model +# subagents = false # do not offer the `task` tool (default true; every call asks first) # explore_model = "claude-haiku-4-5" # read-only `task` subagents; default: cheapest tier of the provider # remember_model = true # reuse the last model picked with /model or /provider # compact_at = 900000 # auto-compact at this many tokens; default: 90% of the context window diff --git a/crates/hx-cli/src/main.rs b/crates/hx-cli/src/main.rs index 44884b6..ff135b5 100644 --- a/crates/hx-cli/src/main.rs +++ b/crates/hx-cli/src/main.rs @@ -49,6 +49,9 @@ struct Cli { /// prompt (also `permissions = "auto"`). #[arg(long, conflicts_with = "yolo")] auto: bool, + /// Do not offer the `task` subagent tool to the model. + #[arg(long)] + no_subagents: bool, /// Run bash, LSP servers and lens runners in a sandbox (bwrap / seatbelt). #[arg(long, conflicts_with = "no_sandbox")] sandbox: bool, @@ -160,6 +163,8 @@ struct Config { max_tokens: Option, /// Model for read-only `task` subagents; default: the provider's cheapest tier (Haiku / Luna). explore_model: Option, + /// Register the `task` subagent tool (default true; each call still asks the user). `--no-subagents` = off. + subagents: Option, /// Add the `codemode` tool: JS scripts that call the other tools (default false). codemode: Option, /// Capture the mouse for wheel scrolling (default true; false = terminal selection works without shift). @@ -236,6 +241,7 @@ impl Config { compact_at: o.compact_at.or(c.compact_at), max_tokens: o.max_tokens.or(c.max_tokens), explore_model: o.explore_model.or(c.explore_model), + subagents: o.subagents.or(c.subagents), codemode: o.codemode.or(c.codemode), mouse: o.mouse.or(c.mouse), remember_model: o.remember_model.or(c.remember_model), @@ -704,7 +710,9 @@ async fn main() -> Result<()> { ]; rows.extend(skill_rows); let mut specs = reg.specs(); - specs.push(hx_core::subagent::spec()); + if !cli.no_subagents && cfg.subagents != Some(false) { + specs.push(hx_core::subagent::spec()); + } specs.sort_by_key(|t| { std::cmp::Reverse(serde_json::to_string(t).map_or(0, |s| s.len())) }); @@ -1052,7 +1060,7 @@ async fn main() -> Result<()> { mgr.warm(probe).await; } trace("lens"); - { + if !cli.no_subagents && cfg.subagents != Some(false) { // children get the parent's tools as of now (no `task`, so no recursion) let mut general = agent.tools.clone(); general.retain(|n| n != "ask_user" && n != "exit_plan"); diff --git a/crates/hx-core/src/approve.rs b/crates/hx-core/src/approve.rs index ddcffed..91d9f98 100644 --- a/crates/hx-core/src/approve.rs +++ b/crates/hx-core/src/approve.rs @@ -42,7 +42,12 @@ pub fn question(tool: &str, input: &Value) -> Option { detail: s("file_path"), rule: String::new(), }), - "Grep" | "Glob" | "LS" | "TodoWrite" | "NotebookRead" | "Task" | "Agent" => None, + "Grep" | "Glob" | "LS" | "TodoWrite" | "NotebookRead" => None, + "Task" | "Agent" => Some(Request { + tool: "task".into(), + detail: format!("subagent: {}", s("description")), + rule: "task:claude".into(), + }), t if t.starts_with("mcp__hx__") => None, "WebFetch" => Some(crate::permit::request( "web_fetch", diff --git a/crates/hx-core/src/permit.rs b/crates/hx-core/src/permit.rs index 2d176ae..03bd2a4 100644 --- a/crates/hx-core/src/permit.rs +++ b/crates/hx-core/src/permit.rs @@ -198,7 +198,7 @@ pub fn needs_permit(tool: &str, args: &serde_json::Value) -> bool { match tool { "bash" => !readonly_cmd(a("command").trim()), "read" => secret(a("path")), - "web_fetch" => true, + "web_fetch" | "task" => true, _ => gated(tool), } } @@ -261,6 +261,25 @@ pub fn request(tool: &str, args: &serde_json::Value) -> Request { rule: format!("web:{host}"), }; } + if tool == "task" { + let kind = args["kind"].as_str().unwrap_or("explore"); + let ps: Vec<&str> = match args["prompts"].as_array() { + Some(a) => a.iter().filter_map(|v| v.as_str()).collect(), + None => vec![args["prompt"].as_str().unwrap_or_default()], + }; + let first: String = ps + .first() + .copied() + .unwrap_or_default() + .chars() + .take(120) + .collect(); + return Request { + tool: tool.into(), + detail: format!("{} {kind} subagent(s): {first}", ps.len()), + rule: format!("task:{kind}"), + }; + } if tool != "bash" { return Request { tool: tool.into(), @@ -467,6 +486,13 @@ mod tests { assert_eq!(bash("go test $(id)").rule, ""); assert_eq!(request("edit", &json!({"path": "a.rs"})).rule, ""); assert!(gated("bash") && !gated("read")); + let t = serde_json::json!({"prompts": ["a", "b"], "kind": "general"}); + assert!(needs_permit("task", &t)); + let r = request("task", &t); + assert_eq!( + (r.rule.as_str(), r.detail.starts_with("2 general")), + ("task:general", true) + ); } #[test] diff --git a/crates/hx-core/src/subagent.rs b/crates/hx-core/src/subagent.rs index e4f3376..64dd29b 100644 --- a/crates/hx-core/src/subagent.rs +++ b/crates/hx-core/src/subagent.rs @@ -283,7 +283,7 @@ impl Task { pub fn spec() -> ToolSpec { ToolSpec { name: "task".into(), - description: "Run a subagent in a fresh context; you get back only its final answer. kind=explore (default): read-only research on a cheaper model; use it for searching/reading that would fill your context (many files or >10k tokens). kind=general: same tools as you, may edit. The subagent sees nothing of this conversation: make every prompt self-contained. You are blocked until it answers, so a single task you then wait on only pays off when the search would put >10k tokens in your context; otherwise do it yourself. Prefer splitting work into 2+ independent subtasks: pass `prompts` (array) or several task calls in one turn, they run in parallel. Not for small lookups.".into(), + description: "Run a subagent in a fresh context; you get back only its final answer. The user is asked to approve every call: use it only when the user asked for subagents or parallel work, or when a search would clearly put >10k tokens in your context. Do ordinary discovery (read, grep, lsp, bash) yourself in this session. kind=explore (default): read-only research on a cheaper model. kind=general: same tools as you, may edit. The subagent sees nothing of this conversation: make every prompt self-contained. You are blocked until it answers. For 2+ independent subtasks pass `prompts` (array); they run in parallel.".into(), input_schema: json!({"type":"object","properties":{ "prompt":{"type":"string"}, "prompts":{"type":"array","items":{"type":"string"},"description":"several independent subtasks: one subagent each, run in parallel, answers returned numbered"}, -- 2.54.1