1111go build -o kode ./cmd/kode
1212```
1313
14+ ## Source layout
15+
16+ ```
17+ kode.go Public API (Config, New, Run, Close)
18+ kode_test.go Config and model profile tests
19+ internal/
20+ config/
21+ loader.go Config file loading, env vars, priority merge
22+ loader_test.go Config loading tests
23+ llm/
24+ client.go OpenAI-compatible HTTP client
25+ client_test.go JSON marshaling + response parsing tests
26+ loop/
27+ loop.go ReAct engine (observe → think → act → repeat)
28+ loop_test.go Engine tests with mock server
29+ session/
30+ session.go Session store (CRUD, trim, cleanup)
31+ session_test.go Session tests
32+ render/
33+ render.go Terminal output with model label and color
34+ resource/
35+ resource.go @-reference resolver (files, sessions)
36+ resource_test.go Parse, resolve, search tests
37+ ws/
38+ ws.go RFC 6455 WebSocket framing (~200 LOC)
39+ ws_test.go Handshake, framing, ping/pong tests
40+ tool/
41+ registry.go Thread-safe tool registry
42+ registry_test.go Registry tests
43+ cmd/kode/
44+ main.go CLI entry point, flag parsing, commands, sandbox
45+ main_test.go CLI tests (flag parsing, version, init)
46+ shell.go Built-in shell tool (local or docker exec)
47+ shell_test.go Shell + sandbox tests
48+ serve.go Web UI server (HTTP + WebSocket)
49+ subagent.go Sub-agent command (--goal, --context, --task, JSON stdout)
50+ subagent_tool.go delegate_tasks built-in tool
51+ subagent_test.go Contract tests (30 — flags, JSON, exit codes, tool schema)
52+ subagent_contract_test.go Contract tests (flag parsing, stdout protocol, exit codes)
53+ subagent_e2e_test.go E2E tests (13 — KODE_E2E=true, real subprocess spawning)
54+ ui/
55+ index.html Single-page web UI (~770 LOC, vanilla JS + CSS)
56+ docs/ Documentation
57+ CLI.md CLI reference
58+ CONFIG.md Configuration system
59+ PROVIDERS.md Models, profiles, thinking, context
60+ SESSIONS.md Multi-turn sessions
61+ WEBUI.md Web UI server + WebSocket protocol + @ completion
62+ SUBAGENTS.md Task decomposition + sub-agents + delegate_tasks tool
63+ SECURITY.md Prompt injection, security model
64+ SANDBOXING.md Sandbox configuration
65+ DEVELOPMENT.md This file
66+ ```
67+
1468## Testing
1569
1670``` bash
17- # All tests
18- go test ./... -v - count=1
71+ # All tests (excluding E2E — those need KODE_E2E=true)
72+ go test ./... -count=1
1973
2074# Specific package
2175go test ./internal/session/ -v
76+
77+ # With race detector
78+ go test -race ./... -count=1
79+
80+ # E2E tests (builds kode binary, tests real subprocess spawning)
81+ KODE_E2E=true go test -v -count=1 ./cmd/kode/ -run " TestE2E_"
82+
83+ # Contract tests (sub-agent interface contract — binary must already be built)
84+ go test -v -count=1 ./cmd/kode/ -run " TestSubagent|TestDelegateTasks"
2285```
2386
2487Zero external test dependencies — tests use ` httptest ` , ` testing ` , and the standard library only.
2588
89+ ### Test layers
90+
91+ | Layer | Runner | Tests | What's tested |
92+ | -------| --------| -------| ---------------|
93+ | ** Unit** | ` go test ./... ` | 190+ | Config, LLM client, sessions, renderer, tools, WS, resources |
94+ | ** Contract** | ` go test ./cmd/kode/ ` | 30 | Sub-agent flag parsing, JSON stdout, exit codes, tool schema, config |
95+ | ** E2E** | ` KODE_E2E=true go test -run "TestE2E_" ` | 13 | Real subprocess spawning, tool→binary pipeline, concurrency, timeouts |
96+
2697### Test coverage
2798
2899| Package | Tests | Focus |
@@ -33,45 +104,26 @@ Zero external test dependencies — tests use `httptest`, `testing`, and the sta
33104| ` internal/loop ` | 7 | ReAct engine with httptest mock server |
34105| ` internal/session ` | 19 | CRUD, trim, cleanup, list, latest, edge cases |
35106| ` internal/tool ` | 7 | Registry CRUD, lookup, duplicate detection |
36- | ` cmd/kode ` | 20+ | Flag parsing, init, version, sandbox setup, integration |
107+ | ` internal/ws ` | 8 | WebSocket upgrade, framing, ping/pong |
108+ | ` internal/resource ` | 12 | @-reference parsing, file resolution, session resolution, security |
109+ | ` cmd/kode ` | 60+ | Flag parsing, init, version, sandbox setup, subagent, serve, E2E |
37110
38- ## Source layout
111+ ## Key packages
39112
40- ```
41- kode.go Public API (Config, New, Run, Close)
42- kode_test.go Config and model profile tests
43- internal/
44- config/
45- loader.go Config file loading, env vars, priority merge
46- loader_test.go Config loading tests
47- llm/
48- client.go OpenAI-compatible HTTP client
49- client_test.go JSON marshaling + response parsing tests
50- loop/
51- loop.go ReAct engine (observe → think → act → repeat)
52- loop_test.go Engine tests with mock server
53- session/
54- session.go Session store (CRUD, trim, cleanup)
55- session_test.go Session tests
56- render/
57- render.go Terminal output with model label and color
58- tool/
59- registry.go Thread-safe tool registry
60- registry_test.go Registry tests
61- cmd/kode/
62- main.go CLI entry point, flag parsing, commands, sandbox
63- main_test.go CLI tests
64- shell.go Built-in shell tool (local or docker exec)
65- shell_test.go Shell + sandbox tests
66- docs/ Documentation
67- CLI.md CLI reference
68- CONFIG.md Configuration system
69- PROVIDERS.md Models, profiles, thinking, context
70- SESSIONS.md Multi-turn sessions
71- SECURITY.md Prompt injection, security model
72- SANDBOXING.md Sandbox configuration
73- DEVELOPMENT.md This file
74- ```
113+ ### Web UI (` cmd/kode/serve.go ` + ` internal/ws/ws.go ` + ` cmd/kode/ui/index.html ` )
114+
115+ - ** serve.go** : HTTP server with embedded WebSocket handler, ` @ ` resource API, session list API
116+ - ** ws/ws.go** : Zero-dependency RFC 6455 WebSocket (~ 200 LOC). Handles upgrade, text frames, close, ping/pong
117+ - ** ui/index.html** : Single-file SPA, ~ 770 LOC vanilla JS + CSS. Streaming, collapsible tool blocks, ` @ ` autocomplete, session sidebar
118+
119+ See [ docs/WEBUI.md] ( docs/WEBUI.md ) for the WebSocket protocol and full documentation.
120+
121+ ### Sub-agents (` cmd/kode/subagent.go ` + ` cmd/kode/subagent_tool.go ` )
122+
123+ - ** subagent.go** : CLI handler for ` kode subagent --goal <string> ` . Parses flags, creates agent, runs with minimal system prompt, outputs JSON to stdout
124+ - ** subagent_tool.go** : ` delegate_tasks ` built-in tool. Spawns real OS processes via ` exec.Command ` with temp files for task data
125+
126+ See [ docs/SUBAGENTS.md] ( docs/SUBAGENTS.md ) for full documentation.
75127
76128## Contributing
77129
0 commit comments