agentgui 1.0.915 → 1.0.917

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/AGENTS.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # AgentGUI — Agent Notes
2
2
 
3
+ ## New architecture (2026-05-02 pivot)
4
+
5
+ There are now **two parallel surfaces** in this repo. Don't conflate them when editing.
6
+
7
+ 1. **Live client** at `site/app/` — single static page, imports [`anentrypoint-design`](https://www.npmjs.com/package/anentrypoint-design) from unpkg, talks to any [`acptoapi`](https://www.npmjs.com/package/acptoapi) backend over fetch / SSE. No build step. Deploys to GH Pages at `/app/` via `.github/workflows/gh-pages.yml` (post-flatspace copy step).
8
+ - `site/app/index.html` — shell + CSS
9
+ - `site/app/js/backend.js` — acptoapi client (models, chat-stream, history, search, SSE)
10
+ - `site/app/js/app.js` — webjsx view + state, exposes `window.__agentgui` for debug
11
+ - Configurable backend URL via `?backend=…` query string or `localStorage['agentgui.backend']`
12
+
13
+ 2. **Legacy server** (`server.js`, `lib/`, `static/`) — the npm-installable Node app, still works, still gets `npm run dev`. Being phased out as the static client + acptoapi cover its features. Don't delete in passing; full removal is its own PR.
14
+
15
+ Backend dependencies:
16
+ - `acptoapi` provides chat / messages / models endpoints (existing) + new history endpoints (`/v1/history/sessions`, `/v1/history/sessions/:sid/events`, `/v1/history/search`, `/v1/history/stream`) — see `c:\dev\acptoapi\lib\history\` (ccsniff functionality merged in 2026-05-02).
17
+ - `anentrypoint-design` provides AppShell / Chat / FileGrid / etc. — single-file ESM from unpkg, no install.
18
+
19
+ The static client never imports anything from `lib/` or `server.js`. Cross-contamination = bug.
20
+
21
+ ## Learning audit
22
+
23
+ - 2026-05-02 session: 5 items audited (CI bun, stream imports, windows fallback, GM blocker, ACP history), 0 removed (rs-learn retrieval not yet confirmed; safety default kept all), 1 new fact ingested (acptoapi history integration)
24
+
3
25
  ## CI / GitHub Actions
4
26
 
5
27
  **capture-screenshots must run under bun, not node.**
@@ -31,3 +53,24 @@ On Windows hosts without bun installed, the auto-provisioner on startup and 6h p
31
53
  Fix: `BUNX_RUNNERS` array iterates `['bun', 'npx']` and tries each in sequence. Error detection regex `isMissingCmdError` matches `/not recognized|ENOENT|command not found|cannot find/i` on both `error.message` and captured stdout+stderr. Only falls through to next runner when the `missing` flag is set.
32
54
 
33
55
  Pattern: When a binary might not exist on all platforms, use a runner fallback strategy. Always capture and check both error.message and process output streams. Cross-platform error detection requires regex alternation on common message patterns.
56
+
57
+ ## GM Plugin Autonomy Blocker
58
+
59
+ **gm plugin's pre-tool-use-hook.js enforces "must invoke gm:gm first" gate, blocking multi-tool autonomy. Hook content is NOT sourced from gm-starter/hooks/ files — it is templated from somewhere else.**
60
+
61
+ The gm plugin enforces a gate via `.gm/needs-gm` marker that requires invoking `gm:gm` before any other tool use, which fragments multi-tool autonomous sessions in agentgui. A bypass patch was committed to c:/dev/gm (commit e300acf7, origin/main) in gm-starter/hooks/{pre-tool-use,prompt-submit}-hook.js to skip the gate when `.gm/prd.yml` exists, but it did NOT propagate after `/plugin update gm` (cache hash changed 495e36843d77 → 075e64d58498 but hook content unchanged).
62
+
63
+ The actual hook content is generated/templated from c:/dev/gm, likely from `lib/cli-adapter.js` or `platforms/cli-config-shared.js` or `lib/template-builder.js`, not from gm-starter/hooks/. Next session must:
64
+ 1. Locate the real hook generator in the gm codebase
65
+ 2. Patch it to add `if (autonomous) { try { fs.unlinkSync(needsGmPath); } catch {} }` when `.gm/prd.yml` exists
66
+ 3. Rebuild via `node c:/dev/gm/cli.js c:/dev/gm/gm-starter c:/dev/gm/build`
67
+ 4. Push changes to c:/dev/gm origin/main
68
+ 5. Run `/plugin update gm` in agentgui
69
+
70
+ Only after the real generator is patched will agentgui sessions run autonomously without per-tool ceremony.
71
+
72
+ ## ACP-to-API History Integration
73
+
74
+ **acptoapi (c:\dev\acptoapi) merged Claude Code history routes as of 2026-05-02; ccsniff package is no longer needed.**
75
+
76
+ History functionality (`GET /v1/history/*` endpoints) is now built into acptoapi. Routes: `snapshot` (event/session/project/tool/error counts + byte/date range), `sessions` (list with title/project/cwd/counts), `sessions/:sid/events` (flattened events), `search` (BM25 with snippets), `reindex` (rebuild index), `stream` (SSE). Implementation: `lib/history/` (bm25.js for tokenize/buildIndex/search/snippet, watcher.js for JsonlWatcher + JsonlReplayer, index.js for HistoryStore singleton + flattenEvent). Reads `~/.claude/projects` by default; override with `CLAUDE_PROJECTS_DIR` env var. The ccsniff package itself is no longer required — acptoapi covers the functionality entirely.
package/CLAUDE.md CHANGED
@@ -1,382 +1 @@
1
- # AgentGUI
2
-
3
- Multi-agent GUI client for AI coding agents (Claude Code, Gemini CLI, OpenCode, Goose, etc.) with real-time streaming, WebSocket sync, and SQLite persistence.
4
-
5
- ## Running
6
-
7
- ```bash
8
- npm install
9
- npm run dev # node server.js --watch
10
- ```
11
-
12
- Server starts on `http://localhost:3000`, redirects to `/gm/`.
13
-
14
- ## Architecture
15
-
16
- ```
17
- server.js Bootstrap: imports, constants, wiring of all factories; delegates to lib/ modules for HTTP handler, WS setup, routes, startup
18
- database.js SQLite connection, schema DDL, migrations (queries extracted to lib/db-queries.js)
19
- acp-queries.js ACP query helpers (UUID, timestamp, JSON utilities)
20
- bin/gmgui.cjs CLI entry point (npx agentgui / bun x agentgui)
21
-
22
- lib/claude-runner.js Agent framework - AgentRunner/AgentRegistry classes, direct protocol execution
23
- lib/acp-runner.js ACP JSON-RPC session lifecycle (init, session/new, prompt, drain)
24
- lib/acp-protocol.js ACP session/update message normalization (shared by all ACP agents)
25
- lib/acp-sdk-manager.js ACP tool lifecycle - on-demand start opencode/kilo/codex, health checks, idle timeout
26
- lib/acp-server-machine.js XState v5 machine per ACP tool: stopped/starting/running/crashed/restarting states
27
- lib/agent-discovery.js Agent binary detection (findCommand), ACP server query, discoverAgents, CLI wrapper logic
28
- lib/agent-descriptors.js Data-driven ACP agent descriptor builder
29
- lib/checkpoint-manager.js Session recovery - load checkpoints, inject into resume flow, idempotency
30
- lib/codec.js msgpack encode/decode (pack/unpack wrappers)
31
- lib/db-queries.js All 88 query functions (createQueries factory, extracted from database.js)
32
- lib/execution-machine.js XState v5 machine per conversation: idle/streaming/draining/rate_limited states
33
- lib/gm-agent-configs.js GM agent configuration and spawning
34
- lib/jsonl-parser.js JSONL event parsing, session tracking, streaming state (extracted from jsonl-watcher.js)
35
- lib/jsonl-watcher.js Watches ~/.claude/projects for JSONL file changes, delegates parsing to jsonl-parser.js
36
- lib/oauth-common.js Shared OAuth helpers (buildBaseUrl, isRemoteRequest, encodeOAuthState, result/relay pages)
37
- lib/oauth-gemini.js Gemini OAuth flow (credential discovery, token exchange, callback handling)
38
- lib/oauth-codex.js Codex CLI OAuth flow (PKCE S256, token exchange, callback handling)
39
- lib/plugin-loader.js Plugin discovery and loading (EventEmitter-based)
40
- lib/pm2-manager.js PM2 process management wrapper
41
- lib/speech.js Speech-to-text and text-to-speech via @huggingface/transformers
42
- lib/speech-manager.js TTS orchestration (eager TTS, voice cache, model download, broadcastModelProgress)
43
- lib/tool-install-machine.js XState v5 machine per tool: unchecked/checking/idle/installing/installed/updating/needs_update/failed states
44
- lib/tool-manager.js Tool facade - re-exports from tool-version-check, tool-version-fetch, tool-spawner, tool-provisioner
45
- lib/tool-version-check.js Sync/local version detection: BIN_MAP, FRAMEWORK_PATHS, checkCliInstalled, getCliVersion, checkToolInstalled, compareVersions, getInstalledVersion
46
- lib/tool-version-fetch.js Async/network version functions: getPublishedVersion, fetchPublishedVersion, clearVersionCache, checkToolViaBunx
47
- lib/tool-spawner.js npm/bun install/update spawn with timeout and heartbeat
48
- lib/tool-provisioner.js Auto-provisioning and periodic update checking
49
- lib/routes-speech.js Speech/TTS HTTP route handlers (stt, tts, voices, speech-status)
50
- lib/routes-oauth.js OAuth HTTP route handlers (gemini-oauth/*, codex-oauth/*)
51
- lib/routes-tools.js Tool management HTTP route handlers (list, install, update, history, refresh)
52
- lib/routes-util.js Utility HTTP route handlers (clone, folders, git, home, version, import)
53
- lib/routes-agents.js Agent list/search/auth-status/descriptor/models HTTP route handlers
54
- lib/routes-conversations.js Conversation CRUD HTTP route handlers (list, create, get, update, delete, archive, restore)
55
- lib/routes-messages.js Message/stream/queue HTTP route handlers (GET+POST messages, stream, queue CRUD)
56
- lib/routes-sessions.js Session/chunk/full/execution HTTP route handlers (session get, chunks, full load, execution events)
57
- lib/routes-runs.js Runs HTTP route handlers (POST /api/runs, runs search, run by id, wait, cancel, thread run cancel/wait)
58
- lib/routes-scripts.js Scripts/cancel/resume/inject HTTP route handlers (conversation scripts, run-script, stop-script, cancel, resume, inject)
59
- lib/routes-agent-actions.js Agent auth and update HTTP route handlers (POST /api/agents/:id/auth, POST /api/agents/:id/update)
60
- lib/routes-auth-config.js Auth config HTTP route handlers (GET /api/auth/configs, POST /api/auth/save-config)
61
- lib/routes-upload.js Express sub-app: POST /api/upload/:conversationId (Busboy file upload) + GET /files/:conversationId fsbrowse router; createExpressApp(deps) factory
62
- lib/http-utils.js HTTP utility functions (parseBody, acceptsEncoding, compressAndSend, sendJSON)
63
- lib/http-handler.js Main HTTP request handler factory: createHttpHandler(deps) => async (req,res); rate limiting, auth, CORS, route dispatch, static file serving
64
- lib/provider-config.js Provider config helpers (buildSystemPrompt, maskKey, getProviderConfigs, saveProviderConfig, PROVIDER_CONFIGS)
65
- lib/server-utils.js Server utility functions (logError, errLogPath, makeCleanupExecution, makeGetModelsForAgent)
66
- lib/routes-registry.js Route + WS handler registration: createRegistry(wsRouter, deps) => _routes; wires all HTTP route _match objects and all WS handler registrations
67
- lib/ws-setup.js WebSocket server setup: createWsSetup(server, deps) => { wss, hotReloadClients }; connection auth, client tracking, watch file reload, heartbeat
68
- lib/ws-legacy-handlers.js Legacy WS message handler: subscribe/unsubscribe/terminal PTY/pm2 commands; called from ws-setup.js onLegacy
69
- lib/server-startup.js Server startup: createOnServerReady(deps) => { onServerReady, getJsonlWatcher }; tools, ACP, speech, PM2 monitoring init
70
- lib/server-startup2.js Startup helpers: createAutoImport (hasIndexFilesChanged + performAutoImport), createDbRecovery (orphaned session cleanup), createPluginLoader (plugin extension loading)
71
- lib/routes-debug.js Debug/backup/restore/ws-stats HTTP route handlers
72
- lib/routes-threads.js Thread CRUD HTTP route handlers (ACP v0.2.3 thread API)
73
- lib/ws-protocol.js WebSocket RPC router (WsRouter class)
74
- lib/ws-optimizer.js Per-client priority queue for WS event batching
75
- lib/ws-handlers-conv.js Conversation CRUD, chunks, cancel, steer, inject RPC handlers
76
- lib/ws-handlers-msg.js Message send/stream/list RPC handlers + execution start/enqueue
77
- lib/ws-handlers-queue.js Queue list/delete/update RPC handlers
78
- lib/ws-handlers-session.js Session/agent RPC handlers
79
- lib/ws-handlers-run.js Thread/run RPC handlers
80
- lib/ws-handlers-util.js Utility RPC handlers (speech, auth, git, tools, voice)
81
- lib/ws-handlers-oauth.js Gemini + Codex OAuth WS RPC handlers
82
- lib/ws-handlers-scripts.js npm script run/stop WS RPC handlers
83
- lib/plugins/ Server plugins (acp, agents, auth, database, files, git, speech, stream, tools, websocket, workflow)
84
-
85
- static/index.html Main HTML shell
86
- static/app.js UI IIFEs (sidebar search, error boundary, import, archived view, presets)
87
- static/js/app-shortcuts.js Keyboard shortcuts overlay
88
- static/theme.js Theme switching
89
- static/css/main.css All application styles (extracted from index.html)
90
- static/css/tools-popup.css Tool popup styles
91
- static/js/client.js AgentGUIClient class (constructor + _dbg + init); instantiation at bottom
92
- static/js/client-ws.js WebSocket listeners, _convIsStreaming, _setConvStreaming, setupRendererListeners, restoreStateFromUrl, isValidId (prototype extension)
93
- static/js/client-url.js URL/scroll helpers: updateUrlForConversation, saveScrollPosition, restoreScrollPosition, setupScrollTracking (prototype extension)
94
- static/js/client-ui.js setupUI (modified, calls _setupUIButtonEvents/_setupUIWindowEvents) + setupChatMicButton (prototype extension)
95
- static/js/client-ui-controls.js _setupUIButtonEvents + _setupUIWindowEvents extracted helpers (prototype extension)
96
- static/js/client-ws-msg.js connectWebSocket, handleWebSocketMessage, queueEvent (prototype extension)
97
- static/js/client-streaming.js handleStreamingStart (prototype extension)
98
- static/js/client-streaming2.js handleStreamingResumed, handleStreamingProgress, _handleStreamingProgressInner (prototype extension)
99
- static/js/client-streaming3.js renderBlockContent, scrollToBottom, _showNewContentPill, _removeNewContentPill, handleStreamingError (prototype extension)
100
- static/js/client-streaming4.js handleStreamingComplete, _promptPushIfWeOwnRemote, handleConversationCreated, handleMessageCreated, queue handlers (prototype extension)
101
- static/js/client-events.js fetchAndRenderQueue, handleRateLimitHit/Clear, handleAllConversationsDeleted, isHtmlContent, sanitizeHtml, parseMarkdownCodeBlocks (prototype extension)
102
- static/js/client-render.js renderCodeBlock, renderMessageContent (prototype extension)
103
- static/js/client-exec.js startExecution, optimistic message helpers, _subscribeToConversationUpdates, _flushBgCache (prototype extension)
104
- static/js/client-helpers.js _recoverMissedChunks, cache/placeholder/height/countdown/debug helpers, showLoadingSpinner/hideLoadingSpinner (prototype extension)
105
- static/js/client-ui2.js _showWelcomeScreen, _showSkeletonLoading, streamToConversation, _hydrateSessionBlocks (prototype extension)
106
- static/js/client-conv.js _getLazyObserver, _renderConversationContent, renderChunk, _renderChunkInner, loadAgents, loadSubAgentsForCli (prototype extension)
107
- static/js/client-agents.js checkSpeechStatus, loadModelsForAgent, _populateModelSelector, lock/unlockAgentAndModel, applyAgentAndModelSelection, loadConversations, updateConnectionStatus (prototype extension)
108
- static/js/client-status.js _updateConnectionIndicator, _handleModelDownloadProgress, _handleTTSSetupProgress, _toggleConnectionTooltip, updateMetrics, controls, toggleTheme, createNewConversation (prototype extension)
109
- static/js/client-cache.js cacheCurrentConversation, invalidateCache, loadConversationMessages (prototype extension)
110
- static/js/client-load.js _makeLoadRequest, _verifyRequestId, _completeLoadRequest, _loadConvRender (prototype extension)
111
- static/js/client-scroll.js syncPromptState, updateBusyPromptArea, removeScrollUpDetection, setupScrollUpDetection (prototype extension)
112
- static/js/client-utils.js renderMessagesFragment, renderMessages, escapeHtml, showError, on, emit, agent/model getters, draft/prompt helpers, destroy (prototype extension)
113
- static/js/conversations.js Conversation management (class definition)
114
- static/js/conv-list-renderer.js Conversation list render, CRUD, WS listener (prototype extension)
115
- static/js/conv-sidebar-actions.js Sidebar delegated listeners, folder browser (prototype extension)
116
- static/js/conv-sidebar-clone.js Delete-all, clone UI, DOM-ready bootstrap (prototype extension)
117
- static/js/streaming-renderer.js Renders agent streaming events as HTML
118
- static/js/event-processor.js Processes incoming events
119
- static/js/event-filter-config.js Filters events by type
120
- static/js/websocket-manager.js WebSocket send/subscribe/disconnect methods (prototype extension)
121
- static/js/ws-core.js WebSocketManager class + connect/reconnect/heartbeat core
122
- static/js/ws-latency.js WebSocket latency tracking, ping/pong, quality tiers (prototype extension)
123
- static/js/ws-client.js WsClient RPC wrapper over WebSocketManager
124
- static/js/ui-components.js UI component helpers (modal, tabs, alert, spinner, progress, collapsible)
125
- static/js/ui-components-rendering.js Input/select/button/badge factory helpers (static extension)
126
- static/js/syntax-highlighter.js Code syntax highlighting (class definition)
127
- static/js/syntax-highlighter-render.js Token-to-HTML render logic (prototype extension)
128
- static/js/voice.js Voice input/output
129
- static/js/stt-handler.js Speech-to-text recording and upload
130
- static/js/features.js View toggle, drag-drop upload, model progress indicator
131
- static/js/tools-manager.js Tool install/update UI orchestrator
132
- static/js/tools-manager-ui.js Tool card rendering + voice selector helpers
133
- static/js/agent-auth.js Agent authentication UI (dropdown, auth-status, provider keys)
134
- static/js/agent-auth-oauth.js OAuth modal functions (triggerAuth, onWsMessage, paste fallback)
135
- static/js/dialogs.js Modal dialog system (class definition)
136
- static/js/dialogs-types.js Dialog type-specific render helpers (prototype extension)
137
- static/js/image-loader.js Lazy image loading orchestration for agent file read events
138
- static/js/image-loader-element.js ImageLoader DOM element rendering (prototype extension)
139
- static/js/pm2-monitor.js PM2 process monitor UI
140
- static/js/script-runner.js npm script runner UI
141
- static/js/state-barrier.js Atomic state machine for conversation management
142
- static/js/terminal.js xterm.js terminal integration
143
- static/js/ws-machine.js XState v5 WS connection machine: disconnected/connecting/connected/reconnecting
144
- static/js/conv-machine.js XState v5 per-conversation UI machine: idle/streaming/queued
145
- static/js/tool-install-machine.js XState v5 per-tool UI install machine: idle/installing/installed/updating/needs_update/failed
146
- static/js/voice-machine.js XState v5 voice/TTS machine: idle/queued/speaking/disabled (circuit-breaker)
147
- static/js/conv-list-machine.js XState v5 conversation list machine: unloaded/loading/loaded/error
148
- static/js/prompt-machine.js XState v5 prompt area machine: ready/loading/streaming/queued/disabled
149
- static/lib/xstate.umd.min.js XState v5 browser bundle (UMD, served locally from node_modules)
150
- static/lib/msgpackr.min.js msgpack browser bundle
151
- static/lib/webjsx.js WebJSX library
152
- static/vendor/ Third-party assets (highlight.js, Prism, RippleUI, xterm.js)
153
- ```
154
-
155
- ## XState State Machines
156
-
157
- XState v5 machines own their domains exclusively. No ad-hoc Maps/Sets parallel to machines.
158
-
159
- **Server** (lib/): `execution-machine` (per conversation: idle/streaming/draining/rate_limited), `acp-server-machine` (per tool: stopped/starting/running/crashed/restarting), `tool-install-machine` (per tool: unchecked→checking→idle/installed/needs_update/installing/updating/failed). API: `send(id, event)`, `isLocked()`, snapshots at `GET /api/debug/machines` when DEBUG=1.
160
-
161
- **Client** (static/js/, UMD): `ws-machine` (disconnected/connecting/connected/reconnecting), `conv-machine` (per conv: idle/streaming/queued), `tool-install-machine` (per tool), `voice-machine` (single: idle/queued/speaking/disabled circuit-breaker), `conv-list-machine` (single: unloaded/loading/loaded/error), `prompt-machine` (single: ready/loading/streaming/queued/disabled). Load order: xstate.umd.min.js → ws-machine → conv-machine → tool-install-machine → voice-machine → conv-list-machine → prompt-machine. Exposed at `window.__*` globals for debug.
162
-
163
- ## Key Details
164
-
165
- - Express is used only for file upload (`/api/upload/:conversationId`) and fsbrowse file browser (`/files/:conversationId`). All other routes use raw `http.createServer` with manual routing.
166
- - Agent discovery scans PATH for known CLI binaries (claude, opencode, gemini, goose, etc.) at startup.
167
- - Database lives at `~/.gmgui/data.db`. Tables: conversations, messages, events, sessions, stream chunks.
168
- - WebSocket endpoint is at `BASE_URL + /sync`. Supports subscribe/unsubscribe by sessionId or conversationId, and ping.
169
- - All WS RPC uses msgpack binary encoding (lib/codec.js). Wire format: `{ r, m, p }` request, `{ r, d }` reply, `{ type, seq }` broadcast push.
170
- - `perMessageDeflate` is disabled on the WS server — msgpack binary doesn't compress well and brotli/gzip was blocking the event loop. HTTP-layer gzip handles static assets.
171
- - Static assets use `Cache-Control: public, no-cache` + ETag. Browser always revalidates (sends If-None-Match), server returns 304 if unchanged. Compressed once on first request, served from RAM (`_assetCache` Map keyed by etag).
172
- - Deployment: runs behind Traefik/Caddy which handles TLS and can support WebTransport/QUIC.
173
-
174
- ## Environment Variables
175
-
176
- - `PORT` - Server port (default: 3000)
177
- - `BASE_URL` - URL prefix (default: /gm)
178
- - `STARTUP_CWD` - Working directory passed to agents
179
- - `HOT_RELOAD` - Set to "false" to disable watch mode
180
- - `CODEX_HOME` - Override Codex CLI home directory (default: `~/.codex`)
181
- - `RATE_LIMIT_MAX` - Max HTTP requests per IP per minute (default: 300)
182
- - `PASSWORD` - Basic auth password for all HTTP routes (optional)
183
- - `AGENTGUI_BASE_URL` - Override base URL for OAuth callbacks (e.g., `https://myserver.com`)
184
-
185
- ## ACP Tool Lifecycle
186
-
187
- On startup, agentgui auto-launches bundled ACP tools (opencode, kilo) as HTTP servers:
188
- - OpenCode: port 18100 (`opencode acp --port 18100`)
189
- - Kilo: port 18101 (`kilo acp --port 18101`)
190
-
191
- Managed by `lib/acp-sdk-manager.js`. Features: crash restart with exponential backoff (max 10 in 5min), health checks every 30s via `GET /provider`, clean shutdown on SIGTERM. The `acpPort` field on discovered agents is set automatically once healthy. Models are queried from the running ACP HTTP servers via their `/provider` endpoint.
192
-
193
- ## REST API
194
-
195
- All routes prefixed with `BASE_URL` (default `/gm`). Key endpoints:
196
-
197
- **Conversations**: `GET /api/conversations`, `POST /api/conversations`, `GET/POST/DELETE /api/conversations/:id`, `POST /api/conversations/:id/archive`, `POST /api/conversations/:id/restore`, `GET /api/conversations/:id/messages`, `POST /api/conversations/:id/messages`, `POST /api/conversations/:id/stream`, `GET /api/conversations/:id/full`, `GET /api/conversations/:id/chunks`, `GET /api/conversations/:id/sessions/latest`
198
-
199
- **Sessions**: `GET /api/sessions/:id`, `GET /api/sessions/:id/chunks`, `GET /api/sessions/:id/execution`
200
-
201
- **Agents & ACP**: `GET /api/agents`, `GET /api/acp/status`, `GET /api/health`
202
-
203
- **Speech**: `POST /api/stt`, `POST /api/tts`, `GET /api/speech-status`
204
-
205
- **Tools**: `GET /api/tools`, `GET/POST /api/tools/:id/install`, `POST /api/tools/:id/update`, `GET /api/tools/:id/history`, `POST /api/tools/update`, `POST /api/tools/refresh-all`
206
-
207
- **OAuth**: `POST /api/codex-oauth/start`, `GET /api/codex-oauth/status`, `POST /api/codex-oauth/relay`, `POST /api/codex-oauth/complete`, `GET /codex-oauth2callback`
208
-
209
- **Utility**: `POST /api/folders`, `GET /api/home`
210
-
211
- ## Tool Update System
212
-
213
- Tool updates are managed through a complete pipeline:
214
-
215
- **Update Flow:**
216
- 1. Frontend (`static/js/tools-manager.js`) initiates POST to `/api/tools/{id}/update`
217
- 2. Server (`server.js` lines 1904-1961 for individual, 1973-2003 for batch) spawns bun x process
218
- 3. Tool manager (`lib/tool-manager.js` lines 400-432) executes `bun x <package>` and detects new version
219
- 4. Version is saved to database: `queries.updateToolStatus(toolId, { version, status: 'installed' })`
220
- 5. WebSocket broadcasts `tool_update_complete` with version and status data
221
- 6. Frontend machine transitions to installed/failed via WS event, UI re-renders from machine state
222
-
223
- **Critical Detail:** When updating tools in batch (`/api/tools/update`), the version parameter MUST be included in the database update call. This ensures database persistence across page reloads.
224
-
225
- **Version Detection Sources** (`lib/tool-manager.js`):
226
- - Claude Code: `~/.claude/plugins/{pluginId}/plugin.json`
227
- - OpenCode: `~/.config/opencode/agents/{pluginId}/plugin.json`
228
- - Gemini CLI: `~/.gemini/extensions/{pluginId}/plugin.json`
229
- - Kilo: `~/.config/kilo/agents/{pluginId}/plugin.json`
230
-
231
- **Database Schema** (`database.js`):
232
- - Table: `tool_installations` (toolId, version, status, installed_at, error_message)
233
- - Table: `tool_install_history` (action, status, error_message for audit trail)
234
-
235
- ## Tool Detection System
236
-
237
- **TOOLS** array in `lib/tool-manager.js`: cli (via which + --version) or plugin (via plugin.json). Current: claude, opencode, gemini, kilo, codex, agent-browser (uses `-V`, not `--version`), + plugin tools (gm-cc, gm-oc, gm-gc, gm-kilo, gm-codex).
238
-
239
- **BIN_MAP**: Single constant in `lib/tool-version-check.js` shared by detect + version functions; new CLI tools must be added.
240
-
241
- **FRAMEWORK_PATHS**: Data table (pluginDir/versionFile/parseVersion/optional markerFile). New framework = one table entry.
242
-
243
- **Provisioning**: `autoProvision()` at startup (~10s), `startPeriodicUpdateCheck()` every 6h. Both broadcast tool status via WS.
244
-
245
- ### Tool Installation and Update UI Flow
246
-
247
- When user clicks Install/Update button on a tool:
248
-
249
- 1. **Frontend** (`static/js/tools-manager.js`): Sends INSTALL/UPDATE event to `toolInstallMachineAPI`, sends POST. Machine guards duplicate requests via `isLocked()`.
250
- 2. **Backend** (`server.js`): `tool-install-machine.js` sends INSTALL_START/UPDATE_START, runs async, sends INSTALL_COMPLETE/UPDATE_COMPLETE/FAILED. Broadcasts WS events.
251
- 3. **Frontend WebSocket Handler**: Sends COMPLETE/FAILED/PROGRESS to machine. UI renders from machine state only.
252
-
253
- ## WebSocket Protocol
254
-
255
- Endpoint: `BASE_URL + /sync`. Msgpack binary. Wire: RPC request `{r, m, p}`, reply `{r, d}` or `{r, e}`, broadcast `{type, seq, ...}` batched by `WSOptimizer`. Per-client priority queue: high-priority (streaming_start, message_created, streaming_complete) flush immediately; normal/low batch by latency tier. Rate limit: 100 msg/sec (re-queued if overflow).
256
-
257
- **Legacy messages** (onLegacy): subscribe/unsubscribe/ping/latency_report/terminal_*/pm2_*/set_voice/get_subscriptions
258
-
259
- **RPC methods** (86 total by category): agent (auth/authstat/desc/get/ls/models/search/subagents/update), auth (configs/save), codex (start/status/relay/complete), conv (ls/new/get/upd/del/cancel/chunks/full/steer/inject/search/prune/scripts/run-script), gemini (start/status/relay/complete), git (check/push), msg (send/stream/get/ls), q (ls/upd/del), run (new/stream/get/wait/cancel/search/resume), sess (get/latest/chunks/exec), speech (download/status), thread (new/get/upd/del/search/copy/history/run.stream/run.cancel/run.steer), tools (list), util (home/folders/clone/voices/voice.cache/voice.generate/ws.stats/discover.claude/import.claude)
260
-
261
- ## Steering
262
-
263
- Steering stops the running agent (SIGKILL) and immediately resumes with the new message:
264
-
265
- 1. `conv.steer` RPC (`ws-handlers-conv.js`) — kills active process, marks session interrupted, creates new user message, calls `startExecution()` to resume
266
- 2. Frontend inject button (`#injectBtn`) — when streaming: reads message input, fires `conv.steer`, clears input
267
- 3. `conv.claudeSessionId` on the conversation row ensures the resumed execution picks up `--resume <sessionId>` automatically
268
-
269
- ## Execution State Management
270
-
271
- Three parallel state stores (must stay in sync):
272
- 1. **In-memory maps:** `activeExecutions`, `messageQueues`
273
- 2. **Database:** `conversations.isStreaming`, `sessions.status`
274
- 3. **WebSocket clients:** `streamingConversations` Set on each client
275
-
276
- **`cleanupExecution(conversationId)`** — atomic cleanup function in server.js. Always use this, never inline-delete from maps. Clears `activeExecutions`, sets DB isStreaming=0.
277
-
278
- **Queue drain:** If `processMessageWithStreaming` throws, catch block calls `cleanupExecution` and retries drain after 100ms. Queue never deadlocks.
279
-
280
- ## Message Flow
281
-
282
- User send → check if streaming → (streaming: queue server-side, skip optimistic; else: show optimistic message) → RPC msg.stream → backend checks activeExecutions.has(convId) → (yes: queue, broadcast queue_status; no: execute, return session) → broadcast message_created (non-queued only). Queue renders as yellow blocks. On complete, remove .event-streaming-* DOM blocks.
283
-
284
- ## Conversations Sidebar
285
-
286
- `ConversationManager` in `static/js/conversations.js`:
287
- - Polls `/api/conversations` every 30s
288
- - On poll: if result is non-empty but smaller than cached list, **merges** (keeps cached items not in poll) rather than replacing — prevents transient server responses from dropping conversations
289
- - On empty result with existing cache: keeps existing (server error assumption)
290
- - `render()` uses DOM reconciliation by `data-conv-id` — reuses existing nodes, removes orphans
291
- - `showEmpty()` and `showLoading()` both clear `listEl.innerHTML` — only called when appropriate
292
- - `conversation_deleted` WS event handled in `setupWebSocketListener` — `deleteConversation()` filters array
293
- - `confirmDelete()` calls `deleteConversation()` directly AND server broadcasts `conversation_deleted` — double-call is safe (filter is idempotent)
294
-
295
- ## Base64 Image Rendering in File Read Events
296
-
297
- When an agent reads an image file, the event type may not be `'file_read'`. Three content structures exist:
298
-
299
- **Structure A** (nested): `event.content.source.type === 'base64'`, data at `event.content.source.data`
300
- **Structure B** (flat): `event.content.type === 'base64'`, data at `event.content.data`
301
- **Structure C** (raw string): `event.content` is a base64 string detected by magic-byte prefix
302
-
303
- `renderGeneric` checks for A and B first; if found with `event.path` present, delegates to `renderFileRead`. Without this fallback, non-`file_read` typed image events display as raw text.
304
-
305
- MIME type priority: `event.media_type` → magic-byte detection (PNG/JPEG/WebP/GIF) → `application/octet-stream`.
306
-
307
- ## Voice Model Download
308
-
309
- Models (~470MB: Whisper Base ~280MB + TTS ~190MB) downloaded at startup from GitHub LFS or HuggingFace (fallback). UI: voice tab hidden until ready; progress indicator in header; `model_download_progress` WS broadcast. Cache: `~/.gmgui/models/`.
310
-
311
- ## Performance & Observability
312
-
313
- **Asset serving**: gzip only (no brotli), pre-compressed once, cached in `_assetCache` (etag-keyed). HTML cached, invalidated on hot-reload. **/api/conversations**: single `DISTINCT` query (not N+1). **Chunks**: `getConversationChunksSince()` pushes filter to DB. **Client init**: loadAgents/loadConversations/checkSpeechStatus parallel. **WS**: perMessageDeflate: false (msgpack + zlib blocked event loop).
314
-
315
- **Debug API** (`DEBUG=1`): `/api/debug/machines` snapshots, `/api/debug/state` inspection, `/api/debug/ws-stats` latency. Browser: `window.__debug.getSyncState()` exposes all XState machines.
316
-
317
- PKCE S256 flow vs auth.openai.com. `POST /api/codex-oauth/start` → authUrl. User authenticates → redirect to `/codex-oauth2callback` (local: intercepts localhost:1455/auth/callback; remote: relay page POSTs to `/api/codex-oauth/relay`). Tokens saved to `$CODEX_HOME/auth.json`. WS handlers: codex.start/status/relay/complete.
318
-
319
- ## ACP SDK Integration
320
-
321
- - **@agentclientprotocol/sdk** (`^0.4.1`) added to dependencies
322
- - Full integration (replacing custom WS protocol) is optional/incremental — current WS already gives logical multiplexing via concurrent async handlers
323
-
324
- ## Theme-Aware Rendering
325
-
326
- CSS custom properties for code/thinking blocks live in `static/css/main.css`:
327
- - `--color-bg-code`, `--color-code-text`, `--color-code-border` — light values in `:root`, dark overrides in `html.dark`
328
- - `--color-thinking-bg` — light value in `:root` (`#f5f3ff`), dark override in `html.dark` (`.block-thinking`) set to `#1e1a2e`
329
-
330
- `static/js/streaming-renderer.js` uses `var(--color-bg-code)` etc. in inline styles — no hardcoded `#1e293b`/`#e2e8f0`/`#d1d5db` hex values. Remaining hardcoded hex in the renderer are **intentional semantic colors** (blue links, amber warnings, red errors, purple thinking accents) and must not be replaced with CSS vars.
331
-
332
- `parseAndRenderMarkdown()` in `streaming-renderer.js` handles: `##`/`###` headers, `-`/`*` ul lists, `1.` ol lists, `>` blockquotes, `---` hr, inline bold/italic/code/links via `_mdInline()`. Thinking block content is rendered through this function.
333
-
334
- ## README.md Documentation
335
-
336
- **GitHub Badges and Metrics:**
337
-
338
- The README.md uses shields.io badges with a consistent pattern:
339
- - **Header badges** (lines 7-9): Star count, last commit, latest release — each links to corresponding GitHub page
340
- - **GitHub Stats table** (lines 54-62): Detailed metrics (stars, forks, watchers, issues, activity) — each badge links to its resource page
341
- - **All badges use:** `style=flat-square`, `color=blue`, dynamic data (no hardcoded values)
342
-
343
- **Debug API section** (lines 174-192):
344
- - Documents `DEBUG=1` environment variable for state inspection
345
- - Lists `/api/debug/*` endpoints: machines, state, ws-stats
346
- - Lists browser console `window.__debug` properties with purpose
347
- - Links to CLAUDE.md for complete architecture documentation
348
-
349
- **Approach validated:** Header badges are compact (visual prominence); stats table is detailed (discoverability). Non-redundant, no duplicate metrics, complementary visibility.
350
-
351
- **For future observability improvements:** Use shields.io with the established pattern (flat-square, color=blue, dynamic endpoints). Link badges to corresponding GitHub resource pages. Document in README alongside the badge.
352
-
353
- ## Known Gotchas
354
-
355
- - **`agent-browser --version`** prints help, not version. Use `-V` flag.
356
- - **`all_conversations_deleted`** must be in `BROADCAST_TYPES` set in server.js or it won't fan-out to all clients.
357
- - **`streaming_start` and `message_created`** are high-priority in WSOptimizer — they flush immediately, not batched.
358
- - **Sidebar animation:** `transition: none !important` in index.html CSS — sidebar snaps instantly on toggle by design.
359
- - **Claude Code runs with plugins enabled** — `--dangerously-skip-permissions` was removed to allow gm plugin enforcement.
360
- - **Tool status race on startup:** `autoProvision()` broadcasts `tool_status_update` for already-installed tools so the UI shows correct state before the first manual fetch.
361
- - **Thinking blocks** are transient (not in DB), rendered only via `handleStreamingProgress()` in client.js. The `renderEvent` switch case for `thinking_block` is disabled to prevent double-render.
362
- - **Terminal output** is base64-encoded (`encoding: 'base64'` field on message). Client decodes with `decodeURIComponent(escape(atob(data)))` pattern for multibyte safety.
363
- - **HTML cache** (`_htmlCache`) is only populated when client accepts gzip. In watch mode it's never cached (always fresh).
364
- - **`app.js` and `app-shortcuts.js` script loading:** Both are `<script defer>` tags loaded AFTER `agent-auth.js` in index.html. They depend on `window.wsClient`, `window.conversationManager`, and `window._escHtml` being initialized first. Defer order is guaranteed by source order — adding new defer scripts that depend on these modules requires careful ordering.
365
- - **`window.__debug` registry:** Structured sub-keys via live getters — `machines` (conv/toolInstall/voice/convList/prompt/recording/terminal/ws), `ws` (state/latency/url), `auth`, `perf`, `config`, `renderer`, `conv`. Legacy methods preserved: `getState()`, `getSyncState()`, `getMessageState()`. Uninitialized machines return `'uninitialized'` rather than crashing. All XState v5 machines have no parallel ad-hoc state.
366
- - **`isJsonlBacked` flag:** Only `claude-code` (protocol: `direct`) writes JSONL files. All other agents use `stream-event-handler.js` for broadcasting. `isJsonlBacked = resolvedAgentId === 'claude-code'` — guards in `stream-event-handler.js` prevent double-broadcast for claude-code, and gates ACP streaming for non-JSONL agents.
367
- - **`toolIds` in `server-startup.js` must match `TOOLS` in `tool-manager.js`:** `initializeToolInstallations` runs for each toolId, creating the `tool_installations` row. `tool_install_history` has a FK to `tool_installations(tool_id)`. Any tool omitted from toolIds will cause a FOREIGN KEY constraint failure when the periodic update checker writes history for it.
368
- - **`JsonlWatcher._read(fp)` override:** Captures `this._currentFp` before calling `super._read(fp)`, making the file path available to `_line()` callbacks for project-directory decoding in `_conv()`. JSONL project dirs are encoded (e.g., `-config-workspace-agentgui`) — decoded via `'/' + dirName.slice(1).replace(/-/g, '/')`.
369
- - **`createHttpHandler` uses `getWss: () => wss` (lazy getter):** Passing `wss` directly would crash with TDZ since `wss` is declared after `createHttpHandler` is called. The function form defers access until request time when `wss` is initialized.
370
- - **`_promptPushIfWeOwnRemote` fires after every `streaming_complete`:** `client-streaming4.js` calls `git.check` on the server after each agent turn. If `ownsRemote && (hasChanges || hasUnpushed)`, it auto-sends "Push the changes to the remote repository." to the current conversation. `ownsRemote` is true for non-github remotes, and for github.com remotes only when `GITHUB_USER` env var is set and appears in the URL. Without `GITHUB_USER`, github.com remotes return `ownsRemote=false` (safe default).
371
-
372
- ## Critical Knowledge for Future Sessions
373
-
374
- **Codebase Insight Stale:** `.codeinsight` snapshot is outdated (v1.0.811 claimed server.js=3407L, db-queries.js=1412L, but actual as of 2026-04-17: server.js=201L, db-queries.js=94L). Heavy refactoring already done. Before acting on insight "issues" (SQL injection claims, hardcoded secrets, large files), always verify with grep/read against current state. Most reported issues are false positives or stale.
375
-
376
- **Test Harness Pattern:** test.js prefers `bun:sqlite`, falls back to `better-sqlite3` via createRequire (so it runs under both `bun test.js` and `node test.js` provided `bun install` / `npm install` ran). Call `initSchema()` → `migrateConversationColumns()` → `migrateACPSchema()` in order (conversations table needs agentType column from second migration). `createQueries` signature: `(db, prep, generateId)` where `prep=(sql)=>db.prepare(sql)`. Silence console during schema init to keep test output clean. CI runs `bun test.js` via `.github/workflows/test.yml` on every push/PR to main.
377
-
378
- **CI Auto-Rewrites History:** Every push to main triggers Auto-Declaudeify workflow that filters Claude coauthor commits and force-pushes filtered history. After a push, `git fetch origin` is needed — local SHA drifts from origin SHA.
379
-
380
- **Debug Endpoints Scattered:** Routes at `/api/debug`, `/api/debug/machines`, `/api/debug/state`, `/api/ws-stats`, `/api/debug/ws-stats` (alias). `routes-debug.js` wires all five + backup/restore. DEBUG API in browser: `window.__debug.getSyncState()`.
381
-
382
- **Plugin Files NOT Orphans:** lib/plugins/* are dynamically loaded via `lib/plugin-loader.js` (import with file:// URL + cache-busting `?v=` timestamp). Only truly dead plugin was `lib/plugins/git-plugin.js`. Static scan showing orphans is misleading.
1
+ @AGENTS.md
package/README.md CHANGED
@@ -10,6 +10,23 @@
10
10
 
11
11
  Multi-agent GUI client for AI coding agents with real-time streaming, WebSocket sync, and SQLite persistence.
12
12
 
13
+ ## Live client (new)
14
+
15
+ AgentGUI now ships a static GH Pages client at **`/app/`** that talks to any [`acptoapi`](https://github.com/AnEntrypoint/acptoapi) backend over plain HTTP — no install, no bundler, no DB. Open `https://anentrypoint.github.io/agentgui/app/?backend=http://your-acptoapi-host:4800` and chat with any provider acptoapi proxies (Claude / Gemini / OpenAI-compat brands / kilo / opencode), plus browse local Claude Code JSONL history right in the page.
16
+
17
+ - UI: [anentrypoint-design](https://www.npmjs.com/package/anentrypoint-design) (CDN, single-file ESM)
18
+ - Backend: [acptoapi](https://www.npmjs.com/package/acptoapi) — `npx acptoapi` on the host with Claude Code / API keys; exposes `/v1/chat/completions`, `/v1/messages`, `/v1/history/*`
19
+ - Source: `site/app/` (this repo)
20
+
21
+ History endpoints in `acptoapi` (formerly `ccsniff`'s job):
22
+
23
+ - `GET /v1/history/sessions` — list Claude Code sessions on the host
24
+ - `GET /v1/history/sessions/:sid/events` — flattened events for one session
25
+ - `GET /v1/history/search?q=…` — BM25-ranked search across all events
26
+ - `GET /v1/history/stream` — Server-Sent Events for live tailing
27
+
28
+ The legacy Node server in this repo (`server.js`, `lib/`, `static/`) still ships in the npm `agentgui` package and is the install-friendly path. It is being phased out as the static client + acptoapi pair reach feature parity.
29
+
13
30
  ### Supported Agents
14
31
 
15
32
  | Agent | Protocol | Auto-installable |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.915",
3
+ "version": "1.0.917",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "electron/main.js",
@@ -0,0 +1,56 @@
1
+ <!doctype html>
2
+ <html lang="en" class="ds-247420" data-theme="dark">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>agentgui — live client</title>
7
+ <meta name="description" content="agentgui live client — talks to any acptoapi backend, anywhere.">
8
+ <link rel="stylesheet" href="https://unpkg.com/anentrypoint-design@latest/dist/247420.css">
9
+ <script type="importmap">
10
+ { "imports": {
11
+ "anentrypoint-design": "https://unpkg.com/anentrypoint-design@latest/dist/247420.js"
12
+ } }
13
+ </script>
14
+ <style>
15
+ html,body { margin:0; height:100%; }
16
+ body { background: var(--app-bg, #0b0b0b); color: var(--text, #eee); font-family: var(--ff-body, system-ui); }
17
+ #app { height: 100vh; display: grid; grid-template-rows: auto 1fr; }
18
+ .topbar { display:flex; align-items:center; justify-content:space-between; padding:10px 16px; border-bottom:1px solid rgba(255,255,255,.08); }
19
+ .topbar .brand { font-weight:600; letter-spacing:.04em; }
20
+ .topbar .right { display:flex; gap:10px; align-items:center; }
21
+ .topbar input { width: 320px; padding:6px 10px; border-radius:6px; border:1px solid rgba(255,255,255,.15); background:rgba(255,255,255,.04); color:inherit; font:inherit; }
22
+ .tabs { display:flex; gap:4px; }
23
+ .tabs button { padding:6px 12px; border-radius:6px; border:1px solid transparent; background:transparent; color:inherit; cursor:pointer; font:inherit; }
24
+ .tabs button.active { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.12); }
25
+ .body { display:grid; grid-template-columns: 320px 1fr; min-height:0; }
26
+ .side { border-right:1px solid rgba(255,255,255,.08); overflow:auto; padding:8px; }
27
+ .main { overflow:auto; padding:16px; min-width:0; }
28
+ .empty { opacity:.6; padding:24px; text-align:center; }
29
+ .pill { display:inline-block; padding:1px 7px; border-radius:999px; background: rgba(255,255,255,.1); font-size:11px; margin-left:6px; }
30
+ .pill.ok { background: rgba(80,200,120,.18); color:#7fd; }
31
+ .pill.bad { background: rgba(255,80,80,.18); color:#f88; }
32
+ .row { display:block; padding:8px 10px; border-radius:6px; cursor:pointer; }
33
+ .row:hover { background: rgba(255,255,255,.04); }
34
+ .row.active { background: rgba(255,255,255,.08); }
35
+ .row .t { font-size:13px; }
36
+ .row .s { font-size:11px; opacity:.6; margin-top:2px; font-family: var(--ff-mono, ui-monospace, monospace); }
37
+ .ev { padding:6px 0; border-bottom: 1px dashed rgba(255,255,255,.06); font-family: var(--ff-mono, ui-monospace, monospace); font-size:12px; }
38
+ .ev .h { opacity:.55; margin-bottom:2px; }
39
+ .ev pre { white-space: pre-wrap; margin:0; }
40
+ .chat-host { height:100%; display:flex; flex-direction:column; }
41
+ .chat-msgs { flex:1; overflow:auto; padding:10px 4px; }
42
+ .msg { padding:8px 10px; border-radius:8px; margin:6px 0; max-width:80ch; }
43
+ .msg.user { background: rgba(120,180,255,.08); }
44
+ .msg.assistant { background: rgba(255,255,255,.04); }
45
+ .msg .role { font-size:11px; opacity:.6; margin-bottom:4px; text-transform:uppercase; letter-spacing:.08em; }
46
+ .composer { display:flex; gap:8px; padding:8px; border-top:1px solid rgba(255,255,255,.08); }
47
+ .composer textarea { flex:1; min-height:48px; max-height:200px; resize:vertical; padding:8px 10px; border-radius:6px; border:1px solid rgba(255,255,255,.12); background:rgba(255,255,255,.04); color:inherit; font:inherit; }
48
+ .composer button { padding:8px 16px; border-radius:6px; border:1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.06); color:inherit; cursor:pointer; }
49
+ .composer select { padding:6px 8px; border-radius:6px; border:1px solid rgba(255,255,255,.12); background:rgba(255,255,255,.04); color:inherit; font:inherit; }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div id="app"></div>
54
+ <script type="module" src="./js/app.js"></script>
55
+ </body>
56
+ </html>
@@ -0,0 +1,181 @@
1
+ import { h, applyDiff, installStyles } from 'anentrypoint-design';
2
+ import * as B from './backend.js';
3
+ installStyles().catch(() => {});
4
+
5
+ const state = {
6
+ backend: B.getBackend(),
7
+ health: { status: 'unknown' },
8
+ tab: 'chat',
9
+ models: [],
10
+ selectedModel: '',
11
+ // chat
12
+ chat: { messages: [], busy: false, abort: null, draft: '' },
13
+ // history
14
+ sessions: [],
15
+ selectedSid: null,
16
+ events: [],
17
+ searchQ: '',
18
+ searchHits: null,
19
+ liveTail: [],
20
+ };
21
+
22
+ const root = document.getElementById('app');
23
+
24
+ function render() { applyDiff(root, view()); }
25
+
26
+ function view() {
27
+ return h('div', { class: 'app-root', style: 'display:grid;grid-template-rows:auto 1fr;height:100%' }, topbar(), bodyView());
28
+ }
29
+
30
+ function topbar() {
31
+ const ok = state.health.status === 'ok';
32
+ return h('div', { class: 'topbar' },
33
+ h('div', { class: 'brand' }, 'agentgui ', h('span', { class: 'pill ' + (ok ? 'ok' : 'bad') }, ok ? 'connected' : 'offline')),
34
+ h('div', { class: 'tabs' },
35
+ tabBtn('chat', 'chat'),
36
+ tabBtn('history', 'history'),
37
+ tabBtn('settings', 'settings'),
38
+ ),
39
+ h('div', { class: 'right' },
40
+ h('input', { value: state.backend, placeholder: 'backend url', onchange: e => { state.backend = e.target.value; B.setBackend(state.backend); init(); } }),
41
+ ),
42
+ );
43
+ }
44
+
45
+ function tabBtn(id, label) {
46
+ return h('button', { class: state.tab === id ? 'active' : '', onclick: () => { state.tab = id; render(); if (id === 'history') refreshHistory(); } }, label);
47
+ }
48
+
49
+ function bodyView() {
50
+ if (state.tab === 'chat') return chatView();
51
+ if (state.tab === 'history') return historyView();
52
+ return settingsView();
53
+ }
54
+
55
+ function settingsView() {
56
+ return h('div', { class: 'main' },
57
+ h('h2', {}, 'settings'),
58
+ h('p', {}, 'backend: ', h('code', {}, state.backend)),
59
+ h('p', {}, 'health: ', JSON.stringify(state.health)),
60
+ h('p', {}, 'tip: pass ', h('code', {}, '?backend=https://your-acptoapi-host'), ' to override'),
61
+ );
62
+ }
63
+
64
+ function chatView() {
65
+ return h('div', { class: 'body', style: 'grid-template-columns: 1fr' },
66
+ h('div', { class: 'main chat-host' },
67
+ h('div', { class: 'chat-msgs' },
68
+ ...state.chat.messages.map((m, i) => h('div', { class: 'msg ' + m.role },
69
+ h('div', { class: 'role' }, m.role),
70
+ h('div', { class: 'content' }, m.content || ''),
71
+ )),
72
+ state.chat.messages.length === 0 ? h('div', { class: 'empty' }, 'pick a model and start chatting') : null,
73
+ ),
74
+ h('div', { class: 'composer' },
75
+ h('select', { onchange: e => { state.selectedModel = e.target.value; render(); } },
76
+ h('option', { value: '' }, '— choose model —'),
77
+ ...state.models.map(m => h('option', { value: m.id, selected: m.id === state.selectedModel }, m.id)),
78
+ ),
79
+ h('textarea', {
80
+ placeholder: 'message…',
81
+ value: state.chat.draft,
82
+ oninput: e => { state.chat.draft = e.target.value; },
83
+ onkeydown: e => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendChat(); } },
84
+ }),
85
+ h('button', { onclick: () => state.chat.busy ? cancelChat() : sendChat() }, state.chat.busy ? 'stop' : 'send'),
86
+ ),
87
+ ),
88
+ );
89
+ }
90
+
91
+ async function sendChat() {
92
+ const text = (state.chat.draft || '').trim();
93
+ if (!text || !state.selectedModel || state.chat.busy) return;
94
+ state.chat.messages.push({ role: 'user', content: text });
95
+ state.chat.messages.push({ role: 'assistant', content: '' });
96
+ state.chat.draft = '';
97
+ state.chat.busy = true;
98
+ const ctrl = new AbortController();
99
+ state.chat.abort = ctrl;
100
+ render();
101
+ const cur = state.chat.messages[state.chat.messages.length - 1];
102
+ try {
103
+ for await (const ev of B.streamChat(state.backend, {
104
+ model: state.selectedModel,
105
+ messages: state.chat.messages.slice(0, -1).map(m => ({ role: m.role, content: m.content })),
106
+ signal: ctrl.signal,
107
+ })) {
108
+ if (ev.type === 'text') { cur.content += ev.text; render(); }
109
+ if (ev.type === 'error') { cur.content += '\n[error] ' + JSON.stringify(ev.error); render(); }
110
+ }
111
+ } catch (e) {
112
+ cur.content += '\n[error] ' + e.message;
113
+ } finally {
114
+ state.chat.busy = false;
115
+ state.chat.abort = null;
116
+ render();
117
+ }
118
+ }
119
+
120
+ function cancelChat() { state.chat.abort?.abort(); }
121
+
122
+ function historyView() {
123
+ return h('div', { class: 'body' },
124
+ h('div', { class: 'side' },
125
+ h('input', { class: 'search', placeholder: 'search…', value: state.searchQ, onchange: e => { state.searchQ = e.target.value; runSearch(); } }),
126
+ state.searchHits ? h('div', {},
127
+ h('div', { style: 'font-size:11px;opacity:.6;padding:6px 10px' }, state.searchHits.results.length + ' hits for "' + state.searchHits.query + '"'),
128
+ ...state.searchHits.results.slice(0, 30).map(r => h('div', { class: 'row', onclick: () => loadSession(r.sid) },
129
+ h('div', { class: 't' }, r.snippet || '(no snippet)'),
130
+ h('div', { class: 's' }, r.project + ' · ' + r.role + (r.tool ? ' · ' + r.tool : '')),
131
+ )),
132
+ ) : h('div', {},
133
+ ...state.sessions.slice(0, 80).map(s => h('div', { class: 'row' + (s.sid === state.selectedSid ? ' active' : ''), onclick: () => loadSession(s.sid) },
134
+ h('div', { class: 't' }, s.title || s.project || s.sid),
135
+ h('div', { class: 's' }, s.events + ' ev · ' + s.tools + ' tools · ' + (s.errors ? s.errors + ' err' : 'ok')),
136
+ )),
137
+ state.sessions.length === 0 ? h('div', { class: 'empty' }, 'no sessions yet') : null,
138
+ ),
139
+ ),
140
+ h('div', { class: 'main' },
141
+ state.events.length === 0
142
+ ? h('div', { class: 'empty' }, state.selectedSid ? 'loading…' : 'pick a session')
143
+ : h('div', {},
144
+ ...state.events.map(e => h('div', { class: 'ev' },
145
+ h('div', { class: 'h' }, new Date(e.ts).toLocaleString() + ' · ' + (e.role || '?') + ' · ' + (e.type || '?') + (e.tool ? ' · ' + e.tool : '')),
146
+ h('pre', {}, (e.text || '').slice(0, 4000)),
147
+ )),
148
+ ),
149
+ ),
150
+ );
151
+ }
152
+
153
+ async function refreshHistory() {
154
+ try {
155
+ state.sessions = await B.listSessions(state.backend);
156
+ render();
157
+ } catch (e) { console.warn('history fetch failed:', e.message); }
158
+ }
159
+
160
+ async function runSearch() {
161
+ if (!state.searchQ.trim()) { state.searchHits = null; render(); return; }
162
+ try { state.searchHits = await B.searchHistory(state.backend, state.searchQ, 50); render(); }
163
+ catch (e) { state.searchHits = { query: state.searchQ, results: [], error: e.message }; render(); }
164
+ }
165
+
166
+ async function loadSession(sid) {
167
+ state.selectedSid = sid; state.events = []; render();
168
+ try { state.events = await B.getSessionEvents(state.backend, sid); render(); }
169
+ catch (e) { state.events = [{ ts: Date.now(), role: 'error', type: 'fetch', text: e.message }]; render(); }
170
+ }
171
+
172
+ async function init() {
173
+ state.health = await B.probeBackend(state.backend).then(r => r.ok ? { status: 'ok', ...r.info } : { status: 'down', ...r });
174
+ render();
175
+ try { state.models = await B.listModels(state.backend); if (!state.selectedModel && state.models[0]) state.selectedModel = state.models[0].id; render(); }
176
+ catch (e) { console.warn('models fetch failed:', e.message); }
177
+ if (state.tab === 'history') refreshHistory();
178
+ }
179
+
180
+ window.__agentgui = { state, render };
181
+ init();
@@ -0,0 +1,99 @@
1
+ // acptoapi backend client. Resolves base URL from ?backend= or localStorage or default.
2
+ const KEY = 'agentgui.backend';
3
+ const DEFAULT_BACKEND = 'http://localhost:4800';
4
+
5
+ export function getBackend() {
6
+ const u = new URL(location.href);
7
+ const fromQs = u.searchParams.get('backend');
8
+ if (fromQs) { localStorage.setItem(KEY, fromQs); return fromQs; }
9
+ return localStorage.getItem(KEY) || DEFAULT_BACKEND;
10
+ }
11
+
12
+ export function setBackend(url) {
13
+ localStorage.setItem(KEY, url);
14
+ }
15
+
16
+ export async function probeBackend(base) {
17
+ try {
18
+ const r = await fetch(base + '/health', { method: 'GET' });
19
+ if (!r.ok) return { ok: false, status: r.status };
20
+ const j = await r.json();
21
+ return { ok: true, info: j };
22
+ } catch (e) {
23
+ return { ok: false, error: e.message };
24
+ }
25
+ }
26
+
27
+ export async function listModels(base) {
28
+ const r = await fetch(base + '/v1/models');
29
+ if (!r.ok) throw new Error('models: ' + r.status);
30
+ const j = await r.json();
31
+ return j.data || [];
32
+ }
33
+
34
+ export async function listSessions(base) {
35
+ const r = await fetch(base + '/v1/history/sessions');
36
+ if (!r.ok) throw new Error('sessions: ' + r.status);
37
+ return r.json();
38
+ }
39
+
40
+ export async function getSessionEvents(base, sid) {
41
+ const r = await fetch(base + '/v1/history/sessions/' + encodeURIComponent(sid) + '/events');
42
+ if (!r.ok) throw new Error('events: ' + r.status);
43
+ const j = await r.json();
44
+ return j.events || [];
45
+ }
46
+
47
+ export async function searchHistory(base, q, limit = 50) {
48
+ const r = await fetch(base + '/v1/history/search?q=' + encodeURIComponent(q) + '&limit=' + limit);
49
+ if (!r.ok) throw new Error('search: ' + r.status);
50
+ return r.json();
51
+ }
52
+
53
+ export function streamHistory(base, onEvent) {
54
+ const es = new EventSource(base + '/v1/history/stream');
55
+ for (const k of ['hello', 'event', 'error', 'start', 'complete', 'conversation']) {
56
+ es.addEventListener(k, ev => {
57
+ let data; try { data = JSON.parse(ev.data); } catch { data = null; }
58
+ onEvent(k, data);
59
+ });
60
+ }
61
+ return es;
62
+ }
63
+
64
+ // Streaming chat completions using OpenAI-style SSE.
65
+ export async function* streamChat(base, { model, messages, signal }) {
66
+ const r = await fetch(base + '/v1/chat/completions', {
67
+ method: 'POST',
68
+ headers: { 'Content-Type': 'application/json' },
69
+ body: JSON.stringify({ model, messages, stream: true }),
70
+ signal,
71
+ });
72
+ if (!r.ok) {
73
+ const t = await r.text();
74
+ throw new Error('chat: ' + r.status + ' ' + t.slice(0, 300));
75
+ }
76
+ const reader = r.body.getReader();
77
+ const dec = new TextDecoder();
78
+ let buf = '';
79
+ while (true) {
80
+ const { done, value } = await reader.read();
81
+ if (done) break;
82
+ buf += dec.decode(value, { stream: true });
83
+ let idx;
84
+ while ((idx = buf.indexOf('\n\n')) !== -1) {
85
+ const block = buf.slice(0, idx);
86
+ buf = buf.slice(idx + 2);
87
+ const line = block.split('\n').find(l => l.startsWith('data:'));
88
+ if (!line) continue;
89
+ const payload = line.slice(5).trim();
90
+ if (payload === '[DONE]') return;
91
+ try {
92
+ const j = JSON.parse(payload);
93
+ const delta = j.choices?.[0]?.delta?.content;
94
+ if (delta) yield { type: 'text', text: delta };
95
+ if (j.error) yield { type: 'error', error: j.error };
96
+ } catch (_) {}
97
+ }
98
+ }
99
+ }