@chroxy/server 0.11.0 → 0.11.11
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 +206 -18
- package/README.md +2 -2
- package/hooks/claude-native-route-check.mjs +17 -0
- package/hooks/permission-hook.sh +166 -11
- package/package.json +16 -12
- package/sidecar/Dockerfile +1 -1
- package/sidecar/PROTOCOL.md +9 -1
- package/sidecar/agent.js +102 -10
- package/sidecar/package-lock.json +3 -3
- package/src/acp-config.js +206 -0
- package/src/acp-session.js +958 -0
- package/src/activity-registry.js +110 -5
- package/src/agent-connections.js +304 -0
- package/src/agent-control/client.js +1645 -0
- package/src/agent-control/events.js +551 -0
- package/src/agent-control/local-connection.js +293 -0
- package/src/agent-control/mcp-server.js +547 -0
- package/src/anthropic-compatible-config.js +30 -4
- package/src/anthropic-compatible-session.js +15 -6
- package/src/anthropic-gemini-shim.js +444 -0
- package/src/anthropic-gemini-translate.js +1030 -0
- package/src/anthropic-openai-shim.js +0 -1
- package/src/archive-continuation.js +164 -0
- package/src/assistant-response.js +24 -0
- package/src/auth-probes.js +120 -13
- package/src/background-shell-tracker.js +27 -0
- package/src/base-session.js +1520 -36
- package/src/bearer-recheck.js +49 -0
- package/src/billing-budget.js +19 -0
- package/src/billing-class.js +40 -7
- package/src/binary-provenance-trust.js +11 -5
- package/src/bound-client-policy.js +291 -0
- package/src/built-in-tools/bash-exec.js +46 -7
- package/src/built-in-tools/file-ops.js +69 -5
- package/src/built-in-tools/tool-transforms.js +1113 -13
- package/src/byok-compose-state.js +6 -9
- package/src/byok-credentials.js +2 -3
- package/src/byok-mcp-client.js +92 -7
- package/src/byok-mcp-config.js +633 -122
- package/src/byok-mcp-fleet.js +49 -7
- package/src/byok-mcp-oauth-store.js +18 -16
- package/src/byok-mcp-trust.js +37 -23
- package/src/byok-session.js +707 -179
- package/src/byok-tool-executor.js +2742 -26
- package/src/byok-tools.js +9 -2
- package/src/channels/chroxy-channel-server.js +2 -3
- package/src/checkpoint-manager.js +64 -46
- package/src/claude-channel-session.js +16 -10
- package/src/claude-model-catalog.js +131 -16
- package/src/claude-model-refresh.js +385 -0
- package/src/claude-model-request.js +103 -0
- package/src/claude-setting-sources.js +74 -0
- package/src/claude-stream-parser.js +53 -3
- package/src/claude-tui/diagnostic-tail.js +83 -0
- package/src/claude-tui/form-driver.js +44 -7
- package/src/claude-tui/model-error.js +41 -0
- package/src/claude-tui/pty-driver.js +215 -88
- package/src/claude-tui/sanitize-question-payload.js +109 -0
- package/src/claude-tui/usage-limit.js +239 -0
- package/src/claude-tui-session.js +3563 -284
- package/src/claude-tui-tool-response.js +300 -0
- package/src/cli/agent-cmd.js +236 -0
- package/src/cli/agent-control-cmd.js +65 -0
- package/src/cli/config-cmd.js +4 -4
- package/src/cli/config-dir-cmd.js +234 -0
- package/src/cli/connection-state.js +54 -0
- package/src/cli/deploy-cmd.js +45 -10
- package/src/cli/doctor-cmd.js +7 -3
- package/src/cli/freshness-cmd.js +53 -0
- package/src/cli/init-cmd.js +15 -16
- package/src/cli/pages-cmd.js +6 -4
- package/src/cli/pair-code-cmd.js +7 -6
- package/src/cli/pair-discord-cmd.js +7 -6
- package/src/cli/providers-cmd.js +3 -3
- package/src/cli/schedule-cmd.js +91 -40
- package/src/cli/server-cmd.js +54 -1
- package/src/cli/service-cmd.js +33 -10
- package/src/cli/session-cmd.js +227 -74
- package/src/cli/shared.js +162 -11
- package/src/cli/shell-cmd.js +7 -4
- package/src/cli/status-cmd.js +19 -5
- package/src/cli/tokens-cmd.js +4 -5
- package/src/cli/tunnel-cmd.js +255 -24
- package/src/cli/worktree-gc-cmd.js +2 -2
- package/src/cli-session.js +1250 -126
- package/src/cli.js +8 -0
- package/src/codex-app-server-client.js +36 -3
- package/src/codex-app-server-session.js +1517 -81
- package/src/codex-bundled-client.js +66 -0
- package/src/codex-error-text.js +114 -0
- package/src/codex-model-catalog.js +548 -0
- package/src/codex-model-rejections.js +87 -0
- package/src/codex-native-resume.js +104 -0
- package/src/codex-protocol-capabilities.js +188 -0
- package/src/codex-session.js +450 -27
- package/src/config-dir-migration.js +449 -0
- package/src/config-dir.js +108 -0
- package/src/config.js +306 -26
- package/src/connection-authority.js +48 -0
- package/src/connection-info.js +78 -23
- package/src/connection-locality.js +60 -0
- package/src/container-liveness-monitor.js +189 -0
- package/src/continuation-metadata-worker.js +17 -0
- package/src/continuations.js +227 -0
- package/src/control-room/host-prune.js +5 -0
- package/src/control-room/integrations.js +7 -20
- package/src/control-room/skills-inventory.js +2 -2
- package/src/conversation-scanner.js +42 -39
- package/src/conversation-scope.js +59 -39
- package/src/conversation-search.js +28 -39
- package/src/credential-store.js +23 -19
- package/src/daemon-commit.js +92 -0
- package/src/daemon-idle-state.js +171 -0
- package/src/daemon-update-status.js +314 -0
- package/src/dashboard-build.js +70 -0
- package/src/declared-status.js +90 -0
- package/src/deepseek-credentials.js +2 -3
- package/src/dev-preview.js +170 -182
- package/src/device-preferences.js +2 -2
- package/src/diff-parser.js +87 -0
- package/src/discord-credentials.js +2 -3
- package/src/docker-byok-pool.js +3 -1
- package/src/docker-byok-session.js +678 -78
- package/src/docker-image-allowlist.js +23 -1
- package/src/docker-sdk-session.js +172 -3
- package/src/docker-session.js +294 -11
- package/src/doctor.js +781 -64
- package/src/durable-write.js +35 -0
- package/src/edited-input.js +264 -0
- package/src/environment-manager.js +175 -36
- package/src/environments/authority.js +101 -0
- package/src/environments/backends/container-claude-spawn.js +94 -0
- package/src/environments/backends/docker.js +31 -10
- package/src/environments/backends/k8s.js +49 -24
- package/src/environments/destroy-with-sessions.js +142 -0
- package/src/event-ingest.js +118 -13
- package/src/event-normalizer.js +186 -235
- package/src/folder-trust-wire.js +137 -0
- package/src/folder-trust-worker.js +17 -0
- package/src/folder-trust.js +1572 -0
- package/src/freshness/activity-meter.js +101 -0
- package/src/freshness/adapter.js +199 -0
- package/src/freshness/checks.js +239 -0
- package/src/freshness/config.js +98 -0
- package/src/freshness/core.js +185 -0
- package/src/freshness/derive.js +680 -0
- package/src/freshness/exchange.js +305 -0
- package/src/freshness/file-ledger.js +400 -0
- package/src/freshness/grade.js +81 -0
- package/src/freshness/hash.js +45 -0
- package/src/freshness/inbox.js +163 -0
- package/src/freshness/index.js +20 -0
- package/src/freshness/investigation.js +474 -0
- package/src/freshness/keys.js +177 -0
- package/src/freshness/ledger.js +122 -0
- package/src/freshness/outbox.js +131 -0
- package/src/freshness/policy.js +599 -0
- package/src/freshness/queue.js +843 -0
- package/src/freshness/read-errors.js +23 -0
- package/src/freshness/render.js +153 -0
- package/src/freshness/runtime.js +113 -0
- package/src/freshness/session-registry-adapter.js +161 -0
- package/src/freshness/state-file-adapter.js +167 -0
- package/src/freshness-runner/build-info.js +139 -0
- package/src/freshness-runner/cli.js +105 -0
- package/src/freshness-runner/run-tick.js +109 -0
- package/src/freshness-runner/stamp.js +57 -0
- package/src/freshness-sources/claude-transcript-adapter.js +211 -0
- package/src/freshness-sources/codex-transcript-adapter.js +33 -0
- package/src/freshness-sources/index.js +8 -0
- package/src/gemini-byok-session.js +292 -0
- package/src/gemini-credentials.js +67 -0
- package/src/gemini-key-safety.js +246 -0
- package/src/gemini-models.js +386 -0
- package/src/gemini-session.js +81 -5
- package/src/handler-utils.js +540 -80
- package/src/handlers/checkpoint-handlers.js +47 -4
- package/src/handlers/control-room-handlers.js +51 -11
- package/src/handlers/conversation-handlers.js +469 -56
- package/src/handlers/daemon-update-handlers.js +81 -0
- package/src/handlers/evaluator-handlers.js +14 -1
- package/src/handlers/feature-handlers.js +186 -69
- package/src/handlers/file-handlers.js +57 -13
- package/src/handlers/folder-trust-handlers.js +90 -0
- package/src/handlers/input-handlers.js +714 -48
- package/src/handlers/orchestration-handlers.js +3 -3
- package/src/handlers/principal-admin-handlers.js +229 -0
- package/src/handlers/principal-handlers.js +262 -0
- package/src/handlers/scheduler-handlers.js +92 -18
- package/src/handlers/session-handlers.js +551 -20
- package/src/handlers/session-pr-status-handlers.js +283 -0
- package/src/handlers/session-pr-threads-handlers.js +247 -0
- package/src/handlers/settings-handlers.js +372 -50
- package/src/handlers/skills-handlers.js +20 -4
- package/src/handlers/summarize-handlers.js +32 -1
- package/src/handlers/survey-throttle.js +380 -0
- package/src/health-proof.js +40 -0
- package/src/history-page.js +112 -0
- package/src/http-routes.js +127 -8
- package/src/ide/search.js +24 -6
- package/src/ide/symbols.js +20 -6
- package/src/input-context.js +117 -0
- package/src/instruction-policy-compiler.js +229 -0
- package/src/instruction-policy.js +250 -0
- package/src/jsonl-reader.js +378 -91
- package/src/jsonl-subprocess-session.js +96 -9
- package/src/keychain.js +1 -1
- package/src/logger.js +166 -30
- package/src/mailbox-route.js +113 -22
- package/src/message-wire.js +386 -0
- package/src/model-discovery.js +43 -3
- package/src/models.js +1276 -174
- package/src/notification-prefs.js +27 -4
- package/src/notifications/discord-billing-sink.js +22 -5
- package/src/notifications/discord-ci-sink.js +243 -0
- package/src/notifications/discord-webhook-client.js +71 -0
- package/src/notifications/discord-webhook-sink.js +64 -23
- package/src/notifications/expo-push-sink.js +85 -6
- package/src/notifications/ready-body.js +16 -5
- package/src/ollama-session.js +34 -2
- package/src/orchestration/build-manager.js +9 -2
- package/src/orchestration/git-ops.js +41 -7
- package/src/orchestration/orchestration-manager.js +112 -36
- package/src/orchestration/permission-gate.js +17 -2
- package/src/orchestration/run-model.js +2 -1
- package/src/orchestration/run-record.js +11 -0
- package/src/orchestration/turn-driver.js +185 -43
- package/src/orphan-reaper.js +470 -0
- package/src/outgoing-policy.js +189 -0
- package/src/pairing.js +92 -13
- package/src/path-hash-trust-ledger.js +642 -25
- package/src/permission-deadlines.js +82 -0
- package/src/permission-floor.js +1410 -43
- package/src/permission-hook.js +180 -69
- package/src/permission-manager.js +737 -89
- package/src/permission-mode-support.js +35 -0
- package/src/permission-resolved-by.js +89 -0
- package/src/permission-resolver.js +126 -8
- package/src/permission-scope.js +43 -0
- package/src/platform.js +315 -47
- package/src/preview-ingress.js +54 -0
- package/src/preview-target.js +213 -0
- package/src/principal-audit.js +189 -0
- package/src/principal-binding.js +25 -0
- package/src/principal-brakes.js +21 -0
- package/src/principal-effect.js +101 -0
- package/src/principal-journal.js +905 -0
- package/src/principal-kill-switch.js +183 -0
- package/src/principal-label.js +5 -0
- package/src/principal-pending-permissions.js +177 -0
- package/src/principal-policy.js +1094 -0
- package/src/principal-sessions-snapshot.js +208 -0
- package/src/principal-store.js +488 -0
- package/src/principal-subscriptions.js +283 -0
- package/src/prompt-evaluator.js +34 -4
- package/src/provider-customization.js +180 -0
- package/src/providers.js +209 -4
- package/src/push.js +30 -4
- package/src/question-route-map.js +130 -0
- package/src/redaction.js +531 -20
- package/src/roster-broadcast.js +186 -0
- package/src/scheduled-task-store.js +330 -26
- package/src/scheduler.js +368 -11
- package/src/sdk-session.js +2114 -188
- package/src/server-cli/preview-shutdown.js +22 -0
- package/src/server-cli/push-notification-handler.js +17 -3
- package/src/server-cli/server-orchestrator.js +28 -5
- package/src/server-cli-child.js +33 -18
- package/src/server-cli.js +553 -38
- package/src/server-identity.js +15 -11
- package/src/service.js +396 -25
- package/src/session-archive-limits.js +15 -0
- package/src/session-archive.js +1029 -0
- package/src/session-busy-state.js +72 -0
- package/src/session-ci-watcher.js +1099 -0
- package/src/session-context.js +7 -2
- package/src/session-manager.js +4062 -312
- package/src/session-message-history.js +841 -16
- package/src/session-name-allocator.js +685 -0
- package/src/session-pr-status.js +654 -0
- package/src/session-pr-threads.js +271 -0
- package/src/session-preset-trust.js +3 -3
- package/src/session-preset.js +10 -5
- package/src/session-state-persistence.js +94 -17
- package/src/session-timeout-manager.js +20 -0
- package/src/session-token-store.js +17 -8
- package/src/session-wake.js +240 -0
- package/src/shell-approval-info.js +2 -2
- package/src/shell-approval-store.js +3 -1
- package/src/skills-loader.js +7 -4
- package/src/skills-manager.js +2 -2
- package/src/skills-trust.js +95 -13
- package/src/skills-usage.js +2 -3
- package/src/snapshots-store.js +2 -3
- package/src/statusline.js +100 -29
- package/src/summarize-session.js +53 -4
- package/src/supervisor.js +22 -11
- package/src/sweep-stale-provider-dirs.js +95 -0
- package/src/thinking-level-wire.js +39 -0
- package/src/thinking-stream.js +179 -0
- package/src/tool-result.js +61 -0
- package/src/transcript-sources.js +109 -0
- package/src/transcript-tasks.js +372 -25
- package/src/trusted-file-read.js +302 -0
- package/src/tunnel/base.js +0 -8
- package/src/tunnel/cloudflare.js +34 -31
- package/src/tunnel/index.js +9 -0
- package/src/tunnel/preview.js +64 -0
- package/src/turn-outcome.js +140 -0
- package/src/usage-normalize.js +9 -5
- package/src/user-shell-session.js +59 -5
- package/src/utils/agent-sdk-version.js +107 -0
- package/src/utils/argv-safety.js +770 -0
- package/src/utils/auth-cause.js +60 -0
- package/src/utils/binary-package-manifest.js +639 -0
- package/src/utils/binary-version.js +224 -0
- package/src/utils/bounded-regex-worker.js +29 -0
- package/src/utils/bounded-regex.js +162 -0
- package/src/utils/claude-binary.js +43 -0
- package/src/utils/claude-config-dir.js +245 -0
- package/src/utils/claude-login-command.js +16 -0
- package/src/utils/claude-native-route.js +81 -0
- package/src/utils/componentwise-resolver.js +133 -37
- package/src/utils/deploy-control-files.js +87 -0
- package/src/utils/exec-failure-reason.js +21 -0
- package/src/utils/git-repo.js +42 -0
- package/src/utils/is-entry-point.js +137 -0
- package/src/utils/node-pty-probe.js +95 -0
- package/src/utils/node-pty-support.js +118 -0
- package/src/utils/opened-file-path.js +167 -0
- package/src/utils/path-containment.js +165 -0
- package/src/utils/permission-mode-sidecar.js +51 -0
- package/src/utils/pid-liveness.js +47 -0
- package/src/utils/preflight.js +360 -16
- package/src/utils/read-limiter.js +217 -0
- package/src/utils/regular-file.js +375 -0
- package/src/utils/safe-regex.js +113 -0
- package/src/utils/small-file.js +129 -0
- package/src/utils/spawn-env.js +189 -4
- package/src/utils/stale-session-dirs.js +182 -0
- package/src/utils/stat-identity.js +43 -0
- package/src/utils/verify-provenance.js +406 -13
- package/src/web-task-manager.js +297 -16
- package/src/worktree-gc.js +202 -6
- package/src/ws-auth.js +163 -31
- package/src/ws-broadcaster.js +49 -5
- package/src/ws-client-manager.js +24 -1
- package/src/ws-client-sender.js +7 -0
- package/src/ws-file-ops/browser.js +363 -58
- package/src/ws-file-ops/common.js +320 -14
- package/src/ws-file-ops/git.js +395 -42
- package/src/ws-file-ops/index.js +2 -0
- package/src/ws-file-ops/memory.js +137 -35
- package/src/ws-file-ops/open-nofollow.js +354 -0
- package/src/ws-file-ops/reader.js +571 -113
- package/src/ws-forwarding.js +349 -39
- package/src/ws-handler-context.js +88 -2
- package/src/ws-history.js +1010 -175
- package/src/ws-message-handlers.js +25 -1
- package/src/ws-permissions.js +307 -37
- package/src/ws-schemas.js +5 -0
- package/src/ws-server.js +885 -98
- package/sidecar/node_modules/.package-lock.json +0 -29
- package/sidecar/node_modules/ws/LICENSE +0 -20
- package/sidecar/node_modules/ws/README.md +0 -548
- package/sidecar/node_modules/ws/browser.js +0 -8
- package/sidecar/node_modules/ws/index.js +0 -22
- package/sidecar/node_modules/ws/lib/buffer-util.js +0 -131
- package/sidecar/node_modules/ws/lib/constants.js +0 -19
- package/sidecar/node_modules/ws/lib/event-target.js +0 -292
- package/sidecar/node_modules/ws/lib/extension.js +0 -203
- package/sidecar/node_modules/ws/lib/limiter.js +0 -55
- package/sidecar/node_modules/ws/lib/permessage-deflate.js +0 -528
- package/sidecar/node_modules/ws/lib/receiver.js +0 -706
- package/sidecar/node_modules/ws/lib/sender.js +0 -602
- package/sidecar/node_modules/ws/lib/stream.js +0 -161
- package/sidecar/node_modules/ws/lib/subprotocol.js +0 -62
- package/sidecar/node_modules/ws/lib/validation.js +0 -152
- package/sidecar/node_modules/ws/lib/websocket-server.js +0 -554
- package/sidecar/node_modules/ws/lib/websocket.js +0 -1393
- package/sidecar/node_modules/ws/package.json +0 -70
- package/sidecar/node_modules/ws/wrapper.mjs +0 -21
- package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +0 -111
- package/src/dashboard-next/dist/assets/index-DM-_dISG.css +0 -1
- package/src/dashboard-next/dist/index.html +0 -13
- package/src/dashboard-next/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
package/src/ws-forwarding.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { ServerSessionStatusSchema, ServerActivityDeltaSchema } from '@chroxy/protocol'
|
|
1
2
|
import { createLogger } from './logger.js'
|
|
2
|
-
import {
|
|
3
|
+
import { getRegistryForProvider, resolveRosterProvider } from './models.js'
|
|
3
4
|
import { settlePush } from './push.js'
|
|
4
5
|
import { terminalMirrorRecipient } from './handler-utils.js'
|
|
6
|
+
import { isBoundClient } from './environments/authority.js'
|
|
7
|
+
import { broadcastRosterPerRecipient } from './roster-broadcast.js'
|
|
8
|
+
import { getProviderRuntimeInfo } from './providers.js'
|
|
9
|
+
import { buildFolderTrustStateMessageForDisplay, noteFolderTrustFrame } from './folder-trust-wire.js'
|
|
10
|
+
import { MODEL_UNSUPPORTED_CODE } from './codex-model-rejections.js'
|
|
5
11
|
|
|
6
12
|
const log = createLogger('ws-forwarding')
|
|
7
13
|
|
|
@@ -142,7 +148,81 @@ function terminalSubscriberFilter(sessionId) {
|
|
|
142
148
|
|
|
143
149
|
/** Multi-session forwarding via normalizer */
|
|
144
150
|
function setupSessionForwarding(normalizer, ctx) {
|
|
145
|
-
const { sessionManager, devPreview, checkpointManager, broadcast, broadcastToSession } = ctx
|
|
151
|
+
const { sessionManager, devPreview, checkpointManager, broadcast, broadcastToSession, defaultProvider = null } = ctx
|
|
152
|
+
|
|
153
|
+
// #8497: sessions whose turn a `result` ended in the CURRENT synchronous turn
|
|
154
|
+
// end. A provider that finishes a requested Stop with a `result` and then a
|
|
155
|
+
// `stopped` (claude-cli) emits both back to back in one call stack, so the
|
|
156
|
+
// `stopped` that follows must not announce idle a second time. Cleared on a
|
|
157
|
+
// microtask rather than on the next stream_start: a Stop pressed before the
|
|
158
|
+
// next turn produced any output forwards nothing in between, and a flag that
|
|
159
|
+
// outlived the tick would swallow that turn's idle (the stuck-busy bug this
|
|
160
|
+
// exists to fix). The failure mode of the tick scope is a repeated idle, which
|
|
161
|
+
// is idempotent on every client; the failure mode of a longer scope is a
|
|
162
|
+
// session that stays busy forever.
|
|
163
|
+
const idledByResultThisTick = new Set()
|
|
164
|
+
|
|
165
|
+
// #8502: sessions whose turn-end `session_list` is already queued for this
|
|
166
|
+
// synchronous turn end. A `result` and a `stopped` that coincide (claude-sdk's
|
|
167
|
+
// quiet acknowledgement of a Stop, claude-cli's close handler) share ONE list.
|
|
168
|
+
const turnEndListQueued = new Set()
|
|
169
|
+
|
|
170
|
+
// The `session_list` a turn end refreshes, built AFTER the provider's
|
|
171
|
+
// synchronous teardown rather than inside the emit. claude-sdk, ACP and Codex
|
|
172
|
+
// app-server emit `result` / `stopped` and only then clear `_isBusy`
|
|
173
|
+
// (_clearMessageState), so a list built inside the emit publishes the finished
|
|
174
|
+
// session as busy. `agent_idle` reaches viewers only, and the clients re-derive
|
|
175
|
+
// `isIdle` from this list's rows, so a client that is not viewing the session
|
|
176
|
+
// would end the turn busy. A microtask runs once the emitting call stack
|
|
177
|
+
// unwinds and before any later await; the providers clear busy synchronously in
|
|
178
|
+
// that same stack (checked per provider in #8502).
|
|
179
|
+
//
|
|
180
|
+
// `afterBusyCleared` marks the list the provider itself asked for once its busy
|
|
181
|
+
// window really ended (`busy_cleared`). Every other trigger is skipped while the
|
|
182
|
+
// session reports `busyClearedOwed`: its busy flag outlives the `result` (the
|
|
183
|
+
// jsonl-subprocess family clears it in the child's close handler, a later
|
|
184
|
+
// event-loop turn), so a list built now would publish the finished session as
|
|
185
|
+
// busy AFTER the viewer's agent_idle, and the clients, which re-derive isIdle
|
|
186
|
+
// from the list row even for the active session, would flip back to Working
|
|
187
|
+
// until the child exits. The session states this itself; it is not guessed
|
|
188
|
+
// from `isRunning`, which is also true for a restarted queued turn and for
|
|
189
|
+
// background shells, where the list is correct and wanted.
|
|
190
|
+
const queueTurnEndSessionList = (sessionId, { afterBusyCleared = false } = {}) => {
|
|
191
|
+
if (turnEndListQueued.has(sessionId)) return
|
|
192
|
+
turnEndListQueued.add(sessionId)
|
|
193
|
+
queueMicrotask(() => {
|
|
194
|
+
turnEndListQueued.delete(sessionId)
|
|
195
|
+
if (!afterBusyCleared && sessionManager.getSession?.(sessionId)?.session?.busyClearedOwed === true) return
|
|
196
|
+
try {
|
|
197
|
+
executeSideEffects([{ type: 'session_list' }], sessionId, ctx)
|
|
198
|
+
} catch (err) {
|
|
199
|
+
log.error(`deferred session_list after turn end threw for session ${sessionId}: ${err?.message || err}`)
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// #8873: the `session_list` a provider start's outcome refreshes
|
|
205
|
+
// (`session_restore_failed`, `session_start_settled`), coalesced so a burst of
|
|
206
|
+
// outcomes costs one `listSessions()` and one send per client rather than one
|
|
207
|
+
// each. Restored sessions start together at boot, so their failures (and the
|
|
208
|
+
// #8876 deadline timers) arrive together. They arrive as separate timer or I/O
|
|
209
|
+
// callbacks, and Node drains microtasks between callbacks, so a microtask
|
|
210
|
+
// would coalesce only outcomes emitted in one call stack. `setImmediate` runs
|
|
211
|
+
// once per event-loop turn, after every callback of that turn. The list is
|
|
212
|
+
// built when it fires, so it reflects every outcome in the burst.
|
|
213
|
+
let startOutcomeListQueued = false
|
|
214
|
+
const queueStartOutcomeSessionList = () => {
|
|
215
|
+
if (!ctx.broadcastSessionList || startOutcomeListQueued) return
|
|
216
|
+
startOutcomeListQueued = true
|
|
217
|
+
setImmediate(() => {
|
|
218
|
+
startOutcomeListQueued = false
|
|
219
|
+
try {
|
|
220
|
+
ctx.broadcastSessionList()
|
|
221
|
+
} catch (err) {
|
|
222
|
+
log.error(`deferred session_list after a provider start outcome threw: ${err?.message || err}`)
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
}
|
|
146
226
|
|
|
147
227
|
sessionManager.on('session_event', ({ sessionId, event, data }) => {
|
|
148
228
|
// #5313 (WP-1.3): this listener runs synchronously inside the
|
|
@@ -152,30 +232,54 @@ function setupSessionForwarding(normalizer, ctx) {
|
|
|
152
232
|
// Contain it: wrap the body, log with the session id, and swallow so a
|
|
153
233
|
// single malformed event can't bring down the process.
|
|
154
234
|
try {
|
|
155
|
-
// models_updated is global —
|
|
235
|
+
// models_updated is global — not scoped to viewers of one session (unlike
|
|
236
|
+
// broadcastToSession). #7895: it is no longer sent to every client
|
|
237
|
+
// unconditionally either — broadcastRosterPerRecipient fans it out so
|
|
238
|
+
// each connected client receives it only when the tag names a registry
|
|
239
|
+
// their own active session actually uses (see that function's docstring,
|
|
240
|
+
// ./roster-broadcast.js, for the exact per-tag recipient rule).
|
|
156
241
|
// Look up the session's provider so clients receive the provider-scoped
|
|
157
242
|
// defaultModel rather than the Claude-only global. Falls back to the
|
|
158
|
-
//
|
|
159
|
-
// destroyed)
|
|
160
|
-
//
|
|
243
|
+
// daemon's resolved default when the session is not found (e.g. already
|
|
244
|
+
// destroyed) — same resolution `ws-history.js`'s connect path uses
|
|
245
|
+
// (`resolveRosterProvider`), so a roster this event produces is tagged the
|
|
246
|
+
// same way whether a client learns of it via reconnect or via this live
|
|
247
|
+
// push. (#2993)
|
|
248
|
+
//
|
|
249
|
+
// #7895 — this used to hardcode the fallback tag to `'claude-sdk'` and
|
|
250
|
+
// broadcast ONE message. A claude-cli/claude-tui/claude-byok client keys
|
|
251
|
+
// its roster by the EXACT tag it arrives under
|
|
252
|
+
// (`packages/store-core/src/models-by-provider.ts`), so that single
|
|
253
|
+
// `claude-sdk`-tagged message was delivered and discarded by every other
|
|
254
|
+
// Claude-family client — the same #7756 bug the overlay-reload path was
|
|
255
|
+
// fixed for. `broadcastRosterPerRecipient` (`./roster-broadcast.js`) is
|
|
256
|
+
// that same per-recipient re-tagging, shared rather than re-implemented a
|
|
257
|
+
// third time: a default-registry roster is re-sent once per known
|
|
258
|
+
// Claude-family tag, each copy filtered to the clients that resolve to it;
|
|
259
|
+
// a non-Claude roster (codex, gemini, …) is sent once, unchanged, to its
|
|
260
|
+
// exact-match clients only — untouched from pre-#7895 behaviour.
|
|
161
261
|
if (event === 'models_updated' && data?.models) {
|
|
162
262
|
const sessionEntry = sessionManager.getSession(sessionId)
|
|
163
263
|
const providerName = sessionEntry?.provider ?? null
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
264
|
+
const rosterProvider = resolveRosterProvider(providerName, defaultProvider)
|
|
265
|
+
// getRegistryForProvider never returns a falsy value (unknown/null names
|
|
266
|
+
// fall back to defaultRegistry), and resolveRosterProvider never returns
|
|
267
|
+
// a falsy tag either — so this always resolves to a real registry.
|
|
268
|
+
const defaultModel = getRegistryForProvider(rosterProvider).getDefaultModelId()
|
|
269
|
+
broadcastRosterPerRecipient({
|
|
270
|
+
broadcast,
|
|
271
|
+
sessionManager,
|
|
272
|
+
defaultProvider,
|
|
273
|
+
message: { type: 'available_models', models: data.models, defaultModel, provider: rosterProvider },
|
|
274
|
+
})
|
|
172
275
|
return
|
|
173
276
|
}
|
|
174
277
|
|
|
175
278
|
// #5665: monthly programmatic-credit meter is machine-wide — broadcast to
|
|
176
279
|
// ALL authenticated clients, not per-session.
|
|
177
280
|
if (event === 'monthly_budget') {
|
|
178
|
-
|
|
281
|
+
// The host's spend meter: not for a session-scoped connection.
|
|
282
|
+
broadcast({ type: 'monthly_budget', ...data }, (client) => !isBoundClient(client))
|
|
179
283
|
return
|
|
180
284
|
}
|
|
181
285
|
|
|
@@ -206,26 +310,105 @@ function setupSessionForwarding(normalizer, ctx) {
|
|
|
206
310
|
return
|
|
207
311
|
}
|
|
208
312
|
|
|
209
|
-
//
|
|
210
|
-
|
|
313
|
+
// #8301: a DAEMON-authored user turn (the CI-completion wake, recorded by
|
|
314
|
+
// SessionManager.recordDaemonUserInput). Same wire shape input-handlers.js
|
|
315
|
+
// broadcasts for a typed input, minus `clientId` — there is no sending
|
|
316
|
+
// client, so every viewer of the session renders it. Transient here: the
|
|
317
|
+
// history entry was recorded at the source, which is what a reconnecting
|
|
318
|
+
// client replays. Not routed through the normalizer — like terminal_output
|
|
319
|
+
// above, it is a straight relay with no per-provider shape to normalise.
|
|
320
|
+
if (event === 'user_input') {
|
|
321
|
+
broadcastToSession(sessionId, {
|
|
322
|
+
type: 'user_input',
|
|
323
|
+
sessionId,
|
|
324
|
+
text: typeof data?.text === 'string' ? data.text : '',
|
|
325
|
+
messageId: data?.messageId,
|
|
326
|
+
timestamp: typeof data?.timestamp === 'number' ? data.timestamp : Date.now(),
|
|
327
|
+
// The daemon wrote this turn, not a person. Optional and additive: an
|
|
328
|
+
// older client ignores it and renders the bubble as it always did.
|
|
329
|
+
...(data?.source === 'daemon' ? { source: 'daemon' } : {}),
|
|
330
|
+
})
|
|
331
|
+
return
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// #8502: a provider whose `result` precedes the end of its busy window (the
|
|
335
|
+
// jsonl-subprocess family: the child is still exiting when the result line is
|
|
336
|
+
// parsed) says so when busy actually clears. Nothing to normalise or relay to
|
|
337
|
+
// a viewer: it exists to refresh the list the clients re-derive busy from.
|
|
338
|
+
if (event === 'busy_cleared') {
|
|
339
|
+
queueTurnEndSessionList(sessionId, { afterBusyCleared: true })
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Sidebar activity feed: lightweight status broadcast to ALL authenticated clients.
|
|
344
|
+
// #7393: not for a `late` thinking stream_start (claude-tui shows a reasoning
|
|
345
|
+
// block that reached the transcript after its turn's `result`). That is a
|
|
346
|
+
// finished turn being decorated, not the session starting work, and nothing
|
|
347
|
+
// would send idle again until the next `result`.
|
|
348
|
+
if (event === 'stream_start' && data?.late !== true) {
|
|
211
349
|
broadcast({ type: 'session_activity', sessionId, isBusy: true, lastCost: null })
|
|
212
350
|
} else if (event === 'result') {
|
|
213
351
|
broadcast({ type: 'session_activity', sessionId, isBusy: false, lastCost: data?.cost ?? null })
|
|
352
|
+
idledByResultThisTick.add(sessionId)
|
|
353
|
+
queueMicrotask(() => idledByResultThisTick.delete(sessionId))
|
|
354
|
+
queueTurnEndSessionList(sessionId)
|
|
214
355
|
}
|
|
215
356
|
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
357
|
+
// #8497: a requested Stop ends the turn with `stopped` and, on most
|
|
358
|
+
// providers (ACP, Codex app-server, the jsonl-subprocess family), NO
|
|
359
|
+
// `result`. Both clients leave busy on `agent_idle` / `session_activity`,
|
|
360
|
+
// which only a `result` produced, so those sessions stayed busy for good.
|
|
361
|
+
// Announcing idle here covers every provider at the one place they all meet
|
|
362
|
+
// the wire, and `stopped` stays the quiet confirmation. #9241: BaseSession.emit
|
|
363
|
+
// now mints a `result` carrying the `stopped_before_output` marker ahead of a
|
|
364
|
+
// `stopped` for a Stop that came before any output, and that result idles the
|
|
365
|
+
// client first (`idledByResultThisTick`); every other requested Stop still has no
|
|
366
|
+
// `result`, so no chip. Skipped when the same turn end already went idle through
|
|
367
|
+
// a `result`.
|
|
368
|
+
let announceIdle = false
|
|
369
|
+
if (event === 'stopped' && !idledByResultThisTick.has(sessionId)) {
|
|
370
|
+
announceIdle = true
|
|
371
|
+
broadcast({ type: 'session_activity', sessionId, isBusy: false, lastCost: null })
|
|
219
372
|
}
|
|
373
|
+
// Every turn end refreshes the list, including a `stopped` the idle frames
|
|
374
|
+
// were deduped against: the `result` that deduped it queued the list, and the
|
|
375
|
+
// queue is idempotent per synchronous turn end.
|
|
376
|
+
if (event === 'stopped') queueTurnEndSessionList(sessionId)
|
|
377
|
+
// A turn can also end with only an `error` (an SDK query that threw, a BYOK
|
|
378
|
+
// `_emitTurnError`, ACP / Codex `_failTurn`): no `result`, no `stopped`, so no
|
|
379
|
+
// agent_idle or idle ping, and the clients leave busy on nothing else. The
|
|
380
|
+
// list is the one signal left. An `error` that does not end a turn costs one
|
|
381
|
+
// list that reports the session's true state, which is still busy.
|
|
382
|
+
if (event === 'error') queueTurnEndSessionList(sessionId)
|
|
220
383
|
|
|
221
384
|
const normCtx = {
|
|
222
385
|
sessionId,
|
|
223
386
|
mode: 'multi',
|
|
224
387
|
getSessionEntry: () => sessionManager.getSession(sessionId),
|
|
388
|
+
announceIdle,
|
|
225
389
|
}
|
|
226
390
|
const result = normalizer.normalize(event, data, normCtx)
|
|
227
391
|
if (!result) return
|
|
228
392
|
|
|
393
|
+
// #7745/#7835: creation/subscription can replay before an async provider
|
|
394
|
+
// handshake and project-policy compilation finish. Ready is the first
|
|
395
|
+
// generic event after those facts settle, so refresh the same bounded
|
|
396
|
+
// session-scoped snapshot used by sendSessionInfo. This is deliberately a
|
|
397
|
+
// separate frame: existing ready and boolean capability semantics stay
|
|
398
|
+
// unchanged, while the creating tab converges without a reselect.
|
|
399
|
+
if (event === 'ready') {
|
|
400
|
+
const entry = sessionManager.getSession(sessionId)
|
|
401
|
+
if (entry?.session) {
|
|
402
|
+
result.messages.push({
|
|
403
|
+
msg: {
|
|
404
|
+
type: 'provider_runtime_info',
|
|
405
|
+
sessionId,
|
|
406
|
+
...getProviderRuntimeInfo(entry.provider, entry.session),
|
|
407
|
+
},
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
229
412
|
// Handle delta buffering
|
|
230
413
|
if (result.buffer) {
|
|
231
414
|
// #6818: forward the thinking flag so the coalesced frame reconstructs as
|
|
@@ -235,18 +418,74 @@ function setupSessionForwarding(normalizer, ctx) {
|
|
|
235
418
|
}
|
|
236
419
|
|
|
237
420
|
// Execute side effects before messages (flush_deltas must happen before stream_end broadcast)
|
|
238
|
-
|
|
421
|
+
// #8502: a `result`'s own `session_list` is the queued turn-end one (above),
|
|
422
|
+
// built after the provider's teardown. Running it here too would publish the
|
|
423
|
+
// stale busy row first and a second list straight after it.
|
|
424
|
+
executeSideEffects(
|
|
425
|
+
event === 'result' ? result.sideEffects?.filter((effect) => effect.type !== 'session_list') : result.sideEffects,
|
|
426
|
+
sessionId,
|
|
427
|
+
ctx,
|
|
428
|
+
)
|
|
239
429
|
executeRegistrations(result.registrations, sessionId, ctx)
|
|
240
430
|
|
|
241
431
|
// Broadcast messages
|
|
242
432
|
for (const { msg, filter } of result.messages) {
|
|
243
433
|
const stamped = withServerTs(msg)
|
|
244
|
-
|
|
434
|
+
// Bounded session attention is visible with the session roster, even
|
|
435
|
+
// when the operator is viewing another session. The broadcaster retains
|
|
436
|
+
// its central bound-session recipient check. All other work stays scoped.
|
|
437
|
+
if (msg.type === 'session_status') {
|
|
438
|
+
const parsed = ServerSessionStatusSchema.safeParse({ ...stamped, sessionId })
|
|
439
|
+
if (parsed.success) broadcast(parsed.data)
|
|
440
|
+
} else if (msg.type === 'activity_delta' && msg.entry?.id === 'decision:session' && msg.entry?.kind === 'decision') {
|
|
441
|
+
const parsed = ServerActivityDeltaSchema.safeParse({ ...stamped, sessionId })
|
|
442
|
+
if (parsed.success && parsed.data.entry.label.length <= 280) {
|
|
443
|
+
const { id, kind, label, status, startedAt, endedAt } = parsed.data.entry
|
|
444
|
+
broadcast({ ...parsed.data, entry: { id, kind, label, status, startedAt, ...(endedAt !== undefined ? { endedAt } : {}) } })
|
|
445
|
+
}
|
|
446
|
+
} else if (filter) {
|
|
245
447
|
broadcastToSession(sessionId, stamped, filter)
|
|
246
448
|
} else {
|
|
247
449
|
broadcastToSession(sessionId, stamped)
|
|
248
450
|
}
|
|
249
451
|
}
|
|
452
|
+
|
|
453
|
+
// #8909: a backend model refusal changes the ledger every session on the same
|
|
454
|
+
// codex client reads live, so resend each same-provider session's runtime frame
|
|
455
|
+
// (this one included) and let its picker disable the model. After the event's
|
|
456
|
+
// own messages, so the error reaches clients first. One failing session must
|
|
457
|
+
// not stop the rest, and a failure to enumerate sessions must not abort the
|
|
458
|
+
// rest of this listener, including the afterEffects step below.
|
|
459
|
+
if (event === 'error' && data?.code === MODEL_UNSUPPORTED_CODE) {
|
|
460
|
+
try {
|
|
461
|
+
const provider = sessionManager.getSession(sessionId)?.provider
|
|
462
|
+
const rows = provider ? sessionManager.listSessions() || [] : []
|
|
463
|
+
for (const row of rows) {
|
|
464
|
+
const sid = row?.sessionId
|
|
465
|
+
if (!sid) continue
|
|
466
|
+
try {
|
|
467
|
+
const peer = sessionManager.getSession(sid)
|
|
468
|
+
if (!peer?.session || peer.provider !== provider) continue
|
|
469
|
+
broadcastToSession(sid, withServerTs({
|
|
470
|
+
type: 'provider_runtime_info',
|
|
471
|
+
sessionId: sid,
|
|
472
|
+
...getProviderRuntimeInfo(peer.provider, peer.session),
|
|
473
|
+
}))
|
|
474
|
+
} catch (err) {
|
|
475
|
+
log.error(`provider_runtime_info refresh after model rejection failed for session ${sid}: ${err?.message || err}`)
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
} catch (err) {
|
|
479
|
+
log.error(`provider_runtime_info refresh after model rejection failed: ${err?.message || err}`)
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// #7379: AFTER the broadcast, deliberately. Releasing a permission runs
|
|
484
|
+
// ws-permissions' cleanup() -> tearDownRoute, which unsubscribes the
|
|
485
|
+
// permission-induced viewers of this session — so anything released here
|
|
486
|
+
// must already have been told. Same executor as sideEffects so the two
|
|
487
|
+
// buckets can never grow divergent handling.
|
|
488
|
+
executeSideEffects(result.afterEffects, sessionId, ctx)
|
|
250
489
|
} catch (err) {
|
|
251
490
|
// #5313 (WP-1.3): see the try at the top of this listener.
|
|
252
491
|
const message = err?.message || String(err)
|
|
@@ -265,6 +504,20 @@ function setupSessionForwarding(normalizer, ctx) {
|
|
|
265
504
|
// (#2954). History stays on disk; client shows a retry affordance.
|
|
266
505
|
sessionManager.on('session_restore_failed', safeForward('session_restore_failed', (payload) => {
|
|
267
506
|
broadcast({ type: 'session_restore_failed', ...payload })
|
|
507
|
+
// #8861 / #8092: a session re-parked after an ASYNC start failure was already
|
|
508
|
+
// in the last `session_list` (it was live when that went out), and the
|
|
509
|
+
// restore-branch teardown in `_handleAsyncStartFailure` never emits
|
|
510
|
+
// `session_destroyed`, so without a refresh every client's sidebar keeps a
|
|
511
|
+
// clickable entry for a session that no longer exists ("Session not found").
|
|
512
|
+
// Re-sending the list is what removes it.
|
|
513
|
+
queueStartOutcomeSessionList()
|
|
514
|
+
}))
|
|
515
|
+
|
|
516
|
+
// #8872: a session whose async start() was still settling went out in
|
|
517
|
+
// `session_list` as `starting`; once the start resolves, re-send the list so
|
|
518
|
+
// every client can open it.
|
|
519
|
+
sessionManager.on('session_start_settled', safeForward('session_start_settled', () => {
|
|
520
|
+
queueStartOutcomeSessionList()
|
|
268
521
|
}))
|
|
269
522
|
|
|
270
523
|
// Persist failures — surface to clients so the user knows a session-list
|
|
@@ -291,12 +544,23 @@ function setupSessionForwarding(normalizer, ctx) {
|
|
|
291
544
|
broadcastToSession(sessionId, {
|
|
292
545
|
type: 'session_error',
|
|
293
546
|
code: errorCode || 'SESSION_START_FAILED',
|
|
547
|
+
// #8981: lets clients tell a refused fresh session apart from every other
|
|
548
|
+
// session_error and record it as a coded chat error. Mirrored by
|
|
549
|
+
// SESSION_CREATE_FAILED_CATEGORY in store-core.
|
|
550
|
+
category: 'create_failed',
|
|
294
551
|
sessionId,
|
|
295
552
|
recoverable: false,
|
|
296
553
|
message: errorMessage
|
|
297
554
|
? `The session failed to start: ${errorMessage}`
|
|
298
555
|
: `The session failed to start${provider ? ` (${provider})` : ''}.`,
|
|
299
556
|
})
|
|
557
|
+
// #8981: nothing else announces the removal. `session_destroyed` listeners
|
|
558
|
+
// never send a `session_list`, and clients drop a session (and its messages)
|
|
559
|
+
// only when a list omits it, so the failed session would linger in sidebars
|
|
560
|
+
// and a coded entry parked for it would never land. The setImmediate inside
|
|
561
|
+
// fires after the synchronous destroySession that follows this emit, so the
|
|
562
|
+
// list omits the session.
|
|
563
|
+
queueStartOutcomeSessionList()
|
|
300
564
|
}))
|
|
301
565
|
|
|
302
566
|
// #5731 (T3): a checkpoint create/delete that couldn't be flushed to disk will
|
|
@@ -319,8 +583,11 @@ function setupSessionForwarding(normalizer, ctx) {
|
|
|
319
583
|
}
|
|
320
584
|
|
|
321
585
|
// Dev server preview: broadcast tunnel start/stop to clients
|
|
322
|
-
devPreview.on('
|
|
323
|
-
broadcastToSession(sessionId,
|
|
586
|
+
devPreview.on('dev_preview_status', safeForward('dev_preview_status', ({ sessionId, ...message }) => {
|
|
587
|
+
broadcastToSession(sessionId, message)
|
|
588
|
+
}))
|
|
589
|
+
devPreview.on('dev_preview_started', safeForward('dev_preview_started', ({ sessionId, port, url, target, exposure }) => {
|
|
590
|
+
broadcastToSession(sessionId, { type: 'dev_preview', port, url, ...(target ? { target, exposure } : {}) })
|
|
324
591
|
}))
|
|
325
592
|
devPreview.on('dev_preview_stopped', safeForward('dev_preview_stopped', ({ sessionId, port }) => {
|
|
326
593
|
broadcastToSession(sessionId, { type: 'dev_preview_stopped', port })
|
|
@@ -329,7 +596,7 @@ function setupSessionForwarding(normalizer, ctx) {
|
|
|
329
596
|
// (and the exposed local port) may still be live. Surface it as a per-session
|
|
330
597
|
// error banner (reusing `session_error`, like the checkpoint/persist failure
|
|
331
598
|
// paths) so the user can verify / kill cloudflared instead of assuming the
|
|
332
|
-
// port is closed.
|
|
599
|
+
// port is closed. The slot stays tracked until child exit is confirmed.
|
|
333
600
|
devPreview.on('dev_preview_stop_failed', safeForward('dev_preview_stop_failed', ({ sessionId, port, error }) => {
|
|
334
601
|
if (!sessionId) return
|
|
335
602
|
broadcastToSession(sessionId, {
|
|
@@ -350,7 +617,7 @@ function setupSessionForwarding(normalizer, ctx) {
|
|
|
350
617
|
|
|
351
618
|
/** Legacy single CLI session forwarding via normalizer */
|
|
352
619
|
function setupCliForwarding(normalizer, ctx) {
|
|
353
|
-
const { cliSession, devPreview, broadcast } = ctx
|
|
620
|
+
const { cliSession, devPreview, broadcast, defaultProvider = null } = ctx
|
|
354
621
|
|
|
355
622
|
// #3240: `skill_changed` is forwarded so legacy single-CLI users get the
|
|
356
623
|
// same trust-mismatch broadcast as multi-session mode. The normaliser
|
|
@@ -405,6 +672,12 @@ function setupCliForwarding(normalizer, ctx) {
|
|
|
405
672
|
broadcast(stamped)
|
|
406
673
|
}
|
|
407
674
|
}
|
|
675
|
+
|
|
676
|
+
// #7379: after the broadcast — see the multi-session path. This path
|
|
677
|
+
// broadcasts globally rather than per-session, so the unsubscribe hazard
|
|
678
|
+
// does not bite here; the ordering is mirrored anyway so the two paths
|
|
679
|
+
// cannot drift into different semantics for the same effect.
|
|
680
|
+
executeSideEffects(result.afterEffects, null, ctx)
|
|
408
681
|
} catch (err) {
|
|
409
682
|
const message = err?.message || String(err)
|
|
410
683
|
log.error(`legacy-cli forwarding threw (event=${event}): ${message}${err?.stack ? '\n' + err.stack : ''}`)
|
|
@@ -412,16 +685,12 @@ function setupCliForwarding(normalizer, ctx) {
|
|
|
412
685
|
})
|
|
413
686
|
}
|
|
414
687
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
cliSession.on('tool_result', safeForward('cli:tool_result', (data) => {
|
|
418
|
-
if (data?.result) {
|
|
419
|
-
devPreview.handleToolResult('__legacy__', data.result)
|
|
420
|
-
}
|
|
688
|
+
devPreview.on('dev_preview_status', safeForward('cli:dev_preview_status', ({ sessionId, ...message }) => {
|
|
689
|
+
if (sessionId === '__legacy__') broadcast({ ...message, sessionId })
|
|
421
690
|
}))
|
|
422
|
-
devPreview.on('dev_preview_started', safeForward('cli:dev_preview_started', ({ sessionId, port, url }) => {
|
|
691
|
+
devPreview.on('dev_preview_started', safeForward('cli:dev_preview_started', ({ sessionId, port, url, target, exposure }) => {
|
|
423
692
|
if (sessionId === '__legacy__') {
|
|
424
|
-
broadcast({ type: 'dev_preview', port, url })
|
|
693
|
+
broadcast({ type: 'dev_preview', port, url, ...(target ? { target, exposure } : {}) })
|
|
425
694
|
}
|
|
426
695
|
}))
|
|
427
696
|
devPreview.on('dev_preview_stopped', safeForward('cli:dev_preview_stopped', ({ sessionId, port }) => {
|
|
@@ -444,12 +713,23 @@ function setupCliForwarding(normalizer, ctx) {
|
|
|
444
713
|
}
|
|
445
714
|
}))
|
|
446
715
|
|
|
447
|
-
// models_updated bypasses normalizer — global broadcast.
|
|
448
|
-
//
|
|
449
|
-
//
|
|
716
|
+
// models_updated bypasses normalizer — global broadcast. Legacy single-CLI
|
|
717
|
+
// mode has no sessionManager and exactly one running session, so — unlike
|
|
718
|
+
// the multi-session path above — there is no per-client provider variance
|
|
719
|
+
// to fan out over; every connected client sees the SAME roster tag. Tag it
|
|
720
|
+
// with whatever `ws-history.js`'s legacy connect path
|
|
721
|
+
// (`resolveRosterProvider(null, billingCanary?.defaultProvider)`) would send
|
|
722
|
+
// for this daemon, rather than the literal `'claude-cli'` (#7895): a
|
|
723
|
+
// claude-tui or claude-byok client — or a daemon started with a non-default
|
|
724
|
+
// `config.provider` — keys its roster by that EXACT tag
|
|
725
|
+
// (`packages/store-core/src/models-by-provider.ts`), so a hardcoded
|
|
726
|
+
// `'claude-cli'` was delivered and discarded whenever the connect-time tag
|
|
727
|
+
// disagreed.
|
|
450
728
|
cliSession.on('models_updated', safeForward('cli:models_updated', (data) => {
|
|
451
729
|
if (data?.models) {
|
|
452
|
-
|
|
730
|
+
const legacyProvider = resolveRosterProvider(null, defaultProvider)
|
|
731
|
+
const legacyRegistry = getRegistryForProvider(legacyProvider)
|
|
732
|
+
broadcast({ type: 'available_models', models: data.models, defaultModel: legacyRegistry.getDefaultModelId(), provider: legacyProvider })
|
|
453
733
|
}
|
|
454
734
|
}))
|
|
455
735
|
}
|
|
@@ -457,7 +737,7 @@ function setupCliForwarding(normalizer, ctx) {
|
|
|
457
737
|
/** Execute side effect descriptors returned by the normalizer */
|
|
458
738
|
function executeSideEffects(sideEffects, sessionId, ctx) {
|
|
459
739
|
if (!sideEffects) return
|
|
460
|
-
const { normalizer, sessionManager, pushManager, broadcast, broadcastToSession, broadcastSessionList } = ctx
|
|
740
|
+
const { normalizer, sessionManager, pushManager, broadcast, broadcastToSession, broadcastSessionList, releasePermission } = ctx
|
|
461
741
|
for (const effect of sideEffects) {
|
|
462
742
|
switch (effect.type) {
|
|
463
743
|
case 'session_list':
|
|
@@ -469,6 +749,20 @@ function executeSideEffects(sideEffects, sessionId, ctx) {
|
|
|
469
749
|
}
|
|
470
750
|
}
|
|
471
751
|
break
|
|
752
|
+
case 'release_permission':
|
|
753
|
+
// #7379: the session says the turn behind this prompt is dead, so the
|
|
754
|
+
// daemon must stop holding (and re-sending) its pending entry. Optional
|
|
755
|
+
// in ctx so a harness that does not wire permissions still forwards
|
|
756
|
+
// events; a no-op when the requestId was never in the HTTP map, which is
|
|
757
|
+
// the normal case for the SDK path and for a hook that closed cleanly.
|
|
758
|
+
if (releasePermission) {
|
|
759
|
+
try {
|
|
760
|
+
releasePermission(effect.requestId, sessionId)
|
|
761
|
+
} catch (err) {
|
|
762
|
+
log.warn(`Failed to release abandoned permission ${effect.requestId}: ${err?.message || err}`)
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
break
|
|
472
766
|
case 'refresh_context':
|
|
473
767
|
if (sessionManager) {
|
|
474
768
|
sessionManager.getSessionContext(effect.sessionId || sessionId).then((ctxData) => {
|
|
@@ -505,6 +799,22 @@ function executeSideEffects(sideEffects, sessionId, ctx) {
|
|
|
505
799
|
}
|
|
506
800
|
break
|
|
507
801
|
}
|
|
802
|
+
case 'folder_trust_refresh': {
|
|
803
|
+
// A `ready` that found no fresh cached trust state: send the frame when the
|
|
804
|
+
// scan resolves, unless the session is gone by then. Display only.
|
|
805
|
+
const sid = effect.sessionId ?? sessionId
|
|
806
|
+
const entry = sessionManager?.getSession(sid)
|
|
807
|
+
if (entry && broadcastToSession) {
|
|
808
|
+
buildFolderTrustStateMessageForDisplay(sid, entry).then((frame) => {
|
|
809
|
+
if (!frame || !sessionManager.getSession(sid)) return
|
|
810
|
+
noteFolderTrustFrame(sessionManager, frame)
|
|
811
|
+
broadcastToSession(sid, withServerTs(frame))
|
|
812
|
+
}).catch((err) => {
|
|
813
|
+
log.debug(`folder trust refresh failed for ${sid}: ${err?.message || err}`)
|
|
814
|
+
})
|
|
815
|
+
}
|
|
816
|
+
break
|
|
817
|
+
}
|
|
508
818
|
case 'log':
|
|
509
819
|
log.info(effect.message)
|
|
510
820
|
break
|