@chroxy/server 0.11.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 +204 -18
- package/README.md +2 -2
- package/hooks/claude-native-route-check.mjs +17 -0
- package/hooks/permission-hook.sh +166 -11
- package/package.json +16 -12
- package/sidecar/Dockerfile +1 -1
- package/sidecar/PROTOCOL.md +9 -1
- package/sidecar/agent.js +102 -10
- package/sidecar/package-lock.json +3 -3
- package/src/acp-config.js +206 -0
- package/src/acp-session.js +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 +1203 -36
- package/src/bearer-recheck.js +49 -0
- package/src/billing-budget.js +19 -0
- package/src/billing-class.js +40 -7
- package/src/binary-provenance-trust.js +11 -5
- package/src/bound-client-policy.js +279 -0
- package/src/built-in-tools/bash-exec.js +46 -7
- package/src/built-in-tools/file-ops.js +69 -5
- package/src/built-in-tools/tool-transforms.js +1113 -13
- package/src/byok-compose-state.js +6 -9
- package/src/byok-credentials.js +2 -3
- package/src/byok-mcp-client.js +92 -7
- package/src/byok-mcp-config.js +628 -121
- package/src/byok-mcp-fleet.js +49 -7
- package/src/byok-mcp-oauth-store.js +18 -16
- package/src/byok-mcp-trust.js +3 -3
- package/src/byok-session.js +650 -175
- package/src/byok-tool-executor.js +2662 -26
- package/src/byok-tools.js +9 -2
- package/src/channels/chroxy-channel-server.js +2 -3
- package/src/checkpoint-manager.js +64 -46
- package/src/claude-channel-session.js +16 -10
- package/src/claude-model-catalog.js +131 -16
- package/src/claude-model-refresh.js +385 -0
- package/src/claude-model-request.js +103 -0
- package/src/claude-stream-parser.js +53 -3
- package/src/claude-tui/diagnostic-tail.js +83 -0
- package/src/claude-tui/form-driver.js +44 -7
- package/src/claude-tui/model-error.js +41 -0
- package/src/claude-tui/pty-driver.js +211 -88
- package/src/claude-tui/sanitize-question-payload.js +109 -0
- package/src/claude-tui/usage-limit.js +239 -0
- package/src/claude-tui-session.js +3513 -287
- package/src/claude-tui-tool-response.js +300 -0
- package/src/cli/agent-control-cmd.js +65 -0
- package/src/cli/config-cmd.js +4 -4
- package/src/cli/config-dir-cmd.js +234 -0
- package/src/cli/deploy-cmd.js +45 -10
- package/src/cli/doctor-cmd.js +7 -3
- package/src/cli/init-cmd.js +15 -16
- package/src/cli/providers-cmd.js +3 -3
- package/src/cli/schedule-cmd.js +68 -39
- package/src/cli/server-cmd.js +48 -1
- package/src/cli/service-cmd.js +33 -10
- package/src/cli/session-cmd.js +227 -74
- package/src/cli/shared.js +162 -11
- package/src/cli/tokens-cmd.js +4 -5
- package/src/cli/tunnel-cmd.js +255 -24
- package/src/cli/worktree-gc-cmd.js +2 -2
- package/src/cli-session.js +1066 -121
- package/src/cli.js +4 -0
- package/src/codex-app-server-client.js +36 -3
- package/src/codex-app-server-session.js +1454 -79
- 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 +450 -27
- package/src/config-dir-migration.js +444 -0
- package/src/config-dir.js +108 -0
- package/src/config.js +286 -26
- 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 +7 -20
- package/src/control-room/skills-inventory.js +2 -2
- 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 +23 -19
- package/src/daemon-commit.js +92 -0
- package/src/daemon-idle-state.js +171 -0
- package/src/daemon-update-status.js +314 -0
- package/src/dashboard-build.js +70 -0
- package/src/declared-status.js +90 -0
- package/src/deepseek-credentials.js +2 -3
- package/src/dev-preview.js +169 -182
- package/src/device-preferences.js +2 -2
- package/src/diff-parser.js +87 -0
- package/src/discord-credentials.js +2 -3
- package/src/docker-byok-pool.js +3 -1
- package/src/docker-byok-session.js +678 -78
- package/src/docker-image-allowlist.js +23 -1
- package/src/docker-sdk-session.js +172 -3
- package/src/docker-session.js +284 -10
- package/src/doctor.js +767 -61
- 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 +31 -10
- package/src/environments/backends/k8s.js +49 -24
- package/src/environments/destroy-with-sessions.js +142 -0
- package/src/event-ingest.js +118 -13
- package/src/event-normalizer.js +151 -233
- package/src/gemini-session.js +81 -5
- package/src/handler-utils.js +535 -68
- package/src/handlers/checkpoint-handlers.js +39 -4
- package/src/handlers/control-room-handlers.js +51 -11
- package/src/handlers/conversation-handlers.js +469 -56
- package/src/handlers/daemon-update-handlers.js +81 -0
- package/src/handlers/evaluator-handlers.js +14 -1
- package/src/handlers/feature-handlers.js +186 -69
- package/src/handlers/file-handlers.js +57 -13
- package/src/handlers/input-handlers.js +685 -48
- package/src/handlers/orchestration-handlers.js +3 -3
- package/src/handlers/scheduler-handlers.js +88 -14
- package/src/handlers/session-handlers.js +542 -20
- package/src/handlers/session-pr-status-handlers.js +283 -0
- package/src/handlers/session-pr-threads-handlers.js +247 -0
- package/src/handlers/settings-handlers.js +330 -42
- 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/health-proof.js +40 -0
- package/src/history-page.js +104 -0
- package/src/http-routes.js +127 -8
- package/src/ide/search.js +24 -6
- package/src/ide/symbols.js +20 -6
- package/src/input-context.js +117 -0
- package/src/instruction-policy-compiler.js +229 -0
- package/src/instruction-policy.js +250 -0
- package/src/jsonl-reader.js +289 -82
- package/src/jsonl-subprocess-session.js +92 -8
- package/src/keychain.js +1 -1
- package/src/logger.js +63 -17
- 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 +12 -4
- package/src/notifications/discord-billing-sink.js +22 -5
- package/src/notifications/discord-ci-sink.js +243 -0
- package/src/notifications/discord-webhook-client.js +71 -0
- package/src/notifications/discord-webhook-sink.js +64 -23
- package/src/notifications/expo-push-sink.js +85 -6
- package/src/notifications/ready-body.js +16 -5
- package/src/ollama-session.js +34 -2
- package/src/orchestration/build-manager.js +9 -2
- package/src/orchestration/git-ops.js +41 -7
- package/src/orchestration/orchestration-manager.js +80 -33
- package/src/orchestration/permission-gate.js +13 -1
- package/src/orchestration/run-model.js +2 -1
- package/src/orchestration/turn-driver.js +44 -20
- package/src/orphan-reaper.js +413 -0
- package/src/outgoing-policy.js +183 -0
- package/src/pairing.js +92 -13
- package/src/path-hash-trust-ledger.js +642 -25
- package/src/permission-deadlines.js +82 -0
- package/src/permission-floor.js +1357 -42
- package/src/permission-hook.js +180 -69
- package/src/permission-manager.js +712 -83
- package/src/permission-mode-support.js +35 -0
- package/src/permission-resolver.js +122 -8
- package/src/permission-scope.js +43 -0
- package/src/platform.js +159 -43
- 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 +207 -4
- 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/scheduled-task-store.js +318 -26
- package/src/scheduler.js +73 -3
- package/src/sdk-session.js +2060 -187
- 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 +28 -5
- package/src/server-cli-child.js +33 -18
- package/src/server-cli.js +524 -38
- package/src/server-identity.js +15 -11
- package/src/service.js +396 -25
- package/src/session-archive-limits.js +15 -0
- package/src/session-archive.js +1029 -0
- package/src/session-busy-state.js +72 -0
- package/src/session-ci-watcher.js +926 -0
- package/src/session-context.js +7 -2
- package/src/session-manager.js +3491 -312
- package/src/session-message-history.js +722 -16
- package/src/session-pr-status.js +654 -0
- package/src/session-pr-threads.js +271 -0
- package/src/session-preset-trust.js +3 -3
- package/src/session-preset.js +10 -5
- package/src/session-state-persistence.js +94 -17
- package/src/session-timeout-manager.js +20 -0
- package/src/session-token-store.js +17 -8
- package/src/session-wake.js +240 -0
- package/src/shell-approval-info.js +2 -2
- package/src/shell-approval-store.js +3 -1
- package/src/skills-loader.js +7 -4
- package/src/skills-manager.js +2 -2
- package/src/skills-trust.js +95 -13
- package/src/skills-usage.js +2 -3
- package/src/snapshots-store.js +2 -3
- package/src/statusline.js +23 -11
- package/src/summarize-session.js +51 -4
- package/src/supervisor.js +22 -11
- package/src/sweep-stale-provider-dirs.js +95 -0
- package/src/thinking-level-wire.js +39 -0
- package/src/thinking-stream.js +179 -0
- package/src/tool-result.js +61 -0
- package/src/transcript-sources.js +109 -0
- package/src/transcript-tasks.js +372 -25
- package/src/trusted-file-read.js +302 -0
- package/src/tunnel/base.js +0 -8
- package/src/tunnel/cloudflare.js +34 -31
- package/src/tunnel/index.js +9 -0
- package/src/tunnel/preview.js +64 -0
- package/src/turn-outcome.js +137 -0
- package/src/usage-normalize.js +9 -5
- package/src/user-shell-session.js +59 -5
- package/src/utils/agent-sdk-version.js +107 -0
- package/src/utils/argv-safety.js +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 +133 -37
- package/src/utils/deploy-control-files.js +87 -0
- package/src/utils/exec-failure-reason.js +21 -0
- package/src/utils/git-repo.js +42 -0
- package/src/utils/is-entry-point.js +137 -0
- package/src/utils/node-pty-probe.js +95 -0
- package/src/utils/node-pty-support.js +118 -0
- package/src/utils/opened-file-path.js +167 -0
- package/src/utils/path-containment.js +165 -0
- package/src/utils/permission-mode-sidecar.js +51 -0
- package/src/utils/preflight.js +360 -16
- package/src/utils/read-limiter.js +217 -0
- package/src/utils/regular-file.js +375 -0
- package/src/utils/safe-regex.js +113 -0
- package/src/utils/small-file.js +129 -0
- package/src/utils/spawn-env.js +189 -4
- package/src/utils/stale-session-dirs.js +182 -0
- package/src/utils/stat-identity.js +43 -0
- package/src/utils/verify-provenance.js +406 -13
- package/src/web-task-manager.js +256 -16
- package/src/worktree-gc.js +7 -2
- 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 +331 -58
- package/src/ws-file-ops/common.js +320 -14
- package/src/ws-file-ops/git.js +395 -42
- package/src/ws-file-ops/index.js +2 -0
- package/src/ws-file-ops/memory.js +137 -35
- package/src/ws-file-ops/open-nofollow.js +354 -0
- package/src/ws-file-ops/reader.js +571 -113
- package/src/ws-forwarding.js +329 -39
- package/src/ws-handler-context.js +70 -2
- package/src/ws-history.js +940 -172
- package/src/ws-message-handlers.js +17 -1
- package/src/ws-permissions.js +307 -37
- package/src/ws-schemas.js +5 -0
- package/src/ws-server.js +643 -96
- package/sidecar/node_modules/.package-lock.json +0 -29
- package/sidecar/node_modules/ws/LICENSE +0 -20
- package/sidecar/node_modules/ws/README.md +0 -548
- package/sidecar/node_modules/ws/browser.js +0 -8
- package/sidecar/node_modules/ws/index.js +0 -22
- package/sidecar/node_modules/ws/lib/buffer-util.js +0 -131
- package/sidecar/node_modules/ws/lib/constants.js +0 -19
- package/sidecar/node_modules/ws/lib/event-target.js +0 -292
- package/sidecar/node_modules/ws/lib/extension.js +0 -203
- package/sidecar/node_modules/ws/lib/limiter.js +0 -55
- package/sidecar/node_modules/ws/lib/permessage-deflate.js +0 -528
- package/sidecar/node_modules/ws/lib/receiver.js +0 -706
- package/sidecar/node_modules/ws/lib/sender.js +0 -602
- package/sidecar/node_modules/ws/lib/stream.js +0 -161
- package/sidecar/node_modules/ws/lib/subprotocol.js +0 -62
- package/sidecar/node_modules/ws/lib/validation.js +0 -152
- package/sidecar/node_modules/ws/lib/websocket-server.js +0 -554
- package/sidecar/node_modules/ws/lib/websocket.js +0 -1393
- package/sidecar/node_modules/ws/package.json +0 -70
- package/sidecar/node_modules/ws/wrapper.mjs +0 -21
- package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +0 -111
- package/src/dashboard-next/dist/assets/index-DM-_dISG.css +0 -1
- package/src/dashboard-next/dist/index.html +0 -13
- package/src/dashboard-next/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { createLogger } from './logger.js'
|
|
2
|
+
|
|
3
|
+
const log = createLogger('container-liveness')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* #7601 — how often the proactive poll inspects each live containerized session's
|
|
7
|
+
* container. The reactive #7599 paths already catch a vanish that happens
|
|
8
|
+
* DURING a turn (SDK query reject) or that closes a live exec child (CLI); this
|
|
9
|
+
* poll is the ONLY thing that catches an IDLE session whose container was stopped
|
|
10
|
+
* EXTERNALLY (a plain `docker stop`, which emits no chroxy event), and it is what
|
|
11
|
+
* gives a no-long-lived-process session (docker-byok, #7600) any idle
|
|
12
|
+
* detection at all. 30s balances "surface before the user's
|
|
13
|
+
* next turn" against the cost of one `docker inspect` per distinct container.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_LIVENESS_INTERVAL_MS = 30_000
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* #7620 — describe an out-of-contract verdict for the log WITHOUT trusting it.
|
|
19
|
+
*
|
|
20
|
+
* The verdict comes from the very injection seam the guard below exists to
|
|
21
|
+
* distrust, so a bare `JSON.stringify` is not safe: it THROWS on a circular
|
|
22
|
+
* object (the raw `docker inspect` blob a mis-implemented seam is most likely to
|
|
23
|
+
* forward) and on a BigInt. That throw would escape the per-target try into the
|
|
24
|
+
* tick's outer catch — replacing the diagnostic that justifies warning at all
|
|
25
|
+
* with a generic line, AND releasing the `_ticking` latch while other
|
|
26
|
+
* containers' inspects are still in flight, so the next tick re-inspects them.
|
|
27
|
+
* Total by construction: every branch returns a string and none can throw.
|
|
28
|
+
*/
|
|
29
|
+
function describeVerdict(verdict) {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.stringify(verdict) ?? String(verdict)
|
|
32
|
+
} catch {
|
|
33
|
+
return `[unserialisable ${typeof verdict}]`
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* ContainerLivenessMonitor — a periodic, unref'd `docker inspect` poll over the
|
|
39
|
+
* live containerized sessions, surfacing CONTAINER_VANISHED (#7599) on any whose
|
|
40
|
+
* container has been stopped or removed underneath it.
|
|
41
|
+
*
|
|
42
|
+
* Deliberately docker-agnostic: it takes an `enumerate` fn (the live targets)
|
|
43
|
+
* and an `inspect` fn (containerId → 'running' | 'gone' | 'unknown'), so the
|
|
44
|
+
* SessionManager owns lifecycle without depending on a Docker backend, and the
|
|
45
|
+
* daemon-down guard lives with the injected inspect (see inspectContainerLiveness).
|
|
46
|
+
*
|
|
47
|
+
* Batching: multiple sessions in one container environment share a containerId,
|
|
48
|
+
* so the tick inspects each DISTINCT container once and fans the verdict to every
|
|
49
|
+
* session bound to it. An env with no sessions contributes no target and is never
|
|
50
|
+
* inspected (the #7601 negative control).
|
|
51
|
+
*/
|
|
52
|
+
export class ContainerLivenessMonitor {
|
|
53
|
+
/**
|
|
54
|
+
* @param {object} opts
|
|
55
|
+
* @param {() => Array<{sessionId: string, containerId: string, session: object}>} opts.enumerate
|
|
56
|
+
* live containerized poll targets (session exposes notifyContainerVanished + holds a containerId)
|
|
57
|
+
* @param {(containerId: string) => Promise<'running'|'gone'|'unknown'>} opts.inspect
|
|
58
|
+
* @param {(target: {sessionId: string, containerId: string, session: object}) => any} [opts.onRecovered]
|
|
59
|
+
* #7602 — called once per RECOVERY EDGE (see _tick). Optional: without it the
|
|
60
|
+
* poll only clears the latch, exactly as in #7601.
|
|
61
|
+
* @param {number} [opts.intervalMs]
|
|
62
|
+
* @param {object} [opts.logger]
|
|
63
|
+
*/
|
|
64
|
+
constructor({ enumerate, inspect, onRecovered = null, intervalMs = DEFAULT_LIVENESS_INTERVAL_MS, logger = log } = {}) {
|
|
65
|
+
this._enumerate = enumerate
|
|
66
|
+
this._inspect = inspect
|
|
67
|
+
this._onRecovered = onRecovered
|
|
68
|
+
this._intervalMs = intervalMs
|
|
69
|
+
this._log = logger
|
|
70
|
+
this._timer = null
|
|
71
|
+
// Skip a tick if the prior one is still awaiting inspects (each inspect can
|
|
72
|
+
// block up to the docker exec/inspect timeout), so a slow Docker daemon can't
|
|
73
|
+
// stack overlapping ticks.
|
|
74
|
+
this._ticking = false
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Start the poll. No-op if already running or if the required fns are missing
|
|
79
|
+
* (so a deployment that never wired a Docker inspect simply never polls).
|
|
80
|
+
*/
|
|
81
|
+
start() {
|
|
82
|
+
if (this._timer) return
|
|
83
|
+
if (typeof this._enumerate !== 'function' || typeof this._inspect !== 'function') return
|
|
84
|
+
this._timer = setInterval(() => { this._tick() }, this._intervalMs)
|
|
85
|
+
// Never keep the event loop (and thus the daemon process) alive for a poll.
|
|
86
|
+
if (typeof this._timer.unref === 'function') this._timer.unref()
|
|
87
|
+
this._log.info(`Container liveness poll enabled (every ${this._intervalMs}ms)`)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
stop() {
|
|
91
|
+
if (this._timer) {
|
|
92
|
+
clearInterval(this._timer)
|
|
93
|
+
this._timer = null
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
destroy() {
|
|
98
|
+
this.stop()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* One poll pass. Enumerate live containerized sessions, inspect each distinct
|
|
103
|
+
* container once, and surface CONTAINER_VANISHED on the sessions whose
|
|
104
|
+
* container is gone (or clear the latch on the ones whose container is running
|
|
105
|
+
* again). Every failure is contained: one bad inspect or one throwing session
|
|
106
|
+
* must not abort the whole pass or wedge the interval.
|
|
107
|
+
*
|
|
108
|
+
* #7602 — the RECOVERY EDGE. `clearContainerVanished()` returns true only when
|
|
109
|
+
* it actually flipped the latch, i.e. exactly on the gone→running transition of
|
|
110
|
+
* a session that HAD vanished. `onRecovered` is invoked on that edge and only
|
|
111
|
+
* there, which is what keeps the re-attach from re-running on every healthy
|
|
112
|
+
* tick of a session that never vanished (30s apart, that would re-resolve the
|
|
113
|
+
* environment binding of every idle containerized session forever). A provider
|
|
114
|
+
* whose `clearContainerVanished` returns nothing — an older stub, or one that
|
|
115
|
+
* predates the boolean — yields NO edge, so the failure direction is "no
|
|
116
|
+
* reconnect attempted", never "reconnect attempted spuriously". #7620 holds
|
|
117
|
+
* that same direction for a broken INSPECT seam: only 'running' reaches the
|
|
118
|
+
* clear/recovery branch, and an unrecognised verdict no-ops like 'unknown'.
|
|
119
|
+
*/
|
|
120
|
+
async _tick() {
|
|
121
|
+
if (this._ticking) return
|
|
122
|
+
this._ticking = true
|
|
123
|
+
try {
|
|
124
|
+
const targets = this._enumerate() || []
|
|
125
|
+
if (targets.length === 0) return // negative control: nothing to poll
|
|
126
|
+
|
|
127
|
+
// Batch by containerId: one inspect per DISTINCT container, fanned to every
|
|
128
|
+
// session bound to it (env-backed sessions share a container).
|
|
129
|
+
const byContainer = new Map()
|
|
130
|
+
for (const t of targets) {
|
|
131
|
+
if (!t || !t.containerId || !t.session) continue
|
|
132
|
+
const list = byContainer.get(t.containerId)
|
|
133
|
+
// #7602: the whole TARGET is carried, not just the session — the
|
|
134
|
+
// recovery edge hands `sessionId` to onRecovered, which is what the
|
|
135
|
+
// SessionManager needs to find the entry's `environmentId`.
|
|
136
|
+
if (list) list.push(t)
|
|
137
|
+
else byContainer.set(t.containerId, [t])
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
await Promise.all([...byContainer.entries()].map(async ([containerId, targets]) => {
|
|
141
|
+
let status
|
|
142
|
+
try {
|
|
143
|
+
status = await this._inspect(containerId)
|
|
144
|
+
} catch (err) {
|
|
145
|
+
// The inspect fn owns the gone/unknown classification; a throw here is
|
|
146
|
+
// unexpected. Treat it as 'unknown' — never surface a vanish on an
|
|
147
|
+
// inspect that failed in a way we didn't classify.
|
|
148
|
+
this._log.warn(`container-liveness inspect threw for ${String(containerId).slice(0, 12)}: ${err?.message || err}`)
|
|
149
|
+
status = 'unknown'
|
|
150
|
+
}
|
|
151
|
+
if (status === 'unknown') return // transient (daemon down / timeout) — leave the latch as-is
|
|
152
|
+
// #7620 — the fan-out is CLOSED over the three-value contract. `inspect`
|
|
153
|
+
// is an INJECTION SEAM, so 'running' is tested explicitly here and every
|
|
154
|
+
// unrecognised verdict degrades to the SAME no-op as 'unknown' rather
|
|
155
|
+
// than falling through to the clear/recovery branch below. A broken seam
|
|
156
|
+
// must fail in the "no reconnect attempted" direction, exactly as a
|
|
157
|
+
// provider whose clearContainerVanished returns nothing does — not clear
|
|
158
|
+
// a vanish latch and trigger a re-attach. Warned once per CONTAINER (the
|
|
159
|
+
// verdict is a property of the container, not of each bound session)
|
|
160
|
+
// because an unrecognised verdict means the seam itself is broken.
|
|
161
|
+
if (status !== 'running' && status !== 'gone') {
|
|
162
|
+
this._log.warn(`container-liveness: unrecognised verdict ${describeVerdict(status)} for ${String(containerId).slice(0, 12)} — treating as unknown`)
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
for (const target of targets) {
|
|
166
|
+
const session = target.session
|
|
167
|
+
try {
|
|
168
|
+
if (status === 'gone') {
|
|
169
|
+
session.notifyContainerVanished?.()
|
|
170
|
+
continue
|
|
171
|
+
}
|
|
172
|
+
// #7602: only a genuine gone→running transition is a recovery edge.
|
|
173
|
+
// A throwing re-attach is contained by this loop's own catch below,
|
|
174
|
+
// like every other per-session call here — it must not abort the
|
|
175
|
+
// fan-out to the other sessions sharing this container.
|
|
176
|
+
if (session.clearContainerVanished?.() !== true) continue
|
|
177
|
+
if (this._onRecovered) await this._onRecovered(target)
|
|
178
|
+
} catch (err) {
|
|
179
|
+
this._log.warn(`container-liveness surface failed: ${err?.message || err}`)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}))
|
|
183
|
+
} catch (err) {
|
|
184
|
+
this._log.warn(`container-liveness tick failed: ${err?.message || err}`)
|
|
185
|
+
} finally {
|
|
186
|
+
this._ticking = false
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Isolated metadata only: no seed body reads. Parent owns deadline and concurrency.
|
|
2
|
+
import { statSync } from 'node:fs'
|
|
3
|
+
|
|
4
|
+
let input = ''
|
|
5
|
+
process.stdin.setEncoding('utf8')
|
|
6
|
+
process.stdin.on('data', (chunk) => { input += chunk })
|
|
7
|
+
process.stdin.on('end', () => {
|
|
8
|
+
const results = {}
|
|
9
|
+
for (const { id, seedPath, cwd } of JSON.parse(input)) {
|
|
10
|
+
try {
|
|
11
|
+
const seed = statSync(seedPath)
|
|
12
|
+
results[id] = seed.isFile() && statSync(cwd).isDirectory()
|
|
13
|
+
? `${seed.dev}:${seed.ino}:${seed.size}:${seed.mtimeMs}:${seed.ctimeMs}` : null
|
|
14
|
+
} catch { results[id] = null }
|
|
15
|
+
}
|
|
16
|
+
process.stdout.write(JSON.stringify(results))
|
|
17
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Path-only, daemon-lifetime opportunities. Filesystem probes run in a child. */
|
|
2
|
+
import { createHash } from 'node:crypto'
|
|
3
|
+
import { spawn } from 'node:child_process'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
export const CONTINUATION_TTL_MS = 30 * 60_000
|
|
7
|
+
const MAX_CONTINUATIONS = 50
|
|
8
|
+
|
|
9
|
+
/** One killable worker globally; a stuck syscall cannot fill libuv's pool or
|
|
10
|
+
* create an unbounded process queue. Keep the slot until child close. The worker
|
|
11
|
+
* path seam is direct-test-only, never populated from HTTP input. */
|
|
12
|
+
export function createContinuationProbe({ workerPath = fileURLToPath(new URL('./continuation-metadata-worker.js', import.meta.url)), timeoutMs = 1000 } = {}) {
|
|
13
|
+
let active = false
|
|
14
|
+
return (entries) => {
|
|
15
|
+
if (active || entries.length === 0) return Promise.resolve(null)
|
|
16
|
+
active = true
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
let child, timer, settled = false, output = ''
|
|
19
|
+
const finish = (result) => {
|
|
20
|
+
if (settled) return
|
|
21
|
+
settled = true
|
|
22
|
+
clearTimeout(timer)
|
|
23
|
+
resolve(result)
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
child = spawn(process.execPath, ['--', workerPath], { stdio: ['pipe', 'pipe', 'ignore'] })
|
|
27
|
+
timer = setTimeout(() => { finish(null); child.kill('SIGKILL') }, timeoutMs)
|
|
28
|
+
child.on('error', () => { active = false; finish(null) })
|
|
29
|
+
child.on('close', (code) => {
|
|
30
|
+
active = false
|
|
31
|
+
let result = null
|
|
32
|
+
if (code === 0) {
|
|
33
|
+
try { result = JSON.parse(output) } catch { /* unavailable */ }
|
|
34
|
+
}
|
|
35
|
+
finish(result)
|
|
36
|
+
})
|
|
37
|
+
child.stdout.on('data', (chunk) => {
|
|
38
|
+
output += chunk
|
|
39
|
+
if (output.length > 65_536) { finish(null); child.kill('SIGKILL') }
|
|
40
|
+
})
|
|
41
|
+
child.stdin.on('error', () => { finish(null); child.kill('SIGKILL') })
|
|
42
|
+
child.stdin.end(JSON.stringify(entries.map(({ id, seedPath, cwd }) => ({ id, seedPath, cwd }))))
|
|
43
|
+
} catch {
|
|
44
|
+
if (child) child.kill('SIGKILL')
|
|
45
|
+
else active = false
|
|
46
|
+
finish(null)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const probeMetadata = createContinuationProbe()
|
|
53
|
+
function expired(entry, now) {
|
|
54
|
+
return now - entry.ts > CONTINUATION_TTL_MS || entry.ts > now + 60_000
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function refreshMetadata(server, now, probe) {
|
|
58
|
+
if (server._continuationRefresh) return server._continuationRefresh
|
|
59
|
+
const entries = [...(server._continuations?.values() || [])].filter((entry) => !expired(entry, now) && !entry.baselineFailed)
|
|
60
|
+
if (entries.length === 0) return
|
|
61
|
+
const refresh = (async () => {
|
|
62
|
+
const results = await probe(entries)
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
if (server._continuations?.get(entry.id) !== entry) continue
|
|
65
|
+
if (!results || !Object.hasOwn(results, entry.id)) {
|
|
66
|
+
// Without the announcement's initial snapshot we cannot tell whether a
|
|
67
|
+
// later successful check sees the original file or a replacement. Only
|
|
68
|
+
// a newer announcement may establish another baseline in that case.
|
|
69
|
+
if (entry.fingerprint === undefined) {
|
|
70
|
+
entry.fingerprint = null
|
|
71
|
+
entry.baselineFailed = true
|
|
72
|
+
}
|
|
73
|
+
entry.unavailable = 'metadata timeout'
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
const current = results[entry.id]
|
|
77
|
+
if (entry.fingerprint === undefined) entry.fingerprint = current
|
|
78
|
+
entry.unavailable = !current || !entry.fingerprint ? 'missing' : current !== entry.fingerprint ? 'changed' : null
|
|
79
|
+
}
|
|
80
|
+
})()
|
|
81
|
+
server._continuationRefresh = refresh
|
|
82
|
+
try { await refresh } finally { if (server._continuationRefresh === refresh) server._continuationRefresh = null }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function recordContinuation(server, event, now = Date.now(), probe = probeMetadata) {
|
|
86
|
+
const { seedPath, cwd } = event.data
|
|
87
|
+
const id = createHash('sha256').update(JSON.stringify([cwd, seedPath])).digest('hex')
|
|
88
|
+
if (!server._continuations) server._continuations = new Map()
|
|
89
|
+
const previous = server._continuations.get(id)
|
|
90
|
+
if (previous && event.ts <= previous.ts) return { opportunity: previous, duplicate: true }
|
|
91
|
+
const opportunity = { id, seedPath, cwd, ts: event.ts, fingerprint: undefined, unavailable: 'checking metadata' }
|
|
92
|
+
server._continuations.delete(id)
|
|
93
|
+
server._continuations.set(id, opportunity)
|
|
94
|
+
while (server._continuations.size > MAX_CONTINUATIONS) server._continuations.delete(server._continuations.keys().next().value)
|
|
95
|
+
// The isolated probe never delays the ingest acknowledgement.
|
|
96
|
+
if (server._continuationRefresh) {
|
|
97
|
+
// That batch already captured its entries. Joining its promise would leave
|
|
98
|
+
// this announcement unexamined until a later refresh could adopt a new file.
|
|
99
|
+
opportunity.fingerprint = null
|
|
100
|
+
opportunity.baselineFailed = true
|
|
101
|
+
opportunity.unavailable = 'metadata timeout'
|
|
102
|
+
} else {
|
|
103
|
+
void refreshMetadata(server, now, probe).catch(() => {})
|
|
104
|
+
}
|
|
105
|
+
return { opportunity, duplicate: false }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function listContinuations(server, now = Date.now(), probe = probeMetadata) {
|
|
109
|
+
await refreshMetadata(server, now, probe)
|
|
110
|
+
return [...(server._continuations?.values() || [])].reverse().map((entry) => {
|
|
111
|
+
const unavailable = expired(entry, now) ? 'expired' : entry.unavailable
|
|
112
|
+
return { id: entry.id, seedPath: entry.seedPath, cwd: entry.cwd, ts: entry.ts, available: unavailable === null, unavailable }
|
|
113
|
+
})
|
|
114
|
+
}
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
import { execFile } from 'child_process'
|
|
35
|
+
import { assertAuthorized } from '../connection-authority.js'
|
|
35
36
|
import { promisify } from 'util'
|
|
36
37
|
import { parseByteSize } from './containers.js'
|
|
37
38
|
import { listSnapshots } from '../snapshots-store.js'
|
|
@@ -347,6 +348,7 @@ export async function runHostPrune(opts = {}) {
|
|
|
347
348
|
listByokSnapshots = () => listSnapshots(),
|
|
348
349
|
_execFile = execFileAsync,
|
|
349
350
|
_now = () => new Date(),
|
|
351
|
+
isAuthorized,
|
|
350
352
|
} = opts
|
|
351
353
|
const selected = PRUNE_KINDS.includes(kind) ? kind : 'all'
|
|
352
354
|
const survey = await surveyHostPrune({ listEnvironments, listByokSnapshots, _execFile, _now })
|
|
@@ -360,9 +362,11 @@ export async function runHostPrune(opts = {}) {
|
|
|
360
362
|
failures: [],
|
|
361
363
|
}
|
|
362
364
|
if (!survey.dockerAvailable) return result
|
|
365
|
+
assertAuthorized(isAuthorized)
|
|
363
366
|
|
|
364
367
|
if (selected === 'containers' || selected === 'all') {
|
|
365
368
|
for (const c of survey.containers) {
|
|
369
|
+
assertAuthorized(isAuthorized)
|
|
366
370
|
try {
|
|
367
371
|
await _execFile('docker', ['rm', c.id], EXEC_OPTS)
|
|
368
372
|
result.removedContainers += 1
|
|
@@ -374,6 +378,7 @@ export async function runHostPrune(opts = {}) {
|
|
|
374
378
|
}
|
|
375
379
|
if (selected === 'images' || selected === 'all') {
|
|
376
380
|
for (const img of survey.images) {
|
|
381
|
+
assertAuthorized(isAuthorized)
|
|
377
382
|
try {
|
|
378
383
|
await _execFile('docker', ['rmi', img.id], EXEC_OPTS)
|
|
379
384
|
result.removedImages += 1
|
|
@@ -49,12 +49,14 @@
|
|
|
49
49
|
*/
|
|
50
50
|
|
|
51
51
|
import { execFile } from 'child_process'
|
|
52
|
+
import { assertAuthorized } from '../connection-authority.js'
|
|
52
53
|
import { promisify } from 'util'
|
|
53
54
|
import { readFile, stat } from 'fs/promises'
|
|
54
55
|
import { join } from 'path'
|
|
55
56
|
import { parseGithubOwnerRepo } from './survey.js'
|
|
56
57
|
import { DEFAULT_CONCURRENCY, EXEC_TIMEOUT_MS } from './constants.js'
|
|
57
58
|
import { isoFromEpochMs } from '../utils/iso-datetime.js'
|
|
59
|
+
import { execFailureReason } from '../utils/exec-failure-reason.js'
|
|
58
60
|
|
|
59
61
|
const execFileAsync = promisify(execFile)
|
|
60
62
|
|
|
@@ -256,23 +258,6 @@ async function surveyCache(statFn, repoPath) {
|
|
|
256
258
|
return { present: true, sizeBytes, lastModified }
|
|
257
259
|
}
|
|
258
260
|
|
|
259
|
-
/**
|
|
260
|
-
* First meaningful line of a subprocess failure, for the per-repo `reason` /
|
|
261
|
-
* the reindex error message. `label` names the failing command ("repo-memory
|
|
262
|
-
* report" for the survey cell, "repo-memory index" for the #5500 action).
|
|
263
|
-
*
|
|
264
|
-
* @param {unknown} err
|
|
265
|
-
* @param {string} [label]
|
|
266
|
-
* @returns {string}
|
|
267
|
-
*/
|
|
268
|
-
function execFailureReason(err, label = 'repo-memory report') {
|
|
269
|
-
const stderr = err && typeof err === 'object' && typeof err.stderr === 'string' ? err.stderr : ''
|
|
270
|
-
const firstLine = stderr.split('\n').map(l => l.trim()).find(l => l.length > 0)
|
|
271
|
-
if (firstLine) return `${label} failed: ${firstLine}`
|
|
272
|
-
const message = err && typeof err === 'object' && typeof err.message === 'string' ? err.message : 'unknown error'
|
|
273
|
-
return `${label} failed: ${message}`
|
|
274
|
-
}
|
|
275
|
-
|
|
276
261
|
/**
|
|
277
262
|
* #5500: parse the human-readable `repo-memory index <root>` report into the
|
|
278
263
|
* `IntegrationActionCountsSchema` shape. The CLI has no `--json` for index —
|
|
@@ -329,9 +314,10 @@ export function parseRepoMemoryIndexCounts(stdout) {
|
|
|
329
314
|
* @returns {Promise<{ counts: object|null }>}
|
|
330
315
|
*/
|
|
331
316
|
export async function runRepoMemoryIndex(repoPath, opts = {}) {
|
|
332
|
-
const { bin, _execFile = execFileAsync } = opts
|
|
317
|
+
const { bin, _execFile = execFileAsync, isAuthorized } = opts
|
|
333
318
|
const binPath = await resolveRepoMemoryBin(_execFile, bin)
|
|
334
319
|
if (!binPath) throw new Error(CLI_MISSING_NOTE)
|
|
320
|
+
assertAuthorized(isAuthorized)
|
|
335
321
|
let stdout
|
|
336
322
|
try {
|
|
337
323
|
;({ stdout } = await _execFile(binPath, ['index', repoPath], INDEX_EXEC_OPTS))
|
|
@@ -391,7 +377,7 @@ function rerunFailure(reason, message) {
|
|
|
391
377
|
* @returns {Promise<{ runId: number }>}
|
|
392
378
|
*/
|
|
393
379
|
export async function runRepoRelayRerun(repoPath, runId, opts = {}) {
|
|
394
|
-
const { _execFile = execFileAsync } = opts
|
|
380
|
+
const { _execFile = execFileAsync, isAuthorized } = opts
|
|
395
381
|
|
|
396
382
|
const ghPath = await probeBinOnPath(_execFile, 'gh')
|
|
397
383
|
if (!ghPath) throw rerunFailure('gh-missing', GH_MISSING_NOTE)
|
|
@@ -434,6 +420,7 @@ export async function runRepoRelayRerun(repoPath, runId, opts = {}) {
|
|
|
434
420
|
`run ${runId} did not fail (${state}) — only failed runs can be re-run`)
|
|
435
421
|
}
|
|
436
422
|
|
|
423
|
+
assertAuthorized(isAuthorized)
|
|
437
424
|
try {
|
|
438
425
|
await _execFile(ghPath, ['run', 'rerun', String(runId), '-R', slug], RERUN_EXEC_OPTS)
|
|
439
426
|
} catch (err) {
|
|
@@ -833,7 +820,7 @@ async function surveyRepoMemory(ctx, repo) {
|
|
|
833
820
|
report = parseRepoMemoryReport(typeof stdout === 'string' ? stdout : '')
|
|
834
821
|
if (report === null) reason = 'repo-memory report produced unparseable output'
|
|
835
822
|
} catch (err) {
|
|
836
|
-
reason = execFailureReason(err)
|
|
823
|
+
reason = execFailureReason(err, 'repo-memory report')
|
|
837
824
|
}
|
|
838
825
|
}
|
|
839
826
|
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
import { readFileSync } from 'fs'
|
|
47
47
|
import { join, dirname } from 'path'
|
|
48
|
-
import { loadActiveSkills, findRepoSkillsDir,
|
|
48
|
+
import { loadActiveSkills, findRepoSkillsDir, defaultSkillsDir } from '../skills-loader.js'
|
|
49
49
|
import { DEFAULT_CONCURRENCY } from './constants.js'
|
|
50
50
|
import { isoFromEpochMs } from '../utils/iso-datetime.js'
|
|
51
51
|
|
|
@@ -249,7 +249,7 @@ function failureReason(err) {
|
|
|
249
249
|
*/
|
|
250
250
|
export async function surveySkillsInventory(repoSet, opts = {}) {
|
|
251
251
|
const {
|
|
252
|
-
globalDir =
|
|
252
|
+
globalDir = defaultSkillsDir(),
|
|
253
253
|
root = '',
|
|
254
254
|
usage = null,
|
|
255
255
|
concurrency = DEFAULT_CONCURRENCY,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { readdir, stat,
|
|
1
|
+
import { readdir, stat, realpath } from 'fs/promises'
|
|
2
|
+
import { readContainedBytes } from './utils/regular-file.js'
|
|
2
3
|
import { join, basename } from 'path'
|
|
3
|
-
import {
|
|
4
|
+
import { claudeProjectsDir } from './utils/claude-config-dir.js'
|
|
4
5
|
import { decodeProjectPath } from './jsonl-reader.js'
|
|
5
6
|
import { runWithConcurrency } from './utils/concurrency.js'
|
|
6
7
|
|
|
7
|
-
const PROJECTS_DIR = join(homedir(), '.claude', 'projects')
|
|
8
8
|
const PREVIEW_BYTES = 32 * 1024 // read first 32KB for preview extraction
|
|
9
9
|
const MIN_FILE_SIZE = 100 // skip tiny/empty files
|
|
10
10
|
const CONCURRENCY = 15 // max parallel file reads
|
|
@@ -35,12 +35,15 @@ export function clearScanCache() {
|
|
|
35
35
|
*
|
|
36
36
|
* @returns {{ preview: string|null, cwd: string|null }}
|
|
37
37
|
*/
|
|
38
|
-
async function extractMetadata(filePath) {
|
|
39
|
-
let handle
|
|
38
|
+
async function extractMetadata(filePath, root) {
|
|
40
39
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
// One pinned, contained, non-blocking read of the head of the file: the
|
|
41
|
+
// listing and this read are separate steps, and the name can be re-pointed in
|
|
42
|
+
// between (utils/regular-file.js readContainedBytes).
|
|
43
|
+
const head = await readContainedBytes(filePath, root, PREVIEW_BYTES, { head: true })
|
|
44
|
+
if (head === null) return { preview: null, cwd: null }
|
|
45
|
+
const buf = head
|
|
46
|
+
const bytesRead = head.length
|
|
44
47
|
// Use TextDecoder with stream: true to avoid replacement characters
|
|
45
48
|
// when the read boundary splits a multi-byte UTF-8 character
|
|
46
49
|
const decoder = new TextDecoder('utf-8', { fatal: false })
|
|
@@ -92,15 +95,15 @@ async function extractMetadata(filePath) {
|
|
|
92
95
|
return { preview, cwd }
|
|
93
96
|
} catch {
|
|
94
97
|
return { preview: null, cwd: null }
|
|
95
|
-
} finally {
|
|
96
|
-
if (handle) await handle.close()
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
async function performScan(projectsDir) {
|
|
101
|
+
async function performScan(projectsDir, provider) {
|
|
101
102
|
let projectDirs
|
|
103
|
+
let rootReal
|
|
102
104
|
try {
|
|
103
|
-
|
|
105
|
+
rootReal = await realpath(projectsDir)
|
|
106
|
+
projectDirs = await readdir(rootReal, { withFileTypes: true })
|
|
104
107
|
} catch {
|
|
105
108
|
return []
|
|
106
109
|
}
|
|
@@ -115,7 +118,7 @@ async function performScan(projectsDir) {
|
|
|
115
118
|
const decodedPath = decodeProjectPath(encodedName)
|
|
116
119
|
const projectName = decodedPath ? basename(decodedPath) : encodedName
|
|
117
120
|
|
|
118
|
-
const dirPath = join(
|
|
121
|
+
const dirPath = join(rootReal, encodedName)
|
|
119
122
|
let files
|
|
120
123
|
try {
|
|
121
124
|
files = await readdir(dirPath)
|
|
@@ -129,6 +132,7 @@ async function performScan(projectsDir) {
|
|
|
129
132
|
candidates.push({
|
|
130
133
|
filePath: join(dirPath, file),
|
|
131
134
|
conversationId: file.replace('.jsonl', ''),
|
|
135
|
+
locator: `${encodedName}/${file}`,
|
|
132
136
|
decodedPath,
|
|
133
137
|
projectName,
|
|
134
138
|
})
|
|
@@ -146,10 +150,16 @@ async function performScan(projectsDir) {
|
|
|
146
150
|
|
|
147
151
|
if (fileStat.size < MIN_FILE_SIZE) return null
|
|
148
152
|
|
|
149
|
-
const { preview, cwd } = await extractMetadata(c.filePath)
|
|
153
|
+
const { preview, cwd } = await extractMetadata(c.filePath, rootReal)
|
|
150
154
|
|
|
151
155
|
return {
|
|
152
156
|
conversationId: c.conversationId,
|
|
157
|
+
// #7828: which provider's store this was found in, and an opaque,
|
|
158
|
+
// read-only locator (`<project dir>/<file>`, relative to that provider's
|
|
159
|
+
// projects dir) the matching transcript adapter resolves. Never a path
|
|
160
|
+
// the client can substitute: the reader re-validates it.
|
|
161
|
+
provider,
|
|
162
|
+
sourceLocator: c.locator,
|
|
153
163
|
project: cwd || c.decodedPath,
|
|
154
164
|
projectName: cwd ? basename(cwd) : c.projectName,
|
|
155
165
|
modifiedAt: fileStat.mtime.toISOString(),
|
|
@@ -194,14 +204,26 @@ export async function scanConversations(opts = {}) {
|
|
|
194
204
|
let dirs
|
|
195
205
|
if (Array.isArray(opts.projectsDirs) && opts.projectsDirs.length > 0) {
|
|
196
206
|
// Deduplicate while preserving order
|
|
197
|
-
|
|
207
|
+
// Entries are a bare directory (untagged: provider null) or a
|
|
208
|
+
// `{ provider, projectsDir }` source (#7828). Dedup on directory + provider.
|
|
209
|
+
const seenEntries = new Set()
|
|
210
|
+
dirs = []
|
|
211
|
+
for (const e of opts.projectsDirs) {
|
|
212
|
+
const entry = typeof e === 'string' ? { projectsDir: e, provider: null } : { projectsDir: e?.projectsDir, provider: e?.provider ?? null }
|
|
213
|
+
if (typeof entry.projectsDir !== 'string' || entry.projectsDir === '') continue
|
|
214
|
+
const k = `${entry.provider}\0${entry.projectsDir}`
|
|
215
|
+
if (seenEntries.has(k)) continue
|
|
216
|
+
seenEntries.add(k)
|
|
217
|
+
dirs.push(entry)
|
|
218
|
+
}
|
|
198
219
|
} else {
|
|
199
|
-
|
|
220
|
+
// The default store is Claude's; an explicit single dir is untagged.
|
|
221
|
+
dirs = [{ projectsDir: opts.projectsDir || claudeProjectsDir(), provider: opts.projectsDir ? null : 'claude' }]
|
|
200
222
|
}
|
|
201
223
|
const maxResults = Math.max(0, Math.floor(opts.maxResults || 0))
|
|
202
224
|
|
|
203
225
|
// Cache key is the sorted+joined list of directories (sorted for stability)
|
|
204
|
-
const cacheKey =
|
|
226
|
+
const cacheKey = dirs.map(d => `${d.provider}\u0001${d.projectsDir}`).sort().join('\0')
|
|
205
227
|
|
|
206
228
|
// Check cache
|
|
207
229
|
const now = Date.now()
|
|
@@ -220,7 +242,7 @@ export async function scanConversations(opts = {}) {
|
|
|
220
242
|
// Scan all directories and merge results
|
|
221
243
|
_pendingScanKey = cacheKey
|
|
222
244
|
_pendingScan = (async () => {
|
|
223
|
-
const perDirResults = await Promise.all(dirs.map(d => performScan(d)))
|
|
245
|
+
const perDirResults = await Promise.all(dirs.map(d => performScan(d.projectsDir, d.provider)))
|
|
224
246
|
// Flatten, sort merged results by most recently modified
|
|
225
247
|
const merged = perDirResults.flat()
|
|
226
248
|
merged.sort((a, b) => b.modifiedAtMs - a.modifiedAtMs)
|