Skip to content

Commit b3a0101

Browse files
author
goweft
committed
docs: update for sub-agent decomposition\n\nREADME:\n- Add internal/agent/ to architecture layout with one-line description\n- Extend DbC paragraph: name the three agents, explain shell→agent\n delegation and contract freeze/check lifecycle\n\nARCHITECTURE.md:\n- Update verified-against commit to 682c886\n- Add agent/ package to binary layout with agent descriptions\n- Expand llm/ note: called exclusively by agents and shell.handleChat\n- Replace request flow diagram: each KindCreate/Edit/Combine now shows\n agent name, pre/postcondition checks, and workspace operation\n- Rewrite DbC section: per-agent contract table with rules for each\n agent, note on 10% truncation guard in EditAgent
1 parent 682c886 commit b3a0101

2 files changed

Lines changed: 49 additions & 14 deletions

File tree

ARCHITECTURE.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CAS Architecture
22

33
**Last updated:** 2026-05-19
4-
**Verified against:** commit `1863de0`
4+
**Verified against:** commit `682c886`
55

66
---
77

@@ -26,6 +26,9 @@ cmd/cas/main.go Entry point. Wires store → shell → TUI and starts
2626
internal/
2727
intent/ detect.go Zero-latency regex classifier. Fires before any LLM
2828
call. Maps a user message to a Kind and workspace type.
29+
agent/ agent.go Named sub-agents with per-agent contracts. Three agents:
30+
GenerationAgent (create), EditAgent (edit), CombineAgent (combine).
31+
Shell delegates to agents; agents own all workspace LLM calls.
2932
contract/ contract.go Design by Contract enforcement. Pre/post/invariant
3033
checks on workspace operations. Fail-closed.
3134
workspace/ workspace.go Workspace type and lifecycle (create, update, close,
@@ -36,6 +39,7 @@ internal/
3639
and context-aware edit.
3740
llm/ llm.go Multi-provider LLM bridge. Streaming and non-streaming.
3841
Provider: CAS_PROVIDER env (ollama | anthropic | groq | openai | openrouter).
42+
Called exclusively by agents and shell.handleChat.
3943
store/ store.go Store interface (SessionStore).
4044
sqlite.go SQLiteStore — production persistence at ~/.cas/cas.db.
4145
memory.go MemoryStore — in-memory, used in tests.
@@ -62,14 +66,30 @@ tests/tui/ TUI integration tests. Spawn the real binary in tmux
6266
User message
6367
6468
65-
intent.Detect() ← regex only, no LLM call, no latency
69+
intent.Detect() ← regex only, no LLM call, no latency
6670
6771
├─ KindClose → workspace.Manager.Close()
6872
├─ KindRun → runner.Run(workspace.Content)
69-
├─ KindCombine → shell.handleCombine() + resolve.resolveAll()
70-
├─ KindEdit → contract check → llm.Stream() → workspace.Update()
71-
├─ KindCreate → contract check → llm.Stream() → workspace.Create()
72-
└─ KindChat → llm.Stream() → chat reply
73+
74+
├─ KindCreate → GenerationAgent
75+
│ contract.CheckPreconditions() ← wsType, prompt, title
76+
│ llm.Stream()
77+
│ contract.CheckPostconditions() ← non-empty, ≤512 KB
78+
│ workspace.Create()
79+
80+
├─ KindEdit → EditAgent
81+
│ contract.CheckPreconditions() ← wsType, content, request
82+
│ llm.Stream()
83+
│ contract.CheckPostconditions() ← non-empty, ≤512 KB, ≥10% original
84+
│ workspace.Update()
85+
86+
├─ KindCombine → CombineAgent
87+
│ contract.CheckPreconditions() ← ≥2 sources, all non-empty
88+
│ llm.Stream()
89+
│ contract.CheckPostconditions() ← non-empty, ≤512 KB
90+
│ workspace.Create()
91+
92+
└─ KindChat → llm.Stream() → chat reply (no agent, no workspace op)
7393
7494
7595
conductor.Observe() ← updates ~/.cas/profile.json
@@ -85,21 +105,32 @@ registered plugin prefix, the plugin handler fires and the flow short-circuits.
85105

86106
## Design by Contract
87107

88-
The contract package implements Bertrand Meyer's Design by Contract as the
89-
security primitive for workspace operations.
108+
The contract package implements Bertrand Meyer's Design by Contract (1988) as
109+
the security primitive for workspace operations.
90110

91111
Contracts are constructed and frozen before any LLM call. The model cannot
92112
see, modify, or reason about them. Violations are always fatal to the
93113
operation — no fallback, no retry, no LLM-assisted recovery. The three phases:
94114

95-
- **Preconditions** — checked before the operation starts (e.g. workspace type
96-
is allowed)
97-
- **Postconditions** — checked after the operation completes (e.g. content size
98-
within limit)
115+
- **Preconditions** — checked before the LLM call (e.g. workspace type allowed,
116+
prompt non-empty)
117+
- **Postconditions** — checked after the LLM call (e.g. content non-empty, size
118+
within limit, edit result not drastically shorter than original)
99119
- **Invariants** — structural rules that must always hold
100120

101-
`DefaultWorkspaceContract` is applied to all create/update operations.
102-
Callers extend it with operation-specific rules before freezing.
121+
Each agent constructs its own contract from `contract.New()`. The contract is
122+
frozen before the LLM call and cannot be modified by the agent or the model.
123+
124+
Per-agent contract rules:
125+
126+
| Agent | Preconditions | Postconditions |
127+
|-------------------|--------------------------------------------|---------------------------------------------|
128+
| GenerationAgent | wsType valid, prompt non-empty, title non-empty | content non-empty, ≤ 512 KB |
129+
| EditAgent | wsType valid, content non-empty, request non-empty | result non-empty, ≤ 512 KB, ≥ 10% of original |
130+
| CombineAgent | ≥ 2 sources, all sources non-empty | result non-empty, ≤ 512 KB |
131+
132+
The 10% truncation guard on EditAgent catches cases where the model returns
133+
only a fragment of the updated document instead of the full content.
103134

104135
---
105136

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ contract.CheckPostconditions() // did the output meet requirements?
8585

8686
Contracts run in Go, external to the model. The model cannot modify, bypass, or reason about them. Any violation fails the operation — fail-closed always. Based on Bertrand Meyer's Design by Contract (1988).
8787

88+
Each workspace operation is owned by a named agent (`GenerationAgent`, `EditAgent`, `CombineAgent`). Contracts are frozen before the LLM call and checked again after. The shell delegates to agents; agents never call each other.
89+
8890
### Three workspace types
8991

9092
| Type | Badge | Model (Ollama) | Model (Anthropic) | Model (Groq) | Model (OpenAI) | Model (OpenRouter) |
@@ -213,6 +215,8 @@ Full terminal editor via `charmbracelet/bubbles` textarea. All standard cursor m
213215
```
214216
internal/
215217
├── intent/ Zero-latency intent detection — regex, no LLM call
218+
├── agent/ Named sub-agents: GenerationAgent, EditAgent, CombineAgent
219+
│ Each owns one category of LLM call with a frozen contract
216220
├── contract/ Design by Contract enforcement, fail-closed
217221
├── workspace/ Lifecycle: create, update, undo, close, restore
218222
├── shell/ Session manager: ProcessMessage, StreamMessage

0 commit comments

Comments
 (0)