How yeachan-heo/gajae-code works
Purpose and entry points
Gajae-Code (gjc) is a Bun/TypeScript coding-agent harness for structured interview → plan → evidence-backed execution, optionally in tmux worktrees. Primary CLI startup and command dispatch are in packages/coding-agent/src/cli.ts and packages/coding-agent/src/main.ts; the published launcher is packages/coding-agent/bin/gjc.js. Interactive, print, and ACP modes branch from packages/coding-agent/src/modes/.
Session and agent execution core
AgentSession and the session manager own conversation state, model calls, tool invocation, streaming output, retries/fallbacks, and persistence. Session data is separated from UI and transports, enabling local TUI, headless CLI, SDK clients, and bots to drive the same runtime.
• packages/coding-agent/src/session/agent-session.ts
• packages/coding-agent/src/session/session-manager.ts
• packages/agent/src/agent-loop.ts
The agent loop consumes normalized provider streams, appends messages/tool results, enforces attempt scopes and resource accounting, then invokes maintenance such as compaction.
AI provider and credential boundary
packages/ai is the provider abstraction: model registry/selection, provider-specific request and streaming adapters, schema normalization, OAuth/API-key storage, retry policy, and usage accounting. This isolates the agent/session layer from OpenAI, Anthropic, Google, AWS Bedrock, Azure, Ollama, Cursor, GitHub Copilot, and other compatible endpoints.
• packages/ai/src/api-registry.ts
• packages/ai/src/model-manager.ts
• packages/ai/src/providers/register-builtins.ts
• packages/ai/src/auth-storage.ts
Auth broker and gateway services expose local credential/protocol mediation rather than embedding provider logic in every caller: packages/ai/src/auth-broker/server.ts, packages/ai/src/auth-gateway/server.ts.
Context durability and workflow control
The agent package maintains append-only context and compaction/summarization to stay within provider context limits. The coding-agent session layer persists histories, blobs, artifacts, session trees, and model/fallback state. GJC’s workflow state separately records durable deep-interview, ralplan, ultragoal, and team progress with validation and atomic writing.
• packages/agent/src/append-only-context.ts
• packages/agent/src/compaction/compaction.ts
• packages/coding-agent/src/session/session-storage.ts
• packages/coding-agent/src/gjc-runtime/state-runtime.ts
• packages/coding-agent/src/gjc-runtime/ultragoal-runtime.ts
This boundary makes execution evidence and workflow state survive process/UI restarts.
Tools, mutation, and local-runtime boundary
Tool registration connects model calls to constrained local capabilities: read/search/edit, shell/PTY, GitHub, browser, web search, MCP, LSP, notebook-style JS/Python evaluation, and optional desktop control. Editing and shell execution remain explicit tool boundaries, while extensions and hooks are loaded through dedicated capability and quarantine paths.
• packages/coding-agent/src/tools/index.ts
• packages/coding-agent/src/edit/index.ts
• packages/coding-agent/src/exec/bash-executor.ts
• packages/coding-agent/src/runtime-mcp/manager.ts
• packages/coding-agent/src/extensibility/gjc-plugins/loader.ts
Python execution uses a persistent kernel runtime; browser and computer control launch/manage external local processes and permissions.
User, automation, and remote-control surfaces
The terminal UI is a reusable component package rendered by interactive mode; controllers translate input/events into session operations. ACP supports editor-agent protocol clients. The SDK host/broker exposes session discovery, lifecycle, control, query, reverse RPC, and stdio/socket transport. Chat daemons adapt this protocol to Telegram, Discord, and Slack without terminal scraping.
• packages/tui/src/tui.ts
• packages/coding-agent/src/modes/interactive-mode.ts
• packages/coding-agent/src/modes/acp/acp-agent.ts
• packages/coding-agent/src/sdk/host/host.ts
• packages/coding-agent/src/sdk/bus/engine.ts
Native and platform infrastructure
Rust crates provide N-API native bindings for performance-sensitive and OS-dependent capabilities: PTYs, filesystem/search/edit primitives, screenshots/input, memory/process management, and isolation/copy mechanisms. The TypeScript native package loads platform binaries; release packages supply Darwin, Linux, and Windows variants.
• crates/pi-natives/src/lib.rs
• crates/pi-natives/src/computer/mod.rs
• packages/natives/native/index.js
• packages/natives/scripts/build-native.ts
The repository is a Bun workspace with Rust/Cargo native builds, optional tmux/worktrees, SQLite-backed session-related storage, and network dependencies for LLM providers, OAuth, web search, chat APIs, npm update checks, and plugin/MCP endpoints.
Main entry points: interactive-mode.ts Execution modes · agent-loop.ts Agent loop · index.ts Tool registry · session-manager.ts Session manager
Components 22
Entry & surfaces
- Published launcher
packages/coding-agent/bin/gjc.js - CLI dispatch
packages/coding-agent/src/cli.ts - Application startup
packages/coding-agent/src/main.ts - Execution modes · Interactive, print, and ACP modes select a session driver.
packages/coding-agent/src/modes/interactive-mode.ts - Terminal UI
packages/tui/src/tui.ts - ACP agent
packages/coding-agent/src/modes/acp/acp-agent.ts - SDK host and bus · Provides lifecycle, control, query, and reverse RPC over stdio or sockets.
packages/coding-agent/src/sdk/host/host.ts
Agent runtime
- Session manager
packages/coding-agent/src/session/session-manager.ts - Agent session · Owns model calls, tool invocation, streaming, retries, and output.
packages/coding-agent/src/session/agent-session.ts - Agent loop · Appends model and tool results while enforcing attempts and resource accounting.
packages/agent/src/agent-loop.ts - Append-only context
packages/agent/src/append-only-context.ts - Context compaction · Maintains provider context limits.
packages/agent/src/compaction/compaction.ts
Provider & local integration
- AI registry and models · Selects models and normalizes provider requests and streams.
packages/ai/src/api-registry.ts - Provider adapters · Registers OpenAI, Anthropic, Google, Bedrock, Azure, Ollama, Copilot, and compatible endpoints.
packages/ai/src/providers/register-builtins.ts - Auth broker and gateway · Mediates OAuth and API-key access for local clients.
packages/ai/src/auth-broker/server.ts - Tool registry · Exposes constrained read, search, edit, shell, GitHub, browser, MCP, LSP, and evaluation tools.
packages/coding-agent/src/tools/index.ts - Runtime MCP manager
packages/coding-agent/src/runtime-mcp/manager.ts - Plugin loader
packages/coding-agent/src/extensibility/gjc-plugins/loader.ts
Durability & workflow
- Session storage · Stores histories, blobs, artifacts, session trees, and fallback state.
packages/coding-agent/src/session/session-storage.ts - Workflow state · Atomically records interview, plan, ultragoal, and team progress.
packages/coding-agent/src/gjc-runtime/state-runtime.ts
Native platform
- Native bindings · Loads Rust-backed PTY, filesystem, search, edit, computer, and isolation capabilities.
packages/natives/native/index.js - Rust native crate
crates/pi-natives/src/lib.rs
Connections 21
- Published launcher → CLI dispatch: starts
- CLI dispatch → Application startup: dispatches
- Application startup → Execution modes: selects
- Execution modes → Terminal UI: interactive UI
- Execution modes → ACP agent: editor mode
- Execution modes → Session manager: drives sessions
- SDK host and bus → Session manager: remote control
- Session manager → Agent session: creates and restores
- Agent session → Agent loop: runs
- Agent loop → AI registry and models: model streams
- AI registry and models → Provider adapters: uses adapters
- AI registry and models → Auth broker and gateway: obtains credentials
- Agent loop → Tool registry: invokes tools
- Tool registry → Runtime MCP manager: connects MCP
- Tool registry → Plugin loader: loads extensions
- Tool registry → Native bindings: uses local capabilities
- Native bindings → Rust native crate: loads bindings
- Agent loop → Append-only context: appends events
- Append-only context → Context compaction: compacts when needed
- Session manager → Session storage: persists sessions
- Agent session → Workflow state: records workflow progress