Skip to content

Add OpenCode agent support#341

Open
adrianmg wants to merge 3 commits intoentireio:mainfrom
adrianmg:adrianmg/opencode-support
Open

Add OpenCode agent support#341
adrianmg wants to merge 3 commits intoentireio:mainfrom
adrianmg:adrianmg/opencode-support

Conversation

@adrianmg
Copy link

@adrianmg adrianmg commented Feb 15, 2026

Summary

Adds OpenCode as a third supported coding agent alongside Claude Code and Gemini CLI.

  • New opencode agent package with embedded TypeScript plugin, hook install/uninstall, JSONL transcript parsing, and token usage calculation
  • Hook handlers for all 4 lifecycle events (session-start, user-prompt-submit, stop, task)
  • Full unit tests (61 tests) + integration tests (23 tests) across both strategies
  • Refactored removeAgentHooks() from hardcoded agent list to registry-based iteration
CleanShot.2026-02-15.at.00.45.16.mp4
image

How it works

Users enable OpenCode support with:

entire enable --agent opencode

This installs .opencode/plugins/entire.ts — a TypeScript plugin that hooks into OpenCode's plugin API and calls entire hooks opencode <event> for each lifecycle event. The plugin exports the session transcript as JSONL to a temp directory for checkpoint metadata extraction.

Key design decisions

  • Plugin is go:embed'd into the Go binary and written to .opencode/plugins/entire.ts during InstallHooks
  • Transcript handling: OpenCode doesn't store JSONL on disk like Claude Code does. The plugin writes transcripts to os.tmpdir()/entire-opencode/<sessionId>.jsonl using OpenCode's SDK export API
  • Stop handler follows Gemini's handleAfterAgent pattern (not commitWithMetadata)
  • entire enable default unchanged — still defaults to Claude Code. OpenCode requires --agent opencode
  • Binary resolution: Plugin resolves the entire binary via ENTIRE_BIN env var (set by hook handlers) with fallback to PATH lookup

Files

Area Files
Agent package cmd/entire/cli/agent/opencode/ (8 files)
Hook handlers hooks_opencode_handlers.go, hook_registry.go
State capture state.go (CaptureOpencodePrePromptState)
Condensation strategy/manual_commit_condensation.go
Integration tests integration_test/ (4 files)
Setup/wiring setup.go, hooks_cmd.go, registry.go

Testing

  • 61 unit tests covering agent methods, hook install/uninstall, plugin API contract assertions, transcript parsing, and token usage calculation
  • 23 integration tests covering enable/disable, hook lifecycle, checkpoint save/rewind, condensation, and multi-session workflows across both strategies
  • All tests pass with -race flag

@adrianmg adrianmg requested a review from a team as a code owner February 15, 2026 08:36
Copilot AI review requested due to automatic review settings February 15, 2026 08:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds OpenCode as a third supported AI coding agent alongside Claude Code and Gemini CLI. The implementation follows the established agent abstraction pattern and includes comprehensive testing and documentation.

Changes:

  • New OpenCode agent package with TypeScript plugin, hook handlers, transcript parsing, and token usage calculation
  • Hook lifecycle handlers for session-start, stop, task-start, and task-complete events
  • Refactored agent hook management from hardcoded checks to registry-based iteration in setup.go

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/entire/cli/agent/opencode/*.go OpenCode agent implementation (hooks, transcript parsing, types)
cmd/entire/cli/agent/opencode/entire.ts Embedded TypeScript plugin for OpenCode's plugin system
cmd/entire/cli/hooks_opencode_handlers.go Hook lifecycle event handlers for OpenCode sessions
cmd/entire/cli/hook_registry.go Hook registration for OpenCode events
cmd/entire/cli/state.go Pre-prompt state capture for OpenCode JSONL transcripts
cmd/entire/cli/strategy/manual_commit_condensation.go OpenCode-specific prompt extraction and token usage
cmd/entire/cli/setup.go Refactored agent hook management to use registry pattern
cmd/entire/cli/summarize/summarize.go OpenCode condensed transcript placeholder (not yet implemented)
cmd/entire/cli/integration_test/*.go Comprehensive integration tests for OpenCode workflows
README.md Documentation updates for OpenCode support

Comment on lines +22 to +34
// Resolve the entire binary path once at load time.
// Supports ENTIRE_BIN env var override for development/testing.
function resolveBinary(): string {
const envBin = process.env.ENTIRE_BIN;
if (envBin) return envBin;
try {
return execSync("which entire", { encoding: "utf-8" }).trim();
} catch {
return "entire";
}
}

const entireBin = resolveBinary();
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The PR description states that the ENTIRE_BIN environment variable is "set by hook handlers", but there's no code in hooks_opencode_handlers.go or the hook execution path that actually sets this variable. The resolveBinary function will fall back to using 'which entire' or PATH lookup, which works fine, but the PR description is misleading. Either the description should be corrected to say ENTIRE_BIN is optional (with fallback to PATH), or the hook handlers should actually set this variable for consistency.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant