Overview
Three core subsystems:- CLI + TUI — User interface (argument parsing, interactive browser)
- Registry + Installer — Agent catalog and file management
- Discovery Pipeline — Upstream sync and quality validation (manual dispatch)
Components
1. CLI (bin/cli.mjs)
Responsibility: Parse arguments, route commands. Supported commands:install [agent]— Install one or more agentsuninstall [agent]— Remove agentslist— Show all agents by categorylist --packs— Show predefined packssearch <query>— Fuzzy search agentsupdate— Reinstall outdated agents (hash mismatch)verify— Check lock file integrityrehash— Rebuild lock from disktui— Launch interactive browser
- Zero dependencies (Node.js 20+ stdlib only)
- Multi-value flags:
--pack backend,devopsor--pack backend --pack devops - Permission flags:
--permissions,--yolo,--permission-override - Dry-run mode:
--dry-run - Force overwrite:
--force
2. TUI (src/tui/)
Responsibility: Interactive agent browser. Modules:| Module | Responsibility |
|---|---|
index.mjs | Lifecycle orchestrator, signal handling (SIGINT, SIGWINCH), main loop |
screen.mjs | Terminal I/O (raw mode, ANSI flush, resize, input) |
input.mjs | Key parser (raw bytes → ~20 Action types) |
state.mjs | State machine (browse, search, confirm, installing, pack_detail, done, quit) |
renderer.mjs | Frame builder (state → ANSI string) |
ansi.mjs | ANSI codes, colors, box drawing, category/tab palettes |
- Auto-detect TTY (falls back to
--helpif stdin not a terminal) - Smooth scrolling (viewport, cursor tracking)
- Real-time search filtering
- Graceful signal handling (SIGINT = quit, SIGWINCH = resize)
- Atomic state updates (no partial renders)
3. Registry (src/registry.mjs)
Responsibility: Load and validatemanifest.json, expose query helpers.
Manifest structure:
- Agent names match
SAFE_NAME_RE(alphanumeric, hyphens, underscores) - Categories and packs reference only valid agents
- No duplicate agent names
- Required fields present (
name,category,description,mode)
4. Installer (src/installer.mjs)
Responsibility: Download agents from GitHub raw and write to disk. Flow:- Resolve agent URL:
https://raw.githubusercontent.com/<owner>/<repo>/<ref>/agents/<category>/<name>.md - Download via HTTPS (Node.js
httpsmodule) - Apply permission modifications if
--permissionsor--permission-overrideprovided - Write to
.opencode/agents/<category>/<name>.md - Record SHA-256 hash in lock file
- Host allowlist (GitHub raw only)
- Path traversal prevention (no
.., no absolute paths) - HTTPS required
- SHA-256 integrity tracking (post-install)
5. Lock System (src/lock.mjs)
Responsibility: Track installed agent hashes, detect modifications. See Lock System for full details. Key functions:6. Permission System (src/permissions/)
Responsibility: Resolve and apply permission presets/overrides. See Permissions for full details. Modules:| Module | Responsibility |
|---|---|
presets.mjs | Define 4 presets (strict, balanced, permissive, yolo) |
resolve.mjs | Layered precedence (CLI > saved > built-in) |
cli.mjs | Parse permission flags (--permissions, --yolo, --permission-override) |
persistence.mjs | Load/save preferences to ~/.config/opencode/agent-permissions.json |
warnings.mjs | Display security warnings for YOLO mode |
writer.mjs | Modify agent frontmatter with resolved permissions |
7. Discovery Pipeline (scripts/)
Responsibility: Manual tools for upstream agent evaluation. Scripts:| Script | Purpose |
|---|---|
sync-agents.py | Fetch agents from upstream, convert tools: → permission: |
sync_common.py | HTTP utilities (ETag cache, frontmatter parser) |
update-manifest.py | Merge sync manifest into root manifest |
quality_scorer.py | 8-dimension quality scoring |
generate_readme_scores.py | Regenerate README score tables |
- Trigger via GitHub Actions
workflow_dispatch - Parameters:
tier(core/extended/all),force,dry_run sync-agents.pyfetches upstream agents- Convert
tools:topermission:(CURATED_AGENTS dict for known agents) update-manifest.pymerges into root manifest- Prefix
[NEEDS_REVIEW]for new agents - Validate (tests, frontmatter, manifest coherence)
- If not dry_run: commit to
sync/agents-latest, create PR
- Agents not in
CURATED_AGENTSgetUNKNOWN_PERMISSIONS - Actions pinned by SHA (not mutable tags)
- Path traversal validation
- ETag-based HTTP caching
Data Flow
Install Command
TUI Session
Verify Command
File Structure
Module Dependencies
Zero npm dependencies. All modules use Node.js 20+ stdlib:fs/fs/promises— File I/Opath— Path manipulationcrypto— SHA-256 hashinghttps— Agent downloadsreadline— TUI raw modeprocess— Signals, stdin/stdout
Configuration
Manifest Path
Default:manifest.json in repo root.
Override via OPENCODE_AGENTS_MANIFEST env var (for testing).
Install Directory
Default:.opencode/agents/ (from manifest base_path).
Can be overridden in manifest:
Permission Preferences
Stored in~/.config/opencode/agent-permissions.json:
Testing
893 tests across Node.js and Python:- 560 JS tests (CLI, TUI, lock, registry, installer)
- 23 TypeScript tests (plugin)
- 310 Python tests (sync scripts, quality scorer)
CI/CD
Four parallel jobs on every push/PR:- test — Python tests (3.10, 3.12, 3.13)
- test-cli — Node tests (20, 22, 23)
- lint — Python/Node syntax, shellcheck, frontmatter, manifest
- validate-agents — Manifest coherence, deprecated fields
Performance
CLI startup: < 50ms (zero dependencies) TUI rendering: 60+ FPS on modern terminals Install speed: Network-bound (GitHub raw download) Manifest load: < 5ms (cached after first read)Related
- Permissions — Permission system deep dive
- Lock System — Integrity verification
- Quality Scoring — Agent quality metrics