Skip to content

Conversation

@rothnic
Copy link

@rothnic rothnic commented Dec 4, 2025

Summary

This PR enhances OpenCode integration in CodeMachine with two major features:

1. Agent Field for Workflow Steps

Adds agent field to workflow step configuration, enabling steps to specify which OpenCode agent to use via the --agent flag.

2. Consolidated Server Mode (Experimental)

Enables workflow steps to share a single OpenCode server instance, avoiding MCP cold boot times between steps.

New capabilities:

  • startOpenCodeServer() - starts server on random port with health polling
  • attachToExternalServer() - connects to existing external server
  • checkServerHealth() / listServerAgents() - server introspection
  • --attach flag for opencode run command
  • --opencode-server / --opencode-attach CLI flags for codemachine start
  • Automatic server lifecycle in workflow execution (start, inject URLs, cleanup)

CLI Usage:

# Start consolidated server (experimental)
codemachine start --opencode-server

# Attach to existing external server
codemachine start --opencode-attach http://localhost:4096

Files Changed

File Change
src/workflows/templates/types.ts Added agent, attach, opencodeServer, opencodeAttach fields
src/infra/engines/core/types.ts Added agent, attach to EngineRunOptions
src/agents/runner/runner.ts Added agent, attach to ExecuteAgentOptions
src/infra/engines/providers/opencode/execution/server.ts NEW - Server lifecycle management
src/infra/engines/providers/opencode/execution/commands.ts Added attach option, buildOpenCodeServeCommand()
src/infra/engines/providers/opencode/execution/runner.ts Added attach option passthrough
src/workflows/execution/step.ts Passes agent and attach to executeAgent()
src/workflows/execution/workflow.ts Full server lifecycle integration
src/cli/commands/start.command.ts Added --opencode-server and --opencode-attach flags
tests/integration/opencode/server.test.ts NEW - Integration tests

Testing

  • All existing tests pass (215 pass, 26 skip)
  • New integration tests for server lifecycle (requires OpenCode CLI)
  • Type checking passes

Enables workflow step definitions to specify which OpenCode agent configuration
to use via the --agent flag. The infrastructure for --agent was already in place
in the OpenCode executor layer, this change plumbs it through from workflows.

Changes:
- Add agent?: string to ModuleStep (workflow step config)
- Add agent?: string to EngineRunOptions (engine interface)
- Add agent?: string to ExecuteAgentOptions (runner interface)
- Pass step.agent through executeStep() -> executeAgent() -> engine.run()

The agent name flows: workflow.js step.agent -> executeStep() -> executeAgent() -> engine.run() -> runOpenCode() -> buildOpenCodeRunCommand() -> 'opencode run --agent <name>'
Adds server lifecycle management to enable workflow steps to share a single
OpenCode server instance, avoiding MCP cold boot times between steps.

New features:
- startOpenCodeServer() - starts server on random port with health polling
- attachToExternalServer() - connects to existing external server
- checkServerHealth() / listServerAgents() - server introspection
- --attach flag for opencode run command
- --opencode-server / --opencode-attach CLI flags for codemachine start
- Automatic server lifecycle in workflow execution (start, inject URLs, cleanup)

Integration tests included for command building, server lifecycle, and
external server attachment.
- Add project-first template resolution: check .codemachine/ before package templates
- Support inline prompt field as alternative to promptPath in workflow steps
- Fix empty memory content crashes in runner and trigger modules
- Update ModuleStep type to make promptPath optional when prompt is provided
- Update validator to accept either promptPath or prompt field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants