Skip to content

Harness TS ​

OpenCode-Style Terminal Agent Harness · 30-Day Tutorial ​

Project Status: D030 / 30 · v0.1.0 · MIT
Technology Stack: TypeScript · Bun · OpenAI-compatible API · MCP stdio
Study Label: OpenCode-clone; public codename harness-ts.

Harness TS studies how OpenCode's terminal Agent works and implements it from scratch as a clean-room project using TypeScript + Bun. The project covers Providers, the Agent Loop, tool permissions, sessions, MCP, terminal rendering, and release acceptance.

← Back to Series Overview · View Source Code · Upstream OpenCode

MVP Features ​

Provider and Agent Loop ​

  • OpenAI-compatible Chat Completions and SSE.
  • Incremental tool-call parsing and the Agent Loop.
  • Retries for 429/5xx responses, Retry-After handling, and retry boundaries after streaming responses.
  • Debug Trace, Provider event logging, and secret redaction.
  • Multiple Provider Profiles and CLI --profile selection.

Tools and Permissions ​

  • Three basic tools: Bash, Read, and Edit.
  • Tool execution timeouts, cancellation, non-zero exits, and output truncation.
  • Ask/Allow/Deny permission model and path Glob rules.
  • Diff previews, TTY/Non-TTY rendering, and Spinner.
  • Tool errors are fed back to the Agent so it can correct subsequent actions based on failures.

Sessions and Context ​

  • JSONL session persistence, Resume, and Fork.
  • Atomic writes and temporary-file cleanup.
  • Compaction and 20-round Soak validation.
  • CLI Chat, Run, New, Resume, and Sessions operation modes.

MCP stdio ​

  • Initialize handshake, tool discovery, and tool invocation.
  • Request timeouts, process exits, and cancellation handling.
  • Standard-output noise tolerance and Pending request cleanup.

30-Day Learning Focus ​

StageMain Topics
Getting StartedProvider, messages, streaming responses, Agent Loop, and tool contracts
Tools and PermissionsBash/Read/Edit, path rules, approvals, and error recovery
SessionsJSONL, Resume, Fork, atomic writes, and Compaction
InteroperabilityMCP stdio lifecycle, timeouts, and cancellation
Terminal ExperienceTTY rendering, Spinner, Diff, and CLI modes
ReleaseRetries, Trace redaction, Profiles, Soak, E2E, and documentation

Acceptance Record ​

The project retrospective records 206 offline tests, TypeScript type checking, coverage checks, daily evidence, and D030 release acceptance. Tests and evidence validate the MVP contracts; refer to the v0.1.0 tag and repository documentation for the specific baseline.

Explicitly Outside the MVP Scope ​

Production-grade OAuth, a plugin marketplace, LSP, SQL, multi-tenant isolation, a desktop client, and a complete model catalog are outside the current scope. The project is suitable as a foundation for learning, experimentation, and local OpenAI-compatible Endpoints; it does not claim production-grade security.

Clean Room and Licensing ​

The research pin is OpenCode v1.19.6. The project records research notes, a Clean-room Log, and third-party attributions. It studies behavior and interfaces only, without copying upstream code; the project's own implementation is released under MIT.

Keep building. Stay curious.