clew-code 0.2.27 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -19
- package/dist/main.js +2262 -2234
- package/docs/commands.html +3 -0
- package/docs/internals/long-term-memory-design.md +173 -89
- package/docs/js/main.js +438 -437
- package/docs/personal-profile.html +113 -0
- package/package.json +165 -165
package/docs/commands.html
CHANGED
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
<tr><td><code>/exit</code></td><td>Exit the REPL</td></tr>
|
|
38
38
|
<tr><td><code>/help</code></td><td>List all available commands</td></tr>
|
|
39
39
|
<tr><td><code>/resume</code></td><td>Resume a previous session</td></tr>
|
|
40
|
+
<tr><td><code>/profile</code></td><td>Switch between <strong>coding</strong> and <strong>personal</strong> profiles. Personal profile turns Clew into a personal AI control center with delegation, memory-driven learning, and skill creation. See <a href="personal-profile.html">Personal Profile</a>.</td></tr>
|
|
41
|
+
<tr><td><code>/maxmode on|off|candidates N</code></td><td>Toggle Max Mode — parallel N candidates via LLM judge</td></tr>
|
|
40
42
|
</tbody>
|
|
41
43
|
</table>
|
|
42
44
|
|
|
@@ -130,6 +132,7 @@
|
|
|
130
132
|
<tr><td><code>/memory stats</code></td><td>Activity density chart</td></tr>
|
|
131
133
|
<tr><td><code>/memory digest</code></td><td>Show weekly/monthly digests</td></tr>
|
|
132
134
|
<tr><td><code>/memory search</code></td><td>Search stored memory entries</td></tr>
|
|
135
|
+
<tr><td><code>/maxmode on|off|candidates N</code></td><td>Toggle Max Mode — parallel candidate selection via LLM judge</td></tr>
|
|
133
136
|
</tbody>
|
|
134
137
|
</table>
|
|
135
138
|
|
|
@@ -1,89 +1,173 @@
|
|
|
1
|
-
# Long-Term Memory System Implementation
|
|
2
|
-
|
|
3
|
-
## Architecture
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
~/.clew/projects/<project-root>/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
--
|
|
29
|
-
CREATE TABLE
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
--
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
|
83
|
-
|
|
84
|
-
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
# Long-Term Memory System Implementation
|
|
2
|
+
|
|
3
|
+
## Architecture
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
~/.clew/projects/<project-root>/
|
|
7
|
+
├── session-memory.db ← SQLite (bun:sqlite)
|
|
8
|
+
│ ├── sessions ← session records + consolidation level
|
|
9
|
+
│ ├── topic_index ← tag → session mapping
|
|
10
|
+
│ └── digests ← weekly/monthly summaries
|
|
11
|
+
├── memory/ ← Auto-memory directory (MEMORY.md + topic files)
|
|
12
|
+
│ ├── MEMORY.md ← Entrypoint, loaded into system prompt
|
|
13
|
+
│ └── ... ← Other markdown memory files
|
|
14
|
+
└── sessions/
|
|
15
|
+
└── <sessionId>/
|
|
16
|
+
└── checkpoints/ ← Structured checkpoint files
|
|
17
|
+
├── index.json ← Lightweight index
|
|
18
|
+
├── cycle.txt ← Current rebuild cycle number
|
|
19
|
+
├── notes.md ← Main agent's append-only scratchpad
|
|
20
|
+
├── 20-<id>.json ← 20% progress checkpoint
|
|
21
|
+
├── 45-<id>.json ← 45% progress checkpoint
|
|
22
|
+
└── 70-<id>.json ← 70% progress checkpoint (triggers MEMORY.md promotion)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Database Schema
|
|
26
|
+
|
|
27
|
+
```sql
|
|
28
|
+
-- Each session
|
|
29
|
+
CREATE TABLE sessions (
|
|
30
|
+
session_id TEXT PRIMARY KEY,
|
|
31
|
+
start_time INTEGER, end_time INTEGER,
|
|
32
|
+
model TEXT, provider TEXT,
|
|
33
|
+
summary TEXT,
|
|
34
|
+
key_decisions TEXT, -- JSON array
|
|
35
|
+
active_files TEXT, -- JSON array
|
|
36
|
+
tags TEXT, -- JSON array
|
|
37
|
+
consolidated INTEGER DEFAULT 0 -- 0=raw, 1=weekly, 2=monthly
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
-- Topic → session index
|
|
41
|
+
CREATE TABLE topic_index (
|
|
42
|
+
topic TEXT NOT NULL,
|
|
43
|
+
session_id TEXT NOT NULL,
|
|
44
|
+
PRIMARY KEY(topic, session_id)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
-- Weekly/monthly digests
|
|
48
|
+
CREATE TABLE digests (
|
|
49
|
+
period TEXT NOT NULL, -- '2026-W24' or '2026-06'
|
|
50
|
+
type TEXT NOT NULL, -- 'weekly' or 'monthly'
|
|
51
|
+
summary TEXT,
|
|
52
|
+
patterns TEXT, -- recurring patterns detected
|
|
53
|
+
session_count INTEGER,
|
|
54
|
+
created_at INTEGER,
|
|
55
|
+
PRIMARY KEY(period, type)
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Consolidation Flow
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
saveSessionSummary()
|
|
63
|
+
→ INSERT session (consolidated=0)
|
|
64
|
+
→ UPDATE topic_index
|
|
65
|
+
→ consolidateIfNeeded()
|
|
66
|
+
→ SELECT sessions WHERE consolidated=0 AND end_time < 7d ago
|
|
67
|
+
→ GROUP BY ISO week, then by month
|
|
68
|
+
→ Generate weekly digest (patterns from tags + decisions)
|
|
69
|
+
→ Mark sessions consolidated=1
|
|
70
|
+
→ Generate monthly digest from weekly digests
|
|
71
|
+
→ Mark sessions consolidated=2
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Layered Memory
|
|
75
|
+
|
|
76
|
+
Inspired by MiMo Code's 4-layer memory design. Each layer has a different lifecycle and persistence:
|
|
77
|
+
|
|
78
|
+
| Layer | Storage | Lifecycle | Written by |
|
|
79
|
+
|-------|---------|-----------|------------|
|
|
80
|
+
| Session | `checkpoints/<id>.json` | Per-session, cleared on session end | Checkpoint Writer (inline) |
|
|
81
|
+
| Notes | `checkpoints/notes.md` | Per-session, read + cleared at each checkpoint | Main agent (append-only) |
|
|
82
|
+
| Project | `memory/MEMORY.md` | Cross-session, persists indefinitely | Checkpoint Promoter (70%), autoDream, manual |
|
|
83
|
+
| Global | `MEMORY.md` at config root | Cross-project, persists indefinitely | autoDream, manual |
|
|
84
|
+
| History | SQLite (`session-memory.db`) | Permanent, append-only | Session Logger |
|
|
85
|
+
|
|
86
|
+
### Session Checkpoint
|
|
87
|
+
|
|
88
|
+
Triggered at 20%/45%/70% of goal's `maxTurns` budget. Written as fire-and-forget (`.catch(noop)`) so it never blocks the main loop.
|
|
89
|
+
|
|
90
|
+
Fields: goalText, turnCount, elapsedMs, filesModified, commandsRun, decisions, currentBlockers, nextSteps, summary, cycle, notes.
|
|
91
|
+
|
|
92
|
+
### Notes Scratchpad
|
|
93
|
+
|
|
94
|
+
`notes.md` is the main agent's **only** persistent write channel. The agent is told about it via system prompt when a goal is active. At each checkpoint, the writer reads notes and routes them into the structured checkpoint fields, then clears the scratchpad.
|
|
95
|
+
|
|
96
|
+
### Project Memory (MEMORY.md)
|
|
97
|
+
|
|
98
|
+
At the 70% checkpoint, the Checkpoint Promoter promotes stable information into `MEMORY.md`:
|
|
99
|
+
- Repeatedly modified files → "active files"
|
|
100
|
+
- Persistent decisions → "architecture decisions"
|
|
101
|
+
- Notes → "session notes"
|
|
102
|
+
|
|
103
|
+
Promotion is fire-and-forget (non-blocking).
|
|
104
|
+
|
|
105
|
+
### Goal Verifier
|
|
106
|
+
|
|
107
|
+
When the agent attempts to terminate with an active goal, an independent forked agent reviews the conversation against the goal text. If the goal isn't met, the gap is attached as `goalGap` in the result metadata. The verifier:
|
|
108
|
+
- Does **not** participate in actual work (no alignment bias)
|
|
109
|
+
- Receives the same context as the agent (actual tool outputs)
|
|
110
|
+
- Returns `{ isComplete, gap?, isImpossible? }`
|
|
111
|
+
- Failure is non-fatal — normal termination proceeds
|
|
112
|
+
|
|
113
|
+
## Files
|
|
114
|
+
|
|
115
|
+
| File | Purpose |
|
|
116
|
+
|------|---------|
|
|
117
|
+
| `src/services/longTermMemory/crossSession.ts` | Core: save, load, consolidate, topic index |
|
|
118
|
+
| `src/services/longTermMemory/timeline.ts` | Timeline queries, density stats, digest format |
|
|
119
|
+
| `src/services/longTermMemory/consolidate.ts` | Preview/save consolidation candidates |
|
|
120
|
+
| `src/services/longTermMemory/index.ts` | Barrel exports |
|
|
121
|
+
| `src/services/checkpoint/checkpointWriter.ts` | Structured checkpoint system + notes scratchpad + cycle tracking |
|
|
122
|
+
| `src/services/checkpoint/checkpointPromoter.ts` | Checkpoint → MEMORY.md promotion |
|
|
123
|
+
| `src/services/goal/goalVerifier.ts` | Independent goal completion verification |
|
|
124
|
+
| `src/services/maxMode/candidateRunner.ts` | Max Mode: parallel candidate selection with LLM judge |
|
|
125
|
+
| `src/commands/maxMode/maxMode.tsx` | `/maxmode` command (on/off/candidates N) |
|
|
126
|
+
|
|
127
|
+
## Checkpoint Flow
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
User turn → query() loop
|
|
131
|
+
↓
|
|
132
|
+
Turn count crosses threshold (20/45/70%)?
|
|
133
|
+
↓ yes
|
|
134
|
+
Extract decisions, commands, files from recent messages
|
|
135
|
+
↓
|
|
136
|
+
Read notes.md + current cycle
|
|
137
|
+
↓
|
|
138
|
+
Fire-and-forget writeCheckpoint() + clearNotes()
|
|
139
|
+
↓
|
|
140
|
+
If threshold === 70%: promoteCheckpoints() → append to MEMORY.md
|
|
141
|
+
↓
|
|
142
|
+
Continue query() loop
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Rebuild Cycle
|
|
146
|
+
|
|
147
|
+
When context window fills, compact runs `tryRebuildFromCheckpoint()`. If a checkpoint exists, it builds a **layered context prompt** instead of a flat summary:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
Goal + Progress Metadata
|
|
151
|
+
↓
|
|
152
|
+
Key Decisions + Files Modified + Commands Executed
|
|
153
|
+
↓
|
|
154
|
+
Accumulated Notes (from scratchpad)
|
|
155
|
+
↓
|
|
156
|
+
Phase Summary (if any)
|
|
157
|
+
↓
|
|
158
|
+
Current Blockers + Next Steps
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Each rebuild increments `cycle`, so the model can see it's in a continued session window.
|
|
162
|
+
|
|
163
|
+
## Commands
|
|
164
|
+
|
|
165
|
+
| Command | Action |
|
|
166
|
+
|---------|--------|
|
|
167
|
+
| `/memory save [summary]` | Save session + auto-consolidate old data |
|
|
168
|
+
| `/memory timeline` | Show chronological session history |
|
|
169
|
+
| `/memory stats` | Activity density chart |
|
|
170
|
+
| `/memory digest` | Show weekly/monthly digests |
|
|
171
|
+
| `/memory preview` | Preview sessions ready for consolidation |
|
|
172
|
+
| `/memory consolidate` | Mark old sessions as consolidated |
|
|
173
|
+
| `/maxmode on\|off\|candidates N` | Toggle parallel candidate selection |
|