@oyasmi/pipiclaw 0.5.1 → 0.5.3
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 +308 -209
- package/dist/agent/channel-runner.d.ts +47 -0
- package/dist/agent/channel-runner.js +441 -0
- package/dist/agent/index.d.ts +3 -0
- package/dist/agent/index.js +2 -0
- package/dist/agent/progress-formatter.d.ts +4 -0
- package/dist/agent/progress-formatter.js +52 -0
- package/dist/agent/run-queue.d.ts +7 -0
- package/dist/agent/run-queue.js +26 -0
- package/dist/agent/runner-factory.d.ts +3 -0
- package/dist/agent/runner-factory.js +10 -0
- package/dist/agent/session-events.d.ts +14 -0
- package/dist/agent/session-events.js +215 -0
- package/dist/agent/session-resource-gate.d.ts +10 -0
- package/dist/agent/session-resource-gate.js +44 -0
- package/dist/agent/type-guards.d.ts +22 -0
- package/dist/agent/type-guards.js +106 -0
- package/dist/agent/types.d.ts +160 -0
- package/dist/agent/types.js +22 -0
- package/dist/agent.d.ts +2 -16
- package/dist/agent.js +1 -782
- package/dist/command-extension.d.ts +0 -1
- package/dist/command-extension.js +0 -1
- package/dist/commands.d.ts +0 -1
- package/dist/commands.js +0 -1
- package/dist/config-loader.d.ts +0 -1
- package/dist/config-loader.js +1 -2
- package/dist/context.d.ts +58 -15
- package/dist/context.js +50 -8
- package/dist/index.d.ts +12 -13
- package/dist/index.js +12 -13
- package/dist/log.d.ts +0 -1
- package/dist/log.js +0 -1
- package/dist/main.d.ts +0 -1
- package/dist/main.js +5 -405
- package/dist/memory/bootstrap.d.ts +6 -0
- package/dist/memory/bootstrap.js +46 -0
- package/dist/{memory-candidates.d.ts → memory/candidates.d.ts} +1 -1
- package/dist/{memory-candidates.js → memory/candidates.js} +33 -21
- package/dist/memory/chinese-words.d.ts +1 -0
- package/dist/memory/chinese-words.js +273 -0
- package/dist/{memory-consolidation.d.ts → memory/consolidation.d.ts} +0 -1
- package/dist/{memory-consolidation.js → memory/consolidation.js} +26 -35
- package/dist/{memory-files.d.ts → memory/files.d.ts} +0 -6
- package/dist/{memory-files.js → memory/files.js} +11 -36
- package/dist/{memory-lifecycle.d.ts → memory/lifecycle.d.ts} +23 -6
- package/dist/memory/lifecycle.js +246 -0
- package/dist/{memory-recall.d.ts → memory/recall.d.ts} +2 -2
- package/dist/memory/recall.js +501 -0
- package/dist/{session-memory.d.ts → memory/session.d.ts} +1 -1
- package/dist/{session-memory.js → memory/session.js} +31 -62
- package/dist/model-utils.d.ts +0 -1
- package/dist/model-utils.js +0 -1
- package/dist/paths.d.ts +0 -1
- package/dist/paths.js +0 -1
- package/dist/prompt-builder.d.ts +0 -1
- package/dist/prompt-builder.js +0 -1
- package/dist/runtime/bootstrap.d.ts +47 -0
- package/dist/runtime/bootstrap.js +450 -0
- package/dist/{delivery.d.ts → runtime/delivery.d.ts} +0 -1
- package/dist/{delivery.js → runtime/delivery.js} +1 -2
- package/dist/{dingtalk.d.ts → runtime/dingtalk.d.ts} +10 -1
- package/dist/{dingtalk.js → runtime/dingtalk.js} +87 -28
- package/dist/{events.d.ts → runtime/events.d.ts} +0 -1
- package/dist/{events.js → runtime/events.js} +1 -2
- package/dist/{store.d.ts → runtime/store.d.ts} +5 -1
- package/dist/{store.js → runtime/store.js} +60 -20
- package/dist/sandbox.d.ts +0 -1
- package/dist/sandbox.js +1 -2
- package/dist/{llm-json.d.ts → shared/llm-json.d.ts} +0 -1
- package/dist/{llm-json.js → shared/llm-json.js} +0 -1
- package/dist/shared/markdown-sections.d.ts +6 -0
- package/dist/{markdown-sections.js → shared/markdown-sections.js} +10 -4
- package/dist/{shell-escape.d.ts → shared/shell-escape.d.ts} +0 -1
- package/dist/{shell-escape.js → shared/shell-escape.js} +0 -1
- package/dist/shared/text-utils.d.ts +9 -0
- package/dist/shared/text-utils.js +36 -0
- package/dist/shared/type-guards.d.ts +5 -0
- package/dist/shared/type-guards.js +12 -0
- package/dist/shared/types.d.ts +14 -0
- package/dist/shared/types.js +1 -0
- package/dist/sidecar-worker.d.ts +0 -1
- package/dist/sidecar-worker.js +1 -8
- package/dist/{sub-agents.d.ts → subagents/discovery.d.ts} +0 -1
- package/dist/{sub-agents.js → subagents/discovery.js} +2 -3
- package/dist/{tools/subagent.d.ts → subagents/tool.d.ts} +2 -16
- package/dist/{tools/subagent.js → subagents/tool.js} +16 -38
- package/dist/tools/attach.d.ts +0 -1
- package/dist/tools/attach.js +0 -1
- package/dist/tools/bash.d.ts +0 -1
- package/dist/tools/bash.js +0 -1
- package/dist/tools/edit.d.ts +0 -1
- package/dist/tools/edit.js +1 -2
- package/dist/tools/index.d.ts +1 -2
- package/dist/tools/index.js +1 -2
- package/dist/tools/read.d.ts +0 -1
- package/dist/tools/read.js +1 -2
- package/dist/tools/truncate.d.ts +0 -1
- package/dist/tools/truncate.js +0 -1
- package/dist/tools/write-content.d.ts +0 -1
- package/dist/tools/write-content.js +1 -2
- package/dist/tools/write.d.ts +0 -1
- package/dist/tools/write.js +0 -1
- package/package.json +9 -3
- package/CHANGELOG.md +0 -47
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js.map +0 -1
- package/dist/command-extension.d.ts.map +0 -1
- package/dist/command-extension.js.map +0 -1
- package/dist/commands.d.ts.map +0 -1
- package/dist/commands.js.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js.map +0 -1
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js.map +0 -1
- package/dist/delivery.d.ts.map +0 -1
- package/dist/delivery.js.map +0 -1
- package/dist/dingtalk.d.ts.map +0 -1
- package/dist/dingtalk.js.map +0 -1
- package/dist/events.d.ts.map +0 -1
- package/dist/events.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/llm-json.d.ts.map +0 -1
- package/dist/llm-json.js.map +0 -1
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js.map +0 -1
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/markdown-sections.d.ts +0 -6
- package/dist/markdown-sections.d.ts.map +0 -1
- package/dist/markdown-sections.js.map +0 -1
- package/dist/memory-candidates.d.ts.map +0 -1
- package/dist/memory-candidates.js.map +0 -1
- package/dist/memory-consolidation.d.ts.map +0 -1
- package/dist/memory-consolidation.js.map +0 -1
- package/dist/memory-files.d.ts.map +0 -1
- package/dist/memory-files.js.map +0 -1
- package/dist/memory-lifecycle.d.ts.map +0 -1
- package/dist/memory-lifecycle.js +0 -150
- package/dist/memory-lifecycle.js.map +0 -1
- package/dist/memory-recall.d.ts.map +0 -1
- package/dist/memory-recall.js +0 -218
- package/dist/memory-recall.js.map +0 -1
- package/dist/model-utils.d.ts.map +0 -1
- package/dist/model-utils.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/prompt-builder.d.ts.map +0 -1
- package/dist/prompt-builder.js.map +0 -1
- package/dist/sandbox.d.ts.map +0 -1
- package/dist/sandbox.js.map +0 -1
- package/dist/session-memory-files.d.ts +0 -2
- package/dist/session-memory-files.d.ts.map +0 -1
- package/dist/session-memory-files.js +0 -2
- package/dist/session-memory-files.js.map +0 -1
- package/dist/session-memory.d.ts.map +0 -1
- package/dist/session-memory.js.map +0 -1
- package/dist/shell-escape.d.ts.map +0 -1
- package/dist/shell-escape.js.map +0 -1
- package/dist/sidecar-worker.d.ts.map +0 -1
- package/dist/sidecar-worker.js.map +0 -1
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/sub-agents.d.ts.map +0 -1
- package/dist/sub-agents.js.map +0 -1
- package/dist/tools/attach.d.ts.map +0 -1
- package/dist/tools/attach.js.map +0 -1
- package/dist/tools/bash.d.ts.map +0 -1
- package/dist/tools/bash.js.map +0 -1
- package/dist/tools/edit.d.ts.map +0 -1
- package/dist/tools/edit.js.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/read.d.ts.map +0 -1
- package/dist/tools/read.js.map +0 -1
- package/dist/tools/subagent.d.ts.map +0 -1
- package/dist/tools/subagent.js.map +0 -1
- package/dist/tools/truncate.d.ts.map +0 -1
- package/dist/tools/truncate.js.map +0 -1
- package/dist/tools/write-content.d.ts.map +0 -1
- package/dist/tools/write-content.js.map +0 -1
- package/dist/tools/write.d.ts.map +0 -1
- package/dist/tools/write.js.map +0 -1
- package/docs/improve-memory/design.md +0 -537
- package/docs/improve-memory/interfaces-and-tests.md +0 -473
- package/docs/improve-memory/spec.md +0 -357
- package/docs/memory-rfc.md +0 -297
- package/docs/proj-review.md +0 -188
- package/docs/subagent/pi-subagent-analyse.txt +0 -190
- package/docs/subagent/pi-subagent-design.txt +0 -266
- package/docs/subagent/pi-subagent-phase1-plan.txt +0 -529
- package/docs/test-supplementation-plan.md +0 -553
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
# Pipiclaw Context Upgrade Spec
|
|
2
|
-
|
|
3
|
-
## Status
|
|
4
|
-
|
|
5
|
-
Draft
|
|
6
|
-
|
|
7
|
-
## Purpose
|
|
8
|
-
|
|
9
|
-
This spec defines the next-stage context architecture for `pipiclaw`.
|
|
10
|
-
|
|
11
|
-
It extends the existing [memory RFC](/Users/oyasmi/projects/pipiclaw/docs/memory-rfc.md) rather than replacing it wholesale.
|
|
12
|
-
|
|
13
|
-
The primary goal is not "more memory files". The goal is to materially improve:
|
|
14
|
-
|
|
15
|
-
1. cross-turn continuity
|
|
16
|
-
2. long-task stability
|
|
17
|
-
3. compaction resilience
|
|
18
|
-
4. sub-agent usefulness
|
|
19
|
-
5. skill usefulness in a long-running DingTalk channel workspace
|
|
20
|
-
|
|
21
|
-
The design remains file-based and runtime-local. It does not introduce embeddings, vector search, or a dedicated memory database.
|
|
22
|
-
|
|
23
|
-
## Problems To Solve
|
|
24
|
-
|
|
25
|
-
The current model is good enough to persist durable facts, but still leaves several gaps:
|
|
26
|
-
|
|
27
|
-
1. `MEMORY.md` and `HISTORY.md` are available but not proactively surfaced, so the model often fails to use them at the right time.
|
|
28
|
-
2. "current working state" is mixed into durable memory and is therefore either too weak, too stale, or too noisy.
|
|
29
|
-
3. compaction happens with only indirect help from memory consolidation, which is weaker than having an explicit working-state artifact.
|
|
30
|
-
4. sub-agents are context-isolated, but there is no standard way to give them the most relevant channel memory automatically.
|
|
31
|
-
5. skills are loaded, but they do not yet participate in a richer lifecycle where memory and runtime hooks reinforce one another.
|
|
32
|
-
|
|
33
|
-
## Non-Goals
|
|
34
|
-
|
|
35
|
-
1. No vector retrieval, embedding index, semantic database, or memory plugin framework.
|
|
36
|
-
2. No special standalone `memory_search` tool for the model.
|
|
37
|
-
3. No automatic mutation of workspace-level `SOUL.md`, `AGENTS.md`, or workspace `MEMORY.md`.
|
|
38
|
-
4. No proactive scanning of `log.jsonl` or `context.jsonl` as normal memory inputs.
|
|
39
|
-
5. No attempt to clone the full `claude-code` agent OS, swarm runtime, or prompt-cache infrastructure in this phase.
|
|
40
|
-
|
|
41
|
-
## Context Layers
|
|
42
|
-
|
|
43
|
-
The upgraded context model has five layers.
|
|
44
|
-
|
|
45
|
-
### 1. Identity Layer
|
|
46
|
-
|
|
47
|
-
- `workspace/SOUL.md`
|
|
48
|
-
- `workspace/AGENTS.md`
|
|
49
|
-
|
|
50
|
-
Semantics:
|
|
51
|
-
|
|
52
|
-
- loaded into session context at session start
|
|
53
|
-
- human-managed
|
|
54
|
-
- authoritative
|
|
55
|
-
- not rewritten by runtime maintenance
|
|
56
|
-
|
|
57
|
-
### 2. Shared Durable Memory
|
|
58
|
-
|
|
59
|
-
- `workspace/MEMORY.md`
|
|
60
|
-
|
|
61
|
-
Semantics:
|
|
62
|
-
|
|
63
|
-
- stable shared background
|
|
64
|
-
- read on demand
|
|
65
|
-
- not auto-rewritten by runtime
|
|
66
|
-
|
|
67
|
-
### 3. Channel Durable Memory
|
|
68
|
-
|
|
69
|
-
- `<channel>/MEMORY.md`
|
|
70
|
-
|
|
71
|
-
Semantics:
|
|
72
|
-
|
|
73
|
-
- durable facts, decisions, preferences, constraints, medium-horizon open loops
|
|
74
|
-
- append-first, then cleanup/fold
|
|
75
|
-
- channel-scoped
|
|
76
|
-
- runtime-managed
|
|
77
|
-
|
|
78
|
-
Important change:
|
|
79
|
-
|
|
80
|
-
`MEMORY.md` is no longer the primary owner of minute-by-minute "what am I doing right now" state. It may still contain open loops, but detailed active execution state belongs to `SESSION.md`.
|
|
81
|
-
|
|
82
|
-
### 4. Channel Working Memory
|
|
83
|
-
|
|
84
|
-
- `<channel>/SESSION.md`
|
|
85
|
-
|
|
86
|
-
Semantics:
|
|
87
|
-
|
|
88
|
-
- current task state
|
|
89
|
-
- active files and commands
|
|
90
|
-
- current hypotheses and next steps
|
|
91
|
-
- recent important errors and corrections
|
|
92
|
-
- channel-scoped handoff artifact across sessions and compactions
|
|
93
|
-
- runtime-managed
|
|
94
|
-
|
|
95
|
-
This is the major addition in this spec.
|
|
96
|
-
|
|
97
|
-
### 5. Channel History
|
|
98
|
-
|
|
99
|
-
- `<channel>/HISTORY.md`
|
|
100
|
-
|
|
101
|
-
Semantics:
|
|
102
|
-
|
|
103
|
-
- summarized chronological recovery material
|
|
104
|
-
- older work periods, decisions, milestones
|
|
105
|
-
- runtime-managed
|
|
106
|
-
- not intended for normal manual maintenance
|
|
107
|
-
|
|
108
|
-
## Cold Storage
|
|
109
|
-
|
|
110
|
-
These files remain cold:
|
|
111
|
-
|
|
112
|
-
- `<channel>/log.jsonl`
|
|
113
|
-
- `<channel>/context.jsonl`
|
|
114
|
-
|
|
115
|
-
They are not part of normal memory recall and are not proactively loaded into prompts.
|
|
116
|
-
|
|
117
|
-
## Core Invariants
|
|
118
|
-
|
|
119
|
-
The upgraded design must preserve these invariants:
|
|
120
|
-
|
|
121
|
-
1. File-based operation remains the source of truth.
|
|
122
|
-
2. The model should not need to remember to manually read the right memory file in common cases.
|
|
123
|
-
3. `SESSION.md` is the working-state artifact.
|
|
124
|
-
4. `MEMORY.md` is the durable-facts artifact.
|
|
125
|
-
5. `HISTORY.md` is the chronological-summary artifact.
|
|
126
|
-
6. Workspace memory remains human-managed.
|
|
127
|
-
7. Raw transport/session archives remain cold.
|
|
128
|
-
8. Failure of a background updater must not corrupt persisted memory files.
|
|
129
|
-
9. The system must degrade gracefully when an updater fails.
|
|
130
|
-
10. Memory improvements must help sub-agents and skills, not just the main agent.
|
|
131
|
-
|
|
132
|
-
## File Semantics
|
|
133
|
-
|
|
134
|
-
### `SESSION.md`
|
|
135
|
-
|
|
136
|
-
`SESSION.md` is channel-scoped hot memory.
|
|
137
|
-
|
|
138
|
-
It should answer:
|
|
139
|
-
|
|
140
|
-
1. What is the user currently trying to achieve?
|
|
141
|
-
2. What is the current state of work?
|
|
142
|
-
3. Which files and commands matter right now?
|
|
143
|
-
4. What constraints and recent failures should not be forgotten?
|
|
144
|
-
5. What are the next likely steps?
|
|
145
|
-
|
|
146
|
-
It should not become:
|
|
147
|
-
|
|
148
|
-
1. a raw transcript
|
|
149
|
-
2. a duplicate of all durable facts already in `MEMORY.md`
|
|
150
|
-
3. an infinite worklog
|
|
151
|
-
|
|
152
|
-
Read/write rule:
|
|
153
|
-
|
|
154
|
-
1. runtime-managed by default
|
|
155
|
-
2. eligible for automatic targeted recall
|
|
156
|
-
3. not intended for normal manual maintenance by the main agent
|
|
157
|
-
4. may be edited only when an explicit user/admin instruction makes that the task itself
|
|
158
|
-
|
|
159
|
-
### `MEMORY.md`
|
|
160
|
-
|
|
161
|
-
`MEMORY.md` remains the durable channel memory, but the threshold for what belongs here gets stricter.
|
|
162
|
-
|
|
163
|
-
It should keep:
|
|
164
|
-
|
|
165
|
-
1. stable preferences
|
|
166
|
-
2. durable decisions
|
|
167
|
-
3. medium-horizon constraints
|
|
168
|
-
4. important open loops that must survive beyond the current execution burst
|
|
169
|
-
|
|
170
|
-
It should avoid:
|
|
171
|
-
|
|
172
|
-
1. step-by-step active worklog
|
|
173
|
-
2. temporary local debugging observations unless they have lasting value
|
|
174
|
-
3. detailed "current state" that will likely be obsolete after a few turns
|
|
175
|
-
|
|
176
|
-
Read/write rule:
|
|
177
|
-
|
|
178
|
-
1. readable on demand
|
|
179
|
-
2. writable by runtime consolidation
|
|
180
|
-
3. still manually writable when necessary
|
|
181
|
-
4. cleanup is allowed to remove transient state that should now live in `SESSION.md`
|
|
182
|
-
|
|
183
|
-
### `HISTORY.md`
|
|
184
|
-
|
|
185
|
-
`HISTORY.md` remains the recovery narrative.
|
|
186
|
-
|
|
187
|
-
It should keep:
|
|
188
|
-
|
|
189
|
-
1. notable work periods
|
|
190
|
-
2. milestones
|
|
191
|
-
3. decision outcomes
|
|
192
|
-
4. enough chronology for later recovery
|
|
193
|
-
|
|
194
|
-
It should avoid:
|
|
195
|
-
|
|
196
|
-
1. dense per-turn detail
|
|
197
|
-
2. raw snippets copied from transcript
|
|
198
|
-
3. facts better represented in `MEMORY.md`
|
|
199
|
-
|
|
200
|
-
Read/write rule:
|
|
201
|
-
|
|
202
|
-
1. readable on demand
|
|
203
|
-
2. runtime-managed
|
|
204
|
-
3. not intended for ordinary manual edits
|
|
205
|
-
|
|
206
|
-
## Closed-Loop Lifecycle
|
|
207
|
-
|
|
208
|
-
The upgraded model introduces an explicit closed loop:
|
|
209
|
-
|
|
210
|
-
1. active session work happens in warm context
|
|
211
|
-
2. recent work updates `SESSION.md`
|
|
212
|
-
3. stable facts and medium-horizon open loops are promoted into `MEMORY.md`
|
|
213
|
-
4. older narrative is summarized into `HISTORY.md`
|
|
214
|
-
5. future prompts receive targeted recall from `SESSION.md`, `MEMORY.md`, and `HISTORY.md`
|
|
215
|
-
|
|
216
|
-
This loop must work even when:
|
|
217
|
-
|
|
218
|
-
1. the session compacts
|
|
219
|
-
2. the user starts a new session in the same channel
|
|
220
|
-
3. the process restarts
|
|
221
|
-
4. the main agent delegates work to a sub-agent
|
|
222
|
-
|
|
223
|
-
## Recall Model
|
|
224
|
-
|
|
225
|
-
The system should stop relying purely on "the model may remember to read memory files".
|
|
226
|
-
|
|
227
|
-
Instead, each turn may inject a small amount of relevant memory context chosen from:
|
|
228
|
-
|
|
229
|
-
1. `SESSION.md`
|
|
230
|
-
2. channel `MEMORY.md`
|
|
231
|
-
3. workspace `MEMORY.md`
|
|
232
|
-
4. channel `HISTORY.md`
|
|
233
|
-
|
|
234
|
-
Selection rules:
|
|
235
|
-
|
|
236
|
-
1. small budget
|
|
237
|
-
2. high precision
|
|
238
|
-
3. recency-aware
|
|
239
|
-
4. section-aware
|
|
240
|
-
5. prefer `SESSION.md` when current work state matters
|
|
241
|
-
6. prefer `MEMORY.md` when durable constraints or preferences matter
|
|
242
|
-
7. prefer `HISTORY.md` when recovery of older narrative matters
|
|
243
|
-
|
|
244
|
-
## SESSION.md Lifecycle Contract
|
|
245
|
-
|
|
246
|
-
`SESSION.md` must follow this lifecycle:
|
|
247
|
-
|
|
248
|
-
1. created automatically with the channel memory files
|
|
249
|
-
2. not loaded wholesale into every prompt
|
|
250
|
-
3. eligible for targeted recall injection
|
|
251
|
-
4. updated in the background during normal work
|
|
252
|
-
5. synchronously refreshed before context-reduction boundaries when possible
|
|
253
|
-
6. carried across `/new` session boundaries within the same channel
|
|
254
|
-
7. cleaned and condensed periodically so it remains current
|
|
255
|
-
8. recreated automatically if missing on an old channel directory
|
|
256
|
-
|
|
257
|
-
Important semantic rule:
|
|
258
|
-
|
|
259
|
-
`/new` starts a new model session, but does not imply "forget current channel work". `SESSION.md` is allowed to survive `/new` if the channel still has active work.
|
|
260
|
-
|
|
261
|
-
## Relationship Between SESSION.md And Existing Memory Files
|
|
262
|
-
|
|
263
|
-
The relationship is:
|
|
264
|
-
|
|
265
|
-
1. `SESSION.md` owns high-churn working state
|
|
266
|
-
2. `MEMORY.md` owns durable and semi-durable channel knowledge
|
|
267
|
-
3. `HISTORY.md` owns older narrative recovery
|
|
268
|
-
|
|
269
|
-
Promotion rules:
|
|
270
|
-
|
|
271
|
-
1. stable facts discovered in `SESSION.md` may be promoted into `MEMORY.md`
|
|
272
|
-
2. resolved work periods may be summarized into `HISTORY.md`
|
|
273
|
-
3. stale transient content should be removed from `SESSION.md`
|
|
274
|
-
4. cleanup may also remove overly transient content that had historically accumulated in `MEMORY.md`
|
|
275
|
-
|
|
276
|
-
This lets the system gradually migrate away from using channel `MEMORY.md` as the sole carrier of both durable and active state.
|
|
277
|
-
|
|
278
|
-
## Source Of Truth Precedence
|
|
279
|
-
|
|
280
|
-
When the same topic appears in multiple files, runtime and prompts should treat them in this precedence order:
|
|
281
|
-
|
|
282
|
-
1. `SESSION.md` for current active work state
|
|
283
|
-
2. `MEMORY.md` for durable constraints and decisions
|
|
284
|
-
3. `HISTORY.md` for older chronology
|
|
285
|
-
|
|
286
|
-
Practical implication:
|
|
287
|
-
|
|
288
|
-
1. a stale `MEMORY.md` note must not override a fresher `SESSION.md` current-state section
|
|
289
|
-
2. a stale `HISTORY.md` block must not override a fresher durable decision in `MEMORY.md`
|
|
290
|
-
|
|
291
|
-
## Compaction Contract
|
|
292
|
-
|
|
293
|
-
Compaction should become `SESSION.md`-aware.
|
|
294
|
-
|
|
295
|
-
The preferred order is:
|
|
296
|
-
|
|
297
|
-
1. refresh `SESSION.md`
|
|
298
|
-
2. run inline durable consolidation into `MEMORY.md` and `HISTORY.md`
|
|
299
|
-
3. compact using the latest `SESSION.md` as part of the retained context strategy
|
|
300
|
-
|
|
301
|
-
Graceful degradation rules:
|
|
302
|
-
|
|
303
|
-
1. if `SESSION.md` refresh fails, use the last persisted `SESSION.md`
|
|
304
|
-
2. if durable consolidation fails, compaction may still proceed if `SESSION.md` is available
|
|
305
|
-
3. failures must be logged and retried in background maintenance
|
|
306
|
-
|
|
307
|
-
This keeps compaction safe without turning memory maintenance into a hard availability dependency.
|
|
308
|
-
|
|
309
|
-
## Migration Contract
|
|
310
|
-
|
|
311
|
-
Existing channel directories already containing only `MEMORY.md` and `HISTORY.md` must migrate safely.
|
|
312
|
-
|
|
313
|
-
Migration rules:
|
|
314
|
-
|
|
315
|
-
1. missing `SESSION.md` is treated as normal and repaired by ensure-file bootstrap
|
|
316
|
-
2. existing `MEMORY.md` and `HISTORY.md` content remains authoritative
|
|
317
|
-
3. no one-time destructive rewrite of historical `MEMORY.md` content is required
|
|
318
|
-
4. transient content historically living in `MEMORY.md` is cleaned gradually by normal maintenance
|
|
319
|
-
|
|
320
|
-
This keeps rollout incremental and low-risk for live DingTalk channels.
|
|
321
|
-
|
|
322
|
-
## Sub-Agent Contract
|
|
323
|
-
|
|
324
|
-
Sub-agents remain isolated by default, but the runtime gains a standard way to provide them with the right memory context.
|
|
325
|
-
|
|
326
|
-
Two modes should exist:
|
|
327
|
-
|
|
328
|
-
1. isolated
|
|
329
|
-
- current behavior
|
|
330
|
-
- only runtime basics plus the explicitly provided task
|
|
331
|
-
2. contextual
|
|
332
|
-
- runtime prepends relevant memory and working-state context automatically
|
|
333
|
-
|
|
334
|
-
The contextual mode should pull from the same recall pipeline as the main agent, but with stricter budgets.
|
|
335
|
-
|
|
336
|
-
## Skill Contract
|
|
337
|
-
|
|
338
|
-
Skills should become lightweight participants in the upgraded context system.
|
|
339
|
-
|
|
340
|
-
Expected improvements:
|
|
341
|
-
|
|
342
|
-
1. richer frontmatter describing when a skill should be used
|
|
343
|
-
2. optional scoped hooks for session lifecycle events
|
|
344
|
-
3. optional declaration of memory relevance or path relevance
|
|
345
|
-
|
|
346
|
-
The skill system is still intentionally lighter than the `claude-code` version. The goal is stronger reuse and better context shaping, not a full plugin platform.
|
|
347
|
-
|
|
348
|
-
## Rollout Principle
|
|
349
|
-
|
|
350
|
-
This spec is designed for staged implementation:
|
|
351
|
-
|
|
352
|
-
1. first improve recall
|
|
353
|
-
2. then add `SESSION.md`
|
|
354
|
-
3. then bridge compaction
|
|
355
|
-
4. then upgrade sub-agent and skill integration
|
|
356
|
-
|
|
357
|
-
At each stage, existing `MEMORY.md` and `HISTORY.md` behavior must continue to work.
|
package/docs/memory-rfc.md
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
# Pipiclaw Memory Model RFC
|
|
2
|
-
|
|
3
|
-
## Status
|
|
4
|
-
|
|
5
|
-
Superseded in part by [`docs/improve-memory/spec.md`](/Users/oyasmi/projects/pipiclaw/docs/improve-memory/spec.md) and [`docs/improve-memory/design.md`](/Users/oyasmi/projects/pipiclaw/docs/improve-memory/design.md).
|
|
6
|
-
|
|
7
|
-
This RFC remains useful for the original file-based memory rationale, but it no longer fully describes the current design because the runtime now introduces:
|
|
8
|
-
|
|
9
|
-
1. `SESSION.md` as a distinct channel working-memory layer
|
|
10
|
-
2. proactive relevant-memory injection
|
|
11
|
-
3. a revised lifecycle between `SESSION.md`, `MEMORY.md`, and `HISTORY.md`
|
|
12
|
-
|
|
13
|
-
## Goals
|
|
14
|
-
|
|
15
|
-
1. Define a minimal memory model for `pipiclaw` aligned with the `nanobot` style.
|
|
16
|
-
2. Make memory flow explicit: record, read, consolidate, and reuse.
|
|
17
|
-
3. Keep raw transport/session files cold and separate from memory.
|
|
18
|
-
4. Limit what is loaded into session context by default.
|
|
19
|
-
5. Preserve simple file-based operations and avoid introducing a dedicated memory database or memory-specific tools.
|
|
20
|
-
|
|
21
|
-
## Non-Goals
|
|
22
|
-
|
|
23
|
-
1. No OpenClaw-style vector retrieval, embedding index, or memory plugins.
|
|
24
|
-
2. No `memory_search` or `memory_get` tool.
|
|
25
|
-
3. No automatic runtime mutation of workspace-level `MEMORY.md`, `SOUL.md`, or `AGENTS.md`.
|
|
26
|
-
4. No automatic loading or scanning of `log.jsonl` or `context.jsonl` as part of memory behavior.
|
|
27
|
-
|
|
28
|
-
## Design Summary
|
|
29
|
-
|
|
30
|
-
Pipiclaw memory is split into two channel-level files plus one workspace-level admin file:
|
|
31
|
-
|
|
32
|
-
- `workspace/MEMORY.md`
|
|
33
|
-
- Stable, admin-managed, shared background memory.
|
|
34
|
-
- Not automatically updated by runtime consolidation.
|
|
35
|
-
- `<channel>/MEMORY.md`
|
|
36
|
-
- Durable channel memory.
|
|
37
|
-
- Updated automatically by consolidation.
|
|
38
|
-
- May also be updated manually by the agent.
|
|
39
|
-
- `<channel>/HISTORY.md`
|
|
40
|
-
- Channel history summaries.
|
|
41
|
-
- Updated automatically by consolidation only.
|
|
42
|
-
- Not intended for direct manual maintenance by the agent.
|
|
43
|
-
|
|
44
|
-
Raw storage remains separate:
|
|
45
|
-
|
|
46
|
-
- `<channel>/log.jsonl`
|
|
47
|
-
- Raw message log only.
|
|
48
|
-
- Cold storage.
|
|
49
|
-
- Not proactively loaded or scanned by runtime.
|
|
50
|
-
- `<channel>/context.jsonl`
|
|
51
|
-
- Raw session persistence only.
|
|
52
|
-
- Cold storage.
|
|
53
|
-
- Not proactively loaded or scanned by runtime for memory purposes.
|
|
54
|
-
|
|
55
|
-
## File Model
|
|
56
|
-
|
|
57
|
-
### Workspace-Level Files
|
|
58
|
-
|
|
59
|
-
- `SOUL.md`
|
|
60
|
-
- Loaded into session context at session start.
|
|
61
|
-
- Read-only from the agent's perspective unless a human explicitly changes it.
|
|
62
|
-
- `AGENTS.md`
|
|
63
|
-
- Loaded into session context at session start.
|
|
64
|
-
- Read-only from the agent's perspective unless a human explicitly changes it.
|
|
65
|
-
- `MEMORY.md`
|
|
66
|
-
- Not loaded by default.
|
|
67
|
-
- Listed in the system prompt with its role and path.
|
|
68
|
-
- Intended to be read on demand by the agent.
|
|
69
|
-
- Stable and admin-managed.
|
|
70
|
-
|
|
71
|
-
### Channel-Level Files
|
|
72
|
-
|
|
73
|
-
- `MEMORY.md`
|
|
74
|
-
- Not loaded by default.
|
|
75
|
-
- Listed in the system prompt with its role and path.
|
|
76
|
-
- Intended to be read on demand by the agent.
|
|
77
|
-
- Primary durable memory for the channel.
|
|
78
|
-
- `HISTORY.md`
|
|
79
|
-
- Not loaded by default.
|
|
80
|
-
- Listed in the system prompt with its role and path.
|
|
81
|
-
- Intended to be read on demand by the agent.
|
|
82
|
-
- Append-oriented summary history for older context.
|
|
83
|
-
- `log.jsonl`
|
|
84
|
-
- Raw archive only.
|
|
85
|
-
- Not memory.
|
|
86
|
-
- Runtime must not proactively load or scan it.
|
|
87
|
-
- `context.jsonl`
|
|
88
|
-
- Raw session archive only.
|
|
89
|
-
- Not memory.
|
|
90
|
-
- Runtime must not proactively load or scan it.
|
|
91
|
-
|
|
92
|
-
## Default Context Loading
|
|
93
|
-
|
|
94
|
-
At session start, runtime loads the following into session context:
|
|
95
|
-
|
|
96
|
-
1. Workspace-level `SOUL.md`
|
|
97
|
-
2. Workspace-level `AGENTS.md`
|
|
98
|
-
3. Built-in tool descriptions
|
|
99
|
-
4. Summaries of both workspace-level and channel-level skills
|
|
100
|
-
|
|
101
|
-
At session start, runtime does not load the following by default:
|
|
102
|
-
|
|
103
|
-
1. Workspace-level `MEMORY.md`
|
|
104
|
-
2. Channel-level `MEMORY.md`
|
|
105
|
-
3. Channel-level `HISTORY.md`
|
|
106
|
-
4. `<channel>/log.jsonl`
|
|
107
|
-
5. `<channel>/context.jsonl`
|
|
108
|
-
|
|
109
|
-
The system prompt must explicitly tell the agent:
|
|
110
|
-
|
|
111
|
-
1. Where `workspace/MEMORY.md`, `<channel>/MEMORY.md`, and `<channel>/HISTORY.md` live.
|
|
112
|
-
2. What each file is for.
|
|
113
|
-
3. That these files are not preloaded.
|
|
114
|
-
4. That the agent is encouraged to read them on demand when memory or history is relevant.
|
|
115
|
-
|
|
116
|
-
Changes to workspace-level `SOUL.md` and `AGENTS.md` take effect on new sessions. They are not reloaded on every turn.
|
|
117
|
-
|
|
118
|
-
## Agent Read/Write Rules
|
|
119
|
-
|
|
120
|
-
### Reads
|
|
121
|
-
|
|
122
|
-
The agent should prefer:
|
|
123
|
-
|
|
124
|
-
1. `<channel>/MEMORY.md` for durable channel facts, decisions, preferences, and ongoing state.
|
|
125
|
-
2. `<channel>/HISTORY.md` for older summarized context.
|
|
126
|
-
3. `workspace/MEMORY.md` for stable shared background.
|
|
127
|
-
|
|
128
|
-
The agent should not treat `log.jsonl` or `context.jsonl` as normal memory sources. Those files are for raw recovery, debugging, or explicit transcript-level investigation only.
|
|
129
|
-
|
|
130
|
-
### Writes
|
|
131
|
-
|
|
132
|
-
The agent may:
|
|
133
|
-
|
|
134
|
-
1. Read `workspace/MEMORY.md`
|
|
135
|
-
2. Read `<channel>/MEMORY.md`
|
|
136
|
-
3. Read `<channel>/HISTORY.md`
|
|
137
|
-
4. Manually update `<channel>/MEMORY.md` when necessary
|
|
138
|
-
|
|
139
|
-
The agent should not manually maintain `<channel>/HISTORY.md` during normal operation. `HISTORY.md` is runtime-managed.
|
|
140
|
-
|
|
141
|
-
The runtime must never automatically update:
|
|
142
|
-
|
|
143
|
-
1. `workspace/SOUL.md`
|
|
144
|
-
2. `workspace/AGENTS.md`
|
|
145
|
-
3. `workspace/MEMORY.md`
|
|
146
|
-
|
|
147
|
-
## Consolidation
|
|
148
|
-
|
|
149
|
-
Consolidation is the primary mechanism that keeps memory moving.
|
|
150
|
-
|
|
151
|
-
Consolidation takes recent session material and produces two outputs:
|
|
152
|
-
|
|
153
|
-
1. Durable facts and live channel state in `<channel>/MEMORY.md`
|
|
154
|
-
2. Older summarized history in `<channel>/HISTORY.md`
|
|
155
|
-
|
|
156
|
-
Consolidation must not write to workspace-level `MEMORY.md`.
|
|
157
|
-
|
|
158
|
-
### Trigger Model
|
|
159
|
-
|
|
160
|
-
Runtime should run consolidation automatically only when a session is about to compact or trim context.
|
|
161
|
-
|
|
162
|
-
There is no separate turn-count trigger, token-watermark trigger, or per-turn memory-dirty trigger in this RFC.
|
|
163
|
-
|
|
164
|
-
### Consolidation Input
|
|
165
|
-
|
|
166
|
-
Consolidation operates on recent session material already in the active session state. It does not scan `log.jsonl` or `context.jsonl`.
|
|
167
|
-
|
|
168
|
-
### Consolidation Output Rules
|
|
169
|
-
|
|
170
|
-
`<channel>/MEMORY.md` should contain:
|
|
171
|
-
|
|
172
|
-
1. Durable facts about the channel, user, project, preferences, constraints, and long-lived open threads.
|
|
173
|
-
2. Current state that matters across turns.
|
|
174
|
-
3. Cleaned and deduplicated entries.
|
|
175
|
-
4. Structured sections rather than free-form prose.
|
|
176
|
-
|
|
177
|
-
`<channel>/HISTORY.md` should contain:
|
|
178
|
-
|
|
179
|
-
1. Append-oriented summaries of older conversation chunks.
|
|
180
|
-
2. Resolved decisions and notable milestones.
|
|
181
|
-
3. Enough context for later recovery without replaying raw transcripts.
|
|
182
|
-
|
|
183
|
-
### Consolidation Semantics
|
|
184
|
-
|
|
185
|
-
Consolidation should:
|
|
186
|
-
|
|
187
|
-
1. Extract durable facts from recent session material.
|
|
188
|
-
2. Append new channel-memory entries into `<channel>/MEMORY.md` during normal operation.
|
|
189
|
-
3. Periodically clean up `<channel>/MEMORY.md` with a larger sweep that removes outdated entries, merges duplicates, and tightens wording.
|
|
190
|
-
4. Append or roll forward summarized older material into `<channel>/HISTORY.md`.
|
|
191
|
-
5. Periodically fold older `HISTORY.md` blocks into coarser summaries while keeping newer blocks more detailed.
|
|
192
|
-
6. Remove redundancy between the two files.
|
|
193
|
-
7. Prefer stable facts in `MEMORY.md` and narrative progression in `HISTORY.md`.
|
|
194
|
-
|
|
195
|
-
This RFC adopts an append-first strategy for `MEMORY.md`, with periodic cleanup passes rather than full rewrite on every consolidation.
|
|
196
|
-
|
|
197
|
-
Consolidation should not:
|
|
198
|
-
|
|
199
|
-
1. Dump raw message transcripts into `HISTORY.md`
|
|
200
|
-
2. Copy large blocks from `context.jsonl` or `log.jsonl`
|
|
201
|
-
3. Preserve outdated facts just because they were once true
|
|
202
|
-
|
|
203
|
-
## Suggested File Semantics
|
|
204
|
-
|
|
205
|
-
`<channel>/MEMORY.md` should be organized as stable sections such as:
|
|
206
|
-
|
|
207
|
-
1. `## Identity / Participants`
|
|
208
|
-
2. `## Preferences`
|
|
209
|
-
3. `## Ongoing Work`
|
|
210
|
-
4. `## Constraints`
|
|
211
|
-
5. `## Decisions`
|
|
212
|
-
6. `## Open Loops`
|
|
213
|
-
|
|
214
|
-
`<channel>/HISTORY.md` should be organized as chronological summary blocks such as:
|
|
215
|
-
|
|
216
|
-
1. Dated headings
|
|
217
|
-
2. Short summaries of work periods
|
|
218
|
-
3. Key decisions and outcomes
|
|
219
|
-
|
|
220
|
-
Exact formatting can evolve, but the split between durable memory and summarized history should remain stable.
|
|
221
|
-
|
|
222
|
-
## Consolidation Execution Model
|
|
223
|
-
|
|
224
|
-
Consolidation uses a two-phase execution model:
|
|
225
|
-
|
|
226
|
-
1. Inline phase
|
|
227
|
-
- Runs synchronously when a compaction or trim is about to happen.
|
|
228
|
-
- Responsible for producing the minimum safe memory updates needed before context is reduced.
|
|
229
|
-
2. Background phase
|
|
230
|
-
- Runs later as a per-channel queued maintenance pass.
|
|
231
|
-
- Responsible for larger cleanup work, including `MEMORY.md` cleanup sweeps and `HISTORY.md` folding.
|
|
232
|
-
|
|
233
|
-
The background phase must not replace the inline phase for compaction safety. It is an additional maintenance pass, not the primary durability guarantee.
|
|
234
|
-
|
|
235
|
-
## Compaction And Trimming Contract
|
|
236
|
-
|
|
237
|
-
Consolidation is hard-gated before compaction or trim.
|
|
238
|
-
|
|
239
|
-
This means:
|
|
240
|
-
|
|
241
|
-
1. If a compaction or trim would discard context, runtime must first run inline consolidation.
|
|
242
|
-
2. If inline consolidation fails, compaction or trim must not proceed.
|
|
243
|
-
3. After successful inline consolidation, the runtime may compact or trim.
|
|
244
|
-
|
|
245
|
-
This RFC does not allow trim-first or compact-first behavior when memory durability depends on consolidation.
|
|
246
|
-
|
|
247
|
-
## Runtime Responsibilities
|
|
248
|
-
|
|
249
|
-
Runtime is responsible for:
|
|
250
|
-
|
|
251
|
-
1. Loading only the default context described in this RFC.
|
|
252
|
-
2. Exposing file locations and roles clearly in the system prompt.
|
|
253
|
-
3. Running automatic consolidation.
|
|
254
|
-
4. Updating `<channel>/MEMORY.md` and `<channel>/HISTORY.md` during consolidation.
|
|
255
|
-
5. Keeping `log.jsonl` and `context.jsonl` cold.
|
|
256
|
-
|
|
257
|
-
Runtime is not responsible for:
|
|
258
|
-
|
|
259
|
-
1. Auto-loading memory files into every turn
|
|
260
|
-
2. Indexing memory into a vector database
|
|
261
|
-
3. Providing special memory-only tools
|
|
262
|
-
|
|
263
|
-
## Session Model
|
|
264
|
-
|
|
265
|
-
Session context is warm.
|
|
266
|
-
|
|
267
|
-
Memory files are warm-on-demand.
|
|
268
|
-
|
|
269
|
-
`log.jsonl` and `context.jsonl` are cold.
|
|
270
|
-
|
|
271
|
-
The intended flow is:
|
|
272
|
-
|
|
273
|
-
1. Session starts with `SOUL.md`, `AGENTS.md`, built-in tool descriptions, and skill summaries.
|
|
274
|
-
2. Agent reads channel or workspace memory files if the task needs them.
|
|
275
|
-
3. Conversation progresses in session state.
|
|
276
|
-
4. Runtime consolidates session material into `<channel>/MEMORY.md` and `<channel>/HISTORY.md`.
|
|
277
|
-
5. Older raw storage remains available but is not part of ordinary memory behavior.
|
|
278
|
-
|
|
279
|
-
## Migration Impact
|
|
280
|
-
|
|
281
|
-
This RFC implies the following behavior changes from the current implementation:
|
|
282
|
-
|
|
283
|
-
1. `workspace/MEMORY.md` and `<channel>/MEMORY.md` are no longer injected into the system prompt by default.
|
|
284
|
-
2. `SOUL.md` and `AGENTS.md` are no longer reloaded on every turn.
|
|
285
|
-
3. `log.jsonl` is no longer scanned to rebuild context as part of normal turn processing.
|
|
286
|
-
4. `context.jsonl` is no longer treated as a memory source.
|
|
287
|
-
5. Consolidation becomes the main persistence path for channel memory.
|
|
288
|
-
|
|
289
|
-
## Fixed Decisions
|
|
290
|
-
|
|
291
|
-
This RFC fixes the following design choices:
|
|
292
|
-
|
|
293
|
-
1. Consolidation triggers only before compaction or trim.
|
|
294
|
-
2. `<channel>/MEMORY.md` uses append-first updates with periodic cleanup sweeps.
|
|
295
|
-
3. `<channel>/HISTORY.md` uses append-first updates with periodic folding of older blocks.
|
|
296
|
-
4. Consolidation uses a two-phase execution model: inline for safety, background for maintenance.
|
|
297
|
-
5. Consolidation is hard-gated before compaction or trim.
|