utils

September 2, 2026 · View on GitHub

Generated: 2026-08-24 / f3642fcda

OVERVIEW

Harness-neutral pure-TypeScript core package (@oh-my-opencode/utils). Consumed by both adapters (packages/omo-opencode, packages/omo-codex) and the other Core packages. Barrel-exports runtime shims, config tooling, file utilities, prompt gating, git parsing, and migration maps.

CATEGORY MAP

GroupKey FilesRole
Deep Mergedeep-merge.tsdeepMerge() — recursive, prototype-pollution safe (__proto__/constructor/prototype filtered), max depth 50
Frontmatterfrontmatter.tsparseFrontmatter() — default YAML (js-yaml JSON_SCHEMA) + rule-mode parser with multiline glob arrays
File Utilsfile-utils.ts, atomic-write.ts, xdg-data-dir.tsSymlink resolution, atomic writes with tolerant fsync, XDG data dir with tmp fallback
Runtime Shimsruntime/spawn.ts, runtime/which.ts, runtime/file.tsspawn() / spawnSync() — prefers Bun.spawn, falls back to Node child_process; unified SpawnedProcess interface
Prompt Gateprompt-async-gate.ts + prompt-async-gate/*.tsdispatchInternalPrompt() — reservation + queue + semantic dedupe + live-route fallback; the mandated gate for all internal session.prompt calls
Git Worktreegit-worktree/*.tsPorcelain status parser, diff stat collection, formatFileChanges()
Migrationmigration.ts, migration/*.tsAgent-name, hook-name, model-version, agent-category migration maps; migrateConfigFile()
Command Execcommand-executor/execute-command.ts, execute-hook-command.tsexecuteCommand() via node:child_process exec; stderr inlined in return string
Ast-grepast-grep/*.tssg binary provisioning: pinned manifest, resolver/cache, install script; provisionSgBinary()
Process Sweepprocess-sweep/*.tsFamily-based orphan cleanup: LSP daemon proxy/version sweeps, ownership attestation
Process Treeprocess-tree.ts, process-tree-termination.ts, process-stream-reader.tsProcess tree enumeration/termination, stream reading
Logginglogging/*.tsBuffered logger (flush/rotation) + product identity
Zip Listingzip-entry-listing/*.tstar / zipinfo / Python / PowerShell adapters + symlink target reading
Portsport-utils.tsfindAvailablePort(), DEFAULT_SERVER_PORT
Miscsnake-case.ts, jsonc-parser.ts, record-type-guard.ts, logger.tsKey transformation, safe JSONC parse, type guards, injectable shared logger stub

NOTES

  • Dependencies: js-yaml, jsonc-parser (only production deps).
  • No path aliases: relative imports only; strict ESNext + bundler moduleResolution.
  • Runtime portability: runtime/spawn.ts wraps both Bun and Node APIs so downstream packages can run under Electron-hosted OpenCode.
  • Side effects: package.json sideEffects pins src/prompt-async-gate/queue.ts; tree-shaking must keep the queue module.
  • Process-sweep invariant: the LSP daemon server shape (cli.js daemon, no mcp) is NEVER a proxy candidate — only the proxy shape is swept (process-sweep/lsp-proxy-family.ts, pinned by tests).
  • Prompt-async-gate is critical infrastructure: every internal prompt dispatch across the plugin must route through dispatchInternalPrompt() to prevent duplicate injections and race conditions. See the root AGENTS.md "Internal message injection is dangerous" section.