From d0ec1eebd7a656989e47a06f05994f64840e0f5b Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 20 Mar 2026 09:10:42 +0000 Subject: [PATCH] story-kit: create 343_refactor_abstract_agent_runtime_to_support_non_claude_code_backends --- ...ime_to_support_non_claude_code_backends.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .story_kit/work/1_backlog/343_refactor_abstract_agent_runtime_to_support_non_claude_code_backends.md diff --git a/.story_kit/work/1_backlog/343_refactor_abstract_agent_runtime_to_support_non_claude_code_backends.md b/.story_kit/work/1_backlog/343_refactor_abstract_agent_runtime_to_support_non_claude_code_backends.md new file mode 100644 index 0000000..54fb3bb --- /dev/null +++ b/.story_kit/work/1_backlog/343_refactor_abstract_agent_runtime_to_support_non_claude_code_backends.md @@ -0,0 +1,40 @@ +--- +name: "Abstract agent runtime to support non-Claude-Code backends" +--- + +# Refactor 343: Abstract agent runtime to support non-Claude-Code backends + +## Current State + +- TBD + +## Desired State + +Currently agent spawning is tightly coupled to Claude Code CLI — agents are spawned as PTY processes running the `claude` binary. To support ChatGPT and Gemini as agent backends, we need to abstract the agent runtime. + +The agent pool currently does: +1. Spawn `claude` CLI process via portable-pty +2. Stream JSON events from stdout +3. Parse tool calls, text output, thinking traces +4. Wait for process exit, run gates + +This needs to become a trait so different backends can be plugged in: +- Claude Code (existing) — spawns `claude` CLI, parses JSON stream +- OpenAI API — calls ChatGPT via API with tool definitions, manages conversation loop +- Gemini API — calls Gemini via API with tool definitions, manages conversation loop + +The key abstraction is: an agent runtime takes a prompt + tools and produces a stream of events (text output, tool calls, completion). The existing PTY/Claude Code logic becomes one implementation of this trait. + +## Acceptance Criteria + +- [ ] Define an AgentRuntime trait with methods for: start, stream_events, stop, get_status +- [ ] ClaudeCodeRuntime implements the trait using existing PTY spawning logic +- [ ] Agent pool uses the trait instead of directly spawning Claude Code +- [ ] Runtime selection is configurable per agent in project.toml (e.g. runtime = 'claude-code') +- [ ] All existing Claude Code agent functionality preserved +- [ ] Event stream format is runtime-agnostic (text, tool_call, thinking, done) +- [ ] Token usage tracking works across runtimes + +## Out of Scope + +- TBD