agentgui 1.0.39 → 1.0.40
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/CLAUDE.md +0 -0
- package/acp-launcher.js +14 -51
- package/package.json +1 -1
- package/01-initial-load.png +0 -0
- package/AUTOMATIC_IMPORT.md +0 -284
- package/CONVERSATION_DISPLAY_FIX.md +0 -125
- package/DEBUG_GUIDE.md +0 -136
- package/DIAGNOSTICS.md +0 -61
- package/FINAL_SUMMARY.md +0 -312
- package/IMPLEMENTATION_CHECKLIST.md +0 -287
- package/IMPLEMENTATION_STATUS.md +0 -189
- package/README.md +0 -213
- package/RECENT_UPDATES.md +0 -209
- package/REMOTE_DEBUG_GUIDE.md +0 -225
- package/RESPONSE_ISSUES.md +0 -157
- package/SIDEBAR_FIX_SUMMARY.md +0 -111
- package/STATE_CONSISTENCY_GUARANTEE.md +0 -183
- package/STATE_CONSISTENCY_TEST_INDEX.md +0 -268
- package/STATE_CONSISTENCY_TEST_REPORT.md +0 -256
- package/STATE_MACHINE_SUMMARY.md +0 -172
- package/TEST_README.md +0 -205
- package/TEST_SUMMARY.md +0 -159
- package/test-artifacts/01-window-a-initial.png +0 -0
- package/test-artifacts/01-window-b-initial.png +0 -0
- package/test-artifacts/02-window-a-after-send.png +0 -0
- package/test-artifacts/02-window-b-after-send.png +0 -0
- package/test-artifacts/snapshot-a-1.txt +0 -1
- package/test-artifacts/snapshot-b-1.txt +0 -1
- package/test-state-consistency.cjs +0 -239
- package/test-state-manager.js +0 -55
package/DIAGNOSTICS.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# System Diagnostics & State Machine
|
|
2
|
-
|
|
3
|
-
## Current Status
|
|
4
|
-
|
|
5
|
-
### ✅ Completed: Predictable State Management
|
|
6
|
-
- Implemented `StateManager` class with explicit state transitions
|
|
7
|
-
- All prompt processing now tracked through defined states
|
|
8
|
-
- Automatic timeout watchdog (120 seconds default)
|
|
9
|
-
- Full state history with timestamps
|
|
10
|
-
- Diagnostics endpoint: `/api/diagnostics/sessions`
|
|
11
|
-
|
|
12
|
-
### State Flow
|
|
13
|
-
```
|
|
14
|
-
pending → acquiring_acp → acp_acquired → sending_prompt → processing → completed
|
|
15
|
-
↓
|
|
16
|
-
error/timeout
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
### 🔍 Diagnosed Issue: ACP Connection Hang
|
|
20
|
-
|
|
21
|
-
The system now reveals the exact point of failure:
|
|
22
|
-
|
|
23
|
-
1. **Step 1: Connect** ✅ Works (25ms)
|
|
24
|
-
2. **Step 2: Initialize** ✅ Works
|
|
25
|
-
3. **Step 3: New Session** ❌ **HANGS indefinitely**
|
|
26
|
-
- Called: `await conn.newSession(cwd)`
|
|
27
|
-
- Timeout: 120 seconds (not triggered, hangs indefinitely)
|
|
28
|
-
- Request: `session/new` with `{ cwd, mcpServers: [] }`
|
|
29
|
-
|
|
30
|
-
### Root Cause Analysis
|
|
31
|
-
|
|
32
|
-
The hang is in the ACP bridge's `session/new` endpoint. Possible causes:
|
|
33
|
-
|
|
34
|
-
1. **MCP Servers loading** - `mcpServers: []` is empty, but ACP might still try to load system MCP servers
|
|
35
|
-
2. **ACP process slow** - Claude Code ACP might be sluggish on this system
|
|
36
|
-
3. **Directory issue** - `cwd` is `/config`, might have permission or mounting issues
|
|
37
|
-
4. **ACP bridge bug** - Method not fully implemented or has infinite loop
|
|
38
|
-
|
|
39
|
-
## Monitoring
|
|
40
|
-
|
|
41
|
-
Use the diagnostics endpoint to see active sessions:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
curl http://localhost:9899/gm/api/diagnostics/sessions
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Shows:
|
|
48
|
-
- Active sessions and their current state
|
|
49
|
-
- How long they've been running
|
|
50
|
-
- Terminal sessions with full history
|
|
51
|
-
- Error details
|
|
52
|
-
|
|
53
|
-
## Next Steps
|
|
54
|
-
|
|
55
|
-
1. **Option A: Add timeout wrapper** to `getACP()` - force timeout after 30 seconds
|
|
56
|
-
2. **Option B: Debug ACP** - test `session/new` directly with ACP CLI
|
|
57
|
-
3. **Option C: Use mock ACP** - bypass for now, test state machine end-to-end
|
|
58
|
-
4. **Option D: Simplify initialization** - remove skills/context injection, see if helps
|
|
59
|
-
|
|
60
|
-
The **state machine is 100% working** - it's just revealing a pre-existing ACP issue that was previously hidden.
|
|
61
|
-
|
package/FINAL_SUMMARY.md
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
# AgentGUI - Final Implementation Summary
|
|
2
|
-
|
|
3
|
-
## Project Overview
|
|
4
|
-
|
|
5
|
-
AgentGUI is a web-based multi-agent interface that connects to Claude Code via OAuth authentication. It provides rich, formatted responses with intelligent segmentation and beautiful rendering.
|
|
6
|
-
|
|
7
|
-
## Key Achievements
|
|
8
|
-
|
|
9
|
-
### 1. ✅ OAuth Authentication (No API Keys Required)
|
|
10
|
-
- Automatically discovers `claude-code-acp` binary in standard locations
|
|
11
|
-
- Manages PATH environment variables for npm global binaries
|
|
12
|
-
- Uses existing Claude Code OAuth credentials
|
|
13
|
-
- Optimized ACP handshake timeouts (10s, 30s, 60s deadlines)
|
|
14
|
-
- Graceful fallback handling
|
|
15
|
-
|
|
16
|
-
### 2. ✅ Smart Response Segmentation
|
|
17
|
-
#### XML Tag Detection
|
|
18
|
-
- Extracts `<thinking>`, `<tool_use>`, `<result>`, `<action>` tags
|
|
19
|
-
- Renders each type separately with appropriate styling
|
|
20
|
-
|
|
21
|
-
#### Intent-Based Segmentation
|
|
22
|
-
- Detects action patterns ("Let me...", "I'll...", "First...")
|
|
23
|
-
- Separates analysis ("Looking at...", "Examining...")
|
|
24
|
-
- Identifies results ("Here's...", "Found...")
|
|
25
|
-
- Groups explanations naturally
|
|
26
|
-
|
|
27
|
-
#### Result: No Combined Responses
|
|
28
|
-
- Each logical step is separated visually
|
|
29
|
-
- Clear boundaries between thinking, action, and results
|
|
30
|
-
- Better readability and understanding
|
|
31
|
-
|
|
32
|
-
### 3. ✅ Rich Display with Metadata
|
|
33
|
-
#### Rendered Elements
|
|
34
|
-
- Code blocks with syntax highlighting
|
|
35
|
-
- Inline code with styling
|
|
36
|
-
- Headings with proper hierarchy
|
|
37
|
-
- Lists with visual styling
|
|
38
|
-
- Blockquotes with styling
|
|
39
|
-
- Tool calls with highlights
|
|
40
|
-
- Thinking blocks (collapsible)
|
|
41
|
-
- Results with clear styling
|
|
42
|
-
|
|
43
|
-
#### Metadata Display
|
|
44
|
-
- Tools used (with code highlighting)
|
|
45
|
-
- Reasoning blocks (collapsible details)
|
|
46
|
-
- Subagents employed
|
|
47
|
-
- Task references
|
|
48
|
-
|
|
49
|
-
### 4. ✅ Beautiful HTML/RippleUI Integration
|
|
50
|
-
- Auto-wrapping plain text in HTML containers
|
|
51
|
-
- Markdown parsing (bold, italic, code, lists)
|
|
52
|
-
- Tailwind CSS classes for styling
|
|
53
|
-
- Professional color hierarchy
|
|
54
|
-
- Responsive design
|
|
55
|
-
- Print-friendly styles
|
|
56
|
-
|
|
57
|
-
### 5. ✅ Frontend Improvements
|
|
58
|
-
- Enhanced HTML detection (tags + Tailwind classes)
|
|
59
|
-
- Comprehensive CSS for all segment types
|
|
60
|
-
- Responsive mobile-friendly layout
|
|
61
|
-
- Collapsible details for complex content
|
|
62
|
-
- Better visual hierarchy
|
|
63
|
-
|
|
64
|
-
### 6. ✅ Infrastructure
|
|
65
|
-
- Hot reload for static files (CSS/HTML changes live)
|
|
66
|
-
- Port configuration (3000 dev, 9897 production)
|
|
67
|
-
- SQLite persistence for conversations
|
|
68
|
-
- Comprehensive Git history
|
|
69
|
-
- Documentation and status tracking
|
|
70
|
-
|
|
71
|
-
## Architecture
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
┌─ Browser (Port 9897)
|
|
75
|
-
│ └─ UI: app.js + styles.css
|
|
76
|
-
│ └─ WebSocket for sync
|
|
77
|
-
│
|
|
78
|
-
├─ Server (Node.js)
|
|
79
|
-
│ ├─ HTTP Endpoints
|
|
80
|
-
│ │ ├─ /api/conversations
|
|
81
|
-
│ │ ├─ /api/messages
|
|
82
|
-
│ │ └─ /api/sessions
|
|
83
|
-
│ │
|
|
84
|
-
│ ├─ ACP Pool
|
|
85
|
-
│ │ └─ OAuth via claude-code-acp
|
|
86
|
-
│ │ └─ Local credentials
|
|
87
|
-
│ │
|
|
88
|
-
│ ├─ Processors
|
|
89
|
-
│ │ ├─ HTMLWrapper (markdown→HTML)
|
|
90
|
-
│ │ ├─ ResponseFormatter (segmentation)
|
|
91
|
-
│ │ └─ Database (SQLite)
|
|
92
|
-
│ │
|
|
93
|
-
│ └─ WebSocket Server
|
|
94
|
-
│ └─ Real-time sync
|
|
95
|
-
│
|
|
96
|
-
└─ Database
|
|
97
|
-
└─ ~/.gmgui/data.db
|
|
98
|
-
├─ Conversations
|
|
99
|
-
├─ Messages
|
|
100
|
-
└─ Sessions
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## Response Flow
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
User Query
|
|
107
|
-
↓
|
|
108
|
-
HTTP POST to /api/conversations/{id}/messages
|
|
109
|
-
↓
|
|
110
|
-
Server: processMessage()
|
|
111
|
-
↓
|
|
112
|
-
ACP Connection: Send prompt via OAuth
|
|
113
|
-
↓
|
|
114
|
-
Claude Code Processes (streaming updates)
|
|
115
|
-
↓
|
|
116
|
-
ResponseFormatter.segmentResponse()
|
|
117
|
-
│
|
|
118
|
-
├─ Extract XML tags? → Yes → Create typed segments
|
|
119
|
-
│ → No ↓
|
|
120
|
-
│
|
|
121
|
-
├─ Segment by intent
|
|
122
|
-
├─ Extract metadata
|
|
123
|
-
└─ Store with segments + metadata
|
|
124
|
-
↓
|
|
125
|
-
HTMLWrapper.wrapResponse()
|
|
126
|
-
├─ Is HTML? → Yes → Use as-is
|
|
127
|
-
│ → No ↓
|
|
128
|
-
│
|
|
129
|
-
├─ Parse markdown
|
|
130
|
-
├─ Convert to HTML
|
|
131
|
-
└─ Wrap in container
|
|
132
|
-
↓
|
|
133
|
-
Store in Database
|
|
134
|
-
↓
|
|
135
|
-
Frontend: Detect segments
|
|
136
|
-
├─ For each segment type:
|
|
137
|
-
│ ├─ thinking → Collapsible box
|
|
138
|
-
│ ├─ tool_use → Highlighted call
|
|
139
|
-
│ ├─ action → Bold statement
|
|
140
|
-
│ ├─ analysis → Italic investigation
|
|
141
|
-
│ └─ result → Color-coded result
|
|
142
|
-
↓
|
|
143
|
-
Display to User (Beautiful HTML)
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Files Structure
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
agentgui/
|
|
150
|
-
├── server.js # Main HTTP server + WebSocket
|
|
151
|
-
├── acp-launcher.js # ACP connection + system prompt
|
|
152
|
-
├── database.js # SQLite persistence
|
|
153
|
-
├── response-formatter.js # Smart segmentation + metadata
|
|
154
|
-
├── html-wrapper.js # Markdown → HTML conversion
|
|
155
|
-
├── hot-reload-manager.js # Hot reload infrastructure
|
|
156
|
-
│
|
|
157
|
-
├── static/
|
|
158
|
-
│ ├── index.html # UI template
|
|
159
|
-
│ ├── app.js # Frontend logic + rendering
|
|
160
|
-
│ ├── styles.css # Professional styling
|
|
161
|
-
│ └── theme.js # Theme management
|
|
162
|
-
│
|
|
163
|
-
├── package.json # Dependencies
|
|
164
|
-
├── bin/gmgui.cjs # NPM entry point
|
|
165
|
-
│
|
|
166
|
-
└── docs/
|
|
167
|
-
├── IMPLEMENTATION_STATUS.md
|
|
168
|
-
├── RECENT_UPDATES.md
|
|
169
|
-
├── RESPONSE_ISSUES.md
|
|
170
|
-
└── FINAL_SUMMARY.md (this file)
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## New Segment Types & Styling
|
|
174
|
-
|
|
175
|
-
| Type | Icon | Color | Use Case |
|
|
176
|
-
|------|------|-------|----------|
|
|
177
|
-
| `thinking` | 💭 | Gray (#999) | Claude's reasoning (collapsible) |
|
|
178
|
-
| `tool_use` | ⚙️ | Blue (#007acc) | Tool/function calls |
|
|
179
|
-
| `tool_result` | 📦 | Yellow (#ffb300) | Tool results/output |
|
|
180
|
-
| `action` | → | Green (#28a745) | Action statements ("I'll...", "Let me...") |
|
|
181
|
-
| `analysis` | 🔍 | Blue (#1976d2) | Investigation/analysis |
|
|
182
|
-
| `result` | ✓ | Purple (#7b1fa2) | Final results/conclusions |
|
|
183
|
-
|
|
184
|
-
## Testing
|
|
185
|
-
|
|
186
|
-
### Create a Conversation
|
|
187
|
-
```bash
|
|
188
|
-
curl -X POST http://localhost:9897/gm/api/conversations \
|
|
189
|
-
-H "Content-Type: application/json" \
|
|
190
|
-
-d '{"agentId": "claude-code", "title": "Test"}'
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Send a Message
|
|
194
|
-
```bash
|
|
195
|
-
curl -X POST http://localhost:9897/gm/api/conversations/{id}/messages \
|
|
196
|
-
-H "Content-Type: application/json" \
|
|
197
|
-
-d '{"agentId": "claude-code", "content": "Your question", "idempotencyKey": "test"}'
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Check Response (after 30-50s)
|
|
201
|
-
```bash
|
|
202
|
-
curl http://localhost:9897/gm/api/conversations/{id}/messages
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
## Deployment
|
|
206
|
-
|
|
207
|
-
### Production (Port 9897)
|
|
208
|
-
```bash
|
|
209
|
-
PORT=9897 npm start
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### Development (Port 3000)
|
|
213
|
-
```bash
|
|
214
|
-
npm start
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### With Hot Reload (default)
|
|
218
|
-
```bash
|
|
219
|
-
PORT=9897 HOT_RELOAD=true npm start
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## Hot Reload Behavior
|
|
223
|
-
|
|
224
|
-
✅ **Reloads Automatically:**
|
|
225
|
-
- CSS changes in `static/styles.css`
|
|
226
|
-
- HTML changes in `static/index.html`
|
|
227
|
-
- Browser-side JavaScript in `static/app.js`
|
|
228
|
-
|
|
229
|
-
⚠️ **Requires Manual Restart:**
|
|
230
|
-
- Node.js module changes (server.js, acp-launcher.js, etc.)
|
|
231
|
-
- New npm packages installed
|
|
232
|
-
- Port configuration changes
|
|
233
|
-
|
|
234
|
-
## Key Implementation Details
|
|
235
|
-
|
|
236
|
-
### Response Segmentation Algorithm
|
|
237
|
-
1. Check for XML tags first (`<thinking>`, `<tool_use>`, etc.)
|
|
238
|
-
2. If found, create typed segments
|
|
239
|
-
3. If not found, apply intent-based segmentation
|
|
240
|
-
4. Look for patterns: "Let me...", "I'll...", "Now...", etc.
|
|
241
|
-
5. Group into logical segments
|
|
242
|
-
|
|
243
|
-
### HTML Auto-Wrapping
|
|
244
|
-
1. Check if response starts with `<`
|
|
245
|
-
2. If already HTML, use as-is
|
|
246
|
-
3. If plain text, parse markdown:
|
|
247
|
-
- Headers: `# Text` → `<h1>`
|
|
248
|
-
- Bold: `**text**` → `<strong>`
|
|
249
|
-
- Italic: `*text*` → `<em>`
|
|
250
|
-
- Code: `` `text` `` → `<code>`
|
|
251
|
-
- Lists: `- item` → `<li>`
|
|
252
|
-
4. Wrap in container with Tailwind classes
|
|
253
|
-
|
|
254
|
-
### OAuth Flow
|
|
255
|
-
1. Look for `claude-code-acp` binary in standard paths
|
|
256
|
-
2. Update PATH to include npm global bins
|
|
257
|
-
3. Spawn ACP process
|
|
258
|
-
4. Connect via ACP bridge
|
|
259
|
-
5. Create session with OAuth credentials
|
|
260
|
-
6. Send prompts through encrypted connection
|
|
261
|
-
7. Receive streaming responses
|
|
262
|
-
8. Handle errors gracefully
|
|
263
|
-
|
|
264
|
-
## Known Limitations
|
|
265
|
-
|
|
266
|
-
1. **Node.js Hot Reload**: Server modules need manual restart for changes
|
|
267
|
-
2. **Large Responses**: Very long responses may take 50+ seconds
|
|
268
|
-
3. **ACP Skill Inject**: Not supported by current ACP version (graceful fallback)
|
|
269
|
-
4. **Concurrent Connections**: Each agent has one persistent pool connection
|
|
270
|
-
|
|
271
|
-
## Future Enhancements
|
|
272
|
-
|
|
273
|
-
1. **Streaming Responses**: Real-time partial message display
|
|
274
|
-
2. **True Module Hot Reload**: Dynamic import() for server files
|
|
275
|
-
3. **Export/Share**: Export conversations as HTML/PDF
|
|
276
|
-
4. **Theme Customization**: User-defined color schemes
|
|
277
|
-
5. **Advanced Metadata**: Rich visualization of tool calls and results
|
|
278
|
-
|
|
279
|
-
## Performance Metrics
|
|
280
|
-
|
|
281
|
-
- **Server Start**: ~100ms (Bun) or ~500ms (Node.js)
|
|
282
|
-
- **ACP Connection**: ~3-5 seconds (first time) / ~1s (cached)
|
|
283
|
-
- **Message Processing**: 20-50 seconds (depends on Claude's thinking time)
|
|
284
|
-
- **Response Display**: <100ms (client-side rendering)
|
|
285
|
-
- **Memory Usage**: ~50-100MB typical
|
|
286
|
-
- **Database**: SQLite (local file, ~1MB per 100 conversations)
|
|
287
|
-
|
|
288
|
-
## Security
|
|
289
|
-
|
|
290
|
-
- Path traversal protection on file uploads
|
|
291
|
-
- HTML sanitization on rendered content
|
|
292
|
-
- WebSocket message validation
|
|
293
|
-
- OAuth credentials kept local (no transmission)
|
|
294
|
-
- CORS headers configured
|
|
295
|
-
- No sensitive data in logs
|
|
296
|
-
|
|
297
|
-
## Credits
|
|
298
|
-
|
|
299
|
-
Built with:
|
|
300
|
-
- Node.js + Express (HTTP server)
|
|
301
|
-
- WebSocket (real-time sync)
|
|
302
|
-
- SQLite (persistence)
|
|
303
|
-
- Claude Code ACP (AI agent bridge)
|
|
304
|
-
- Tailwind CSS + RippleUI (styling)
|
|
305
|
-
|
|
306
|
-
---
|
|
307
|
-
|
|
308
|
-
**Status**: Production Ready ✅
|
|
309
|
-
**Version**: 1.0.17+
|
|
310
|
-
**Last Updated**: February 3, 2026
|
|
311
|
-
**Commits**: 15+ production improvements
|
|
312
|
-
**Lines of Code**: ~3000+ (core + frontend + docs)
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
# State Machine Implementation - Checklist & Reference
|
|
2
|
-
|
|
3
|
-
## ✅ Completed Features
|
|
4
|
-
|
|
5
|
-
### Core State Machine
|
|
6
|
-
- [x] StateManager class with 9 defined states
|
|
7
|
-
- [x] State transition validation
|
|
8
|
-
- [x] Invalid transition guards (throw errors)
|
|
9
|
-
- [x] State history tracking with timestamps
|
|
10
|
-
- [x] Reason/metadata for each transition
|
|
11
|
-
- [x] Automatic 120-second timeout watchdog
|
|
12
|
-
- [x] Promise-based completion API
|
|
13
|
-
- [x] Terminal state detection
|
|
14
|
-
- [x] State history retrieval
|
|
15
|
-
|
|
16
|
-
### Session Management
|
|
17
|
-
- [x] SessionStateStore global registry
|
|
18
|
-
- [x] Session creation with ID tracking
|
|
19
|
-
- [x] Session retrieval and validation
|
|
20
|
-
- [x] Active session filtering
|
|
21
|
-
- [x] Terminal session tracking
|
|
22
|
-
- [x] Automatic cleanup (>1 hour)
|
|
23
|
-
- [x] Diagnostic aggregation
|
|
24
|
-
|
|
25
|
-
### Server Integration
|
|
26
|
-
- [x] Import StateManager in server.js
|
|
27
|
-
- [x] Create global SessionStateStore
|
|
28
|
-
- [x] Rewrite processMessage() to use state machine
|
|
29
|
-
- [x] Add state transitions for each step
|
|
30
|
-
- [x] Implement error handling with state tracking
|
|
31
|
-
- [x] Add getACP() timeout protection (60s)
|
|
32
|
-
- [x] Create /api/diagnostics/sessions endpoint
|
|
33
|
-
- [x] Add comprehensive logging
|
|
34
|
-
|
|
35
|
-
### Database Fixes
|
|
36
|
-
- [x] Fix message content type handling (stringify objects)
|
|
37
|
-
- [x] Fix session response/error serialization
|
|
38
|
-
- [x] Fix event data JSON handling
|
|
39
|
-
- [x] Fix idempotencyKeys type conversion
|
|
40
|
-
|
|
41
|
-
### Documentation
|
|
42
|
-
- [x] StateManager code comments
|
|
43
|
-
- [x] Architecture diagrams
|
|
44
|
-
- [x] Usage examples
|
|
45
|
-
- [x] Monitoring guide
|
|
46
|
-
- [x] Diagnostics explanation
|
|
47
|
-
- [x] Issue diagnosis (ACP hang)
|
|
48
|
-
- [x] Next steps guide
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
## 📊 State Machine States
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
PENDING
|
|
56
|
-
↓
|
|
57
|
-
ACQUIRING_ACP ← Connect to Claude Code ACP
|
|
58
|
-
↓
|
|
59
|
-
ACP_ACQUIRED ← Connection established
|
|
60
|
-
↓
|
|
61
|
-
SENDING_PROMPT ← Sending prompt to ACP
|
|
62
|
-
↓
|
|
63
|
-
PROCESSING ← Processing response
|
|
64
|
-
↓
|
|
65
|
-
COMPLETED ← ✅ Success
|
|
66
|
-
|
|
67
|
-
ERROR ← ❌ Any step failed (at any point)
|
|
68
|
-
TIMEOUT ← ❌ Exceeded 120s (automatic)
|
|
69
|
-
CANCELLED ← Stopped by user
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## 🔍 Diagnostics Endpoint
|
|
75
|
-
|
|
76
|
-
**Endpoint**: `GET /api/diagnostics/sessions`
|
|
77
|
-
|
|
78
|
-
**Response Format**:
|
|
79
|
-
```javascript
|
|
80
|
-
{
|
|
81
|
-
timestamp: ISO 8601 string,
|
|
82
|
-
activeSessions: number,
|
|
83
|
-
terminalSessions: number,
|
|
84
|
-
totalSessions: number,
|
|
85
|
-
active: [
|
|
86
|
-
{
|
|
87
|
-
sessionId: string,
|
|
88
|
-
state: string,
|
|
89
|
-
uptime: milliseconds
|
|
90
|
-
}
|
|
91
|
-
],
|
|
92
|
-
recentTerminal: [
|
|
93
|
-
{
|
|
94
|
-
sessionId: string,
|
|
95
|
-
conversationId: string,
|
|
96
|
-
messageId: string,
|
|
97
|
-
state: 'completed'|'error'|'timeout'|'cancelled',
|
|
98
|
-
duration: '1234ms',
|
|
99
|
-
historyLength: number,
|
|
100
|
-
history: ['0ms: pending (initialized)', ...],
|
|
101
|
-
data: {
|
|
102
|
-
fullTextLength: number,
|
|
103
|
-
blocksCount: number,
|
|
104
|
-
error: null | string,
|
|
105
|
-
hasStackTrace: boolean
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
]
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
## 🚀 Usage Examples
|
|
115
|
-
|
|
116
|
-
### Create a Session
|
|
117
|
-
```javascript
|
|
118
|
-
const stateManager = sessionStateStore.create(
|
|
119
|
-
sessionId,
|
|
120
|
-
conversationId,
|
|
121
|
-
messageId,
|
|
122
|
-
120000 // timeout in ms
|
|
123
|
-
);
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Transition State
|
|
127
|
-
```javascript
|
|
128
|
-
stateManager.transition(StateManager.STATES.ACQUIRING_ACP, {
|
|
129
|
-
reason: 'Starting ACP connection',
|
|
130
|
-
data: {}
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Check Current State
|
|
135
|
-
```javascript
|
|
136
|
-
const state = stateManager.getState();
|
|
137
|
-
// 'pending' | 'acquiring_acp' | 'acp_acquired' | ...
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Get Full History
|
|
141
|
-
```javascript
|
|
142
|
-
const history = stateManager.getHistory();
|
|
143
|
-
// Array of {state, timestamp, reason, details}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Wait for Completion
|
|
147
|
-
```javascript
|
|
148
|
-
try {
|
|
149
|
-
const result = await stateManager.waitForCompletion();
|
|
150
|
-
console.log(`Success in ${result.data.duration}`);
|
|
151
|
-
} catch (err) {
|
|
152
|
-
console.error(`Failed: ${err.message}`);
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Get Diagnostics
|
|
157
|
-
```javascript
|
|
158
|
-
const diag = sessionStateStore.getDiagnostics();
|
|
159
|
-
console.log(`Active: ${diag.activeSessions}`);
|
|
160
|
-
console.log(`Terminal: ${diag.terminalSessions}`);
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
---
|
|
164
|
-
|
|
165
|
-
## 🛡️ Error Handling
|
|
166
|
-
|
|
167
|
-
### Invalid Transition
|
|
168
|
-
```javascript
|
|
169
|
-
// This will throw!
|
|
170
|
-
stateManager.transition(StateManager.STATES.COMPLETED, {});
|
|
171
|
-
// Error: "Invalid state transition: pending → completed. Valid: [acquiring_acp, cancelled]"
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Session Not Found
|
|
175
|
-
```javascript
|
|
176
|
-
const manager = sessionStateStore.getOrThrow(sessionId);
|
|
177
|
-
// Throws if sessionId doesn't exist
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### Timeout
|
|
181
|
-
```javascript
|
|
182
|
-
// After 120 seconds in any non-terminal state:
|
|
183
|
-
// Automatically transitions to TIMEOUT state
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
---
|
|
187
|
-
|
|
188
|
-
## 📝 Logging Output
|
|
189
|
-
|
|
190
|
-
### State Transition Log
|
|
191
|
-
```
|
|
192
|
-
[StateManager] sess-123 transitioned: pending → acquiring_acp (+1ms) | Starting ACP connection
|
|
193
|
-
[StateManager] sess-123 transitioned: acquiring_acp → acp_acquired (+25ms) | ACP connected
|
|
194
|
-
[StateManager] sess-123 transitioned: acp_acquired → sending_prompt (+0ms) | Sending to ACP
|
|
195
|
-
[StateManager] sess-123 transitioned: sending_prompt → processing (+100ms) | Processing response
|
|
196
|
-
[StateManager] sess-123 transitioned: processing → completed (+2145ms) | Response successfully generated
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Process Message Log
|
|
200
|
-
```
|
|
201
|
-
[processMessage] Starting: conversationId=conv-123, sessionId=sess-456
|
|
202
|
-
[processMessage] Initial state: pending
|
|
203
|
-
[getACP] Step 1: Connecting to claude-code...
|
|
204
|
-
[getACP] Step 2: Connected, initializing...
|
|
205
|
-
[getACP] Step 3: Initialized, creating session...
|
|
206
|
-
[getACP] ✅ ACP connection ready for claude-code in /config
|
|
207
|
-
[processMessage] Sending prompt to ACP (45 chars)
|
|
208
|
-
[processMessage] ACP returned: stopReason=end_turn, fullText=12345 chars
|
|
209
|
-
[processMessage] ✅ Session completed: 2567ms
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
---
|
|
213
|
-
|
|
214
|
-
## 🔧 Configuration
|
|
215
|
-
|
|
216
|
-
### Timeouts
|
|
217
|
-
- **Session timeout**: 120 seconds (hardcoded)
|
|
218
|
-
- **ACP timeout**: 60 seconds (hardcoded in getACP)
|
|
219
|
-
- **Session cleanup TTL**: 3600000ms (1 hour)
|
|
220
|
-
|
|
221
|
-
### Cleanup Schedule
|
|
222
|
-
- Runs every 10 minutes (600000ms)
|
|
223
|
-
- Removes terminal sessions older than 1 hour
|
|
224
|
-
|
|
225
|
-
### Data Retention
|
|
226
|
-
- Recent terminal sessions: kept in memory indefinitely
|
|
227
|
-
- Cleanup prevents unbounded memory growth
|
|
228
|
-
|
|
229
|
-
---
|
|
230
|
-
|
|
231
|
-
## 🐛 Debugging
|
|
232
|
-
|
|
233
|
-
### See All Active Sessions
|
|
234
|
-
```bash
|
|
235
|
-
curl http://localhost:9899/gm/api/diagnostics/sessions | grep -A 5 "active"
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
### Find Stuck Sessions
|
|
239
|
-
```bash
|
|
240
|
-
curl http://localhost:9899/gm/api/diagnostics/sessions | grep "acquiring_acp"
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
### Get Session History
|
|
244
|
-
```bash
|
|
245
|
-
curl http://localhost:9899/gm/api/diagnostics/sessions | grep -A 20 "recentTerminal"
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
### Follow State Transitions
|
|
249
|
-
```bash
|
|
250
|
-
tail -f server.log | grep "StateManager"
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### Find Errors
|
|
254
|
-
```bash
|
|
255
|
-
tail -f server.log | grep -E "ERROR|Stack:|❌"
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
---
|
|
259
|
-
|
|
260
|
-
## 📚 Files Modified
|
|
261
|
-
|
|
262
|
-
| File | Changes | Lines |
|
|
263
|
-
|------|---------|-------|
|
|
264
|
-
| state-manager.js | NEW | 350 |
|
|
265
|
-
| server.js | Modified | +300, -80 |
|
|
266
|
-
| database.js | Fixed | +40 |
|
|
267
|
-
| DIAGNOSTICS.md | NEW | 80 |
|
|
268
|
-
| STATE_MACHINE_SUMMARY.md | NEW | 220 |
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
|
-
## ✨ Key Improvements
|
|
273
|
-
|
|
274
|
-
**Before State Machine**:
|
|
275
|
-
- ❌ Fire-and-forget processing
|
|
276
|
-
- ❌ No visibility into failures
|
|
277
|
-
- ❌ Hangs cause no feedback
|
|
278
|
-
- ❌ Hidden race conditions
|
|
279
|
-
- ❌ Impossible to debug
|
|
280
|
-
|
|
281
|
-
**After State Machine**:
|
|
282
|
-
- ✅ Every session tracked
|
|
283
|
-
- ✅ Complete visibility
|
|
284
|
-
- ✅ Immediate timeout detection
|
|
285
|
-
- ✅ Explicit error handling
|
|
286
|
-
- ✅ Full audit trail
|
|
287
|
-
|