subagent tool: add option to run in a different directory

This commit is contained in:
damocles 2026-09-11 21:40:01 +02:00
commit cfddb1bd40
2 changed files with 61 additions and 13 deletions

View file

@ -37,6 +37,15 @@ struct StartArgs {
/// belongs in `prompt_file`, not here.
#[serde(default = "default_trigger")]
trigger: String,
/// Working directory for the subagent's session — e.g. a git worktree
/// you've already prepared for it, so a parallel batch of subagents
/// never race on the same working tree. Must exist. Omit to inherit
/// this daemon's own working directory (today's default). Claude
/// derives its per-project session storage from this path, so
/// `continue`/`status` against this name must pass this exact same
/// `dir` again to find the session — see those tools' own docs.
#[serde(default)]
dir: Option<String>,
}
fn default_trigger() -> String {
@ -53,12 +62,22 @@ struct ContinueArgs {
/// default — this does not have to match whatever model `start` used.
#[serde(default)]
model: Option<String>,
/// The same `dir` given at `start`, if any — sessions are stored keyed
/// by directory, so a different (or omitted) `dir` here looks in the
/// wrong place and reports no session found under `name` even though
/// one exists.
#[serde(default)]
dir: Option<String>,
}
#[derive(Debug, Deserialize, JsonSchema)]
struct StatusArgs {
/// The subagent name to check.
name: String,
/// The same `dir` given at `start`, if any — see `continue`'s `dir` doc
/// for why this has to match.
#[serde(default)]
dir: Option<String>,
}
#[derive(Debug, Deserialize, JsonSchema)]
@ -95,6 +114,7 @@ impl SubagentMcp {
args.model,
&args.prompt_file,
args.trigger,
args.dir.as_deref(),
) {
Ok(msg) => msg,
Err(e) => format!("start error: {e:#}"),
@ -110,7 +130,13 @@ impl SubagentMcp {
`start`. Refuses a name with no session on disk at all, or one already running."
)]
fn r#continue(&self, Parameters(args): Parameters<ContinueArgs>) -> String {
match session::continue_(&self.state, &args.name, args.prompt, args.model) {
match session::continue_(
&self.state,
&args.name,
args.prompt,
args.model,
args.dir.as_deref(),
) {
Ok(msg) => msg,
Err(e) => format!("continue error: {e:#}"),
}
@ -138,7 +164,7 @@ impl SubagentMcp {
`continue` to give it another turn), and no such session at all."
)]
fn status(&self, Parameters(args): Parameters<StatusArgs>) -> String {
match session::status(&self.state, &args.name) {
match session::status(&self.state, &args.name, args.dir.as_deref()) {
Ok(msg) => msg,
Err(e) => format!("status error: {e:#}"),
}