@hienlh/ppm 0.9.19 → 0.9.21
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/CHANGELOG.md +11 -0
- package/dist/web/assets/{browser-tab-DQooX_NG.js → browser-tab-h-o4sr-C.js} +1 -1
- package/dist/web/assets/{chat-tab-DN1gkctd.js → chat-tab-CAtJTlUG.js} +1 -1
- package/dist/web/assets/{code-editor-CQS14TkD.js → code-editor-BpqGrgO5.js} +1 -1
- package/dist/web/assets/{database-viewer-Cubi4CgO.js → database-viewer-CAoT6uGQ.js} +1 -1
- package/dist/web/assets/{diff-viewer-Dhe-nwBH.js → diff-viewer-topWA5Ta.js} +1 -1
- package/dist/web/assets/{extension-webview-DKk1VRdk.js → extension-webview-CaKx8yvJ.js} +1 -1
- package/dist/web/assets/{git-graph-1I4ZysBp.js → git-graph-CtzzQol9.js} +1 -1
- package/dist/web/assets/index-CrA8grdC.js +37 -0
- package/dist/web/assets/keybindings-store-BkysY7OH.js +1 -0
- package/dist/web/assets/{markdown-renderer-BSnLPKA9.js → markdown-renderer-nuQkYTwi.js} +1 -1
- package/dist/web/assets/{postgres-viewer-C0ymjGr_.js → postgres-viewer-D8RVcxoD.js} +1 -1
- package/dist/web/assets/{settings-tab-DAEDfps3.js → settings-tab-BO8VGVhV.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-DpJ1s0OV.js → sqlite-viewer-CeOBrFyF.js} +1 -1
- package/dist/web/assets/{tab-store-CeOacjuH.js → tab-store-D_bvdnNN.js} +1 -1
- package/dist/web/assets/{terminal-tab-Dpch-fU5.js → terminal-tab-CqTiEwFF.js} +1 -1
- package/dist/web/assets/{use-monaco-theme-VqvGfpV-.js → use-monaco-theme-BFgASSqT.js} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/docs/streaming-input-guide.md +267 -0
- package/package.json +1 -1
- package/snapshot-state.md +1526 -0
- package/src/providers/claude-agent-sdk.ts +57 -8
- package/src/web/app.tsx +11 -8
- package/test-session-ops.mjs +444 -0
- package/test-tokens.mjs +212 -0
- package/.claude.bak/agent-memory/tester/MEMORY.md +0 -3
- package/.claude.bak/agent-memory/tester/project-ppm-test-conventions.md +0 -32
- package/dist/web/assets/index-BzIjHwjQ.js +0 -37
- package/dist/web/assets/keybindings-store-B4z1Uu7-.js +0 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# Streaming Input Migration Quick Reference (v0.8.55+)
|
|
2
|
+
|
|
3
|
+
## What Changed?
|
|
4
|
+
|
|
5
|
+
**Before (v0.8.54):** Each message triggered a new SDK query
|
|
6
|
+
```
|
|
7
|
+
Message 1 → SDK subprocess spawn → generate response → close
|
|
8
|
+
Message 2 → SDK subprocess spawn → generate response → close
|
|
9
|
+
(Slow, context resets between messages)
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
**After (v0.8.55):** Single persistent streaming session
|
|
13
|
+
```
|
|
14
|
+
Session created → AsyncGenerator streaming input opened
|
|
15
|
+
Message 1 → Push into generator → process events
|
|
16
|
+
Message 2 → Push into same generator → continue streaming
|
|
17
|
+
(Fast, continuous context, no SDK restarts)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Key Concepts
|
|
21
|
+
|
|
22
|
+
### Session State (BE-Owned)
|
|
23
|
+
The backend maintains a `SessionEntry` per chat session:
|
|
24
|
+
- Tracks connected clients (can be zero if FE disconnected)
|
|
25
|
+
- Maintains streaming phase (idle, connecting, thinking, streaming)
|
|
26
|
+
- Buffers events for reconnection sync
|
|
27
|
+
- Auto-cleans after 5 minutes of FE inactivity
|
|
28
|
+
|
|
29
|
+
### Message Priority (v0.8.55+)
|
|
30
|
+
```typescript
|
|
31
|
+
// Send message with priority
|
|
32
|
+
ws.send({
|
|
33
|
+
type: "message",
|
|
34
|
+
content: "Debug this code",
|
|
35
|
+
priority: "now" // "now" | "next" | "later"
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
- **"now"** — Abort current query, restart with this message
|
|
39
|
+
- **"next"** — Queue after current, run next
|
|
40
|
+
- **"later"** — Append to queue, run last
|
|
41
|
+
|
|
42
|
+
### Event Buffering on Reconnect
|
|
43
|
+
When FE WS reconnects after disconnect:
|
|
44
|
+
1. BE sends `session_state` with current phase + pending approval
|
|
45
|
+
2. BE sends `turn_events` with all buffered events since last connection
|
|
46
|
+
3. FE rebuilds chat UI state from buffered events
|
|
47
|
+
4. No message loss (unless session cleaned up after 5min)
|
|
48
|
+
|
|
49
|
+
## Common Patterns
|
|
50
|
+
|
|
51
|
+
### Frontend: Send Message
|
|
52
|
+
```typescript
|
|
53
|
+
// In useChat hook or message input handler
|
|
54
|
+
ws.send(JSON.stringify({
|
|
55
|
+
type: "message",
|
|
56
|
+
content: userInput,
|
|
57
|
+
priority: "now", // Optional
|
|
58
|
+
images: [{ id: "img1", data: "base64..." }] // Optional
|
|
59
|
+
}));
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Frontend: Handle Reconnection
|
|
63
|
+
```typescript
|
|
64
|
+
function handleReconnect() {
|
|
65
|
+
// 1. WS open fires
|
|
66
|
+
// 2. Server sends session_state
|
|
67
|
+
const sessionState = JSON.parse(msg);
|
|
68
|
+
// 3. Server sends turn_events
|
|
69
|
+
const turnEvents = JSON.parse(msg);
|
|
70
|
+
|
|
71
|
+
// 4. FE rebuilds state from buffered events
|
|
72
|
+
turnEvents.events.forEach(event => {
|
|
73
|
+
chatStore.addEvent(event);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// 5. FE is now synced with BE
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Backend: Session Lifecycle
|
|
81
|
+
```typescript
|
|
82
|
+
// 1. FE connects
|
|
83
|
+
open(ws) {
|
|
84
|
+
const entry = activeSessions.get(sessionId);
|
|
85
|
+
if (!entry) {
|
|
86
|
+
// Create new session entry
|
|
87
|
+
activeSessions.set(sessionId, {
|
|
88
|
+
phase: "idle",
|
|
89
|
+
clients: new Set([ws]),
|
|
90
|
+
turnEvents: []
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
// Reconnect: clear cleanup timer, add client
|
|
94
|
+
entry.clients.add(ws);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 2. FE sends message
|
|
99
|
+
message(ws, data) {
|
|
100
|
+
const parsed = JSON.parse(data);
|
|
101
|
+
if (parsed.type === "message") {
|
|
102
|
+
// Abort current if streaming, wait for cleanup
|
|
103
|
+
if (entry.phase !== "idle") {
|
|
104
|
+
entry.abort.abort();
|
|
105
|
+
await entry.streamPromise;
|
|
106
|
+
}
|
|
107
|
+
// Start new streaming loop (detached)
|
|
108
|
+
entry.streamPromise = runStreamLoop(...);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 3. Streaming loop runs independently
|
|
113
|
+
async function runStreamLoop() {
|
|
114
|
+
for await (const event of chatService.sendMessage(...)) {
|
|
115
|
+
bufferAndBroadcast(sessionId, event); // To all connected clients
|
|
116
|
+
}
|
|
117
|
+
setPhase(sessionId, "idle"); // Back to idle when done
|
|
118
|
+
if (entry.clients.size === 0) {
|
|
119
|
+
startCleanupTimer(sessionId); // 5-min cleanup
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 4. FE disconnects
|
|
124
|
+
close(ws) {
|
|
125
|
+
entry.clients.delete(ws);
|
|
126
|
+
// Stream continues! (BE owns the connection)
|
|
127
|
+
// Timer started if no more clients
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Phase State Machine
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
┌─ initializing (setup, session resume)
|
|
135
|
+
↓
|
|
136
|
+
idle ←→ connecting (waiting for first SDK event, heartbeat)
|
|
137
|
+
↑ ↓
|
|
138
|
+
│ ┌──→ thinking (extended thinking)
|
|
139
|
+
│ ↓ ↓
|
|
140
|
+
└─── streaming (text/tool_use content)
|
|
141
|
+
↑ ↓
|
|
142
|
+
└─────┘ (dynamic switch)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Transitions:**
|
|
146
|
+
- Heartbeat: `connecting` → (5s elapsed updates) → `thinking` (when content arrives)
|
|
147
|
+
- Content: `thinking` → `streaming` (first text event)
|
|
148
|
+
- Dynamic: `streaming` ↔ `thinking` (based on event types)
|
|
149
|
+
- Done: Any → `idle` (stream complete, ready for next message)
|
|
150
|
+
|
|
151
|
+
## WebSocket Messages (v0.8.55+)
|
|
152
|
+
|
|
153
|
+
### Client → Server
|
|
154
|
+
```typescript
|
|
155
|
+
// Send message
|
|
156
|
+
{ type: "message"; content: string; priority?: string; images?: {...}[] }
|
|
157
|
+
|
|
158
|
+
// Approve tool
|
|
159
|
+
{ type: "approval_response"; requestId: string; approved: boolean }
|
|
160
|
+
|
|
161
|
+
// Cancel current
|
|
162
|
+
{ type: "cancel" }
|
|
163
|
+
|
|
164
|
+
// Handshake after open
|
|
165
|
+
{ type: "ready" }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Server → Client
|
|
169
|
+
```typescript
|
|
170
|
+
// Content
|
|
171
|
+
{ type: "text"; content: string }
|
|
172
|
+
{ type: "thinking"; content: string }
|
|
173
|
+
|
|
174
|
+
// Tool execution
|
|
175
|
+
{ type: "tool_use"; tool: string; input: unknown }
|
|
176
|
+
{ type: "tool_result"; output: string; isError?: boolean }
|
|
177
|
+
|
|
178
|
+
// User approval request
|
|
179
|
+
{ type: "approval_request"; requestId: string; tool: string; input: unknown }
|
|
180
|
+
|
|
181
|
+
// Session state (sent on open/ready)
|
|
182
|
+
{ type: "session_state"; sessionId: string; phase: SessionPhase; pendingApproval: {...} | null }
|
|
183
|
+
|
|
184
|
+
// Buffered events (on reconnect)
|
|
185
|
+
{ type: "turn_events"; events: unknown[] }
|
|
186
|
+
|
|
187
|
+
// Metadata
|
|
188
|
+
{ type: "account_info"; accountId: string; accountLabel: string }
|
|
189
|
+
{ type: "phase_changed"; phase: SessionPhase; elapsed?: number }
|
|
190
|
+
{ type: "title_updated"; title: string }
|
|
191
|
+
|
|
192
|
+
// Completion
|
|
193
|
+
{ type: "done"; sessionId: string; contextWindowPct?: number }
|
|
194
|
+
|
|
195
|
+
// Error
|
|
196
|
+
{ type: "error"; message: string }
|
|
197
|
+
|
|
198
|
+
// Keepalive
|
|
199
|
+
{ type: "ping" }
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Benefits
|
|
203
|
+
|
|
204
|
+
| Aspect | Before (v0.8.54) | After (v0.8.55) |
|
|
205
|
+
|--------|------------------|-----------------|
|
|
206
|
+
| **SDK Restarts** | Per message | Once per session |
|
|
207
|
+
| **Context** | Resets between messages | Persistent |
|
|
208
|
+
| **Startup Time** | 2-5s per message | Instant follow-ups |
|
|
209
|
+
| **Reconnection** | Message loss | Event buffering ensures sync |
|
|
210
|
+
| **Concurrency** | N/A | Multiple clients per session |
|
|
211
|
+
| **Tool Approvals** | Restarts query | Integrated in stream |
|
|
212
|
+
|
|
213
|
+
## Troubleshooting
|
|
214
|
+
|
|
215
|
+
### Session Cleaned Up (No Longer Exists)
|
|
216
|
+
**Cause:** FE disconnected for >5 minutes
|
|
217
|
+
**Solution:** Create new session, FE reconnects with new sessionId
|
|
218
|
+
|
|
219
|
+
### Events Missing After Reconnect
|
|
220
|
+
**Cause:** Server-side event buffer (10k event limit) overflowed
|
|
221
|
+
**Solution:** Flush buffer periodically or increase limit if needed
|
|
222
|
+
|
|
223
|
+
### Phase Stuck in "Connecting"
|
|
224
|
+
**Cause:** SDK subprocess not responding (120s timeout)
|
|
225
|
+
**Solution:** Check environment (ANTHROPIC_API_KEY, network), see error message for hints
|
|
226
|
+
|
|
227
|
+
### Multiple Clients Out of Sync
|
|
228
|
+
**Cause:** Broadcast failed for one client, others ahead
|
|
229
|
+
**Solution:** Evicted client will reconnect and re-sync from buffered events
|
|
230
|
+
|
|
231
|
+
## Debugging
|
|
232
|
+
|
|
233
|
+
### Enable Logging
|
|
234
|
+
```bash
|
|
235
|
+
# Check server logs for session lifecycle
|
|
236
|
+
[chat] session=abc123 phase → connecting
|
|
237
|
+
[chat] session=abc123 first SDK event after 1250ms: type=text
|
|
238
|
+
[chat] session=abc123 stream completed (45 events)
|
|
239
|
+
[chat] session=abc123 phase → idle
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Check Session State
|
|
243
|
+
```typescript
|
|
244
|
+
// On WS message handler
|
|
245
|
+
console.log(`Session entry:`, activeSessions.get(sessionId));
|
|
246
|
+
// Outputs: { phase, clients.size, pendingApprovalEvent, turnEvents.length }
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Monitor Reconnections
|
|
250
|
+
```typescript
|
|
251
|
+
// In WS open handler
|
|
252
|
+
console.log(`FE reconnected (phase=${existing.phase}, clients=${existing.clients.size})`);
|
|
253
|
+
// Tells you: active streaming, how many clients connected
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Performance Notes
|
|
257
|
+
|
|
258
|
+
- **No SDK overhead:** Persistent streaming eliminates subprocess spawn overhead
|
|
259
|
+
- **Event buffering:** Clients see all events after reconnect (max 10k events per turn)
|
|
260
|
+
- **Memory:** Session entries cleaned after 5min (bounded memory usage)
|
|
261
|
+
- **Latency:** Follow-up messages start immediately (no SDK init)
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
**For detailed architecture:** See `docs/system-architecture.md` → "Chat Streaming Flow" section
|
|
266
|
+
**For API types:** See `src/types/api.ts` and `src/types/chat.ts`
|
|
267
|
+
**For implementation:** See `src/server/ws/chat.ts` and `src/providers/claude-agent-sdk.ts`
|