Skip to content

Conversation

@betterclever
Copy link
Contributor

@betterclever betterclever commented Jan 29, 2026

ENG-100 — OpenCode Agent Component

Summary

  • Add OpenCode agent component to run a non-interactive investigation loop in Docker.
  • Generate opencode.json wired to the MCP gateway for tool calls.
  • Produce a markdown report output from the agent.
  • Stream terminal output for execution visibility.

What changed

  • New OpenCode agent component definition under worker/src/components/ai/opencode.ts.
  • Docker execution flow to set up workspace, write configs/prompts, and run OpenCode.
  • Gateway token resolution + MCP config injection for agent tool access.
  • Output wiring for report and logs.

How it works (high level)

  1. Create /workspace and context/task files.
  2. Build opencode.json with MCP gateway URL + token.
  3. Write investigator prompt template.
  4. Run OpenCode in non-interactive mode.
  5. Return markdown report + terminal stream.

Testing

  • Not run (please run relevant workflow / E2E manually).

Notes

  • PR base: ENG-132.
  • Stacked with ENG-101/102.

Refs: ENG-100

Adds the new OpenCode agent component with configurable 'providerConfig'. Refactors common gateway token logic into a shared 'utils.ts' used by both AI Agent and OpenCode.

Signed-off-by: betterclever <[email protected]>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a03de01336

ℹ️ 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".

Comment on lines 226 to 231
env: {
// OpenCode might need API keys.
// If the definition includes an API Key in the 'model' contract, we should pass it.
...(model?.apiKey
? { OPENAI_API_KEY: model.apiKey, ANTHROPIC_API_KEY: model.apiKey }
: {}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Forward API keys for non-OpenAI providers

The component accepts the shared LLMProviderSchema, which includes gemini and openrouter providers, but the container environment only forwards OPENAI_API_KEY/ANTHROPIC_API_KEY. When a user selects gemini or openrouter and supplies an API key in the model input, no provider-specific key is passed into the OpenCode container, so authentication will fail unless they manually duplicate it via providerConfig. This makes those providers effectively unusable despite being allowed by the contract.

Useful? React with 👍 / 👎.

betterclever and others added 18 commits January 30, 2026 14:13
- Add zai-coding-plan to LLMProviderSchema with apiKey and modelId support
- Fix OpenCode component to use proper model format (provider/modelId)
- Configure Z.AI provider with apiKey in provider.options
- Fix MCP server config to use type: "remote" instead of transport: "http"
- Remove unused env var API key handling in favor of provider config

Co-Authored-By: Claude <[email protected]>
Signed-off-by: betterclever <[email protected]>
- Use sh -c with properly quoted prompt string to handle multi-word prompts
- Escape single quotes in prompt to prevent shell injection
- Add current-state.md documenting investigation and findings
- Add opencode E2E test

Co-Authored-By: Claude <[email protected]>
Signed-off-by: betterclever <[email protected]>
…er script

- Remove --quiet flag (doesn't exist in opencode 1.1.34), use --log-level ERROR
- Use wrapper script approach to handle prompt file reading inside container
- Set entrypoint to /bin/sh to override default opencode entrypoint
- Fix test assertions to check outputSummary.report instead of output.report
- Update current-state.md with resolution details

E2E tests now passing: 2 pass, 0 fail

Co-Authored-By: Claude <[email protected]>
Signed-off-by: betterclever <[email protected]>
…ided

When a custom systemPrompt is provided, the task was not being included
because the {{TASK}} placeholder only exists in the default template.

Now the task is always appended to ensure OpenCode receives the full prompt.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: betterclever <[email protected]>
- Add optional baseUrl and headers properties to zai-coding-plan provider
- Add zai-coding-plan to ModelProvider type in ai-agent.ts
- This fixes TypeScript build errors when using the new provider

Co-Authored-By: Claude <[email protected]>
Signed-off-by: betterclever <[email protected]>
… d.ts files

- Remove emitDeclarationOnly: true from worker/tsconfig.json
- This allows TypeScript to emit both .js and .d.ts files
- Fixes backend typecheck errors when importing from @shipsec/studio-worker/workflows
- The worker still uses source files directly via bun, so .js files don't interfere

Co-Authored-By: Claude <[email protected]>
Signed-off-by: betterclever <[email protected]>
- Rename unused 'error' to '_error' in catch block to satisfy ESLint
- Apply code formatting from linter to opencode.ts

Co-Authored-By: Claude <[email protected]>
Signed-off-by: betterclever <[email protected]>
Signed-off-by: betterclever <[email protected]>
feat: MCP AWS servers and proxy (ENG-103)

Consolidating the work in 1 PR from the stack
…nt-ui

feat: tool mode UI + agent orchestration (ENG-101/102)

Consolidating the work in one PR
@betterclever betterclever merged commit 561512b into eng-132/tool-mode-orchestration Jan 30, 2026
2 of 3 checks passed
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