|
1 | 1 | # PROJECT KNOWLEDGE BASE |
2 | 2 |
|
3 | | -**Generated:** 2026-02-21 21:18:51 UTC+09:00 |
4 | | -**Commit:** N/A (repository has no commits yet) |
5 | | -**Branch:** master (unborn) |
| 3 | +**Updated:** 2026-02-25 |
| 4 | +**Version:** 0.1.1 (npm published) |
| 5 | +**Branch:** master |
6 | 6 |
|
7 | 7 | ## OVERVIEW |
8 | | -Reference-only repository for OpenCode HUD architecture/planning. Contains analysis docs for OpenCode plugin surfaces, oh-my-opencode layering, and a phased universal HUD implementation plan. |
| 8 | +Real-time usage HUD plugin for OpenCode CLI. Shows provider API utilization, context tokens, cost, and agent info as a dim blockquote appended to assistant output. |
9 | 9 |
|
10 | 10 | ## STRUCTURE |
11 | 11 | ```text |
12 | 12 | ./ |
13 | | -├── OPENCODE_ARCHITECTURE_ANALYSIS.md # OpenCode internals, hook/event/output constraints |
14 | | -├── OH_MY_OPENCODE_ARCHITECTURE_ANALYSIS.md # oh-my-opencode composition and reusable patterns |
15 | | -├── OPENCODE_HUD_UNIVERSAL_PLAN.md # original universal HUD plan (baseline) |
16 | | -├── OPENCODE_HUD_UNIVERSAL_PLAN_VNEXT.md # strengthened vNext plan with gates/controls |
17 | | -└── OPENCODE_HUD_IMPLEMENTATION_ISSUES.md # phase-grouped issue breakdown (task-level) |
| 13 | +├── src/ |
| 14 | +│ ├── plugin.ts # Main plugin — hooks, usage line builder, output augmentation |
| 15 | +│ ├── index.ts # Default export |
| 16 | +│ ├── api.ts # Public API re-exports |
| 17 | +│ ├── config/index.ts # HUD profiles and config types |
| 18 | +│ ├── model-registry.ts # Model metadata, context limits, cost rates |
| 19 | +│ ├── cost-calculator.ts # Per-message cost resolution |
| 20 | +│ ├── usage-aggregator.ts # Rolling usage sample accumulator |
| 21 | +│ ├── disk-cache.ts # Persistent cache for provider snapshots |
| 22 | +│ ├── polling-manager.ts # Background API polling orchestrator |
| 23 | +│ ├── fetch-claude.ts # Anthropic usage API client |
| 24 | +│ ├── fetch-openai.ts # OpenAI Codex usage API client |
| 25 | +│ ├── fetch-utils.ts # Shared HTTP utilities |
| 26 | +│ ├── auth-resolver.ts # Anthropic credential auto-detection |
| 27 | +│ ├── auth-resolver-openai.ts # OpenAI credential auto-detection |
| 28 | +│ ├── provider-usage.types.ts # Provider usage snapshot types |
| 29 | +│ ├── runtime/ |
| 30 | +│ │ ├── reducer.ts # HUD state machine (tool transitions) |
| 31 | +│ │ ├── intake.ts # Raw event parser |
| 32 | +│ │ ├── event-allowlist.ts # Allowed event types |
| 33 | +│ │ ├── formatting.ts # Display text sanitization |
| 34 | +│ │ ├── coexistence.ts # Multi-channel dispatch (prompt + publisher) |
| 35 | +│ │ ├── prompt-fallback.ts # Prompt channel with rate limiting |
| 36 | +│ │ ├── publisher.ts # Optional snapshot publisher |
| 37 | +│ │ └── channels/ |
| 38 | +│ │ ├── index.ts # Channel exports |
| 39 | +│ │ └── prompt.ts # Prompt message formatter |
| 40 | +│ └── cli/ |
| 41 | +│ ├── index.ts # CLI entry point (install/uninstall) |
| 42 | +│ ├── config-manager.ts # opencode.json config resolution |
| 43 | +│ ├── install-transaction.ts # Atomic install operations |
| 44 | +│ ├── uninstall-transaction.ts # Atomic uninstall operations |
| 45 | +│ └── local-plugin-transaction.ts # Local plugin shim management |
| 46 | +├── tests/ # vitest |
| 47 | +├── bin/opencode-status-hud.js # CLI binary |
| 48 | +├── docs/guide/installation.md # Installation guide (published to npm) |
| 49 | +├── docs/QUICKSTART.md # Quick start reference |
| 50 | +├── docs/CONFIG_DEFAULTS.md # Config defaults reference |
| 51 | +└── dist/ # Built output (tsc) |
18 | 52 | ``` |
19 | 53 |
|
20 | 54 | ## WHERE TO LOOK |
21 | 55 | | Task | Location | Notes | |
22 | 56 | |------|----------|-------| |
23 | | -| Understand OpenCode plugin limits | `OPENCODE_ARCHITECTURE_ANALYSIS.md` | Evidence-backed limits: no core patching, hook/TUI boundaries | |
24 | | -| Reuse composition/install patterns | `OH_MY_OPENCODE_ARCHITECTURE_ANALYSIS.md` | Bootstrap pipeline, hook tiering, installer idempotency | |
25 | | -| Track baseline plan assumptions | `OPENCODE_HUD_UNIVERSAL_PLAN.md` | Scope, phased milestones, verification, rollout | |
26 | | -| Execute strengthened implementation plan | `OPENCODE_HUD_UNIVERSAL_PLAN_VNEXT.md` | go/no-go gates, risk controls, verification strategy | |
27 | | -| Register work as granular tasks/issues | `OPENCODE_HUD_IMPLEMENTATION_ISSUES.md` | phase-grouped atomic issue definitions and dependency order | |
28 | | - |
29 | | -## CODE MAP |
30 | | -No local source code in this repository. All symbol/file references inside docs point to external repositories (`opencode/...`, `oh-my-opencode/...`). |
| 57 | +| HUD line format and output augmentation | `src/plugin.ts` | `buildAssistantUsageLine`, `appendUsageLineToOutputText` | |
| 58 | +| Provider API polling | `src/polling-manager.ts` | Creates per-provider pollers | |
| 59 | +| Anthropic usage fetch | `src/fetch-claude.ts` | Rate limit window parsing | |
| 60 | +| OpenAI Codex usage fetch | `src/fetch-openai.ts` | Codex API billing/usage | |
| 61 | +| Credential auto-detection | `src/auth-resolver.ts`, `src/auth-resolver-openai.ts` | Reads from env, config files | |
| 62 | +| Model metadata and context limits | `src/model-registry.ts` | Dynamic via chat.params hook | |
| 63 | +| Plugin install/uninstall CLI | `src/cli/` | Local shim or config-array mode | |
| 64 | +| State machine for tool transitions | `src/runtime/reducer.ts` | HudState, transitions | |
| 65 | +| Multi-channel dispatch | `src/runtime/coexistence.ts` | Prompt + publisher coordination | |
31 | 66 |
|
32 | 67 | ## CONVENTIONS |
33 | | -- This repo is documentation-first; keep additions evidence-based and concise. |
34 | | -- Preserve explicit distinction between: |
35 | | - - OpenCode-native capabilities |
36 | | - - oh-my-opencode-specific behavior |
37 | | - - proposed universal HUD implementation details |
38 | | -- Prefer stable, known event contracts and avoid undocumented assumptions. |
| 68 | +- Zero external env setup required — credentials auto-detected from existing provider configs |
| 69 | +- Output channel is primary: blockquote (`> usage line`) appended to assistant text |
| 70 | +- No ANSI escape codes in output text (stripped before blockquote wrapping) |
| 71 | +- All source uses strict TypeScript — no `as any`, no `@ts-ignore` |
| 72 | +- Tests use vitest, no mocking of external services (polling manager injectable) |
39 | 73 |
|
40 | 74 | ## ANTI-PATTERNS (THIS PROJECT) |
41 | | -- Do not require tmux for baseline HUD behavior (`OPENCODE_HUD_UNIVERSAL_PLAN.md`). |
42 | | -- Do not modify OpenCode core (`OPENCODE_HUD_UNIVERSAL_PLAN.md`, `OPENCODE_ARCHITECTURE_ANALYSIS.md`). |
43 | | -- Do not assume unknown web reducer events will render (`OPENCODE_ARCHITECTURE_ANALYSIS.md`). |
44 | | -- Do not introduce hard dependency on `oh-my-opencode` (`OPENCODE_HUD_UNIVERSAL_PLAN.md`). |
45 | | - |
46 | | -## UNIQUE STYLES |
47 | | -- Architecture docs are constraint-driven: each claim should tie back to concrete runtime/plugin surfaces. |
48 | | -- Implementation guidance is phased and testable (success criteria per phase). |
49 | | -- Keep practical "what to reuse / what not to inherit" framing when adding comparative analysis. |
| 75 | +- Do not modify OpenCode CLI core or oh-my-opencode |
| 76 | +- Do not require tmux for baseline HUD behavior |
| 77 | +- Do not use ANSI codes in output text (TUI renders markdown, not raw ANSI) |
| 78 | +- Do not suppress type errors with `as any` or `@ts-ignore` |
50 | 79 |
|
51 | 80 | ## COMMANDS |
52 | 81 | ```bash |
53 | | -# This repository currently has no local build/test scripts. |
54 | | -# Use standard documentation hygiene when editing: |
55 | | -markdownlint "*.md" # if markdownlint is available |
| 82 | +npm run typecheck # tsc --noEmit |
| 83 | +npm run test # vitest run |
| 84 | +npm run build # tsc -p tsconfig.build.json |
| 85 | +npm run ci # typecheck + test + build (prepublishOnly) |
56 | 86 | ``` |
57 | | - |
58 | | -## NOTES |
59 | | -- There are no subdirectories at present; only root-level AGENTS.md is warranted. |
60 | | -- If code or packages are later added, create nested AGENTS.md only for directories with distinct ownership, conventions, or high complexity. |
|
0 commit comments