@chroxy/server 0.10.0 → 0.11.0
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/CONFIG.md +411 -14
- package/hooks/permission-hook.sh +253 -3
- package/package.json +8 -15
- package/sidecar/node_modules/.package-lock.json +29 -0
- package/sidecar/node_modules/ws/LICENSE +20 -0
- package/sidecar/node_modules/ws/README.md +548 -0
- package/sidecar/node_modules/ws/browser.js +8 -0
- package/sidecar/node_modules/ws/index.js +22 -0
- package/sidecar/node_modules/ws/lib/buffer-util.js +131 -0
- package/sidecar/node_modules/ws/lib/constants.js +19 -0
- package/sidecar/node_modules/ws/lib/event-target.js +292 -0
- package/sidecar/node_modules/ws/lib/extension.js +203 -0
- package/sidecar/node_modules/ws/lib/limiter.js +55 -0
- package/sidecar/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/sidecar/node_modules/ws/lib/receiver.js +706 -0
- package/sidecar/node_modules/ws/lib/sender.js +602 -0
- package/sidecar/node_modules/ws/lib/stream.js +161 -0
- package/sidecar/node_modules/ws/lib/subprotocol.js +62 -0
- package/sidecar/node_modules/ws/lib/validation.js +152 -0
- package/sidecar/node_modules/ws/lib/websocket-server.js +554 -0
- package/sidecar/node_modules/ws/lib/websocket.js +1393 -0
- package/sidecar/node_modules/ws/package.json +70 -0
- package/sidecar/node_modules/ws/wrapper.mjs +21 -0
- package/src/base-session.js +151 -6
- package/src/billing-budget.js +5 -1
- package/src/binary-provenance-trust.js +95 -0
- package/src/built-in-tools/file-ops.js +5 -4
- package/src/byok-mcp-client.js +1061 -13
- package/src/byok-mcp-config.js +1201 -4
- package/src/byok-mcp-fleet.js +374 -29
- package/src/byok-mcp-oauth-store.js +327 -0
- package/src/byok-mcp-oauth.js +635 -0
- package/src/byok-mcp-trust.js +254 -37
- package/src/byok-session.js +789 -13
- package/src/byok-tool-executor.js +20 -13
- package/src/checkpoint-manager.js +33 -6
- package/src/chroxy-host-metadata.js +122 -0
- package/src/claude-stream-parser.js +56 -0
- package/src/claude-tui/pty-driver.js +54 -14
- package/src/claude-tui-session.js +106 -7
- package/src/cli/config-cmd.js +2 -2
- package/src/cli/deploy-cmd.js +1 -1
- package/src/cli/init-cmd.js +1 -1
- package/src/cli/providers-cmd.js +3 -3
- package/src/cli/schedule-cmd.js +775 -0
- package/src/cli/server-cmd.js +16 -1
- package/src/cli/service-cmd.js +39 -19
- package/src/cli/shared.js +7 -4
- package/src/cli/tokens-cmd.js +213 -0
- package/src/cli/tunnel-cmd.js +1 -1
- package/src/cli-session.js +66 -10
- package/src/cli.js +4 -0
- package/src/codex-app-server-session.js +671 -39
- package/src/codex-session.js +121 -18
- package/src/config.js +453 -27
- package/src/control-room/integrations.js +16 -10
- package/src/control-room/skills-inventory.js +6 -1
- package/src/control-room/survey.js +32 -0
- package/src/credential-store.js +256 -10
- package/src/dashboard-next/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/src/diagnostics.js +3 -0
- package/src/docker-sdk-session.js +16 -1
- package/src/docker-session.js +9 -0
- package/src/doctor.js +19 -8
- package/src/environments/backends/docker.js +8 -0
- package/src/environments/backends/k8s.js +9 -0
- package/src/event-ingest.js +19 -1
- package/src/event-normalizer.js +354 -19
- package/src/external-session-registry.js +0 -0
- package/src/gemini-session.js +19 -2
- package/src/github-webhook.js +188 -4
- package/src/handler-utils.js +42 -8
- package/src/handlers/checkpoint-handlers.js +126 -19
- package/src/handlers/control-room-handlers.js +48 -18
- package/src/handlers/conversation-handlers.js +127 -2
- package/src/handlers/credential-handlers.js +43 -2
- package/src/handlers/file-handlers.js +47 -3
- package/src/handlers/github-webhook-handlers.js +204 -0
- package/src/handlers/input-handlers.js +4 -0
- package/src/handlers/orchestration-handlers.js +238 -0
- package/src/handlers/scheduler-handlers.js +510 -0
- package/src/handlers/session-handlers.js +10 -2
- package/src/handlers/settings-handlers.js +510 -11
- package/src/handlers/token-handlers.js +11 -2
- package/src/http-routes.js +159 -0
- package/src/jsonl-reader.js +60 -6
- package/src/jsonl-subprocess-session.js +35 -6
- package/src/keychain.js +159 -12
- package/src/logger.js +182 -19
- package/src/notification-prefs.js +88 -6
- package/src/notifications/discord-webhook-sink.js +30 -1
- package/src/orchestration/build-manager.js +56 -0
- package/src/orchestration/decision-contract.js +245 -0
- package/src/orchestration/git-ops.js +347 -0
- package/src/orchestration/orchestration-manager.js +1295 -0
- package/src/orchestration/permission-gate.js +109 -0
- package/src/orchestration/role-prompts.js +136 -0
- package/src/orchestration/run-budget.js +81 -0
- package/src/orchestration/run-ledger.js +487 -0
- package/src/orchestration/run-model.js +205 -0
- package/src/orchestration/run-record.js +336 -0
- package/src/orchestration/run-report.js +194 -0
- package/src/orchestration/to-wire.js +201 -0
- package/src/orchestration/turn-driver.js +398 -0
- package/src/pairing.js +146 -1
- package/src/permission-audit.js +79 -3
- package/src/permission-floor.js +455 -0
- package/src/permission-manager.js +492 -40
- package/src/permission-resolver.js +55 -7
- package/src/permission-rule-store.js +411 -0
- package/src/platform.js +367 -23
- package/src/providers.js +21 -2
- package/src/schedule-parser.js +311 -0
- package/src/scheduled-task-store.js +653 -0
- package/src/scheduler.js +1029 -0
- package/src/sdk-session.js +338 -5
- package/src/server-cli/server-orchestrator.js +23 -0
- package/src/server-cli/tunnel-lifecycle-handler.js +3 -2
- package/src/server-cli.js +238 -26
- package/src/server-identity.js +28 -4
- package/src/service.js +291 -33
- package/src/session-manager.js +417 -25
- package/src/session-message-history.js +27 -21
- package/src/session-title.js +168 -0
- package/src/session-token-store.js +60 -35
- package/src/skills-usage.js +20 -2
- package/src/statusline.js +584 -0
- package/src/subagent-counter.js +9 -1
- package/src/supervisor.js +77 -27
- package/src/token-manager.js +39 -9
- package/src/transcript-tasks.js +41 -6
- package/src/tunnel/cloudflare.js +115 -8
- package/src/tunnel/index.js +4 -1
- package/src/tunnel-check.js +1 -1
- package/src/turn-tracker.js +0 -0
- package/src/usage-normalize.js +118 -0
- package/src/user-shell-session.js +98 -32
- package/src/utils/componentwise-resolver.js +205 -0
- package/src/utils/composite-key.js +45 -0
- package/src/utils/iso-datetime.js +51 -0
- package/src/utils/preflight.js +140 -28
- package/src/utils/spawn-env.js +8 -2
- package/src/utils/verify-binary.js +276 -0
- package/src/utils/verify-provenance.js +241 -0
- package/src/utils/wire-counters.js +48 -0
- package/src/worktree-gc.js +4 -1
- package/src/ws-file-ops/browser.js +42 -11
- package/src/ws-file-ops/common.js +68 -1
- package/src/ws-file-ops/git.js +221 -3
- package/src/ws-file-ops/index.js +5 -0
- package/src/ws-file-ops/memory.js +358 -0
- package/src/ws-file-ops/reader.js +124 -0
- package/src/ws-forwarding.js +44 -16
- package/src/ws-handler-context.js +19 -0
- package/src/ws-history.js +84 -11
- package/src/ws-message-handlers.js +6 -0
- package/src/ws-outbound-schemas.js +207 -0
- package/src/ws-permissions.js +285 -4
- package/src/ws-schemas.js +1 -0
- package/src/ws-server.js +301 -17
package/src/ws-server.js
CHANGED
|
@@ -22,8 +22,9 @@ import { handleAuthMessage, handlePairMessage, handlePairRequestMessage, handleK
|
|
|
22
22
|
import { postPairLinkToDiscord } from './discord-pair-delivery.js'
|
|
23
23
|
import { sendPostAuthInfo, replayHistory, flushPostAuthQueue, sendSessionInfo } from './ws-history.js'
|
|
24
24
|
import { createDevicePreferences } from './device-preferences.js'
|
|
25
|
-
import { isUserShellEnabled, isIdeFeatureEnabled } from './config.js'
|
|
25
|
+
import { isUserShellEnabled, isIdeFeatureEnabled, isOrchestrationEnabled, DEFAULT_MAX_PAYLOAD_BYTES } from './config.js'
|
|
26
26
|
import { createHttpHandler } from './http-routes.js'
|
|
27
|
+
import { setMcpOAuthCallbackBase } from './byok-mcp-oauth.js'
|
|
27
28
|
import { CheckpointManager } from './checkpoint-manager.js'
|
|
28
29
|
import { DevPreviewManager } from './dev-preview.js'
|
|
29
30
|
import { WebTaskManager } from './web-task-manager.js'
|
|
@@ -38,6 +39,8 @@ import { terminalMirrorRecipient } from './handler-utils.js'
|
|
|
38
39
|
import { getProviderDataDirs } from './providers.js'
|
|
39
40
|
import { assertCtxShape } from './ws-handler-context.js'
|
|
40
41
|
import { isLoopbackHost } from './bind-host.js'
|
|
42
|
+
import { getLanIp } from './lan-ip.js'
|
|
43
|
+
import { deriveWebhookPayloadUrl } from './github-webhook.js'
|
|
41
44
|
import { isLocalOrLanPeer } from './connection-locality.js'
|
|
42
45
|
|
|
43
46
|
const __filename = fileURLToPath(import.meta.url)
|
|
@@ -181,6 +184,13 @@ export const TUNNEL_STATUS_MIN_PROTOCOL_VERSION = 2
|
|
|
181
184
|
let _latestVersionCache = { version: null, checkedAt: 0 }
|
|
182
185
|
const VERSION_CHECK_TTL = 3600_000 // 1 hour
|
|
183
186
|
|
|
187
|
+
// #7053: how long the panic-revoke ack waits on its durable-write persist before
|
|
188
|
+
// reporting the outcome as UNKNOWN. Long enough that a slow-but-working fsync or
|
|
189
|
+
// keychain call still reports the truthful result, short enough that an operator
|
|
190
|
+
// who just hit the panic button is not left staring at nothing. Overridable per
|
|
191
|
+
// instance via `_revokeAckTimeoutMs` (tests use a few ms).
|
|
192
|
+
const REVOKE_ACK_TIMEOUT_MS = 10_000
|
|
193
|
+
|
|
184
194
|
// #5555.6 — keepalive sweep cadence. Previously 30s, which (with the
|
|
185
195
|
// two-phase mark-then-terminate cycle) held a zombie client up to ~60s — ~6×
|
|
186
196
|
// longer than a client holds a zombie server (15s ping + 5s pong timeout =
|
|
@@ -268,6 +278,7 @@ function _isSecureRequest(req) {
|
|
|
268
278
|
* { type: 'browse_files', path? } — request file/directory listing for file browser
|
|
269
279
|
* { type: 'read_file', path } — request file content for file viewer
|
|
270
280
|
* { type: 'write_file', path, content } — write file content (path validated, 5MB limit)
|
|
281
|
+
* { type: 'memory_read', requestId? } — request the effective merged CLAUDE.md memory stack + auto-memory descriptor (#6864, epic #6760); no client-supplied path (server-chosen locations only)
|
|
271
282
|
* { type: 'list_slash_commands' } — request available slash commands
|
|
272
283
|
* { type: 'list_agents' } — request available custom agents
|
|
273
284
|
* { type: 'request_full_history', sessionId? } — request full JSONL history for a session
|
|
@@ -286,10 +297,12 @@ function _isSecureRequest(req) {
|
|
|
286
297
|
* { type: 'get_diff', path? } — request git diff for working directory
|
|
287
298
|
* { type: 'git_branches' } — request git branch list
|
|
288
299
|
* { type: 'git_commit', message, files? } — commit staged/specified files
|
|
300
|
+
* { type: 'git_create_pr', title, body?, base?, draft? } — push current branch + open a PR via gh (#6876)
|
|
289
301
|
* { type: 'git_stage', files } — stage files for commit
|
|
290
302
|
* { type: 'git_status' } — request git status
|
|
291
303
|
* { type: 'git_unstage', files } — unstage files
|
|
292
304
|
* { type: 'list_conversations' } — request saved conversation list
|
|
305
|
+
* { type: 'request_conversation_transcript', conversationId, cwd? } — read-only replay of a CLOSED conversation from disk (no provider spawn; #6860)
|
|
293
306
|
* { type: 'list_files', path? } — request file listing for a path
|
|
294
307
|
* { type: 'list_symbols', path? } — request workspace symbol table (#6471, opt-in IDE — features.ide)
|
|
295
308
|
* { type: 'resolve_symbol', symbol, file? } — resolve a symbol name to its definition (#6475, opt-in IDE — features.ide)
|
|
@@ -314,6 +327,13 @@ function _isSecureRequest(req) {
|
|
|
314
327
|
* { type: 'terminal_input', sessionId, data } — #5835 Phase 3 raw keystrokes → live claude-tui PTY (true remote control); authority mirrors `input` (bound-session check + single-driver primary gate; an observer's keystroke is rejected with input_conflict)
|
|
315
328
|
* { type: 'set_thinking_level', level } — set thinking budget level ('default'|'high'|'max')
|
|
316
329
|
* { type: 'set_permission_rules', rules, sessionId } — set per-session auto-approval rules
|
|
330
|
+
* { type: 'set_mcp_server_enabled', server, enabled, sessionId?, requestId? } — #6824 runtime park/unpark of an ALREADY-CONFIGURED MCP server (BYOK lane; own-session gate)
|
|
331
|
+
* { type: 'submit_mcp_auth_code', server, code, sessionId?, requestId? } — #6822 submit a pasted OAuth authorization code for a remote MCP server (BYOK lane)
|
|
332
|
+
* { type: 'add_mcp_server', name, config, scope?, sessionId?, requestId? } — #6974 ADD an MCP server, persisting it to the user's MCP config (BYOK lane; STRICT-PRIMARY gate — any non-primary token is rejected, since a configured server is a command this machine will spawn; #7001)
|
|
333
|
+
* { type: 'remove_mcp_server', name, scope?, sessionId?, requestId? } — #6974 permanently REMOVE a configured MCP server from the user's MCP config (BYOK lane; same strict-primary gate)
|
|
334
|
+
* { type: 'scheduled_tasks_request', requestId? } — #6871 read the standing scheduled-task registry + the scheduler gate state (host-level: a pairing-BOUND client is rejected)
|
|
335
|
+
* { type: 'scheduled_task_action', action, taskId?, task?, requestId? } — #6871 create/update/pause/resume/delete a scheduled task (UNBOUND-STRICT-PRIMARY gate — a scheduled task makes this machine run an agent session unattended; a pairing-BOUND client is rejected even if it is primary, #7025)
|
|
336
|
+
* { type: 'set_scheduler_enabled', enabled, requestId? } — #6871 flip the PERSISTED global scheduled-execution gate (features.scheduler); same unbound-strict-primary gate, and a daemon restart is required for it to take effect (reported as scheduler.restartRequired)
|
|
317
337
|
* { type: 'set_prompt_evaluator', value: boolean, sessionId? } — toggle the per-session promptEvaluator (#3185)
|
|
318
338
|
* { type: 'set_prompt_evaluator_skip_pattern', value: string|null, sessionId? } — set the per-session evaluator skip-pattern source (#3639)
|
|
319
339
|
* { type: 'set_chroxy_context_hint', value: boolean, sessionId? } — toggle the per-session Chroxy context hint (#3805)
|
|
@@ -344,14 +364,15 @@ function _isSecureRequest(req) {
|
|
|
344
364
|
* { type: 'terminal_size', sessionId, cols, rows } — #5835 Phase 2 authoritative live-PTY grid size; sent to a client on terminal_subscribe and broadcast to all terminal subscribers on a primary-driven terminal_resize so observers re-letterbox to the same grid
|
|
345
365
|
* { type: 'tool_start', messageId, toolUseId, tool, input, serverName? } — tool invocation (serverName present for MCP tools)
|
|
346
366
|
* { type: 'tool_input_delta', messageId, toolUseId, partialJson } — #4080/#4081: incremental partial JSON for the streaming tool_use `input`; concatenate per-toolUseId for the live bubble preview
|
|
347
|
-
* { type: 'tool_result', toolUseId, result, truncated, images? } — tool result (images: [{mediaType, data}])
|
|
348
|
-
* { type: 'mcp_servers', servers: [{ name, status }] }
|
|
367
|
+
* { type: 'tool_result', toolUseId, result, truncated, images?, isError? } — tool result (images: [{mediaType, data}]; #6712 isError flags a failed tool for the error affordance)
|
|
368
|
+
* { type: 'mcp_servers', servers: [{ name, status, enabled?, canToggle?, authUrl? }] } — configured MCP servers (#6824: enabled + canToggle per-server; BYOK lane sets canToggle:true so clients render the enable/disable toggle; status 'disabled' = parked; #6822: status 'oauth-required' + authUrl surfaces the browser authorization URL a remote server needs)
|
|
349
369
|
* { type: 'result', ... } — query stats
|
|
350
370
|
* { type: 'status', connected: true } — connection status
|
|
351
371
|
* { type: 'claude_ready' } — Claude Code ready for input
|
|
352
372
|
* { type: 'model_changed', model: '...' } — active model updated
|
|
353
373
|
* { type: 'available_models', models: [...], provider?, defaultModel? } — models the active provider accepts
|
|
354
374
|
* { type: 'permission_input', requestId, found, tool?, input?, error? } — #6543 (IDE P3 feature B) reply to a `get_permission_input` pull: the FULL secret-redacted tool input for a pending permission (the `permission_request` broadcast truncates `input` at ~10K), so a client can build a per-hunk pre-write diff. `found:false` (+ `error`) when the request is unknown / already resolved / owned by another session — the handler is session-bound (a client only gets input for a permission its session owns).
|
|
375
|
+
* { type: 'permission_audit_result', entries } — #6772 reply to a `query_permission_audit` pull: recent permission audit entries (mode changes / session-rule changes / allow-deny decisions) matching the query's optional sessionId/auditType/since/limit. Consumed by the dashboard's per-session "Permission history" view.
|
|
355
376
|
* { type: 'permission_request', requestId, tool, description, input, remainingMs } — permission prompt
|
|
356
377
|
* { type: 'confirm_permission_mode', mode, warning } — server challenges auto mode (client must re-send with confirmed: true)
|
|
357
378
|
* { type: 'permission_mode_changed', mode: '...' } — permission mode updated
|
|
@@ -394,14 +415,15 @@ function _isSecureRequest(req) {
|
|
|
394
415
|
* { type: 'client_focus_changed', clientId, sessionId, timestamp } — another client changed session focus
|
|
395
416
|
* { type: 'checkpoint_created', sessionId, checkpoint } — checkpoint created (auto or manual)
|
|
396
417
|
* { type: 'checkpoint_list', sessionId, checkpoints } — list of checkpoints
|
|
397
|
-
* { type: 'checkpoint_restored', checkpointId,
|
|
418
|
+
* { type: 'checkpoint_restored', checkpointId, mode, newSessionId?, name?, filesOnly? } — checkpoint restored (#6766/#6767: mode 'files' keeps the current session — no newSessionId, name = the checkpoint's name; 'conversation'/'both' create + re-home to a rewound session, name = its name; filesOnly true = working tree only, conversation NOT branched)
|
|
398
419
|
* { type: 'primary_changed', sessionId, clientId } — last-writer-wins primary changed (null on disconnect)
|
|
399
420
|
* { type: 'session_role', sessionId, primaryClientId } — #5589/#5281: explicit primary-ownership; client derives its role (primary iff primaryClientId === own clientId, observer if another holds it, null = unclaimed)
|
|
400
421
|
* { type: 'pong' } — heartbeat response
|
|
401
422
|
* { type: 'permission_expired', requestId, sessionId, message } — permission response could not be routed (expired/handled)
|
|
402
|
-
* { type: 'token_rotated', token?, expiresAt, reason? } — API token changed. Scheduled rotation carries the new `token` to encrypted clients (transparent re-key, sessions survive). A `reason: 'revoke'` (#6006) carries NO token: the operator revoked, so the server severed user-shell sessions and cleared this connection's auth — the client must re-authenticate with the current token (obtained out-of-band).
|
|
423
|
+
* { type: 'token_rotated', token?, expiresAt, reason? } — API token changed. Scheduled rotation carries the new `token` to encrypted clients (transparent re-key, sessions survive). A `reason: 'revoke'` (#6006) carries NO token: the operator revoked, so the server severed user-shell sessions and cleared this connection's auth — the client must re-authenticate with the current token (obtained out-of-band). #6965: for a revoke this message is WITHHELD until the daemon's token persist reports success, so the ack can never precede the revocation being stored — that persist is an fsync of the temp file + containing directory on the `config.json` fallback, while on the OS-keychain path (the macOS/libsecret default) durability is delegated to the keychain and no fsync is performed here. If the persist FAILS the connection receives an `error` with `code: 'REVOKE_NOT_DURABLE'` FIRST and then this message anyway: enforcement already ran unconditionally, so the client must still re-authenticate — the message carries no token and makes no durability claim, and the caveat rides the error. #7053: the wait is BOUNDED (`REVOKE_ACK_TIMEOUT_MS`), because an `onPersist` that never settles would otherwise emit nothing at all and make the panic button look like a no-op; on timeout the connection gets `code: 'REVOKE_DURABILITY_UNKNOWN'` — deliberately NOT `REVOKE_NOT_DURABLE`, since a timeout means the outcome is unknown and may still land, not that the write is known to have failed — followed by this message on the same reasoning.
|
|
403
424
|
* { type: 'session_warning', sessionId, name, reason, message, remainingMs } — session about to timeout
|
|
404
425
|
* { type: 'session_timeout', sessionId, name, idleMs } — session destroyed due to idle timeout
|
|
426
|
+
* { type: 'statusline_output', sessionId, text, active?, truncated? } — #6791: rendered stdout of the user's own Claude Code statusLine script (active:false + empty text clears it)
|
|
405
427
|
* { type: 'dev_preview', port, url, sessionId } — dev server preview tunnel opened
|
|
406
428
|
* { type: 'dev_preview_stopped', port, sessionId } — dev server preview tunnel closed
|
|
407
429
|
* { type: 'web_task_created', task } — cloud task launched
|
|
@@ -416,11 +438,14 @@ function _isSecureRequest(req) {
|
|
|
416
438
|
* { type: 'error', message } — general error message
|
|
417
439
|
* { type: 'file_list', path, files, error? } — file listing response
|
|
418
440
|
* { type: 'git_branches_result', branches, current, error? } — git branches result
|
|
419
|
-
* { type: 'git_commit_result',
|
|
420
|
-
* { type: '
|
|
441
|
+
* { type: 'git_commit_result', hash, message, error } — git commit result
|
|
442
|
+
* { type: 'git_create_pr_result', url, number, branch, base, error } — in-app PR creation result (#6876; dashboard-only v1)
|
|
443
|
+
* { type: 'git_stage_result', error } — git stage result
|
|
421
444
|
* { type: 'git_status_result', status, error? } — git status result
|
|
422
|
-
* { type: 'git_unstage_result',
|
|
423
|
-
* { type: 'write_file_result',
|
|
445
|
+
* { type: 'git_unstage_result', error } — git unstage result
|
|
446
|
+
* { type: 'write_file_result', path, error } — write file result
|
|
447
|
+
* { type: 'append_memory_result', path, created, error? } — `#`-quick-append ack (#6861)
|
|
448
|
+
* { type: 'memory_stack_result', entries, memoryFile, error?, requestId? } — reply to `memory_read` (#6864, epic #6760): ordered global/project/local CLAUDE.md stack with per-file provenance (+ recursively-resolved @imports, path-confined to the session cwd + ~/.claude) plus the auto-generated MEMORY.md descriptor. Server-only for v1 — no client handler yet; the dashboard/mobile memory-panel consumers are the sibling slices #6867/#6870
|
|
424
449
|
* { type: 'log_entry', level, message, timestamp } — server log entry for dashboard
|
|
425
450
|
* { type: 'session_activity', sessionId, isBusy, lastCost } — session busy/idle state change
|
|
426
451
|
* { type: 'session_context', sessionId, cwd, conversationId?, ... } — session context data
|
|
@@ -464,6 +489,7 @@ function _isSecureRequest(req) {
|
|
|
464
489
|
* { type: 'external_sessions_snapshot', requestId?, generatedAt, sessions, error? } — Control Room mission-control external-session survey reply (#5969, epic #5422 phase 4); reply to an `external_sessions_request`. `sessions` lists the LIVE external Claude Code sessions the daemon learned about over `POST /api/events` (#5413) — sessions it did NOT launch — each carrying source/sessionId/name/project/cwd, a read-only `status` ('running'|'idle'), active `subagents`, and `lastActivityTs`. Read-only (no PTY/control handle exists for these). Host-level: a session-bound token is refused with an additive `error: { code, message }` on an otherwise-empty (schema-valid) snapshot. `requestId` echoes the request when provided.
|
|
465
490
|
* { type: 'repo_events_delta', generatedAt, event } — Control Room repo-events LIVE delta (#6536, PR-2 of #5966); server-INITIATED (no request) push of a single newly-buffered repo-event when a GitHub webhook delivery lands, so the pane updates without a Refresh. Host-level: broadcast ONLY to unbound (host-authority) clients — a session-bound (share-a-session) token never receives host repo activity. A client that hasn't run the survey ignores it; a client with a snapshot appends the event (bounded). No `error`/`requestId` — degraded surveys still flow through the pull `repo_events_snapshot`.
|
|
466
491
|
* { type: 'repo_events_snapshot', requestId?, generatedAt, events, error? } — Control Room repo-events survey reply (#5966, epic #5422 phase 5); reply to a `repo_events_request`. `events` is the tail (most-recent-last) of the daemon's bounded RepoEventStore — GitHub-webhook activity (push/pull_request/issues/ping) ingested HMAC-verified over `POST /api/github/webhook` (#6468) — each carrying kind/repo/actor/at plus kind-specific branch/action/number/title/url and a pre-rendered `summary`. Read-only; no delta stream (a full snapshot per pull, like the host/mailbox/external surveys). Host-level: a session-bound token is refused with an additive `error: { code, message }` on an otherwise-empty (schema-valid) snapshot. `requestId` echoes the request when provided.
|
|
492
|
+
* { type: 'github_webhook_config', requestId?, generatedAt, configured, source, payloadUrl, lanOnly, note?, recommendedEvents, deliveries, error? } — Control Room repo-events webhook-secret config reply (#6540, item 3 of #6536); reply to a `github_webhook_config_request` and to a `github_webhook_set_secret` / `github_webhook_clear_secret` write. Reports whether an HMAC secret is configured and its `source` ('store'|'env'|'none') — never the value — plus the `payloadUrl` to paste into GitHub (derived from the live tunnel URL, else the LAN address, `lanOnly` + `note` when GitHub can't reach it), the `recommendedEvents`, and the recent-`deliveries` readout (count / last / verify result). Writes are host-authority gated (a session-bound token is rejected with a generic `error`); the read is open to any authenticated client. `requestId` echoes the request when provided.
|
|
467
493
|
* { type: 'summarize_session_result', sessionId, summary, truncated?, requestId? } — reply to a `summarize_session` (#5547); the model-written continuation brief built from the session's persisted history, seeded editable into the dashboard's create-session composer. `truncated` flags a windowed history. Failures surface as a SUMMARIZE_FAILED `session_error` echoing `sessionId`/`requestId` (curated message — no token/key material).
|
|
468
494
|
* { type: 'session_preset_snapshot', cwd, preset: { source, active, trustState, enabled, preamble, seed, preambleLength, seedLength, capped, repoPath } | null, requestId? } — Control Room per-repo session-preset reply (#5553, epic #5159); reply to a host-authority `session_preset_get` / `session_preset_set` / `session_preset_approve` / `session_preset_revoke`. `preset` is null when the repo has no preset. Full preamble + seed text reaches HOST-level clients only (the four requests are rejected for session-bound pairing clients). `requestId` echoes the request when provided.
|
|
469
495
|
* { type: 'provider_list', providers } — available providers
|
|
@@ -502,6 +528,11 @@ function _isSecureRequest(req) {
|
|
|
502
528
|
* { type: 'evaluator_rewrite', sessionId, originalDraft, rewritten, reasoning, evaluatorIterationId } — auto-evaluator rewrite verdict broadcast (#3208 schema, #3186 emit, #3188 dashboard handler)
|
|
503
529
|
* { type: 'evaluator_clarify', sessionId, originalDraft, clarification, reasoning, evaluatorIterationId, evaluatorIteration } — auto-evaluator clarify verdict broadcast (#3208 schema, #3186 emit, #3188 dashboard handler)
|
|
504
530
|
* { type: 'stdin_dropped_totals', sessionId, bytes, count, reason, escalated } — cumulative SidecarProcess pre-dial-cap drop totals (#3544, transient)
|
|
531
|
+
* { type: 'orchestration_runs_snapshot', requestId?, generatedAt, runs: [RunSummary], error? } — orchestration runs-list survey (#6691, dashboard-only v1)
|
|
532
|
+
* { type: 'orchestration_run_snapshot', requestId?, generatedAt, seq, run: RunDetail|null, error? } — one run's full detail (pull-only; run:null = degraded reply) (#6691)
|
|
533
|
+
* { type: 'orchestration_run_delta', runId, seq, generatedAt, run?, node?, gate?, timeline? } — live run update pushed to host-level clients; client applies iff seq===held+1 (#6691)
|
|
534
|
+
* { type: 'scheduled_tasks', generatedAt, scheduler: { enabled, engineArmed, restartRequired, source }, schedulableProviders, defaultProvider, defaultProviderRefusal, tasks[], requestId?, error? } — #6871 scheduled-task registry snapshot for the dashboard panel; sent to the REQUESTING client only, and re-emitted as the ack for every accepted mutation. Each task carries the engine's own verdicts (providerRefusal / effectivePermissionMode / permissionModeClamped / quarantined) so a client never re-derives a safety decision
|
|
535
|
+
* { type: 'orchestration_action_ack', requestId?, action, runId, gateId? } — terminal success echo for a mutating orchestration action (#6691)
|
|
505
536
|
*
|
|
506
537
|
* Encrypted envelope (bidirectional, wraps any message above after key exchange):
|
|
507
538
|
* { type: 'encrypted', d: '<base64 ciphertext>', n: <nonce counter> }
|
|
@@ -543,7 +574,7 @@ function _isSecureRequest(req) {
|
|
|
543
574
|
* - A session operation failed in an expected, user-facing way → `session_error`
|
|
544
575
|
*/
|
|
545
576
|
export class WsServer {
|
|
546
|
-
constructor({ port, apiToken, cliSession, sessionManager, defaultSessionId, authRequired = true, pushManager = null, maxPayload, noEncrypt, keyExchangeTimeoutMs, localhostBypass, tokenManager, pairingManager, serverIdentity = null, maxPendingConnections, backpressureThreshold, environmentManager, config = null, diagnosticsRateLimit = null, devicePreferences = null, pagesStore = null, pagesRateLimiter } = {}) {
|
|
577
|
+
constructor({ port, apiToken, cliSession, sessionManager, defaultSessionId, authRequired = true, pushManager = null, maxPayload, noEncrypt, keyExchangeTimeoutMs, localhostBypass, tokenManager, pairingManager, serverIdentity = null, maxPendingConnections, backpressureThreshold, environmentManager, orchestrationManager = null, schedulerEngine = null, config = null, diagnosticsRateLimit = null, devicePreferences = null, pagesStore = null, pagesRateLimiter } = {}) {
|
|
547
578
|
this.port = port
|
|
548
579
|
this.apiToken = apiToken
|
|
549
580
|
this._tokenManager = tokenManager || null
|
|
@@ -558,7 +589,9 @@ export class WsServer {
|
|
|
558
589
|
// can read settings (e.g. workspaceRoots for cwd allowlist) at
|
|
559
590
|
// message time. May be null in tests that don't pass it through.
|
|
560
591
|
this.config = config || null
|
|
561
|
-
|
|
592
|
+
// #7011 — default comes from config.js so the `--max-payload` help text and
|
|
593
|
+
// CONFIG.md quote the same number this fallback applies.
|
|
594
|
+
this._maxPayload = maxPayload || DEFAULT_MAX_PAYLOAD_BYTES
|
|
562
595
|
this.authRequired = authRequired
|
|
563
596
|
this._encryptionEnabled = !noEncrypt
|
|
564
597
|
this._keyExchangeTimeoutMs = keyExchangeTimeoutMs ?? 10_000
|
|
@@ -884,6 +917,27 @@ export class WsServer {
|
|
|
884
917
|
// Lazily created on the first webhook delivery, so null until then —
|
|
885
918
|
// the survey handler treats a null store as an empty (schema-valid) feed.
|
|
886
919
|
get repoEventStore() { return self._repoEventStore ?? null },
|
|
920
|
+
// #6540: repo-events webhook-secret config surface. `webhookPayloadUrl`
|
|
921
|
+
// derives the GitHub payload URL from the live tunnel/LAN origin;
|
|
922
|
+
// `repoWebhookDeliveries` is the in-memory recent-delivery ring the HTTP
|
|
923
|
+
// webhook receiver fills (null until the first delivery);
|
|
924
|
+
// `setWebhookSecretCache` lets the config handler refresh the in-process
|
|
925
|
+
// hot cache after a set/rotate/clear so live deliveries pick it up without
|
|
926
|
+
// a keychain re-read (and a rotate never serves a stale cached value).
|
|
927
|
+
get webhookPayloadUrl() { return self.getWebhookPayloadUrl() },
|
|
928
|
+
get repoWebhookDeliveries() { return self._repoWebhookDeliveries ?? null },
|
|
929
|
+
setWebhookSecretCache: (value) => {
|
|
930
|
+
self._githubWebhookSecret = (typeof value === 'string' && value.length > 0) ? value : null
|
|
931
|
+
},
|
|
932
|
+
// #6691: the OrchestrationManager, wired for real in E-4. Null until then
|
|
933
|
+
// (and whenever the feature is off) — the handlers treat a null manager
|
|
934
|
+
// as "engine not running" and reply with an unavailable error.
|
|
935
|
+
get orchestrationManager() { return self._orchestrationManager ?? null },
|
|
936
|
+
// #6871: the SchedulerEngine, for the scheduled-tasks panel's gate +
|
|
937
|
+
// quarantine readout. Null whenever scheduled execution is disabled (the
|
|
938
|
+
// default) — the handlers report that as "not armed" rather than hiding
|
|
939
|
+
// it. Late-bound so it tracks the server instance.
|
|
940
|
+
get schedulerEngine() { return self._schedulerEngine ?? null },
|
|
887
941
|
},
|
|
888
942
|
runtime: {
|
|
889
943
|
get draining() { return self._draining },
|
|
@@ -964,6 +1018,10 @@ export class WsServer {
|
|
|
964
1018
|
// `ide` capability so clients gate IDE UI. Late-bound getter so a test
|
|
965
1019
|
// mutating self.config is seen.
|
|
966
1020
|
get ideEnabled() { return isIdeFeatureEnabled(self.config) },
|
|
1021
|
+
// #6691: whether the orchestration harness is enabled on THIS server,
|
|
1022
|
+
// surfaced as the `orchestration` capability so the dashboard reveals the
|
|
1023
|
+
// Runs surface. Server-wide gate, not token-scoped; fail-closed.
|
|
1024
|
+
get orchestrationEnabled() { return isOrchestrationEnabled(self.config) },
|
|
967
1025
|
// #6006: whether the operator panic button (revoke_token) can fire — true
|
|
968
1026
|
// iff a usable rotating TokenManager exists (i.e. auth is on). Mirrors the
|
|
969
1027
|
// token-handlers availability check (`typeof revoke === 'function'`) so the
|
|
@@ -1060,6 +1118,12 @@ export class WsServer {
|
|
|
1060
1118
|
// Multi-session support: prefer sessionManager, fall back to single cliSession
|
|
1061
1119
|
this.sessionManager = sessionManager || null
|
|
1062
1120
|
this.environmentManager = environmentManager || null
|
|
1121
|
+
// #6691 (E-4): the OrchestrationManager (null when the feature is off). Its
|
|
1122
|
+
// run_delta events are forwarded to host-level clients by server-cli via
|
|
1123
|
+
// _broadcastOrchestrationDelta; the handlers read it off ctx.services.
|
|
1124
|
+
this._orchestrationManager = orchestrationManager || null
|
|
1125
|
+
// #6871: nullable by design — null whenever scheduled execution is disabled.
|
|
1126
|
+
this._schedulerEngine = schedulerEngine || null
|
|
1063
1127
|
this.defaultSessionId = defaultSessionId || null
|
|
1064
1128
|
this._checkpointManager = new CheckpointManager()
|
|
1065
1129
|
|
|
@@ -1071,6 +1135,7 @@ export class WsServer {
|
|
|
1071
1135
|
this._sessionCreatedHandler = ({ sessionId }) => {
|
|
1072
1136
|
const entry = sessionManager.getSession(sessionId)
|
|
1073
1137
|
this._registerSessionHookSecretIfMissing(sessionId, entry)
|
|
1138
|
+
this._attachPermissionAuditSink(sessionId, entry)
|
|
1074
1139
|
}
|
|
1075
1140
|
this._sessionDestroyedHandler = ({ sessionId }) => {
|
|
1076
1141
|
// Look up the stored secret — the session is already removed from the map
|
|
@@ -1158,7 +1223,12 @@ export class WsServer {
|
|
|
1158
1223
|
if (sessionManager._sessions instanceof Map && typeof sessionManager.getSession === 'function') {
|
|
1159
1224
|
for (const [sessionId, entry] of sessionManager._sessions) {
|
|
1160
1225
|
if (entry?._destroying) continue
|
|
1161
|
-
|
|
1226
|
+
const resolved = sessionManager.getSession(sessionId)
|
|
1227
|
+
this._registerSessionHookSecretIfMissing(sessionId, resolved)
|
|
1228
|
+
// #6830 — restored sessions predate this WsServer (restoreState runs
|
|
1229
|
+
// before construction, same shape as the #3716 hook-secret gap), so
|
|
1230
|
+
// their persisted-rule audit sinks must be wired retroactively too.
|
|
1231
|
+
this._attachPermissionAuditSink(sessionId, resolved)
|
|
1162
1232
|
}
|
|
1163
1233
|
}
|
|
1164
1234
|
}
|
|
@@ -1238,8 +1308,12 @@ export class WsServer {
|
|
|
1238
1308
|
|
|
1239
1309
|
// Wire TokenManager rotation events — broadcast new token to all clients
|
|
1240
1310
|
this._tokenRotatedHandler = null
|
|
1311
|
+
// #6965: the in-flight revoke-ack gate (a promise resolving to
|
|
1312
|
+
// `{ ok, error? }`), or null when the last revoke had nothing to wait on.
|
|
1313
|
+
// Exposed so a test can await the gate deterministically.
|
|
1314
|
+
this._lastRevokeAck = null
|
|
1241
1315
|
if (this._tokenManager) {
|
|
1242
|
-
this._tokenRotatedHandler = ({ newToken, expiresAt, reason }) => {
|
|
1316
|
+
this._tokenRotatedHandler = ({ newToken, expiresAt, reason, persisted = null }) => {
|
|
1243
1317
|
// Update our reference so subsequent auth checks use the new token
|
|
1244
1318
|
this.apiToken = newToken
|
|
1245
1319
|
|
|
@@ -1263,7 +1337,11 @@ export class WsServer {
|
|
|
1263
1337
|
} catch (err) {
|
|
1264
1338
|
log.error(`Failed to sever user-shell sessions on revoke: ${err.message}`)
|
|
1265
1339
|
}
|
|
1266
|
-
|
|
1340
|
+
//
|
|
1341
|
+
// ENFORCEMENT (severing above + stripping authority below) is immediate
|
|
1342
|
+
// and unconditional — it must NEVER wait on, or be skipped because of,
|
|
1343
|
+
// disk I/O. Only the client-facing ACK is gated on durability (#6965).
|
|
1344
|
+
const forcedSockets = []
|
|
1267
1345
|
for (const [ws, client] of this.clients) {
|
|
1268
1346
|
// Skip connections still mid-handshake (not yet authenticated): they
|
|
1269
1347
|
// hold no authority to strip and will fail their pending auth step
|
|
@@ -1271,10 +1349,149 @@ export class WsServer {
|
|
|
1271
1349
|
if (!client.authenticated || ws.readyState !== 1) continue
|
|
1272
1350
|
client.authenticated = false
|
|
1273
1351
|
client.isPrimaryToken = false
|
|
1274
|
-
|
|
1275
|
-
|
|
1352
|
+
forcedSockets.push(ws)
|
|
1353
|
+
}
|
|
1354
|
+
log.warn(`Token REVOKED — severed ${severed} user-shell session(s), forced re-auth on ${forcedSockets.length} connection(s)`)
|
|
1355
|
+
|
|
1356
|
+
const sendRevokeAck = () => {
|
|
1357
|
+
for (const ws of forcedSockets) {
|
|
1358
|
+
if (ws.readyState !== 1) continue
|
|
1359
|
+
this._send(ws, { type: 'token_rotated', expiresAt, reason: 'revoke' })
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// #6965: the revoke ack must not precede its durable write. #6963 made the
|
|
1364
|
+
// panic-revoke's token write durable, but `onPersist` was fire-and-forget
|
|
1365
|
+
// and this ack raced it — so the operator could be told the highest-authority
|
|
1366
|
+
// token was dead while a power loss inside the OS writeback window brought the
|
|
1367
|
+
// daemon back still honouring it. Wait for the persist to report success —
|
|
1368
|
+
// an fsync of the temp file + containing directory on the `config.json`
|
|
1369
|
+
// fallback, while the OS-keychain path delegates durability to the
|
|
1370
|
+
// keychain and performs no fsync here — THEN ack. On failure the client
|
|
1371
|
+
// ALSO gets an explicit error — see below.
|
|
1372
|
+
if (!persisted) {
|
|
1373
|
+
// Nothing to wait on (no persist callback configured — e.g. a test
|
|
1374
|
+
// TokenManager, or a deployment with no token persistence). Unchanged
|
|
1375
|
+
// synchronous behaviour.
|
|
1376
|
+
this._lastRevokeAck = null
|
|
1377
|
+
sendRevokeAck()
|
|
1378
|
+
return
|
|
1276
1379
|
}
|
|
1277
|
-
|
|
1380
|
+
// #7053: BOUND the gate. Waiting on `persisted` is right, but waiting
|
|
1381
|
+
// FOREVER is its own false safety: a persist that never settles emits
|
|
1382
|
+
// no ack and no error, so the operator sees a panic-revoke that appears
|
|
1383
|
+
// to do nothing — while enforcement above has already run. Today's
|
|
1384
|
+
// `onPersist` (server-cli) is synchronous, so this is latent rather
|
|
1385
|
+
// than live; the moment it becomes async, an unbounded gate turns the
|
|
1386
|
+
// most consequential control in the daemon into a silent no-op.
|
|
1387
|
+
//
|
|
1388
|
+
// A timeout is NOT the same verdict as a rejection: a rejection means
|
|
1389
|
+
// the write is KNOWN to have failed, a timeout means the outcome is
|
|
1390
|
+
// UNKNOWN and may still land. It gets its own code so the operator is
|
|
1391
|
+
// not told something the daemon does not know.
|
|
1392
|
+
let settled = false
|
|
1393
|
+
let resolveAck
|
|
1394
|
+
const ackSettled = new Promise((res) => { resolveAck = res })
|
|
1395
|
+
this._lastRevokeAck = ackSettled
|
|
1396
|
+
const timeoutMs = this._revokeAckTimeoutMs ?? REVOKE_ACK_TIMEOUT_MS
|
|
1397
|
+
const timer = setTimeout(() => {
|
|
1398
|
+
if (settled) return
|
|
1399
|
+
settled = true
|
|
1400
|
+
log.error(
|
|
1401
|
+
`Token REVOKE persist did not report within ${timeoutMs}ms — the revoke HOLDS in this process, ` +
|
|
1402
|
+
`but whether it reached disk is UNKNOWN. Check the storage layer; re-revoke after a restart to be sure.`,
|
|
1403
|
+
)
|
|
1404
|
+
// Same ordering as the rejection branch, and for the same reason: the
|
|
1405
|
+
// diagnostic first, then the state transition (which tears the socket
|
|
1406
|
+
// down client-side, so a frame queued after it can be lost).
|
|
1407
|
+
for (const ws of forcedSockets) {
|
|
1408
|
+
if (ws.readyState !== 1) continue
|
|
1409
|
+
this._send(ws, {
|
|
1410
|
+
type: 'error',
|
|
1411
|
+
code: 'REVOKE_DURABILITY_UNKNOWN',
|
|
1412
|
+
message:
|
|
1413
|
+
`Token revoke is enforced for the running daemon, but its write did not report within ${timeoutMs}ms — ` +
|
|
1414
|
+
'whether it reached disk is unknown. After a restart the daemon may come back on either token. ' +
|
|
1415
|
+
'Check the storage layer and revoke again to be certain.',
|
|
1416
|
+
})
|
|
1417
|
+
}
|
|
1418
|
+
// Still send the transition. It carries no token and claims no
|
|
1419
|
+
// durability; it is the client's ONLY automatic trigger to drop the
|
|
1420
|
+
// now-dead credential and re-authenticate. Withholding it would leave
|
|
1421
|
+
// every device "connected" holding a revoked token.
|
|
1422
|
+
sendRevokeAck()
|
|
1423
|
+
resolveAck({ ok: false, timedOut: true })
|
|
1424
|
+
}, timeoutMs)
|
|
1425
|
+
// Never let the bound hold the event loop open (a pending timer here
|
|
1426
|
+
// would keep the process — and the test runner — alive).
|
|
1427
|
+
timer.unref?.()
|
|
1428
|
+
|
|
1429
|
+
persisted.then(
|
|
1430
|
+
() => {
|
|
1431
|
+
if (settled) {
|
|
1432
|
+
log.warn('Token REVOKE persist landed AFTER the durability bound had already been reported as unknown.')
|
|
1433
|
+
return
|
|
1434
|
+
}
|
|
1435
|
+
settled = true
|
|
1436
|
+
clearTimeout(timer)
|
|
1437
|
+
sendRevokeAck()
|
|
1438
|
+
resolveAck({ ok: true })
|
|
1439
|
+
},
|
|
1440
|
+
(err) => {
|
|
1441
|
+
const message = err?.message || String(err)
|
|
1442
|
+
if (settled) {
|
|
1443
|
+
// error, not warn: this is a CONFIRMED non-durable write — strictly
|
|
1444
|
+
// worse than the "unknown" the operator was already told — and no
|
|
1445
|
+
// client frame is sent for it (that would double-send), so this
|
|
1446
|
+
// line is the only surviving artifact. It must not rank below the
|
|
1447
|
+
// on-time failure in alerting.
|
|
1448
|
+
log.error(
|
|
1449
|
+
`Token REVOKE persist FAILED (${message}) after the durability bound had already reported unknown — ` +
|
|
1450
|
+
`the write is now known NOT to be durable. Fix the storage error and revoke again.`,
|
|
1451
|
+
)
|
|
1452
|
+
return
|
|
1453
|
+
}
|
|
1454
|
+
settled = true
|
|
1455
|
+
clearTimeout(timer)
|
|
1456
|
+
log.error(
|
|
1457
|
+
`Token REVOKE could not be confirmed durable (${message}) — the revoke HOLDS in this process, ` +
|
|
1458
|
+
`but a restart is not guaranteed to come back on the new token. Fix the storage error and revoke again.`,
|
|
1459
|
+
)
|
|
1460
|
+
// Send the operator DIAGNOSTIC first, then the revoke transition.
|
|
1461
|
+
//
|
|
1462
|
+
// Both, deliberately. The `error` envelope is the operator's report that
|
|
1463
|
+
// durability is unproven; `token_rotated{reason:'revoke'}` is the CLIENT
|
|
1464
|
+
// STATE TRANSITION — for the mobile app it is the sole automatic trigger
|
|
1465
|
+
// for clearing the now-dead credential and prompting re-auth (app
|
|
1466
|
+
// message-handler `case 'token_rotated'` with no token →
|
|
1467
|
+
// clearSavedConnection() + disconnect() + re-scan alert). `case 'error'`
|
|
1468
|
+
// shows an alert and touches neither the socket nor secure storage, so
|
|
1469
|
+
// withholding the transition left every connected device "connected" while
|
|
1470
|
+
// holding a REVOKED token with its server-side authority already stripped:
|
|
1471
|
+
// privileged ops failing opaquely, nothing prompting a re-pair.
|
|
1472
|
+
//
|
|
1473
|
+
// Sending it is not a false success: the message carries NO token and makes
|
|
1474
|
+
// NO durability claim. It says "this connection's authority is gone, you must
|
|
1475
|
+
// re-authenticate", which is TRUE here — enforcement above already ran,
|
|
1476
|
+
// unconditionally. The durability caveat rides the error, not this message.
|
|
1477
|
+
//
|
|
1478
|
+
// Diagnostic first because the transition tears the socket down client-side;
|
|
1479
|
+
// a frame queued after it can be dropped before the client reads it.
|
|
1480
|
+
for (const ws of forcedSockets) {
|
|
1481
|
+
if (ws.readyState !== 1) continue
|
|
1482
|
+
this._send(ws, {
|
|
1483
|
+
type: 'error',
|
|
1484
|
+
code: 'REVOKE_NOT_DURABLE',
|
|
1485
|
+
message:
|
|
1486
|
+
'Token revoke is enforced for the running daemon but its write could NOT be confirmed durable on disk — ' +
|
|
1487
|
+
'after a restart the daemon may come back on either the new token or the previous one. ' +
|
|
1488
|
+
'Resolve the storage error and revoke again.',
|
|
1489
|
+
})
|
|
1490
|
+
}
|
|
1491
|
+
sendRevokeAck()
|
|
1492
|
+
resolveAck({ ok: false, error: message })
|
|
1493
|
+
},
|
|
1494
|
+
)
|
|
1278
1495
|
return
|
|
1279
1496
|
}
|
|
1280
1497
|
|
|
@@ -1585,6 +1802,38 @@ export class WsServer {
|
|
|
1585
1802
|
log.debug(`Registered hook secret for session ${sessionId}`)
|
|
1586
1803
|
}
|
|
1587
1804
|
|
|
1805
|
+
/**
|
|
1806
|
+
* #6830 (PR #6842 review) — wire this server's PermissionAuditLog straight
|
|
1807
|
+
* into a session's persisted-rule audit path. Called from the
|
|
1808
|
+
* `session_created` handler AND the constructor's retroactive scan (same
|
|
1809
|
+
* dual wiring as _registerSessionHookSecretIfMissing, for the same #3716
|
|
1810
|
+
* restored-session reason).
|
|
1811
|
+
*
|
|
1812
|
+
* A persisted-rule auto-approve deliberately bypasses the whole
|
|
1813
|
+
* session-event pipeline: emitting `permission_resolved` for it would ride
|
|
1814
|
+
* ws-forwarding → broadcastToSession to every client on EVERY rule-matched
|
|
1815
|
+
* tool call (the PR #6842 review finding). The sink is a plain callback
|
|
1816
|
+
* into logPersistedRuleApproval, which also COALESCES repeats per
|
|
1817
|
+
* (sessionId, tool, projectKey) so the 500-entry ring is never flooded.
|
|
1818
|
+
*
|
|
1819
|
+
* The closure captures ONLY the audit log + sessionId — never `this` — so
|
|
1820
|
+
* a session outliving a retired WsServer pins a small ring buffer, not the
|
|
1821
|
+
* whole server (the #3060 concern that motivated the removable
|
|
1822
|
+
* session_event listeners). Single-slot on the manager side: a replacement
|
|
1823
|
+
* WsServer's attach overwrites this one (last writer wins).
|
|
1824
|
+
*
|
|
1825
|
+
* @param {string} sessionId
|
|
1826
|
+
* @param {object|null} entry - SessionManager entry ({ session, ... })
|
|
1827
|
+
*/
|
|
1828
|
+
_attachPermissionAuditSink(sessionId, entry) {
|
|
1829
|
+
const session = entry?.session
|
|
1830
|
+
if (typeof session?.setPermissionAuditSink !== 'function') return
|
|
1831
|
+
const audit = this._permissionAudit
|
|
1832
|
+
session.setPermissionAuditSink((info) => {
|
|
1833
|
+
audit.logPersistedRuleApproval({ sessionId, tool: info?.tool, projectKey: info?.projectKey ?? null })
|
|
1834
|
+
})
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1588
1837
|
/**
|
|
1589
1838
|
* Register a per-session hook secret so POST /permission accepts it.
|
|
1590
1839
|
* Called by session-manager when a CliSession is created.
|
|
@@ -1702,6 +1951,27 @@ export class WsServer {
|
|
|
1702
1951
|
}
|
|
1703
1952
|
}
|
|
1704
1953
|
|
|
1954
|
+
/**
|
|
1955
|
+
* #6540 — derive the public `…/api/github/webhook` payload URL an operator
|
|
1956
|
+
* pastes into GitHub, from the server's live origin. Prefers the tunnel URL
|
|
1957
|
+
* (public), then an operator-supplied external URL (SKIP_TUNNEL), then the LAN
|
|
1958
|
+
* address (flagged `lanOnly` — GitHub can't reach it, e.g. `--tunnel none`).
|
|
1959
|
+
* The derivation is a pure function (github-webhook.js); this just gathers the
|
|
1960
|
+
* live inputs. Surfaced to the config handler via `ctx.services.webhookPayloadUrl`.
|
|
1961
|
+
*
|
|
1962
|
+
* @returns {{ url: string|null, lanOnly: boolean, note: string|null }}
|
|
1963
|
+
*/
|
|
1964
|
+
getWebhookPayloadUrl() {
|
|
1965
|
+
return deriveWebhookPayloadUrl({
|
|
1966
|
+
tunnelUrl: this._tunnelUrl,
|
|
1967
|
+
externalUrl: this.config?.externalUrl,
|
|
1968
|
+
boundHost: this._boundHost,
|
|
1969
|
+
port: this.port,
|
|
1970
|
+
lanIp: getLanIp(),
|
|
1971
|
+
isLoopbackHost,
|
|
1972
|
+
})
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1705
1975
|
start(host) {
|
|
1706
1976
|
// #5356: remember what we bound. `undefined` means the default
|
|
1707
1977
|
// all-interfaces bind — record it as 0.0.0.0 so exposure reads true.
|
|
@@ -2105,6 +2375,11 @@ export class WsServer {
|
|
|
2105
2375
|
}, 60_000)
|
|
2106
2376
|
|
|
2107
2377
|
log.info(`Server listening on ${host || '0.0.0.0'}:${this.port} (${this.serverMode} mode)`)
|
|
2378
|
+
// #6822: point the MCP OAuth redirect at this daemon's loopback callback so a
|
|
2379
|
+
// desktop-local browser auto-completes the flow; remote/tunneled browsers
|
|
2380
|
+
// that can't reach loopback fall back to the paste-code path. An operator
|
|
2381
|
+
// override (CHROXY_MCP_OAUTH_REDIRECT_URI) still wins inside the module.
|
|
2382
|
+
try { setMcpOAuthCallbackBase(`http://127.0.0.1:${this.port}`) } catch { /* best-effort */ }
|
|
2108
2383
|
}
|
|
2109
2384
|
|
|
2110
2385
|
/**
|
|
@@ -2291,6 +2566,15 @@ export class WsServer {
|
|
|
2291
2566
|
)
|
|
2292
2567
|
}
|
|
2293
2568
|
|
|
2569
|
+
// #6691: push a single orchestration run delta to host-level (unbound) clients
|
|
2570
|
+
// only — runs are host-wide cross-session objects; a session-bound token never
|
|
2571
|
+
// receives them. Called by the OrchestrationManager (E-4); the `delta`
|
|
2572
|
+
// already carries its own type/runId/seq (schemas/server/orchestration.ts).
|
|
2573
|
+
_broadcastOrchestrationDelta(delta) {
|
|
2574
|
+
if (!delta) return
|
|
2575
|
+
this._broadcast(delta, (client) => !client.boundSessionId)
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2294
2578
|
/**
|
|
2295
2579
|
* #5510: deliver a terminal `pair_result` to the requester's still-open
|
|
2296
2580
|
* connection (if present) and drop the tracking entry. On approve the result
|