Skip to content

Commit c018a16

Browse files
committed
Document Web client and sub-agent system
New docs: - docs/WEBUI.md — kode serve: architecture, features (@ completion, sessions, streaming), WebSocket protocol, flags, implementation details - docs/SUBAGENTS.md — task decomposition: architecture diagram, when to decompose, delegate_tasks tool schema, kode subagent CLI, output protocol, system prompt, security model, testing layers, E2E flow Updated docs: - README.md — link to WEBUI.md + SUBAGENTS.md, quick ref entries - docs/CLI.md — serve + subagent in commands table - docs/CONFIG.md — subagent config section with table - docs/DEVELOPMENT.md — full source layout, test layers, key packages
1 parent d6cc1e3 commit c018a16

6 files changed

Lines changed: 578 additions & 39 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ kode run --learn "Set up a Go project with CI"
8484
| **Multi-Turn Sessions** | [docs/SESSIONS.md](docs/SESSIONS.md) — save, continue, list, trim, cleanup |
8585
| **Sandboxing** | [docs/SANDBOXING.md](docs/SANDBOXING.md) — Docker isolation, security, config |
8686
| **Security** | [docs/SECURITY.md](docs/SECURITY.md) — prompt injection, sandbox model |
87+
| **Web UI** | [docs/WEBUI.md](docs/WEBUI.md)`kode serve`, WebSocket protocol, `@` resource completion |
88+
| **Sub-Agents** | [docs/SUBAGENTS.md](docs/SUBAGENTS.md) — task decomposition, parallel OS-process sub-agents |
8789
| **Skills** | [docs/CLI.md#skills](docs/CLI.md#skills) — learn, list, save, import, curate |
8890
| **Development** | [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) — building, testing, contributing |
8991

@@ -105,6 +107,8 @@ kode skill view <name> # View a skill
105107
kode skill delete <name> # Delete a skill
106108
kode skill import <uri> [--basic --yes] # Import skill from URI
107109
kode skill curate # Quality/overlap audit
110+
kode serve [--addr :8080] [--open] # Web UI server
111+
kode subagent --goal <string> [flags] # Run a focused sub-task (JSON stdout)
108112
kode init [--global] [--force] # Create config file
109113
kode version # Print version
110114

docs/CLI.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
| `kode skill delete <name>` | Delete a skill |
2020
| `kode skill import <uri> [flags]` | Import a skill from file:// or https:// |
2121
| `kode skill curate` | Analyze skills for quality, staleness, trigger overlap |
22+
| `kode serve [--addr :8080] [--open]` | Web UI server with WebSocket streaming, `@` resource completion, session history |
23+
| `kode subagent --goal <string> [flags]` | Run a focused sub-task; outputs JSON on stdout. Spawned by `delegate_tasks` tool |
2224
| `kode init [--global] [--force]` | Create a config file template |
2325
| `kode version` | Print version and exit |
2426

docs/CONFIG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,28 @@ The `skills` section controls the skill system:
110110
| `curation.staleness_days` || 90 | Days without use before flagging as stale |
111111
| `curation.auto_prune` || false | Auto-delete stale skills on curate (no prompt) |
112112

113+
## Sub-agent configuration
114+
115+
The `subagent` section controls task decomposition and parallel sub-agent execution (see [docs/SUBAGENTS.md](docs/SUBAGENTS.md)):
116+
117+
```json
118+
{
119+
"subagent": {
120+
"max_concurrency": 3,
121+
"timeout_seconds": 120,
122+
"max_iterations": 15
123+
}
124+
}
125+
```
126+
127+
| Field | Default | Description |
128+
|-------|---------|-------------|
129+
| `max_concurrency` | 3 | Max sub-agents running in parallel (max 8) |
130+
| `timeout_seconds` | 120 | Default timeout per sub-agent (overridden by `--timeout`) |
131+
| `max_iterations` | 15 | Default max think→act cycles per sub-agent (overridden by `--max-iter`) |
132+
133+
This section is optional. Omitted fields inherit sensible defaults.
134+
113135
## kode init
114136

115137
Create a config file template:
@@ -142,6 +164,9 @@ KODE_SANDBOX=true kode run "run untrusted script"
142164
# Enable skill learning via env var
143165
KODE_SKILLS_LEARN=true kode run "set up CI"
144166

167+
# Sub-agent config (project-level)
168+
echo '{"subagent": {"max_concurrency": 5, "timeout_seconds": 300}}' > ./kode.json
169+
145170
# CLI flag always wins
146171
kode run --model gpt-4o --base-url https://api.openai.com/v1 "task"
147172
```

docs/DEVELOPMENT.md

Lines changed: 91 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,89 @@
1111
go 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
2175
go 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

2487
Zero 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

Comments
 (0)