@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
|
@@ -42,12 +42,13 @@
|
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
import { readFileSync, mkdirSync } from 'node:fs'
|
|
45
|
-
import { dirname
|
|
46
|
-
import { homedir } from 'node:os'
|
|
45
|
+
import { dirname } from 'node:path'
|
|
47
46
|
import { writeFileRestricted } from '../platform.js'
|
|
48
47
|
import { createLogger } from '../logger.js'
|
|
49
48
|
import { sleep } from '../utils/sleep.js'
|
|
50
49
|
import { NotificationSink } from './sink.js'
|
|
50
|
+
import { configPath } from '../config-dir.js'
|
|
51
|
+
import { MAX_EXTERNAL_PROJECT_CHARS } from '../external-session-registry.js'
|
|
51
52
|
import {
|
|
52
53
|
cachedResolveDiscordWebhookUrl,
|
|
53
54
|
isValidDiscordWebhookUrl,
|
|
@@ -62,11 +63,15 @@ import {
|
|
|
62
63
|
DEFAULT_ERROR_COLOR,
|
|
63
64
|
DEFAULT_ONLINE_COLOR,
|
|
64
65
|
DEFAULT_OFFLINE_COLOR,
|
|
66
|
+
DEFAULT_ALLOWED_MENTIONS,
|
|
65
67
|
isValidColor,
|
|
66
68
|
escapeAndCap,
|
|
69
|
+
truncate,
|
|
70
|
+
neutralizeMentions,
|
|
67
71
|
formatDuration,
|
|
68
72
|
apiBase,
|
|
69
73
|
fetchWithDiscordRetry,
|
|
74
|
+
MAX_EMBED_TITLE_CHARS,
|
|
70
75
|
} from './discord-webhook-client.js'
|
|
71
76
|
|
|
72
77
|
const log = createLogger('discord')
|
|
@@ -124,6 +129,16 @@ const DEFAULT_OFFLINE_AFTER_MS = 30 * 60_000 // 30m
|
|
|
124
129
|
// events keep it fresh via routine PATCH.
|
|
125
130
|
// offline — session ended (bash SessionEnd: routine PATCH in place;
|
|
126
131
|
// no-op when nothing is tracked or already offline)
|
|
132
|
+
//
|
|
133
|
+
// `ci_complete` (#7424) is deliberately NOT listed here: a CI-completion event
|
|
134
|
+
// is not a session-lifecycle state, and mapping it onto one would repaint
|
|
135
|
+
// whatever this project's status embed actually shows (idle/online/...) with
|
|
136
|
+
// a stale CI verdict from a run that may have settled long after the session
|
|
137
|
+
// moved on — see #7428. `send()` below returns `true` for any unmapped
|
|
138
|
+
// category without touching the store or the wire, which is the same "not
|
|
139
|
+
// ours" no-op every other unmapped category gets; `discord-ci-sink.js`
|
|
140
|
+
// (registered alongside this sink) is the one that actually delivers it, as
|
|
141
|
+
// its own separate message.
|
|
127
142
|
const STATE_FOR_CATEGORY = {
|
|
128
143
|
activity_update: 'idle',
|
|
129
144
|
result: 'idle',
|
|
@@ -148,6 +163,10 @@ const STATE_TITLES = {
|
|
|
148
163
|
offline: (project) => `\u{1F534} ${project} — Session Offline`,
|
|
149
164
|
}
|
|
150
165
|
|
|
166
|
+
// Re-exported for back-compat: moved to discord-webhook-client.js in #7428 so
|
|
167
|
+
// discord-ci-sink.js can share it without importing this (much larger) file.
|
|
168
|
+
export { MAX_EMBED_TITLE_CHARS }
|
|
169
|
+
|
|
151
170
|
export class DiscordWebhookSink extends NotificationSink {
|
|
152
171
|
/**
|
|
153
172
|
* @param {object} [opts]
|
|
@@ -265,7 +284,7 @@ export class DiscordWebhookSink extends NotificationSink {
|
|
|
265
284
|
_resolvedStatePath() {
|
|
266
285
|
// Lazy like discord-credentials.credentialsFilePath so tests that mutate
|
|
267
286
|
// HOME (and the sandbox guard) see the current home, not a frozen one.
|
|
268
|
-
return this._statePath ||
|
|
287
|
+
return this._statePath || configPath('discord-webhook-state.json')
|
|
269
288
|
}
|
|
270
289
|
|
|
271
290
|
/**
|
|
@@ -340,12 +359,31 @@ export class DiscordWebhookSink extends NotificationSink {
|
|
|
340
359
|
* pipeline notification carries (Phase 3 ingest events will carry an
|
|
341
360
|
* explicit `project`). Sanitized the same way the bash original sanitized
|
|
342
361
|
* project names so state keys stay filesystem/log safe.
|
|
362
|
+
*
|
|
363
|
+
* #8063 review (found while closing #7123): every fallback in the chain
|
|
364
|
+
* above — `data.project`, `data.sessionName`, `data.sessionId` — is a raw
|
|
365
|
+
* `IngestEventDataSchema` value, wire-legal up to 4096 chars (16x
|
|
366
|
+
* `MAX_EXTERNAL_PROJECT_CHARS`). #7123 stripped `data.project` from the
|
|
367
|
+
* ingest-side spread, but `sessionName`/`sessionId` reach this function
|
|
368
|
+
* unclamped the same way `project` did, and `event.sessionId`'s envelope
|
|
369
|
+
* override in event-ingest.js only fires when it's truthy — sessionId is
|
|
370
|
+
* optional. Clamping HERE, on the OUTPUT, closes every current fallback in
|
|
371
|
+
* one place and any future one added to the chain, rather than chasing
|
|
372
|
+
* each raw field at its source. `MAX_EXTERNAL_PROJECT_CHARS` (not
|
|
373
|
+
* `MAX_EXTERNAL_SESSION_ID_CHARS`) is the right bound: whichever field
|
|
374
|
+
* produced it, this function's return value is always used downstream as
|
|
375
|
+
* a PROJECT identifier — the state-file map key and the per-project color
|
|
376
|
+
* override lookup — never as a session id in its own right. Slicing the
|
|
377
|
+
* already-sanitized string (not the raw input) means a short key is
|
|
378
|
+
* returned byte-for-byte unchanged — existing on-disk state-file entries
|
|
379
|
+
* for values under the cap are not rewritten or orphaned.
|
|
343
380
|
*/
|
|
344
381
|
_projectKey(notification) {
|
|
345
382
|
const data = notification?.data || {}
|
|
346
383
|
const raw = data.project || data.sessionName || data.sessionId || 'chroxy'
|
|
347
384
|
const sanitized = String(raw).replace(/[^A-Za-z0-9._-]/g, '')
|
|
348
|
-
|
|
385
|
+
const key = sanitized.length > 0 ? sanitized : 'unknown'
|
|
386
|
+
return key.length > MAX_EXTERNAL_PROJECT_CHARS ? key.slice(0, MAX_EXTERNAL_PROJECT_CHARS) : key
|
|
349
387
|
}
|
|
350
388
|
|
|
351
389
|
// -- Sink contract --------------------------------------------------------
|
|
@@ -637,19 +675,44 @@ export class DiscordWebhookSink extends NotificationSink {
|
|
|
637
675
|
|
|
638
676
|
_buildPayload(project, entry) {
|
|
639
677
|
const titleFor = STATE_TITLES[entry.state] || STATE_TITLES.idle
|
|
678
|
+
// #7105: `project` is only as bounded as whoever minted it — the ingest
|
|
679
|
+
// path derives it from a path basename, and `_projectKey` sanitizes its
|
|
680
|
+
// charset, not its length. Budget the PROJECT against this state's own
|
|
681
|
+
// decoration (emoji + separator + state text, measured from the template
|
|
682
|
+
// itself so a wordier state can't silently overflow) so the state suffix —
|
|
683
|
+
// the title's entire information content — survives the truncation instead
|
|
684
|
+
// of being cut off the end. The outer cap is the belt-and-braces guarantee
|
|
685
|
+
// that whatever a title template does, the embed stays Discord-legal.
|
|
686
|
+
//
|
|
687
|
+
// `truncate`, not `escapeAndCap`: Discord does not render markdown in embed
|
|
688
|
+
// TITLES (only in descriptions and field values), so escaping here would
|
|
689
|
+
// put a visible backslash in front of every `_` — a character `_projectKey`
|
|
690
|
+
// deliberately allows in a project name. Length is the only hazard here.
|
|
691
|
+
const projectBudget = MAX_EMBED_TITLE_CHARS - titleFor('').length
|
|
692
|
+
// `project` is NOT re-neutralized here: it is already `_projectKey()`'s
|
|
693
|
+
// sanitized output (`[^A-Za-z0-9._-]` stripped, #7105/#8063), and that
|
|
694
|
+
// charset excludes `@`/`<`/`>` outright — a mention can't survive into the
|
|
695
|
+
// title through this path. (`truncate`, not `escapeAndCap`, for the same
|
|
696
|
+
// reason noted below: Discord doesn't render markdown in embed titles.)
|
|
697
|
+
const title = truncate(titleFor(truncate(project, projectBudget)), MAX_EMBED_TITLE_CHARS)
|
|
640
698
|
const fields = []
|
|
641
|
-
// Free-text user/transcript fields (#5475):
|
|
642
|
-
//
|
|
643
|
-
//
|
|
644
|
-
//
|
|
699
|
+
// Free-text user/transcript fields (#5475/#8105): neutralize Discord
|
|
700
|
+
// mention syntax FIRST (a session name, task body, or tool detail can
|
|
701
|
+
// carry a literal `@everyone`/`@here`/role/user mention straight from
|
|
702
|
+
// caller-supplied data — #8105), THEN escape markdown so e.g.
|
|
703
|
+
// `watch dist/*_test.js` still renders literally. escapeAndCap truncates
|
|
704
|
+
// first, escapes, then clamps the FINAL escaped string so it can't blow
|
|
705
|
+
// past Discord's 1024-char field limit (see escapeAndCap); running
|
|
706
|
+
// neutralizeMentions after truncation could instead clip a mention
|
|
707
|
+
// mid-match and let it through, so it always runs on the raw value.
|
|
645
708
|
if (entry.body) {
|
|
646
|
-
fields.push({ name: 'Status', value: escapeAndCap(entry.body), inline: false })
|
|
709
|
+
fields.push({ name: 'Status', value: escapeAndCap(neutralizeMentions(entry.body)), inline: false })
|
|
647
710
|
}
|
|
648
711
|
if (entry.detail) {
|
|
649
|
-
fields.push({ name: 'Detail', value: escapeAndCap(entry.detail), inline: false })
|
|
712
|
+
fields.push({ name: 'Detail', value: escapeAndCap(neutralizeMentions(entry.detail)), inline: false })
|
|
650
713
|
}
|
|
651
714
|
if (entry.sessionName) {
|
|
652
|
-
fields.push({ name: 'Session', value: escapeAndCap(entry.sessionName, 100), inline: true })
|
|
715
|
+
fields.push({ name: 'Session', value: escapeAndCap(neutralizeMentions(entry.sessionName), 100), inline: true })
|
|
653
716
|
}
|
|
654
717
|
if (Number.isFinite(entry.subagents) && entry.subagents > 0) {
|
|
655
718
|
fields.push({ name: 'Subagents', value: String(entry.subagents), inline: true })
|
|
@@ -658,12 +721,19 @@ export class DiscordWebhookSink extends NotificationSink {
|
|
|
658
721
|
return {
|
|
659
722
|
username: this._botName,
|
|
660
723
|
embeds: [{
|
|
661
|
-
title
|
|
724
|
+
title,
|
|
662
725
|
color: this._colorFor(project, entry.state),
|
|
663
726
|
fields,
|
|
727
|
+
// `this._botName` is a trusted, admin-set constructor option (config.json
|
|
728
|
+
// / CLI default), never caller-supplied free text — no neutralization
|
|
729
|
+
// needed for the footer.
|
|
664
730
|
footer: { text: `${this._botName} · ${formatDuration(elapsedSec)}` },
|
|
665
731
|
timestamp: new Date(this._now()).toISOString(),
|
|
666
732
|
}],
|
|
733
|
+
// Server-side backstop (#8105), on top of neutralizeMentions() above: no
|
|
734
|
+
// configured user/role ping exists for this sink (see
|
|
735
|
+
// DEFAULT_ALLOWED_MENTIONS), so no mention type is allowed at all.
|
|
736
|
+
allowed_mentions: DEFAULT_ALLOWED_MENTIONS,
|
|
667
737
|
}
|
|
668
738
|
}
|
|
669
739
|
|
|
@@ -79,6 +79,9 @@ async function fetchWithRetry(url, options) {
|
|
|
79
79
|
// Exported for testing (re-exported from push.js for existing importers)
|
|
80
80
|
export { fetchWithRetry, FETCH_TIMEOUT_MS, MAX_RETRIES, BACKOFF_BASE_MS }
|
|
81
81
|
|
|
82
|
+
// The owner recorded for a registration restored from disk (see _loadFromDisk).
|
|
83
|
+
const RESTORED_OWNER = Symbol('restored-registration')
|
|
84
|
+
|
|
82
85
|
export class ExpoPushSink extends NotificationSink {
|
|
83
86
|
constructor({ storagePath } = {}) {
|
|
84
87
|
super({ name: 'expo-push' })
|
|
@@ -95,6 +98,11 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
95
98
|
// review on PR #2806). Owner IDs are client connection IDs in
|
|
96
99
|
// production; tests can use any unique string.
|
|
97
100
|
this._tokenOwners = new Map()
|
|
101
|
+
// Session scope of a registration: token -> Map<ownerId, sessionId> for the
|
|
102
|
+
// owners that registered it on behalf of ONE session (a session-scoped
|
|
103
|
+
// connection). An owner absent from the inner map registered it unscoped.
|
|
104
|
+
// See `_sessionsFor`.
|
|
105
|
+
this._ownerSessions = new Map()
|
|
98
106
|
this._loadFromDisk()
|
|
99
107
|
}
|
|
100
108
|
|
|
@@ -109,6 +117,10 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
109
117
|
for (const token of pushTokens) {
|
|
110
118
|
if (typeof token === 'string' && token.length > 0) {
|
|
111
119
|
this.tokens.add(token)
|
|
120
|
+
// A destination restored from disk was registered unscoped, by the host.
|
|
121
|
+
// Record that as an owner so a session-scoped registration of the same
|
|
122
|
+
// token can neither narrow it nor remove it when that connection leaves.
|
|
123
|
+
this._tokenOwners.set(token, new Set([RESTORED_OWNER]))
|
|
112
124
|
}
|
|
113
125
|
}
|
|
114
126
|
for (const token of laTokens) {
|
|
@@ -127,7 +139,10 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
127
139
|
try {
|
|
128
140
|
mkdirSync(dirname(this._storagePath), { recursive: true })
|
|
129
141
|
writeFileRestricted(this._storagePath, JSON.stringify({
|
|
130
|
-
|
|
142
|
+
// A session-scoped registration lasts as long as its connection (it is
|
|
143
|
+
// released when that connection goes), so it is never written down:
|
|
144
|
+
// restored from disk it would come back without its scope.
|
|
145
|
+
tokens: [...this.tokens].filter((t) => this._sessionsFor(t) === null),
|
|
131
146
|
liveActivityTokens: [...this._liveActivityTokens],
|
|
132
147
|
}))
|
|
133
148
|
} catch (err) {
|
|
@@ -150,7 +165,14 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
150
165
|
* registered token to the connection that registered it, so tokens get
|
|
151
166
|
* pruned on client disconnect.
|
|
152
167
|
*/
|
|
153
|
-
registerToken(token, ownerId = null) {
|
|
168
|
+
registerToken(token, ownerId = null, { sessionId = null } = {}) {
|
|
169
|
+
// A registration made on behalf of one session (`sessionId`) needs an owner:
|
|
170
|
+
// its scope is tracked per owner and ends with it. Without one there would be
|
|
171
|
+
// nothing to release it, and it would outlive the connection unscoped.
|
|
172
|
+
if (sessionId != null && ownerId == null) {
|
|
173
|
+
log.warn('Rejected session-scoped push credential without an owner')
|
|
174
|
+
return false
|
|
175
|
+
}
|
|
154
176
|
if (typeof token !== 'string' || token.length === 0) {
|
|
155
177
|
log.warn(`Rejected invalid push credential: ${String(token).slice(0, 40)}`)
|
|
156
178
|
return false
|
|
@@ -159,10 +181,11 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
159
181
|
log.warn(`Rejected malformed push credential (unrecognized format): ${token.slice(0, 40)}`)
|
|
160
182
|
return false
|
|
161
183
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
184
|
+
const isNew = !this.tokens.has(token)
|
|
185
|
+
if (isNew) this.tokens.add(token)
|
|
186
|
+
// An unscoped owner joining a token that only scoped owners held makes it
|
|
187
|
+
// unscoped, which is what the persisted set is keyed on.
|
|
188
|
+
const widens = sessionId == null && this._ownerSessions.has(token)
|
|
166
189
|
// Track ownership for ref-counted prune-on-disconnect (2026-04-11
|
|
167
190
|
// audit blocker 6 + Copilot review on PR #2806). Multiple clients
|
|
168
191
|
// may register the same token (reconnect race, multi-device); the
|
|
@@ -174,11 +197,51 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
174
197
|
this._tokenOwners.set(token, owners)
|
|
175
198
|
}
|
|
176
199
|
owners.add(ownerId)
|
|
200
|
+
let scoped = this._ownerSessions.get(token)
|
|
201
|
+
if (sessionId != null) {
|
|
202
|
+
if (!scoped) {
|
|
203
|
+
scoped = new Map()
|
|
204
|
+
this._ownerSessions.set(token, scoped)
|
|
205
|
+
}
|
|
206
|
+
scoped.set(ownerId, sessionId)
|
|
207
|
+
} else if (scoped) {
|
|
208
|
+
scoped.delete(ownerId)
|
|
209
|
+
if (scoped.size === 0) this._ownerSessions.delete(token)
|
|
210
|
+
}
|
|
177
211
|
}
|
|
212
|
+
// After the owner and scope bookkeeping above: what is written to disk
|
|
213
|
+
// depends on it (a session-scoped registration is never persisted).
|
|
214
|
+
if (isNew || widens) this._persistToDisk()
|
|
178
215
|
log.info(`Registered push credential ${token.slice(0, 30)}...`)
|
|
179
216
|
return true
|
|
180
217
|
}
|
|
181
218
|
|
|
219
|
+
/**
|
|
220
|
+
* The sessions a registered token may receive notifications for, or null when
|
|
221
|
+
* it may receive all of them.
|
|
222
|
+
*
|
|
223
|
+
* A token is limited only when EVERY owner holding it registered it for a
|
|
224
|
+
* session; one unscoped owner (the host's own device) makes it unscoped, and a
|
|
225
|
+
* token with no recorded owner (restored from disk) is unscoped. So a
|
|
226
|
+
* session-scoped connection can narrow what it receives but can never widen the
|
|
227
|
+
* delivery of a token someone else registered.
|
|
228
|
+
* @param {string} token
|
|
229
|
+
* @returns {Set<string>|null}
|
|
230
|
+
*/
|
|
231
|
+
_sessionsFor(token) {
|
|
232
|
+
const scoped = this._ownerSessions.get(token)
|
|
233
|
+
if (!scoped || scoped.size === 0) return null
|
|
234
|
+
const owners = this._tokenOwners.get(token)
|
|
235
|
+
if (!owners || owners.size === 0) return null
|
|
236
|
+
const sessions = new Set()
|
|
237
|
+
for (const owner of owners) {
|
|
238
|
+
const sid = scoped.get(owner)
|
|
239
|
+
if (sid === undefined) return null
|
|
240
|
+
sessions.add(sid)
|
|
241
|
+
}
|
|
242
|
+
return sessions
|
|
243
|
+
}
|
|
244
|
+
|
|
182
245
|
/**
|
|
183
246
|
* Release one owner's claim on a token. If the last owner goes away,
|
|
184
247
|
* the token is removed from the registry entirely. Returns true if
|
|
@@ -195,10 +258,19 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
195
258
|
return this.removeToken(token)
|
|
196
259
|
}
|
|
197
260
|
owners.delete(ownerId)
|
|
261
|
+
const scoped = this._ownerSessions.get(token)
|
|
262
|
+
let hadScope = false
|
|
263
|
+
if (scoped) {
|
|
264
|
+
hadScope = scoped.delete(ownerId)
|
|
265
|
+
if (scoped.size === 0) this._ownerSessions.delete(token)
|
|
266
|
+
}
|
|
198
267
|
if (owners.size === 0) {
|
|
199
268
|
this._tokenOwners.delete(token)
|
|
200
269
|
return this.removeToken(token)
|
|
201
270
|
}
|
|
271
|
+
// The registration that was limited to a session may have been the only thing
|
|
272
|
+
// keeping the token off disk: persist now that it may be unscoped.
|
|
273
|
+
if (hadScope) this._persistToDisk()
|
|
202
274
|
return false
|
|
203
275
|
}
|
|
204
276
|
|
|
@@ -242,6 +314,7 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
242
314
|
removeToken(token) {
|
|
243
315
|
if (this.tokens.delete(token)) {
|
|
244
316
|
this._tokenOwners.delete(token)
|
|
317
|
+
this._ownerSessions.delete(token)
|
|
245
318
|
this._persistToDisk()
|
|
246
319
|
return true
|
|
247
320
|
}
|
|
@@ -314,7 +387,13 @@ export class ExpoPushSink extends NotificationSink {
|
|
|
314
387
|
const shouldBypassQuietHours = context.shouldBypassQuietHours ?? (() => false)
|
|
315
388
|
|
|
316
389
|
const eligibleTokens = []
|
|
390
|
+
const notificationSession = typeof data?.sessionId === 'string' ? data.sessionId : null
|
|
317
391
|
for (const token of this.tokens) {
|
|
392
|
+
// A token registered for specific sessions receives only notifications
|
|
393
|
+
// that name one of them. One with no session (a host-wide notice) is not
|
|
394
|
+
// for it.
|
|
395
|
+
const sessions = this._sessionsFor(token)
|
|
396
|
+
if (sessions && !(notificationSession !== null && sessions.has(notificationSession))) continue
|
|
318
397
|
if (!isCategoryEnabled(category, token)) continue
|
|
319
398
|
if (isInQuietHours(now, token) && !shouldBypassQuietHours(category, token)) continue
|
|
320
399
|
eligibleTokens.push(token)
|
|
@@ -114,8 +114,8 @@ function formatRelativeWakeup(at, now) {
|
|
|
114
114
|
*
|
|
115
115
|
* @param {{ backgroundTasks?: Array<{toolUseId:string, description?:string, startedAt?:number}>,
|
|
116
116
|
* scheduledWakeup?: { at:number, reason?:string } | null } | null | undefined} snapshot
|
|
117
|
-
* Output of `
|
|
118
|
-
* type doesn't expose one / the transcript scan degraded.
|
|
117
|
+
* Output of `peekBackgroundTaskSnapshot()` (#5436 / #8052), or null when
|
|
118
|
+
* the session type doesn't expose one / the transcript scan degraded.
|
|
119
119
|
* @param {number} [now] Reference epoch ms for the relative wakeup offset —
|
|
120
120
|
* defaults to `Date.now()`. Parameterized so tests can pin the offset against
|
|
121
121
|
* a fixed `at` without freezing the global clock.
|
|
@@ -162,14 +162,25 @@ export function composeReadyNotificationBody(snapshot, now = Date.now()) {
|
|
|
162
162
|
/**
|
|
163
163
|
* Read a session's background-task snapshot for notification enrichment.
|
|
164
164
|
* Returns null (= "no information", body unchanged) when the session type
|
|
165
|
-
* doesn't implement `
|
|
165
|
+
* doesn't implement `peekBackgroundTaskSnapshot()` or the read throws —
|
|
166
166
|
* the same degrade-to-plain-ready posture as event-normalizer's
|
|
167
167
|
* backgroundTaskFields().
|
|
168
|
+
*
|
|
169
|
+
* #8052: this call is deliberately side-effect-free — it goes through
|
|
170
|
+
* `peekBackgroundTaskSnapshot()`, never `getBackgroundTaskSnapshot()`. This
|
|
171
|
+
* composes an idle-push body whenever the session has no active viewers, so
|
|
172
|
+
* nothing here ever broadcasts a `claude_ready` / `background_tasks_changed`
|
|
173
|
+
* message to a client. Reading through the side-effecting method would
|
|
174
|
+
* silently advance the idle-poll's dedup baseline (and could stop the poll
|
|
175
|
+
* outright on a drained snapshot) with nobody ever told what changed —
|
|
176
|
+
* stranding a client's already-shown background-task indicator forever
|
|
177
|
+
* (`ws-history.js` replays a bare `claude_ready`, where an absent field means
|
|
178
|
+
* "keep state").
|
|
168
179
|
*/
|
|
169
180
|
export function readBackgroundTaskSnapshot(session) {
|
|
170
181
|
try {
|
|
171
|
-
return typeof session?.
|
|
172
|
-
? session.
|
|
182
|
+
return typeof session?.peekBackgroundTaskSnapshot === 'function'
|
|
183
|
+
? session.peekBackgroundTaskSnapshot()
|
|
173
184
|
: null
|
|
174
185
|
} catch {
|
|
175
186
|
return null
|
package/src/ollama-session.js
CHANGED
|
@@ -17,8 +17,14 @@
|
|
|
17
17
|
* `getAllowedModels()` returns null (session-manager treats a
|
|
18
18
|
* non-array as "no restriction"). `getFallbackModels()` seeds the
|
|
19
19
|
* dashboard picker with Ollama's recommended coder models; dynamic
|
|
20
|
-
* discovery via GET /api/tags (#5421, ollama-tags.js)
|
|
21
|
-
*
|
|
20
|
+
* discovery via GET /api/tags (#5421, ollama-tags.js) ADDS the
|
|
21
|
+
* actually-installed list when the daemon is reachable. It does not
|
|
22
|
+
* replace the seed — this line said "replaces" until #7761 and the code
|
|
23
|
+
* never did, which is the comment-claims-more-than-the-code class
|
|
24
|
+
* (#7290/#7291): the recommendations stay in the picker so a machine
|
|
25
|
+
* that has pulled two models is still offered the other three. That
|
|
26
|
+
* union is now declared, not incidental — see
|
|
27
|
+
* `staticModelsAreRecommendations` below.
|
|
22
28
|
* Discovery is ADVISORY only — it feeds the picker, never validation.
|
|
23
29
|
* - Zero pricing. Local inference is free; `_getPricing` returns a
|
|
24
30
|
* zero-rate entry (not null) so byok-session's "no pricing entry"
|
|
@@ -42,6 +48,7 @@ import Anthropic from '@anthropic-ai/sdk'
|
|
|
42
48
|
import { ClaudeByokSession } from './byok-session.js'
|
|
43
49
|
import { resolveOllamaBaseUrl, ollamaEnvOverride, refreshOllamaModels } from './ollama-tags.js'
|
|
44
50
|
import { BILLING_CLASSES } from './billing-class.js'
|
|
51
|
+
import { BYOK_CUSTOMIZATION, customizationWithEgress } from './provider-customization.js'
|
|
45
52
|
|
|
46
53
|
// Compatibility re-export — resolution moved to ollama-tags.js (#5421).
|
|
47
54
|
export { resolveOllamaBaseUrl }
|
|
@@ -71,6 +78,13 @@ const OLLAMA_FALLBACK_MODELS = Object.freeze([
|
|
|
71
78
|
const OLLAMA_ZERO_PRICING = Object.freeze({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0 })
|
|
72
79
|
|
|
73
80
|
export class OllamaSession extends ClaudeByokSession {
|
|
81
|
+
static get customizationDescriptor() {
|
|
82
|
+
// Localhost is the default, but both CHROXY_OLLAMA_BASE_URL and OLLAMA_HOST
|
|
83
|
+
// may point at a remote origin. The descriptor must not claim local-only.
|
|
84
|
+
return customizationWithEgress(BYOK_CUSTOMIZATION, 'unknown')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static agentConnectionRoutes = ['local']
|
|
74
88
|
// #5858: NOT Claude-family — Ollama rides ClaudeByokSession's agent loop but
|
|
75
89
|
// serves locally-pulled models (getAllowedModels() returns null, #5418), so
|
|
76
90
|
// override the inherited flag to false (never soft-fall-back to claude).
|
|
@@ -133,6 +147,24 @@ export class OllamaSession extends ClaudeByokSession {
|
|
|
133
147
|
return OLLAMA_FALLBACK_MODELS
|
|
134
148
|
}
|
|
135
149
|
|
|
150
|
+
/**
|
|
151
|
+
* #7761 — this provider's static seed is a RECOMMENDATION list, not a roster
|
|
152
|
+
* claim: `OLLAMA_FALLBACK_MODELS` names coder models worth pulling, and
|
|
153
|
+
* `/api/tags` reports the ones this machine has actually pulled. The two are
|
|
154
|
+
* different facts, so a discovery refresh must UNION rather than replace, or
|
|
155
|
+
* the picker stops suggesting anything the user has not already installed
|
|
156
|
+
* (pinned in ollama-tags.test.js: "merged fallbacks").
|
|
157
|
+
*
|
|
158
|
+
* Every other non-Claude provider leaves this false — for them the refresh IS
|
|
159
|
+
* the provider's own roster, and unioning a hand-maintained table back in is
|
|
160
|
+
* exactly how a retired model reached the wire forever (#7761).
|
|
161
|
+
*
|
|
162
|
+
* @returns {boolean}
|
|
163
|
+
*/
|
|
164
|
+
static get staticModelsAreRecommendations() {
|
|
165
|
+
return true
|
|
166
|
+
}
|
|
167
|
+
|
|
136
168
|
static getAllowedModels() {
|
|
137
169
|
// null = no restriction. Valid models are whatever `ollama list`
|
|
138
170
|
// shows on this machine; the daemon can't know that statically, and
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boot-time factory for the OrchestrationManager (epic #6691, E-4). Isolated so
|
|
3
|
+
* the daemon-boot wiring in server-cli.js is testable: it returns a fully-wired
|
|
4
|
+
* manager when the feature is on, null when it's off, and — critically — null
|
|
5
|
+
* (never a throw) when construction fails, so the orchestration feature can
|
|
6
|
+
* NEVER break daemon boot.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { join } from 'node:path'
|
|
10
|
+
import { isOrchestrationEnabled } from '../config.js'
|
|
11
|
+
import { validateCwdAllowed } from '../handler-utils.js'
|
|
12
|
+
import { OrchestrationManager } from './orchestration-manager.js'
|
|
13
|
+
import { RunLedger } from './run-ledger.js'
|
|
14
|
+
import { TurnDriver } from './turn-driver.js'
|
|
15
|
+
import { createGitOps } from './git-ops.js'
|
|
16
|
+
import { OrchestrationPermissionGate } from './permission-gate.js'
|
|
17
|
+
|
|
18
|
+
export function buildOrchestrationManager({ sessionManager, config, chroxyDir, log = null } = {}) {
|
|
19
|
+
if (!isOrchestrationEnabled(config)) return null
|
|
20
|
+
try {
|
|
21
|
+
const ledger = new RunLedger({ baseDir: join(chroxyDir, 'orchestration') })
|
|
22
|
+
// Load prior runs from disk BEFORE anything writes: without this, the first
|
|
23
|
+
// post-restart createRun would rewrite runs-index.json from the empty
|
|
24
|
+
// in-memory map, clobbering the durable index. Pure load + journal replay —
|
|
25
|
+
// no run is auto-resumed (in-flight runs stay at their last persisted
|
|
26
|
+
// status; full restart-reconcile — suspend/interrupted marking, orphan
|
|
27
|
+
// worktree sweep — is tracked in #6743).
|
|
28
|
+
const recovered = ledger.recoverRuns()
|
|
29
|
+
if (recovered.length) log?.info?.(`Orchestration: recovered ${recovered.length} run record(s) from disk`)
|
|
30
|
+
const turnDriver = new TurnDriver({ sessionManager, log })
|
|
31
|
+
const manager = new OrchestrationManager({
|
|
32
|
+
sessionManager,
|
|
33
|
+
ledger,
|
|
34
|
+
turnDriver,
|
|
35
|
+
gitOps: createGitOps(),
|
|
36
|
+
config,
|
|
37
|
+
roles: config?.orchestration?.roles || null,
|
|
38
|
+
validateCwd: (cwd) => validateCwdAllowed(cwd, config),
|
|
39
|
+
permissionGateFactory: (opts) => new OrchestrationPermissionGate(opts),
|
|
40
|
+
log,
|
|
41
|
+
})
|
|
42
|
+
// The factory owns construction, so it owns teardown: extend dispose() to
|
|
43
|
+
// also stop the turn driver (SessionManager listeners) and flush the ledger.
|
|
44
|
+
//
|
|
45
|
+
// Async since #7142: the manager's dispose settles once its backgrounded
|
|
46
|
+
// starts have. The order is load-bearing — mark the manager disposed, then
|
|
47
|
+
// abort in-flight turns (the driver rejects them), wait for the starts that
|
|
48
|
+
// rejection unwinds, and only THEN flush and close the ledger they would
|
|
49
|
+
// otherwise journal to.
|
|
50
|
+
const managerDispose = manager.dispose.bind(manager)
|
|
51
|
+
manager.dispose = async () => {
|
|
52
|
+
const drained = managerDispose()
|
|
53
|
+
try { turnDriver.dispose() } catch { /* idempotent best-effort */ }
|
|
54
|
+
try { await drained } catch { /* allSettled never rejects; belt and braces */ }
|
|
55
|
+
try { ledger.dispose() } catch { /* flushes pending snapshot writes */ }
|
|
56
|
+
}
|
|
57
|
+
log?.info?.('Orchestration engine enabled (features.orchestration)')
|
|
58
|
+
return manager
|
|
59
|
+
} catch (err) {
|
|
60
|
+
log?.warn?.(`Orchestration engine failed to initialize — feature disabled for this boot: ${err?.message || err}`)
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
63
|
+
}
|