@chroxy/server 0.10.0 → 0.11.10
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 +602 -19
- package/README.md +2 -2
- package/hooks/claude-native-route-check.mjs +17 -0
- package/hooks/permission-hook.sh +416 -11
- package/package.json +20 -23
- 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 +954 -0
- package/src/activity-registry.js +110 -5
- package/src/agent-connections.js +293 -0
- package/src/agent-control/client.js +1616 -0
- package/src/agent-control/events.js +547 -0
- package/src/agent-control/local-connection.js +275 -0
- package/src/agent-control/mcp-server.js +545 -0
- package/src/anthropic-compatible-config.js +29 -4
- package/src/anthropic-compatible-session.js +15 -6
- 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 +1353 -41
- package/src/bearer-recheck.js +49 -0
- package/src/billing-budget.js +24 -1
- package/src/billing-class.js +40 -7
- package/src/binary-provenance-trust.js +101 -0
- package/src/bound-client-policy.js +279 -0
- package/src/built-in-tools/bash-exec.js +46 -7
- package/src/built-in-tools/file-ops.js +74 -9
- 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 +1153 -20
- package/src/byok-mcp-config.js +1712 -8
- package/src/byok-mcp-fleet.js +416 -29
- package/src/byok-mcp-oauth-store.js +329 -0
- package/src/byok-mcp-oauth.js +635 -0
- package/src/byok-mcp-trust.js +257 -40
- package/src/byok-session.js +1400 -149
- package/src/byok-tool-executor.js +2681 -38
- package/src/byok-tools.js +9 -2
- package/src/channels/chroxy-channel-server.js +2 -3
- package/src/checkpoint-manager.js +96 -51
- package/src/chroxy-host-metadata.js +122 -0
- 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-stream-parser.js +109 -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 +223 -60
- 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 +3611 -286
- package/src/claude-tui-tool-response.js +300 -0
- package/src/cli/agent-control-cmd.js +65 -0
- package/src/cli/config-cmd.js +6 -6
- package/src/cli/config-dir-cmd.js +234 -0
- package/src/cli/deploy-cmd.js +46 -11
- package/src/cli/doctor-cmd.js +7 -3
- package/src/cli/init-cmd.js +16 -17
- package/src/cli/providers-cmd.js +6 -6
- package/src/cli/schedule-cmd.js +804 -0
- package/src/cli/server-cmd.js +64 -2
- package/src/cli/service-cmd.js +70 -27
- package/src/cli/session-cmd.js +227 -74
- package/src/cli/shared.js +168 -14
- package/src/cli/tokens-cmd.js +212 -0
- package/src/cli/tunnel-cmd.js +256 -25
- package/src/cli/worktree-gc-cmd.js +2 -2
- package/src/cli-session.js +1117 -116
- package/src/cli.js +8 -0
- package/src/codex-app-server-client.js +36 -3
- package/src/codex-app-server-session.js +2108 -101
- package/src/codex-bundled-client.js +66 -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 +571 -45
- package/src/config-dir-migration.js +444 -0
- package/src/config-dir.js +108 -0
- package/src/config.js +738 -52
- package/src/connection-authority.js +48 -0
- package/src/connection-info.js +5 -9
- 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 +114 -0
- package/src/control-room/host-prune.js +5 -0
- package/src/control-room/integrations.js +23 -30
- package/src/control-room/skills-inventory.js +8 -3
- package/src/control-room/survey.js +32 -0
- package/src/conversation-scanner.js +40 -18
- package/src/conversation-scope.js +59 -39
- package/src/conversation-search.js +24 -22
- package/src/credential-store.js +279 -29
- 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 +169 -182
- package/src/device-preferences.js +2 -2
- package/src/diagnostics.js +3 -0
- 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 +188 -4
- package/src/docker-session.js +293 -10
- package/src/doctor.js +783 -66
- package/src/edited-input.js +264 -0
- package/src/environment-manager.js +175 -36
- package/src/environments/authority.js +95 -0
- package/src/environments/backends/container-claude-spawn.js +94 -0
- package/src/environments/backends/docker.js +39 -10
- package/src/environments/backends/k8s.js +58 -24
- package/src/environments/destroy-with-sessions.js +142 -0
- package/src/event-ingest.js +137 -14
- package/src/event-normalizer.js +363 -110
- package/src/external-session-registry.js +0 -0
- package/src/gemini-session.js +100 -7
- package/src/github-webhook.js +188 -4
- package/src/handler-utils.js +563 -62
- package/src/handlers/checkpoint-handlers.js +162 -20
- package/src/handlers/control-room-handlers.js +99 -29
- package/src/handlers/conversation-handlers.js +563 -25
- package/src/handlers/credential-handlers.js +43 -2
- 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 +101 -13
- package/src/handlers/github-webhook-handlers.js +204 -0
- package/src/handlers/input-handlers.js +689 -48
- package/src/handlers/orchestration-handlers.js +238 -0
- package/src/handlers/scheduler-handlers.js +584 -0
- package/src/handlers/session-handlers.js +546 -16
- 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 +822 -35
- package/src/handlers/skills-handlers.js +13 -4
- package/src/handlers/summarize-handlers.js +32 -1
- package/src/handlers/survey-throttle.js +380 -0
- package/src/handlers/token-handlers.js +11 -2
- package/src/health-proof.js +40 -0
- package/src/history-page.js +104 -0
- package/src/http-routes.js +286 -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 +309 -48
- package/src/jsonl-subprocess-session.js +122 -9
- package/src/keychain.js +160 -13
- package/src/logger.js +240 -31
- package/src/mailbox-route.js +11 -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 +100 -10
- 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 +82 -12
- 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 +63 -0
- package/src/orchestration/decision-contract.js +245 -0
- package/src/orchestration/git-ops.js +381 -0
- package/src/orchestration/orchestration-manager.js +1342 -0
- package/src/orchestration/permission-gate.js +121 -0
- package/src/orchestration/role-prompts.js +136 -0
- package/src/orchestration/run-budget.js +81 -0
- package/src/orchestration/run-ledger.js +487 -0
- package/src/orchestration/run-model.js +206 -0
- package/src/orchestration/run-record.js +336 -0
- package/src/orchestration/run-report.js +194 -0
- package/src/orchestration/to-wire.js +201 -0
- package/src/orchestration/turn-driver.js +422 -0
- package/src/orphan-reaper.js +413 -0
- package/src/outgoing-policy.js +183 -0
- package/src/pairing.js +236 -12
- package/src/path-hash-trust-ledger.js +642 -25
- package/src/permission-audit.js +79 -3
- package/src/permission-deadlines.js +82 -0
- package/src/permission-floor.js +1770 -0
- package/src/permission-hook.js +180 -69
- package/src/permission-manager.js +1175 -94
- package/src/permission-mode-support.js +35 -0
- package/src/permission-resolver.js +174 -12
- package/src/permission-rule-store.js +411 -0
- package/src/permission-scope.js +43 -0
- package/src/platform.js +483 -23
- package/src/preview-ingress.js +54 -0
- package/src/preview-target.js +213 -0
- package/src/prompt-evaluator.js +34 -4
- package/src/provider-customization.js +180 -0
- package/src/providers.js +228 -6
- package/src/push.js +30 -4
- package/src/question-route-map.js +130 -0
- package/src/redaction.js +360 -8
- package/src/roster-broadcast.js +186 -0
- package/src/schedule-parser.js +311 -0
- package/src/scheduled-task-store.js +945 -0
- package/src/scheduler.js +1099 -0
- package/src/sdk-session.js +2374 -168
- package/src/server-cli/preview-shutdown.js +22 -0
- package/src/server-cli/push-notification-handler.js +11 -2
- package/src/server-cli/server-orchestrator.js +50 -4
- package/src/server-cli/tunnel-lifecycle-handler.js +3 -2
- package/src/server-cli-child.js +33 -18
- package/src/server-cli.js +760 -62
- package/src/server-identity.js +42 -14
- package/src/service.js +682 -53
- 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 +926 -0
- package/src/session-context.js +7 -2
- package/src/session-manager.js +3879 -308
- package/src/session-message-history.js +749 -37
- 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-title.js +168 -0
- package/src/session-token-store.js +70 -36
- 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 +22 -5
- package/src/snapshots-store.js +2 -3
- package/src/statusline.js +596 -0
- package/src/subagent-counter.js +9 -1
- package/src/summarize-session.js +51 -4
- package/src/supervisor.js +99 -38
- 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/token-manager.js +39 -9
- package/src/tool-result.js +61 -0
- package/src/transcript-sources.js +109 -0
- package/src/transcript-tasks.js +413 -31
- package/src/trusted-file-read.js +302 -0
- package/src/tunnel/base.js +0 -8
- package/src/tunnel/cloudflare.js +145 -35
- package/src/tunnel/index.js +13 -1
- package/src/tunnel/preview.js +64 -0
- package/src/tunnel-check.js +1 -1
- package/src/turn-outcome.js +137 -0
- package/src/turn-tracker.js +0 -0
- package/src/usage-normalize.js +122 -0
- package/src/user-shell-session.js +157 -37
- package/src/utils/agent-sdk-version.js +107 -0
- package/src/utils/argv-safety.js +741 -0
- package/src/utils/auth-cause.js +60 -0
- package/src/utils/binary-package-manifest.js +597 -0
- package/src/utils/binary-version.js +224 -0
- package/src/utils/bounded-regex-worker.js +25 -0
- package/src/utils/bounded-regex.js +153 -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 +301 -0
- package/src/utils/composite-key.js +45 -0
- 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/iso-datetime.js +51 -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/preflight.js +485 -29
- 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 +196 -5
- package/src/utils/stale-session-dirs.js +182 -0
- package/src/utils/stat-identity.js +43 -0
- package/src/utils/verify-binary.js +276 -0
- package/src/utils/verify-provenance.js +634 -0
- package/src/utils/wire-counters.js +48 -0
- package/src/web-task-manager.js +256 -16
- package/src/worktree-gc.js +11 -3
- package/src/ws-auth.js +69 -21
- package/src/ws-broadcaster.js +14 -2
- package/src/ws-client-manager.js +16 -1
- package/src/ws-client-sender.js +7 -0
- package/src/ws-file-ops/browser.js +370 -66
- package/src/ws-file-ops/common.js +384 -11
- package/src/ws-file-ops/git.js +615 -44
- package/src/ws-file-ops/index.js +7 -0
- package/src/ws-file-ops/memory.js +460 -0
- package/src/ws-file-ops/open-nofollow.js +354 -0
- package/src/ws-file-ops/reader.js +676 -94
- package/src/ws-forwarding.js +373 -55
- package/src/ws-handler-context.js +89 -2
- package/src/ws-history.js +1018 -177
- package/src/ws-message-handlers.js +23 -1
- package/src/ws-outbound-schemas.js +207 -0
- package/src/ws-permissions.js +589 -38
- package/src/ws-schemas.js +6 -0
- package/src/ws-server.js +936 -105
- 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/sidecar/agent.js
CHANGED
|
@@ -13,9 +13,9 @@ import { createServer } from 'node:http'
|
|
|
13
13
|
import { createInterface } from 'node:readline'
|
|
14
14
|
import { spawn as nodeSpawn } from 'node:child_process'
|
|
15
15
|
import { timingSafeEqual, randomUUID } from 'node:crypto'
|
|
16
|
-
import { readFileSync } from 'node:fs'
|
|
16
|
+
import { readFileSync, realpathSync } from 'node:fs'
|
|
17
17
|
import { fileURLToPath } from 'node:url'
|
|
18
|
-
import { dirname, join } from 'node:path'
|
|
18
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
19
19
|
import { Transform } from 'node:stream'
|
|
20
20
|
import { WebSocketServer } from 'ws'
|
|
21
21
|
|
|
@@ -129,6 +129,8 @@ const AGENT_TOKEN = process.env.CHROXY_AGENT_TOKEN ?? null
|
|
|
129
129
|
// environment. The child is the user-facing CLI; agent-internal credentials
|
|
130
130
|
// have no business being readable from inside it.
|
|
131
131
|
const AGENT_SECRET_ENV_KEYS = ['CHROXY_AGENT_TOKEN']
|
|
132
|
+
// Env names a spawn frame may ask the agent to remove from the child's env (`unsetEnv`).
|
|
133
|
+
const UNSETTABLE_ENV_KEYS = new Set(['CLAUDE_CONFIG_DIR'])
|
|
132
134
|
|
|
133
135
|
// Constant-time token comparison — adapted from token-compare.js in the main server.
|
|
134
136
|
function safeTokenCompare(a, b) {
|
|
@@ -232,6 +234,12 @@ export class PodAgent {
|
|
|
232
234
|
* @param {number} [opts.stdinDrainTimeoutMs] Override wedged-child drain timeout in ms (tests).
|
|
233
235
|
* @param {Function} [opts.setTimeoutFn] Override setTimeout for deterministic timer tests.
|
|
234
236
|
* @param {Function} [opts.clearTimeoutFn] Override clearTimeout for deterministic timer tests.
|
|
237
|
+
* @param {Function} [opts.nowFn] Override Date.now for deterministic ACTIVITY tests (#7690).
|
|
238
|
+
* `lastActiveAt` decides which session the size cap evicts,
|
|
239
|
+
* and it is REWRITTEN on every emitted frame — so a test that
|
|
240
|
+
* pins it can have the pin overwritten by a frame that lands
|
|
241
|
+
* a moment later. Injecting the clock is what makes that
|
|
242
|
+
* ordering a property of the test rather than of the machine.
|
|
235
243
|
*/
|
|
236
244
|
constructor({ spawnFn = nodeSpawn, token = AGENT_TOKEN, killGraceMs = KILL_GRACE_MS,
|
|
237
245
|
stdinCloseGraceMs = DEFAULT_STDIN_CLOSE_GRACE_MS,
|
|
@@ -241,7 +249,8 @@ export class PodAgent {
|
|
|
241
249
|
maxSessions = DEFAULT_MAX_SESSIONS,
|
|
242
250
|
stdinDrainTimeoutMs = DEFAULT_STDIN_DRAIN_TIMEOUT_MS,
|
|
243
251
|
setTimeoutFn = setTimeout,
|
|
244
|
-
clearTimeoutFn = clearTimeout
|
|
252
|
+
clearTimeoutFn = clearTimeout,
|
|
253
|
+
nowFn = Date.now } = {}) {
|
|
245
254
|
this._spawnFn = spawnFn
|
|
246
255
|
this._token = token
|
|
247
256
|
this._killGraceMs = killGraceMs
|
|
@@ -268,6 +277,12 @@ export class PodAgent {
|
|
|
268
277
|
: FALLBACK_STDIN_DRAIN_TIMEOUT_MS
|
|
269
278
|
this._setTimeoutFn = setTimeoutFn
|
|
270
279
|
this._clearTimeoutFn = clearTimeoutFn
|
|
280
|
+
this._nowFn = nowFn
|
|
281
|
+
// Monotonic creation counter, used ONLY to break `lastActiveAt` ties in
|
|
282
|
+
// `_enforceSessionCap`. Insertion order already decided them, but only as a
|
|
283
|
+
// side effect of Map iteration — an implicit rule nothing stated and no test
|
|
284
|
+
// could fail on (#7690).
|
|
285
|
+
this._sessionSeq = 0
|
|
271
286
|
|
|
272
287
|
// Fail-secure warning. Emitted from the constructor (not module-load) so
|
|
273
288
|
// tests and embedders that pass an explicit `token` don't see a misleading
|
|
@@ -630,11 +645,21 @@ export class PodAgent {
|
|
|
630
645
|
_enforceSessionCap() {
|
|
631
646
|
if (this._sessions.size < this._maxSessions) return
|
|
632
647
|
|
|
648
|
+
// Strictly older, or the same age and created FIRST. The tie-break is
|
|
649
|
+
// explicit since #7690: `lastActiveAt` comes from a clock, two sessions can
|
|
650
|
+
// share a millisecond (Windows' timer granularity is ~15.6ms), and with a
|
|
651
|
+
// bare `<` the winner was then decided by Map iteration order. That gave the
|
|
652
|
+
// right answer — insertion order IS creation order — but as a side effect
|
|
653
|
+
// nothing stated and no test could fail on. `createdSeq` makes the ordering
|
|
654
|
+
// total, so it is a property of the data rather than of the container.
|
|
655
|
+
const isOlder = (a, b) => a.lastActiveAt < b.lastActiveAt ||
|
|
656
|
+
(a.lastActiveAt === b.lastActiveAt && a.createdSeq < b.createdSeq)
|
|
657
|
+
|
|
633
658
|
// Prefer evicting idle sessions (no activeWs) over live ones.
|
|
634
659
|
let evictTarget = null
|
|
635
660
|
for (const session of this._sessions.values()) {
|
|
636
661
|
if (session.activeWs !== null) continue
|
|
637
|
-
if (evictTarget === null || session
|
|
662
|
+
if (evictTarget === null || isOlder(session, evictTarget)) {
|
|
638
663
|
evictTarget = session
|
|
639
664
|
}
|
|
640
665
|
}
|
|
@@ -642,7 +667,7 @@ export class PodAgent {
|
|
|
642
667
|
// Fall back to evicting the globally oldest session if all are active.
|
|
643
668
|
if (evictTarget === null) {
|
|
644
669
|
for (const session of this._sessions.values()) {
|
|
645
|
-
if (evictTarget === null || session
|
|
670
|
+
if (evictTarget === null || isOlder(session, evictTarget)) {
|
|
646
671
|
evictTarget = session
|
|
647
672
|
}
|
|
648
673
|
}
|
|
@@ -772,7 +797,7 @@ export class PodAgent {
|
|
|
772
797
|
// ---------------------------------------------------------------------------
|
|
773
798
|
|
|
774
799
|
_handleSpawn(ws, msg) {
|
|
775
|
-
const { cmd, args = [], env = {}, cwd, stdin: stdinMode = 'pipe' } = msg
|
|
800
|
+
const { cmd, args = [], env = {}, unsetEnv, cwd, stdin: stdinMode = 'pipe' } = msg
|
|
776
801
|
|
|
777
802
|
if (!cmd) {
|
|
778
803
|
this._send(ws, { type: 'error', message: 'spawn: cmd is required' })
|
|
@@ -815,6 +840,14 @@ export class PodAgent {
|
|
|
815
840
|
stdio: [resolvedStdin, 'pipe', 'pipe'],
|
|
816
841
|
env: { ...sanitizedAgentEnv, ...env },
|
|
817
842
|
}
|
|
843
|
+
// Variables the spawner asks to have removed from the merged env (the agent's
|
|
844
|
+
// own env, e.g. one defined by the image or pod, would otherwise survive).
|
|
845
|
+
// Only an allowlisted name is honoured.
|
|
846
|
+
if (Array.isArray(unsetEnv)) {
|
|
847
|
+
for (const key of unsetEnv) {
|
|
848
|
+
if (UNSETTABLE_ENV_KEYS.has(key)) delete spawnOpts.env[key]
|
|
849
|
+
}
|
|
850
|
+
}
|
|
818
851
|
if (cwd) spawnOpts.cwd = cwd
|
|
819
852
|
|
|
820
853
|
let child
|
|
@@ -839,7 +872,17 @@ export class PodAgent {
|
|
|
839
872
|
activeWs: ws,
|
|
840
873
|
seq: 0,
|
|
841
874
|
buffer: [],
|
|
842
|
-
|
|
875
|
+
// INERT TODAY, and kept deliberately. A stderr frame is emitted
|
|
876
|
+
// immediately after spawn, and `_emitSessionFrame` re-stamps
|
|
877
|
+
// `lastActiveAt`, so this initial value is overwritten before anything
|
|
878
|
+
// can read it — measured by tracing every write on a real spawn, and the
|
|
879
|
+
// reason a mutant that swaps this one call for `Date.now()` survives the
|
|
880
|
+
// suite while the other two do not (#7690 review). It stays on `_nowFn`
|
|
881
|
+
// because a field initialised from a different clock than it is updated
|
|
882
|
+
// from is a trap for the first path that creates a session without
|
|
883
|
+
// emitting, not because a test can currently tell.
|
|
884
|
+
lastActiveAt: this._nowFn(),
|
|
885
|
+
createdSeq: ++this._sessionSeq,
|
|
843
886
|
idleTimer: null,
|
|
844
887
|
// Cooperative backpressure flag for child.stdin.write() (#3396).
|
|
845
888
|
// True while a 'drain' listener is armed and the WS is paused.
|
|
@@ -1166,7 +1209,7 @@ export class PodAgent {
|
|
|
1166
1209
|
|
|
1167
1210
|
// Attach this WS to the session and refresh activity timestamp.
|
|
1168
1211
|
session.activeWs = ws
|
|
1169
|
-
session.lastActiveAt =
|
|
1212
|
+
session.lastActiveAt = this._nowFn()
|
|
1170
1213
|
ws._sessionId = sessionId
|
|
1171
1214
|
|
|
1172
1215
|
// Replay any buffered frames the client hasn't seen yet (seq > lastSeq).
|
|
@@ -1204,7 +1247,7 @@ export class PodAgent {
|
|
|
1204
1247
|
*/
|
|
1205
1248
|
_emitSessionFrame(session, frame, cb) {
|
|
1206
1249
|
session.seq += 1
|
|
1207
|
-
session.lastActiveAt =
|
|
1250
|
+
session.lastActiveAt = this._nowFn()
|
|
1208
1251
|
const seqFrame = { ...frame, seq: session.seq }
|
|
1209
1252
|
|
|
1210
1253
|
// Ring buffer: drop oldest entry when at capacity.
|
|
@@ -1274,7 +1317,56 @@ export class PodAgent {
|
|
|
1274
1317
|
// Entrypoint — only runs when executed directly, not when imported in tests.
|
|
1275
1318
|
// ---------------------------------------------------------------------------
|
|
1276
1319
|
|
|
1277
|
-
|
|
1320
|
+
// Realpath both sides. Node's ESM loader resolves symlinks in
|
|
1321
|
+
// `import.meta.url` while argv[1] is whatever the caller typed, so a raw
|
|
1322
|
+
// comparison also breaks on any relative invocation (`node ./agent.js`).
|
|
1323
|
+
// This is a standalone in-pod bundle with its own package.json, so it cannot
|
|
1324
|
+
// import packages/server/src/utils/is-entry-point.js — duplicated on purpose
|
|
1325
|
+
// (#7213). The body below runs the same code as that file and as
|
|
1326
|
+
// scripts/lib/is-entry-point.mjs — inlined as an IIFE, so it reads
|
|
1327
|
+
// `import.meta.url` directly rather than taking it as a parameter. The drift
|
|
1328
|
+
// gate in scripts/__tests__/is-entry-point.test.mjs compares all three with
|
|
1329
|
+
// comments stripped and fails if they diverge; change one, change all (#7222).
|
|
1330
|
+
const invokedDirectly = (() => {
|
|
1331
|
+
if (!process.argv[1]) return false
|
|
1332
|
+
// The plain comparison runs first and is conclusive on its own: identical
|
|
1333
|
+
// paths mean this IS the entry point, decided without touching the
|
|
1334
|
+
// filesystem. Consulting realpath first and reading a failure as false lets
|
|
1335
|
+
// an EACCES on a parent directory (or a script unlinked after launch) turn a
|
|
1336
|
+
// direct run into a silent exit-0 no-op — the exact class this guard exists
|
|
1337
|
+
// to remove (#7217 review). Realpath is only needed when the paths differ,
|
|
1338
|
+
// where a symlink is the sole thing that can still make them one file.
|
|
1339
|
+
const self = fileURLToPath(import.meta.url)
|
|
1340
|
+
const invoked = resolve(process.argv[1])
|
|
1341
|
+
if (self === invoked) return true
|
|
1342
|
+
const failures = []
|
|
1343
|
+
const real = (p) => {
|
|
1344
|
+
try {
|
|
1345
|
+
return realpathSync(p)
|
|
1346
|
+
} catch (err) {
|
|
1347
|
+
failures.push({ path: p, code: err.code || err.message })
|
|
1348
|
+
return null
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
const realSelf = real(self)
|
|
1352
|
+
const realInvoked = real(invoked)
|
|
1353
|
+
if (realSelf !== null && realInvoked !== null) return realSelf === realInvoked
|
|
1354
|
+
|
|
1355
|
+
// Undecidable, but not silent (#7226): in a pod, an agent that starts and
|
|
1356
|
+
// does nothing is indistinguishable from one that is merely idle, so the
|
|
1357
|
+
// reason has to reach the container log. See the twin in
|
|
1358
|
+
// packages/server/src/utils/is-entry-point.js for why this warns on ANY
|
|
1359
|
+
// realpath failure rather than carving out ENOENT.
|
|
1360
|
+
const why = failures.map(({ path, code }) => `${path}: ${code}`).join('; ')
|
|
1361
|
+
console.warn(
|
|
1362
|
+
`[is-entry-point] ${basename(self)}: cannot determine whether this module was run ` +
|
|
1363
|
+
`directly — realpath failed (${why}). Assuming it was imported, so its command-line ` +
|
|
1364
|
+
'behaviour did NOT run. If you invoked it directly, it did nothing.',
|
|
1365
|
+
)
|
|
1366
|
+
return false
|
|
1367
|
+
})()
|
|
1368
|
+
|
|
1369
|
+
if (invokedDirectly) {
|
|
1278
1370
|
const agent = new PodAgent()
|
|
1279
1371
|
agent.listen(PORT).catch((err) => {
|
|
1280
1372
|
console.error('[chroxy-pod-agent] Failed to start:', err)
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"node_modules/ws": {
|
|
22
|
-
"version": "8.
|
|
23
|
-
"resolved": "https://registry.npmjs.org/ws/-/ws-8.
|
|
24
|
-
"integrity": "sha512-
|
|
22
|
+
"version": "8.21.3",
|
|
23
|
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.3.tgz",
|
|
24
|
+
"integrity": "sha512-201TZ/kPWxoPr/OKWjquZR1SWKXcvxdH+e1xrx89b3YbmzLMFCLfnaG1HFIgWzJOEWZ7MvpK++odZufgYR50Rw==",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">=10.0.0"
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config-driven ACP (Agent Client Protocol) provider endpoints (#7319, part of
|
|
3
|
+
* the #7304/#7306 ACP-interop tranche) — validation + normalization for the
|
|
4
|
+
* `providers.acp` config block.
|
|
5
|
+
*
|
|
6
|
+
* Any agent that speaks ACP (see https://agentclientprotocol.com) can be
|
|
7
|
+
* declared in config.json under `providers.acp` and registered as a
|
|
8
|
+
* first-class provider at startup — one spawn `command`/`args`/`env`, no
|
|
9
|
+
* bespoke session class. Entries are validated here and registered by
|
|
10
|
+
* `registerAcpProviders` (acp-session.js).
|
|
11
|
+
*
|
|
12
|
+
* Entry shape:
|
|
13
|
+
* {
|
|
14
|
+
* "id": "my-agent", // required — provider id (lowercase, digits, dashes)
|
|
15
|
+
* "label": "My Agent", // optional — dashboard label (defaults to id)
|
|
16
|
+
* "command": "/path/to/agent-cli", // required — executable spawned over stdio (absolute path or PATH-resolvable)
|
|
17
|
+
* "args": ["--acp"], // optional — argv passed to the executable (default [])
|
|
18
|
+
* "env": { "SOME_VAR": "value" } // optional — extra environment variables for the child (default {})
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* Unlike the Anthropic/OpenAI-compatible blocks' `apiKeyEnv`/`credentialsKey`
|
|
22
|
+
* indirection, `env` here is a literal passthrough: ACP agents authenticate
|
|
23
|
+
* themselves (their own OAuth / API-key story), so there is no chroxy-side
|
|
24
|
+
* credential to name — the same shape Zed's `agent_servers` config uses. This
|
|
25
|
+
* module only validates that every value is a string (a malformed non-string
|
|
26
|
+
* value would otherwise reach `child_process.spawn`'s env object as-is);
|
|
27
|
+
* whether config.json is an appropriate place to put a given value is the
|
|
28
|
+
* operator's call, same as any locally-edited config file. The AMBIENT
|
|
29
|
+
* daemon environment does NOT pass through to the child by default — the
|
|
30
|
+
* agent's `command` is entirely operator-chosen and unvetted, so
|
|
31
|
+
* `buildAcpChildEnv` (acp-session.js) uses the ALLOWLIST posture
|
|
32
|
+
* `spawn-env.js` reserves for third-party providers (`STANDARD_ALLOWLIST`),
|
|
33
|
+
* not the denylist posture reserved for the first-party Claude CLI: nothing
|
|
34
|
+
* outside that baseline reaches the child unless THIS `env` map adds it.
|
|
35
|
+
* Chroxy's OWN daemon secret (the primary bearer token,
|
|
36
|
+
* `CHROXY_SECRET_DENYLIST` in spawn-env.js) is additionally stripped
|
|
37
|
+
* UNCONDITIONALLY at spawn time — applied in acp-session.js AFTER this map is
|
|
38
|
+
* merged in, so it can never be smuggled back in via this map either.
|
|
39
|
+
*
|
|
40
|
+
* Permissions ship DENIED BY DEFAULT for every entry registered from this
|
|
41
|
+
* block (#7319) — there is no config knob to change that yet. #7320 wires the
|
|
42
|
+
* real permission bridge.
|
|
43
|
+
*
|
|
44
|
+
* This module is deliberately dependency-free (no SDK, no logger) so
|
|
45
|
+
* config.js can import it without pulling the spawn/ACP-SDK machinery into
|
|
46
|
+
* the config-load path — same rationale as anthropic-compatible-config.js.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
// Reused (not duplicated) — this IS the live "which ids can a config-driven
|
|
50
|
+
// provider never claim" list. `PROVIDER_ID_RE` below is a local literal
|
|
51
|
+
// copy of anthropic-compatible-config.js's own regex rather than an import:
|
|
52
|
+
// that module documents duplicating its own char-class regexes (the Rancher
|
|
53
|
+
// note in config.js) precisely so this module can stay import-light; the
|
|
54
|
+
// RESERVED ID list is different — a real, growing set of names — so THAT is
|
|
55
|
+
// worth importing to avoid drift.
|
|
56
|
+
import { RESERVED_PROVIDER_IDS } from './anthropic-compatible-config.js'
|
|
57
|
+
|
|
58
|
+
export { RESERVED_PROVIDER_IDS }
|
|
59
|
+
|
|
60
|
+
// Provider id charset — mirrors anthropic-compatible-config.js's
|
|
61
|
+
// `PROVIDER_ID_RE` verbatim: lowercase letter first, then lowercase letters,
|
|
62
|
+
// digits, or dashes; max 64 chars.
|
|
63
|
+
const PROVIDER_ID_RE = /^[a-z][a-z0-9-]{0,63}$/
|
|
64
|
+
|
|
65
|
+
// #7547: exported + `*_ENTRY_KEYS` so the CONFIG.md doc gate compares the ACP entry
|
|
66
|
+
// shape on the `providers` row against this set (see COMPATIBLE_ENTRY_KEYS).
|
|
67
|
+
export const ACP_ENTRY_KEYS = new Set(['id', 'label', 'command', 'args', 'env'])
|
|
68
|
+
|
|
69
|
+
function typeName(value) {
|
|
70
|
+
return Array.isArray(value) ? 'array' : typeof value
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Validate ONE entry; returns the normalized frozen entry, or null when the
|
|
75
|
+
* entry must be dropped. Pushes human-readable warnings either way.
|
|
76
|
+
*/
|
|
77
|
+
function validateEntry(raw, path, seenIds, reservedIds, warnings) {
|
|
78
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
79
|
+
warnings.push(`Invalid value for '${path}': expected an object, got ${typeName(raw)}`)
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let valid = true
|
|
84
|
+
|
|
85
|
+
for (const key of Object.keys(raw)) {
|
|
86
|
+
if (!ACP_ENTRY_KEYS.has(key)) {
|
|
87
|
+
warnings.push(`Unknown key '${path}.${key}' (will be ignored)`)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// --- id ---
|
|
92
|
+
const id = raw.id
|
|
93
|
+
if (typeof id !== 'string' || !PROVIDER_ID_RE.test(id)) {
|
|
94
|
+
warnings.push(
|
|
95
|
+
`Invalid value for '${path}.id': expected a lowercase identifier (letters, digits, dashes; must start with a letter, max 64 chars), got ${JSON.stringify(id)}`,
|
|
96
|
+
)
|
|
97
|
+
valid = false
|
|
98
|
+
} else if (reservedIds.has(id)) {
|
|
99
|
+
warnings.push(`Invalid value for '${path}.id': '${id}' collides with a built-in or already-registered provider id`)
|
|
100
|
+
valid = false
|
|
101
|
+
} else if (seenIds.has(id)) {
|
|
102
|
+
warnings.push(`Invalid value for '${path}.id': duplicate id '${id}' (already declared by an earlier entry)`)
|
|
103
|
+
valid = false
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// --- label ---
|
|
107
|
+
let label = typeof id === 'string' ? id : null
|
|
108
|
+
if (Object.prototype.hasOwnProperty.call(raw, 'label')) {
|
|
109
|
+
if (typeof raw.label !== 'string' || raw.label.length === 0) {
|
|
110
|
+
warnings.push(`Invalid value for '${path}.label': expected a non-empty string, got ${JSON.stringify(raw.label)} — falling back to the id`)
|
|
111
|
+
} else {
|
|
112
|
+
label = raw.label
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// --- command ---
|
|
117
|
+
const command = raw.command
|
|
118
|
+
if (typeof command !== 'string' || command.trim().length === 0) {
|
|
119
|
+
warnings.push(`Invalid value for '${path}.command': required — the executable to spawn (absolute path, or one resolvable on PATH)`)
|
|
120
|
+
valid = false
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// --- args ---
|
|
124
|
+
let args = []
|
|
125
|
+
if (Object.prototype.hasOwnProperty.call(raw, 'args')) {
|
|
126
|
+
if (!Array.isArray(raw.args) || raw.args.some((a) => typeof a !== 'string')) {
|
|
127
|
+
warnings.push(`Invalid value for '${path}.args': expected an array of strings, got ${typeName(raw.args)}`)
|
|
128
|
+
valid = false
|
|
129
|
+
} else {
|
|
130
|
+
args = [...raw.args]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// --- env ---
|
|
135
|
+
let env = {}
|
|
136
|
+
if (Object.prototype.hasOwnProperty.call(raw, 'env')) {
|
|
137
|
+
if (typeof raw.env !== 'object' || raw.env === null || Array.isArray(raw.env)) {
|
|
138
|
+
warnings.push(`Invalid value for '${path}.env': expected an object of string environment variables, got ${typeName(raw.env)}`)
|
|
139
|
+
valid = false
|
|
140
|
+
} else {
|
|
141
|
+
const normalizedEnv = {}
|
|
142
|
+
let envValid = true
|
|
143
|
+
for (const key of Object.keys(raw.env)) {
|
|
144
|
+
if (typeof raw.env[key] !== 'string') {
|
|
145
|
+
warnings.push(`Invalid value for '${path}.env.${key}': expected a string, got ${typeName(raw.env[key])}`)
|
|
146
|
+
envValid = false
|
|
147
|
+
continue
|
|
148
|
+
}
|
|
149
|
+
normalizedEnv[key] = raw.env[key]
|
|
150
|
+
}
|
|
151
|
+
if (envValid) {
|
|
152
|
+
env = normalizedEnv
|
|
153
|
+
} else {
|
|
154
|
+
valid = false
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!valid) return null
|
|
160
|
+
|
|
161
|
+
seenIds.add(id)
|
|
162
|
+
return Object.freeze({
|
|
163
|
+
id,
|
|
164
|
+
label,
|
|
165
|
+
command: command.trim(),
|
|
166
|
+
args: Object.freeze(args),
|
|
167
|
+
env: Object.freeze(env),
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Validate + normalize the `providers.acp` array.
|
|
173
|
+
*
|
|
174
|
+
* Never throws. Invalid entries are dropped (with a warning each); valid
|
|
175
|
+
* siblings survive — same "drop bad entries, keep the rest" contract as
|
|
176
|
+
* `validateAnthropicCompatibleProviders`.
|
|
177
|
+
*
|
|
178
|
+
* @param {*} value - The raw `providers.acp` value
|
|
179
|
+
* @param {{ reservedIds?: Iterable<string> }} [opts] - Extra ids the entries
|
|
180
|
+
* may not claim (the live registry at registration time); the static
|
|
181
|
+
* RESERVED_PROVIDER_IDS are always included.
|
|
182
|
+
* @returns {{ entries: Array<object>, warnings: string[] }} Normalized frozen
|
|
183
|
+
* entries: `{ id, label, command, args, env }`.
|
|
184
|
+
*/
|
|
185
|
+
export function validateAcpProviders(value, opts = {}) {
|
|
186
|
+
const warnings = []
|
|
187
|
+
const entries = []
|
|
188
|
+
|
|
189
|
+
if (!Array.isArray(value)) {
|
|
190
|
+
warnings.push(`Invalid value for 'providers.acp': expected an array of agent entries, got ${typeName(value)}`)
|
|
191
|
+
return { entries, warnings }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const reservedIds = new Set(RESERVED_PROVIDER_IDS)
|
|
195
|
+
if (opts.reservedIds) {
|
|
196
|
+
for (const id of opts.reservedIds) reservedIds.add(id)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const seenIds = new Set()
|
|
200
|
+
for (let i = 0; i < value.length; i++) {
|
|
201
|
+
const normalized = validateEntry(value[i], `providers.acp[${i}]`, seenIds, reservedIds, warnings)
|
|
202
|
+
if (normalized) entries.push(normalized)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return { entries, warnings }
|
|
206
|
+
}
|