storkit: merge 343_refactor_abstract_agent_runtime_to_support_non_claude_code_backends

This commit is contained in:
Dave
2026-03-20 22:05:25 +00:00
parent 52c5344ce5
commit 4344081b54
6 changed files with 307 additions and 22 deletions

View File

@@ -17,6 +17,7 @@ use super::{
AgentEvent, AgentInfo, AgentStatus, CompletionReport, PipelineStage, agent_config_stage,
pipeline_stage,
};
use super::runtime::{AgentRuntime, ClaudeCodeRuntime, RuntimeContext};
/// Build the composite key used to track agents in the pool.
fn composite_key(story_id: &str, agent_name: &str) -> String {
@@ -513,25 +514,38 @@ impl AgentPool {
});
Self::notify_agent_state_changed(&watcher_tx_clone);
// Step 4: launch the agent process.
match super::pty::run_agent_pty_streaming(
&sid,
&aname,
&command,
&args,
&prompt,
&wt_path_str,
&tx_clone,
&log_clone,
log_writer_clone,
inactivity_timeout_secs,
child_killers_clone,
)
.await
{
Ok(pty_result) => {
// Step 4: launch the agent process via the configured runtime.
let runtime_name = config_clone
.find_agent(&aname)
.and_then(|a| a.runtime.as_deref())
.unwrap_or("claude-code");
let run_result = match runtime_name {
"claude-code" => {
let runtime = ClaudeCodeRuntime::new(child_killers_clone.clone());
let ctx = RuntimeContext {
story_id: sid.clone(),
agent_name: aname.clone(),
command,
args,
prompt,
cwd: wt_path_str,
inactivity_timeout_secs,
};
runtime
.start(ctx, tx_clone.clone(), log_clone.clone(), log_writer_clone)
.await
}
other => Err(format!(
"Unknown agent runtime '{other}'; check the 'runtime' field in project.toml. \
Supported: 'claude-code'"
)),
};
match run_result {
Ok(result) => {
// Persist token usage if the agent reported it.
if let Some(ref usage) = pty_result.token_usage
if let Some(ref usage) = result.token_usage
&& let Ok(agents) = agents_ref.lock()
&& let Some(agent) = agents.get(&key_clone)
&& let Some(ref pr) = agent.project_root
@@ -557,7 +571,7 @@ impl AgentPool {
port_for_task,
&sid,
&aname,
pty_result.session_id,
result.session_id,
watcher_tx_clone.clone(),
)
.await;