@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
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { formatWriteConfirmation } from './built-in-tools/tool-transforms.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalise a claude-tui PostToolUse hook's `tool_response` into the same
|
|
5
|
+
* kind of flat display text SdkSession/CliSession forward for a tool_result
|
|
6
|
+
* (see tool-result.js's `emitToolResults`).
|
|
7
|
+
*
|
|
8
|
+
* #8082: the PostToolUse hook payload's `tool_response` field is Claude
|
|
9
|
+
* Code's raw structured tool result (the same object the on-disk transcript
|
|
10
|
+
* stores as `toolUseResult`, alongside a `tool_result` content block whose
|
|
11
|
+
* `content` is the flattened text the model actually saw). The claude-tui
|
|
12
|
+
* provider only observes the hook payload, not the transcript's sibling
|
|
13
|
+
* content block, so — unlike SdkSession/CliSession, which read `content`
|
|
14
|
+
* directly off the tool_result block via `emitToolResults` — there is no
|
|
15
|
+
* flattened-text field available here for the built-in tools. This function
|
|
16
|
+
* unwraps the known structured shapes into the same kind of plain text
|
|
17
|
+
* instead of forwarding (and previously, JSON.stringify-ing) the envelope.
|
|
18
|
+
*
|
|
19
|
+
* Order of preference (see the #8082 PR review, Critical #1 — a plain
|
|
20
|
+
* string `content` field is AMBIGUOUS and its priority relative to the
|
|
21
|
+
* Write-shape check is load-bearing; a fixture that pins this ordering
|
|
22
|
+
* lives in the test suite as the "rule order" regression case):
|
|
23
|
+
*
|
|
24
|
+
* 1a. A `content` field that is an ARRAY of `{ type: 'text', text }`
|
|
25
|
+
* blocks — this shape is unambiguous (Write/Edit/Bash/Read never
|
|
26
|
+
* produce it) and always wins: it's the exact shape emitToolResults()
|
|
27
|
+
* flattens, and it's what an MCP `{ content: [...], isError }` tool
|
|
28
|
+
* response carries verbatim.
|
|
29
|
+
* 1b. A `content` field that is a STRING — used as-is, UNLESS the object
|
|
30
|
+
* is shaped like the built-in Write tool's result (see
|
|
31
|
+
* `isFileWriteResponseShape`), in which case this branch is skipped
|
|
32
|
+
* and rule 2 handles it instead. Grep's content-mode result
|
|
33
|
+
* (`{ mode: 'content', content: '<rg output>', numLines }`) and a
|
|
34
|
+
* string-content MCP response both qualify here; Write's result also
|
|
35
|
+
* carries a string `content` field, but there it is the ENTIRE
|
|
36
|
+
* written file, not a flattened summary — the whole reason this rule
|
|
37
|
+
* needs the Write-shape exclusion (#8082 review, Critical #1).
|
|
38
|
+
* 2. The known built-in Write shape: `{ type: 'create'|'update', filePath,
|
|
39
|
+
* content, structuredPatch, originalFile, userModified }` — rendered as
|
|
40
|
+
* the SAME short confirmation text `byok-tool-executor.js`'s `runWrite`
|
|
41
|
+
* already produces for a successful write (`formatWriteConfirmation`,
|
|
42
|
+
* built-in-tools/tool-transforms.js), never the file body. Checked
|
|
43
|
+
* BEFORE the Bash/Read unwraps below too — not just before rule 1b —
|
|
44
|
+
* so a (pathological, never real) object that happened to satisfy both
|
|
45
|
+
* the Write shape and a Bash/Read shape still renders the Write
|
|
46
|
+
* confirmation, never the file body misread as stdout/file content.
|
|
47
|
+
* 3. The known built-in Bash shape: `{ stdout, stderr, interrupted,
|
|
48
|
+
* isImage, noOutputExpected }`.
|
|
49
|
+
* 4. The known built-in Read shape: `{ type: 'text', file: { content } }`.
|
|
50
|
+
* 4b. (checked right after rule 1a) `{ type: 'file_unchanged', file: {
|
|
51
|
+
* filePath } }` — a repeated Read of an unchanged file — rendered as
|
|
52
|
+
* "File unchanged since it was last read (<path>)" (#8252).
|
|
53
|
+
* 5. Anything else — unchanged from before this normalizer existed:
|
|
54
|
+
* `JSON.stringify(resp)`. This is a deliberate no-regression floor: an
|
|
55
|
+
* unrecognised structured shape must render exactly as it did before,
|
|
56
|
+
* never worse.
|
|
57
|
+
*
|
|
58
|
+
* KNOWN LIMITATION (not a regression — see the #8082 PR review, Suggestion
|
|
59
|
+
* #3): an array `content` mixing a `{ type: 'image', ... }` block with text
|
|
60
|
+
* blocks silently drops the image block with no placeholder (unlike Bash's
|
|
61
|
+
* `isImage: true`, which renders `[Image output omitted]`). Before this
|
|
62
|
+
* normalizer existed the whole envelope was JSON.stringify-d — including raw
|
|
63
|
+
* base64 — so this is not worse than before, but it means MCP tool results
|
|
64
|
+
* get parity with SdkSession/CliSession for TEXT content only; a real
|
|
65
|
+
* `tool_result` event carries images via a separate `images` array
|
|
66
|
+
* (tool-result.js's `emitToolResults`) that claude-tui's `tool_result` event
|
|
67
|
+
* has no field for at all today.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} toolName
|
|
70
|
+
* @param {unknown} resp - `payload.tool_response` from a PostToolUse hook.
|
|
71
|
+
* @returns {string}
|
|
72
|
+
*/
|
|
73
|
+
export function normalizeClaudeTuiToolResponse(toolName, resp) {
|
|
74
|
+
if (typeof resp === 'string') return resp
|
|
75
|
+
if (resp === null || resp === undefined) return ''
|
|
76
|
+
if (typeof resp !== 'object') return ''
|
|
77
|
+
|
|
78
|
+
// Rule 1a — array-of-text-blocks content ALWAYS qualifies. This shape is
|
|
79
|
+
// unambiguous: Write/Edit/Bash/Read never produce it, so checking it
|
|
80
|
+
// unconditionally (before the Write-shape check even runs) cannot regress
|
|
81
|
+
// anything.
|
|
82
|
+
const fromArrayContent = flattenArrayContent(resp.content)
|
|
83
|
+
if (fromArrayContent !== null) return fromArrayContent
|
|
84
|
+
|
|
85
|
+
// Rule 4b, checked right after rule 1a (#8252) — a repeated Read of a file that has not changed. Claude
|
|
86
|
+
// Code answers with `{ type: 'file_unchanged', file: { filePath } }` instead of
|
|
87
|
+
// the content, and the model is told to refer to the earlier read. Shape-
|
|
88
|
+
// matched, not tool-matched: the type tag is unambiguous.
|
|
89
|
+
if (resp.type === 'file_unchanged') return normalizeFileUnchangedResponse(resp)
|
|
90
|
+
|
|
91
|
+
// The Write-shape check MUST be computed (and consulted by rule 1b)
|
|
92
|
+
// BEFORE a string `content` field is allowed to win. Reversing this —
|
|
93
|
+
// checking Bash/Read/Write shapes only after an unconditional string
|
|
94
|
+
// rule 1 — is exactly the regression the #8082 PR review found: Write's
|
|
95
|
+
// structured result carries a string `content` field (the entire file),
|
|
96
|
+
// and an unscoped rule 1 renders it verbatim instead of a short
|
|
97
|
+
// confirmation. See the "rule order" mutant in the test suite for the
|
|
98
|
+
// fixture that pins this.
|
|
99
|
+
const isWriteShape = isFileWriteResponseShape(resp)
|
|
100
|
+
|
|
101
|
+
// Rule 1b — a plain string `content` field, when the object is NOT
|
|
102
|
+
// shaped like a Write result (Grep content-mode, string-content MCP).
|
|
103
|
+
if (typeof resp.content === 'string' && !isWriteShape) {
|
|
104
|
+
return resp.content
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// The Write-shape check ALSO has to win over the Bash/Read tool-specific
|
|
108
|
+
// unwraps below, not just over rule 1b — a pathological object could in
|
|
109
|
+
// principle satisfy both isFileWriteResponseShape AND
|
|
110
|
+
// normalizeBashResponse's "has stdout or stderr" test (or Read's file.content
|
|
111
|
+
// test); Write must still take priority so its `content` (the whole file)
|
|
112
|
+
// is never mistaken for stdout/file-content text. A genuine Bash/Read
|
|
113
|
+
// result never carries filePath/structuredPatch/type:create|update, so
|
|
114
|
+
// this ordering has NO effect on any real tool response — see the
|
|
115
|
+
// "rule-order regression" fixtures in the test suite that pin it.
|
|
116
|
+
if (isWriteShape) {
|
|
117
|
+
return normalizeWriteResponse(resp)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (toolName === 'Bash') {
|
|
121
|
+
const bash = normalizeBashResponse(resp)
|
|
122
|
+
if (bash !== null) return bash
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (toolName === 'Read') {
|
|
126
|
+
const read = normalizeReadResponse(resp)
|
|
127
|
+
if (read !== null) return read
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Unknown/unmapped shape — unchanged from today's behavior.
|
|
131
|
+
try {
|
|
132
|
+
return JSON.stringify(resp)
|
|
133
|
+
} catch {
|
|
134
|
+
return String(resp)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Flatten a tool_result-block-shaped `content` field that is an ARRAY of
|
|
140
|
+
* `{ type: 'text', text }` blocks, the same way tool-result.js's
|
|
141
|
+
* `emitToolResults` flattens `block.content`: filtered to `type: 'text'`
|
|
142
|
+
* blocks and joined with `\n`. Returns null when `content` is not an array,
|
|
143
|
+
* or is an array with no text block at all (so the caller falls through to
|
|
144
|
+
* the Write-shape check / a tool-specific unwrap), NOT when it flattens to
|
|
145
|
+
* an empty string (a legitimately empty text result is a valid result).
|
|
146
|
+
*
|
|
147
|
+
* Deliberately does NOT handle a string `content` — that branch is
|
|
148
|
+
* ambiguous (see `normalizeClaudeTuiToolResponse`'s rule 1b) and is decided
|
|
149
|
+
* by the caller together with `isFileWriteResponseShape`, not here.
|
|
150
|
+
*
|
|
151
|
+
* @param {unknown} content
|
|
152
|
+
* @returns {string|null}
|
|
153
|
+
*/
|
|
154
|
+
function flattenArrayContent(content) {
|
|
155
|
+
if (!Array.isArray(content)) return null
|
|
156
|
+
const hasTextBlock = content.some((b) => b && typeof b === 'object' && b.type === 'text')
|
|
157
|
+
if (!hasTextBlock) return null
|
|
158
|
+
return content
|
|
159
|
+
.filter((b) => b && b.type === 'text' && typeof b.text === 'string')
|
|
160
|
+
.map((b) => b.text)
|
|
161
|
+
.join('\n')
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Does `resp` look like the built-in Write tool's structured result —
|
|
166
|
+
* `{ type: 'create'|'update', filePath, content, structuredPatch,
|
|
167
|
+
* originalFile, userModified }` — where `content` is the ENTIRE written
|
|
168
|
+
* file, not a flattened model-facing summary?
|
|
169
|
+
*
|
|
170
|
+
* Checked by shape rather than tool name: `type: 'create'|'update'` AND a
|
|
171
|
+
* string `content`. Both are required. `filePath` or `structuredPatch` alone
|
|
172
|
+
* is NOT enough, because Edit's result carries both (`{ filePath, oldString,
|
|
173
|
+
* newString, originalFile, structuredPatch, … }`) and has no `content`;
|
|
174
|
+
* matching it here would render "Wrote 0 bytes to <path>", a false
|
|
175
|
+
* statement, where Edit's unchanged fallback is at least accurate.
|
|
176
|
+
*
|
|
177
|
+
* @param {Record<string, unknown>} resp
|
|
178
|
+
* @returns {boolean}
|
|
179
|
+
*/
|
|
180
|
+
function isFileWriteResponseShape(resp) {
|
|
181
|
+
return (resp.type === 'create' || resp.type === 'update') && typeof resp.content === 'string'
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Unwrap the built-in Bash tool's structured result:
|
|
186
|
+
* `{ stdout, stderr, interrupted, isImage, noOutputExpected }`.
|
|
187
|
+
*
|
|
188
|
+
* - stdout alone → stdout, unchanged (matches the SdkSession/CliSession
|
|
189
|
+
* shape: a Bash result with no stderr is just the command's output text).
|
|
190
|
+
* - stdout + non-empty stderr → stdout, then stderr on its own line. stderr
|
|
191
|
+
* must never be silently dropped — that's the whole "Bash cards show
|
|
192
|
+
* stdout, and stderr when it isn't empty" acceptance criterion.
|
|
193
|
+
* - stderr alone (stdout empty) → stderr by itself, so a failing command
|
|
194
|
+
* with no stdout still shows *something* rather than a blank card.
|
|
195
|
+
* - both empty + interrupted → a short placeholder rather than a blank
|
|
196
|
+
* card with no explanation.
|
|
197
|
+
* - both empty, not interrupted → '' (matches ToolBubble's existing
|
|
198
|
+
* "empty string result renders nothing" contract — nothing ran wrong,
|
|
199
|
+
* there's just nothing to show).
|
|
200
|
+
* - `isImage: true` → the hook payload carries no actual image bytes for
|
|
201
|
+
* Bash (unlike Read/MCP image content blocks, which flow through
|
|
202
|
+
* `flattenArrayContent` above and tool-result.js's own image
|
|
203
|
+
* extraction), so `stdout` here is not decodable image data by this
|
|
204
|
+
* provider today. A placeholder avoids dumping raw/base64 noise into a
|
|
205
|
+
* plain-text tool card; see the PR for the "Needs live check" note.
|
|
206
|
+
*
|
|
207
|
+
* Returns null when `resp` doesn't carry either of `stdout`/`stderr` as a
|
|
208
|
+
* string at all (not really a Bash-shaped response), so the caller falls
|
|
209
|
+
* through to the generic JSON.stringify floor.
|
|
210
|
+
*
|
|
211
|
+
* @param {Record<string, unknown>} resp
|
|
212
|
+
* @returns {string|null}
|
|
213
|
+
*/
|
|
214
|
+
function normalizeBashResponse(resp) {
|
|
215
|
+
if (typeof resp.stdout !== 'string' && typeof resp.stderr !== 'string') return null
|
|
216
|
+
|
|
217
|
+
const stdout = typeof resp.stdout === 'string' ? resp.stdout : ''
|
|
218
|
+
const stderr = typeof resp.stderr === 'string' ? resp.stderr : ''
|
|
219
|
+
|
|
220
|
+
if (resp.isImage === true) {
|
|
221
|
+
return stderr ? `[Image output omitted]\n${stderr}` : '[Image output omitted]'
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!stdout && !stderr) {
|
|
225
|
+
return resp.interrupted === true ? '[Interrupted — no output]' : ''
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (stderr) {
|
|
229
|
+
return stdout ? `${stdout}\n${stderr}` : stderr
|
|
230
|
+
}
|
|
231
|
+
return stdout
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Unwrap the built-in Read tool's structured result:
|
|
236
|
+
* `{ type: 'text', file: { filePath, content, numLines, startLine,
|
|
237
|
+
* totalLines } }`. Returns the file content verbatim, or null when `resp`
|
|
238
|
+
* doesn't carry a `file.content` string (falls through to the generic
|
|
239
|
+
* JSON.stringify floor).
|
|
240
|
+
*
|
|
241
|
+
* @param {Record<string, unknown>} resp
|
|
242
|
+
* @returns {string|null}
|
|
243
|
+
*/
|
|
244
|
+
function normalizeReadResponse(resp) {
|
|
245
|
+
const file = resp.file
|
|
246
|
+
if (!file || typeof file !== 'object' || typeof file.content !== 'string') return null
|
|
247
|
+
return file.content
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Render the built-in Write tool's structured result — `{ type:
|
|
252
|
+
* 'create'|'update', filePath, content, structuredPatch, originalFile,
|
|
253
|
+
* userModified }` — as the SAME short confirmation text
|
|
254
|
+
* `byok-tool-executor.js`'s `runWrite` already produces for a successful
|
|
255
|
+
* write, via the shared `formatWriteConfirmation` helper
|
|
256
|
+
* (built-in-tools/tool-transforms.js). NEVER the file body (#8082 PR
|
|
257
|
+
* review, Critical #1) — `resp.content` here is the entire written file,
|
|
258
|
+
* which is exactly why this function exists instead of letting rule 1b
|
|
259
|
+
* render it.
|
|
260
|
+
*
|
|
261
|
+
* `bytesWritten` isn't carried on the hook's `tool_response` the way it is
|
|
262
|
+
* on `byok-tool-executor.js`'s own write result, so it's derived from the
|
|
263
|
+
* written content's UTF-8 byte length — the same measure `writeFileTool`
|
|
264
|
+
* itself reports for an ordinary write.
|
|
265
|
+
*
|
|
266
|
+
* Only called when `isFileWriteResponseShape(resp)` is true — which can
|
|
267
|
+
* match on `structuredPatch` or `type` alone, so `filePath` is NOT
|
|
268
|
+
* guaranteed to be present here. A missing/non-string `filePath` or
|
|
269
|
+
* `content` still renders a confirmation (empty path / `0` bytes
|
|
270
|
+
* respectively) rather than throwing.
|
|
271
|
+
*
|
|
272
|
+
* @param {Record<string, unknown>} resp
|
|
273
|
+
* @returns {string}
|
|
274
|
+
*/
|
|
275
|
+
function normalizeWriteResponse(resp) {
|
|
276
|
+
const content = typeof resp.content === 'string' ? resp.content : ''
|
|
277
|
+
return formatWriteConfirmation({
|
|
278
|
+
bytesWritten: Buffer.byteLength(content, 'utf8'),
|
|
279
|
+
filePath: typeof resp.filePath === 'string' ? resp.filePath : '',
|
|
280
|
+
created: resp.type === 'create',
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Render the built-in Read tool's repeated-read result — `{ type:
|
|
286
|
+
* 'file_unchanged', file: { filePath } }` — as one plain sentence naming the
|
|
287
|
+
* file, instead of the JSON envelope (#8252). A missing path drops the
|
|
288
|
+
* parenthetical rather than printing an empty one.
|
|
289
|
+
*
|
|
290
|
+
* @param {Record<string, unknown>} resp
|
|
291
|
+
* @returns {string}
|
|
292
|
+
*/
|
|
293
|
+
function normalizeFileUnchangedResponse(resp) {
|
|
294
|
+
const filePath = resp.file && typeof resp.file === 'object' && typeof resp.file.filePath === 'string'
|
|
295
|
+
? resp.file.filePath
|
|
296
|
+
: ''
|
|
297
|
+
return filePath
|
|
298
|
+
? `File unchanged since it was last read (${filePath})`
|
|
299
|
+
: 'File unchanged since it was last read'
|
|
300
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chroxy agent — manage agent principals (agent-principals.md section 3).
|
|
3
|
+
*
|
|
4
|
+
* chroxy agent grant --label <label> --scope <tier> (--session <id> | --cwd <root>) [--ttl <dur>]
|
|
5
|
+
* chroxy agent list
|
|
6
|
+
* chroxy agent revoke <label-or-principalId>
|
|
7
|
+
* chroxy agent disable --all | --label <label>
|
|
8
|
+
* chroxy agent enable --all | --label <label>
|
|
9
|
+
*
|
|
10
|
+
* `list`, `revoke`, `disable` and `enable` ASK THE RUNNING DAEMON over the strict-primary, loopback-only
|
|
11
|
+
* `principal_admin_*` WebSocket types, with the primary token from connection.json,
|
|
12
|
+
* exactly as `chroxy agent-control` reaches it. The CLI never reads or writes the
|
|
13
|
+
* principal store: the daemon process is the only writer, so daemon and CLI cannot race.
|
|
14
|
+
*
|
|
15
|
+
* `grant` REFUSES until the audit writer and kill switch land (contract section 12
|
|
16
|
+
* landing order): it prints "agent principals not yet enabled" and exits non-zero without
|
|
17
|
+
* contacting the daemon, and no token is generated anywhere.
|
|
18
|
+
*/
|
|
19
|
+
import { PRINCIPALS_NOT_ENABLED_MESSAGE } from '../principal-store.js'
|
|
20
|
+
import { LIVENESS_UNVERIFIED_MESSAGE } from './connection-state.js'
|
|
21
|
+
|
|
22
|
+
const out = (s) => process.stdout.write(`${s}\n`)
|
|
23
|
+
const err = (s) => process.stderr.write(`${s}\n`)
|
|
24
|
+
|
|
25
|
+
/** Connect to the local daemon as the primary client; resolves a `{ request, close }` pair. */
|
|
26
|
+
async function connectToLocalDaemon(deps = {}) {
|
|
27
|
+
const resolveLocalConnection = deps.resolveLocalConnection || (await import('../agent-control/local-connection.js')).resolveLocalConnection
|
|
28
|
+
const conn = resolveLocalConnection()
|
|
29
|
+
// #9074/#9229: report the resolver's reason as it is. Every refusal happens before a
|
|
30
|
+
// credential-bearing connection is returned, so no token is used on any of them.
|
|
31
|
+
if (!conn.ok) return { ok: false, reason: conn.reason }
|
|
32
|
+
if (!conn.token) return { ok: false, reason: 'no_token' }
|
|
33
|
+
const { AgentControlClient } = deps.AgentControlClient ? { AgentControlClient: deps.AgentControlClient } : await import('../agent-control/client.js')
|
|
34
|
+
const client = new AgentControlClient({ url: conn.url, token: conn.token, silent: true, deviceName: 'chroxy-agent-cli' })
|
|
35
|
+
try {
|
|
36
|
+
await client.connect()
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return { ok: false, reason: 'unavailable', message: e?.message || 'connect failed' }
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
ok: true,
|
|
42
|
+
request: (type, fields) => client.request(type, fields, { replyType: 'principal_admin_result' }),
|
|
43
|
+
close: () => client.close(),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function reportConnectFailure(result) {
|
|
48
|
+
switch (result.reason) {
|
|
49
|
+
case 'not_running': err('Chroxy server is not running. Start it with `chroxy start`.'); break
|
|
50
|
+
case 'liveness_unverified': err(LIVENESS_UNVERIFIED_MESSAGE); break
|
|
51
|
+
case 'no_token': err('Server is running without an auth token: agent management is unavailable.'); break
|
|
52
|
+
default: err(`Could not reach the daemon: ${result.message || result.reason}`)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function ask(type, fields, deps) {
|
|
57
|
+
const conn = await (deps.connect || connectToLocalDaemon)(deps)
|
|
58
|
+
if (!conn.ok) return { ok: false, transport: true, ...conn }
|
|
59
|
+
try {
|
|
60
|
+
return { ok: true, reply: await conn.request(type, fields) }
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return { ok: false, transport: true, reason: 'unavailable', message: e?.message || 'request failed' }
|
|
63
|
+
} finally {
|
|
64
|
+
try { await conn.close() } catch { /* already closed */ }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function formatWhen(ms) {
|
|
69
|
+
return typeof ms === 'number' && Number.isFinite(ms) ? new Date(ms).toISOString() : '-'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* `chroxy agent grant`. REFUSES, and does not even contact the daemon: until the audit
|
|
74
|
+
* writer and kill switch land there is nothing to ask for, and no token is generated in
|
|
75
|
+
* this process or any other. Always a failure.
|
|
76
|
+
*/
|
|
77
|
+
export async function runAgentGrant(_options = {}, deps = {}) {
|
|
78
|
+
const e = deps.err || err
|
|
79
|
+
e(PRINCIPALS_NOT_ENABLED_MESSAGE)
|
|
80
|
+
return { ok: false, refused: true, reason: 'not_enabled' }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function runAgentList(options = {}, deps = {}) {
|
|
84
|
+
const w = deps.out || out
|
|
85
|
+
const e = deps.err || err
|
|
86
|
+
const result = await ask('principal_admin_list', {}, deps)
|
|
87
|
+
if (!result.ok) { reportConnectFailure(result); return result }
|
|
88
|
+
const reply = result.reply
|
|
89
|
+
if (reply.ok !== true) { e(`Request refused: ${reply.message || reply.code}`); return { ok: false, reply } }
|
|
90
|
+
if (options.json) { w(JSON.stringify(reply.principals, null, 2)); return { ok: true, reply } }
|
|
91
|
+
if (reply.health && reply.health.ok !== true) {
|
|
92
|
+
e(`Principal store is not trusted, every principal is refused: ${reply.health.reason}`)
|
|
93
|
+
return { ok: false, reply, reason: 'store_invalid' }
|
|
94
|
+
}
|
|
95
|
+
if (reply.principals.length === 0) { w('No agent principals.'); return { ok: true, reply } }
|
|
96
|
+
w(`${reply.principals.length} agent principal(s):`)
|
|
97
|
+
for (const p of reply.principals) {
|
|
98
|
+
w(` ${p.label} id=${p.principalId} scope=${p.scope} state=${p.state} expires=${formatWhen(p.expiresAt)}`)
|
|
99
|
+
}
|
|
100
|
+
return { ok: true, reply }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function runAgentRevoke(target, _options = {}, deps = {}) {
|
|
104
|
+
const w = deps.out || out
|
|
105
|
+
const e = deps.err || err
|
|
106
|
+
if (typeof target !== 'string' || target.length === 0) {
|
|
107
|
+
e('Name the principal to revoke: a label or a principal id (see: chroxy agent list).')
|
|
108
|
+
return { ok: false, reason: 'bad_args' }
|
|
109
|
+
}
|
|
110
|
+
// A label never contains an uppercase letter or a dot, and an id may; the daemon
|
|
111
|
+
// resolves a label among live grants and an id exactly, so ask with both selectors
|
|
112
|
+
// off one word: id first, then label.
|
|
113
|
+
let result = await ask('principal_admin_revoke', { principalId: target }, deps)
|
|
114
|
+
if (result.ok && result.reply?.code === 'NOT_FOUND') result = await ask('principal_admin_revoke', { label: target }, deps)
|
|
115
|
+
if (!result.ok) { reportConnectFailure(result); return result }
|
|
116
|
+
const reply = result.reply
|
|
117
|
+
if (reply.ok !== true) { e(`Revoke refused: ${reply.message || reply.code}`); return { ok: false, reply } }
|
|
118
|
+
if (reply.durable === false) {
|
|
119
|
+
e(`${reply.message || 'Revoked, but NOT durable: revoke again once the principal store is writable.'}`)
|
|
120
|
+
return { ok: false, reply, reason: 'not_durable' }
|
|
121
|
+
}
|
|
122
|
+
w(`Revoked ${reply.principalId}${reply.alreadyRevoked ? ' (it was already revoked)' : ''}. Its connections are closed.`)
|
|
123
|
+
return { ok: true, reply }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** `--all` xor `--label <label>`. Returns the request fields or null. */
|
|
127
|
+
function switchFields(options) {
|
|
128
|
+
const hasAll = options?.all === true
|
|
129
|
+
const hasLabel = typeof options?.label === 'string' && options.label.length > 0
|
|
130
|
+
if (hasAll === hasLabel) return null
|
|
131
|
+
return hasAll ? { all: true } : { label: options.label }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function describeSwitch(fields) {
|
|
135
|
+
return fields.all === true ? 'every agent principal' : `agent principals labelled ${fields.label}`
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* `chroxy agent disable --all | --label <label>`: the persistent kill switch. The daemon
|
|
140
|
+
* flips it in memory, persists it, then acknowledges; the exit status is non-zero when the
|
|
141
|
+
* switch could not be confirmed durable (it is still ON in the running daemon).
|
|
142
|
+
*/
|
|
143
|
+
export async function runAgentDisable(options = {}, deps = {}) {
|
|
144
|
+
const w = deps.out || out
|
|
145
|
+
const e = deps.err || err
|
|
146
|
+
const fields = switchFields(options)
|
|
147
|
+
if (fields === null) {
|
|
148
|
+
e('Name what to disable: --all, or --label <label> (not both).')
|
|
149
|
+
return { ok: false, reason: 'bad_args' }
|
|
150
|
+
}
|
|
151
|
+
const result = await ask('principal_admin_disable', fields, deps)
|
|
152
|
+
if (!result.ok) { reportConnectFailure(result); return result }
|
|
153
|
+
const reply = result.reply
|
|
154
|
+
if (reply.ok !== true) { e(`Disable refused: ${reply.message || reply.code}`); return { ok: false, reply } }
|
|
155
|
+
if (reply.durable === false) {
|
|
156
|
+
e(`${reply.message || 'Disabled, but NOT durable: disable again once the config directory is writable.'}`)
|
|
157
|
+
return { ok: false, reply, reason: 'not_durable' }
|
|
158
|
+
}
|
|
159
|
+
w(`Disabled ${describeSwitch(fields)} (durable). Their connections are closed; re-enable with: chroxy agent enable ${fields.all ? '--all' : `--label ${fields.label}`}`)
|
|
160
|
+
return { ok: true, reply }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** `chroxy agent enable --all | --label <label>`: explicit re-enable; never automatic. */
|
|
164
|
+
export async function runAgentEnable(options = {}, deps = {}) {
|
|
165
|
+
const w = deps.out || out
|
|
166
|
+
const e = deps.err || err
|
|
167
|
+
const fields = switchFields(options)
|
|
168
|
+
if (fields === null) {
|
|
169
|
+
e('Name what to enable: --all, or --label <label> (not both).')
|
|
170
|
+
return { ok: false, reason: 'bad_args' }
|
|
171
|
+
}
|
|
172
|
+
const result = await ask('principal_admin_enable', fields, deps)
|
|
173
|
+
if (!result.ok) { reportConnectFailure(result); return result }
|
|
174
|
+
const reply = result.reply
|
|
175
|
+
if (reply.ok !== true) { e(`Enable refused: ${reply.message || reply.code}`); return { ok: false, reply } }
|
|
176
|
+
if (reply.durable === false) {
|
|
177
|
+
e(`${reply.message || 'Enabled, but NOT durable.'}`)
|
|
178
|
+
return { ok: false, reply, reason: 'not_durable' }
|
|
179
|
+
}
|
|
180
|
+
w(`Enabled ${describeSwitch(fields)} (durable).`)
|
|
181
|
+
return { ok: true, reply }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function registerAgentCommand(program) {
|
|
185
|
+
const agent = program.command('agent').description('Manage agent principals: scoped, revocable credentials for a supervisor agent (agent-principals.md)')
|
|
186
|
+
|
|
187
|
+
agent
|
|
188
|
+
.command('grant')
|
|
189
|
+
.description('Grant a principal (refuses until agent principals are enabled)')
|
|
190
|
+
.option('--label <label>', 'Operator label, ^[a-z0-9_-]{1,32}$')
|
|
191
|
+
.option('--scope <tier>', 'observe | steer | drive | answer')
|
|
192
|
+
.option('--session <id>', 'Limit the grant to one session id')
|
|
193
|
+
.option('--cwd <root>', 'Limit the grant to sessions under a working-directory root')
|
|
194
|
+
.option('--ttl <dur>', 'Lifetime, at most 7 days (default 24h)')
|
|
195
|
+
.action(async (options) => {
|
|
196
|
+
await runAgentGrant(options)
|
|
197
|
+
process.exitCode = 1
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
agent
|
|
201
|
+
.command('list')
|
|
202
|
+
.description('List agent principals and their state')
|
|
203
|
+
.option('--json', 'Output machine-readable JSON')
|
|
204
|
+
.action(async (options) => {
|
|
205
|
+
const r = await runAgentList(options)
|
|
206
|
+
if (!r.ok) process.exitCode = 1
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
agent
|
|
210
|
+
.command('revoke <principal>')
|
|
211
|
+
.description('Revoke a principal by label or principal id, and close its connections')
|
|
212
|
+
.action(async (principal, options) => {
|
|
213
|
+
const r = await runAgentRevoke(principal, options)
|
|
214
|
+
if (!r.ok) process.exitCode = 1
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
agent
|
|
218
|
+
.command('disable')
|
|
219
|
+
.description('Kill switch: disable every agent principal (--all) or one label (--label), persistently, and close their connections')
|
|
220
|
+
.option('--all', 'Disable every agent principal')
|
|
221
|
+
.option('--label <label>', 'Disable the principals carrying this label')
|
|
222
|
+
.action(async (options) => {
|
|
223
|
+
const r = await runAgentDisable(options)
|
|
224
|
+
if (!r.ok) process.exitCode = 1
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
agent
|
|
228
|
+
.command('enable')
|
|
229
|
+
.description('Re-enable disabled agent principals (--all or --label); never automatic')
|
|
230
|
+
.option('--all', 'Re-enable every agent principal')
|
|
231
|
+
.option('--label <label>', 'Re-enable the principals carrying this label')
|
|
232
|
+
.action(async (options) => {
|
|
233
|
+
const r = await runAgentEnable(options)
|
|
234
|
+
if (!r.ok) process.exitCode = 1
|
|
235
|
+
})
|
|
236
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chroxy agent-control — stdio MCP server exposing this daemon's session
|
|
3
|
+
* control surface to an external agent harness (Codex, Claude, Gemini, …).
|
|
4
|
+
*
|
|
5
|
+
* chroxy agent-control --stdio → local daemon, read-write
|
|
6
|
+
* chroxy agent-control --stdio --read-only → local daemon, mutation tools absent
|
|
7
|
+
* chroxy agent-control --stdio --url wss://host --pin-identity <key>
|
|
8
|
+
* → remote daemon (token via env — see below)
|
|
9
|
+
* chroxy agent-control --stdio --url ws://host --allow-insecure-ws
|
|
10
|
+
* → remote daemon over cleartext ws:// (see below)
|
|
11
|
+
*
|
|
12
|
+
* This is a thin CLI wrapper around `agent-control/mcp-server.js`'s own
|
|
13
|
+
* `main()`, passing Commander's parsed options so both `--url value` and
|
|
14
|
+
* `--url=value` preserve the explicit target and identity pin. See
|
|
15
|
+
* docs/guides/agent-control.md for the full design, security
|
|
16
|
+
* model, and MCP-host configuration examples.
|
|
17
|
+
*
|
|
18
|
+
* There is deliberately NO `--token` flag: argv is visible to every other
|
|
19
|
+
* process on this machine via `ps`. A remote connection's token is read
|
|
20
|
+
* ONLY from the `CHROXY_AGENT_CONTROL_TOKEN` environment variable; the local
|
|
21
|
+
* (default) case needs no token in argv or config at all — it reads
|
|
22
|
+
* connection.json itself.
|
|
23
|
+
*
|
|
24
|
+
* A plain `ws://` URL to a host that is not loopback is REFUSED at startup
|
|
25
|
+
* (#7969): the bearer token goes out in the first `auth` frame, before any key
|
|
26
|
+
* exchange, so on cleartext `ws://` anyone on the network path can read it, and
|
|
27
|
+
* `--pin-identity` cannot protect it (the pin is checked only afterwards). Use
|
|
28
|
+
* `wss://`, or pass `--allow-insecure-ws` to accept that risk on a network you
|
|
29
|
+
* trust. "Loopback" is strict: `localhost`, an IPv4 address in 127.0.0.0/8, or
|
|
30
|
+
* `[::1]` — see `hostStaysOnThisMachine` in agent-control/local-connection.js. The
|
|
31
|
+
* flag is argv-only: a URL configured through CHROXY_AGENT_CONTROL_URL still
|
|
32
|
+
* needs `--allow-insecure-ws` in the arguments. The rule lives in
|
|
33
|
+
* `validateExplicitUrl` (agent-control/local-connection.js), shared by the
|
|
34
|
+
* resolver and `main()`'s startup check; this wrapper only declares the option.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export function registerAgentControlCommand(program) {
|
|
38
|
+
program
|
|
39
|
+
.command('agent-control')
|
|
40
|
+
// Boolean flags take no value, but Commander tolerates a stray positional
|
|
41
|
+
// word by default, so `--allow-insecure-ws false` (or `0`, or
|
|
42
|
+
// `--allow-command-approvals false`) parsed as the flag being SET: the
|
|
43
|
+
// operator wrote "false" and got cleartext transport / command approvals
|
|
44
|
+
// (#7969). Reject excess arguments on THIS command only, so a value after
|
|
45
|
+
// a boolean flag is an error instead of silently enabling it. The command
|
|
46
|
+
// takes no positional arguments, so nothing legitimate is lost.
|
|
47
|
+
.allowExcessArguments(false)
|
|
48
|
+
.description('Run a stdio MCP server exposing chroxy session control to an external agent harness (Codex, Claude, Gemini, …). Requires --stdio (the only supported mode). Remote connections read the token ONLY from CHROXY_AGENT_CONTROL_TOKEN — there is no --token flag.')
|
|
49
|
+
.option('--stdio', 'Run as a stdio MCP server (required — this command has no other mode)')
|
|
50
|
+
.option('--read-only', 'Disable mutation tools (create/send-input/interrupt/respond-permission)')
|
|
51
|
+
.option('--url <url>', 'Explicit remote daemon URL — never inferred; token via CHROXY_AGENT_CONTROL_TOKEN. Use wss://. A ws:// URL to any host other than loopback (localhost, 127.0.0.0/8, [::1]) is refused unless --allow-insecure-ws is given, because the token is sent in cleartext before any key exchange.')
|
|
52
|
+
.option('--allow-insecure-ws', 'Accept a ws:// --url (or CHROXY_AGENT_CONTROL_URL) to a non-loopback host, sending the bearer token in cleartext before any key exchange — anyone on the network path can read it and --pin-identity cannot protect it. Argv only: there is no environment-variable equivalent. Prints a startup WARNING. Prefer wss://.')
|
|
53
|
+
.option('--pin-identity <key>', "Pin the daemon's Ed25519 identity public key (base64) — or set CHROXY_AGENT_CONTROL_PIN")
|
|
54
|
+
.option('--allow-command-approvals', "Let the connected planner approve command-style tool calls (Bash, PowerShell, Monitor, codex shell) via chroxy_respond_permission — off by default because the protected-path floor cannot see through an arbitrary command string (e.g. `cat .env` looks like an ordinary, unfloored Bash call). Still subject to the floored/ownership gates. Logs a startup warning when enabled.")
|
|
55
|
+
.action(async (options) => {
|
|
56
|
+
if (!options.stdio) {
|
|
57
|
+
process.stderr.write('chroxy agent-control requires --stdio (the only supported mode).\n')
|
|
58
|
+
process.stderr.write('Usage: chroxy agent-control --stdio [--read-only] [--url <url>] [--pin-identity <key>] [--allow-command-approvals] [--allow-insecure-ws]\n')
|
|
59
|
+
process.exitCode = 1
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
const { main } = await import('../agent-control/mcp-server.js')
|
|
63
|
+
await main({ readOnly: options.readOnly, url: options.url, identityPublicKey: options.pinIdentity, allowCommandApprovals: options.allowCommandApprovals, allowInsecureWs: options.allowInsecureWs })
|
|
64
|
+
})
|
|
65
|
+
}
|
package/src/cli/config-cmd.js
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
* chroxy config — Show current configuration
|
|
3
3
|
*/
|
|
4
4
|
import { existsSync, readFileSync } from 'fs'
|
|
5
|
-
import {
|
|
5
|
+
import { configFile } from './shared.js'
|
|
6
6
|
|
|
7
7
|
export function registerConfigCommand(program) {
|
|
8
8
|
program
|
|
9
9
|
.command('config')
|
|
10
10
|
.description('Show current configuration')
|
|
11
11
|
.action(() => {
|
|
12
|
-
if (!existsSync(
|
|
12
|
+
if (!existsSync(configFile())) {
|
|
13
13
|
console.log('No config found. Run \'chroxy init\' first.')
|
|
14
14
|
process.exit(1)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const config = JSON.parse(readFileSync(
|
|
17
|
+
const config = JSON.parse(readFileSync(configFile(), 'utf-8'))
|
|
18
18
|
|
|
19
19
|
console.log('\n📋 Current Configuration\n')
|
|
20
|
-
console.log(` Config file: ${
|
|
20
|
+
console.log(` Config file: ${configFile()}`)
|
|
21
21
|
console.log(` Port: ${config.port}`)
|
|
22
22
|
const tunnelMode = config.tunnel || 'quick'
|
|
23
23
|
if (tunnelMode === 'named') {
|