Skip to content
Barney0809Public

About

coda — 用 Java 25 + Spring Boot 3.5 写的本地编码 Agent(Spring Shell CLI)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

coda — a coding agent in Java

A command-line coding agent that runs inside your repository. Java 25 + Spring Boot 3.5 + Spring Shell.

It reads the workspace, then acts through a small, explicitly registered set of tools — read, search, patch, run, delegate — and keeps its session state on disk under .coda/, so a run can be inspected or resumed later.

Quick Start

mvn clean package -DskipTests
java --enable-preview -jar target/coda-0.1.0.jar

Pick a model backend (Ollama is the default and needs no key):

export CODA_DEFAULT_PROVIDER=openai
export CODA_PROVIDER_OPENAI_API_KEY=sk-...
export CODA_PROVIDER_OPENAI_MODEL=gpt-5.4
java --enable-preview -jar target/coda-0.1.0.jar

Shell Commands

Command Alias Description
ask <message> a Run one task
chat c Interactive loop
status Session / provider / step count
session [id] Show or switch session
provider <name> Switch model backend
reset Reset session memory

Inside chat: /exit, /status, /reset.

Architecture

com.fu.coda
├── config/          CodaProperties, EnvLoader (.env)
├── model/           ModelClient + 5 backends (Ollama, OpenAI, Anthropic, DeepSeek, Fake)
├── workspace/       Git context, project-doc pre-scan, fingerprint
├── tool/            Tool, ToolRegistry, ToolValidator, ApprovalGate
│   └── impl/        7 tools: list_files, read_file, search, run_shell,
│                    write_file, patch_file, delegate
├── memory/          WorkingMemory + DurableMemoryStore + LayeredMemory
├── context/         Prompt assembly, section budgets, reduction
├── runtime/         CodaAgent (orchestrator), TaskState, RunStore, SessionStore,
│                    SecurityService, ParseService, PromptService,
│                    CheckpointService, ToolExecutionService, DurablePromotionService
├── shell/           Spring Shell commands and REPL
├── benchmark/       Runner, fixtures, verifiers
├── metrics/         Run metrics
└── persistence/     CodaPaths (.coda/ layout)

Tools

Tool Risk Description
list_files safe List a directory
read_file safe Read a line range
search safe Regex search (ripgrep, with a pure-Java fallback)
delegate safe Spawn a read-only child agent
run_shell risky Run a shell command in the repo root
write_file risky Create or overwrite a file
patch_file risky Replace an exact text block

Risky tools go through ApprovalGate, configured by coda.approval: ask | auto | never. Tools are stateless: every execute() call stands alone.

Context Budget

The prompt is split into five sections with per-section character budgets:

Section Budget (chars) Content
prefix 6,000 Agent manual: rules, tool signatures, workspace snapshot
memory 1,600 Task, recent files, file summaries, episodic notes
relevant_memory 800 Notes retrieved for the current request
history 7,600 Transcript, semantically compressed
current_request unlimited Never trimmed
total 16,000

Those numbers were measured, not guessed: in this repository the static manual is ~1,728 chars, 7 tool signatures ~1.2k, and the workspace snapshot ~2.5k, so prefix gets 6,000 to stay intact. When the total is exceeded, sections shrink in the order relevant_memory → history → memory → prefix — the tool signatures are the last thing to lose, because a model that cannot see a tool will not use it. Every reduction is logged with section / before_chars / after_chars / overflow_chars.

History compression runs before length clipping: the last 5 entries are kept whole (up to 1,000 chars each), repeated read_file calls collapse to the first occurrence, old run_shell calls become one summary line, and other old entries are clipped to 80 chars.

Memory

LayeredMemory
  ├── WorkingMemory        session-scoped: task, recent files (8), file summaries (6), notes (12)
  └── DurableMemoryStore   .coda/memory/MEMORY.md + topics/*.md

File summaries carry a freshness flag — after a file is edited, summaries built from the old content are invalidated rather than silently reused. Promotion to durable memory is explicit: only notes worth keeping across sessions are promoted, and the call returns both what was promoted and what it replaced.

Tests

mvn test

22 tests: context budgets and reduction, history compression, prompt contract, response parsing, utils. benchmark/ holds a task suite (BenchmarkRunner + fixtures + verifiers) that collects metrics/.

Requirements

  • JDK 25 (the build enables preview features)
  • Maven 3.9+

Known Limitations

  • Tool execution and runtime orchestration still have thin test coverage; tests cluster around context and parsing.
  • delegate is read-only and depth-limited to 1.
  • Budget numbers come from one measured repository; a second project may need different splits.

License

MIT

About

coda — 用 Java 25 + Spring Boot 3.5 写的本地编码 Agent(Spring Shell CLI)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages