@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
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import { stat
|
|
1
|
+
import { stat } from 'fs/promises'
|
|
2
2
|
import { constants as fsConstants } from 'fs'
|
|
3
|
-
import { resolve, dirname, normalize,
|
|
3
|
+
import { resolve, dirname, normalize, extname } from 'path'
|
|
4
4
|
import { homedir } from 'os'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { claudeConfigDir, isFilesystemRoot, resolveClaudeConfigDirOverride } from '../utils/claude-config-dir.js'
|
|
6
|
+
import { realpathOfDeepestAncestor, isConfigDirOrDirectChild, fileOpErrorMessage, clientSafeError } from './common.js'
|
|
7
|
+
import { truncateForLog } from './reader.js'
|
|
8
|
+
import { createLogger } from '../logger.js'
|
|
9
|
+
import { openNoFollow } from './open-nofollow.js'
|
|
10
|
+
import { isPathWithin } from '../utils/path-containment.js'
|
|
11
|
+
import { projectSlug } from '../jsonl-reader.js'
|
|
12
|
+
import { readPinnedHandle, readFdBounded } from '../utils/regular-file.js'
|
|
13
|
+
|
|
14
|
+
const log = createLogger('ws')
|
|
7
15
|
|
|
8
16
|
/** stat-size ceiling before attempting a read (matches readFileContent) */
|
|
9
17
|
const MAX_FILE_SIZE = 512 * 1024
|
|
@@ -109,16 +117,26 @@ function hasMarkdownExt(p) {
|
|
|
109
117
|
* IMPORT_ALLOWED_EXTS is rejected up front — same skip shape as out-of-bounds —
|
|
110
118
|
* closing the "@import a non-markdown sensitive file under ~/.claude" class (#6971).
|
|
111
119
|
*
|
|
120
|
+
* With `{ markdownOutside: projectReal }` (the three fixed root files pass this,
|
|
121
|
+
* #8021), the target may resolve anywhere INSIDE `projectReal` — the dashboard's
|
|
122
|
+
* file viewer can already open every file there, so a `CLAUDE.md` symlinked to
|
|
123
|
+
* an extensionless `.cursorrules` keeps working — but a target OUTSIDE it (i.e.
|
|
124
|
+
* under ~/.claude) must be markdown. That closes `CLAUDE.md ->
|
|
125
|
+
* ~/.claude/.credentials.json`, which the fixed roots' exemption from the
|
|
126
|
+
* `@import` gate had left open.
|
|
127
|
+
*
|
|
112
128
|
* Never throws — every failure mode folds into a ready-to-push `skipEntry`
|
|
113
129
|
* (byte-identical MEMORY_SKIP_ERROR shape, echoing the LEXICAL request path —
|
|
114
130
|
* no distinguishing oracle) instead of a resolved path.
|
|
115
131
|
*
|
|
116
132
|
* @param {string} lexicalAbsPath - Absolute LEXICAL (pre-realpath) target path
|
|
117
133
|
* @param {string[]} allowedRoots - Real-path roots the target must resolve within
|
|
118
|
-
* @param {{requireMarkdownExt?: boolean}} [opts] -
|
|
134
|
+
* @param {{requireMarkdownExt?: boolean, markdownOutside?: string}} [opts] - `requireMarkdownExt`:
|
|
135
|
+
* the `@import` markdown gate; `markdownOutside`: the project's real path, outside of
|
|
136
|
+
* which the target must be markdown (fixed root files, #8021)
|
|
119
137
|
* @returns {Promise<{resolvedPath: string|null, skipEntry: object|null}>}
|
|
120
138
|
*/
|
|
121
|
-
async function resolveConfinedMemoryPath(lexicalAbsPath, allowedRoots, { requireMarkdownExt = false } = {}) {
|
|
139
|
+
async function resolveConfinedMemoryPath(lexicalAbsPath, allowedRoots, { requireMarkdownExt = false, markdownOutside = null } = {}) {
|
|
122
140
|
const base = { path: lexicalAbsPath, exists: false, content: null, truncated: false, skipped: false, error: null }
|
|
123
141
|
|
|
124
142
|
// `@import` markdown allowlist (import path ONLY; the fixed root files are
|
|
@@ -126,8 +144,9 @@ async function resolveConfinedMemoryPath(lexicalAbsPath, allowedRoots, { require
|
|
|
126
144
|
// `~/.claude/settings.json`, an identity key, a `.jsonl` transcript, an
|
|
127
145
|
// extensionless file — is rejected with the SAME shape an out-of-bounds path
|
|
128
146
|
// gets, so there's no distinguishing oracle between "out of bounds", "not
|
|
129
|
-
// markdown", and "doesn't exist".
|
|
130
|
-
// so a non-markdown import never
|
|
147
|
+
// markdown", and "doesn't exist". This LEXICAL check runs BEFORE any
|
|
148
|
+
// realpath/stat, so a non-markdown import never touches the filesystem; the
|
|
149
|
+
// resolved target is checked again below (#8017). (#6971)
|
|
131
150
|
if (requireMarkdownExt && !hasMarkdownExt(lexicalAbsPath)) {
|
|
132
151
|
return { resolvedPath: null, skipEntry: { ...base, skipped: true, error: MEMORY_SKIP_ERROR } }
|
|
133
152
|
}
|
|
@@ -142,7 +161,25 @@ async function resolveConfinedMemoryPath(lexicalAbsPath, allowedRoots, { require
|
|
|
142
161
|
return { resolvedPath: null, skipEntry: { ...base, skipped: true, error: MEMORY_SKIP_ERROR } }
|
|
143
162
|
}
|
|
144
163
|
|
|
145
|
-
|
|
164
|
+
// #8017 — the lexical check above only sees the path AS WRITTEN. A `.md`-named
|
|
165
|
+
// symlink (`notes.md -> ~/.claude/.credentials.json`) passes it and resolves
|
|
166
|
+
// in-bounds, so the allowlist must hold for the RESOLVED target too — the
|
|
167
|
+
// path phase 2 actually opens. Same skip shape: no oracle.
|
|
168
|
+
if (requireMarkdownExt && !hasMarkdownExt(resolvedPath)) {
|
|
169
|
+
return { resolvedPath: null, skipEntry: { ...base, skipped: true, error: MEMORY_SKIP_ERROR } }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// #8021 — a fixed root may point anywhere in the project, but outside it
|
|
173
|
+
// (under ~/.claude) only at markdown. Same skip shape: no oracle.
|
|
174
|
+
// Nested roots, on purpose: when the session cwd is home (or above), ~/.claude
|
|
175
|
+
// is INSIDE the project, so this never fires — and `read_file` can then open
|
|
176
|
+
// ~/.claude/.credentials.json directly too. The invariant is "the memory panel
|
|
177
|
+
// exposes nothing the file viewer would refuse", pinned by memory-read.test.js.
|
|
178
|
+
if (markdownOutside && !isPathWithin(resolvedPath, markdownOutside) && !hasMarkdownExt(resolvedPath)) {
|
|
179
|
+
return { resolvedPath: null, skipEntry: { ...base, skipped: true, error: MEMORY_SKIP_ERROR } }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const withinRoot = allowedRoots.some((root) => isPathWithin(resolvedPath, root))
|
|
146
183
|
if (!withinRoot) {
|
|
147
184
|
// Outside every allowed root — reject WITHOUT stat'ing (no existence oracle).
|
|
148
185
|
// Echo the LEXICAL request path (base.path), NOT the realpath-resolved path,
|
|
@@ -150,20 +187,34 @@ async function resolveConfinedMemoryPath(lexicalAbsPath, allowedRoots, { require
|
|
|
150
187
|
return { resolvedPath: null, skipEntry: { ...base, skipped: true, error: MEMORY_SKIP_ERROR } }
|
|
151
188
|
}
|
|
152
189
|
|
|
190
|
+
// The config directory itself and any file directly in it are daemon-managed
|
|
191
|
+
// state, so the memory panel shows nothing the file viewer refuses (the same
|
|
192
|
+
// invariant as the #8021 carve-out above). It only bites when the config
|
|
193
|
+
// directory sits INSIDE an allowed root, i.e. a project cwd at or above it. Same
|
|
194
|
+
// skip shape as every other refusal here: no oracle.
|
|
195
|
+
if (await isConfigDirOrDirectChild(resolvedPath)) {
|
|
196
|
+
return { resolvedPath: null, skipEntry: { ...base, skipped: true, error: MEMORY_SKIP_ERROR } }
|
|
197
|
+
}
|
|
198
|
+
|
|
153
199
|
return { resolvedPath, skipEntry: null }
|
|
154
200
|
}
|
|
155
201
|
|
|
156
202
|
/**
|
|
157
203
|
* Phase 2 of the confined-memory-file read: `stat`/`open`/read an ALREADY
|
|
158
204
|
* resolved+validated real path (see `resolveConfinedMemoryPath`). The final
|
|
159
|
-
* open
|
|
160
|
-
* swapped in at the target between validation and open is
|
|
161
|
-
* followed)
|
|
205
|
+
* open goes through `openNoFollow`, which closes the post-validation TOCTOU
|
|
206
|
+
* window (a symlink swapped in at the target between validation and open is
|
|
207
|
+
* rejected with ELOOP, not followed) on win32 as well as POSIX — the bare
|
|
208
|
+
* `O_NOFOLLOW` flag this used to pass is undefined on Windows and ORed to 0,
|
|
209
|
+
* so the refusal documented here was not actually happening there (#7280).
|
|
162
210
|
*
|
|
163
211
|
* @param {string} resolvedPath - Real (post-realpath, already containment-checked) path
|
|
212
|
+
* @param {() => Promise<void>} [__testBetweenStatAndOpen] - TEST-ONLY seam, run
|
|
213
|
+
* after the pre-open `stat` and before the open so a test can swap the file
|
|
214
|
+
* for a FIFO deterministically. Every production caller passes one argument.
|
|
164
215
|
* @returns {Promise<{path: string, exists: boolean, content: string|null, truncated: boolean, skipped: boolean, error: string|null}>}
|
|
165
216
|
*/
|
|
166
|
-
async function readResolvedMemoryFile(resolvedPath) {
|
|
217
|
+
export async function readResolvedMemoryFile(resolvedPath, __testBetweenStatAndOpen, pinRoot = null) {
|
|
167
218
|
const base = { path: resolvedPath, exists: false, content: null, truncated: false, skipped: false, error: null }
|
|
168
219
|
|
|
169
220
|
let fileStat
|
|
@@ -171,7 +222,8 @@ async function readResolvedMemoryFile(resolvedPath) {
|
|
|
171
222
|
fileStat = await stat(resolvedPath)
|
|
172
223
|
} catch (err) {
|
|
173
224
|
if (err.code === 'ENOENT') return { ...base, exists: false }
|
|
174
|
-
|
|
225
|
+
log.error(`memory file stat failed: ${truncateForLog(err.message)}`)
|
|
226
|
+
return { ...base, error: fileOpErrorMessage(err) }
|
|
175
227
|
}
|
|
176
228
|
|
|
177
229
|
if (!fileStat.isFile()) {
|
|
@@ -181,17 +233,40 @@ async function readResolvedMemoryFile(resolvedPath) {
|
|
|
181
233
|
return { ...base, exists: true, error: 'File too large (max 512KB)' }
|
|
182
234
|
}
|
|
183
235
|
|
|
236
|
+
if (__testBetweenStatAndOpen) await __testBetweenStatAndOpen()
|
|
237
|
+
|
|
184
238
|
let buf
|
|
185
239
|
let fh
|
|
186
240
|
try {
|
|
187
|
-
fh = await
|
|
188
|
-
|
|
241
|
+
fh = await openNoFollow(resolvedPath, fsConstants.O_RDONLY)
|
|
242
|
+
// #7938 — the `fileStat.isFile()` check above ran BEFORE this open, so it
|
|
243
|
+
// cannot see a non-regular file (a FIFO/device) swapped in during the
|
|
244
|
+
// TOCTOU window between that stat and this open. openNoFollow's O_NONBLOCK
|
|
245
|
+
// keeps the open itself from hanging on a planted FIFO with no writer, but
|
|
246
|
+
// reading its content is still the wrong thing to do — re-check isFile()
|
|
247
|
+
// on the OPENED fd, which cannot be raced the same way, before reading.
|
|
248
|
+
// Without this, a FIFO raced in here reads as an EMPTY file (a
|
|
249
|
+
// non-blocking read of a writerless FIFO is EOF): exists, content '',
|
|
250
|
+
// no error. Same text as the pre-open refusal above.
|
|
251
|
+
// Bounded read from the descriptor; with a pin root the opened object must
|
|
252
|
+
// also be the file this name denotes beneath that root (parents included).
|
|
253
|
+
try {
|
|
254
|
+
buf = pinRoot
|
|
255
|
+
? await readPinnedHandle(fh, resolvedPath, pinRoot, MAX_FILE_SIZE)
|
|
256
|
+
: await readFdBounded(fh, MAX_FILE_SIZE)
|
|
257
|
+
} catch (pinErr) {
|
|
258
|
+
if (pinErr.code === 'ENOTREG') throw clientSafeError('Not a regular file')
|
|
259
|
+
if (pinErr.code === 'EFBIG') throw clientSafeError('File too large (max 512KB)')
|
|
260
|
+
if (pinErr.code === 'EACCES') throw Object.assign(new Error('pinned'), { code: 'ELOOP' })
|
|
261
|
+
throw pinErr
|
|
262
|
+
}
|
|
189
263
|
} catch (err) {
|
|
190
264
|
if (err.code === 'ELOOP') {
|
|
191
265
|
// Symlink appeared at the canonical path after validation — reject.
|
|
192
266
|
return { ...base, exists: true, skipped: true, error: 'Access denied: possible symlink race — read skipped' }
|
|
193
267
|
}
|
|
194
|
-
|
|
268
|
+
log.error(`memory file read failed: ${truncateForLog(err.message)}`)
|
|
269
|
+
return { ...base, exists: true, error: fileOpErrorMessage(err) }
|
|
195
270
|
} finally {
|
|
196
271
|
await fh?.close()
|
|
197
272
|
}
|
|
@@ -216,13 +291,18 @@ async function readResolvedMemoryFile(resolvedPath) {
|
|
|
216
291
|
*
|
|
217
292
|
* @param {string} lexicalAbsPath - Absolute LEXICAL (pre-realpath) target path
|
|
218
293
|
* @param {string[]} allowedRoots - Real-path roots the target must resolve within
|
|
219
|
-
* @param {{requireMarkdownExt?: boolean}} [opts] -
|
|
294
|
+
* @param {{requireMarkdownExt?: boolean, markdownOutside?: string}} [opts] - see resolveConfinedMemoryPath
|
|
220
295
|
* @returns {Promise<{path: string|null, exists: boolean, content: string|null, truncated: boolean, skipped: boolean, error: string|null}>}
|
|
221
296
|
*/
|
|
297
|
+
/** The allowed root a resolved path lies beneath (the root its parents are pinned to). */
|
|
298
|
+
function pinRootFor(resolvedPath, allowedRoots) {
|
|
299
|
+
return allowedRoots.find((r) => isPathWithin(resolvedPath, r)) ?? null
|
|
300
|
+
}
|
|
301
|
+
|
|
222
302
|
async function readConfinedMemoryFile(lexicalAbsPath, allowedRoots, opts = {}) {
|
|
223
303
|
const { resolvedPath, skipEntry } = await resolveConfinedMemoryPath(lexicalAbsPath, allowedRoots, opts)
|
|
224
304
|
if (skipEntry) return skipEntry
|
|
225
|
-
return readResolvedMemoryFile(resolvedPath)
|
|
305
|
+
return readResolvedMemoryFile(resolvedPath, undefined, pinRootFor(resolvedPath, allowedRoots))
|
|
226
306
|
}
|
|
227
307
|
|
|
228
308
|
/**
|
|
@@ -247,7 +327,7 @@ async function collectImports(content, importingFileAbsPath, allowedRoots, visit
|
|
|
247
327
|
const key = resolvedPath || lexicalTarget
|
|
248
328
|
if (visited.has(key)) continue // cycle/dup guard — before any read
|
|
249
329
|
visited.add(key)
|
|
250
|
-
const entry = skipEntry ?? await readResolvedMemoryFile(resolvedPath)
|
|
330
|
+
const entry = skipEntry ?? await readResolvedMemoryFile(resolvedPath, undefined, pinRootFor(resolvedPath, allowedRoots))
|
|
251
331
|
outEntries.push({ ...entry, scope: 'import', importedFrom: importingFileAbsPath })
|
|
252
332
|
if (entry.exists && entry.content && !entry.skipped && !entry.error) {
|
|
253
333
|
await collectImports(entry.content, entry.path, allowedRoots, visited, depth + 1, outEntries)
|
|
@@ -272,7 +352,8 @@ export function createMemoryOps(sendFn, resolveSessionCwd) {
|
|
|
272
352
|
* https://code.claude.com/docs/en/memory ("content is ordered from the
|
|
273
353
|
* filesystem root down to your working directory"; within one directory,
|
|
274
354
|
* CLAUDE.local.md is read right after that directory's CLAUDE.md):
|
|
275
|
-
* 1. global —
|
|
355
|
+
* 1. global — <claude config dir>/CLAUDE.md (loaded first, lowest precedence;
|
|
356
|
+
* the dir is CLAUDE_CONFIG_DIR when valid, else ~/.claude)
|
|
276
357
|
* 2. project — <sessionCwd>/CLAUDE.md
|
|
277
358
|
* 3. local — <sessionCwd>/CLAUDE.local.md (loaded last, highest precedence)
|
|
278
359
|
* Managed/enterprise policy memory is out of scope — chroxy has no managed-
|
|
@@ -286,7 +367,7 @@ export function createMemoryOps(sendFn, resolveSessionCwd) {
|
|
|
286
367
|
* design), so there is no client-controlled traversal surface for the three
|
|
287
368
|
* root files. The ONLY variable input is @import references found INSIDE
|
|
288
369
|
* those files' own content, which are confined to the same two roots
|
|
289
|
-
* (session cwd,
|
|
370
|
+
* (session cwd, claude's config dir) via `readConfinedMemoryFile` AND restricted
|
|
290
371
|
* to markdown targets (`.md`/`.markdown`) — an import resolving outside both
|
|
291
372
|
* roots, or to a non-markdown file (e.g. `~/.claude/.credentials.json`), is
|
|
292
373
|
* reported (for provenance/transparency) with `skipped: true` and is never
|
|
@@ -296,12 +377,12 @@ export function createMemoryOps(sendFn, resolveSessionCwd) {
|
|
|
296
377
|
*
|
|
297
378
|
* Also resolves the project's auto-generated MEMORY.md descriptor, keyed by
|
|
298
379
|
* the SAME per-cwd path encoding `resolveJsonlPath` uses for transcript
|
|
299
|
-
* storage (`
|
|
380
|
+
* storage (`projectSlug` in jsonl-reader.js) — confirmed empirically
|
|
300
381
|
* against a live `~/.claude/projects/` tree to be keyed by the literal
|
|
301
382
|
* session cwd, not the git repository root (each worktree gets its own,
|
|
302
383
|
* separate memory directory).
|
|
303
384
|
*/
|
|
304
|
-
async function readMemoryStack(ws, sessionCwd, requestId) {
|
|
385
|
+
async function readMemoryStack(ws, sessionCwd, requestId, { confineToProject = false } = {}) {
|
|
305
386
|
const send = (payload) => sendFn(ws, requestId === undefined ? payload : { ...payload, requestId })
|
|
306
387
|
|
|
307
388
|
if (!sessionCwd) {
|
|
@@ -313,29 +394,50 @@ export function createMemoryOps(sendFn, resolveSessionCwd) {
|
|
|
313
394
|
try {
|
|
314
395
|
cwdReal = await resolveSessionCwd(sessionCwd)
|
|
315
396
|
} catch (err) {
|
|
316
|
-
|
|
397
|
+
log.error(`memory stack cwd resolve failed: ${truncateForLog(err.message)}`)
|
|
398
|
+
send({ type: 'memory_stack_result', entries: [], memoryFile: null, error: fileOpErrorMessage(err, 'Failed to resolve session directory') })
|
|
317
399
|
return
|
|
318
400
|
}
|
|
319
401
|
|
|
402
|
+
// The canonical form is read first and the async resolution second; the
|
|
403
|
+
// global memory root is used only when the two are equal and not a filesystem
|
|
404
|
+
// root, otherwise it is unavailable. claudeConfigDir() is canonical for an
|
|
405
|
+
// override but the default `<home>/.claude` is only lexical, so the canonical
|
|
406
|
+
// form comes from the same sync resolver for both.
|
|
407
|
+
const claudeHome = claudeConfigDir()
|
|
408
|
+
const claudeHomeCanonical = resolveClaudeConfigDirOverride(claudeHome)
|
|
320
409
|
let claudeHomeReal
|
|
321
410
|
try {
|
|
322
|
-
claudeHomeReal = await realpathOfDeepestAncestor(
|
|
411
|
+
claudeHomeReal = await realpathOfDeepestAncestor(claudeHome)
|
|
323
412
|
} catch {
|
|
324
|
-
claudeHomeReal = normalize(
|
|
413
|
+
claudeHomeReal = normalize(claudeHome)
|
|
325
414
|
}
|
|
326
|
-
|
|
327
|
-
|
|
415
|
+
const claudeRootUsable = claudeHomeCanonical !== null && claudeHomeReal === claudeHomeCanonical && !isFilesystemRoot(claudeHomeReal)
|
|
416
|
+
// The session's own generated-memory directory inside the config tree.
|
|
417
|
+
const encoded = projectSlug(cwdReal)
|
|
418
|
+
// The lexical name is the root, always. `projects/<slug>` may itself be a
|
|
419
|
+
// link: a project-confined reader then refuses it (a component of the root is a
|
|
420
|
+
// link, so nothing resolves beneath it), and an unconfined reader resolves the
|
|
421
|
+
// file's real path against the whole config tree anyway.
|
|
422
|
+
const projectMemoryRoot = resolve(claudeHomeReal, 'projects', encoded)
|
|
423
|
+
// A project-confined reader (a session-scoped connection) is given the
|
|
424
|
+
// session directory and THIS project's memory directory — not the whole
|
|
425
|
+
// config tree, which also holds the user-level memory and every other
|
|
426
|
+
// project's memory — and the user-level CLAUDE.md is not read at all.
|
|
427
|
+
const allowedRoots = confineToProject
|
|
428
|
+
? (claudeRootUsable ? [cwdReal, projectMemoryRoot] : [cwdReal])
|
|
429
|
+
: (claudeRootUsable ? [cwdReal, claudeHomeReal] : [cwdReal])
|
|
328
430
|
const visited = new Set()
|
|
329
431
|
const entries = []
|
|
330
432
|
|
|
331
433
|
const roots = [
|
|
332
|
-
{ scope: 'global', lexicalPath: resolve(claudeHomeReal, 'CLAUDE.md') },
|
|
434
|
+
...(confineToProject ? [] : [{ scope: 'global', lexicalPath: resolve(claudeHomeReal, 'CLAUDE.md') }]),
|
|
333
435
|
{ scope: 'project', lexicalPath: resolve(cwdReal, 'CLAUDE.md') },
|
|
334
436
|
{ scope: 'local', lexicalPath: resolve(cwdReal, 'CLAUDE.local.md') },
|
|
335
437
|
]
|
|
336
438
|
|
|
337
439
|
for (const { scope, lexicalPath } of roots) {
|
|
338
|
-
const entry = await readConfinedMemoryFile(lexicalPath, allowedRoots)
|
|
440
|
+
const entry = await readConfinedMemoryFile(lexicalPath, allowedRoots, { markdownOutside: cwdReal })
|
|
339
441
|
visited.add(entry.path || lexicalPath)
|
|
340
442
|
entries.push({ ...entry, scope, importedFrom: null })
|
|
341
443
|
if (entry.exists && entry.content && !entry.skipped && !entry.error) {
|
|
@@ -344,10 +446,10 @@ export function createMemoryOps(sendFn, resolveSessionCwd) {
|
|
|
344
446
|
}
|
|
345
447
|
|
|
346
448
|
// Auto-generated project memory (MEMORY.md) — restricted to the
|
|
347
|
-
//
|
|
348
|
-
|
|
349
|
-
const memoryFilePath = resolve(
|
|
350
|
-
const memoryFile = await readConfinedMemoryFile(memoryFilePath, [claudeHomeReal])
|
|
449
|
+
// claude config dir root only (it never lives under the session cwd), and
|
|
450
|
+
// its resolved target must be markdown like every other read here.
|
|
451
|
+
const memoryFilePath = resolve(projectMemoryRoot, 'memory', 'MEMORY.md')
|
|
452
|
+
const memoryFile = await readConfinedMemoryFile(memoryFilePath, claudeRootUsable ? [confineToProject ? projectMemoryRoot : claudeHomeReal] : [], { requireMarkdownExt: true })
|
|
351
453
|
|
|
352
454
|
send({ type: 'memory_stack_result', entries, memoryFile, error: null })
|
|
353
455
|
}
|