@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
@@ -55,14 +55,17 @@
55
55
  */
56
56
 
57
57
  import { existsSync, readFileSync, writeFileSync, mkdirSync, renameSync, chmodSync, unlinkSync } from 'node:fs'
58
- import { homedir } from 'node:os'
59
- import { join, dirname } from 'node:path'
58
+ import { dirname } from 'node:path'
59
+ import { configPath } from './config-dir.js'
60
60
 
61
61
  /**
62
62
  * Authoritative category list. MUST stay in sync with the keys of
63
63
  * `RATE_LIMITS` in `push.js` — these are the categories the server can
64
64
  * fire today. The schema-coverage test asserts every category has a
65
- * default.
65
+ * default. It is also pinned, in both directions, to the client roster
66
+ * (labels + render order) in `@chroxy/protocol`
67
+ * (`notification-categories.ts`) by `tests/notification-category-roster.test.js`
68
+ * (#7429): add a new category there too, or that test names the one missing.
66
69
  *
67
70
  * History: the issue text (#4541) sketches `permission / question / error /
68
71
  * result / inactivity` as user-facing labels; the wire-level set below is
@@ -70,6 +73,7 @@ import { join, dirname } from 'node:path'
70
73
  * can map these to friendlier labels without changing the protocol).
71
74
  */
72
75
  export const ALL_CATEGORIES = Object.freeze([
76
+ 'continuation',
73
77
  'permission',
74
78
  'result',
75
79
  'activity_update',
@@ -92,6 +96,10 @@ export const ALL_CATEGORIES = Object.freeze([
92
96
  // (mailbox-route.js). Listed so the category is mutable in prefs and visible
93
97
  // in snapshots (sanitizeCategoryMap strips unknown keys otherwise).
94
98
  'mailbox',
99
+ // #7424: CI-completion events from the session CI watcher. Listed so the
100
+ // category is mutable in prefs and visible in snapshots (sanitizeCategoryMap
101
+ // strips unknown keys otherwise).
102
+ 'ci_complete',
95
103
  ])
96
104
 
97
105
  /**
@@ -119,6 +127,26 @@ export const CATEGORY_DEFAULTS = Object.freeze(
119
127
  */
120
128
  export const DEFAULT_BYPASS_CATEGORIES = Object.freeze(['permission', 'activity_error'])
121
129
 
130
+ /**
131
+ * #7080 — wire bounds mirroring `ServerNotificationPrefsSchema` in @chroxy/protocol
132
+ * (schemas/server/billing.ts): a bypass entry is `min(1).max(64)`, the list is
133
+ * `.max(64)` items, and a device token is a record key of `min(1).max(512)`.
134
+ *
135
+ * The loader used to enforce TYPE only (`typeof s === 'string' && s.length > 0`)
136
+ * while the schema constrains RANGE, so a hand-edited prefs file produced a
137
+ * message the clients could not parse. The failure is unusually bad for a
138
+ * "cosmetic" cap: the client safeParses the WHOLE message, so `notificationPrefs`
139
+ * stays null and the dashboard renders "Loading preferences…" indefinitely on both
140
+ * clients — and `push.js` re-persists the offending value on the next patch, so it
141
+ * never self-heals. Refusing the value here is what keeps the panel alive.
142
+ *
143
+ * Pinned by a test that safeParses the REAL schema, so these cannot drift silently.
144
+ * (#7085 tracks exporting these from @chroxy/protocol so loaders stop retyping them.)
145
+ */
146
+ const MAX_BYPASS_CATEGORY_CHARS = 64
147
+ const MAX_BYPASS_CATEGORIES = 64
148
+ const MAX_DEVICE_TOKEN_CHARS = 512
149
+
122
150
  const _ALL_CATEGORIES_SET = new Set(ALL_CATEGORIES)
123
151
  // Two-digit zero-padded HH:MM with HH in 00-23 and MM in 00-59 (#4566).
124
152
  // The narrower regex replaces the older `/^\d{2}:\d{2}$/`, which accepted
@@ -127,7 +155,7 @@ const _ALL_CATEGORIES_SET = new Set(ALL_CATEGORIES)
127
155
  const _HHMM_RE = /^(?:[01]\d|2[0-3]):[0-5]\d$/
128
156
 
129
157
  export function defaultNotificationPrefsPath() {
130
- return process.env.CHROXY_NOTIFICATION_PREFS_PATH || join(homedir(), '.chroxy', 'notification-prefs.json')
158
+ return process.env.CHROXY_NOTIFICATION_PREFS_PATH || configPath('notification-prefs.json')
131
159
  }
132
160
 
133
161
  /**
@@ -179,6 +207,22 @@ function sanitizeDevices(raw, { log } = {}) {
179
207
  const out = {}
180
208
  for (const [token, entry] of Object.entries(raw)) {
181
209
  if (typeof token !== 'string' || token.length === 0) continue
210
+ // #7080: DROP an over-cap token, symmetric with the non-string/empty cases
211
+ // above. A push token is an ADDRESS: truncating it to 512 yields a token that
212
+ // addresses nothing and is then re-persisted by the next patch, permanently
213
+ // corrupting the file. Dropping self-heals on the next register_push_token.
214
+ if (token.length > MAX_DEVICE_TOKEN_CHARS) {
215
+ // NOTE this is DESTRUCTIVE on the next write: loadPrefs' output is also what
216
+ // savePrefs persists, and push.js `touchDevice` re-persists the whole
217
+ // sanitized object on every register_push_token — so one phone reconnecting
218
+ // erases this entry from disk. Accepted deliberately: a >512-char key cannot
219
+ // be a real push token, so nothing addressable is lost, and the alternative
220
+ // (preserving it) needs a load-for-wire / load-for-persistence split that
221
+ // does not exist here. Unlike a scheduled task (#7050), there is no operator
222
+ // data in an unrouteable token worth keeping.
223
+ log?.warn?.(`notification-prefs: dropped a device entry whose token exceeds ${MAX_DEVICE_TOKEN_CHARS} chars (unrepresentable on the wire; it will not survive the next save)`)
224
+ continue
225
+ }
182
226
  if (!entry || typeof entry !== 'object') continue
183
227
  const cleaned = { categories: sanitizeCategoryMap(entry.categories) }
184
228
  // Tri-state: present-as-null means "explicitly disable muting on this
@@ -196,7 +240,7 @@ function sanitizeDevices(raw, { log } = {}) {
196
240
  }
197
241
  }
198
242
  if (Object.prototype.hasOwnProperty.call(entry, 'bypassCategories')) {
199
- const bypass = sanitizeBypassList(entry.bypassCategories)
243
+ const bypass = sanitizeBypassList(entry.bypassCategories, { log, context: `device ${token} bypassCategories` })
200
244
  if (bypass !== null) cleaned.bypassCategories = bypass
201
245
  }
202
246
  // #4587: non-critical metadata for the per-device list UI. Operators
@@ -260,17 +304,63 @@ function sanitizeQuietHours(raw) {
260
304
  * (older binary, newer prefs file mentioning a category the binary hasn't
261
305
  * shipped yet) preserves the stored value.
262
306
  */
263
- function sanitizeBypassList(raw) {
307
+ function sanitizeBypassList(raw, { log, context = 'bypassCategories' } = {}) {
264
308
  if (raw == null) return null
265
309
  if (!Array.isArray(raw)) return []
266
- const seen = new Set()
310
+ // Retain KNOWN categories (a fixed set of ALL_CATEGORIES.length) and at most
311
+ // MAX_BYPASS_CATEGORIES unknowns, so a hostile file with a huge array cannot make
312
+ // the loader hold the whole thing. Deliberately NOT "keep the first N while
313
+ // iterating": that bounds memory but is positional, which is exactly what dropped
314
+ // a real `permission` entry past the cap (see the clamp comment below).
315
+ const knownSeen = new Set()
316
+ const unknownSeen = new Set()
317
+ let droppedLong = 0
318
+ let droppedOverflow = 0
267
319
  for (const item of raw) {
268
320
  if (typeof item !== 'string') continue
269
321
  const trimmed = item.trim()
270
322
  if (trimmed.length === 0) continue
271
- seen.add(trimmed)
323
+ // #7080: REJECT the element rather than truncating it. A category name is an
324
+ // identifier matched against ALL_CATEGORIES, so a truncated name matches
325
+ // nothing AND gets re-persisted — strictly worse than dropping it. This does
326
+ // narrow the forward-compat intent above: a future category longer than the
327
+ // wire cap will not be preserved by an older binary. That trade is
328
+ // deliberate — one un-bypassed category beats a dead notification panel.
329
+ if (trimmed.length > MAX_BYPASS_CATEGORY_CHARS) {
330
+ droppedLong += 1
331
+ continue
332
+ }
333
+ if (ALL_CATEGORIES.includes(trimmed)) {
334
+ knownSeen.add(trimmed)
335
+ continue
336
+ }
337
+ // Unknowns are the only unbounded input, so they are the only thing capped
338
+ // during iteration. A known category can never be lost this way.
339
+ if (unknownSeen.size >= MAX_BYPASS_CATEGORIES) {
340
+ droppedOverflow += 1
341
+ continue
342
+ }
343
+ unknownSeen.add(trimmed)
344
+ }
345
+ if (droppedLong > 0) {
346
+ log?.warn?.(`notification-prefs: dropped ${droppedLong} ${context} entr${droppedLong === 1 ? 'y' : 'ies'} longer than ${MAX_BYPASS_CATEGORY_CHARS} chars (unrepresentable on the wire)`)
272
347
  }
273
- return [...seen]
348
+ const list = [...knownSeen, ...unknownSeen]
349
+ if (list.length <= MAX_BYPASS_CATEGORIES && droppedOverflow === 0) return list
350
+ // CLAMP the length — but NOT positionally. A plain slice(0, N) drops whatever
351
+ // sits past the cap, which can be a REAL category: losing `permission` from the
352
+ // bypass list suppresses a blocking permission prompt during quiet hours and the
353
+ // agent stalls indefinitely (the #4544 rationale above). That is a worse failure
354
+ // than the unparseable snapshot this bound exists to prevent.
355
+ //
356
+ // So keep every RECOGNISED category first, then fill the remaining slots with
357
+ // unrecognised ones (preserving their relative order). This also serves the
358
+ // forward-compat intent better than a slice: the entries at risk of being
359
+ // dropped are now exactly the ones this binary cannot act on anyway.
360
+ const kept = list.slice(0, MAX_BYPASS_CATEGORIES)
361
+ const dropped = (list.length - kept.length) + droppedOverflow
362
+ log?.warn?.(`notification-prefs: ${context} exceeded ${MAX_BYPASS_CATEGORIES} entries; keeping ${kept.length} (recognised categories first, ${dropped} unrecognised dropped)`)
363
+ return kept
274
364
  }
275
365
 
276
366
  /**
@@ -289,7 +379,7 @@ export function loadPrefs(filePath = defaultNotificationPrefsPath(), { log } = {
289
379
  // coerced to defaults so the gate never misbehaves.
290
380
  let bypass = base.bypassCategories
291
381
  if (Object.prototype.hasOwnProperty.call(raw ?? {}, 'bypassCategories')) {
292
- const cleaned = sanitizeBypassList(raw.bypassCategories)
382
+ const cleaned = sanitizeBypassList(raw.bypassCategories, { log })
293
383
  bypass = cleaned ?? [...DEFAULT_BYPASS_CATEGORIES]
294
384
  }
295
385
  const cleanedQuietHours = sanitizeQuietHours(raw?.quietHours)
@@ -37,12 +37,12 @@
37
37
  */
38
38
 
39
39
  import { readFileSync, mkdirSync } from 'node:fs'
40
- import { dirname, join } from 'node:path'
41
- import { homedir } from 'node:os'
40
+ import { dirname } from 'node:path'
42
41
  import { writeFileRestricted } from '../platform.js'
43
42
  import { createLogger } from '../logger.js'
44
43
  import { sleep } from '../utils/sleep.js'
45
44
  import { NotificationSink } from './sink.js'
45
+ import { configPath } from '../config-dir.js'
46
46
  import {
47
47
  cachedResolveDiscordWebhookUrl,
48
48
  isValidDiscordWebhookUrl,
@@ -50,8 +50,10 @@ import {
50
50
  import {
51
51
  DEFAULT_ERROR_COLOR,
52
52
  DEFAULT_ONLINE_COLOR,
53
+ DEFAULT_ALLOWED_MENTIONS,
53
54
  isValidColor,
54
55
  escapeAndCap,
56
+ neutralizeMentions,
55
57
  apiBase,
56
58
  fetchWithDiscordRetry,
57
59
  } from './discord-webhook-client.js'
@@ -124,7 +126,7 @@ export class DiscordBillingSink extends NotificationSink {
124
126
  // -- State persistence ----------------------------------------------------
125
127
 
126
128
  _resolvedStatePath() {
127
- return this._statePath || join(homedir(), '.chroxy', 'discord-billing-state.json')
129
+ return this._statePath || configPath('discord-billing-state.json')
128
130
  }
129
131
 
130
132
  /** Load the single-message store fresh from disk (read-per-send). */
@@ -295,15 +297,25 @@ export class DiscordBillingSink extends NotificationSink {
295
297
  ? notification.data.codes.filter((c) => typeof c === 'string')
296
298
  : []
297
299
  const fields = []
300
+ // #5475/#8105: neutralize Discord mention syntax FIRST, then escape
301
+ // markdown. `body` is the billing canary's free-text warning message and
302
+ // `codes` are its identifiers — both ultimately caller-supplied
303
+ // (notification.data), so a literal `@everyone`/`@here`/role/user mention
304
+ // in either must not reach Discord as a live ping. Same ordering
305
+ // requirement as the status sink: neutralizeMentions on the raw value,
306
+ // escapeAndCap (truncate + escape + re-clamp) after.
298
307
  if (body) {
299
- fields.push({ name: resolved ? 'Resolved' : 'Warnings', value: escapeAndCap(body), inline: false })
308
+ fields.push({ name: resolved ? 'Resolved' : 'Warnings', value: escapeAndCap(neutralizeMentions(body)), inline: false })
300
309
  }
301
310
  if (!resolved && codes.length > 0) {
302
311
  // 200 is a deliberate short cap — codes are short identifiers
303
312
  // (SILENT_METERED_DEFAULT, …); a handful never approaches the 1024 field
304
313
  // limit, and a runaway list is fine to truncate.
305
- fields.push({ name: 'Codes', value: escapeAndCap(codes.join(', '), 200), inline: false })
314
+ fields.push({ name: 'Codes', value: escapeAndCap(neutralizeMentions(codes.join(', ')), 200), inline: false })
306
315
  }
316
+ // Title is built entirely from `this._botName` (trusted, admin-set) and
317
+ // `codes.length` (a number) — no caller-supplied free text, so no
318
+ // neutralization is needed here (unlike the fields above).
307
319
  const title = resolved
308
320
  ? `\u{2705} ${this._botName} — Billing alerts cleared`
309
321
  : codes.length > 1
@@ -315,9 +327,14 @@ export class DiscordBillingSink extends NotificationSink {
315
327
  title,
316
328
  color: resolved ? this._resolvedColor : this._alertColor,
317
329
  fields,
330
+ // Same reasoning as the title: this._botName is trusted, not free text.
318
331
  footer: { text: this._botName },
319
332
  timestamp: new Date(this._now()).toISOString(),
320
333
  }],
334
+ // Server-side backstop (#8105), on top of neutralizeMentions() above: no
335
+ // configured user/role ping exists for this sink — see
336
+ // DEFAULT_ALLOWED_MENTIONS in discord-webhook-client.js.
337
+ allowed_mentions: DEFAULT_ALLOWED_MENTIONS,
321
338
  }
322
339
  }
323
340
  }
@@ -0,0 +1,243 @@
1
+ /**
2
+ * DiscordCiSink — one fresh Discord message per CI run (#7428).
3
+ *
4
+ * #7424/#7426 added the `ci_complete` push category (a CI run settling on the
5
+ * pull request a session opened) and wired the Expo sink to deliver it. The
6
+ * per-project status sink (`discord-webhook-sink.js`) does not: `ci_complete`
7
+ * has no entry in its `STATE_FOR_CATEGORY` map, so its `send()` returns
8
+ * `true` — a silent no-op indistinguishable from delivery (#7428's original
9
+ * bug report). CI completion is not a session-lifecycle state; folding it
10
+ * into the status embed would repaint whatever the session's actual state is
11
+ * (idle/online/...) with a CI verdict from a run that may have settled long
12
+ * after the session moved on to something else.
13
+ *
14
+ * Decided (#7428, option 2 — Chris, 2026-09-28): **one Discord message per CI
15
+ * run**, always a fresh POST, never an edit. Unlike `discord-billing-sink.js`
16
+ * (its precedent for "an event that is not a session state" — one tracked
17
+ * global message, re-pinged on change) this sink keeps NO state file at all:
18
+ * two `ci_complete` events for the same PR (a re-push settling a second time)
19
+ * are two distinct completions and get two distinct messages. Editing the
20
+ * first message in place would erase the fact that a second run happened.
21
+ *
22
+ * The embed only ever uses fields the `ci_complete` payload
23
+ * (`ciCompletionPush` in session-ci-watcher.js) actually carries today: the
24
+ * PR number and link (`data.prNumber` / `data.prUrl`), a ✅/❌ conclusion
25
+ * (`data.verdict`), and the human-readable title/body chroxy already built
26
+ * (`describeCiCompletion` — check counts, merge state, and the PR title as a
27
+ * trailing " — <title>" clause). That payload carries no duration/timing
28
+ * field at all yet, so a duration is rendered only when the notification
29
+ * happens to carry a numeric `data.durationSeconds` — never fabricated — and
30
+ * omitted otherwise (see `_buildPayload`).
31
+ *
32
+ * A PR title is GitHub-authored free text, so it goes through the same
33
+ * markdown escaping (`escapeAndCap`) every other Discord sink applies to
34
+ * user/transcript content (#5475), plus mention neutralization
35
+ * (`neutralizeMentions`, discord-webhook-client.js) so an `@everyone` /
36
+ * `@here` / role-or-user mention in a PR title can't read as a live ping.
37
+ */
38
+
39
+ import { createLogger } from '../logger.js'
40
+ import { sleep } from '../utils/sleep.js'
41
+ import { NotificationSink } from './sink.js'
42
+ import {
43
+ cachedResolveDiscordWebhookUrl,
44
+ isValidDiscordWebhookUrl,
45
+ } from '../discord-credentials.js'
46
+ import {
47
+ DEFAULT_PROJECT_COLOR,
48
+ DEFAULT_ERROR_COLOR,
49
+ DEFAULT_ONLINE_COLOR,
50
+ DEFAULT_ALLOWED_MENTIONS,
51
+ MAX_EMBED_TITLE_CHARS,
52
+ isValidColor,
53
+ escapeAndCap,
54
+ neutralizeMentions,
55
+ formatDuration,
56
+ apiBase,
57
+ fetchWithDiscordRetry,
58
+ } from './discord-webhook-client.js'
59
+
60
+ const log = createLogger('discord')
61
+
62
+ const CI_CATEGORY = 'ci_complete'
63
+
64
+ export class DiscordCiSink extends NotificationSink {
65
+ /**
66
+ * @param {object} [opts]
67
+ * @param {string} [opts.botName] - Webhook display name + footer label.
68
+ * @param {boolean} [opts.ciAlerts] - Kill-switch
69
+ * (notifications.discord.ciAlerts). Default ON when a webhook resolves;
70
+ * set false to keep CI-completion notices off Discord while the status
71
+ * sink / billing sink stay on.
72
+ * @param {number} [opts.successColor] - Sidebar color for a passing run
73
+ * (default: green, same as the status sink's online color).
74
+ * @param {number} [opts.failureColor] - Sidebar color for a failing run
75
+ * (default: red).
76
+ * @param {number} [opts.unknownColor] - Sidebar color for a verdict this
77
+ * daemon does not recognise (default: blurple — neutral, not a false
78
+ * "passed" or "failed").
79
+ * @param {Function} [opts.resolveWebhookUrl] - Injection seam for tests;
80
+ * defaults to the env > 0600-credentials.json resolver.
81
+ * @param {Function} [opts.sleepImpl] - Injection seam for tests (429/backoff waits).
82
+ * @param {Function} [opts.now] - Clock seam for tests; defaults to Date.now.
83
+ */
84
+ constructor({
85
+ botName = 'Chroxy',
86
+ ciAlerts = true,
87
+ successColor = DEFAULT_ONLINE_COLOR,
88
+ failureColor = DEFAULT_ERROR_COLOR,
89
+ unknownColor = DEFAULT_PROJECT_COLOR,
90
+ resolveWebhookUrl = cachedResolveDiscordWebhookUrl,
91
+ sleepImpl = sleep,
92
+ now = Date.now,
93
+ } = {}) {
94
+ super({ name: 'discord-ci' })
95
+ this._botName = typeof botName === 'string' && botName.length > 0 ? botName.slice(0, 80) : 'Chroxy'
96
+ this._enabled = ciAlerts !== false
97
+ this._successColor = isValidColor(successColor) ? successColor : DEFAULT_ONLINE_COLOR
98
+ this._failureColor = isValidColor(failureColor) ? failureColor : DEFAULT_ERROR_COLOR
99
+ this._unknownColor = isValidColor(unknownColor) ? unknownColor : DEFAULT_PROJECT_COLOR
100
+ this._resolveWebhookUrl = resolveWebhookUrl
101
+ this._sleep = sleepImpl
102
+ this._now = now
103
+ }
104
+
105
+ /**
106
+ * Sink contract: configured iff CI alerts are enabled AND a syntactically
107
+ * valid webhook URL resolves. Off when either is missing — the registry
108
+ * then never asks this sink to send.
109
+ */
110
+ isConfigured() {
111
+ return this._enabled && this._configuredUrl() != null
112
+ }
113
+
114
+ /** Resolve + validate the webhook URL, or null. Never throws, never logs the URL. */
115
+ _configuredUrl() {
116
+ let resolved
117
+ try {
118
+ resolved = this._resolveWebhookUrl()
119
+ } catch {
120
+ return null
121
+ }
122
+ const url = resolved?.url
123
+ return typeof url === 'string' && isValidDiscordWebhookUrl(url) ? url : null
124
+ }
125
+
126
+ // -- Sink contract --------------------------------------------------------
127
+
128
+ /**
129
+ * Deliver one `ci_complete` notification as a brand-new Discord message.
130
+ * Only the `ci_complete` category is handled; everything else is skipped so
131
+ * the status sink keeps sole ownership of session-lifecycle events (the
132
+ * same "not ours" no-op the billing sink applies to non-billing
133
+ * categories).
134
+ *
135
+ * Resolves `false` ONLY on a hard channel failure (final non-2xx, network
136
+ * throw), per the sink contract. The per-DEVICE context evaluators are run
137
+ * once with `deviceId = null` (a webhook has no device identity), matching
138
+ * the other two Discord sinks.
139
+ */
140
+ async send(notification, context = {}) {
141
+ if (notification?.category !== CI_CATEGORY) return true // not ours — skip
142
+
143
+ const webhookUrl = this._configuredUrl()
144
+ if (!webhookUrl || !this._enabled) return true // unconfigured — registry normally skips us anyway
145
+
146
+ const now0 = context.now ?? this._now()
147
+ const isCategoryEnabled = context.isCategoryEnabled ?? (() => true)
148
+ const isInQuietHours = context.isInQuietHours ?? (() => false)
149
+ const shouldBypassQuietHours = context.shouldBypassQuietHours ?? (() => false)
150
+ if (!isCategoryEnabled(CI_CATEGORY, null)) return true
151
+ if (isInQuietHours(now0, null) && !shouldBypassQuietHours(CI_CATEGORY, null)) return true
152
+
153
+ try {
154
+ const payload = this._buildPayload(notification)
155
+ const res = await this._discordFetch(`${apiBase(webhookUrl)}?wait=true`, {
156
+ method: 'POST',
157
+ headers: { 'Content-Type': 'application/json' },
158
+ body: JSON.stringify(payload),
159
+ })
160
+ if (!res.ok) {
161
+ log.error(`Discord CI-completion POST failed (HTTP ${res.status})`)
162
+ return false
163
+ }
164
+ return true
165
+ } catch (err) {
166
+ log.error(`Discord CI-completion alert failed: ${err?.message || err}`)
167
+ return false
168
+ }
169
+ }
170
+
171
+ /** Delegate to the shared client's fetch policy, passing the injected sleep seam. */
172
+ async _discordFetch(url, options) {
173
+ return fetchWithDiscordRetry(url, options, { sleepImpl: this._sleep })
174
+ }
175
+
176
+ // -- Embed building ---------------------------------------------------------
177
+
178
+ /**
179
+ * Build the one-shot embed from whatever the `ci_complete` payload actually
180
+ * carries. Every field is read defensively (wrong type / missing → treated
181
+ * as absent) since a notification object is, in the end, caller-supplied
182
+ * data, not a trusted internal type.
183
+ */
184
+ _buildPayload(notification) {
185
+ const data = notification?.data && typeof notification.data === 'object' && !Array.isArray(notification.data)
186
+ ? notification.data
187
+ : {}
188
+ const verdict = typeof data.verdict === 'string' ? data.verdict : null
189
+ const prNumber = Number.isInteger(data.prNumber) ? data.prNumber : null
190
+ const prUrl = typeof data.prUrl === 'string' && data.prUrl.length > 0 ? data.prUrl : null
191
+ // The producer (session-ci-watcher.js ciCompletionPush) carries no timing
192
+ // field today — render gracefully rather than assume that never changes.
193
+ const durationSeconds = Number.isFinite(data.durationSeconds) ? data.durationSeconds : null
194
+
195
+ const emoji = verdict === 'failure' ? '\u{274C}' : verdict === 'success' ? '\u{2705}' : '\u{2753}'
196
+ const color = verdict === 'failure' ? this._failureColor : verdict === 'success' ? this._successColor : this._unknownColor
197
+
198
+ // `notification.title` (describeCiCompletion) already reads "CI passed on
199
+ // #1234" / "CI failed on #1234" / "CI finished on #1234 with unrecognised
200
+ // checks" — chroxy-authored, but still sanitized defensively since a
201
+ // notification object is caller-supplied. Missing/malformed → fall back
202
+ // to a title built from the one field we know is safe (an integer).
203
+ const rawTitle = typeof notification?.title === 'string' && notification.title.length > 0
204
+ ? notification.title
205
+ : (prNumber != null ? `CI finished on #${prNumber}` : 'CI finished')
206
+ const title = escapeAndCap(neutralizeMentions(`${emoji} ${rawTitle}`), MAX_EMBED_TITLE_CHARS)
207
+
208
+ // `notification.body` carries the check-count summary plus, when GitHub
209
+ // reports one, a trailing " — <PR title>" clause (describeCiCompletion) —
210
+ // the one place the actual (GitHub-authored) PR title text shows up.
211
+ const description = typeof notification?.body === 'string' && notification.body.length > 0
212
+ ? escapeAndCap(neutralizeMentions(notification.body))
213
+ : undefined
214
+
215
+ const fields = []
216
+ if (durationSeconds != null) {
217
+ fields.push({ name: 'Duration', value: formatDuration(durationSeconds), inline: true })
218
+ }
219
+
220
+ const embed = {
221
+ title,
222
+ color,
223
+ fields,
224
+ footer: { text: this._botName },
225
+ timestamp: new Date(this._now()).toISOString(),
226
+ }
227
+ if (description) embed.description = description
228
+ // Makes the embed title a clickable link to the PR — the "link" the
229
+ // decision comment asks for — without inventing a separate field for it.
230
+ if (prUrl) embed.url = prUrl
231
+
232
+ return {
233
+ username: this._botName,
234
+ embeds: [embed],
235
+ // Server-side backstop for neutralizeMentions() (#8105: now the shared
236
+ // default every Discord sink sets — see DEFAULT_ALLOWED_MENTIONS):
237
+ // Discord itself parses no mentions from this message, so nothing in a
238
+ // GitHub-authored PR title can ping anyone even if a mention form slips
239
+ // past the text transform.
240
+ allowed_mentions: DEFAULT_ALLOWED_MENTIONS,
241
+ }
242
+ }
243
+ }
@@ -108,6 +108,77 @@ export function escapeAndCap(text, max = 1000) {
108
108
  return trailing % 2 === 1 ? cut.slice(0, -1) : cut
109
109
  }
110
110
 
111
+ /**
112
+ * Discord's hard embed-title limit (#7105, moved here from
113
+ * discord-webhook-sink.js in #7428 so a second embed-building sink —
114
+ * discord-ci-sink.js — can share it without importing the status sink).
115
+ *
116
+ * Past it the ENTIRE webhook POST/PATCH comes back 400, so whatever the embed
117
+ * was reporting silently stops updating. Every free-text field goes through
118
+ * escapeAndCap for the same reason; a title needs the same ceiling even
119
+ * though Discord does not render markdown in titles (escapeAndCap's escaping
120
+ * step is then a no-op for a plain chroxy-authored title, but the length cap
121
+ * still applies).
122
+ *
123
+ * https://discord.com/developers/docs/resources/message#embed-object-embed-limits
124
+ */
125
+ export const MAX_EMBED_TITLE_CHARS = 256
126
+
127
+ // Discord's mention grammar: `@everyone` / `@here` (exact, case-sensitive in
128
+ // the client, matched case-insensitively here to be conservative) and the
129
+ // snowflake forms `<@123>` (user), `<@!123>` (nickname-mention user), `<@&123>`
130
+ // (role).
131
+ const MENTION_PATTERN = /<@[!&]?\d+>|@(?:everyone|here)\b/gi
132
+
133
+ /**
134
+ * Neutralize Discord mention syntax in free text so a PR title (or any other
135
+ * GitHub-authored string a sink embeds) can't ping `@everyone`/`@here`/a
136
+ * role/a user (#7428). Discord's mention parser needs the EXACT substring
137
+ * (`@everyone`, `<@123>`, ...) with nothing in between; inserting an
138
+ * invisible zero-width space (U+200B) right after the leading `@` breaks that
139
+ * match while leaving the text visually unchanged to a human reader — the
140
+ * same technique used by webhook bots generally, and cheaper than stripping
141
+ * or rewriting the mention (which would make a legitimately-named PR like
142
+ * "Add @here handling" unreadable).
143
+ *
144
+ * Order matters relative to escapeAndCap: call this FIRST, then escapeAndCap
145
+ * — escaping doesn't touch `@`/`<`/`>`/digits so the two passes don't
146
+ * interact, but running mention neutralization after a truncation could clip
147
+ * a mention mid-match and skip it.
148
+ */
149
+ export function neutralizeMentions(text) {
150
+ if (typeof text !== 'string') return ''
151
+ return text.replace(MENTION_PATTERN, (match) => (
152
+ match.startsWith('<@') ? `<@​${match.slice(2)}` : `@​${match.slice(1)}`
153
+ ))
154
+ }
155
+
156
+ /**
157
+ * Default `allowed_mentions` payload for every Discord sink (#8105): a
158
+ * server-side backstop telling Discord to parse NO mentions out of the
159
+ * message at all, regardless of what text reaches the wire. This is
160
+ * defense-in-depth layered ON TOP OF neutralizeMentions() (#7428), not a
161
+ * substitute for it — the text transform keeps a mention from being
162
+ * recognisable even by a human glancing at the raw JSON payload or a client
163
+ * that doesn't honour `allowed_mentions`, while this field is Discord's own
164
+ * guarantee that its API won't ping anyone even if a mention form ever slips
165
+ * past the text transform (a regex miss, a future field that forgets to
166
+ * call it, ...).
167
+ *
168
+ * None of the three Discord sinks (status, billing, CI) configure a
169
+ * deliberate ping to a specific user or role — `notifications.discord` has
170
+ * no such config key (see CONFIG.md / docs/guides/discord-notifications.md)
171
+ * — so `{ parse: [] }` (no mention types allowed at all) is correct for
172
+ * every sink today. A sink that ever needs a deliberate, configured ping
173
+ * would pass its own `{ parse: [], users: [id] }` / `{ ..., roles: [id] }`
174
+ * instead of this default — never a blanket `parse: []` that would silently
175
+ * swallow it.
176
+ *
177
+ * Frozen so sharing one reference across every payload can't be mutated by
178
+ * accident; JSON.stringify doesn't care either way, this is just hygiene.
179
+ */
180
+ export const DEFAULT_ALLOWED_MENTIONS = Object.freeze({ parse: [] })
181
+
111
182
  /** Build the Discord webhook API base from a validated webhook URL. */
112
183
  export function apiBase(webhookUrl) {
113
184
  const parts = extractWebhookIdToken(webhookUrl)