@chroxy/server 0.11.10 → 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 +4 -2
- package/package.json +3 -3
- package/src/acp-session.js +5 -1
- package/src/agent-connections.js +12 -1
- package/src/agent-control/client.js +29 -0
- package/src/agent-control/events.js +8 -4
- package/src/agent-control/local-connection.js +34 -16
- package/src/agent-control/mcp-server.js +2 -0
- package/src/anthropic-compatible-config.js +1 -0
- package/src/anthropic-gemini-shim.js +444 -0
- package/src/anthropic-gemini-translate.js +1030 -0
- package/src/base-session.js +319 -2
- package/src/bound-client-policy.js +12 -0
- package/src/byok-mcp-config.js +9 -5
- package/src/byok-mcp-trust.js +34 -20
- package/src/byok-session.js +62 -9
- package/src/byok-tool-executor.js +81 -1
- package/src/claude-setting-sources.js +74 -0
- package/src/claude-tui/pty-driver.js +5 -1
- package/src/claude-tui/usage-limit.js +2 -2
- package/src/claude-tui-session.js +57 -4
- package/src/cli/agent-cmd.js +236 -0
- package/src/cli/connection-state.js +54 -0
- package/src/cli/freshness-cmd.js +53 -0
- 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/schedule-cmd.js +25 -3
- package/src/cli/server-cmd.js +6 -0
- package/src/cli/shell-cmd.js +7 -4
- package/src/cli/status-cmd.js +19 -5
- package/src/cli-session.js +190 -11
- package/src/cli.js +4 -0
- package/src/codex-app-server-session.js +78 -17
- package/src/codex-error-text.js +114 -0
- package/src/config-dir-migration.js +11 -6
- package/src/config.js +23 -3
- package/src/connection-info.js +73 -14
- package/src/continuations.js +153 -40
- package/src/conversation-scanner.js +2 -21
- package/src/conversation-search.js +4 -17
- package/src/dev-preview.js +2 -1
- package/src/docker-session.js +10 -1
- package/src/doctor.js +14 -3
- package/src/durable-write.js +35 -0
- package/src/environments/authority.js +7 -1
- package/src/event-normalizer.js +35 -2
- 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/handler-utils.js +6 -13
- package/src/handlers/checkpoint-handlers.js +8 -0
- package/src/handlers/folder-trust-handlers.js +90 -0
- package/src/handlers/input-handlers.js +40 -11
- package/src/handlers/principal-admin-handlers.js +229 -0
- package/src/handlers/principal-handlers.js +262 -0
- package/src/handlers/scheduler-handlers.js +4 -4
- package/src/handlers/session-handlers.js +10 -1
- package/src/handlers/settings-handlers.js +42 -8
- package/src/handlers/skills-handlers.js +7 -0
- package/src/history-page.js +8 -0
- package/src/jsonl-reader.js +90 -10
- package/src/jsonl-subprocess-session.js +4 -1
- package/src/logger.js +105 -15
- package/src/mailbox-route.js +102 -0
- package/src/notification-prefs.js +15 -0
- package/src/orchestration/orchestration-manager.js +38 -9
- package/src/orchestration/permission-gate.js +4 -1
- package/src/orchestration/run-record.js +11 -0
- package/src/orchestration/turn-driver.js +151 -33
- package/src/orphan-reaper.js +77 -20
- package/src/outgoing-policy.js +10 -4
- package/src/permission-floor.js +54 -2
- package/src/permission-manager.js +32 -13
- package/src/permission-resolved-by.js +89 -0
- package/src/permission-resolver.js +7 -3
- package/src/platform.js +156 -4
- 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/providers.js +2 -0
- package/src/redaction.js +181 -22
- package/src/scheduled-task-store.js +12 -0
- package/src/scheduler.js +304 -17
- package/src/sdk-session.js +60 -7
- package/src/server-cli/push-notification-handler.js +6 -1
- package/src/server-cli.js +30 -1
- package/src/session-ci-watcher.js +210 -37
- package/src/session-manager.js +590 -19
- package/src/session-message-history.js +121 -2
- package/src/session-name-allocator.js +685 -0
- package/src/statusline.js +78 -19
- package/src/summarize-session.js +2 -0
- package/src/turn-outcome.js +5 -2
- package/src/utils/argv-safety.js +29 -0
- package/src/utils/binary-package-manifest.js +57 -15
- package/src/utils/bounded-regex-worker.js +4 -0
- package/src/utils/bounded-regex.js +16 -7
- package/src/utils/pid-liveness.js +47 -0
- package/src/web-task-manager.js +45 -4
- package/src/worktree-gc.js +195 -4
- package/src/ws-auth.js +103 -19
- package/src/ws-broadcaster.js +39 -7
- package/src/ws-client-manager.js +8 -0
- package/src/ws-file-ops/browser.js +35 -3
- package/src/ws-forwarding.js +23 -3
- package/src/ws-handler-context.js +18 -0
- package/src/ws-history.js +79 -12
- package/src/ws-message-handlers.js +10 -2
- package/src/ws-server.js +253 -13
package/CONFIG.md
CHANGED
|
@@ -107,6 +107,7 @@ of `~/.chroxy/config.json` regardless of which group it appears in.
|
|
|
107
107
|
| Key | Type | CLI Flag | Environment Variable | Description |
|
|
108
108
|
|-----|------|----------|---------------------|-------------|
|
|
109
109
|
| `maxSessions` | number | - | `CHROXY_MAX_SESSIONS` | Maximum concurrent sessions (default `5`). Creating one past the cap is rejected with `SESSION_LIMIT_REACHED`. Must be ≥ 1. |
|
|
110
|
+
| `sessionNaming` | string | - | *(unmapped — see [note](#environment-variable-names))* | How a session created without a name is named: `project` (default) gives `<project> <n>` (numbers kept per project in a durable store next to `session-state.json`), `legacy` keeps `Session <n>`. An explicit name always wins; a project that cannot be determined, or a store that cannot be trusted, falls back to the legacy name. Any other value warns at startup and uses `project`. |
|
|
110
111
|
| `maxMessages` | number | `--max-messages <count>` | `CHROXY_MAX_MESSAGES` | Messages retained per session before FIFO eviction (default `1000`). |
|
|
111
112
|
| `maxHistory` | number | - | `CHROXY_MAX_HISTORY` | Legacy alias for `maxMessages`. `maxMessages` wins when both are set; prefer the canonical key. |
|
|
112
113
|
| `maxPayload` | number | `--max-payload <bytes>` | `CHROXY_MAX_PAYLOAD` | WebSocket max message size in bytes. **Effective default `10485760` (10 MB)** — large enough for image / document attachments. Range `1024` (1 KB) – `104857600` (100 MB); values outside it warn at startup. |
|
|
@@ -147,6 +148,7 @@ of `~/.chroxy/config.json` regardless of which group it appears in.
|
|
|
147
148
|
| `providers` | array \| object | - | `CHROXY_PROVIDERS` | Two forms. **Array** (legacy, written by `chroxy init`): informational list of provider ids the user opted into. **Object** (#5419): `providers.anthropicCompatible` is an array of config-driven Anthropic-compatible endpoint entries (Z.ai GLM, Moonshot Kimi, MiniMax, LM Studio, llama.cpp, vLLM, OpenRouter, custom) — each entry `{ id, label?, baseUrl, apiKeyEnv?, credentialsKey?, defaultModel, models?, pricing?, contextWindow?, modelDiscovery? }` registers a first-class provider at startup, selectable via `provider` / `--provider <id>`. An entry opts into live model-catalog discovery with `modelDiscovery: { "url": "https://…", "format": "openrouter" }` (`"openai"` for a bare `/v1/models` id list, e.g. LM Studio or vLLM): the discovered catalog feeds the model picker and replaces the static model allowlist for validation — see [Model discovery](../../docs/providers.md#model-discovery). API keys are **never** inlined: `apiKeyEnv` names an env var, `credentialsKey` names a `~/.chroxy/credentials.json` field (mode `0600`); entries carrying literal secrets are rejected. Invalid entries are warned about and skipped; valid siblings still register. The object form carries three more sub-blocks: `providers.openaiCompatible` — the identical entry shape for endpoints that speak the **OpenAI Chat Completions** API instead (OpenAI, OpenRouter, LM Studio, vLLM, llama.cpp, Together, Groq, DeepInfra, custom), where `baseUrl` is an OpenAI API base typically ending in `/v1`; `providers.acp` (#7319) — an array of config-driven **Agent Client Protocol** agents, each entry `{ id, label?, command, args?, env? }` spawning an arbitrary ACP-speaking agent over stdio, permissions **denied by default** (no bridge yet — #7320); and `providers.allowAnyModel`, see [Unrestricted provider models](#unrestricted-provider-models-providersallowanymodel). See [Anthropic-compatible endpoints](../../docs/providers.md#anthropic-compatible-endpoints-config-driven), [OpenAI-compatible endpoints](../../docs/providers.md#openai-compatible-endpoints-config-driven), and [ACP agents](../../docs/providers.md#acp-agents-config-driven). |
|
|
148
149
|
| `agentConnections` | array | - | *(unmapped — see [note](#environment-variable-names))* | Explicit, non-secret agent routes shown in the existing session-creation provider picker. Each entry is `{ id, label, provider?, runtime, authRoute, accountRef?, credentialKey?, inferenceLocation? }`; see [Agent connections](#agent-connections). |
|
|
149
150
|
| `legacyCli` | boolean | `--legacy-cli` | `CHROXY_LEGACY_CLI` | Legacy shorthand that maps to `provider: "claude-cli"` when no explicit `provider` is set. Prefer setting `provider` directly; an explicit `provider` always wins. |
|
|
151
|
+
| `codexBinary` | string | - | `CHROXY_CODEX_BIN` | Explicit path of the `codex` client the codex provider launches, instead of the first `codex` on `PATH` (#8609). The config-file value is published to `CHROXY_CODEX_BIN` once at startup by `applyCodexBinaryConfig`, and an env var that is already set wins. See [../../docs/providers.md](../../docs/providers.md). |
|
|
150
152
|
|
|
151
153
|
### Permissions and security gates
|
|
152
154
|
|
|
@@ -178,7 +180,7 @@ of `~/.chroxy/config.json` regardless of which group it appears in.
|
|
|
178
180
|
| `worktreeGc` | object | - | *(unmapped — see [note](#environment-variable-names))* | Garbage collection for orphaned agent worktrees (#5158). `{ autoReap?: boolean, reapIntervalMs?: number, maxLockAgeMs?: number }`. `autoReap` is **off by default**; when on, the daemon reclaims dead-pid-locked worktrees on startup and then every `reapIntervalMs` (default `1800000` / 30 min), clean trees only, never `--force`. `maxLockAgeMs` is an absolute-age fallback for the PID-liveness check — `0` (the default) disables it. The `chroxy worktree gc` CLI is always available for manual / dry-run use regardless of this block. |
|
|
179
181
|
| `orphanReap` | object | - | *(unmapped — see [note](#environment-variable-names))* | Orphaned-child reaper (#7606). `{ enabled?: boolean, sweepIntervalMs?: number, minAgeMs?: number }`. `enabled` is **on by default**: the daemon periodically `SIGKILL`s processes that are reparented to pid 1, owned by the daemon's uid, older than `minAgeMs` (default `600000` / 10 min) and whose working directory is inside chroxy's own session-worktree root — work a dead session left running (the kill sites already reap a session's process tree; this is the backstop for a daemon crash or a child that outlived a force-exit). Sweeps every `sweepIntervalMs` (default `300000` / 5 min). POSIX only; a no-op on Windows. |
|
|
180
182
|
| `sessionArchive` | object | - | *(unmapped — see [note](#environment-variable-names))* | Provider-neutral session archive. `{ enabled?: boolean, maxEntries?: number, maxAgeDays?: number, maxMegabytes?: number }`. When a session leaves the live set (closed, idle-timed-out, stale at boot, or a dismissed / expired failed restore) the history chroxy itself holds is kept as a gzip record under `archive/` next to the session-state file (directory `0700`, files `0600`), so a Codex / Gemini / BYOK session — which cannot be resumed — stays **readable** (paged, read-only) from Control Room. It resumes nothing. `enabled` is **on by default**; turning it off stops new records only and retention still deletes old ones. Retention deletes the oldest records first: older than `maxAgeDays` (default `30`), beyond `maxEntries` (default `100`, at most `1000` — a larger value warns and is clamped), then until the total is within `maxMegabytes` (default `256`). An invalid value warns and falls back to the default. At boot a session last active more than 24 hours ago is not restored: it leaves the live list, archived unless archiving is off. A session with **no history** (for example the startup `Default`) has nothing to archive, so it is restored at any age instead, like a recent session (#8870). The same four values are editable from dashboard **Settings → Session archive** (primary client only): a change is validated like this block (a `maxEntries` above `1000` is rejected there, not clamped), saved to this file and applied **without a restart** — retention re-runs at once — and turning archiving off can also delete every existing archive (#8869). |
|
|
181
|
-
| `sessionCi` | object | - | *(unmapped — see [note](#environment-variable-names))* | CI-completion watching for the pull request a session opened (#7424). `{ watch?: boolean, wakeAgent?: boolean, intervalMs?: number, discoveryIntervalMs?: number, maxSurveysPerTick?: number }`. `watch` is **on by default**: one sweep (never a timer per session) surveys each session's PR through your own `gh` every `intervalMs` (default `60000`) while a run is in flight, and every `discoveryIntervalMs` (default `300000`) otherwise. When a run settles — `pending === 0`, not merely "green" — it fires a `ci_complete` notification and, unless `wakeAgent` is `false`, types one line into that session's prompt if it is an idle claude-tui session. Set `watch: false` for a host that must make no background GitHub calls. A run that starts and finishes between two sweeps is missed rather than reported late. `maxSurveysPerTick` (default `4`, clamped to an integer ≥ 1) caps how many sessions one sweep pass surveys — the escape hatch for sweep contention on a many-session daemon (#7436). |
|
|
183
|
+
| `sessionCi` | object | - | *(unmapped — see [note](#environment-variable-names))* | CI-completion watching for the pull request a session opened (#7424). `{ watch?: boolean, wakeAgent?: boolean, intervalMs?: number, discoveryIntervalMs?: number, maxSurveysPerTick?: number, maxConsecutiveWakes?: number }`. `watch` is **on by default**: one sweep (never a timer per session) surveys each session's PR through your own `gh` every `intervalMs` (default `60000`) while a run is in flight, and every `discoveryIntervalMs` (default `300000`) otherwise. When a run settles — `pending === 0`, not merely "green" — it fires a `ci_complete` notification and, unless `wakeAgent` is `false`, types one line into that session's prompt if it is an idle claude-tui session. Set `watch: false` for a host that must make no background GitHub calls. A run that starts and finishes between two sweeps is missed rather than reported late. `maxSurveysPerTick` (default `4`, clamped to an integer ≥ 1) caps how many sessions one sweep pass surveys — the escape hatch for sweep contention on a many-session daemon (#7436). `maxConsecutiveWakes` (default `3`, floored to an integer ≥ 1) bounds the wake → push → CI → wake loop (#8326): after that many daemon wakes into one session with no user-typed input between (typing in chat or the terminal pane resets the count; a daemon-authored wake does not), the next wake is refused with outcome `wake-cap` and logged, while the `ci_complete` push notification still goes out. The count is in-memory, per session, and starts at 0 after a daemon restart. Mailbox and scheduler/orchestration turns are neither counted nor capped. |
|
|
182
184
|
|
|
183
185
|
### Control Room
|
|
184
186
|
|
|
@@ -266,7 +268,7 @@ rather than being silently dropped.
|
|
|
266
268
|
| `worktreeGc` | `autoReap`, `reapIntervalMs`, `maxLockAgeMs` |
|
|
267
269
|
| `orphanReap` | `enabled`, `sweepIntervalMs`, `minAgeMs` |
|
|
268
270
|
| `sessionArchive` | `enabled`, `maxEntries`, `maxAgeDays`, `maxMegabytes` |
|
|
269
|
-
| `sessionCi` | `watch`, `wakeAgent`, `intervalMs`, `discoveryIntervalMs`, `maxSurveysPerTick` |
|
|
271
|
+
| `sessionCi` | `watch`, `wakeAgent`, `intervalMs`, `discoveryIntervalMs`, `maxSurveysPerTick`, `maxConsecutiveWakes` |
|
|
270
272
|
| `userShell` | `enabled`, `requireApproval` |
|
|
271
273
|
| `environments.k8s` | `namespace`, `inCluster`, `kubeconfigPath`, `sidecarImage`, `imagePullPolicy`, `connectMode`, `namespaceQuota`, `namespaceLimitRange`, `workspace` |
|
|
272
274
|
| `environments.rancher` | `rancherUrl`, `clusterId`, `token`, `tokenEnv`, `tokenFile`, `caData`, `skipTLSVerify`, `defaultProjectId` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chroxy/server",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.11",
|
|
4
4
|
"files": [
|
|
5
5
|
"src",
|
|
6
6
|
"hooks",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@agentclientprotocol/sdk": "1.4.0",
|
|
30
30
|
"@anthropic-ai/claude-agent-sdk": "^0.2.0",
|
|
31
31
|
"@anthropic-ai/sdk": "^0.91.1",
|
|
32
|
-
"@chroxy/protocol": "^0.11.
|
|
33
|
-
"@chroxy/store-core": "^0.11.
|
|
32
|
+
"@chroxy/protocol": "^0.11.11",
|
|
33
|
+
"@chroxy/store-core": "^0.11.11",
|
|
34
34
|
"@kubernetes/client-node": "^1.4.0",
|
|
35
35
|
"@modelcontextprotocol/sdk": "^1.32.0",
|
|
36
36
|
"@xterm/addon-fit": "^0.10.0",
|
package/src/acp-session.js
CHANGED
|
@@ -673,7 +673,11 @@ export function createAcpSessionClass(rawEntry) {
|
|
|
673
673
|
this._activeTurn = null
|
|
674
674
|
const wasIntentional = this._consumeIntentionalStop()
|
|
675
675
|
if (wasIntentional) {
|
|
676
|
-
|
|
676
|
+
// #9241: the prompt RESOLVED while the Stop was armed: the requested stop. (The
|
|
677
|
+
// failure path below also reports `stopped`, without this word.)
|
|
678
|
+
// Only a `cancelled` stop reason is the cancel being honoured; a limit or a
|
|
679
|
+
// refusal that won the race with `session/cancel` is not a Stop.
|
|
680
|
+
this.emit('stopped', res?.stopReason === 'cancelled' ? { stopRequested: true } : {})
|
|
677
681
|
this._clearMessageState()
|
|
678
682
|
this._maybeDequeue()
|
|
679
683
|
return
|
package/src/agent-connections.js
CHANGED
|
@@ -106,6 +106,17 @@ function declaredCredentialKey(ProviderClass) {
|
|
|
106
106
|
return cleanString(ProviderClass.agentConnectionCredentialKey, 128)
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
// An isolated API route normally resolves its key by name through the generic
|
|
110
|
+
// resolver. A provider whose credential has aliases of its own (Gemini:
|
|
111
|
+
// GOOGLE_API_KEY, a legacy stored field) declares ITS resolver here so a connection
|
|
112
|
+
// is ready exactly when a session of that provider would find a key.
|
|
113
|
+
function declaredCredentialResolver(ProviderClass) {
|
|
114
|
+
if (!ProviderClass || !Object.prototype.hasOwnProperty.call(ProviderClass, 'resolveAgentConnectionCredential')) return null
|
|
115
|
+
return typeof ProviderClass.resolveAgentConnectionCredential === 'function'
|
|
116
|
+
? (key) => ProviderClass.resolveAgentConnectionCredential(key)
|
|
117
|
+
: null
|
|
118
|
+
}
|
|
119
|
+
|
|
109
120
|
function blocked(reasonCode, message, recoveryAction) {
|
|
110
121
|
return { state: 'blocked', reasonCode, message, recoveryAction }
|
|
111
122
|
}
|
|
@@ -260,7 +271,7 @@ export class AgentConnectionRegistry {
|
|
|
260
271
|
`Runtime '${definition.runtime}' cannot apply credential reference '${credentialKey || 'unset'}' to an isolated API route.`,
|
|
261
272
|
)
|
|
262
273
|
} else {
|
|
263
|
-
const credential = this._deps.resolveCredential(credentialKey)
|
|
274
|
+
const credential = (declaredCredentialResolver(ProviderClass) || this._deps.resolveCredential)(credentialKey)
|
|
264
275
|
readiness = credential.value
|
|
265
276
|
? definition.runtime === 'codex'
|
|
266
277
|
? unknown(
|
|
@@ -272,6 +272,8 @@ export class AgentControlClient extends EventEmitter {
|
|
|
272
272
|
// subscribe_sessions) at a time on this connection — see SERIAL_REPLY_TYPES.
|
|
273
273
|
this._serialQueue = Promise.resolve()
|
|
274
274
|
this._pendingSerialOp = null // { kind, resolve, reject, timer }
|
|
275
|
+
// management requests in flight (`request()`): each entry settles one with an error
|
|
276
|
+
this._pendingRequests = new Set()
|
|
275
277
|
|
|
276
278
|
// sessionId -> { requestedModel: string|null, lastKnownStatus }. Accepts
|
|
277
279
|
// an INJECTED Map so a caller managing reconnects across multiple
|
|
@@ -524,6 +526,32 @@ export class AgentControlClient extends EventEmitter {
|
|
|
524
526
|
// Public API
|
|
525
527
|
// ---------------------------------------------------------------------
|
|
526
528
|
|
|
529
|
+
/**
|
|
530
|
+
* Send one correlated management request and resolve with the first `replyType`
|
|
531
|
+
* frame that echoes its `requestId` (#9116: `chroxy agent ...` asks the daemon, which
|
|
532
|
+
* is the only writer of the principal store). Bounded by the request timeout; never
|
|
533
|
+
* retried, so an uncertain outcome is reported as uncertain.
|
|
534
|
+
* @param {string} type
|
|
535
|
+
* @param {object} fields
|
|
536
|
+
* @param {{ replyType: string, timeoutMs?: number }} opts
|
|
537
|
+
* @returns {Promise<object>}
|
|
538
|
+
*/
|
|
539
|
+
async request(type, fields, { replyType, timeoutMs = this._requestTimeoutMs }) {
|
|
540
|
+
this._assertReady()
|
|
541
|
+
const requestId = randomUUID()
|
|
542
|
+
return new Promise((resolve, reject) => {
|
|
543
|
+
// Registered with the common pending-operation cleanup (`_rejectAllPending`), so
|
|
544
|
+
// close(), a socket close and a connection failure all settle it with that error.
|
|
545
|
+
const abort = (err) => done(reject, err)
|
|
546
|
+
const done = (fn, v) => { clearTimeout(timer); this.removeListener('message', onMsg); this._pendingRequests.delete(abort); fn(v) }
|
|
547
|
+
const timer = setTimeout(() => done(reject, new TimeoutError(type, timeoutMs)), timeoutMs)
|
|
548
|
+
this._pendingRequests.add(abort)
|
|
549
|
+
const onMsg = (msg) => { if (msg?.type === replyType && msg.requestId === requestId) done(resolve, msg) }
|
|
550
|
+
this.on('message', onMsg)
|
|
551
|
+
try { this._send({ type, requestId, ...fields }) } catch (err) { done(reject, err) }
|
|
552
|
+
})
|
|
553
|
+
}
|
|
554
|
+
|
|
527
555
|
async listSessions() {
|
|
528
556
|
this._assertReady()
|
|
529
557
|
const msg = await this._runSerial('list_sessions', this._requestTimeoutMs, () => {
|
|
@@ -1607,6 +1635,7 @@ export class AgentControlClient extends EventEmitter {
|
|
|
1607
1635
|
pending.resolve({ status: 'uncertain', requestId, sessionId: pending.sessionId, disconnected: true, message: err.message })
|
|
1608
1636
|
}
|
|
1609
1637
|
this._pendingPermissionResponses.clear()
|
|
1638
|
+
for (const abort of [...this._pendingRequests]) abort(err)
|
|
1610
1639
|
if (this._pendingSerialOp) {
|
|
1611
1640
|
clearTimeout(this._pendingSerialOp.timer)
|
|
1612
1641
|
this._pendingSerialOp.reject(err)
|
|
@@ -44,7 +44,7 @@ export const MAX_EVENT_BYTES = 8192
|
|
|
44
44
|
// types below) is silently dropped — this is the allowlist, not a denylist,
|
|
45
45
|
// so a new high-frequency broadcast type added to the protocol later does
|
|
46
46
|
// NOT automatically start flooding the retained log.
|
|
47
|
-
const FORWARDED_TYPES = new Set([
|
|
47
|
+
export const FORWARDED_TYPES = new Set([
|
|
48
48
|
'message',
|
|
49
49
|
'tool_start',
|
|
50
50
|
'tool_input_delta',
|
|
@@ -56,6 +56,10 @@ const FORWARDED_TYPES = new Set([
|
|
|
56
56
|
'permission_mode_changed',
|
|
57
57
|
'confirm_permission_mode',
|
|
58
58
|
'model_changed',
|
|
59
|
+
// #9075: the requested (`level`) and effective (`effective`: a string, null for "not
|
|
60
|
+
// reported yet", absent for "this provider makes no such report") effort. Applied-setting
|
|
61
|
+
// metadata, never the thinking text, which stays excluded below.
|
|
62
|
+
'thinking_level_changed',
|
|
59
63
|
'available_models',
|
|
60
64
|
'agent_busy',
|
|
61
65
|
'agent_idle',
|
|
@@ -130,7 +134,7 @@ function boundIdentityValue(value) {
|
|
|
130
134
|
* `truncated: true` so a caller can tell the difference from a payload that
|
|
131
135
|
* was always this shape.
|
|
132
136
|
*/
|
|
133
|
-
function truncateEventData(data, type) {
|
|
137
|
+
export function truncateEventData(data, type, maxBytes = MAX_EVENT_BYTES) {
|
|
134
138
|
if (!data || typeof data !== 'object') {
|
|
135
139
|
return { truncated: true, originalType: type }
|
|
136
140
|
}
|
|
@@ -142,7 +146,7 @@ function truncateEventData(data, type) {
|
|
|
142
146
|
// identity fields are each near the cap (9 fields * 512B can still exceed
|
|
143
147
|
// a small MAX_EVENT_BYTES in a future retune) — check the real total
|
|
144
148
|
// rather than assuming the per-field cap times the field count fits.
|
|
145
|
-
if (Buffer.byteLength(JSON.stringify(kept), 'utf8') >
|
|
149
|
+
if (Buffer.byteLength(JSON.stringify(kept), 'utf8') > maxBytes) {
|
|
146
150
|
return { truncated: true, originalType: type }
|
|
147
151
|
}
|
|
148
152
|
let textKey = null
|
|
@@ -154,7 +158,7 @@ function truncateEventData(data, type) {
|
|
|
154
158
|
const full = Buffer.from(data[textKey], 'utf8')
|
|
155
159
|
const fitsWithPrefixBytes = (n) => {
|
|
156
160
|
const candidate = { ...kept, [textKey]: full.subarray(0, n).toString('utf8') }
|
|
157
|
-
return Buffer.byteLength(JSON.stringify(candidate), 'utf8') <=
|
|
161
|
+
return Buffer.byteLength(JSON.stringify(candidate), 'utf8') <= maxBytes
|
|
158
162
|
}
|
|
159
163
|
if (!fitsWithPrefixBytes(0)) {
|
|
160
164
|
// Even an empty text field doesn't fit (identity fields alone are too
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
import { existsSync, readFileSync } from 'node:fs'
|
|
30
30
|
import { isIPv4 } from 'node:net'
|
|
31
31
|
import { getConnectionInfoPath } from '../connection-info.js'
|
|
32
|
+
import { probePidLiveness, PID_ALIVE, PID_DEAD } from '../utils/pid-liveness.js'
|
|
32
33
|
|
|
33
34
|
export const DEFAULT_LOCAL_PORT = 8765
|
|
34
35
|
const MIN_PORT = 1
|
|
@@ -37,16 +38,28 @@ const MAX_PORT = 65535
|
|
|
37
38
|
/**
|
|
38
39
|
* Non-mutating equivalent of `readConnectionInfo()` — reads and parses
|
|
39
40
|
* connection.json (respecting `CHROXY_CONFIG_DIR` via `getConnectionInfoPath`)
|
|
40
|
-
* and
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* and classifies the recorded pid, but never unlinks the file. Returns `null` for
|
|
42
|
+
* "no file" or "unparseable". Otherwise it returns the record, marked as below when
|
|
43
|
+
* its pid is not verified alive.
|
|
44
|
+
*
|
|
45
|
+
* The pid is classified by `probePidLiveness` (#9074), and only a verified-alive
|
|
46
|
+
* record comes back unmarked:
|
|
47
|
+
* - `_stale: true`: the pid is proven gone (ESRCH).
|
|
48
|
+
* - `_livenessUnverified: true`: liveness could not be established. That covers
|
|
49
|
+
* EPERM under a sandbox, any other probe error, and a missing or malformed pid.
|
|
50
|
+
* It is neither "running" nor "dead": resolveLocalConnection refuses it
|
|
51
|
+
* WITHOUT handing out the token.
|
|
52
|
+
* Neither marker deletes the file: a connection.json is evidence, not litter this
|
|
53
|
+
* module gets to clean up.
|
|
43
54
|
*
|
|
44
55
|
* @param {object} [deps]
|
|
45
56
|
* @param {function} [deps.getConnectionInfoPath]
|
|
57
|
+
* @param {function} [deps.probePidLiveness] - test seam (mocked errno only)
|
|
46
58
|
* @returns {object|null}
|
|
47
59
|
*/
|
|
48
60
|
export function readConnectionInfoNonMutating(deps = {}) {
|
|
49
61
|
const getPath = deps.getConnectionInfoPath || getConnectionInfoPath
|
|
62
|
+
const probe = typeof deps.probePidLiveness === 'function' ? deps.probePidLiveness : probePidLiveness
|
|
50
63
|
const path = getPath()
|
|
51
64
|
if (!existsSync(path)) return null
|
|
52
65
|
let info
|
|
@@ -56,17 +69,9 @@ export function readConnectionInfoNonMutating(deps = {}) {
|
|
|
56
69
|
return null
|
|
57
70
|
}
|
|
58
71
|
if (!info || typeof info !== 'object') return null
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} catch {
|
|
63
|
-
// Stale — the daemon that wrote this is gone. Report it as such
|
|
64
|
-
// (resolveLocalConnection treats a dead pid the same as "not running"
|
|
65
|
-
// below) WITHOUT deleting the file — a stale connection.json is
|
|
66
|
-
// evidence, not litter this module gets to clean up.
|
|
67
|
-
return { ...info, _stale: true }
|
|
68
|
-
}
|
|
69
|
-
}
|
|
72
|
+
const liveness = probe(info.pid)
|
|
73
|
+
if (liveness === PID_DEAD) return { ...info, _stale: true }
|
|
74
|
+
if (liveness !== PID_ALIVE) return { ...info, _livenessUnverified: true }
|
|
70
75
|
return info
|
|
71
76
|
}
|
|
72
77
|
|
|
@@ -163,9 +168,19 @@ function loopbackPortFromUrl(url) {
|
|
|
163
168
|
* without ever including the token in a thrown message, log, or returned
|
|
164
169
|
* diagnostic field beyond the dedicated `token` property.
|
|
165
170
|
*
|
|
166
|
-
*
|
|
171
|
+
* A record whose pid is proven gone resolves `not_running`, as does no record at all.
|
|
172
|
+
* A record whose liveness could not be verified (`_livenessUnverified`, #9074) resolves
|
|
173
|
+
* `liveness_unverified`. Both refusals happen before a credential-bearing connection
|
|
174
|
+
* is returned: the result carries no `token`, so this resolver never hands out the
|
|
175
|
+
* primary bearer on an unverified record. (The record, token included, has already
|
|
176
|
+
* been parsed by then; it is simply not returned.) A verified-alive pid is not proof
|
|
177
|
+
* of the daemon's identity either (see utils/pid-liveness.js); the existing auth and
|
|
178
|
+
* transport checks still apply to whatever is dialed.
|
|
179
|
+
*
|
|
180
|
+
* @param {object} [deps] - injection seam for tests. An injected reader is a test seam and
|
|
181
|
+
* is trusted as given; production always uses the verifying non-mutating reader.
|
|
167
182
|
* @param {function} [deps.readConnectionInfo]
|
|
168
|
-
* @returns {{ ok: true, url: string, token: string|null, port: number } | { ok: false, reason:
|
|
183
|
+
* @returns {{ ok: true, url: string, token: string|null, port: number } | { ok: false, reason: 'not_running'|'liveness_unverified' }}
|
|
169
184
|
*/
|
|
170
185
|
export function resolveLocalConnection(deps = {}) {
|
|
171
186
|
const readInfo = deps.readConnectionInfo || readConnectionInfoNonMutating
|
|
@@ -173,6 +188,9 @@ export function resolveLocalConnection(deps = {}) {
|
|
|
173
188
|
if (!info || info._stale) {
|
|
174
189
|
return { ok: false, reason: 'not_running' }
|
|
175
190
|
}
|
|
191
|
+
if (info._livenessUnverified) {
|
|
192
|
+
return { ok: false, reason: 'liveness_unverified' }
|
|
193
|
+
}
|
|
176
194
|
const port =
|
|
177
195
|
(isValidPort(info.port) && info.port)
|
|
178
196
|
|| loopbackPortFromUrl(info.httpUrl)
|
|
@@ -326,6 +326,8 @@ function describeConnectionFailure(reason) {
|
|
|
326
326
|
switch (reason) {
|
|
327
327
|
case 'not_running':
|
|
328
328
|
return 'chroxy daemon is not running locally (no connection.json). Start it with `chroxy start`, or pass --url with CHROXY_AGENT_CONTROL_TOKEN set for a remote daemon.'
|
|
329
|
+
case 'liveness_unverified':
|
|
330
|
+
return 'could not verify that the daemon recorded in connection.json is running: the record has no valid pid, or that pid could not be inspected from here (for example inside a sandbox). Its token was not used, and the record was left in place.'
|
|
329
331
|
case 'no_local_token':
|
|
330
332
|
return 'chroxy daemon is running without an auth token (--no-auth) or the token could not be read locally.'
|
|
331
333
|
case 'remote_requires_token':
|