@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,537 +0,0 @@
|
|
|
1
|
-
# Pipiclaw Context Upgrade Design
|
|
2
|
-
|
|
3
|
-
## Scope
|
|
4
|
-
|
|
5
|
-
This document translates the context-upgrade spec into runtime behavior for `pipiclaw`.
|
|
6
|
-
|
|
7
|
-
It covers:
|
|
8
|
-
|
|
9
|
-
1. relevant memory injection
|
|
10
|
-
2. `SESSION.md`
|
|
11
|
-
3. changed `MEMORY.md` / `HISTORY.md` flow
|
|
12
|
-
4. compaction integration
|
|
13
|
-
5. contextual sub-agents
|
|
14
|
-
6. skill metadata and lightweight hooks
|
|
15
|
-
|
|
16
|
-
## Current Baseline
|
|
17
|
-
|
|
18
|
-
Today the main integration points are:
|
|
19
|
-
|
|
20
|
-
1. [ChannelRunner](/Users/oyasmi/projects/pipiclaw/src/agent.ts#L260)
|
|
21
|
-
2. [buildAppendSystemPrompt](/Users/oyasmi/projects/pipiclaw/src/prompt-builder.ts#L7)
|
|
22
|
-
3. [MemoryLifecycle](/Users/oyasmi/projects/pipiclaw/src/memory-lifecycle.ts#L20)
|
|
23
|
-
4. [memory consolidation](/Users/oyasmi/projects/pipiclaw/src/memory-consolidation.ts#L271)
|
|
24
|
-
5. [sub-agent discovery and execution](/Users/oyasmi/projects/pipiclaw/src/sub-agents.ts#L189) [subagent tool](/Users/oyasmi/projects/pipiclaw/src/tools/subagent.ts#L235)
|
|
25
|
-
6. [channel memory file bootstrap](/Users/oyasmi/projects/pipiclaw/src/memory-files.ts#L60)
|
|
26
|
-
|
|
27
|
-
The design below intentionally reuses these hooks rather than introducing a second runtime.
|
|
28
|
-
|
|
29
|
-
## Design Overview
|
|
30
|
-
|
|
31
|
-
### Main Idea
|
|
32
|
-
|
|
33
|
-
Introduce a new working-state artifact, `SESSION.md`, and a recall pipeline that proactively surfaces only the memory slices most likely to matter on the current turn.
|
|
34
|
-
|
|
35
|
-
The runtime then uses three complementary maintenance loops:
|
|
36
|
-
|
|
37
|
-
1. turn-time recall loop
|
|
38
|
-
2. session-state update loop
|
|
39
|
-
3. durable consolidation loop
|
|
40
|
-
|
|
41
|
-
### Why This Works
|
|
42
|
-
|
|
43
|
-
This design borrows the highest-value ideas from `claude-code` without importing its heaviest machinery:
|
|
44
|
-
|
|
45
|
-
1. proactive relevant-memory surfacing
|
|
46
|
-
2. explicit session notes
|
|
47
|
-
3. sidecar worker pattern for background extraction
|
|
48
|
-
4. compaction informed by working-state artifacts
|
|
49
|
-
|
|
50
|
-
It does not attempt to reproduce:
|
|
51
|
-
|
|
52
|
-
1. full prompt-cache-safe fork infrastructure
|
|
53
|
-
2. multi-backend swarm orchestration
|
|
54
|
-
3. complex task OS abstractions
|
|
55
|
-
|
|
56
|
-
## Runtime Components
|
|
57
|
-
|
|
58
|
-
### A. Relevant Memory Recall
|
|
59
|
-
|
|
60
|
-
Purpose:
|
|
61
|
-
|
|
62
|
-
- improve precision of context use without making every turn read full memory files
|
|
63
|
-
|
|
64
|
-
Inputs:
|
|
65
|
-
|
|
66
|
-
1. user message
|
|
67
|
-
2. current session model
|
|
68
|
-
3. `SESSION.md`
|
|
69
|
-
4. channel `MEMORY.md`
|
|
70
|
-
5. workspace `MEMORY.md`
|
|
71
|
-
6. channel `HISTORY.md`
|
|
72
|
-
|
|
73
|
-
Outputs:
|
|
74
|
-
|
|
75
|
-
1. a small injected memory block prepended to the user prompt
|
|
76
|
-
|
|
77
|
-
Selection pipeline:
|
|
78
|
-
|
|
79
|
-
1. parse each file into sections/blocks
|
|
80
|
-
2. score locally with lexical and structural heuristics
|
|
81
|
-
3. if candidate set is large, optionally rerank with a small model call
|
|
82
|
-
4. truncate to injection budget
|
|
83
|
-
|
|
84
|
-
Priority order:
|
|
85
|
-
|
|
86
|
-
1. `SESSION.md`
|
|
87
|
-
2. channel `MEMORY.md`
|
|
88
|
-
3. workspace `MEMORY.md`
|
|
89
|
-
4. `HISTORY.md`
|
|
90
|
-
|
|
91
|
-
Reasons:
|
|
92
|
-
|
|
93
|
-
1. current state usually matters more than old history
|
|
94
|
-
2. channel-local state usually matters more than workspace-shared background
|
|
95
|
-
3. history should help recovery, not dominate normal turns
|
|
96
|
-
|
|
97
|
-
### B. SESSION.md Updater
|
|
98
|
-
|
|
99
|
-
Purpose:
|
|
100
|
-
|
|
101
|
-
- maintain a compact, structured representation of the current working state
|
|
102
|
-
|
|
103
|
-
Shape:
|
|
104
|
-
|
|
105
|
-
Recommended stable sections:
|
|
106
|
-
|
|
107
|
-
1. `# Session Title`
|
|
108
|
-
2. `# Current State`
|
|
109
|
-
3. `# User Intent`
|
|
110
|
-
4. `# Active Files`
|
|
111
|
-
5. `# Decisions`
|
|
112
|
-
6. `# Constraints`
|
|
113
|
-
7. `# Errors & Corrections`
|
|
114
|
-
8. `# Next Steps`
|
|
115
|
-
9. `# Worklog`
|
|
116
|
-
|
|
117
|
-
Update model:
|
|
118
|
-
|
|
119
|
-
1. background updates after meaningful work
|
|
120
|
-
2. forced refresh before compaction
|
|
121
|
-
3. forced refresh before `/new` session switch
|
|
122
|
-
|
|
123
|
-
Important choice:
|
|
124
|
-
|
|
125
|
-
The updater should return structured JSON, and the runtime should render Markdown.
|
|
126
|
-
|
|
127
|
-
Reason:
|
|
128
|
-
|
|
129
|
-
1. less fragile than asking the worker to surgically edit Markdown
|
|
130
|
-
2. easier to test
|
|
131
|
-
3. easier to enforce section boundaries
|
|
132
|
-
4. easier to migrate format later
|
|
133
|
-
|
|
134
|
-
### C. Durable Consolidation
|
|
135
|
-
|
|
136
|
-
Purpose:
|
|
137
|
-
|
|
138
|
-
- promote long-lived facts to `MEMORY.md`
|
|
139
|
-
- push older narrative to `HISTORY.md`
|
|
140
|
-
|
|
141
|
-
This extends the existing system rather than replacing it.
|
|
142
|
-
|
|
143
|
-
Behavioral change:
|
|
144
|
-
|
|
145
|
-
The consolidation worker should treat `SESSION.md` as an input artifact when deciding:
|
|
146
|
-
|
|
147
|
-
1. what belongs in durable memory
|
|
148
|
-
2. what is still merely active work state
|
|
149
|
-
3. what should move to history
|
|
150
|
-
|
|
151
|
-
That change closes the loop:
|
|
152
|
-
|
|
153
|
-
recent transcript -> `SESSION.md` -> durable promotion -> future recall
|
|
154
|
-
|
|
155
|
-
### D. Sidecar Worker Abstraction
|
|
156
|
-
|
|
157
|
-
Purpose:
|
|
158
|
-
|
|
159
|
-
- unify small internal worker tasks under one runtime helper
|
|
160
|
-
|
|
161
|
-
Candidate tasks:
|
|
162
|
-
|
|
163
|
-
1. relevant-memory reranking
|
|
164
|
-
2. `SESSION.md` update generation
|
|
165
|
-
3. durable consolidation cleanup
|
|
166
|
-
4. history folding
|
|
167
|
-
|
|
168
|
-
This does not need prompt-cache-safe inheritance in the first iteration.
|
|
169
|
-
|
|
170
|
-
The first version should optimize for:
|
|
171
|
-
|
|
172
|
-
1. correctness
|
|
173
|
-
2. isolation
|
|
174
|
-
3. observability
|
|
175
|
-
4. shared error handling
|
|
176
|
-
|
|
177
|
-
## Source Of Truth Rules
|
|
178
|
-
|
|
179
|
-
The runtime should make conflicts boring and deterministic.
|
|
180
|
-
|
|
181
|
-
### Current Work State
|
|
182
|
-
|
|
183
|
-
For current active work state, trust:
|
|
184
|
-
|
|
185
|
-
1. live in-memory session messages first
|
|
186
|
-
2. then `SESSION.md`
|
|
187
|
-
3. then `MEMORY.md`
|
|
188
|
-
4. then `HISTORY.md`
|
|
189
|
-
|
|
190
|
-
### Durable Constraints And Decisions
|
|
191
|
-
|
|
192
|
-
For durable constraints and decisions, trust:
|
|
193
|
-
|
|
194
|
-
1. explicit human-managed workspace files first
|
|
195
|
-
2. then channel `MEMORY.md`
|
|
196
|
-
3. then `SESSION.md`
|
|
197
|
-
4. then `HISTORY.md`
|
|
198
|
-
|
|
199
|
-
This prevents the new hot-memory layer from accidentally becoming the durable truth for everything.
|
|
200
|
-
|
|
201
|
-
## Detailed Lifecycle
|
|
202
|
-
|
|
203
|
-
### 1. Channel Bootstrap
|
|
204
|
-
|
|
205
|
-
When a channel directory is created or touched for the first time:
|
|
206
|
-
|
|
207
|
-
1. ensure `MEMORY.md`
|
|
208
|
-
2. ensure `HISTORY.md`
|
|
209
|
-
3. ensure `SESSION.md`
|
|
210
|
-
|
|
211
|
-
This should extend the existing [ensureChannelMemoryFilesSync](/Users/oyasmi/projects/pipiclaw/src/memory-files.ts#L60) behavior.
|
|
212
|
-
|
|
213
|
-
### 2. Session Start
|
|
214
|
-
|
|
215
|
-
At session start:
|
|
216
|
-
|
|
217
|
-
1. load `SOUL.md`
|
|
218
|
-
2. load `AGENTS.md`
|
|
219
|
-
3. load skills metadata
|
|
220
|
-
4. do not preload `MEMORY.md`, `HISTORY.md`, or `SESSION.md`
|
|
221
|
-
|
|
222
|
-
Rationale:
|
|
223
|
-
|
|
224
|
-
1. keep base prompt lean
|
|
225
|
-
2. let recall injection decide what to surface
|
|
226
|
-
|
|
227
|
-
### 3. Normal User Turn
|
|
228
|
-
|
|
229
|
-
Before `session.prompt()`:
|
|
230
|
-
|
|
231
|
-
1. build the formatted user message as today
|
|
232
|
-
2. run relevant-memory recall
|
|
233
|
-
3. prepend a runtime context block if recall produced useful results
|
|
234
|
-
|
|
235
|
-
After the turn finishes successfully:
|
|
236
|
-
|
|
237
|
-
1. evaluate whether the turn dirtied working state enough to refresh `SESSION.md`
|
|
238
|
-
2. if yes, queue the background updater
|
|
239
|
-
|
|
240
|
-
Dirty signals include:
|
|
241
|
-
|
|
242
|
-
1. at least one assistant final response
|
|
243
|
-
2. tool activity
|
|
244
|
-
3. file-writing activity
|
|
245
|
-
4. large token delta
|
|
246
|
-
5. explicit user steering that changes task direction
|
|
247
|
-
|
|
248
|
-
### 4. Busy Steering / Follow-Up
|
|
249
|
-
|
|
250
|
-
Steer and follow-up messages remain normal runtime messages, but they should also count as `SESSION.md`-dirty signals.
|
|
251
|
-
|
|
252
|
-
Reason:
|
|
253
|
-
|
|
254
|
-
These are precisely the moments when "current state" tends to change.
|
|
255
|
-
|
|
256
|
-
### 5. Before Compaction
|
|
257
|
-
|
|
258
|
-
When `session_before_compact` fires:
|
|
259
|
-
|
|
260
|
-
1. synchronously refresh `SESSION.md` using the current session messages
|
|
261
|
-
2. run inline durable consolidation
|
|
262
|
-
3. proceed to compaction
|
|
263
|
-
|
|
264
|
-
Fallback:
|
|
265
|
-
|
|
266
|
-
1. if refresh fails, keep the last persisted `SESSION.md`
|
|
267
|
-
2. if durable consolidation fails, compaction still proceeds with the last good durable files
|
|
268
|
-
|
|
269
|
-
### 6. After Compaction
|
|
270
|
-
|
|
271
|
-
After compaction:
|
|
272
|
-
|
|
273
|
-
1. queue background cleanup for `MEMORY.md`
|
|
274
|
-
2. queue background folding for `HISTORY.md`
|
|
275
|
-
3. do not immediately rewrite `SESSION.md` again unless compaction changed work state interpretation
|
|
276
|
-
|
|
277
|
-
### 7. Before New Session
|
|
278
|
-
|
|
279
|
-
When `session_before_switch(reason=new)` fires:
|
|
280
|
-
|
|
281
|
-
1. synchronously refresh `SESSION.md`
|
|
282
|
-
2. run inline durable consolidation
|
|
283
|
-
3. allow session switch
|
|
284
|
-
|
|
285
|
-
After switch:
|
|
286
|
-
|
|
287
|
-
1. background cleanup may run
|
|
288
|
-
2. `SESSION.md` remains available to the next session
|
|
289
|
-
|
|
290
|
-
### 8. Process Restart
|
|
291
|
-
|
|
292
|
-
After restart:
|
|
293
|
-
|
|
294
|
-
1. the runner should reconstruct state from files
|
|
295
|
-
2. `SESSION.md` serves as the persisted hot handoff
|
|
296
|
-
3. no extra persisted metadata is required in the first iteration
|
|
297
|
-
|
|
298
|
-
Design choice:
|
|
299
|
-
|
|
300
|
-
Do not add a `memory-state.json` file yet.
|
|
301
|
-
|
|
302
|
-
Reason:
|
|
303
|
-
|
|
304
|
-
1. first iteration can remain simple
|
|
305
|
-
2. `SESSION.md` is already the persisted hot state
|
|
306
|
-
3. current session messages plus file timestamps are sufficient for an initial robust version
|
|
307
|
-
|
|
308
|
-
If later needed, a metadata file can be added as a follow-up optimization rather than a baseline dependency.
|
|
309
|
-
|
|
310
|
-
### 9. Old Channel Migration
|
|
311
|
-
|
|
312
|
-
For existing channels that predate this design:
|
|
313
|
-
|
|
314
|
-
1. create `SESSION.md` lazily when the channel is next touched
|
|
315
|
-
2. do not perform a one-shot rewrite of `MEMORY.md`
|
|
316
|
-
3. let background cleanup gradually strip transient working-state details from `MEMORY.md`
|
|
317
|
-
|
|
318
|
-
This avoids rollout-time churn on live channels.
|
|
319
|
-
|
|
320
|
-
## Memory Ownership Rules
|
|
321
|
-
|
|
322
|
-
### SESSION.md Owns
|
|
323
|
-
|
|
324
|
-
1. precise active task state
|
|
325
|
-
2. active files and commands
|
|
326
|
-
3. immediate next steps
|
|
327
|
-
4. recent significant errors
|
|
328
|
-
5. temporary but important work hypotheses
|
|
329
|
-
|
|
330
|
-
### MEMORY.md Owns
|
|
331
|
-
|
|
332
|
-
1. durable facts
|
|
333
|
-
2. durable preferences
|
|
334
|
-
3. stable constraints
|
|
335
|
-
4. decisions that should survive beyond current execution
|
|
336
|
-
5. medium-horizon open loops
|
|
337
|
-
|
|
338
|
-
### HISTORY.md Owns
|
|
339
|
-
|
|
340
|
-
1. chronological work periods
|
|
341
|
-
2. milestones
|
|
342
|
-
3. older summarized context
|
|
343
|
-
|
|
344
|
-
### Cleanup Implication
|
|
345
|
-
|
|
346
|
-
Background cleanup should now be allowed to remove from `MEMORY.md` content that is clearly transient working state and belongs in `SESSION.md`.
|
|
347
|
-
|
|
348
|
-
This is an intentional semantic shift from the current append-first-only behavior.
|
|
349
|
-
|
|
350
|
-
## End-To-End Flow
|
|
351
|
-
|
|
352
|
-
The intended steady-state loop is:
|
|
353
|
-
|
|
354
|
-
1. user sends a message
|
|
355
|
-
2. runtime recalls relevant context from `SESSION.md`, `MEMORY.md`, and `HISTORY.md`
|
|
356
|
-
3. main agent runs with a small injected memory block
|
|
357
|
-
4. turn completes
|
|
358
|
-
5. runtime updates `SESSION.md` if work state changed enough
|
|
359
|
-
6. before compaction or new session, runtime forces a fresh `SESSION.md` flush
|
|
360
|
-
7. runtime promotes durable facts to `MEMORY.md` and older narrative to `HISTORY.md`
|
|
361
|
-
8. next turn benefits from the updated files
|
|
362
|
-
|
|
363
|
-
This is the operational closure that the current design lacks.
|
|
364
|
-
|
|
365
|
-
## Recall Injection Format
|
|
366
|
-
|
|
367
|
-
Use an explicit runtime wrapper rather than pretending the memory snippets are part of the user text.
|
|
368
|
-
|
|
369
|
-
Recommended shape:
|
|
370
|
-
|
|
371
|
-
```text
|
|
372
|
-
<runtime_context>
|
|
373
|
-
Relevant context for this turn:
|
|
374
|
-
|
|
375
|
-
[session/current-state]
|
|
376
|
-
...
|
|
377
|
-
|
|
378
|
-
[channel-memory/constraints]
|
|
379
|
-
...
|
|
380
|
-
</runtime_context>
|
|
381
|
-
|
|
382
|
-
<user_message>
|
|
383
|
-
...
|
|
384
|
-
</user_message>
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
Rationale:
|
|
388
|
-
|
|
389
|
-
1. separates runtime-provided context from user intent
|
|
390
|
-
2. keeps prompts inspectable in debug mode
|
|
391
|
-
3. makes future migration to attachment-style rendering easier
|
|
392
|
-
|
|
393
|
-
## SESSION.md Rendering
|
|
394
|
-
|
|
395
|
-
The runtime should render `SESSION.md` deterministically from structured update data.
|
|
396
|
-
|
|
397
|
-
Properties:
|
|
398
|
-
|
|
399
|
-
1. stable section order
|
|
400
|
-
2. empty sections omitted or left blank according to template choice
|
|
401
|
-
3. explicit truncation for very large sections
|
|
402
|
-
4. deterministic formatting for testing
|
|
403
|
-
|
|
404
|
-
Recommended rule:
|
|
405
|
-
|
|
406
|
-
- keep a stable template
|
|
407
|
-
- render empty sections as present but blank only if needed for readability
|
|
408
|
-
- otherwise omit clearly empty tail sections to keep file lean
|
|
409
|
-
|
|
410
|
-
Recommended practical default:
|
|
411
|
-
|
|
412
|
-
1. keep top sections stable
|
|
413
|
-
2. omit empty low-value tail sections such as `Worklog` when fully empty
|
|
414
|
-
3. cap `Worklog` aggressively so it never becomes a second `HISTORY.md`
|
|
415
|
-
|
|
416
|
-
## Update Trigger Strategy
|
|
417
|
-
|
|
418
|
-
The updater should not run on every turn.
|
|
419
|
-
|
|
420
|
-
Suggested thresholds:
|
|
421
|
-
|
|
422
|
-
1. at least 2 meaningful user/assistant exchanges since last update
|
|
423
|
-
2. or at least 4 tool calls since last update
|
|
424
|
-
3. or at least one file mutation plus a final assistant reply
|
|
425
|
-
4. or an impending compaction / new-session switch
|
|
426
|
-
|
|
427
|
-
This keeps cost bounded while still refreshing the working state at natural boundaries.
|
|
428
|
-
|
|
429
|
-
## Failure Handling
|
|
430
|
-
|
|
431
|
-
### Relevant Recall Failure
|
|
432
|
-
|
|
433
|
-
If recall fails:
|
|
434
|
-
|
|
435
|
-
1. continue the turn without injected memory
|
|
436
|
-
2. log warning
|
|
437
|
-
3. do not block the agent
|
|
438
|
-
|
|
439
|
-
### SESSION.md Update Failure
|
|
440
|
-
|
|
441
|
-
If the background update fails:
|
|
442
|
-
|
|
443
|
-
1. keep the last persisted file
|
|
444
|
-
2. mark no special error to user
|
|
445
|
-
3. retry next time thresholds are met
|
|
446
|
-
|
|
447
|
-
If the synchronous pre-compaction refresh fails:
|
|
448
|
-
|
|
449
|
-
1. keep the last persisted file
|
|
450
|
-
2. log warning
|
|
451
|
-
3. continue to compaction
|
|
452
|
-
|
|
453
|
-
If no persisted `SESSION.md` exists yet:
|
|
454
|
-
|
|
455
|
-
1. fall back to an empty template
|
|
456
|
-
2. continue without blocking the user
|
|
457
|
-
|
|
458
|
-
### Durable Consolidation Failure
|
|
459
|
-
|
|
460
|
-
If inline durable consolidation fails:
|
|
461
|
-
|
|
462
|
-
1. keep existing `MEMORY.md` and `HISTORY.md`
|
|
463
|
-
2. continue to compaction if `SESSION.md` is available
|
|
464
|
-
3. queue background retry later
|
|
465
|
-
|
|
466
|
-
### Corruption Policy
|
|
467
|
-
|
|
468
|
-
All writes to `SESSION.md`, `MEMORY.md`, and `HISTORY.md` should be atomic.
|
|
469
|
-
|
|
470
|
-
That matches the direction already used in [memory-files.ts](/Users/oyasmi/projects/pipiclaw/src/memory-files.ts#L38).
|
|
471
|
-
|
|
472
|
-
## Sub-Agent Design Integration
|
|
473
|
-
|
|
474
|
-
Current sub-agents are explicitly isolated and only receive a generated runtime preamble plus the supplied task, [subagent.ts](/Users/oyasmi/projects/pipiclaw/src/tools/subagent.ts#L170).
|
|
475
|
-
|
|
476
|
-
The upgraded design adds:
|
|
477
|
-
|
|
478
|
-
1. `contextMode: isolated | contextual`
|
|
479
|
-
2. `memory: none | relevant | session | channel`
|
|
480
|
-
|
|
481
|
-
Semantics:
|
|
482
|
-
|
|
483
|
-
1. `isolated`
|
|
484
|
-
- current behavior
|
|
485
|
-
2. `contextual + relevant`
|
|
486
|
-
- prepend relevant recall slices for the subtask
|
|
487
|
-
3. `contextual + session`
|
|
488
|
-
- prepend condensed `SESSION.md`
|
|
489
|
-
4. `contextual + channel`
|
|
490
|
-
- prepend relevant `SESSION.md` plus durable memory summary
|
|
491
|
-
|
|
492
|
-
This avoids forcing the parent agent to manually hand-write all background context into `task`.
|
|
493
|
-
|
|
494
|
-
## Skill Design Integration
|
|
495
|
-
|
|
496
|
-
Current skill loading is metadata-light and passive, [agent.ts](/Users/oyasmi/projects/pipiclaw/src/agent.ts#L362).
|
|
497
|
-
|
|
498
|
-
The upgraded design adds light frontmatter semantics:
|
|
499
|
-
|
|
500
|
-
1. `when_to_use`
|
|
501
|
-
2. `allowed_tools`
|
|
502
|
-
3. `paths`
|
|
503
|
-
4. `hooks`
|
|
504
|
-
5. optional `memory_scope`
|
|
505
|
-
|
|
506
|
-
Supported hook points in first iteration:
|
|
507
|
-
|
|
508
|
-
1. `before_prompt`
|
|
509
|
-
2. `after_response`
|
|
510
|
-
3. `before_compact`
|
|
511
|
-
4. `after_subagent`
|
|
512
|
-
|
|
513
|
-
These hooks should remain session-scoped and lightweight. They exist to shape runtime context, not to build a separate automation engine.
|
|
514
|
-
|
|
515
|
-
## Explicitly Deferred Decisions
|
|
516
|
-
|
|
517
|
-
These are intentionally deferred so they do not block the first strong implementation:
|
|
518
|
-
|
|
519
|
-
1. persisted dirty-cursor metadata
|
|
520
|
-
2. prompt-cache-safe fork inheritance
|
|
521
|
-
3. richer background scheduling policy
|
|
522
|
-
4. automatic promotion heuristics based on file edit detection alone
|
|
523
|
-
|
|
524
|
-
If the first rollout proves stable, these can be revisited from real usage data rather than guessed up front.
|
|
525
|
-
|
|
526
|
-
## What We Intentionally Do Not Adopt Yet
|
|
527
|
-
|
|
528
|
-
We do not adopt these `claude-code` patterns in the first implementation:
|
|
529
|
-
|
|
530
|
-
1. full cache-safe fork inheritance
|
|
531
|
-
2. streaming concurrent tool executor
|
|
532
|
-
3. tmux/swarm task backends
|
|
533
|
-
4. full task OS abstractions
|
|
534
|
-
|
|
535
|
-
Reason:
|
|
536
|
-
|
|
537
|
-
The biggest near-term performance gain for `pipiclaw` comes from context quality, not orchestration maximalism.
|