How qwen-code-dev-bot/oh-my-cli works
Purpose and entry points
oh-my-cli is a Node.js 22, TypeScript/ESM code-agent CLI: it sends model requests, executes confined file/shell tools, persists sessions, and provides deterministic read-only planning, verification, review, and delivery commands. The main CLI dispatcher is src/index.ts; the agent execution loop is src/agent.ts. It supports interactive terminal UI, non-interactive prompts, NDJSON automation output, optional desktop packaging, and a loopback-only delivery web surface.
Paths: src/index.ts, src/agent.ts, src/tui-shell.ts
Model-backed agent loop
The core control flow is: resolve settings/model → compose workspace and instruction context → call an OpenAI-compatible provider → aggregate text/tool calls → gate and execute tools → append session events → repeat, capped at 30 rounds and governed by a spend budget. Provider retries, token/cost estimation, and headless event reporting wrap this loop.
Paths: src/config.ts, src/provider.ts, src/cost.ts
Workspace tools and safety boundary
Built-in read/list/glob/grep/write/edit/shell tools are confined to the canonical workspace and reject symlink escapes. Mutations pass layered controls: folder-trust/sandbox posture, deterministic shell command policy, approval mode, and redacted impact preview. Read-only discovery remains available without approval.
Paths: src/tools.ts, src/workspace.ts, src/folder-trust.ts
Paths: src/command-policy.ts, src/approval.ts, src/permission-impact.ts
Durable session and recovery subsystem
Sessions are persisted as JSONL in the user state directory. Supporting sidecars provide fail-closed transcript compaction, atomic export, turn-scoped content checkpoints for undo/redo, and isolated side questions that receive no workspace/session mutation handles. Session stats, task monitoring, and LSP status are read-only projections over persisted or runtime state.
Paths: src/session.ts, src/compaction.ts, src/turn-checkpoint.ts
Paths: src/side-question.ts, src/session-stats.ts, src/task-runtime.ts
Repository intelligence and delivery pipeline
A read-only repository layer derives context, ranked symbol maps, trusted instruction context, and canonical verification commands. The delivery pipeline composes deterministic stages: plan → run canonical verification → Git-based change review → CI handoff → delivery verdict. These commands are head-bound, bounded, redacted, and generally avoid model calls.
Paths: src/repo-context.ts, src/repo-map.ts, src/instruction-context.ts
Paths: src/task-plan.ts, src/task-verify.ts, src/change-review.ts
Paths: src/ci-handoff.ts, src/delivery-brief.ts
Extensions, automation, and external services
Primary external service is an OpenAI-compatible HTTP model endpoint configured from environment variables and user-owned settings. Versioned contracts also govern provider, local command-tool, stdio MCP, and workflow integrations; contract resolution is read-only, while invocation is approval/policy-gated and timeout-bounded. Workflows execute sequential isolated headless prompt steps.
Paths: src/provider-contract.ts, src/mcp-contract.ts, src/tool-contract.ts
Paths: src/provider-invocation.ts, src/mcp-invocation.ts, src/workflow-runner.ts
Interfaces and infrastructure
The terminal interface includes a TUI shell and a versioned NDJSON protocol for CI/automation. Optional Electron-style desktop separation uses main, preload, renderer, and service layers. A delivery web server exposes constrained browser-native feature pages on loopback only. Git is material infrastructure for readiness, review, recovery evidence, and leased worktree isolation.
Paths: src/headless-protocol.ts, src/desktop/main.ts, src/desktop/preload.ts
Paths: src/delivery-web.ts, src/worktree-lease.ts, src/evidence-archive.ts
Main entry points: agent.ts Agent loop · index.ts CLI dispatcher · tools.ts Workspace tools · session.ts Session store
Components 22
CLI & Interfaces
- CLI dispatcher · Selects interactive, headless, planning, and delivery commands.
src/index.ts - Terminal UI
src/tui-shell.ts - Automation protocol
src/headless-protocol.ts
Agent Runtime
- Agent loop · Runs bounded model/tool rounds under a spend budget.
src/agent.ts - Model settings
src/config.ts - Model provider · Retries model requests and aggregates text and tool calls.
src/provider.ts - Cost control
src/cost.ts
Workspace Safety
- Workspace tools · Provides confined read, mutation, and shell operations.
src/tools.ts - Workspace boundary · Enforces canonical workspace paths and rejects symlink escapes.
src/workspace.ts - Mutation gates · Combines trust posture, shell policy, approval, and impact preview.
src/approval.ts
Sessions & Recovery
- Session store · Durable agent event history in the user state directory.
src/session.ts - Transcript compaction · Fail-closed transcript compaction and atomic export.
src/compaction.ts - Turn checkpoints
src/turn-checkpoint.ts
Repository Delivery
- Repository intelligence · Derives repository context, symbol maps, instructions, and verification commands.
src/repo-context.ts - Task planning
src/task-plan.ts - Canonical verification · Runs bounded, redacted repository verification commands.
src/task-verify.ts - Change review
src/change-review.ts - Delivery verdict · Produces CI handoff and delivery readiness verdict.
src/delivery-brief.ts - Git evidence & worktrees · Supports review, recovery evidence, and leased worktree isolation.
src/worktree-lease.ts
Extensions & Services
- Contract invocation · Resolves versioned provider, tool, and MCP contracts and invokes them under gates.
src/provider-invocation.ts - Workflow runner · Executes sequential isolated prompt steps.
src/workflow-runner.ts - Model endpoint · OpenAI-compatible endpoint configured by environment and user settings.
Connections 25
- CLI dispatcher → Terminal UI: interactive mode
- CLI dispatcher → Automation protocol: automation output
- CLI dispatcher → Agent loop: starts agent
- CLI dispatcher → Task planning: planning command
- CLI dispatcher → Delivery verdict: delivery command
- Agent loop → Model settings: resolves settings
- Model settings → Model provider: configures
- Agent loop → Model provider: model requests
- Model provider → Model endpoint: HTTP requests
- Agent loop → Cost control: enforces budget
- Agent loop → Repository intelligence: composes context
- Agent loop → Workspace tools: executes tool calls
- Workspace tools → Workspace boundary: confined by
- Workspace tools → Mutation gates: mutations require
- Agent loop → Session store: appends events
- Session store → Transcript compaction: compacts and exports
- Session store → Turn checkpoints: turn recovery
- Repository intelligence → Task planning: planning context
- Task planning → Canonical verification: plan then verify
- Canonical verification → Change review: verified changes
- Change review → Delivery verdict: review evidence
- Git evidence & worktrees → Change review: Git state and evidence
- Contract invocation → Mutation gates: approval and policy
- Workflow runner → Agent loop: isolated prompt steps
- Workflow runner → Automation protocol: headless events