Skip to content

Commit 0b0afa4

Browse files
committed
feat: broaden scope-aware enrichment + add dream consolidation docs
- Task enricher now combines scope + queries for broader coverage - All constraints always included regardless of scope (not just scope-narrowed) - Add DREAM_CONSOLIDATION.md with mermaid sequence + flow diagrams
1 parent 22aa249 commit 0b0afa4

2 files changed

Lines changed: 89 additions & 3 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Dream Consolidation: Passive Knowledge Growth
2+
3+
## How It Works
4+
5+
```mermaid
6+
sequenceDiagram
7+
participant User
8+
participant Claude as AI Assistant
9+
participant Hook as session-end hook
10+
participant LLM as Fast LLM (cheap tier)
11+
participant KG as Knowledge Graph (SQLite)
12+
13+
User->>Claude: Work on tasks in a session
14+
Claude->>Claude: Complete task 1, task 2, task 3...
15+
16+
Note over User,Claude: Session ends (user closes, context full, or circuit breaker)
17+
18+
Claude->>Hook: hook session-end fires
19+
Hook->>Hook: Load session state (tasks_completed > 0?)
20+
21+
alt No tasks completed
22+
Hook->>Hook: Skip dream consolidation
23+
else Tasks were completed
24+
Hook->>Hook: Collect completion summaries from all completed tasks
25+
Hook->>LLM: "Extract architectural decisions, patterns, constraints from these completed tasks"
26+
LLM-->>Hook: JSON findings (type, title, description)
27+
28+
loop For each finding
29+
Hook->>KG: IngestFindings(source_agent="dream", confidence=0.6)
30+
KG->>KG: Dedup against existing nodes (similarity check)
31+
KG->>KG: Store new nodes or skip duplicates
32+
end
33+
34+
Hook-->>User: "Dream: extracted N knowledge items from session"
35+
end
36+
```
37+
38+
## Knowledge Flow
39+
40+
```mermaid
41+
flowchart TD
42+
subgraph "Manual (explicit)"
43+
B[tw bootstrap] --> |"Scan repo, call LLM agents"| KG[(Knowledge Graph)]
44+
R[/taskwing:remember/] --> |"User-initiated"| KG
45+
end
46+
47+
subgraph "Automatic (passive)"
48+
SE[Session End Hook] --> |"Analyze completed tasks"| D[Dream Consolidation]
49+
D --> |"source_agent=dream\nconfidence=0.6"| KG
50+
end
51+
52+
subgraph "Consumption"
53+
KG --> |"ask tool"| AI[AI Assistant Context]
54+
KG --> |"task enrichment"| TC[Task Context]
55+
KG --> |"FormatCompact()"| PC[Plan Context]
56+
end
57+
58+
style D fill:#9b59b6,color:#fff
59+
style KG fill:#3498db,color:#fff
60+
style B fill:#2ecc71,color:#fff
61+
```
62+
63+
## Confidence Tiers
64+
65+
| Source | Agent | Confidence | When |
66+
|---|---|---|---|
67+
| Bootstrap (LLM agents) | doc, code, deps, git | 0.8-1.0 | Explicit `tw bootstrap` run |
68+
| User-initiated | remember | 1.0 | User calls `/taskwing:remember` |
69+
| Dream consolidation | dream | 0.6 | Automatic at session end |
70+
71+
Dream findings have lower confidence because they're inferred from task completion summaries, not from direct code/doc evidence. They won't overwrite higher-confidence bootstrap findings during dedup (UpsertNodeBySummary preserves the higher-confidence version).
72+
73+
## What Gets Extracted
74+
75+
The dream prompt asks the LLM to identify:
76+
- **Decisions**: Technology choices made during the session ("chose Redis over Memcached for caching")
77+
- **Patterns**: Recurring approaches established ("all API handlers follow the middleware chain pattern")
78+
- **Constraints**: Rules discovered or enforced ("never deploy without running the security scan")
79+
80+
Only findings that would be valuable for **future sessions** are extracted. Implementation details, debugging steps, and ephemeral work are filtered by the LLM prompt.

internal/app/plan.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,26 @@ func (a *PlanApp) defaultTaskEnricher(ctx context.Context, queries []string, sco
174174

175175
ks := knowledge.NewService(a.ctx.Repo, a.ctx.LLMCfg)
176176

177-
// Build scope-aware query: prefer task queries, fall back to scope-based, then generic
177+
// Scope-aware query with broad project context as baseline.
178+
// The scope narrows the search, but constraints are always included
179+
// (IncludeConstraints=true) so the task always has the full project rules.
178180
var query string
179-
if len(queries) > 0 {
181+
if len(queries) > 0 && scope != "" {
182+
// Combine both: task-specific queries + scope for broader coverage
183+
query = strings.Join(queries, " ") + " " + scope
184+
} else if len(queries) > 0 {
180185
query = strings.Join(queries, " ")
181186
} else if scope != "" {
182187
query = scope + " patterns constraints decisions"
183188
} else {
184-
query = "project constraints and key technology decisions"
189+
query = "project architecture patterns constraints decisions"
185190
}
186191

187192
modelID := a.ctx.LLMCfg.Model
188193
opts := knowledge.DefaultContextOptionsForModel(modelID)
189194
opts.Query = query
190195
opts.IncludeArchitectureMD = false // Included selectively for first task
196+
opts.IncludeConstraints = true // Always include all constraints regardless of scope
191197
opts.UseLLMQueries = false // Use queries directly for speed
192198

193199
memoryPath, _ := config.GetMemoryBasePath()

0 commit comments

Comments
 (0)