@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.
Files changed (326) hide show
  1. package/CONFIG.md +602 -19
  2. package/README.md +2 -2
  3. package/hooks/claude-native-route-check.mjs +17 -0
  4. package/hooks/permission-hook.sh +416 -11
  5. package/package.json +20 -23
  6. package/sidecar/Dockerfile +1 -1
  7. package/sidecar/PROTOCOL.md +9 -1
  8. package/sidecar/agent.js +102 -10
  9. package/sidecar/package-lock.json +3 -3
  10. package/src/acp-config.js +206 -0
  11. package/src/acp-session.js +954 -0
  12. package/src/activity-registry.js +110 -5
  13. package/src/agent-connections.js +293 -0
  14. package/src/agent-control/client.js +1616 -0
  15. package/src/agent-control/events.js +547 -0
  16. package/src/agent-control/local-connection.js +275 -0
  17. package/src/agent-control/mcp-server.js +545 -0
  18. package/src/anthropic-compatible-config.js +29 -4
  19. package/src/anthropic-compatible-session.js +15 -6
  20. package/src/anthropic-openai-shim.js +0 -1
  21. package/src/archive-continuation.js +164 -0
  22. package/src/assistant-response.js +24 -0
  23. package/src/auth-probes.js +120 -13
  24. package/src/background-shell-tracker.js +27 -0
  25. package/src/base-session.js +1353 -41
  26. package/src/bearer-recheck.js +49 -0
  27. package/src/billing-budget.js +24 -1
  28. package/src/billing-class.js +40 -7
  29. package/src/binary-provenance-trust.js +101 -0
  30. package/src/bound-client-policy.js +279 -0
  31. package/src/built-in-tools/bash-exec.js +46 -7
  32. package/src/built-in-tools/file-ops.js +74 -9
  33. package/src/built-in-tools/tool-transforms.js +1113 -13
  34. package/src/byok-compose-state.js +6 -9
  35. package/src/byok-credentials.js +2 -3
  36. package/src/byok-mcp-client.js +1153 -20
  37. package/src/byok-mcp-config.js +1712 -8
  38. package/src/byok-mcp-fleet.js +416 -29
  39. package/src/byok-mcp-oauth-store.js +329 -0
  40. package/src/byok-mcp-oauth.js +635 -0
  41. package/src/byok-mcp-trust.js +257 -40
  42. package/src/byok-session.js +1400 -149
  43. package/src/byok-tool-executor.js +2681 -38
  44. package/src/byok-tools.js +9 -2
  45. package/src/channels/chroxy-channel-server.js +2 -3
  46. package/src/checkpoint-manager.js +96 -51
  47. package/src/chroxy-host-metadata.js +122 -0
  48. package/src/claude-channel-session.js +16 -10
  49. package/src/claude-model-catalog.js +131 -16
  50. package/src/claude-model-refresh.js +385 -0
  51. package/src/claude-model-request.js +103 -0
  52. package/src/claude-stream-parser.js +109 -3
  53. package/src/claude-tui/diagnostic-tail.js +83 -0
  54. package/src/claude-tui/form-driver.js +44 -7
  55. package/src/claude-tui/model-error.js +41 -0
  56. package/src/claude-tui/pty-driver.js +223 -60
  57. package/src/claude-tui/sanitize-question-payload.js +109 -0
  58. package/src/claude-tui/usage-limit.js +239 -0
  59. package/src/claude-tui-session.js +3611 -286
  60. package/src/claude-tui-tool-response.js +300 -0
  61. package/src/cli/agent-control-cmd.js +65 -0
  62. package/src/cli/config-cmd.js +6 -6
  63. package/src/cli/config-dir-cmd.js +234 -0
  64. package/src/cli/deploy-cmd.js +46 -11
  65. package/src/cli/doctor-cmd.js +7 -3
  66. package/src/cli/init-cmd.js +16 -17
  67. package/src/cli/providers-cmd.js +6 -6
  68. package/src/cli/schedule-cmd.js +804 -0
  69. package/src/cli/server-cmd.js +64 -2
  70. package/src/cli/service-cmd.js +70 -27
  71. package/src/cli/session-cmd.js +227 -74
  72. package/src/cli/shared.js +168 -14
  73. package/src/cli/tokens-cmd.js +212 -0
  74. package/src/cli/tunnel-cmd.js +256 -25
  75. package/src/cli/worktree-gc-cmd.js +2 -2
  76. package/src/cli-session.js +1117 -116
  77. package/src/cli.js +8 -0
  78. package/src/codex-app-server-client.js +36 -3
  79. package/src/codex-app-server-session.js +2108 -101
  80. package/src/codex-bundled-client.js +66 -0
  81. package/src/codex-model-catalog.js +548 -0
  82. package/src/codex-model-rejections.js +87 -0
  83. package/src/codex-native-resume.js +104 -0
  84. package/src/codex-protocol-capabilities.js +188 -0
  85. package/src/codex-session.js +571 -45
  86. package/src/config-dir-migration.js +444 -0
  87. package/src/config-dir.js +108 -0
  88. package/src/config.js +738 -52
  89. package/src/connection-authority.js +48 -0
  90. package/src/connection-info.js +5 -9
  91. package/src/connection-locality.js +60 -0
  92. package/src/container-liveness-monitor.js +189 -0
  93. package/src/continuation-metadata-worker.js +17 -0
  94. package/src/continuations.js +114 -0
  95. package/src/control-room/host-prune.js +5 -0
  96. package/src/control-room/integrations.js +23 -30
  97. package/src/control-room/skills-inventory.js +8 -3
  98. package/src/control-room/survey.js +32 -0
  99. package/src/conversation-scanner.js +40 -18
  100. package/src/conversation-scope.js +59 -39
  101. package/src/conversation-search.js +24 -22
  102. package/src/credential-store.js +279 -29
  103. package/src/daemon-commit.js +92 -0
  104. package/src/daemon-idle-state.js +171 -0
  105. package/src/daemon-update-status.js +314 -0
  106. package/src/dashboard-build.js +70 -0
  107. package/src/declared-status.js +90 -0
  108. package/src/deepseek-credentials.js +2 -3
  109. package/src/dev-preview.js +169 -182
  110. package/src/device-preferences.js +2 -2
  111. package/src/diagnostics.js +3 -0
  112. package/src/diff-parser.js +87 -0
  113. package/src/discord-credentials.js +2 -3
  114. package/src/docker-byok-pool.js +3 -1
  115. package/src/docker-byok-session.js +678 -78
  116. package/src/docker-image-allowlist.js +23 -1
  117. package/src/docker-sdk-session.js +188 -4
  118. package/src/docker-session.js +293 -10
  119. package/src/doctor.js +783 -66
  120. package/src/edited-input.js +264 -0
  121. package/src/environment-manager.js +175 -36
  122. package/src/environments/authority.js +95 -0
  123. package/src/environments/backends/container-claude-spawn.js +94 -0
  124. package/src/environments/backends/docker.js +39 -10
  125. package/src/environments/backends/k8s.js +58 -24
  126. package/src/environments/destroy-with-sessions.js +142 -0
  127. package/src/event-ingest.js +137 -14
  128. package/src/event-normalizer.js +363 -110
  129. package/src/external-session-registry.js +0 -0
  130. package/src/gemini-session.js +100 -7
  131. package/src/github-webhook.js +188 -4
  132. package/src/handler-utils.js +563 -62
  133. package/src/handlers/checkpoint-handlers.js +162 -20
  134. package/src/handlers/control-room-handlers.js +99 -29
  135. package/src/handlers/conversation-handlers.js +563 -25
  136. package/src/handlers/credential-handlers.js +43 -2
  137. package/src/handlers/daemon-update-handlers.js +81 -0
  138. package/src/handlers/evaluator-handlers.js +14 -1
  139. package/src/handlers/feature-handlers.js +186 -69
  140. package/src/handlers/file-handlers.js +101 -13
  141. package/src/handlers/github-webhook-handlers.js +204 -0
  142. package/src/handlers/input-handlers.js +689 -48
  143. package/src/handlers/orchestration-handlers.js +238 -0
  144. package/src/handlers/scheduler-handlers.js +584 -0
  145. package/src/handlers/session-handlers.js +546 -16
  146. package/src/handlers/session-pr-status-handlers.js +283 -0
  147. package/src/handlers/session-pr-threads-handlers.js +247 -0
  148. package/src/handlers/settings-handlers.js +822 -35
  149. package/src/handlers/skills-handlers.js +13 -4
  150. package/src/handlers/summarize-handlers.js +32 -1
  151. package/src/handlers/survey-throttle.js +380 -0
  152. package/src/handlers/token-handlers.js +11 -2
  153. package/src/health-proof.js +40 -0
  154. package/src/history-page.js +104 -0
  155. package/src/http-routes.js +286 -8
  156. package/src/ide/search.js +24 -6
  157. package/src/ide/symbols.js +20 -6
  158. package/src/input-context.js +117 -0
  159. package/src/instruction-policy-compiler.js +229 -0
  160. package/src/instruction-policy.js +250 -0
  161. package/src/jsonl-reader.js +309 -48
  162. package/src/jsonl-subprocess-session.js +122 -9
  163. package/src/keychain.js +160 -13
  164. package/src/logger.js +240 -31
  165. package/src/mailbox-route.js +11 -22
  166. package/src/message-wire.js +386 -0
  167. package/src/model-discovery.js +43 -3
  168. package/src/models.js +1276 -174
  169. package/src/notification-prefs.js +100 -10
  170. package/src/notifications/discord-billing-sink.js +22 -5
  171. package/src/notifications/discord-ci-sink.js +243 -0
  172. package/src/notifications/discord-webhook-client.js +71 -0
  173. package/src/notifications/discord-webhook-sink.js +82 -12
  174. package/src/notifications/expo-push-sink.js +85 -6
  175. package/src/notifications/ready-body.js +16 -5
  176. package/src/ollama-session.js +34 -2
  177. package/src/orchestration/build-manager.js +63 -0
  178. package/src/orchestration/decision-contract.js +245 -0
  179. package/src/orchestration/git-ops.js +381 -0
  180. package/src/orchestration/orchestration-manager.js +1342 -0
  181. package/src/orchestration/permission-gate.js +121 -0
  182. package/src/orchestration/role-prompts.js +136 -0
  183. package/src/orchestration/run-budget.js +81 -0
  184. package/src/orchestration/run-ledger.js +487 -0
  185. package/src/orchestration/run-model.js +206 -0
  186. package/src/orchestration/run-record.js +336 -0
  187. package/src/orchestration/run-report.js +194 -0
  188. package/src/orchestration/to-wire.js +201 -0
  189. package/src/orchestration/turn-driver.js +422 -0
  190. package/src/orphan-reaper.js +413 -0
  191. package/src/outgoing-policy.js +183 -0
  192. package/src/pairing.js +236 -12
  193. package/src/path-hash-trust-ledger.js +642 -25
  194. package/src/permission-audit.js +79 -3
  195. package/src/permission-deadlines.js +82 -0
  196. package/src/permission-floor.js +1770 -0
  197. package/src/permission-hook.js +180 -69
  198. package/src/permission-manager.js +1175 -94
  199. package/src/permission-mode-support.js +35 -0
  200. package/src/permission-resolver.js +174 -12
  201. package/src/permission-rule-store.js +411 -0
  202. package/src/permission-scope.js +43 -0
  203. package/src/platform.js +483 -23
  204. package/src/preview-ingress.js +54 -0
  205. package/src/preview-target.js +213 -0
  206. package/src/prompt-evaluator.js +34 -4
  207. package/src/provider-customization.js +180 -0
  208. package/src/providers.js +228 -6
  209. package/src/push.js +30 -4
  210. package/src/question-route-map.js +130 -0
  211. package/src/redaction.js +360 -8
  212. package/src/roster-broadcast.js +186 -0
  213. package/src/schedule-parser.js +311 -0
  214. package/src/scheduled-task-store.js +945 -0
  215. package/src/scheduler.js +1099 -0
  216. package/src/sdk-session.js +2374 -168
  217. package/src/server-cli/preview-shutdown.js +22 -0
  218. package/src/server-cli/push-notification-handler.js +11 -2
  219. package/src/server-cli/server-orchestrator.js +50 -4
  220. package/src/server-cli/tunnel-lifecycle-handler.js +3 -2
  221. package/src/server-cli-child.js +33 -18
  222. package/src/server-cli.js +760 -62
  223. package/src/server-identity.js +42 -14
  224. package/src/service.js +682 -53
  225. package/src/session-archive-limits.js +15 -0
  226. package/src/session-archive.js +1029 -0
  227. package/src/session-busy-state.js +72 -0
  228. package/src/session-ci-watcher.js +926 -0
  229. package/src/session-context.js +7 -2
  230. package/src/session-manager.js +3879 -308
  231. package/src/session-message-history.js +749 -37
  232. package/src/session-pr-status.js +654 -0
  233. package/src/session-pr-threads.js +271 -0
  234. package/src/session-preset-trust.js +3 -3
  235. package/src/session-preset.js +10 -5
  236. package/src/session-state-persistence.js +94 -17
  237. package/src/session-timeout-manager.js +20 -0
  238. package/src/session-title.js +168 -0
  239. package/src/session-token-store.js +70 -36
  240. package/src/session-wake.js +240 -0
  241. package/src/shell-approval-info.js +2 -2
  242. package/src/shell-approval-store.js +3 -1
  243. package/src/skills-loader.js +7 -4
  244. package/src/skills-manager.js +2 -2
  245. package/src/skills-trust.js +95 -13
  246. package/src/skills-usage.js +22 -5
  247. package/src/snapshots-store.js +2 -3
  248. package/src/statusline.js +596 -0
  249. package/src/subagent-counter.js +9 -1
  250. package/src/summarize-session.js +51 -4
  251. package/src/supervisor.js +99 -38
  252. package/src/sweep-stale-provider-dirs.js +95 -0
  253. package/src/thinking-level-wire.js +39 -0
  254. package/src/thinking-stream.js +179 -0
  255. package/src/token-manager.js +39 -9
  256. package/src/tool-result.js +61 -0
  257. package/src/transcript-sources.js +109 -0
  258. package/src/transcript-tasks.js +413 -31
  259. package/src/trusted-file-read.js +302 -0
  260. package/src/tunnel/base.js +0 -8
  261. package/src/tunnel/cloudflare.js +145 -35
  262. package/src/tunnel/index.js +13 -1
  263. package/src/tunnel/preview.js +64 -0
  264. package/src/tunnel-check.js +1 -1
  265. package/src/turn-outcome.js +137 -0
  266. package/src/turn-tracker.js +0 -0
  267. package/src/usage-normalize.js +122 -0
  268. package/src/user-shell-session.js +157 -37
  269. package/src/utils/agent-sdk-version.js +107 -0
  270. package/src/utils/argv-safety.js +741 -0
  271. package/src/utils/auth-cause.js +60 -0
  272. package/src/utils/binary-package-manifest.js +597 -0
  273. package/src/utils/binary-version.js +224 -0
  274. package/src/utils/bounded-regex-worker.js +25 -0
  275. package/src/utils/bounded-regex.js +153 -0
  276. package/src/utils/claude-binary.js +43 -0
  277. package/src/utils/claude-config-dir.js +245 -0
  278. package/src/utils/claude-login-command.js +16 -0
  279. package/src/utils/claude-native-route.js +81 -0
  280. package/src/utils/componentwise-resolver.js +301 -0
  281. package/src/utils/composite-key.js +45 -0
  282. package/src/utils/deploy-control-files.js +87 -0
  283. package/src/utils/exec-failure-reason.js +21 -0
  284. package/src/utils/git-repo.js +42 -0
  285. package/src/utils/is-entry-point.js +137 -0
  286. package/src/utils/iso-datetime.js +51 -0
  287. package/src/utils/node-pty-probe.js +95 -0
  288. package/src/utils/node-pty-support.js +118 -0
  289. package/src/utils/opened-file-path.js +167 -0
  290. package/src/utils/path-containment.js +165 -0
  291. package/src/utils/permission-mode-sidecar.js +51 -0
  292. package/src/utils/preflight.js +485 -29
  293. package/src/utils/read-limiter.js +217 -0
  294. package/src/utils/regular-file.js +375 -0
  295. package/src/utils/safe-regex.js +113 -0
  296. package/src/utils/small-file.js +129 -0
  297. package/src/utils/spawn-env.js +196 -5
  298. package/src/utils/stale-session-dirs.js +182 -0
  299. package/src/utils/stat-identity.js +43 -0
  300. package/src/utils/verify-binary.js +276 -0
  301. package/src/utils/verify-provenance.js +634 -0
  302. package/src/utils/wire-counters.js +48 -0
  303. package/src/web-task-manager.js +256 -16
  304. package/src/worktree-gc.js +11 -3
  305. package/src/ws-auth.js +69 -21
  306. package/src/ws-broadcaster.js +14 -2
  307. package/src/ws-client-manager.js +16 -1
  308. package/src/ws-client-sender.js +7 -0
  309. package/src/ws-file-ops/browser.js +370 -66
  310. package/src/ws-file-ops/common.js +384 -11
  311. package/src/ws-file-ops/git.js +615 -44
  312. package/src/ws-file-ops/index.js +7 -0
  313. package/src/ws-file-ops/memory.js +460 -0
  314. package/src/ws-file-ops/open-nofollow.js +354 -0
  315. package/src/ws-file-ops/reader.js +676 -94
  316. package/src/ws-forwarding.js +373 -55
  317. package/src/ws-handler-context.js +89 -2
  318. package/src/ws-history.js +1018 -177
  319. package/src/ws-message-handlers.js +23 -1
  320. package/src/ws-outbound-schemas.js +207 -0
  321. package/src/ws-permissions.js +589 -38
  322. package/src/ws-schemas.js +6 -0
  323. package/src/ws-server.js +936 -105
  324. package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +0 -111
  325. package/src/dashboard-next/dist/assets/index-DM-_dISG.css +0 -1
  326. package/src/dashboard-next/dist/index.html +0 -13
package/src/byok-tools.js CHANGED
@@ -122,11 +122,18 @@ export const BUILTIN_TOOLS = [
122
122
  name: 'Glob',
123
123
  description:
124
124
  'List files matching a glob pattern. Pattern is shell-style (e.g. `**/*.ts`, `packages/server/src/*.js`). ' +
125
- '`path` is the search root (default: workspace cwd). Returns file paths relative to the search root.',
125
+ '`path` is the search root (default: workspace cwd). Returns sorted file paths relative to the search root. ' +
126
+ 'Results are confined to the workspace: a leading `/`, a `~`, a `..` segment or a literal space is rejected, ' +
127
+ 'and any match resolving outside the workspace is withheld (#7341). Use `path` to search a subdirectory; ' +
128
+ '`**/*.pdf` still reaches into directories whose names contain spaces. Naming a directory that resolves ' +
129
+ 'outside the workspace (a symlink to a shared store, for example) is an error rather than an empty result. ' +
130
+ 'Very large results are truncated to a sorted prefix with an explicit trailing marker. `pattern` is capped ' +
131
+ 'at 2000 characters and 32 levels of "{...}" brace nesting — an oversized or overly-nested pattern is ' +
132
+ 'refused with EINVAL rather than run.',
126
133
  input_schema: {
127
134
  type: 'object',
128
135
  properties: {
129
- pattern: { type: 'string', description: 'Glob pattern (supports ** for recursive match).' },
136
+ pattern: { type: 'string', description: 'Glob pattern (supports ** for recursive match). Max 2000 characters, max 32 levels of nested "{...}".' },
130
137
  path: { type: 'string', description: 'Optional search root. Defaults to workspace cwd.' },
131
138
  },
132
139
  required: ['pattern'],
@@ -31,7 +31,7 @@
31
31
  * bridge (#3954) replaces this with a Unix socket driven solely by the session.
32
32
  */
33
33
  import { createServer } from 'http'
34
- import { pathToFileURL } from 'url'
34
+ import { isEntryPoint } from '../utils/is-entry-point.js'
35
35
  import { Server } from '@modelcontextprotocol/sdk/server/index.js'
36
36
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
37
37
  import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js'
@@ -238,8 +238,7 @@ export async function main() {
238
238
  // against pathToFileURL(process.argv[1]) — argv[1] can be a RELATIVE path (e.g.
239
239
  // `node ./chroxy-channel-server.js`), so a naive `file://${argv[1]}` would never
240
240
  // match the absolute `import.meta.url` and main() would silently never run.
241
- const isDirectRun = process.argv[1] &&
242
- import.meta.url === pathToFileURL(process.argv[1]).href
241
+ const isDirectRun = isEntryPoint(import.meta.url)
243
242
  if (isDirectRun) {
244
243
  main().catch(err => {
245
244
  console.error('[chroxy-channel] fatal:', err)
@@ -1,13 +1,16 @@
1
1
  import { EventEmitter } from 'events'
2
+ import { assertAuthorized } from './connection-authority.js'
2
3
  import { randomUUID } from 'crypto'
3
- import { existsSync, mkdirSync, readFileSync, unlinkSync } from 'fs'
4
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, unlinkSync } from 'fs'
4
5
  import { join } from 'path'
5
- import { homedir } from 'os'
6
+ import { tmpdir } from 'os'
7
+ import { stripInheritedChroxySecrets } from './utils/spawn-env.js'
6
8
  import { execFile as execFileCb } from 'child_process'
7
9
  import { promisify } from 'util'
8
10
  import { writeFileRestricted } from './platform.js'
9
11
  import { GIT } from './git.js'
10
12
  import { createLogger } from './logger.js'
13
+ import { configPath } from './config-dir.js'
11
14
 
12
15
  const log = createLogger('checkpoint')
13
16
 
@@ -17,8 +20,7 @@ const execFileAsync = promisify(execFileCb)
17
20
  // CHROXY_CONFIG_DIR in beforeEach are respected. Mirrors models.js and
18
21
  // connection-info.js (#4633).
19
22
  function defaultCheckpointsDir() {
20
- const configDir = process.env.CHROXY_CONFIG_DIR || join(homedir(), '.chroxy')
21
- return join(configDir, 'checkpoints')
23
+ return configPath('checkpoints')
22
24
  }
23
25
  const MAX_CHECKPOINTS_PER_SESSION = 50
24
26
 
@@ -62,8 +64,21 @@ async function acquireCwdLock(cwd) {
62
64
  * This avoids touching the shared stash stack, making concurrent sessions
63
65
  * in the same repository safe.
64
66
  *
65
- * Rewind creates a new session that resumes from the checkpoint's
66
- * conversation ID, effectively branching the conversation.
67
+ * The manager owns the git snapshot and the checkpoint metadata only. It does
68
+ * NOT branch the conversation itself — that is decided at restore time by the
69
+ * WS handler based on the session's provider (#6766): for a fork-capable
70
+ * provider (the SDK, via `forkSession`/`upToMessageId`) restore forks the
71
+ * conversation truncated to the checkpoint's `boundaryMessageId`, so the
72
+ * rewound session's transcript stops at the checkpoint. For providers that
73
+ * cannot truncate a resumed transcript the restore is files-only. The
74
+ * `boundaryMessageId` captured here is what makes that truncation possible.
75
+ *
76
+ * #6767: selective restore (files / conversation / both) is orchestrated by the
77
+ * WS handler, not this manager. `restoreCheckpoint` always performs the git
78
+ * restore (used for the 'files' and 'both' modes); the 'conversation'-only mode
79
+ * reads the checkpoint via `getCheckpoint` instead so the working tree is left
80
+ * untouched. Either way the returned record carries `resumeSessionId` +
81
+ * `boundaryMessageId` for the handler's fork decision.
67
82
  */
68
83
  export class CheckpointManager extends EventEmitter {
69
84
  /**
@@ -103,21 +118,15 @@ export class CheckpointManager extends EventEmitter {
103
118
  * @param {string} [params.name] - User-provided checkpoint name
104
119
  * @param {string} [params.description] - Auto-generated description (e.g., last message)
105
120
  * @param {number} [params.messageCount] - Number of messages at checkpoint time
121
+ * @param {string} [params.boundaryMessageId] - #6766: the SDK transcript UUID
122
+ * marking this checkpoint's conversation boundary. When present (SDK
123
+ * provider), restore forks the conversation truncated up to and including
124
+ * this message; absent → the restore is files-only for this checkpoint.
106
125
  * @returns {Promise<object>} The created checkpoint
107
126
  */
108
- async createCheckpoint({ sessionId, resumeSessionId, cwd, name, description, messageCount }) {
127
+ async createCheckpoint({ sessionId, resumeSessionId, cwd, name, description, messageCount, boundaryMessageId, isAuthorized }) {
109
128
  const checkpoints = this._getCheckpoints(sessionId)
110
129
 
111
- // Enforce max checkpoints — remove oldest if at limit
112
- let evictedCwd = null
113
- if (checkpoints.length >= MAX_CHECKPOINTS_PER_SESSION) {
114
- const evicted = checkpoints.shift()
115
- if (evicted?.gitRef) {
116
- evictedCwd = evicted.cwd
117
- this._deleteGitRefTracked(evicted.cwd, evicted.gitRef)
118
- }
119
- }
120
-
121
130
  const checkpoint = {
122
131
  id: randomUUID(),
123
132
  sessionId,
@@ -126,6 +135,10 @@ export class CheckpointManager extends EventEmitter {
126
135
  name: name || `Checkpoint ${(this._counters.get(sessionId) || 0) + 1}`,
127
136
  description: description || '',
128
137
  messageCount: messageCount || 0,
138
+ // #6766: fork boundary for a true conversation rewind at restore. Stored
139
+ // as null when the provider can't supply one (subprocess providers) so a
140
+ // restore of that checkpoint honestly degrades to files-only.
141
+ boundaryMessageId: typeof boundaryMessageId === 'string' && boundaryMessageId ? boundaryMessageId : null,
129
142
  createdAt: Date.now(),
130
143
  gitRef: null,
131
144
  }
@@ -135,12 +148,39 @@ export class CheckpointManager extends EventEmitter {
135
148
  if (isGit) {
136
149
  const release = await acquireCwdLock(cwd)
137
150
  try {
151
+ assertAuthorized(isAuthorized)
138
152
  checkpoint.gitRef = await this._createGitSnapshot(cwd, checkpoint.id)
139
153
  } finally {
140
154
  release()
141
155
  }
142
156
  }
143
157
 
158
+ // Last chance to refuse before anything is evicted or persisted. A refusal here
159
+ // must not leave the snapshot ref it just created behind.
160
+ try {
161
+ assertAuthorized(isAuthorized)
162
+ } catch (err) {
163
+ // Awaited, so the ref is gone when the refusal reaches the caller (a
164
+ // fire-and-forget delete races the caller's next read, and loses on slow spawns).
165
+ if (checkpoint.gitRef && !(await this._deleteGitRef(cwd, checkpoint.gitRef))) {
166
+ this._recordFailedRefDelete(cwd, checkpoint.gitRef)
167
+ log.warn(`Failed to delete git ref ${checkpoint.gitRef} (recorded for retry)`)
168
+ }
169
+ throw err
170
+ }
171
+
172
+ // Enforce max checkpoints — remove oldest if at limit. Only now, with the new
173
+ // snapshot in hand: evicting first would lose a rewind point when the creation
174
+ // is refused or fails partway.
175
+ let evictedCwd = null
176
+ if (checkpoints.length >= MAX_CHECKPOINTS_PER_SESSION) {
177
+ const evicted = checkpoints.shift()
178
+ if (evicted?.gitRef) {
179
+ evictedCwd = evicted.cwd
180
+ this._deleteGitRefTracked(evicted.cwd, evicted.gitRef)
181
+ }
182
+ }
183
+
144
184
  checkpoints.push(checkpoint)
145
185
  this._counters.set(sessionId, (this._counters.get(sessionId) || 0) + 1)
146
186
  this._checkpoints.set(sessionId, checkpoints)
@@ -193,13 +233,19 @@ export class CheckpointManager extends EventEmitter {
193
233
 
194
234
  /**
195
235
  * Restore file state from a checkpoint's git snapshot.
196
- * Does NOT restore conversation state — that requires creating a new session
197
- * with the checkpoint's resumeSessionId (handled by session-manager).
236
+ *
237
+ * This restores the working tree only. The conversation side of a rewind is
238
+ * the WS restore handler's responsibility (#6766): it reads the returned
239
+ * `resumeSessionId` + `boundaryMessageId` and, for a fork-capable provider,
240
+ * forks the conversation truncated to the boundary; otherwise it resumes
241
+ * files-only. Kept here so the git snapshot and the conversation decision stay
242
+ * decoupled across providers.
198
243
  * @param {string} sessionId
199
244
  * @param {string} checkpointId
200
- * @returns {Promise<object>} The checkpoint data (including resumeSessionId)
245
+ * @returns {Promise<object>} The checkpoint data (including resumeSessionId
246
+ * and boundaryMessageId)
201
247
  */
202
- async restoreCheckpoint(sessionId, checkpointId) {
248
+ async restoreCheckpoint(sessionId, checkpointId, { isAuthorized } = {}) {
203
249
  const checkpoint = this.getCheckpoint(sessionId, checkpointId)
204
250
  if (!checkpoint) {
205
251
  throw new Error(`Checkpoint not found: ${checkpointId}`)
@@ -209,6 +255,7 @@ export class CheckpointManager extends EventEmitter {
209
255
  if (checkpoint.gitRef) {
210
256
  const release = await acquireCwdLock(checkpoint.cwd)
211
257
  try {
258
+ assertAuthorized(isAuthorized)
212
259
  await this._restoreGitSnapshot(checkpoint.cwd, checkpoint.gitRef)
213
260
  } finally {
214
261
  release()
@@ -276,52 +323,53 @@ export class CheckpointManager extends EventEmitter {
276
323
  }
277
324
 
278
325
  /**
279
- * Create a snapshot of the current working tree state using a plain commit
280
- * object, without touching the shared git stash stack.
326
+ * Create a snapshot of the working tree under `cwd` as a plain commit object,
327
+ * without touching the shared git stash stack or the repository's index.
281
328
  *
282
329
  * Strategy:
283
- * 1. If the working tree is clean, tag HEAD directly.
284
- * 2. Otherwise:
285
- * a. Capture the current index state via `git write-tree`.
286
- * b. Stage everything (tracked + untracked) with `git add -A`.
287
- * c. Create a snapshot commit object via `git commit-tree` (no branch
288
- * or ref is updated — the commit is dangling until we tag it).
289
- * d. Tag the snapshot commit SHA.
290
- * e. Restore the pre-snapshot index with `git read-tree` so the
291
- * working tree is left exactly as it was.
330
+ * 1. If nothing under `cwd` has changed, tag HEAD directly.
331
+ * 2. Otherwise build the snapshot in a PRIVATE, temporary index
332
+ * (GIT_INDEX_FILE): start from HEAD's tree, stage everything under `cwd`
333
+ * (tracked + untracked, `add -A -- .`), write that tree, create a
334
+ * dangling commit on HEAD with `git commit-tree`, and tag it.
292
335
  *
293
- * This never modifies refs/stash, so concurrent sessions operating on the
294
- * same repository cannot corrupt each other. The per-cwd mutex in the
295
- * caller serialises the git index operations within this process.
336
+ * The repository's own index is never read or rewritten, so staging that
337
+ * happens concurrently is not clobbered, and only paths at or beneath `cwd`
338
+ * can differ from HEAD in the snapshot: a sibling directory's uncommitted
339
+ * content is not captured. It never modifies refs/stash. The per-cwd mutex in
340
+ * the caller serialises snapshots of one directory.
296
341
  */
297
342
  async _createGitSnapshot(cwd, checkpointId) {
298
343
  const tagName = `chroxy-checkpoint/${checkpointId}`
344
+ // A private directory (mode 0700) holds the temporary index, so no other user
345
+ // can read the staged content or swap the file.
346
+ const indexDir = mkdtempSync(join(tmpdir(), 'ckpt-snapshot-'))
347
+ const indexFile = join(indexDir, 'index')
299
348
 
300
349
  try {
301
350
  const { stdout: status } = await execFileAsync(
302
- GIT, ['status', '--porcelain'],
351
+ GIT, ['status', '--porcelain', '--', '.'],
303
352
  { cwd }
304
353
  )
305
354
 
306
355
  if (!status.trim()) {
307
- // Working tree is clean — tag HEAD directly
356
+ // Nothing under cwd has changed — tag HEAD directly
308
357
  await execFileAsync(GIT, ['tag', tagName, 'HEAD'], { cwd })
309
358
  return tagName
310
359
  }
311
360
 
312
- // Capture the current index so we can restore it afterwards
313
- const { stdout: savedIndexTree } = await execFileAsync(
314
- GIT, ['write-tree'],
315
- { cwd }
316
- )
361
+ // git-only child: the daemon's inherited secrets are stripped anyway.
362
+ const env = stripInheritedChroxySecrets({ ...process.env })
363
+ env.GIT_INDEX_FILE = indexFile
317
364
 
318
- // Stage everything including untracked files
319
- await execFileAsync(GIT, ['add', '-A'], { cwd })
365
+ // Seed the private index from HEAD, then stage everything under cwd.
366
+ await execFileAsync(GIT, ['read-tree', 'HEAD'], { cwd, env })
367
+ await execFileAsync(GIT, ['add', '-A', '--', '.'], { cwd, env })
320
368
 
321
- // Write the full working tree as a tree object
369
+ // Write the resulting tree as an object
322
370
  const { stdout: snapshotTree } = await execFileAsync(
323
371
  GIT, ['write-tree'],
324
- { cwd }
372
+ { cwd, env }
325
373
  )
326
374
 
327
375
  // Create a dangling commit from the snapshot tree
@@ -333,15 +381,12 @@ export class CheckpointManager extends EventEmitter {
333
381
  // Tag the snapshot commit for stable retrieval
334
382
  await execFileAsync(GIT, ['tag', tagName, snapshotSha.trim()], { cwd })
335
383
 
336
- // Restore the pre-snapshot index (leaves working tree untouched)
337
- await execFileAsync(GIT, ['read-tree', savedIndexTree.trim()], { cwd })
338
-
339
384
  return tagName
340
385
  } catch (err) {
341
- // Best-effort: restore the index if something went wrong mid-way
342
- try { await execFileAsync(GIT, ['reset', 'HEAD'], { cwd }) } catch { /* ignore */ }
343
386
  log.warn(`Failed to create git snapshot: ${err.message}`)
344
387
  return null
388
+ } finally {
389
+ try { rmSync(indexDir, { recursive: true, force: true }) } catch { /* already gone */ }
345
390
  }
346
391
  }
347
392
 
@@ -0,0 +1,122 @@
1
+ /**
2
+ * chroxy-host-metadata — the identity of the Chroxy host that launched an agent
3
+ * session (#6633).
4
+ *
5
+ * Agents (Claude, Codex, Gemini, …) previously could not answer "what Chroxy
6
+ * build am I running in?" without guessing from screenshots or the checked-out
7
+ * repo. This module computes a small, non-sensitive identity block and exposes
8
+ * it as `CHROXY_HOST_*` environment variables, which are injected into every
9
+ * agent's process environment (see `buildSpawnEnv` for subprocess providers and
10
+ * the server startup `Object.assign(process.env, …)` for the in-process SDK). A
11
+ * session can then read e.g. `$CHROXY_HOST_VERSION` from a Bash tool call.
12
+ *
13
+ * The values are COMPUTED here (version from this package's package.json, git
14
+ * identity via `git`), never passed through from the operator's shell — so they
15
+ * are authoritative and can't be spoofed by a stray `CHROXY_HOST_*` export.
16
+ */
17
+ import { execFileSync } from 'node:child_process'
18
+ import { readFileSync } from 'node:fs'
19
+ import { dirname, join } from 'node:path'
20
+ import { fileURLToPath } from 'node:url'
21
+
22
+ // A synchronous read is fine: the file is tiny and never changes mid-process,
23
+ // and getChroxyHostEnv memoizes the result so this runs at most once on demand
24
+ // (mirrors byok-mcp-client's readPackageVersion). Never block on a
25
+ // missing/unreadable package.json — fall back to a sentinel.
26
+ function readPackageVersion() {
27
+ try {
28
+ const here = dirname(fileURLToPath(import.meta.url))
29
+ const raw = readFileSync(join(here, '..', 'package.json'), 'utf8')
30
+ const parsed = JSON.parse(raw)
31
+ if (typeof parsed?.version === 'string' && parsed.version.length > 0) {
32
+ return parsed.version
33
+ }
34
+ } catch {
35
+ // Fall through — identity should degrade gracefully, never crash a spawn.
36
+ }
37
+ return '0.0.0'
38
+ }
39
+
40
+ /**
41
+ * Best-effort git identity for dev builds. A released npm/tarball install has no
42
+ * `.git`, so this returns `{}` there. Guarded and time-boxed — computing host
43
+ * identity must never block or fail a session spawn.
44
+ *
45
+ * Only a chroxy SOURCE checkout reports git identity. When chroxy is installed as
46
+ * a dependency (`…/node_modules/chroxy/…`), `git rev-parse` would otherwise walk
47
+ * up to the USER's project `.git` and mislabel the build `dev` while leaking the
48
+ * user's branch/SHA into third-party (codex/gemini) subprocesses. The
49
+ * node_modules guard makes that impossible — an installed chroxy is `release`.
50
+ *
51
+ * @param {typeof execFileSync} [exec] - injectable for tests
52
+ * @param {string} [moduleDir] - injectable module directory (for tests)
53
+ * @returns {{ sha?: string, branch?: string }}
54
+ */
55
+ export function readGitIdentity(exec = execFileSync, moduleDir = dirname(fileURLToPath(import.meta.url))) {
56
+ // Installed-as-a-dependency → never inspect the surrounding repo's git.
57
+ if (moduleDir.split(/[/\\]/).includes('node_modules')) return {}
58
+ const cwd = moduleDir
59
+ const run = (args) => String(exec('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 2000 })).trim()
60
+ try {
61
+ const sha = run(['rev-parse', '--short', 'HEAD'])
62
+ if (!sha) return {}
63
+ const out = { sha }
64
+ try {
65
+ const branch = run(['rev-parse', '--abbrev-ref', 'HEAD'])
66
+ // 'HEAD' means detached — no meaningful branch name to report.
67
+ if (branch && branch !== 'HEAD') out.branch = branch
68
+ } catch {
69
+ // No branch is fine; the SHA alone still identifies the build.
70
+ }
71
+ return out
72
+ } catch {
73
+ return {}
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Build the `CHROXY_HOST_*` identity map. Pure — every source is either read
79
+ * fresh or injected, so tests can pin each field without mocking modules.
80
+ *
81
+ * @param {object} [opts]
82
+ * @param {string} [opts.version] - override the package version
83
+ * @param {{ sha?: string, branch?: string }} [opts.git] - override git identity
84
+ * @param {string} [opts.platform] - override process.platform
85
+ * @param {string} [opts.node] - override the node version
86
+ * @param {number|string} [opts.pid] - override the process id
87
+ * @returns {Record<string, string>} string-valued env map (git keys omitted when absent)
88
+ */
89
+ export function buildChroxyHostEnv({ version, git, platform, node, pid } = {}) {
90
+ const g = git ?? readGitIdentity()
91
+ const env = {
92
+ CHROXY_HOST_APP: 'Chroxy',
93
+ CHROXY_HOST_VERSION: version ?? readPackageVersion(),
94
+ // A git SHA means we're running from a working tree → a dev/local build;
95
+ // its absence means a packaged release.
96
+ CHROXY_HOST_CHANNEL: g.sha ? 'dev' : 'release',
97
+ CHROXY_HOST_PLATFORM: platform ?? process.platform,
98
+ CHROXY_HOST_NODE: node ?? process.versions.node,
99
+ CHROXY_HOST_PID: String(pid ?? process.pid),
100
+ }
101
+ if (g.sha) env.CHROXY_HOST_GIT_SHA = g.sha
102
+ if (g.branch) env.CHROXY_HOST_GIT_BRANCH = g.branch
103
+ return env
104
+ }
105
+
106
+ // Memoized per-process view. Git/version don't change mid-run, so compute once
107
+ // and reuse across every spawn.
108
+ let _cache = null
109
+
110
+ /**
111
+ * The memoized `CHROXY_HOST_*` map for this process.
112
+ * @returns {Record<string, string>}
113
+ */
114
+ export function getChroxyHostEnv() {
115
+ if (!_cache) _cache = buildChroxyHostEnv()
116
+ return _cache
117
+ }
118
+
119
+ /** Test seam: drop the memoized value so a test can re-derive it. */
120
+ export function _resetChroxyHostEnvCacheForTest() {
121
+ _cache = null
122
+ }
@@ -1,9 +1,10 @@
1
- import { homedir } from 'os'
2
- import { join } from 'path'
1
+ import { claudeConfigDir } from './utils/claude-config-dir.js'
3
2
  import { BaseSession, buildBaseSessionOpts } from './base-session.js'
3
+ import { CLAUDE_CHANNEL_CUSTOMIZATION } from './provider-customization.js'
4
4
  import { ALLOWED_MODEL_IDS } from './models.js'
5
5
  import { CLAUDE_FALLBACK_MODELS, claudeModelMetadata } from './claude-model-catalog.js'
6
6
  import { BILLING_CLASSES } from './billing-class.js'
7
+ import { CLAUDE_BINARY_CANDIDATES } from './utils/claude-binary.js'
7
8
 
8
9
  // Minimum `claude` CLI version that ships the `--channels` MCP transport.
9
10
  // Verified present in v2.1.163 (the locally-installed CLI) and documented
@@ -35,6 +36,10 @@ export const CLAUDE_CHANNEL_MIN_VERSION = '2.1.80'
35
36
  * permission-mode switch — those stay `false`, same gap `claude-tui` has.
36
37
  */
37
38
  export class ClaudeChannelSession extends BaseSession {
39
+ static get customizationDescriptor() {
40
+ return CLAUDE_CHANNEL_CUSTOMIZATION
41
+ }
42
+
38
43
  // #5858: Claude-family flag — single source of truth for isClaudeProvider().
39
44
  static claudeFamily = true
40
45
 
@@ -50,7 +55,7 @@ export class ClaudeChannelSession extends BaseSession {
50
55
  }
51
56
 
52
57
  static get dataDir() {
53
- return join(homedir(), '.claude')
58
+ return claudeConfigDir()
54
59
  }
55
60
 
56
61
  static get capabilities() {
@@ -70,6 +75,10 @@ export class ClaudeChannelSession extends BaseSession {
70
75
  resume: false,
71
76
  terminal: false,
72
77
  thinkingLevel: false,
78
+ // #7725: the channel transport hands the prompt straight to the upstream
79
+ // `claude` process; the daemon runs no keyword scan on this path.
80
+ thinkingKeywords: false,
81
+ thinkingLevelEffective: false, // #8700: no report of the applied level
73
82
  // Channel notifications stream as they arrive — the headline win
74
83
  // over claude-tui's deliver-on-complete model.
75
84
  streaming: true,
@@ -87,14 +96,11 @@ export class ClaudeChannelSession extends BaseSession {
87
96
  // comparator parses the leading semver out of `claude --version`
88
97
  // (e.g. "2.1.163 (Claude Code)") and fails below this.
89
98
  minVersion: CLAUDE_CHANNEL_MIN_VERSION,
90
- candidates: [
91
- join(homedir(), '.local/bin/claude'),
92
- '/opt/homebrew/bin/claude',
93
- '/usr/local/bin/claude',
94
- join(homedir(), '.claude/local/node_modules/.bin/claude'),
95
- join(homedir(), '.npm-global/bin/claude'),
96
- ],
99
+ candidates: CLAUDE_BINARY_CANDIDATES,
97
100
  installHint: `install Claude Code CLI ≥ ${CLAUDE_CHANNEL_MIN_VERSION} (research preview — channels)`,
101
+ // #7986 review S2: an old/unreadable claude on this floor is a
102
+ // version-skew problem, not a fresh install — `claude update` fixes it.
103
+ updateHint: 'run `claude update`',
98
104
  },
99
105
  credentials: {
100
106
  envVars: [],