@chroxy/server 0.10.0

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 (275) hide show
  1. package/CONFIG.md +695 -0
  2. package/README.md +105 -0
  3. package/hooks/permission-hook.sh +285 -0
  4. package/package.json +69 -0
  5. package/scripts/fix-node-pty-helper.js +44 -0
  6. package/sidecar/Dockerfile +40 -0
  7. package/sidecar/PROTOCOL.md +691 -0
  8. package/sidecar/agent.js +1290 -0
  9. package/sidecar/package-lock.json +43 -0
  10. package/sidecar/package.json +17 -0
  11. package/src/activity-registry.js +491 -0
  12. package/src/anthropic-compatible-config.js +534 -0
  13. package/src/anthropic-compatible-session.js +579 -0
  14. package/src/anthropic-openai-shim.js +109 -0
  15. package/src/anthropic-openai-translate.js +377 -0
  16. package/src/auth-probes.js +296 -0
  17. package/src/background-shell-tracker.js +320 -0
  18. package/src/background-shells.js +125 -0
  19. package/src/base-session.js +1518 -0
  20. package/src/billing-budget.js +191 -0
  21. package/src/billing-canary-monitor.js +203 -0
  22. package/src/billing-class.js +149 -0
  23. package/src/bind-host.js +82 -0
  24. package/src/built-in-tools/bash-exec.js +167 -0
  25. package/src/built-in-tools/file-ops.js +198 -0
  26. package/src/built-in-tools/tool-transforms.js +179 -0
  27. package/src/builtin-commands.js +107 -0
  28. package/src/byok-compose-state-shared.js +31 -0
  29. package/src/byok-compose-state.js +234 -0
  30. package/src/byok-credentials.js +127 -0
  31. package/src/byok-event-translator.js +136 -0
  32. package/src/byok-mcp-client.js +404 -0
  33. package/src/byok-mcp-config.js +159 -0
  34. package/src/byok-mcp-fleet.js +214 -0
  35. package/src/byok-mcp-trust.js +175 -0
  36. package/src/byok-session.js +2019 -0
  37. package/src/byok-subagent-profiles.js +101 -0
  38. package/src/byok-tool-executor.js +813 -0
  39. package/src/byok-tools.js +271 -0
  40. package/src/channels/PACKAGING.md +181 -0
  41. package/src/channels/README.md +99 -0
  42. package/src/channels/chroxy-channel-server.js +248 -0
  43. package/src/checkpoint-manager.js +515 -0
  44. package/src/child-stream-guard.js +38 -0
  45. package/src/claude-channel-session.js +185 -0
  46. package/src/claude-model-catalog.js +266 -0
  47. package/src/claude-stream-parser.js +106 -0
  48. package/src/claude-tui/form-driver.js +874 -0
  49. package/src/claude-tui/pty-driver.js +520 -0
  50. package/src/claude-tui/tested-cli-version.js +22 -0
  51. package/src/claude-tui-attachments.js +342 -0
  52. package/src/claude-tui-session.js +4029 -0
  53. package/src/cli/config-cmd.js +34 -0
  54. package/src/cli/credentials-cmd.js +59 -0
  55. package/src/cli/deploy-cmd.js +167 -0
  56. package/src/cli/doctor-cmd.js +52 -0
  57. package/src/cli/identity-cmd.js +82 -0
  58. package/src/cli/init-cmd.js +209 -0
  59. package/src/cli/pages-cmd.js +167 -0
  60. package/src/cli/pair-code-cmd.js +108 -0
  61. package/src/cli/pair-discord-cmd.js +100 -0
  62. package/src/cli/providers-cmd.js +168 -0
  63. package/src/cli/server-cmd.js +94 -0
  64. package/src/cli/service-cmd.js +237 -0
  65. package/src/cli/session-cmd.js +143 -0
  66. package/src/cli/shared.js +194 -0
  67. package/src/cli/shell-cmd.js +130 -0
  68. package/src/cli/status-cmd.js +204 -0
  69. package/src/cli/tunnel-cmd.js +101 -0
  70. package/src/cli/update-cmd.js +45 -0
  71. package/src/cli/worktree-gc-cmd.js +195 -0
  72. package/src/cli-session.js +1820 -0
  73. package/src/cli.js +60 -0
  74. package/src/codex-app-server-client.js +156 -0
  75. package/src/codex-app-server-session.js +572 -0
  76. package/src/codex-session.js +604 -0
  77. package/src/config.js +1757 -0
  78. package/src/connection-info.js +42 -0
  79. package/src/connection-locality.js +55 -0
  80. package/src/content-blocks.js +42 -0
  81. package/src/control-room/byok-pool.js +130 -0
  82. package/src/control-room/constants.js +26 -0
  83. package/src/control-room/containers.js +258 -0
  84. package/src/control-room/emulators.js +279 -0
  85. package/src/control-room/handler-factory.js +142 -0
  86. package/src/control-room/host-prune.js +387 -0
  87. package/src/control-room/integrations.js +929 -0
  88. package/src/control-room/repo-runtime-config.js +239 -0
  89. package/src/control-room/repo-set.js +162 -0
  90. package/src/control-room/runners.js +479 -0
  91. package/src/control-room/simulators.js +223 -0
  92. package/src/control-room/skills-inventory.js +303 -0
  93. package/src/control-room/survey.js +685 -0
  94. package/src/control-room/wsl.js +182 -0
  95. package/src/conversation-scanner.js +270 -0
  96. package/src/conversation-scope.js +52 -0
  97. package/src/conversation-search.js +216 -0
  98. package/src/cost-budget-manager.js +190 -0
  99. package/src/credential-cipher.js +179 -0
  100. package/src/credential-store.js +786 -0
  101. package/src/credential-test.js +145 -0
  102. package/src/credentials-file.js +58 -0
  103. package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +111 -0
  104. package/src/dashboard-next/dist/assets/index-DM-_dISG.css +1 -0
  105. package/src/dashboard-next/dist/index.html +13 -0
  106. package/src/deepseek-credentials.js +58 -0
  107. package/src/deepseek-session.js +192 -0
  108. package/src/detect-thinking-keyword.js +67 -0
  109. package/src/dev-preview.js +227 -0
  110. package/src/devcontainer-config.js +269 -0
  111. package/src/device-preferences.js +267 -0
  112. package/src/diagnostics.js +187 -0
  113. package/src/diff-parser.js +157 -0
  114. package/src/discord-credentials.js +188 -0
  115. package/src/discord-pair-delivery.js +113 -0
  116. package/src/docker-byok-pool-stats.js +221 -0
  117. package/src/docker-byok-pool.js +841 -0
  118. package/src/docker-byok-session.js +2172 -0
  119. package/src/docker-image-allowlist.js +99 -0
  120. package/src/docker-sdk-session.js +396 -0
  121. package/src/docker-session.js +382 -0
  122. package/src/doctor-billing.js +179 -0
  123. package/src/doctor.js +667 -0
  124. package/src/duration.js +77 -0
  125. package/src/environment-manager.js +753 -0
  126. package/src/environment-statuses.js +20 -0
  127. package/src/environments/backends/docker.js +931 -0
  128. package/src/environments/backends/k8s.js +3030 -0
  129. package/src/environments/backends/rancher.js +326 -0
  130. package/src/environments/backends/types.js +332 -0
  131. package/src/event-ingest.js +546 -0
  132. package/src/event-normalizer.js +1083 -0
  133. package/src/external-session-registry.js +0 -0
  134. package/src/file-store.js +52 -0
  135. package/src/gemini-session.js +498 -0
  136. package/src/get-public-ip.js +52 -0
  137. package/src/git.js +15 -0
  138. package/src/github-webhook.js +256 -0
  139. package/src/handler-utils.js +663 -0
  140. package/src/handlers/checkpoint-handlers.js +202 -0
  141. package/src/handlers/control-room-handlers.js +1945 -0
  142. package/src/handlers/conversation-handlers.js +201 -0
  143. package/src/handlers/credential-handlers.js +247 -0
  144. package/src/handlers/evaluator-handlers.js +94 -0
  145. package/src/handlers/feature-handlers.js +332 -0
  146. package/src/handlers/file-handlers.js +142 -0
  147. package/src/handlers/ide-handlers.js +238 -0
  148. package/src/handlers/input-handlers.js +1048 -0
  149. package/src/handlers/pairing-handlers.js +94 -0
  150. package/src/handlers/repo-handlers.js +295 -0
  151. package/src/handlers/session-handlers.js +660 -0
  152. package/src/handlers/settings-handlers.js +818 -0
  153. package/src/handlers/skills-handlers.js +682 -0
  154. package/src/handlers/summarize-handlers.js +172 -0
  155. package/src/handlers/token-handlers.js +57 -0
  156. package/src/http-oversize.js +51 -0
  157. package/src/http-routes.js +1158 -0
  158. package/src/ide/search.js +268 -0
  159. package/src/ide/symbols.js +423 -0
  160. package/src/ip-utils.js +85 -0
  161. package/src/json-state-file.js +169 -0
  162. package/src/jsonl-reader.js +187 -0
  163. package/src/jsonl-subprocess-session.js +441 -0
  164. package/src/keychain.js +458 -0
  165. package/src/lan-ip.js +38 -0
  166. package/src/logger.js +388 -0
  167. package/src/mailbox-route.js +252 -0
  168. package/src/mcp-tools.js +46 -0
  169. package/src/message-transform.js +102 -0
  170. package/src/metrics.js +67 -0
  171. package/src/model-discovery.js +288 -0
  172. package/src/models.js +1426 -0
  173. package/src/notification-prefs.js +544 -0
  174. package/src/notifications/discord-billing-sink.js +323 -0
  175. package/src/notifications/discord-webhook-client.js +187 -0
  176. package/src/notifications/discord-webhook-sink.js +768 -0
  177. package/src/notifications/expo-push-sink.js +414 -0
  178. package/src/notifications/ready-body.js +177 -0
  179. package/src/notifications/sink-registry.js +98 -0
  180. package/src/notifications/sink.js +82 -0
  181. package/src/ollama-session.js +221 -0
  182. package/src/ollama-tags.js +238 -0
  183. package/src/openai-compatible-session.js +118 -0
  184. package/src/pages-store.js +255 -0
  185. package/src/pairing.js +836 -0
  186. package/src/path-hash-trust-ledger.js +311 -0
  187. package/src/per-session-settings.js +366 -0
  188. package/src/permission-audit.js +120 -0
  189. package/src/permission-hook.js +257 -0
  190. package/src/permission-manager.js +829 -0
  191. package/src/permission-resolver.js +144 -0
  192. package/src/platform.js +139 -0
  193. package/src/prompt-evaluator.js +386 -0
  194. package/src/providers.js +436 -0
  195. package/src/push.js +565 -0
  196. package/src/rate-limiter.js +433 -0
  197. package/src/redaction.js +206 -0
  198. package/src/sdk-session.js +1773 -0
  199. package/src/semver.js +92 -0
  200. package/src/server-cli/push-notification-handler.js +240 -0
  201. package/src/server-cli/server-orchestrator.js +168 -0
  202. package/src/server-cli/startup-display.js +146 -0
  203. package/src/server-cli/tunnel-lifecycle-handler.js +219 -0
  204. package/src/server-cli-child.js +207 -0
  205. package/src/server-cli.js +1223 -0
  206. package/src/server-identity.js +383 -0
  207. package/src/service.js +835 -0
  208. package/src/session-context.js +49 -0
  209. package/src/session-lock.js +60 -0
  210. package/src/session-manager.js +3257 -0
  211. package/src/session-message-history.js +511 -0
  212. package/src/session-preset-trust.js +78 -0
  213. package/src/session-preset.js +458 -0
  214. package/src/session-state-persistence.js +307 -0
  215. package/src/session-timeout-manager.js +166 -0
  216. package/src/session-token-store.js +83 -0
  217. package/src/shell-approval-info.js +45 -0
  218. package/src/shell-approval-store.js +163 -0
  219. package/src/shell-audit.js +63 -0
  220. package/src/skills-budget.js +181 -0
  221. package/src/skills-content-validator.js +106 -0
  222. package/src/skills-frontmatter.js +422 -0
  223. package/src/skills-loader.js +1893 -0
  224. package/src/skills-manager.js +256 -0
  225. package/src/skills-trust.js +532 -0
  226. package/src/skills-usage.js +335 -0
  227. package/src/snapshots-store.js +345 -0
  228. package/src/ssrf-guard.js +130 -0
  229. package/src/subagent-counter.js +149 -0
  230. package/src/summarize-session.js +268 -0
  231. package/src/supervisor.js +929 -0
  232. package/src/test-client.js +131 -0
  233. package/src/token-compare.js +28 -0
  234. package/src/token-manager.js +220 -0
  235. package/src/tool-result.js +87 -0
  236. package/src/transcript-tasks.js +334 -0
  237. package/src/tunnel/base.js +294 -0
  238. package/src/tunnel/cloudflare.js +281 -0
  239. package/src/tunnel/index.js +54 -0
  240. package/src/tunnel-check.js +84 -0
  241. package/src/turn-tracker.js +0 -0
  242. package/src/user-shell-registry.js +218 -0
  243. package/src/user-shell-session.js +411 -0
  244. package/src/utils/check-dependencies.js +70 -0
  245. package/src/utils/concurrency.js +24 -0
  246. package/src/utils/context-window-learn.js +148 -0
  247. package/src/utils/error-message.js +25 -0
  248. package/src/utils/format-bytes.js +35 -0
  249. package/src/utils/preflight.js +143 -0
  250. package/src/utils/resolve-binary.js +91 -0
  251. package/src/utils/respawn-rate-limiter.js +59 -0
  252. package/src/utils/sleep.js +58 -0
  253. package/src/utils/spawn-env.js +193 -0
  254. package/src/utils/validation-patterns.js +23 -0
  255. package/src/utils/win-spawn.js +98 -0
  256. package/src/version-check.js +16 -0
  257. package/src/web-task-manager.js +383 -0
  258. package/src/worktree-gc.js +418 -0
  259. package/src/worktree-reaper.js +168 -0
  260. package/src/ws-auth.js +645 -0
  261. package/src/ws-broadcaster.js +385 -0
  262. package/src/ws-client-manager.js +476 -0
  263. package/src/ws-client-sender.js +115 -0
  264. package/src/ws-file-ops/browser.js +594 -0
  265. package/src/ws-file-ops/common.js +163 -0
  266. package/src/ws-file-ops/git.js +298 -0
  267. package/src/ws-file-ops/index.js +52 -0
  268. package/src/ws-file-ops/reader.js +595 -0
  269. package/src/ws-forwarding.js +543 -0
  270. package/src/ws-handler-context.js +196 -0
  271. package/src/ws-history.js +1251 -0
  272. package/src/ws-message-handlers.js +165 -0
  273. package/src/ws-permissions.js +676 -0
  274. package/src/ws-schemas.js +119 -0
  275. package/src/ws-server.js +2866 -0
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Tool definitions for the claude-byok provider.
3
+ *
4
+ * Schemas match Claude Code's documented input shapes so the model sees
5
+ * a consistent interface across providers — switching from claude-cli /
6
+ * claude-tui / claude-sdk to claude-byok shouldn't require the model to
7
+ * relearn tool calling.
8
+ *
9
+ * These are passed verbatim into `client.messages.stream({ tools })` —
10
+ * the SDK consumes them as Anthropic API tool definitions.
11
+ *
12
+ * Deferred to follow-up issues (see #4047 epic):
13
+ * - MCP — #4048
14
+ */
15
+
16
+ import { SUBAGENT_PROFILE_NAMES } from './byok-subagent-profiles.js'
17
+
18
+ /**
19
+ * Valid TodoWrite status values. Single source of truth — the JSON-schema
20
+ * enum below and the Set used for runtime validation both derive from
21
+ * `TODO_STATUS_LIST` so they can't drift apart.
22
+ */
23
+ export const TODO_STATUS_LIST = Object.freeze(['pending', 'in_progress', 'completed'])
24
+ export const TODO_STATUSES = new Set(TODO_STATUS_LIST)
25
+
26
+ /**
27
+ * Permissiveness ranking for the Task tool's per-launch `permission_mode`
28
+ * override (#5017). Lower number = more restrictive; higher = more permissive.
29
+ *
30
+ * plan (0) — system prompt asks the model to plan before acting;
31
+ * every tool call still gates on user approval through
32
+ * PermissionManager (the byok provider has
33
+ * `planMode: false` and PermissionManager does not
34
+ * special-case 'plan', so the gating is identical to
35
+ * 'approve' from the executor's point of view — the
36
+ * restrictiveness comes from the prompt + approval gate,
37
+ * not a server-side write-tool block).
38
+ * approve (1) — default; every tool call gates on user approval.
39
+ * acceptEdits (2) — Read/Write/Edit/NotebookEdit/Glob/Grep auto-approved.
40
+ * auto (3) — every tool call auto-approved (skip-permissions).
41
+ *
42
+ * The Task tool refuses to launch a subagent under a mode strictly more
43
+ * permissive than the parent's. Equal-or-stricter is allowed.
44
+ *
45
+ * Kept here (next to the schema enum) so the JSON-schema property, the
46
+ * runtime validator in byok-session, and the test matrix all read from
47
+ * one source of truth.
48
+ */
49
+ export const TASK_PERMISSION_MODE_LIST = Object.freeze(['plan', 'approve', 'acceptEdits', 'auto'])
50
+ export const TASK_PERMISSION_MODE_RANK = Object.freeze({
51
+ plan: 0,
52
+ approve: 1,
53
+ acceptEdits: 2,
54
+ auto: 3,
55
+ })
56
+
57
+ export const BUILTIN_TOOLS = [
58
+ {
59
+ name: 'Read',
60
+ description:
61
+ 'Read a text file from the workspace. Returns line-numbered content. ' +
62
+ 'Optionally read a slice via `offset` (1-indexed start line) and `limit` (max lines to return). ' +
63
+ 'Refuses binary files. Use the Glob tool to discover paths first if unsure.',
64
+ input_schema: {
65
+ type: 'object',
66
+ properties: {
67
+ file_path: { type: 'string', description: 'Absolute or workspace-relative path to read.' },
68
+ offset: { type: 'number', description: 'Optional 1-indexed start line.' },
69
+ limit: { type: 'number', description: 'Optional max number of lines to return (default 2000).' },
70
+ },
71
+ required: ['file_path'],
72
+ },
73
+ },
74
+ {
75
+ name: 'Write',
76
+ description:
77
+ 'Write a file, truncating any existing content. Creates the file and any missing parent ' +
78
+ 'directories. Returns the number of bytes written and whether the file is new.',
79
+ input_schema: {
80
+ type: 'object',
81
+ properties: {
82
+ file_path: { type: 'string', description: 'Absolute or workspace-relative path to write.' },
83
+ content: { type: 'string', description: 'New file content.' },
84
+ },
85
+ required: ['file_path', 'content'],
86
+ },
87
+ },
88
+ {
89
+ name: 'Edit',
90
+ description:
91
+ 'Replace `old_string` with `new_string` in a file. Refuses if `old_string` matches multiple ' +
92
+ 'sites (pass `replace_all: true` to override) or matches zero sites. Add surrounding context ' +
93
+ 'to `old_string` to disambiguate when needed.',
94
+ input_schema: {
95
+ type: 'object',
96
+ properties: {
97
+ file_path: { type: 'string', description: 'Absolute or workspace-relative path to edit.' },
98
+ old_string: { type: 'string', description: 'Exact substring to replace. Must be unique unless replace_all is true.' },
99
+ new_string: { type: 'string', description: 'Replacement substring.' },
100
+ replace_all: { type: 'boolean', description: 'Replace every occurrence instead of refusing on multi-match.' },
101
+ },
102
+ required: ['file_path', 'old_string', 'new_string'],
103
+ },
104
+ },
105
+ {
106
+ name: 'Bash',
107
+ description:
108
+ 'Run a shell command via `bash -c`. Returns stdout, stderr, exit code. Timeout default ' +
109
+ '30s (override via `timeout`, max 600s). Output capped at ~1MB total — exceeding the cap ' +
110
+ 'kills the process. Use for build/test/git operations and one-off shell pipelines.',
111
+ input_schema: {
112
+ type: 'object',
113
+ properties: {
114
+ command: { type: 'string', description: 'Full shell command to run via `bash -c`.' },
115
+ description: { type: 'string', description: 'Short human-readable summary of what the command does.' },
116
+ timeout: { type: 'number', description: 'Optional timeout in milliseconds. Max 600000 (10 min).' },
117
+ },
118
+ required: ['command'],
119
+ },
120
+ },
121
+ {
122
+ name: 'Glob',
123
+ description:
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.',
126
+ input_schema: {
127
+ type: 'object',
128
+ properties: {
129
+ pattern: { type: 'string', description: 'Glob pattern (supports ** for recursive match).' },
130
+ path: { type: 'string', description: 'Optional search root. Defaults to workspace cwd.' },
131
+ },
132
+ required: ['pattern'],
133
+ },
134
+ },
135
+ {
136
+ name: 'WebFetch',
137
+ description:
138
+ 'Fetch a public web URL and return readable text. HTML pages are stripped of <script>/<style> ' +
139
+ 'and tags, with entities decoded. JSON and plaintext are returned as-is. Binary content-types ' +
140
+ '(images, octet-stream, etc.) are refused. Response body is capped — overflow is marked ' +
141
+ '`[truncated …]` so the model knows it saw a slice. Only http(s) URLs are allowed; file://, ' +
142
+ 'ftp://, javascript: are refused. Outbound network call: by default the user must approve ' +
143
+ 'each call via a permission prompt. Exception: when the session is in `auto` permission mode ' +
144
+ 'the prompt is bypassed and the call runs immediately — auto mode is a system-wide opt-out ' +
145
+ 'of per-call approval.',
146
+ input_schema: {
147
+ type: 'object',
148
+ properties: {
149
+ url: { type: 'string', description: 'Absolute http(s) URL to fetch.' },
150
+ prompt: { type: 'string', description: 'What the model wants out of the page (passed back verbatim in the result header so the model retains intent).' },
151
+ timeout: { type: 'number', description: 'Optional fetch timeout in milliseconds. Max 120000 (2 min).' },
152
+ },
153
+ required: ['url', 'prompt'],
154
+ },
155
+ },
156
+ {
157
+ name: 'TodoWrite',
158
+ description:
159
+ 'Update the session-scoped todo list. Items are merged by `id` — a call that ' +
160
+ 'omits an item leaves that item unchanged (partial updates are supported). ' +
161
+ 'Each item: `{ id, content, status, activeForm? }`. Status must be one of ' +
162
+ '`pending`, `in_progress`, `completed`. Within a single call each `id` must ' +
163
+ 'be unique — duplicates are rejected as EINVAL so the model sees the mistake ' +
164
+ 'and can self-correct rather than have the last write silently win. ' +
165
+ 'The list is in-memory only — it resets when the session is destroyed. ' +
166
+ 'Returns a short summary of the current list.',
167
+ input_schema: {
168
+ type: 'object',
169
+ properties: {
170
+ todos: {
171
+ type: 'array',
172
+ description: 'Array of todo items to merge into the list (by id).',
173
+ items: {
174
+ type: 'object',
175
+ properties: {
176
+ id: { type: 'string', description: 'Stable identifier — used as the merge key.' },
177
+ content: { type: 'string', description: 'Short description of the task.' },
178
+ status: { type: 'string', enum: TODO_STATUS_LIST, description: 'Current state.' },
179
+ activeForm: { type: 'string', description: 'Optional present-continuous form (e.g. "Running tests") shown when in_progress.' },
180
+ },
181
+ required: ['id', 'content', 'status'],
182
+ },
183
+ },
184
+ },
185
+ required: ['todos'],
186
+ },
187
+ },
188
+ {
189
+ name: 'Task',
190
+ description:
191
+ 'Spawn a focused sub-agent (subagent) to handle a delegated piece of work. The ' +
192
+ 'sub-agent runs as a fresh ClaudeByokSession with its own isolated message history, ' +
193
+ 'inheriting this session\'s permission mode and cwd by default. Use it to: research a topic ' +
194
+ 'without polluting the parent context, run multi-step work in a focused scope, or delegate ' +
195
+ 'a task that needs its own tool budget. The sub-agent\'s final assistant text is returned ' +
196
+ 'as the tool_result — intermediate tool calls happen inside the child and are NOT ' +
197
+ 'surfaced to the parent (only `agent_spawned` / `agent_completed` events fire). ' +
198
+ 'Token cost is accumulated into the parent turn\'s `result.cost` so accounting stays ' +
199
+ 'attributed to the user-facing session. ' +
200
+ 'Cancellation: interrupting the parent cascades to the child via a shared AbortSignal. ' +
201
+ 'Optional `permission_mode` overrides the inherited mode for this single launch, but ' +
202
+ 'is constrained to be at-most-as-permissive as the parent (ranking: plan < approve < ' +
203
+ 'acceptEdits < auto). Requesting a stricter mode is allowed; requesting a more ' +
204
+ 'permissive mode is rejected with an is_error tool_result. ' +
205
+ 'MCP tools: by default the sub-agent inherits the parent\'s MCP fleet (same ' +
206
+ '`mcp__<server>__<tool>` set as this turn), at zero extra spawn cost. Pass ' +
207
+ '`inherit_mcp: false` to launch a sub-agent with built-in tools only (no MCP). ' +
208
+ 'Subagent profiles (#5018): pass `subagent_type` to bias the child toward a focused role. ' +
209
+ `Available profiles: ${SUBAGENT_PROFILE_NAMES.join(', ')}. Each profile carries a tailored ` +
210
+ 'system prompt and may restrict the child\'s tool set (e.g. code-reviewer is read-only). ' +
211
+ 'Unknown subagent_type values fall back to the v1 default (no profile applied) and emit ' +
212
+ 'a warn log on the server so the delegation stays forward-compatible.',
213
+ input_schema: {
214
+ type: 'object',
215
+ properties: {
216
+ description: {
217
+ type: 'string',
218
+ description: 'Short (3-5 word) description of the task. Surfaced as the sub-agent label in the UI.',
219
+ },
220
+ prompt: {
221
+ type: 'string',
222
+ description: 'Full task prompt sent to the sub-agent as its initial user message.',
223
+ },
224
+ subagent_type: {
225
+ type: 'string',
226
+ enum: [...SUBAGENT_PROFILE_NAMES],
227
+ description:
228
+ 'Optional subagent profile id. When set, the runner applies the profile\'s system prompt '
229
+ + `and tool-set restriction to the child. Available profiles: ${SUBAGENT_PROFILE_NAMES.join(', ')}. `
230
+ + 'Unknown values fall back to v1 default (no profile applied) with a server-side warn log.',
231
+ },
232
+ permission_mode: {
233
+ type: 'string',
234
+ enum: [...TASK_PERMISSION_MODE_LIST],
235
+ description: 'Optional per-launch permission mode for the subagent. Must be at-most-as-permissive as the parent (plan < approve < acceptEdits < auto). When omitted, the subagent inherits the parent\'s mode.',
236
+ },
237
+ inherit_mcp: {
238
+ type: 'boolean',
239
+ description: 'When true (the default), the sub-agent inherits the parent\'s MCP fleet so nested tool use can call the same mcp__<server>__<tool> tools the parent sees — at zero extra spawn cost. Pass false to run the sub-agent with built-in tools only (no MCP).',
240
+ },
241
+ },
242
+ required: ['description', 'prompt'],
243
+ },
244
+ },
245
+ {
246
+ name: 'Grep',
247
+ description:
248
+ 'Search file contents for a regex pattern using ripgrep when available. ' +
249
+ 'Returns matching lines with file path + line number. `path` narrows the scope. ' +
250
+ '`glob` further filters by filename pattern (e.g. `*.js`).',
251
+ input_schema: {
252
+ type: 'object',
253
+ properties: {
254
+ pattern: { type: 'string', description: 'Regex pattern (PCRE-style via ripgrep when available).' },
255
+ path: { type: 'string', description: 'Optional search root. Defaults to workspace cwd.' },
256
+ glob: { type: 'string', description: 'Optional filename glob to filter matched files.' },
257
+ '-i': { type: 'boolean', description: 'Case-insensitive match.' },
258
+ '-n': { type: 'boolean', description: 'Include line numbers (default true).' },
259
+ },
260
+ required: ['pattern'],
261
+ },
262
+ },
263
+ ]
264
+
265
+ /**
266
+ * The set of tool names this provider knows how to execute locally.
267
+ * Models that emit a tool_use for a name NOT in this set produce a
268
+ * tool_result with `is_error: true` and a clear message so the chain
269
+ * doesn't silently hang.
270
+ */
271
+ export const BUILTIN_TOOL_NAMES = new Set(BUILTIN_TOOLS.map((t) => t.name))
@@ -0,0 +1,181 @@
1
+ # `chroxy-channel` — plugin-packaging plan
2
+
3
+ > **Status: plan only.** Nothing here is published yet. This document scopes
4
+ > what shipping `chroxy-channel` as an Anthropic-marketplace **Claude plugin**
5
+ > would entail, so that users eventually no longer need
6
+ > `--dangerously-load-development-channels`. It is the packaging deliverable of
7
+ > [#3956](https://github.com/blamechris/chroxy/issues/3956) (parent
8
+ > [#3951](https://github.com/blamechris/chroxy/issues/3951)).
9
+
10
+ ## Why package at all?
11
+
12
+ During the research preview, a custom (non-allowlisted) channel can only be
13
+ loaded with `--dangerously-load-development-channels` — the flag bypasses
14
+ Anthropic's approved-channels allowlist. The spike
15
+ ([`docs/architecture/claude-channels-provider-spike.md`](../../../../docs/architecture/claude-channels-provider-spike.md))
16
+ verified, against the installed CLI, the allowlist gate string:
17
+
18
+ ```
19
+ … is not on the approved channels allowlist (use --dangerously-load-development-channels for local dev)
20
+ ```
21
+
22
+ and the matching warning:
23
+
24
+ ```
25
+ --dangerously-load-development-channels is for local channel development only.
26
+ Do not use this option to run channels you have downloaded off the internet.
27
+ ```
28
+
29
+ Asking chroxy users to pass a deliberately-alarming flag is the main ergonomics
30
+ liability of the channel provider (spike risk **R2**). Getting `chroxy-channel`
31
+ onto an approved marketplace removes that requirement: an approved plugin loads
32
+ via `/plugin install` + `plugin:<name>@<marketplace>` with no dev flag.
33
+
34
+ ## Claude-plugin package layout
35
+
36
+ A Claude plugin that provides a channel is a directory with a manifest plus the
37
+ channel server. Sketch (the exact `plugin.json` schema is defined by the Claude
38
+ plugin docs — verify against
39
+ [code.claude.com/docs/en/channels-reference#package-as-a-plugin](https://code.claude.com/docs/en/channels-reference#package-as-a-plugin)
40
+ before authoring, since the preview schema may change):
41
+
42
+ ```
43
+ chroxy-channel/
44
+ ├── plugin.json # plugin manifest: name, version, description,
45
+ │ # declared channel(s), entry command
46
+ ├── README.md # what it does, security note, support link
47
+ └── server/ # the stdio MCP channel server
48
+ └── chroxy-channel-server.js
49
+ ```
50
+
51
+ - **`plugin.json`** — declares the plugin `name` (`chroxy-channel`), `version`,
52
+ `description`, and the channel it provides (name + the `command`/`args` Claude
53
+ uses to spawn the stdio MCP server). The channel name in the manifest is what
54
+ users reference as `plugin:chroxy-channel@<marketplace>`.
55
+ - **Marketplace metadata** — a marketplace is itself a manifest (commonly a
56
+ `marketplace.json` / repo index) listing the plugins it offers, with the
57
+ fields Anthropic's marketplace format requires (display name, author,
58
+ homepage, source). chroxy's own marketplace would be a small repo that lists
59
+ exactly this one plugin; submitting to a shared marketplace means adding our
60
+ entry to theirs.
61
+ - **Channel server** — the in-tree
62
+ [`chroxy-channel-server.js`](./chroxy-channel-server.js) prototype is the
63
+ starting point. The packaged copy must be self-contained (its
64
+ `@modelcontextprotocol/sdk` dependency bundled or declared) so it runs when
65
+ Claude spawns it from the installed plugin directory rather than from the
66
+ chroxy checkout. This is the crux of the embedded-vs-separate-package open
67
+ question below.
68
+
69
+ > The fields above are described from the public reference, not yet exercised by
70
+ > a real submission — treat the exact manifest keys as **unverified** until we
71
+ > author a real `plugin.json` and a marketplace listing actually loads it.
72
+
73
+ ## Marketplace decision: chroxy's own vs `claude-plugins-official`
74
+
75
+ Two routes, each with trade-offs:
76
+
77
+ | | chroxy-owned marketplace | `claude-plugins-official` |
78
+ |---|---|---|
79
+ | Control | Full — we own the repo, version on our schedule | Anthropic-gated; PR + review to land changes |
80
+ | Trust signal | Users add a third-party marketplace | First-party, highest trust |
81
+ | Removes dev flag? | Yes, if the marketplace is allowlisted / the org allows it | Yes — approved, default-allowed on Console |
82
+ | Review burden | Self-managed; we are the reviewers | Anthropic security review (see below) |
83
+ | Discovery | Users must know to add it | Discoverable in the official catalog |
84
+
85
+ **Recommendation (plan):** pursue the **official** marketplace
86
+ ([`anthropics/claude-plugins-official`](https://github.com/anthropics/claude-plugins-official),
87
+ where the upstream Telegram/Discord/iMessage/fakechat channel plugins live) as
88
+ the end state — it is the only route that removes the dev flag for the broadest
89
+ set of users without each of them trusting a chroxy-owned marketplace, and it
90
+ default-allows on Console. Stand up a **chroxy-owned marketplace as an interim
91
+ step** if we want approved-plugin ergonomics before the official review clears,
92
+ accepting that users must add it explicitly. Defer the final call until the
93
+ channel protocol graduates out of preview (the contract may shift on the way to
94
+ GA, and resubmitting a moving target is wasted review cycles).
95
+
96
+ ## Anthropic security-review expectations
97
+
98
+ Anthropic reviews channel plugins before approving them for a marketplace
99
+ listing (a channel can inject into and reply on behalf of a live Claude
100
+ session, and can relay permission verdicts, so the bar is high). Anticipated
101
+ expectations to satisfy before submitting:
102
+
103
+ - **No arbitrary remote code / no network egress beyond what's documented.** The
104
+ channel server should not phone home or pull executable content off the
105
+ internet — exactly the threat the dev-flag warning calls out.
106
+ - **Permission-relay gating.** If the plugin declares
107
+ `claude/channel/permission`, it must gate who can submit verdicts — anyone who
108
+ can reply can approve tool use (spike R8). chroxy's bridge drives the socket
109
+ from a single trusted writer (`ClaudeChannelSession`); the packaged plugin
110
+ must preserve that property and not expose an open control surface.
111
+ - **Minimal, declared dependencies.** Bundle or pin `@modelcontextprotocol/sdk`
112
+ and avoid a long transitive tree that widens the review surface.
113
+ - **Clear provenance and support.** Author, source repo, and a security-contact
114
+ path in the manifest/README.
115
+ - **Reproducible behaviour.** The reviewer should be able to run the channel and
116
+ see it behave as documented.
117
+
118
+ > These are reasonable expectations inferred from the dev-flag warning and the
119
+ > permission-relay contract; the **exact** review checklist Anthropic applies is
120
+ > not published and is therefore **unverified**. Confirm the current process
121
+ > before submitting.
122
+
123
+ ## How approval removes `--dangerously-load-development-channels`
124
+
125
+ The dev flag exists solely to bypass the approved-channels allowlist during
126
+ local development. Once `chroxy-channel` is an approved plugin on a marketplace
127
+ the user (or their org) trusts:
128
+
129
+ ```bash
130
+ # One-time install of the approved plugin
131
+ /plugin install chroxy-channel@chroxy # or @claude-plugins-official
132
+
133
+ # chroxy then spawns claude with the plugin-tagged channel, no dev flag:
134
+ claude --channels plugin:chroxy-channel@chroxy
135
+ ```
136
+
137
+ `ClaudeChannelSession` would select the `plugin:<name>@<marketplace>` tag form
138
+ (allowlist-enforced) instead of the `server:<name>` +
139
+ `--dangerously-load-development-channels` form it must use during the preview.
140
+ Until then, the dev flag stays — documented in
141
+ [`CONFIG.md`](../../CONFIG.md#claude-channel-research-preview) and
142
+ [`docs/providers.md`](../../../../docs/providers.md#claude-channel-research-preview)
143
+ with a clear explanation of *why* it's needed and that it bypasses only the
144
+ allowlist, not org policy (`channelsEnabled`, `allowedChannelPlugins`).
145
+
146
+ ## Open question: separate npm package vs embedded in `@chroxy/server`
147
+
148
+ Today the channel server lives at
149
+ [`packages/server/src/channels/chroxy-channel-server.js`](./chroxy-channel-server.js),
150
+ inside `@chroxy/server`. For the packaged plugin, Claude spawns the server from
151
+ the **installed plugin directory**, not from the chroxy checkout — so the
152
+ packaged copy must stand alone.
153
+
154
+ - **Embedded in `@chroxy/server` (status quo + a copy step).** Keep the source
155
+ in-tree; the plugin build copies/bundles it into the plugin directory. Pro:
156
+ one source of truth, no version-skew between the bridge and the channel
157
+ server. Con: the plugin build must bundle `@modelcontextprotocol/sdk` and any
158
+ shared helpers, and we ship the same code twice (in the npm package and in the
159
+ plugin).
160
+ - **Separate npm package (e.g. `@chroxy/channel-server`).** Extract the channel
161
+ server into its own published package that both `@chroxy/server` and the
162
+ plugin depend on. Pro: a clean, independently-versioned artifact that the
163
+ plugin can `npm install`; clearer security-review surface (reviewers audit one
164
+ small package). Con: a new package to publish and version; the bridge and the
165
+ channel server can drift if not released together.
166
+
167
+ **Leaning (not decided):** keep it **embedded** until the bridge (#3954) and
168
+ permission relay (#3955) stabilise the channel server's surface, then extract to
169
+ a separate package **if and when** we actually submit to a marketplace — at that
170
+ point an independently-versioned, minimal-dependency artifact is the easier
171
+ thing to get through security review. Decide alongside the marketplace decision
172
+ above, after the protocol leaves preview.
173
+
174
+ ## References
175
+
176
+ - Spike (verified protocol + go/no-go): [`docs/architecture/claude-channels-provider-spike.md`](../../../../docs/architecture/claude-channels-provider-spike.md)
177
+ - Channel server prototype + run instructions: [`README.md`](./README.md)
178
+ - Channels — Package as a plugin: https://code.claude.com/docs/en/channels-reference#package-as-a-plugin
179
+ - Official channel plugins (Telegram/Discord/iMessage/fakechat): https://github.com/anthropics/claude-plugins-official/tree/main/external_plugins
180
+ - Provider scaffold: [`packages/server/src/claude-channel-session.js`](../claude-channel-session.js)
181
+ - User-facing docs: [`CONFIG.md`](../../CONFIG.md#claude-channel-research-preview), [`docs/providers.md`](../../../../docs/providers.md#claude-channel-research-preview)
@@ -0,0 +1,99 @@
1
+ # chroxy-channel — `claude --channels` MCP prototype
2
+
3
+ Standalone prototype that proves the `claude --channels` round-trip end-to-end
4
+ against a real `claude` binary. **No chroxy wiring** — this is intentionally not
5
+ registered in `providers.js`, `ws-server.js`, or any session class. It exists to
6
+ de-risk the channel protocol before the provider scaffold (#3953) and bridge
7
+ (#3954) are built on top of it.
8
+
9
+ See [`docs/architecture/claude-channels-provider-spike.md`](../../../../docs/architecture/claude-channels-provider-spike.md)
10
+ (the #3951 spike) for the verified protocol contract and the go/no-go rationale,
11
+ and [`PACKAGING.md`](./PACKAGING.md) for the plan to ship this as a
12
+ marketplace-approved Claude plugin (which removes the
13
+ `--dangerously-load-development-channels` requirement).
14
+
15
+ ## What it does
16
+
17
+ [`chroxy-channel-server.js`](./chroxy-channel-server.js) is a Node 22 stdio MCP
18
+ server that:
19
+
20
+ 1. Declares the `experimental: { 'claude/channel': {} }` capability — the
21
+ presence of this key is what registers Claude's channel notification listener.
22
+ 2. Declares `tools: {}` and registers a two-way `reply(chat_id, text)` tool whose
23
+ handler logs the reply to **stderr** (the prototype has nowhere else to send
24
+ it yet; the bridge in #3954 will route it back over IPC).
25
+ 3. Listens on a **localhost-only** HTTP port (default `8788`, override with
26
+ `CHROXY_CHANNEL_PORT`). Every `POST` body is forwarded into Claude as a
27
+ `notifications/claude/channel` event with an incrementing `meta.chat_id`.
28
+ 4. Sets `instructions` on the `Server` constructor explaining the `<channel>`
29
+ envelope and how to reply.
30
+ 5. Connects over `StdioServerTransport` — `claude` spawns it as a subprocess.
31
+
32
+ Permission relay (`claude/channel/permission`) is **out of scope** here (sub 4,
33
+ #3955) — the prototype declares only the inbound channel + reply-tool surface.
34
+
35
+ ## Run it manually
36
+
37
+ The server is spawned by `claude` over stdio, so running it directly just exits
38
+ (it has no stdio peer — that is expected).
39
+
40
+ ```bash
41
+ # Terminal 1 — register it in .mcp.json. The relative path below works when you
42
+ # launch claude from this repo's root; for a user-level ~/.claude.json, or to
43
+ # launch from any cwd, use the absolute path to the file instead.
44
+ cat > .mcp.json <<'EOF'
45
+ {
46
+ "mcpServers": {
47
+ "chroxy-channel": {
48
+ "command": "node",
49
+ "args": ["packages/server/src/channels/chroxy-channel-server.js"]
50
+ }
51
+ }
52
+ }
53
+ EOF
54
+
55
+ # Start an interactive claude session that loads the channel. The dev flag is
56
+ # required during the research preview because custom channels are not on the
57
+ # approved allowlist.
58
+ claude --dangerously-load-development-channels server:chroxy-channel
59
+
60
+ # Terminal 2 — push a message into the live session.
61
+ curl -X POST localhost:8788 -d "list the files in this directory"
62
+ ```
63
+
64
+ Expected: the message lands in Claude's transcript as
65
+
66
+ ```text
67
+ <channel source="chroxy-channel" chat_id="1" path="/" method="POST">list the files in this directory</channel>
68
+ ```
69
+
70
+ Claude responds in the session and, when it calls the `reply` tool, the
71
+ prototype logs the reply to stderr (visible in Terminal 1, or in the channel's
72
+ debug log at `~/.claude/debug/<session-id>.txt`).
73
+
74
+ ### Override the port
75
+
76
+ ```bash
77
+ CHROXY_CHANNEL_PORT=9001 claude --dangerously-load-development-channels server:chroxy-channel
78
+ curl -X POST localhost:9001 -d "hello from a different port"
79
+ ```
80
+
81
+ ## Troubleshooting
82
+
83
+ - **`curl` succeeds but nothing reaches Claude** — run `/mcp` in the session to
84
+ check the channel's status. "Failed to connect" usually means an import error;
85
+ check `~/.claude/debug/<session-id>.txt` for the stderr trace.
86
+ - **`curl` fails with "connection refused"** — the port is not bound yet, or a
87
+ stale process from a previous run is holding it. `lsof -i :8788` shows what is
88
+ listening; kill the stale process and restart the session.
89
+ - **"blocked by org policy"** — a Team/Enterprise admin must enable channels for
90
+ the org (`channelsEnabled`). Channels are not available on Bedrock/Vertex.
91
+
92
+ ## Security note
93
+
94
+ The HTTP control surface binds to `127.0.0.1` only. Even so, **anything that can
95
+ POST to the port injects text directly into the live Claude session** — a
96
+ prompt-injection surface (spike risk R8). This prototype keeps the surface for
97
+ `curl` testing; the real bridge (#3954) replaces it with a Unix socket driven
98
+ solely by `ClaudeChannelSession`, and any permission-relay opt-in (#3955) gates
99
+ on that single trusted writer.