@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/statusline.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* statusLine — read the user's Claude Code `statusLine` command from their
|
|
3
|
-
* settings
|
|
2
|
+
* statusLine — read the user's Claude Code `statusLine` command from their
|
|
3
|
+
* user-level settings, execute it the way Claude Code does, and surface its stdout.
|
|
4
4
|
*
|
|
5
5
|
* Feature #6791. A user who has configured a `statusLine` script (git branch,
|
|
6
6
|
* model, a cost tracker, …) sees none of it in Chroxy today; this module reads
|
|
7
7
|
* the effective config and runs it so its output can be broadcast to clients.
|
|
8
8
|
*
|
|
9
|
-
* ──
|
|
10
|
-
* The command is ONLY ever the one in the user's
|
|
11
|
-
*
|
|
12
|
-
* NO client-supplied command and NO client-supplied path: the settings files
|
|
9
|
+
* ── Which command runs (this EXECUTES a shell command) ───────────────────────
|
|
10
|
+
* The command is ONLY ever the one in the user's own user-level settings. There
|
|
11
|
+
* is NO client-supplied command and NO client-supplied path: the settings files
|
|
13
12
|
* are read from fixed, server-chosen locations only
|
|
14
|
-
* - <sessionCwd>/.claude/settings.json (project — highest precedence)
|
|
15
13
|
* - ~/.claude/project-settings.json (user project-settings)
|
|
16
14
|
* - ~/.claude/settings.json (user — lowest precedence)
|
|
17
|
-
* (
|
|
18
|
-
*
|
|
15
|
+
* (`CLAUDE_CONFIG_DIR` replaces `~/.claude`). The session's working directory
|
|
16
|
+
* is consulted for `<sessionCwd>/.claude/settings.json` only when the folder is
|
|
17
|
+
* trusted AND that file's bytes are exactly the ones in the trust record
|
|
18
|
+
* (`readTrustedProjectSettings`, folder-trust.js): read once, verified, parsed and
|
|
19
|
+
* executed from the same buffer, never cached. `sessionCwd` comes from the
|
|
20
|
+
* server's session record, never from the wire.
|
|
19
21
|
*
|
|
20
22
|
* Robustness hardening, none of which Claude Code documents but all of which a
|
|
21
23
|
* long-lived daemon needs so a slow/hostile script can't wedge it:
|
|
@@ -30,11 +32,12 @@
|
|
|
30
32
|
|
|
31
33
|
import { spawn } from 'node:child_process'
|
|
32
34
|
import { readFile } from 'node:fs/promises'
|
|
33
|
-
import {
|
|
35
|
+
import { claudeConfigDir } from './utils/claude-config-dir.js'
|
|
36
|
+
import { readTrustedProjectSettings } from './folder-trust.js'
|
|
34
37
|
import { join } from 'node:path'
|
|
35
38
|
import { EventEmitter } from 'node:events'
|
|
36
39
|
import { createLogger } from './logger.js'
|
|
37
|
-
import { CHROXY_SECRET_DENYLIST } from './utils/spawn-env.js'
|
|
40
|
+
import { CHROXY_SECRET_DENYLIST, stripInheritedChroxySecrets, stripParentClaudeSessionEnv } from './utils/spawn-env.js'
|
|
38
41
|
|
|
39
42
|
const log = createLogger('statusline')
|
|
40
43
|
|
|
@@ -59,15 +62,17 @@ export const STATUSLINE_CONFIG_CACHE_TTL_MS = 5_000
|
|
|
59
62
|
* the session cwd and the user home — none is client-supplied.
|
|
60
63
|
*
|
|
61
64
|
* @param {string} cwd - session working directory (project scope)
|
|
62
|
-
* @param {string}
|
|
65
|
+
* @param {string} claudeDir - claude's user-level config dir (`CLAUDE_CONFIG_DIR`, else `~/.claude`)
|
|
63
66
|
* @returns {string[]} absolute settings.json paths, highest precedence first
|
|
64
67
|
*/
|
|
65
|
-
export function statusLineSettingsPaths(
|
|
68
|
+
export function statusLineSettingsPaths(_cwd, claudeDir) {
|
|
69
|
+
// The session folder's own file is not in this list: it goes through
|
|
70
|
+
// `readTrustedProjectSettings`, which reads it once and checks it against the
|
|
71
|
+
// owner's trust record before anything in it can run.
|
|
66
72
|
const paths = []
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
paths.push(join(
|
|
70
|
-
paths.push(join(homeDir, '.claude', 'settings.json'))
|
|
73
|
+
if (claudeDir) {
|
|
74
|
+
paths.push(join(claudeDir, 'project-settings.json'))
|
|
75
|
+
paths.push(join(claudeDir, 'settings.json'))
|
|
71
76
|
}
|
|
72
77
|
return paths
|
|
73
78
|
}
|
|
@@ -152,10 +157,18 @@ export function buildStatusLineInput(ctx = {}) {
|
|
|
152
157
|
* set. Deliberately does NOT go through `buildSpawnEnv` / the credential store:
|
|
153
158
|
* a status script needs no provider OAuth token, and injecting one would hit
|
|
154
159
|
* the keychain on every periodic spawn (every ~10s) for no benefit.
|
|
160
|
+
*
|
|
161
|
+
* Also strips CHROXY_PORT/CHROXY_HOOK_SECRET (#7360): the statusline script is
|
|
162
|
+
* an arbitrary operator-configured command with no permission-hook role, so
|
|
163
|
+
* any value present is necessarily AMBIENTLY inherited (e.g. this daemon was
|
|
164
|
+
* itself launched from inside another chroxy session) rather than something
|
|
165
|
+
* this builder set itself — exported so the strip is directly unit-testable.
|
|
155
166
|
*/
|
|
156
|
-
function defaultBuildEnv() {
|
|
167
|
+
export function defaultBuildEnv() {
|
|
157
168
|
const env = { ...process.env }
|
|
158
169
|
for (const key of [...CHROXY_SECRET_DENYLIST, 'ANTHROPIC_API_KEY']) delete env[key]
|
|
170
|
+
stripInheritedChroxySecrets(env)
|
|
171
|
+
stripParentClaudeSessionEnv(env) // #8262
|
|
159
172
|
env.COLUMNS = '80'
|
|
160
173
|
env.LINES = '1'
|
|
161
174
|
return env
|
|
@@ -342,7 +355,8 @@ export function statusLineDisplayText(result) {
|
|
|
342
355
|
*/
|
|
343
356
|
export class StatusLineManager extends EventEmitter {
|
|
344
357
|
constructor({
|
|
345
|
-
homeDir
|
|
358
|
+
homeDir,
|
|
359
|
+
claudeDir,
|
|
346
360
|
readFileFn = readFile,
|
|
347
361
|
spawnFn = spawn,
|
|
348
362
|
buildEnv = defaultBuildEnv,
|
|
@@ -354,10 +368,15 @@ export class StatusLineManager extends EventEmitter {
|
|
|
354
368
|
minRefreshIntervalMs = STATUSLINE_MIN_REFRESH_INTERVAL_MS,
|
|
355
369
|
defaultRefreshIntervalMs = STATUSLINE_DEFAULT_REFRESH_INTERVAL_MS,
|
|
356
370
|
configCacheTtlMs = STATUSLINE_CONFIG_CACHE_TTL_MS,
|
|
371
|
+
readProjectSettingsFn = readTrustedProjectSettings,
|
|
357
372
|
} = {}) {
|
|
358
373
|
super()
|
|
359
|
-
|
|
374
|
+
// The user-level dir follows CLAUDE_CONFIG_DIR (#8974). `claudeDir` pins it;
|
|
375
|
+
// a bare `homeDir` (test seam) means `<homeDir>/.claude`; with neither, each
|
|
376
|
+
// resolveConfig() call resolves `claudeConfigDir()` from the daemon's process.env.
|
|
377
|
+
this._claudeDir = claudeDir ?? (homeDir ? join(homeDir, '.claude') : null)
|
|
360
378
|
this._readFileFn = readFileFn
|
|
379
|
+
this._readProjectSettingsFn = readProjectSettingsFn
|
|
361
380
|
this._spawnFn = spawnFn
|
|
362
381
|
this._buildEnv = buildEnv
|
|
363
382
|
this._now = now
|
|
@@ -371,7 +390,7 @@ export class StatusLineManager extends EventEmitter {
|
|
|
371
390
|
|
|
372
391
|
/** @type {Map<string, {config: object|null, expiresAt: number}>} keyed by cwd */
|
|
373
392
|
this._configCache = new Map()
|
|
374
|
-
/** @type {Map<string, {getContext: Function, timer: any, lastRunAt: number, running: boolean, lastText: string|null}>} */
|
|
393
|
+
/** @type {Map<string, {getContext: Function, timer: any, lastRunAt: number, running: boolean, lastText: string|null, fromProject: boolean, epoch: number}>} */
|
|
375
394
|
this._sessions = new Map()
|
|
376
395
|
this._stopped = false
|
|
377
396
|
}
|
|
@@ -386,11 +405,21 @@ export class StatusLineManager extends EventEmitter {
|
|
|
386
405
|
* @returns {Promise<{command:string, refreshIntervalMs:number|null}|null>}
|
|
387
406
|
*/
|
|
388
407
|
async resolveConfig(cwd) {
|
|
408
|
+
return (await this._resolve(cwd)).config
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** `resolveConfig`, also saying whether the config came from the trusted folder's own file. */
|
|
412
|
+
async _resolve(cwd) {
|
|
413
|
+
// The folder's own file first, and never from the cache: it is verified against
|
|
414
|
+
// the trust record on every call, so a trust change or an edit takes effect at once.
|
|
415
|
+
const projectConfig = this._projectConfig(cwd)
|
|
416
|
+
if (projectConfig) return { config: projectConfig, fromProject: true }
|
|
417
|
+
|
|
389
418
|
const cached = this._configCache.get(cwd)
|
|
390
|
-
if (cached && cached.expiresAt > this._now()) return cached.config
|
|
419
|
+
if (cached && cached.expiresAt > this._now()) return { config: cached.config, fromProject: false }
|
|
391
420
|
|
|
392
421
|
let config = null
|
|
393
|
-
for (const path of statusLineSettingsPaths(cwd, this.
|
|
422
|
+
for (const path of statusLineSettingsPaths(cwd, this._claudeDir ?? claudeConfigDir())) {
|
|
394
423
|
let raw
|
|
395
424
|
try {
|
|
396
425
|
raw = await this._readFileFn(path, 'utf8')
|
|
@@ -411,7 +440,18 @@ export class StatusLineManager extends EventEmitter {
|
|
|
411
440
|
}
|
|
412
441
|
|
|
413
442
|
this._configCache.set(cwd, { config, expiresAt: this._now() + this._configCacheTtlMs })
|
|
414
|
-
return config
|
|
443
|
+
return { config, fromProject: false }
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** The verified project statusLine config, or null. Never throws. */
|
|
447
|
+
_projectConfig(cwd) {
|
|
448
|
+
try {
|
|
449
|
+
const raw = this._readProjectSettingsFn(cwd)
|
|
450
|
+
if (raw === null || raw === undefined) return null
|
|
451
|
+
return parseStatusLineConfig(JSON.parse(raw))
|
|
452
|
+
} catch {
|
|
453
|
+
return null
|
|
454
|
+
}
|
|
415
455
|
}
|
|
416
456
|
|
|
417
457
|
/** Drop any cached config (e.g. session ended) so a re-read is forced. */
|
|
@@ -428,8 +468,8 @@ export class StatusLineManager extends EventEmitter {
|
|
|
428
468
|
* @returns {Promise<{active:boolean, text:string, result:object|null}>}
|
|
429
469
|
*/
|
|
430
470
|
async run(ctx) {
|
|
431
|
-
const config = await this.
|
|
432
|
-
if (!config) return { active: false, text: '', result: null }
|
|
471
|
+
const { config, fromProject } = await this._resolve(ctx?.cwd)
|
|
472
|
+
if (!config) return { active: false, text: '', result: null, fromProject: false }
|
|
433
473
|
|
|
434
474
|
let env
|
|
435
475
|
try {
|
|
@@ -450,7 +490,7 @@ export class StatusLineManager extends EventEmitter {
|
|
|
450
490
|
setTimer: this._setTimer,
|
|
451
491
|
clearTimer: this._clearTimer,
|
|
452
492
|
})
|
|
453
|
-
return { active: true, text: statusLineDisplayText(result), result }
|
|
493
|
+
return { active: true, text: statusLineDisplayText(result), result, fromProject }
|
|
454
494
|
}
|
|
455
495
|
|
|
456
496
|
/**
|
|
@@ -470,7 +510,7 @@ export class StatusLineManager extends EventEmitter {
|
|
|
470
510
|
if (!session) {
|
|
471
511
|
// Refresh for a session we aren't tracking a loop for is still valid
|
|
472
512
|
// (event-driven trigger before startSession); create a lightweight record.
|
|
473
|
-
session = { getContext: null, timer: null, lastRunAt: 0, running: false, lastText: null }
|
|
513
|
+
session = { getContext: null, timer: null, lastRunAt: 0, running: false, lastText: null, fromProject: false, epoch: 0 }
|
|
474
514
|
this._sessions.set(sessionId, session)
|
|
475
515
|
}
|
|
476
516
|
if (session.running) return null
|
|
@@ -480,6 +520,7 @@ export class StatusLineManager extends EventEmitter {
|
|
|
480
520
|
|
|
481
521
|
session.running = true
|
|
482
522
|
session.lastRunAt = this._now()
|
|
523
|
+
const epoch = session.epoch
|
|
483
524
|
let outcome
|
|
484
525
|
try {
|
|
485
526
|
outcome = await this.run(ctx)
|
|
@@ -495,7 +536,12 @@ export class StatusLineManager extends EventEmitter {
|
|
|
495
536
|
const still = this._sessions.get(sessionId)
|
|
496
537
|
if (!still) return outcome ? { ...outcome, emitted: false } : null
|
|
497
538
|
|
|
539
|
+
// A run that began before the folder stopped being trusted must not bring the
|
|
540
|
+
// folder's own output back (see clearProjectOutput).
|
|
541
|
+
if (still.epoch !== epoch && outcome.fromProject) return { ...outcome, emitted: false }
|
|
542
|
+
|
|
498
543
|
let emitted = false
|
|
544
|
+
still.fromProject = outcome.active && outcome.fromProject === true
|
|
499
545
|
if (outcome.active) {
|
|
500
546
|
if (outcome.text !== still.lastText) {
|
|
501
547
|
still.lastText = outcome.text
|
|
@@ -518,6 +564,31 @@ export class StatusLineManager extends EventEmitter {
|
|
|
518
564
|
return { active: outcome.active, text: outcome.text, emitted }
|
|
519
565
|
}
|
|
520
566
|
|
|
567
|
+
/**
|
|
568
|
+
* The session's folder stopped being trusted (the owner stopped trusting it, or an edit
|
|
569
|
+
* revoked it). If the status line last shown came from the folder's own settings,
|
|
570
|
+
* clear it now with one empty `output`, instead of leaving that text up until the next
|
|
571
|
+
* refresh, then refresh at once so a user-level status line, if any, takes its place.
|
|
572
|
+
* Output from the user's own settings is left alone.
|
|
573
|
+
* @param {string} sessionId
|
|
574
|
+
* @returns {boolean} true when a cleared output was emitted
|
|
575
|
+
*/
|
|
576
|
+
clearProjectOutput(sessionId) {
|
|
577
|
+
const session = this._sessions.get(sessionId)
|
|
578
|
+
if (!session || this._stopped) return false
|
|
579
|
+
session.epoch += 1 // a run already in flight began while the folder was trusted
|
|
580
|
+
if (!session.fromProject) return false
|
|
581
|
+
session.fromProject = false
|
|
582
|
+
const hadText = session.lastText !== null
|
|
583
|
+
session.lastText = null
|
|
584
|
+
if (hadText) this.emit('output', { sessionId, active: false, text: '', truncated: false, timedOut: false, exitCode: null })
|
|
585
|
+
try {
|
|
586
|
+
const ctx = session.getContext ? session.getContext() : null
|
|
587
|
+
if (ctx) this.refresh(sessionId, ctx, { force: true }).catch(() => {})
|
|
588
|
+
} catch { /* the periodic tick will refresh */ }
|
|
589
|
+
return hadText
|
|
590
|
+
}
|
|
591
|
+
|
|
521
592
|
/**
|
|
522
593
|
* Begin tracking a session: store its context provider and start the periodic
|
|
523
594
|
* refresh loop (a self-rescheduling, unref'd timer — never setInterval, so an
|
|
@@ -531,7 +602,7 @@ export class StatusLineManager extends EventEmitter {
|
|
|
531
602
|
if (this._stopped) return
|
|
532
603
|
let session = this._sessions.get(sessionId)
|
|
533
604
|
if (!session) {
|
|
534
|
-
session = { getContext, timer: null, lastRunAt: 0, running: false, lastText: null }
|
|
605
|
+
session = { getContext, timer: null, lastRunAt: 0, running: false, lastText: null, fromProject: false, epoch: 0 }
|
|
535
606
|
this._sessions.set(sessionId, session)
|
|
536
607
|
} else {
|
|
537
608
|
session.getContext = getContext
|
package/src/summarize-session.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { query } from '@anthropic-ai/claude-agent-sdk'
|
|
24
24
|
import { extractSearchableText } from './conversation-search.js'
|
|
25
25
|
import { createLogger } from './logger.js'
|
|
26
|
+
import { buildSpawnEnv } from './utils/spawn-env.js'
|
|
26
27
|
|
|
27
28
|
const log = createLogger('summarize')
|
|
28
29
|
|
|
@@ -50,6 +51,9 @@ export function flattenHistory(history) {
|
|
|
50
51
|
const lines = []
|
|
51
52
|
for (const entry of history) {
|
|
52
53
|
if (!entry || typeof entry !== 'object') continue
|
|
54
|
+
// #8348: a permission prompt's outcome is a transcript marker, not
|
|
55
|
+
// conversation; its `tool` field would otherwise flatten to a bare "[Bash]".
|
|
56
|
+
if (entry.type === 'permission_outcome') continue
|
|
53
57
|
// extractSearchableText reads entry.message.content; chroxy history entries
|
|
54
58
|
// store their text on `content`. Normalize so the shared flattener sees a
|
|
55
59
|
// message-shaped object regardless of which source produced the entry.
|
|
@@ -178,14 +182,45 @@ export function buildSummaryPrompt({ transcript, truncated, sessionName }) {
|
|
|
178
182
|
* user prompt, and the result text collected from assistant content blocks.
|
|
179
183
|
* Used when the caller doesn't inject a `runOneShot` seam.
|
|
180
184
|
*
|
|
185
|
+
* `queryFn` is an injectable seam (defaults to the real SDK `query`) so a test
|
|
186
|
+
* can assert on the built options — including `pathToClaudeCodeExecutable`
|
|
187
|
+
* (#7986) — without module-mocking `@anthropic-ai/claude-agent-sdk`.
|
|
188
|
+
*
|
|
189
|
+
* `resolveExecutable` has NO default (#8030) — it is a REQUIRED, verified
|
|
190
|
+
* binary-gate call, not a plain path resolve. Before #8030 this defaulted to
|
|
191
|
+
* `resolveClaudeBinary()`, which resolves a path but verifies nothing: a
|
|
192
|
+
* `block`-mode hash-mismatched `claude` that `createSession` would refuse
|
|
193
|
+
* could still be spawned by this one-shot path (the summarizer, the
|
|
194
|
+
* semantic-title generator) with no gate at all. Every caller now supplies a
|
|
195
|
+
* verified resolver — production wires `SessionManager.verifyOneShotExecutable`
|
|
196
|
+
* (see summarize-handlers.js / session-manager.js's `_generateSemanticTitle`),
|
|
197
|
+
* which re-runs the SAME preflight gate `createSession` runs.
|
|
198
|
+
*
|
|
181
199
|
* @param {object} args
|
|
182
200
|
* @param {string} args.prompt
|
|
183
201
|
* @param {string} [args.model] - model id; omitted lets the SDK pick its default.
|
|
184
202
|
* @param {string} [args.cwd]
|
|
185
203
|
* @param {AbortSignal} [args.signal]
|
|
204
|
+
* @param {Function} [args.queryFn] - injected in tests; defaults to the SDK's `query`.
|
|
205
|
+
* @param {Function} args.resolveExecutable - REQUIRED (#8030): `() => string`,
|
|
206
|
+
* a verified binary-gate call. Throwing a `PROVIDER_BINARY_*`-coded error
|
|
207
|
+
* refuses the spawn before `queryFn` is ever invoked.
|
|
186
208
|
* @returns {Promise<string>} the model's text reply.
|
|
209
|
+
* @throws {Error} when `resolveExecutable` is not a function, or when it throws.
|
|
187
210
|
*/
|
|
188
|
-
export async function defaultRunOneShot({ prompt, model, cwd, signal }) {
|
|
211
|
+
export async function defaultRunOneShot({ prompt, model, cwd, signal, queryFn = query, resolveExecutable }) {
|
|
212
|
+
if (typeof resolveExecutable !== 'function') {
|
|
213
|
+
throw new Error('defaultRunOneShot (#8030): resolveExecutable is required — the caller must supply its verified spawn gate (e.g. SessionManager.verifyOneShotExecutable) instead of relying on an unverified default binary resolve.')
|
|
214
|
+
}
|
|
215
|
+
// Resolved BEFORE queryFn so a gate refusal never spawns anything. An empty
|
|
216
|
+
// result is refused too: with pathToClaudeCodeExecutable unset the SDK falls
|
|
217
|
+
// back to its own bundled binary, which nothing has verified.
|
|
218
|
+
const executable = resolveExecutable()
|
|
219
|
+
if (typeof executable !== 'string' || executable.length === 0) {
|
|
220
|
+
const err = new Error('defaultRunOneShot (#8030): the spawn gate returned no binary path — refusing rather than letting the SDK fall back to its bundled binary.')
|
|
221
|
+
err.code = 'PROVIDER_BINARY_UNVERIFIED'
|
|
222
|
+
throw err
|
|
223
|
+
}
|
|
189
224
|
const options = {
|
|
190
225
|
// No tools — a pure text summarization turn. The session must not be able
|
|
191
226
|
// to read/write files or run commands during summarization.
|
|
@@ -193,14 +228,25 @@ export async function defaultRunOneShot({ prompt, model, cwd, signal }) {
|
|
|
193
228
|
permissionMode: 'bypassPermissions',
|
|
194
229
|
allowDangerouslySkipPermissions: true,
|
|
195
230
|
includePartialMessages: false,
|
|
231
|
+
// A one-shot summary needs no settings files.
|
|
232
|
+
settingSources: [],
|
|
196
233
|
maxTurns: 1,
|
|
234
|
+
// #7986 / #8030: the desktop bundle does not ship the Agent SDK's platform
|
|
235
|
+
// binary, and query() throws if pathToClaudeCodeExecutable is unset and
|
|
236
|
+
// that binary is absent — point it at the installed CLI, same as the
|
|
237
|
+
// chat-turn SDK provider, on every install.
|
|
238
|
+
pathToClaudeCodeExecutable: executable,
|
|
239
|
+
// #8262: without `env` the SDK copies process.env wholesale. Use the same
|
|
240
|
+
// builder the chat-turn SDK provider does, so a one-shot summary claude is a
|
|
241
|
+
// top-level session and no parent-session markers are inherited.
|
|
242
|
+
env: buildSpawnEnv('claude-sdk'),
|
|
197
243
|
}
|
|
198
244
|
if (typeof cwd === 'string' && cwd) options.cwd = cwd
|
|
199
245
|
if (typeof model === 'string' && model) options.model = model
|
|
200
246
|
if (signal) options.abortController = abortControllerFromSignal(signal)
|
|
201
247
|
|
|
202
248
|
const parts = []
|
|
203
|
-
const stream =
|
|
249
|
+
const stream = queryFn({ prompt, options })
|
|
204
250
|
for await (const msg of stream) {
|
|
205
251
|
if (msg?.type === 'assistant' && Array.isArray(msg.message?.content)) {
|
|
206
252
|
for (const block of msg.message.content) {
|
|
@@ -240,10 +286,13 @@ function abortControllerFromSignal(signal) {
|
|
|
240
286
|
* @param {string} [args.sessionName] - human label for the brief header.
|
|
241
287
|
* @param {Function} [args.runOneShot] - injected model runner.
|
|
242
288
|
* @param {AbortSignal} [args.signal]
|
|
289
|
+
* @param {Function} [args.resolveExecutable] - #8030: forwarded to the runner
|
|
290
|
+
* (`defaultRunOneShot` requires it; an injected `runOneShot` test double may
|
|
291
|
+
* ignore it). Production wires `SessionManager.verifyOneShotExecutable`.
|
|
243
292
|
* @returns {Promise<{ summary: string, truncated: boolean }>}
|
|
244
293
|
* @throws {Error} when there is no history to summarize or the model returns empty.
|
|
245
294
|
*/
|
|
246
|
-
export async function summarizeSession({ history, model, cwd, sessionName, runOneShot, signal } = {}) {
|
|
295
|
+
export async function summarizeSession({ history, model, cwd, sessionName, runOneShot, signal, resolveExecutable } = {}) {
|
|
247
296
|
const transcript = flattenHistory(history)
|
|
248
297
|
if (!transcript.trim()) {
|
|
249
298
|
const err = new Error('Session has no readable history to summarize')
|
|
@@ -255,7 +304,7 @@ export async function summarizeSession({ history, model, cwd, sessionName, runOn
|
|
|
255
304
|
const prompt = buildSummaryPrompt({ transcript: text, truncated, sessionName })
|
|
256
305
|
|
|
257
306
|
const runner = typeof runOneShot === 'function' ? runOneShot : defaultRunOneShot
|
|
258
|
-
const summary = await runner({ prompt, model, cwd, signal })
|
|
307
|
+
const summary = await runner({ prompt, model, cwd, signal, resolveExecutable })
|
|
259
308
|
|
|
260
309
|
if (typeof summary !== 'string' || !summary.trim()) {
|
|
261
310
|
const err = new Error('The summarizer returned no text')
|
package/src/supervisor.js
CHANGED
|
@@ -5,7 +5,6 @@ import { dirname, resolve, join } from 'path'
|
|
|
5
5
|
import { createInterface } from 'readline'
|
|
6
6
|
import { fileURLToPath } from 'url'
|
|
7
7
|
import { writeFileSync, readFileSync, unlinkSync, existsSync, mkdirSync } from 'fs'
|
|
8
|
-
import { homedir } from 'os'
|
|
9
8
|
import { EventEmitter } from 'events'
|
|
10
9
|
import { createTunnel, parseTunnelArg } from './tunnel/index.js'
|
|
11
10
|
import { QUICK_TUNNEL_DNS_SETTLE_MS, waitForTunnel } from './tunnel-check.js'
|
|
@@ -13,6 +12,8 @@ import { createLogger } from './logger.js'
|
|
|
13
12
|
import QRCode from 'qrcode'
|
|
14
13
|
import { writeConnectionInfo, removeConnectionInfo } from './connection-info.js'
|
|
15
14
|
import { PushManager } from './push.js'
|
|
15
|
+
import { configPath } from './config-dir.js'
|
|
16
|
+
import { isGitShaRef } from './utils/argv-safety.js'
|
|
16
17
|
|
|
17
18
|
function maskToken(token) {
|
|
18
19
|
if (!token) return ''
|
|
@@ -34,7 +35,9 @@ const __filename = fileURLToPath(import.meta.url)
|
|
|
34
35
|
const __dirname = dirname(__filename)
|
|
35
36
|
const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'))
|
|
36
37
|
const SUPERVISOR_VERSION = packageJson.version
|
|
37
|
-
|
|
38
|
+
function defaultPidFile() {
|
|
39
|
+
return configPath('supervisor.pid')
|
|
40
|
+
}
|
|
38
41
|
|
|
39
42
|
const DRAIN_TIMEOUT = 30000
|
|
40
43
|
const RESTART_BACKOFFS = [2000, 2000, 3000, 3000, 5000, 5000, 8000, 8000, 10000, 10000]
|
|
@@ -62,8 +65,8 @@ export class Supervisor extends EventEmitter {
|
|
|
62
65
|
this._port = config.port || parseInt(process.env.PORT || '8765', 10)
|
|
63
66
|
this._apiToken = config.apiToken || process.env.API_TOKEN
|
|
64
67
|
this._tunnelMode = config.tunnel || 'quick'
|
|
65
|
-
this._pidFilePath = config.pidFilePath ||
|
|
66
|
-
this._knownGoodFile = config.knownGoodFile ||
|
|
68
|
+
this._pidFilePath = config.pidFilePath || defaultPidFile()
|
|
69
|
+
this._knownGoodFile = config.knownGoodFile || configPath('known-good-ref')
|
|
67
70
|
this._maxRestarts = (typeof config.maxRestarts === 'number' && config.maxRestarts >= 0)
|
|
68
71
|
? config.maxRestarts
|
|
69
72
|
: 10
|
|
@@ -118,7 +121,7 @@ export class Supervisor extends EventEmitter {
|
|
|
118
121
|
lastBackoffMs: 0,
|
|
119
122
|
}
|
|
120
123
|
|
|
121
|
-
this._pushStoragePath = config.pushStoragePath ||
|
|
124
|
+
this._pushStoragePath = config.pushStoragePath || configPath('push-tokens.json')
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
/** Override point: fork a child process */
|
|
@@ -205,9 +208,9 @@ export class Supervisor extends EventEmitter {
|
|
|
205
208
|
// picks up prefs the child persisted after startup, same as the tokens.
|
|
206
209
|
const push = new PushManager({
|
|
207
210
|
storagePath: this._pushStoragePath,
|
|
208
|
-
prefsPath:
|
|
211
|
+
prefsPath: configPath('notification-prefs.json'),
|
|
209
212
|
discord: {
|
|
210
|
-
statePath:
|
|
213
|
+
statePath: configPath('discord-webhook-state.json'),
|
|
211
214
|
...(this.config.notifications?.discord || {}),
|
|
212
215
|
},
|
|
213
216
|
})
|
|
@@ -828,9 +831,13 @@ export class Supervisor extends EventEmitter {
|
|
|
828
831
|
*
|
|
829
832
|
* Two layers of defense now close this:
|
|
830
833
|
*
|
|
831
|
-
* 1.
|
|
832
|
-
*
|
|
833
|
-
* `
|
|
834
|
+
* 1. `validateCwdAllowed` refuses a session cwd inside the config/state
|
|
835
|
+
* root, so the attacker can't reach `known-good-ref` via `write_file`.
|
|
836
|
+
* Two checks back that: `~/.chroxy` is in FORBIDDEN_HOME_SUBDIRS by
|
|
837
|
+
* name, AND the resolved `configDir()` is denied outright. The second
|
|
838
|
+
* is what keeps this true once CHROXY_CONFIG_DIR relocates the root
|
|
839
|
+
* (#7052) — the name-based set alone would then be guarding an empty
|
|
840
|
+
* directory while the real one sat open.
|
|
834
841
|
*
|
|
835
842
|
* 2. This function validates that the ref resolves to the SAME
|
|
836
843
|
* commit as an existing `known-good-*` git tag. The tag is
|
|
@@ -854,7 +861,11 @@ export class Supervisor extends EventEmitter {
|
|
|
854
861
|
// ≥ 7 chars to match historical behavior but require
|
|
855
862
|
// hex-only content. Rejects arbitrary branch names, refspecs,
|
|
856
863
|
// option flags (-rf, --help), etc.
|
|
857
|
-
|
|
864
|
+
//
|
|
865
|
+
// #7296: `chroxy deploy` reads the SAME file into a `git diff` argv, so
|
|
866
|
+
// the predicate moved to utils/argv-safety.js and both call sites share
|
|
867
|
+
// it. A second transcription of this regex is the drift this prevents.
|
|
868
|
+
if (!isGitShaRef(ref)) {
|
|
858
869
|
this._log.error(`Invalid known-good ref format: "${ref.slice(0, 64)}"`)
|
|
859
870
|
return false
|
|
860
871
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boot-time sweep of stale per-session provider dirs (#7374).
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `server-cli.js` so the sweep is pinned BEHAVIOURALLY. It used
|
|
5
|
+
* to be an inline block in the boot path, guarded only by a test that grepped
|
|
6
|
+
* `server-cli.js` for `sweepStaleSinkDirs(log)` inside an anchored `import(...)`
|
|
7
|
+
* slice. Mutation testing during #7371's review showed two bypasses that kept
|
|
8
|
+
* that guard green:
|
|
9
|
+
*
|
|
10
|
+
* - wrapping the whole block in `if (process.env.__NEVER_SET__) { … }`
|
|
11
|
+
* - replacing the call with `.then(({CliSession}) => void CliSession)` and
|
|
12
|
+
* putting the expected string in a comment INSIDE the anchored window
|
|
13
|
+
*
|
|
14
|
+
* That is catalogue entry 1 ("the gate that never ran"): a source grep cannot
|
|
15
|
+
* tell a call reached at boot from the same characters behind a false
|
|
16
|
+
* condition. Extracting the body means the WORK is now covered by tests that
|
|
17
|
+
* actually run it — see `tests/sweep-stale-provider-dirs.test.js`.
|
|
18
|
+
*
|
|
19
|
+
* What remains source-level is only that `server-cli.js` calls this function at
|
|
20
|
+
* boot. That residual is recorded in `docs/false-safety-guards.md` rather than
|
|
21
|
+
* papered over in a comment here.
|
|
22
|
+
*
|
|
23
|
+
* All four sweeps (claude-tui, claude-cli, codex app-server, docker-byok —
|
|
24
|
+
* #8047 added the latter two) are safe and unconditional: only dirs whose
|
|
25
|
+
* owner pid is DEAD are removed, so a live daemon's dirs — including ours —
|
|
26
|
+
* are kept. Lazily imported so a boot that uses none of the four providers
|
|
27
|
+
* pays nothing, and every failure is warned rather than thrown so a sweep can
|
|
28
|
+
* never affect startup.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The real module loaders. Injectable so a test can drive this function with
|
|
33
|
+
* stubs instead of `mock.module`, which leaks across the parallel test files
|
|
34
|
+
* `node --test` runs.
|
|
35
|
+
*/
|
|
36
|
+
export const DEFAULT_SWEEP_LOADERS = {
|
|
37
|
+
// #5323 (WP-5.1) — claude-tui hook-sink dirs left in /tmp by prior crashed
|
|
38
|
+
// processes (a leak on every crash).
|
|
39
|
+
'claude-tui sink-dir': async () => {
|
|
40
|
+
const { ClaudeTuiSession } = await import('./claude-tui-session.js')
|
|
41
|
+
return (log) => ClaudeTuiSession.sweepStaleSinkDirs(log)
|
|
42
|
+
},
|
|
43
|
+
// #7337 — same sweep for claude-cli's per-session permission-mode sidecar
|
|
44
|
+
// dirs, which leak on a crash for exactly the same reason.
|
|
45
|
+
'claude-cli sidecar-dir': async () => {
|
|
46
|
+
const { CliSession } = await import('./cli-session.js')
|
|
47
|
+
return (log) => CliSession.sweepStaleSidecarDirs(log)
|
|
48
|
+
},
|
|
49
|
+
// #7373 — codex app-server's per-session materialized-attachment dirs,
|
|
50
|
+
// same crash-leak shape as the two sweeps above.
|
|
51
|
+
'codex attach-dir': async () => {
|
|
52
|
+
const { CodexAppServerSession } = await import('./codex-app-server-session.js')
|
|
53
|
+
return (log) => CodexAppServerSession.sweepStaleAttachDirs(log)
|
|
54
|
+
},
|
|
55
|
+
// #7373 — docker-byok's per-session compose env-file dirs. This one is
|
|
56
|
+
// materially worse than a plain directory leak: the file holds
|
|
57
|
+
// ANTHROPIC_API_KEY, so an unswept orphan is a credential left in /tmp.
|
|
58
|
+
'docker-byok env-file-dir': async () => {
|
|
59
|
+
const { DockerByokSession } = await import('./docker-byok-session.js')
|
|
60
|
+
return (log) => DockerByokSession.sweepStaleEnvDirs(log)
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Run every provider's stale-dir sweep. Never rejects: a loader or sweep that
|
|
66
|
+
* throws is warned and the others still run.
|
|
67
|
+
*
|
|
68
|
+
* @param {{ info: Function, warn: Function }} log
|
|
69
|
+
* @param {Record<string, () => Promise<Function>>} [loaders]
|
|
70
|
+
* @returns {Promise<void>}
|
|
71
|
+
*/
|
|
72
|
+
export async function sweepStaleProviderDirs(log, loaders = DEFAULT_SWEEP_LOADERS) {
|
|
73
|
+
await Promise.all(
|
|
74
|
+
Object.entries(loaders).map(async ([label, load]) => {
|
|
75
|
+
try {
|
|
76
|
+
const sweep = await load()
|
|
77
|
+
await sweep(log)
|
|
78
|
+
} catch (err) {
|
|
79
|
+
// The logger is the one call left outside the try, and a throwing
|
|
80
|
+
// `log.warn` would reject `Promise.all` — which nothing awaits, so it
|
|
81
|
+
// surfaces as an unhandledRejection, and server-orchestrator treats
|
|
82
|
+
// that as fatal. The OLD inline form had the identical hole (a throw
|
|
83
|
+
// inside `.catch()` rejects the chain just the same), so this is not a
|
|
84
|
+
// regression being fixed — it is the "never rejects" claim being made
|
|
85
|
+
// true rather than nearly true.
|
|
86
|
+
try {
|
|
87
|
+
log.warn(`${label} sweep failed: ${(err && err.message) || err}`)
|
|
88
|
+
} catch {
|
|
89
|
+
// Nothing left to report it with. Swallowing is correct: a
|
|
90
|
+
// best-effort reaper must never be able to take down boot.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE builder of the wire `thinking_level_changed` frame (#8700).
|
|
3
|
+
*
|
|
4
|
+
* Four senders put this frame on the wire: ws-history's `sendSessionInfo`
|
|
5
|
+
* replay (reconnect / tab switch), the event normalizer's `ready` burst, the
|
|
6
|
+
* `set_thinking_level` handler after an accepted change, and the normalizer's
|
|
7
|
+
* own `thinking_level_changed` entry for a level the SESSION changed or learned
|
|
8
|
+
* (a model switch that dropped an unoffered level, the effort Claude Code
|
|
9
|
+
* reported at the start of a turn). Each used to spell `{ level }` by hand, so a
|
|
10
|
+
* field added to one sender was missing from the rest — a replay would then
|
|
11
|
+
* erase what the live frame had said. They all build it here instead.
|
|
12
|
+
*
|
|
13
|
+
* `level` is what the operator asked for (`default` when nothing was asked).
|
|
14
|
+
* `effective` is what the provider REPORTS it applied, and it is sent only by a
|
|
15
|
+
* provider that declares `capabilities.thinkingLevelEffective`: there `null`
|
|
16
|
+
* means "not reported yet", while an absent key (every other provider) means
|
|
17
|
+
* "this provider makes no such report". Clients render the two differently, so
|
|
18
|
+
* the builder never collapses one into the other.
|
|
19
|
+
*
|
|
20
|
+
* Returns null for a session with no thinking-level concept (`thinkingLevel`
|
|
21
|
+
* getter `undefined`, BaseSession's default), so no sender invents a `default`
|
|
22
|
+
* that would stomp a client's state for a provider that never had one.
|
|
23
|
+
*/
|
|
24
|
+
import { LEGACY_DEFAULT_THINKING_LEVEL } from '@chroxy/protocol'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {object|null|undefined} session
|
|
28
|
+
* @returns {{ type: 'thinking_level_changed', level: string, effective?: string|null } | null}
|
|
29
|
+
*/
|
|
30
|
+
export function buildThinkingLevelChanged(session) {
|
|
31
|
+
const level = session?.thinkingLevel
|
|
32
|
+
if (level === undefined) return null
|
|
33
|
+
const msg = { type: 'thinking_level_changed', level: level || LEGACY_DEFAULT_THINKING_LEVEL }
|
|
34
|
+
if (session.constructor?.capabilities?.thinkingLevelEffective === true) {
|
|
35
|
+
const effective = session.effectiveThinkingLevel
|
|
36
|
+
msg.effective = typeof effective === 'string' && effective.length > 0 ? effective : null
|
|
37
|
+
}
|
|
38
|
+
return msg
|
|
39
|
+
}
|