Define FactoryAgent interface and OpenRouter integration (CS-10476)#4229
Define FactoryAgent interface and OpenRouter integration (CS-10476)#4229
Conversation
Implement the core FactoryAgent interface that decouples the orchestration loop from any specific LLM. This is the foundational ticket for the software factory execution loop. - Define types: FactoryAgentConfig, AgentContext, AgentAction, ResolvedSkill, ToolManifest, TestResult, ToolResult, and placeholder card types - Implement OpenRouterFactoryAgent with dual-path routing: - Direct path via OPENROUTER_API_KEY env var (simplest for local dev/CI) - Proxy path via realm server _request-forward (production, with billing) - Env var takes precedence over config over proxy - Implement MockFactoryAgent for deterministic testing - Add resolveFactoryModel() with CLI > env > FACTORY_DEFAULT_MODEL fallback - Add action validation, response parsing with markdown fence stripping - Add retry-once with error correction on malformed LLM responses - Add smoke-test script (pnpm factory:agent-smoke) for manual verification - 42 tests: unit tests + integration tests with mock HTTP servers Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5759f0f53f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Introduces a new “FactoryAgent” abstraction in packages/software-factory and provides an OpenRouter-backed implementation (with direct-key and realm-server-proxy routing), plus a mock agent and new unit/integration tests to validate parsing, validation, and request routing.
Changes:
- Added
FactoryAgenttypes/utilities (action validation + response parsing) andOpenRouterFactoryAgent/MockFactoryAgent. - Added a CLI smoke-test script for manual end-to-end verification against OpenRouter.
- Added unit + integration tests (including local HTTP stubs) and wired them into the test index.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/software-factory/scripts/lib/factory-agent.ts | Defines core agent types, action parsing/validation, OpenRouter implementation (direct/proxy), and mock agent. |
| packages/software-factory/scripts/factory-agent-smoke.ts | Adds a manual CLI smoke test for exercising OpenRouterFactoryAgent.plan(). |
| packages/software-factory/tests/factory-agent.test.ts | Adds unit tests for action validation, response parsing, model resolution, and request path selection. |
| packages/software-factory/tests/factory-agent.integration.test.ts | Adds integration tests using local HTTP servers for both proxy and direct call paths (including retry behavior). |
| packages/software-factory/tests/index.ts | Registers the new agent test modules. |
| packages/software-factory/package.json | Adds factory:agent-smoke script entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix all prettier and qunit lint errors - Trim and treat blank OPENROUTER_API_KEY as missing (avoids bypassing proxy with empty env var in CI) - Pass authorization through as-is to avoid Bearer Bearer double-prefix - Use new URL() for proxy URL construction (safe without trailing slash) - Reject non-object toolArgs in validation instead of silently dropping - Add tests for blank API key handling and invalid toolArgs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ryagent-interface-and-openrouter-integration-v2 # Conflicts: # packages/software-factory/tests/index.ts
I confirmed I’m on 6205d52 |
pnpm passes '--' through to ts-node which forwards it to the script, so process.argv contains ['--', '--realm-server-url', ...]. parseArgs with strict: true rejects this. Strip the leading '--' like the factory-entrypoint already does. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Fixed in dcea592 -- the Verified locally: |
The -- separator is not needed since pnpm doesn't consume --realm-server-url or --model. The script still strips a leading -- defensively in case users include it out of habit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
FactoryAgentinterface and types (AgentContext,AgentAction,ToolManifest,TestResult, etc.) that decouple the orchestration loop from any specific LLMOpenRouterFactoryAgentwith dual-path routing: direct API key (local dev) or realm server_request-forwardproxy (production with billing)MockFactoryAgentfor deterministic testingTry it out
After checking out this branch, you can verify the full round-trip to an LLM:
Expected output:
The lines between
[and]are the rawAgentAction[]returned by the LLM — the exact actions, file paths, and content will be different every time since it's a real model response. What matters is:type(one of:create_file,update_file,create_test,update_test,invoke_tool,done, etc.)Run the tests:
cd packages/software-factory pnpm test:nodeTest plan
tsc --noEmit)🤖 Generated with Claude Code
Linear: https://linear.app/cardstack/issue/CS-10476