Skip to content

Commit 8b4f6fe

Browse files
Use .drover settings paths and reorganize docs/worker contracts (#3)
* Use .drover settings paths and reorganize docs/worker contracts. Move settings to ~/.drover and .drover with legacy .claude fallback, relocate design specs to docs/adr, extract workercontract package, and add agent-context and environment-variables reference docs. Co-authored-by: Cursor <cursoragent@cursor.com> * chore: enable race detector and CRAP score quality gate * docs(adr): add required product and audience frontmatter The content check rejects these decision records because they have no opening frontmatter block. * test: drop Engine.Wait from the in-repo warden contract The public evaluator is synchronous, so the private engine's Wait no longer exists. These two tests were the only callers. --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0bc2051 commit 8b4f6fe

58 files changed

Lines changed: 1389 additions & 421 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Agent Context for Drover Code
1+
# Agent Context
2+
3+
> **Note to AI Agents:** The Diátaxis agent context also lives at [`docs/reference/agent-context.md`](docs/reference/agent-context.md).
24
35
Welcome, AI Agent. This file is intended to help AI coding assistants understand the structure, context, and conventions of the `drover-code` repository.
46

@@ -27,7 +29,7 @@ Welcome, AI Agent. This file is intended to help AI coding assistants understand
2729
| `internal/tools` | Tool registry and implementations |
2830
| `internal/tui` | Bubble Tea model and views |
2931
| `internal/dream` | Session memory (JSON / SQLite) |
30-
| `design/` | Design specs and roadmap (numbered `01-…`, test plan `13`, UX `14`) |
32+
| `docs/adr/` | Design specs and roadmap (numbered `01-…`, test plan `13`, UX `14`) |
3133
| `docs/` | User-facing docs (Tutorials, How-Tos, Reference, Explanation) |
3234

3335
## Build and test
@@ -45,7 +47,7 @@ Fuzz targets are listed in `.github/workflows/ci.yml` (`fuzz` job).
4547
## Conventions
4648

4749
- Prefer focused changes: match existing style, imports, and error wrapping in touched packages.
48-
- Property / fuzz tests: see `design/12-property-fuzz-testing.md` and doc `13-test-coverage-plan.md`.
50+
- Property / fuzz tests: see `docs/adr/12-property-fuzz-testing.md` and doc `13-test-coverage-plan.md`.
4951
- Do not assume Node: this is Go-only for the main binary.
5052

5153
## Product behavior pointers
@@ -75,7 +77,7 @@ The TUI was migrated from a god-model (~956–1290 LOC in model.go) to a proper
7577
- Guard hooks are real: `pkg/guardclient`, `assessPermissionRisk` (file + bash dangerous patterns), `GuardRiskLevel/Reason` on Model, StatusBar renders risk state.
7678

7779
**Migration history (important for future edits):**
78-
A safe dual-state period was used (legacy Model fields like m.history/m.activeTools/m.permPrompt lived alongside the component fields). All mutations hit both during transition. Once every call site + test was updated, legacy paths and fields were deleted in focused consolidation passes (HistoryView first, LiveRegion second, Permission + full permission.go deletion third). InputArea kept a lighter `syncInputArea()` bridge. Snapshots and 20+ history/fuzz/e2e tests never drifted. See `design/20-week-1-tui-component-migration.md` (Reality Record section) and beads dcode-001..009 for the full story.
80+
A safe dual-state period was used (legacy Model fields like m.history/m.activeTools/m.permPrompt lived alongside the component fields). All mutations hit both during transition. Once every call site + test was updated, legacy paths and fields were deleted in focused consolidation passes (HistoryView first, LiveRegion second, Permission + full permission.go deletion third). InputArea kept a lighter `syncInputArea()` bridge. Snapshots and 20+ history/fuzz/e2e tests never drifted. See `docs/adr/20-week-1-tui-component-migration.md` (Reality Record section) and beads dcode-001..009 for the full story.
7981

8082
When touching TUI code, prefer the component APIs. Update the component's isolated test + the integration snapshots. Do not re-introduce direct mutations on legacy fields that have been removed.
8183

‎README.md‎

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ Docs under `docs/` follow [Diátaxis](https://diataxis.fr/) and require YAML fro
2626
- [Integration Checklist](docs/how-to/integration-checklist.md)
2727

2828
**Reference (Information-oriented):**
29-
- [Agent Personas & Context](AGENTS.md)
29+
- [Agent Personas & Context](docs/reference/agent-context.md)
3030
- [Available Tools](docs/reference/available-tools.md)
31+
- [Environment Variables](docs/reference/environment-variables.md)
3132
- [Implementation Requirements](docs/reference/implementation-reqs.md)
3233
- [Requirements Index](docs/reference/requirements-index.md)
3334
- Requirements Summary (file not in repo)
@@ -37,26 +38,26 @@ Docs under `docs/` follow [Diátaxis](https://diataxis.fr/) and require YAML fro
3738
- [Architecture Overview](docs/explanation/architecture-overview.md)
3839
- [Unikraft Cloud Architecture](docs/explanation/unikraft-cloud.md)
3940

40-
**Design Specifications (`design/`):**
41-
- [01 Foundation](design/01-foundation.md)
42-
- [02 Agent Loop](design/02-agent-loop.md)
43-
- [03 Tools Overview](design/03-tools-overview.md)
44-
- [04 FS Tools](design/04-fs-tools.md)
45-
- [05 Shell Search Tools](design/05-shell-search-tools.md)
46-
- [06 Git Web Tools](design/06-git-web-tools.md)
47-
- [07 TUI](design/07-tui.md)
48-
- [08 Config & Permissions](design/08-config-permissions-undercover.md)
49-
- [09 Advanced Systems](design/09-advanced-systems.md)
50-
- [10 Integrations](design/10-integrations.md)
51-
- [11 Headless Orchestration](design/11-headless-orchestration.md)
52-
- [12 Property Fuzz Testing](design/12-property-fuzz-testing.md)
53-
- [13 Test Coverage Plan](design/13-test-coverage-plan.md)
54-
- [14 UX Memory Improvements](design/14-ux-memory-improvements.md)
55-
- [15 UKC Tools](design/15-ukc-tools.md)
56-
- [16 UKC Workspace Sync](design/16-ukc-workspace-sync.md)
57-
- [17 Custom Commands](design/17-custom-commands.md)
58-
- [Claude Go Design Spec](design/claude-go-design-spec.md)
59-
- [Claude Go Test Spec](design/claude-go-test-spec.md)
41+
**Architecture Decision Records (`docs/adr/`):**
42+
- [01 Foundation](docs/adr/01-foundation.md)
43+
- [02 Agent Loop](docs/adr/02-agent-loop.md)
44+
- [03 Tools Overview](docs/adr/03-tools-overview.md)
45+
- [04 FS Tools](docs/adr/04-fs-tools.md)
46+
- [05 Shell Search Tools](docs/adr/05-shell-search-tools.md)
47+
- [06 Git Web Tools](docs/adr/06-git-web-tools.md)
48+
- [07 TUI](docs/adr/07-tui.md)
49+
- [08 Config & Permissions](docs/adr/08-config-permissions-undercover.md)
50+
- [09 Advanced Systems](docs/adr/09-advanced-systems.md)
51+
- [10 Integrations](docs/adr/10-integrations.md)
52+
- [11 Headless Orchestration](docs/adr/11-headless-orchestration.md)
53+
- [12 Property Fuzz Testing](docs/adr/12-property-fuzz-testing.md)
54+
- [13 Test Coverage Plan](docs/adr/13-test-coverage-plan.md)
55+
- [14 UX Memory Improvements](docs/adr/14-ux-memory-improvements.md)
56+
- [15 UKC Tools](docs/adr/15-ukc-tools.md)
57+
- [16 UKC Workspace Sync](docs/adr/16-ukc-workspace-sync.md)
58+
- [17 Custom Commands](docs/adr/17-custom-commands.md)
59+
- [Claude Go Design Spec](docs/adr/claude-go-design-spec.md)
60+
- [Claude Go Test Spec](docs/adr/claude-go-test-spec.md)
6061

6162
## Requirements
6263

@@ -133,7 +134,7 @@ export CLAUDE_CODE_COORDINATOR_MODE=1
133134
export ANTHROPIC_MODEL=claude-haiku-4-5-20251001
134135
```
135136

136-
or `"model"` in `~/.claude/settings.json` or `.claude/settings.json`.
137+
or `"model"` in `~/.drover/settings.json` or `.drover/settings.json`.
137138

138139
## Other LLM providers (Moonshot, GLM, SGLang / DeepSeek, …)
139140

@@ -143,11 +144,11 @@ drover-code speaks **Anthropic Messages** by default, and **OpenAI Chat Completi
143144

144145
## Configuration
145146

146-
Settings merge in order:
147+
Settings merge in order (legacy `~/.claude` / `.claude` paths at each tier are still read when present; drover wins at the same tier):
147148

148-
1. `~/.claude/settings.json`
149-
2. `<workdir>/.claude/settings.json`
150-
3. `<workdir>/.claude/settings.local.json`
149+
1. `~/.drover/settings.json`
150+
2. `<workdir>/.drover/settings.json`
151+
3. `<workdir>/.drover/settings.local.json`
151152

152153
`CLAUDE.md` files under the working tree are concatenated and injected into the system prompt.
153154

‎cmd/drover-code/envutil.go‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,28 @@ func envIntPositive(key string) int {
3434
return n
3535
}
3636

37-
// anthropicAPIKey returns the first non-empty of ANTHROPIC_API_KEY or
38-
// ANTHROPIC_AUTH_TOKEN (Moonshot/Kimi and some other shims use the latter).
37+
// anthropicAPIKey returns the first non-empty API key from the environment.
38+
// It checks Anthropic, Gemini, and OpenAI keys to support API gateways.
3939
func anthropicAPIKey() string {
40-
if v := strings.TrimSpace(os.Getenv("ANTHROPIC_API_KEY")); v != "" {
41-
return v
40+
keys := []string{
41+
"ANTHROPIC_API_KEY",
42+
"ANTHROPIC_AUTH_TOKEN",
43+
"GEMINI_API_KEY",
44+
"OPENAI_API_KEY",
4245
}
43-
return strings.TrimSpace(os.Getenv("ANTHROPIC_AUTH_TOKEN"))
46+
for _, k := range keys {
47+
if v := strings.TrimSpace(os.Getenv(k)); v != "" {
48+
return v
49+
}
50+
}
51+
return ""
4452
}
4553

4654
func requireAnthropicAPIKey() string {
4755
if k := anthropicAPIKey(); k != "" {
4856
return k
4957
}
50-
fmt.Fprintln(os.Stderr, "error: set ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN")
58+
fmt.Fprintln(os.Stderr, "error: set ANTHROPIC_API_KEY, GEMINI_API_KEY, or OPENAI_API_KEY")
5159
os.Exit(2)
5260
return ""
5361
}

‎cmd/ukc-agent/exec.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"net/http"
12+
"os"
1213
"os/exec"
1314
"sync"
1415
"time"
@@ -65,7 +66,11 @@ func (jr *jobRunner) runCommand(parent context.Context, j *job, command string)
6566
defer cancel()
6667

6768
cmd := exec.CommandContext(ctx, "/bin/sh", "-c", command)
68-
cmd.Dir = "/workspace"
69+
if dir := os.Getenv("UKC_AGENT_WORKSPACE"); dir != "" {
70+
cmd.Dir = dir
71+
} else {
72+
cmd.Dir = "/workspace"
73+
}
6974
stdout, err := cmd.StdoutPipe()
7075
if err != nil {
7176
j.emitThenClose(err.Error(), 1)

‎cmd/ukc-agent/exec_test.go‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"net/http/httptest"
7+
"strings"
8+
"testing"
9+
"time"
10+
)
11+
12+
func TestStreamReplay_LastEventID(t *testing.T) {
13+
jr := newJobRunner("")
14+
id := randomID()
15+
16+
// Create a dummy job with history
17+
j := &job{
18+
id: id,
19+
history: make([]map[string]any, 0, 64),
20+
listeners: make([]chan struct{}, 0),
21+
}
22+
jr.jobs[id] = j
23+
24+
j.trySend(map[string]any{"line": "hello"})
25+
j.trySend(map[string]any{"line": "world"})
26+
j.trySend(map[string]any{"done": true, "exit_code": 0})
27+
28+
// Test requesting from event 1 (skipping "hello", fetching "world" and "done")
29+
req := httptest.NewRequest(http.MethodGet, "/stream", nil)
30+
req.Header.Set("Last-Event-ID", "0")
31+
rec := httptest.NewRecorder()
32+
33+
err := jr.streamSSE(rec, req, id)
34+
if err != nil {
35+
t.Fatalf("streamSSE error: %v", err)
36+
}
37+
38+
out := rec.Body.String()
39+
if strings.Contains(out, "hello") {
40+
t.Fatalf("expected hello to be skipped, got: %s", out)
41+
}
42+
if !strings.Contains(out, "world") {
43+
t.Fatalf("expected world, got: %s", out)
44+
}
45+
}
46+
47+
func TestStreamReplay_GapWarning(t *testing.T) {
48+
jr := newJobRunner("")
49+
id := randomID()
50+
51+
j := &job{
52+
id: id,
53+
history: make([]map[string]any, 0, 64),
54+
listeners: make([]chan struct{}, 0),
55+
baseIndex: 50, // simulate that events 0-49 were evicted
56+
}
57+
jr.jobs[id] = j
58+
59+
j.trySend(map[string]any{"line": "late event"})
60+
j.trySend(map[string]any{"done": true, "exit_code": 0})
61+
62+
// Requesting from event 0, but base is 50, so gap warning should be emitted
63+
req := httptest.NewRequest(http.MethodGet, "/stream", nil)
64+
req.Header.Set("Last-Event-ID", "0")
65+
rec := httptest.NewRecorder()
66+
67+
err := jr.streamSSE(rec, req, id)
68+
if err != nil {
69+
t.Fatalf("streamSSE error: %v", err)
70+
}
71+
72+
out := rec.Body.String()
73+
if !strings.Contains(out, "stream replay gap") {
74+
t.Fatalf("expected gap warning, got: %s", out)
75+
}
76+
if !strings.Contains(out, "late event") {
77+
t.Fatalf("expected late event, got: %s", out)
78+
}
79+
}
80+
81+
func TestStreamReplay_LiveReconnection(t *testing.T) {
82+
jr := newJobRunner("")
83+
tmpDir := t.TempDir()
84+
t.Setenv("UKC_AGENT_WORKSPACE", tmpDir)
85+
id := jr.start(context.Background(), "echo 'first'; sleep 0.1; echo 'second'")
86+
87+
// First connection: read "first", then disconnect
88+
ctx, cancel1 := context.WithCancel(context.Background())
89+
req1, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/stream", nil)
90+
rec1 := httptest.NewRecorder()
91+
92+
// We want to stream until we see "first", then cancel the context to simulate disconnect
93+
go func() {
94+
// Read body manually instead of streamSSE to interleave properly
95+
time.Sleep(50 * time.Millisecond)
96+
cancel1()
97+
}()
98+
99+
_ = jr.streamSSE(rec1, req1, id) // this will return context.Canceled
100+
101+
// Second connection: read the rest
102+
req2 := httptest.NewRequest(http.MethodGet, "/stream", nil)
103+
rec2 := httptest.NewRecorder()
104+
_ = jr.streamSSE(rec2, req2, id)
105+
106+
out := rec2.Body.String()
107+
108+
// We might get "first" again if we didn't use Last-Event-ID, but we should definitely get "second"
109+
if !strings.Contains(out, "second") {
110+
t.Fatalf("expected second to arrive in the stream: %s", out)
111+
}
112+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
---
2+
title: "01 — Foundation: Types, API Client, and Streaming"
3+
description: "Architecture decision record: 01 — Foundation: Types, API Client, and Streaming."
4+
product: drover-code
5+
audience: platform-operator
6+
doc_type: adr
7+
topics:
8+
- agent-jobs
9+
surface: repo-docs
10+
---
11+
112
# 01 — Foundation: Types, API Client, and Streaming
213

314
**Package:** `internal/api`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
---
2+
title: "02 — Agent Loop: Conversation Manager, Agent Loop, and Event System"
3+
description: "Architecture decision record: 02 — Agent Loop: Conversation Manager, Agent Loop, and Event System."
4+
product: drover-code
5+
audience: platform-operator
6+
doc_type: adr
7+
topics:
8+
- agent-jobs
9+
surface: repo-docs
10+
---
11+
112
# 02 — Agent Loop: Conversation Manager, Agent Loop, and Event System
213

314
**Packages:** `internal/convo`, `internal/agent`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
---
2+
title: "03 — Tools Overview: Interface, Registry, and toolutil"
3+
description: "Architecture decision record: 03 — Tools Overview: Interface, Registry, and toolutil."
4+
product: drover-code
5+
audience: platform-operator
6+
doc_type: adr
7+
topics:
8+
- agent-jobs
9+
surface: repo-docs
10+
---
11+
112
# 03 — Tools Overview: Interface, Registry, and toolutil
213

314
**Packages:** `internal/tools`, `internal/tools/toolutil`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
---
2+
title: "04 — File System Tools"
3+
description: "Architecture decision record: 04 — File System Tools."
4+
product: drover-code
5+
audience: platform-operator
6+
doc_type: adr
7+
topics:
8+
- agent-jobs
9+
surface: repo-docs
10+
---
11+
112
# 04 — File System Tools
213

314
**Package:** `internal/tools/fs`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
---
2+
title: "05 — Shell and Search Tools: bash, glob, grep"
3+
description: "Architecture decision record: 05 — Shell and Search Tools: bash, glob, grep."
4+
product: drover-code
5+
audience: platform-operator
6+
doc_type: adr
7+
topics:
8+
- agent-jobs
9+
surface: repo-docs
10+
---
11+
112
# 05 — Shell and Search Tools: bash, glob, grep
213

314
**Package:** `internal/tools/shell`, `internal/tools/search`

0 commit comments

Comments
 (0)