Files
oh-my-opencode/src/shared/AGENTS.md
T
Chau Luu 4713a90816 fix(shared): cap log file growth via size-based rotation
Refs #3772 (the rotation half — EPIPE shutdown-noise suppression
remains a separate follow-up).

`src/shared/logger.ts` appends every entry to `os.tmpdir()/oh-my-opencode.log`
via `fs.appendFileSync` with no size cap. On long-running or busy projects
the file grows into the multi-GB range — a real-world reproduction on one
machine showed a 4.5 GB `oh-my-opencode.log.1` accumulated from per-shutdown
noise across many sessions. Eats `%TEMP%` on Windows and `/tmp` on Unix.

Add size-based rotation inside the existing batched `flush()` path:

  oh-my-opencode.log    → oh-my-opencode.log.1
  oh-my-opencode.log.1  → oh-my-opencode.log.2 (oldest dropped)

Cap is 50 MB per file; worst-case on-disk footprint is therefore ~150 MB.
The check runs only inside `flush()`, so the cost is amortized over
`BUFFER_SIZE_LIMIT` (50 entries) or the 500 ms flush timer. All filesystem
ops stay wrapped in try/catch — logging must never throw — and a failed
rotation leaves existing on-disk state intact rather than crashing the
agent. Pattern mirrors `src/openclaw/reply-listener-log.ts`, but with two
backup slots instead of one to keep a usable history window for debugging.

No config knobs in this iteration. The issue proposes `logs.max_size_mb`
/ `logs.max_files`, but the defaults are reasonable and adding schema is
more surface area than the bug warrants. Easy to promote later (the
existing test seams already let callers override the cap).

Tests:
- `src/shared/logger.test.ts` (new): under-threshold no-rotate, over-
  threshold rotates to `.1`, repeated rotation evicts oldest, rotation-
  failure-doesn't-throw, default path lives under `os.tmpdir()`. Uses a
  `mock.module(...)` substring marker so `script/run-ci-tests.ts` routes
  the file to its own bun process — the logger module's singleton state
  otherwise gets contaminated by sibling tests that mock `./shared`.

Out of scope: suppressing specific shutdown-noise messages (EPIPE,
`unhandledRejection received during shutdown cleanup`). The rotation
cap bounds the disk impact regardless of which noise pattern is
generating volume; per-message suppression can stand on its own
merits in a follow-up.
2026-05-17 19:46:29 +00:00

2.8 KiB

src/shared/ — 278 Utility Files (170 non-test)

Generated: 2026-05-15

OVERVIEW

Cross-cutting utilities used throughout the plugin. Barrel-exported from index.ts. Logger writes oh-my-opencode.log to the OS temp dir (Node's os.tmpdir()/tmp on Linux, %TEMP% on Windows, etc.); rotated at 50 MB; up to 2 backups at .1 / .2. Includes runtime shims for Bun.file, Bun.write, Bun.hash, Bun.which, Bun.spawn to support non-Bun runtimes (Electron-hosted OpenCode).

CATEGORY MAP

Category Files Key Exports
Model Resolution ~22 resolveModel(), checkModelAvailability(), AGENT_MODEL_REQUIREMENTS
Tmux Integration 11 createTmuxSession(), spawnPane(), closePane(), server health
Configuration & Paths 10 resolveOpenCodeConfigDir(), getDataPath(), parseJSONC()
Session Management 8 SessionCursor, trackInjectedPath(), SessionToolsStore
Git Worktree 7 parseGitStatusPorcelain(), collectGitDiffStats(), formatFileChanges()
Command Execution 7 executeCommand(), executeHookCommand(), embedded command registry
Migration 6 migrateConfigFile(), AGENT_NAME_MAP, HOOK_NAME_MAP, MODEL_VERSION_MAP
String & Tool Utils 6 toSnakeCase(), normalizeToolName(), parseFrontmatter()
Agent Configuration 5 getAgentVariant(), AGENT_DISPLAY_NAMES, AGENT_TOOL_RESTRICTIONS
OpenCode Integration 5 injectServerAuth(), detectExternalPlugins(), client accessors
Type Helpers 4 deepMerge(), DynamicTruncator, matchPattern(), isRecord()
Misc 8 log(), readFile(), extractZip(), downloadBinary(), findAvailablePort()

MODEL RESOLUTION PIPELINE

resolveModel(input)
  1. Override: UI-selected model (primary agents only)
  2. Category default: From category config
  3. Provider fallback: AGENT_MODEL_REQUIREMENTS chains
  4. System default: Ultimate fallback

Key files: model-resolver.ts (entry), model-resolution-pipeline.ts (orchestration), model-requirements.ts (fallback chains), model-availability.ts (fuzzy matching).

MIGRATION SYSTEM

Automatically transforms legacy config on load:

  • agent-names.ts: Old agent names → new (e.g., juniorsisyphus-junior)
  • hook-names.ts: Old hook names → new
  • model-versions.ts: Old model IDs → current
  • agent-category.ts: Legacy agent configs → category system

MOST IMPORTED

Utility Import Count Purpose
logger.ts 62 oh-my-opencode.log in os.tmpdir() (50 MB cap, rotates to .1/.2)
data-path.ts 11 XDG storage resolution
model-requirements.ts 11 Agent fallback chains
system-directive.ts 11 System message filtering
frontmatter.ts 10 YAML metadata extraction