Files
zesdex/docs/CODEMAPS/backend.md
T
asepharyana 1d50b94eec feat: update README and documentation for new tools and features
- Updated README.md to reflect the addition of 3 new built-in tools, bringing the total to 37.
- Revised architecture documentation to indicate the increase in tool count.
- Enhanced backend documentation with updated line counts for various modules.
- Modified data documentation to change edit log format from JSON to JSONL.
- Updated dependencies documentation to reflect version upgrades for several crates.
- Improved prompts for auto-reviewer, division implementer, planner, tester, and quality reviewer to enforce stricter coding standards regarding linter bypasses.
- Refactored code in various modules to improve clarity and performance, including updates to error handling and tool execution logic.
- Added comprehensive tests for IPC frame serialization and deserialization.
2026-07-13 14:39:39 +07:00

3.2 KiB

Backend / Service Layer

AI Provider

src/service/provider.rs (310 lines)

  • LlmClient::new(api_key, model, base_url) — constructs blocking reqwest client
  • chat_with_tools() — non-streaming with tool definitions
  • chat_stream() — SSE streaming, returns SseParser yielding StreamEvent
  • Retry logic: up to 3 attempts on transient errors, exponential backoff

OAuth

src/service/oauth/manager.rs (113 lines) + loopback.rs + pkce.rs

  • PKCE flow: CodeVerifier → challenge → browser auth → loopback server → token exchange
  • Configurable via app_config.json provider definitions (auth URL, token URL, scopes)

IPC / Daemon

src/ipc/ (7 files, ~350 lines total)

  • Unix domain socket, length-prefixed JSON frames
  • Daemon sends DaemonFrame (state payload, stream tokens, system notes)
  • Clients send ClientRequest (key presses, resize, submit, scroll)
  • State sync uses full-state push from daemon to client after each action

Workflow Engine

src/app/workflow/engine.rs (648 lines) + script.rs

  • Inline JS-style DSL executed by a lightweight runtime
  • agent(), parallel(), pipeline(), phase(), log() — spawns sub-agents
  • Max concurrency configurable via workflow_max_concurrency setting
  • Company pipeline orchestrator in company.rs (406 lines): full 5-division or quick 3-division pipelines

Sub-Agent System

src/app/subagent/ (6 files: spawn.rs, engine.rs, context.rs, event.rs, division.rs, auto.rs, ~450 lines total)

  • run_subagent() — spawns independent agent with its own tool set and context
  • Communicates via mpsc<SubagentEvent> channel (tool calls, results, completion)
  • Uses LlmClient (same as main agent) with tool-use API
  • Auto-healing: on build/test failure, spawns auto-fix sub-agent
  • Division roles: Strategy, Engineering, Quality, Security, Documentation

MCP Client

src/app/mcp/manager.rs (441+ lines)

  • Stdio transport: spawns child process, JSON-RPC via stdin/stdout
  • HTTP transport: streaming HTTP with JSON-RPC
  • Dynamic tool list refresh and error recovery
  • Persistent child handle for stdio (reuses connection across calls)

Self-Review

src/app/review/mod.rs (495 lines)

  • Post-tool execution quality check against learned lessons
  • Invokes run_subagent() with reviewer prompt
  • Staleness detection: skips review after N consecutive empty results
  • Three review types: code quality, architecture, security

Background Bash

src/app/bgbash/ (2 files: job.rs, control.rs)

  • spawn_bash_job() — runs sh -c in a thread, collects stdout line-by-line
  • Channels: output via mpsc<String>, PID via mpsc<u32>
  • Killable via PID (SIGTERM)
  • Output buffering capped at 10,000 lines to prevent memory issues

Gate Guard / Harness

src/app/harness.rs (495 lines)

  • Harness::gate_tool_call() — verdict-based tool gating (allow/block)
  • Path traversal, credential read, and destructive command detection
  • Pattern detection for stub code, denial language, and assumptions in write/edit content
  • Reason validation for mutating tools (minimum 8 characters, rejects generic non-answers)
  • Includes 8 unit tests for verdict parsing formats