Repository navigation
Description
Overview
Analysis of the .opencode/agents/ (12 files, ~118 KB) and .opencode/commands/ (11 files, ~318 KB) directories reveals significant token waste from cross-file duplication, procedural logic described as prose, inline data tables, and agent boilerplate. Estimated total savings: 36,000–46,000 tokens (47–60%) across ~77,000 current tokens.
Current State
| Category | Files | Total Lines | Est. Tokens |
|---|---|---|---|
| Commands | 11 | 8,107 | ~60,000 |
| Agents | 12 | 2,267 | ~17,000 |
| Total | 23 | 10,374 | ~77,000 |
Key Findings
- Cross-command duplication (~30%): Session-resume guards, mandatory gate patterns, dispatch protocol, GitHub review posting, model name resolution, and shell injection prevention are copy-pasted across 3-6 files each.
- Procedural logic as prose (~20%): 115 deterministic procedures (~24,400 tokens) across 6 major command files — 62 invoke external CLIs, 27 do pure data transformation, 26 read config files. All are 100% deterministic with no creative judgment needed.
- Divisor agent boilerplate (~35% of agent tokens): All 5 Divisor agents share identical Prior Learnings, Source Documents, Output Format, Decision Criteria, and dual-mode explanation blocks.
- Inline data (~5%): Lookup tables, verdict mappings, path classifications, and schemas embedded as prose instead of deterministic lookups.
- Embedded subagent prompts:
uf.review-prcontains a ~500-line inline prompt that re-describes skills.
Approach: Plugin Tools vs. Skills vs. Scripts
Three extraction mechanisms, ordered by LLM removal:
| Mechanism | LLM Involvement | Best For |
|---|---|---|
| Skills | LLM still executes; saves tokens via dedup | Shared instructions requiring judgment |
| Plugin Tools | LLM calls tool, gets structured result; no interpretation | Deterministic procedures, config lookups, API operations |
| Superseded by plugin tools (typed I/O, testable, composable) |
Decision: Phase 2 scripts and Phase 3 config extraction are replaced by plugin tools in a new uf-workflow plugin. Plugin tools have full access to Node.js fs, BunShell, and the OpenCode client API — everything shell scripts can do, plus Zod-validated I/O, AbortSignal cancellation, and vitest testing.
Standard Result Envelope
All uf-workflow tools use a standard result shape:
type ToolSuccess<T> = {
status: "ok"
data?: T // query tools: the answer; side-effect tools: omitted or summary
}
type ToolFailure = {
status: "error"
message: string // human-readable, always present
retryable: boolean // can the agent try again?
code?: string // machine-readable error category
}
type ToolResult<T> = ToolSuccess<T> | ToolFailureOutput verbosity rules:
- Side-effect success: Minimal —
{ status: "ok" }or{ status: "ok", data: "3 labels applied" } - Query success: The answer only —
{ status: "ok", data: { family: "claude-opus-4" } } - Failure: Actionable detail — message, retryable flag, error code
Out of Scope
uf.init.mdconversion (deferred)
Phase 1: Skills + Agent Refactoring (Low Effort, High Impact)
Skills deduplicate shared instructions that require LLM judgment.
- Create divisor-common skill to extract shared Divisor agent boilerplate #660 — Create
divisor-commonskill (shared Divisor boilerplate) — ~2,000 tokens - Create session-resume skill to deduplicate guards and mandatory gates #661 — Create
session-resumeskill (guards + mandatory gates) — ~4,000-5,000 tokens - Extract review-pr subagent prompt into dedicated agent file #662 — Extract
review-prsubagent prompt into dedicated agent — ~4,000 tokens - Expand dispatch-advisor skill to cover full dispatch lifecycle #663 — Expand
dispatch-advisorskill (full dispatch lifecycle) — ~1,200 tokens - Create post_github_review plugin tool for shared PR review posting mechanics #664 — Create
github-review-postingskill — ~800 tokens
Phase 1 total: ~12,000–13,000 tokens saved
Phase 2: uf-workflow Plugin + Tools (Medium Effort, High Impact)
Plugin tools replace prose-described deterministic procedures. The LLM calls a tool and gets a structured result — no stdout parsing, no polling loops, no config interpretation.
Foundation
- Create uf-workflow plugin scaffold with standard result envelope #682 — Create
uf-workflowplugin scaffold with standard result envelope
GitHub API Tools
- Create resolve_model_name plugin tool for deterministic model name extraction #665 —
resolve_model_nametool — deterministic model family extraction (~500 tokens, 3 files) - Create wait_for_ci and check_mergeability plugin tools #666 —
wait_for_ci+check_mergeabilitytools — CI polling and merge status (~300 tokens) - Create ensure_labels and fetch_issue_comments plugin tools #669 —
ensure_labels+fetch_issue_commentstools — label management and comment pagination (~450 tokens) - Create create_fix_branch plugin tool for review-pr fix workflow #675 —
create_fix_branchtool — fix-branch workflow for review-pr (~350 tokens)
Workflow Tools
- Create generate_pr_body plugin tool for template-based PR body assembly #667 —
generate_pr_bodytool — template-based PR body assembly (~500 tokens, LLM still writes summary paragraph) - Create resolve_conflict plugin tool for conflict resolution execution #668 —
resolve_conflicttool — execute selected git conflict resolution strategy (~550 tokens) - Create list_convention_packs plugin tool (detect_resume_point shipped in #745) #670 —
detect_resume_point+list_convention_packstools — resumability detection and pack loading (~400 tokens)
Config Lookup Tools
- Create map_verdict plugin tool for verdict-to-GitHub-event mapping #671 —
map_verdicttool — verdict-to-GitHub-event mapping (replaces inline lookup tables) (~800 tokens) - Create resolve_domain_owner plugin tool for Divisor domain ownership lookup #672 —
resolve_domain_ownertool — Divisor agent domain ownership lookup (~250 tokens) - Create classify_paths plugin tool for deterministic path classification #673 —
classify_pathstool — user-facing path classification (~150 tokens)
Agent Executor (cross-plugin)
- Extract shared agent executor to lib and add deterministic dispatch_agent_run tool #680 — Extract shared agent executor to lib +
dispatch_agent_runtool in review-dispatch plugin
Phase 2 total: ~3,750+ tokens saved from prose, plus additional savings from LLM no longer reading/interpreting config files
Phase 3: Structural Cleanup (Low Effort)
- Deduplicate unleash exit checkpoint templates #674 — Deduplicate unleash exit checkpoint templates — ~350 tokens
Phase 3 total: ~350 tokens saved
Cross-Cutting Consolidation
Several procedures repeat across 3-5 command files. A single tool eliminates ALL instances:
| Pattern | Files Affected | Instances | Tool |
|---|---|---|---|
| Temp file → GH API POST → cleanup | finale, review-pr, review-council, triage-issue, address-feedback | 5+ | post_github_review in uf-workflow |
| PR metadata fetch | review-pr, review-council, address-feedback | 3 | fetch_pr_context (future) |
| Divisor agent discovery | review-pr, review-council, triage-issue | 3 | Already in plan_review_dispatch |
| Convention pack loading | review-pr, review-council | 2 | list_convention_packs |
| Model name extraction | finale, address-feedback, review-pr | 3 | resolve_model_name |
| CLI prereqs check | review-pr, triage-issue, address-feedback | 3 | check_cli_prereqs (future) |
Plugin Architecture
.opencode/plugins/
├── invoke-agent/ # Agent invocation (exists)
├── review-dispatch/ # Review planning + dispatch (exists, gains dispatch_agent_run from #680)
└── uf-workflow/ # NEW: deterministic UF workflow operations
└── index.ts # ~13 tools sharing BunShell + fs dependencies
Acceptance Criteria
- All Phase 1 stories completed
-
uf-workflowplugin created with standard result envelope - All Phase 2 tools implemented and tested
- Phase 3 cleanup completed
- No command file exceeds 800 lines (currently 6 files exceed this)
- No agent file contains duplicated boilerplate from other agents
- All deterministic procedures use plugin tools, not prose
- All tools follow standard result envelope (minimal success, detailed failure)
- Plugin tests pass (
make plugin-test)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
feat(plugins): extract uf-finale plugin tools for ~70% token reduction
feat(plugins): extract uf-finale plugin tools for ~70% token reduction
jflowers commentedon Oct 19, 2026
Tracker maintenance pass on the Phase 1–3 children (2026-10-19), applying the Router Pattern direction from #716 retroactively:
normalize_model_name(feat(plugins): extract uf-finale plugin tools for ~70% token reduction #711, adopted in refactor(commands): resolve model attribution via normalize_model_name #733)format_unleash_exitcode renderers (feat(workflow): migrate deterministic uf.unleash procedures to plugin tools #745)list_convention_packsonly —detect_resume_pointshipped asuf_unleash_detect_resume(feat(workflow): migrate deterministic uf.unleash procedures to plugin tools #745)post_github_reviewplugin tool (the posting chain is deterministic once body + gate decision exist)Phase 1 skills #660, #661, #663 remain correctly scoped as skills — they deduplicate judgment-bearing instructions, which is the right mechanism for those.