@bitkyc08/opencodex 2.92.0 → 2.93.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 (258) hide show
  1. package/bin/ocx.mjs +10 -5
  2. package/gui/dist/assets/{App-sUf_8afJ.js → App-CizjBqyk.js} +18 -18
  3. package/gui/dist/assets/{Tray-BSsxznDm.js → Tray-DamiMqcX.js} +1 -1
  4. package/gui/dist/assets/{index-BlFE_VB_.js → index-DQsht3vH.js} +12 -12
  5. package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
  6. package/gui/dist/assets/{quota-summary-BRlbXgw0.js → quota-summary-BXu4zE8H.js} +1 -1
  7. package/gui/dist/index.html +2 -2
  8. package/package.json +5 -5
  9. package/src/adapters/anthropic.ts +28 -5
  10. package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
  11. package/src/adapters/coding-agent/profile.ts +54 -16
  12. package/src/adapters/coding-agent/turn.ts +30 -2
  13. package/src/adapters/command-code.ts +114 -7
  14. package/src/adapters/cursor/native-exec-fs.ts +11 -9
  15. package/src/adapters/devin/live-models.ts +4 -0
  16. package/src/adapters/google-wire-compiler.ts +1 -2
  17. package/src/adapters/kiro/reasoning.ts +2 -0
  18. package/src/adapters/kiro-refusal.ts +6 -1
  19. package/src/adapters/kiro-wire.ts +1 -1
  20. package/src/adapters/openai-chat/messages.ts +8 -2
  21. package/src/adapters/openai-chat/passthrough.ts +35 -14
  22. package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
  23. package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
  24. package/src/adapters/openai-chat/required-tool-result.ts +64 -0
  25. package/src/adapters/openai-chat.ts +7 -8
  26. package/src/adapters/openai-responses/passthrough.ts +7 -4
  27. package/src/adapters/openai-responses/reasoning.ts +13 -0
  28. package/src/adapters/openai-responses/request-strips.ts +1 -1
  29. package/src/adapters/qoder/adapter.ts +129 -8
  30. package/src/adapters/qoder/scaffold-guard.ts +5 -0
  31. package/src/adapters/reasoning-controls.ts +16 -0
  32. package/src/adapters/tool-call-id.ts +1 -3
  33. package/src/bridge/errors.ts +27 -0
  34. package/src/bridge.ts +1 -1
  35. package/src/chat/inbound.ts +4 -1
  36. package/src/chat/outbound.ts +9 -2
  37. package/src/chat/reasoning-details.ts +28 -5
  38. package/src/claude/desktop-first-party.ts +54 -4
  39. package/src/claude/desktop-picker.ts +11 -8
  40. package/src/claude/first-party-settings.ts +3 -1
  41. package/src/claude/inbound.ts +2 -1
  42. package/src/claude/intercept/local-ca.ts +2 -1
  43. package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
  44. package/src/claude/intercept/picker-ca-startup.ts +3 -1
  45. package/src/claude/intercept/picker-models.ts +6 -3
  46. package/src/claude/intercept/picker-runtime.ts +3 -2
  47. package/src/claude/intercept/runtime.ts +6 -3
  48. package/src/claude/model-info.ts +31 -8
  49. package/src/cli/account-api.ts +11 -0
  50. package/src/cli/capabilities-agents-routing.ts +2 -2
  51. package/src/cli/capabilities-base.ts +7 -1
  52. package/src/cli/capabilities-observe-system.ts +10 -0
  53. package/src/cli/claude-desktop.ts +9 -8
  54. package/src/cli/claude.ts +3 -2
  55. package/src/cli/codex-shim-autorestore.ts +9 -0
  56. package/src/cli/combo-result.ts +7 -0
  57. package/src/cli/combo.ts +18 -0
  58. package/src/cli/cross-home-owner.ts +13 -1
  59. package/src/cli/dispatch.ts +25 -6
  60. package/src/cli/ensure-desired-integrations.ts +8 -6
  61. package/src/cli/export-command.ts +4 -1
  62. package/src/cli/help.ts +2 -1
  63. package/src/cli/index.ts +45 -45
  64. package/src/cli/integration-plan-dto.ts +4 -0
  65. package/src/cli/opencode.ts +20 -9
  66. package/src/cli/registry.ts +6 -4
  67. package/src/cli/root.ts +9 -0
  68. package/src/cli/status.ts +59 -1
  69. package/src/cli/stop-restore.ts +113 -0
  70. package/src/cli/sync-expectation.ts +60 -0
  71. package/src/cli/uninstall-integrations.ts +41 -7
  72. package/src/client/connect.ts +40 -3
  73. package/src/client/link-home.ts +10 -1
  74. package/src/client/machine-api.ts +3 -1
  75. package/src/client/sync-expectation.ts +118 -0
  76. package/src/clients/config-export/agent-clients.ts +96 -0
  77. package/src/clients/config-export/contracts.ts +25 -7
  78. package/src/clients/config-export/qoder.ts +38 -23
  79. package/src/clients/config-export/reasoning-metadata.ts +55 -8
  80. package/src/clients/config-export.ts +12 -0
  81. package/src/clients/lazycodex.ts +7 -2
  82. package/src/clients/reasoning-controls.ts +49 -0
  83. package/src/codex/auth-api/account-identity.ts +14 -0
  84. package/src/codex/auth-api/account-list.ts +29 -2
  85. package/src/codex/auth-api/http.ts +13 -0
  86. package/src/codex/auth-api/main-account-probe.ts +2 -2
  87. package/src/codex/auth-api/pool-mode-gate.ts +16 -3
  88. package/src/codex/auth-api/pool-quota-probe.ts +15 -0
  89. package/src/codex/auth-context.ts +15 -12
  90. package/src/codex/catalog/build-entries.ts +22 -0
  91. package/src/codex/catalog/configured-tiers.ts +70 -0
  92. package/src/codex/catalog/effort.ts +44 -10
  93. package/src/codex/catalog/gather-capture.ts +1 -0
  94. package/src/codex/catalog/heal-observation.ts +155 -13
  95. package/src/codex/catalog/metadata.ts +6 -0
  96. package/src/codex/catalog/model-hints.ts +60 -11
  97. package/src/codex/catalog/model-visibility.ts +3 -2
  98. package/src/codex/catalog/native-models.ts +18 -3
  99. package/src/codex/catalog/parsing.ts +10 -8
  100. package/src/codex/catalog/pinned-models.ts +2 -1
  101. package/src/codex/catalog/provider-models.ts +4 -5
  102. package/src/codex/catalog/retained-sync.ts +2 -1
  103. package/src/codex/catalog/routed-gather.ts +19 -20
  104. package/src/codex/catalog/write-audit.ts +3 -2
  105. package/src/codex/catalog-self-heal.ts +43 -23
  106. package/src/codex/collision-identity.ts +30 -5
  107. package/src/codex/convergence.ts +4 -3
  108. package/src/codex/data/roster-pinned-models.json +177 -1
  109. package/src/codex/desired-state.ts +6 -1
  110. package/src/codex/desktop-compatibility/installed-build.ts +88 -12
  111. package/src/codex/desktop-compatibility/runtime.ts +29 -5
  112. package/src/codex/desktop-compatibility/usage-controller.ts +2 -0
  113. package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
  114. package/src/codex/inject/config-toml.ts +0 -18
  115. package/src/codex/inject/plan.ts +18 -3
  116. package/src/codex/inject/remove.ts +6 -2
  117. package/src/codex/inject.ts +1 -1
  118. package/src/codex/journal.ts +61 -1
  119. package/src/codex/model-entitlements.ts +1 -1
  120. package/src/codex/native-main-owner.ts +27 -1
  121. package/src/codex/native-profile-store.ts +2 -1
  122. package/src/codex/pool-credit-policy.ts +35 -1
  123. package/src/codex/quota-types.ts +3 -0
  124. package/src/codex/quota.ts +24 -4
  125. package/src/codex/role-auto-assign.ts +6 -2
  126. package/src/codex/subagent-defaults.ts +49 -4
  127. package/src/combos/failover.ts +17 -2
  128. package/src/combos/jev-decision-contract.ts +22 -1
  129. package/src/combos/jev-service-exchange.ts +3 -1
  130. package/src/combos/jev.ts +95 -9
  131. package/src/combos/resolve.ts +45 -1
  132. package/src/combos/types.ts +24 -0
  133. package/src/config/load-degrade.ts +5 -0
  134. package/src/config/paths.ts +19 -3
  135. package/src/config/pending-teardown.ts +22 -1
  136. package/src/config/provider-validation.ts +15 -4
  137. package/src/config/removed-opencode-free.ts +11 -0
  138. package/src/config/schema/leaf-validators.ts +5 -0
  139. package/src/generated/compatibility-version.json +314 -230
  140. package/src/generated/model-metadata.ts +5 -5
  141. package/src/images/loop.ts +16 -2
  142. package/src/integrations/catalog-refresh.ts +1 -1
  143. package/src/integrations/hermes-profiles.ts +251 -0
  144. package/src/integrations/merge.ts +8 -0
  145. package/src/integrations/mutation-plan.ts +19 -4
  146. package/src/integrations/registry.ts +5 -0
  147. package/src/integrations/state.ts +36 -1
  148. package/src/integrations/writer.ts +18 -4
  149. package/src/lib/bun-path-runtime.mjs +2 -1
  150. package/src/lib/errors.ts +62 -0
  151. package/src/lib/eventstream-decoder.ts +81 -37
  152. package/src/lib/opaque-proxy-tunnel.ts +32 -8
  153. package/src/lib/pinned-http.ts +35 -2
  154. package/src/lib/process-control.ts +13 -1
  155. package/src/lib/socks5-fetch.ts +59 -64
  156. package/src/lib/socks5-upload-waiter.ts +50 -0
  157. package/src/lib/sse-decoder.ts +7 -2
  158. package/src/lib/state-store-sweeper.ts +40 -14
  159. package/src/lib/windows-native-principal-worker.ts +14 -0
  160. package/src/lib/windows-native-principal.ts +188 -0
  161. package/src/lib/windows-secret-acl.ts +39 -3
  162. package/src/lib/windows-user-principal.ts +62 -18
  163. package/src/link/ssh-config.ts +35 -3
  164. package/src/providers/account-quota-disk.ts +12 -4
  165. package/src/providers/codebuddy-models.ts +6 -0
  166. package/src/providers/codex-capacity.ts +3 -1
  167. package/src/providers/derive.ts +28 -0
  168. package/src/providers/kiro-models.ts +3 -0
  169. package/src/providers/mimo-thinking.ts +12 -0
  170. package/src/providers/model-rename-fields.ts +1 -0
  171. package/src/providers/model-rename-migration.ts +10 -0
  172. package/src/providers/openai-sidecar-credit.ts +2 -2
  173. package/src/providers/reasoning-capabilities.ts +76 -0
  174. package/src/providers/registry/entries-core.ts +14 -12
  175. package/src/providers/registry/entries-extended.ts +63 -20
  176. package/src/providers/registry/model-ids.ts +2 -0
  177. package/src/providers/registry/model-seeds.ts +93 -28
  178. package/src/providers/registry/types.ts +10 -1
  179. package/src/providers/resolved-model-policy.ts +26 -6
  180. package/src/providers/routed-config.ts +9 -1
  181. package/src/providers/stale-model-roster-migration.ts +44 -7
  182. package/src/remote-control/workspace-pi-runtime.ts +11 -6
  183. package/src/responses/compaction-summary.ts +45 -0
  184. package/src/responses/muse-tool-name-alias.ts +1 -2
  185. package/src/responses/parser.ts +3 -2
  186. package/src/responses/schema.ts +1 -0
  187. package/src/responses/thought-signature-replay.ts +10 -2
  188. package/src/routing/capability.ts +8 -2
  189. package/src/routing/history/ingest.ts +28 -3
  190. package/src/server/auth-cors.ts +3 -2
  191. package/src/server/chat-completions.ts +7 -0
  192. package/src/server/chat-native-eligibility.ts +7 -0
  193. package/src/server/chat-native-reasoning.ts +14 -4
  194. package/src/server/direct-local-http.ts +5 -2
  195. package/src/server/effort-policy.ts +5 -1
  196. package/src/server/index/live-sideband.ts +18 -15
  197. package/src/server/index/serve-options.ts +5 -4
  198. package/src/server/management/agent-settings-routes.ts +27 -15
  199. package/src/server/management/combo-routes.ts +4 -0
  200. package/src/server/management/config-routes.ts +2 -2
  201. package/src/server/management/decision-discovery.ts +12 -2
  202. package/src/server/management/hermes-profile-routes.ts +156 -0
  203. package/src/server/management/integration-routes.ts +85 -24
  204. package/src/server/management/model-routes.ts +2 -2
  205. package/src/server/management/model-row-export-metadata.ts +25 -6
  206. package/src/server/management/model-rows.ts +15 -20
  207. package/src/server/management/native-integration-routes.ts +11 -8
  208. package/src/server/management/route-registry.ts +4 -0
  209. package/src/server/management-api.ts +5 -0
  210. package/src/server/models-capabilities.ts +21 -3
  211. package/src/server/responses/adapter-delivery.ts +11 -1
  212. package/src/server/responses/adapter-dispatch.ts +2 -2
  213. package/src/server/responses/codex-ws-exchange.ts +39 -9
  214. package/src/server/responses/codex-ws-session.ts +38 -4
  215. package/src/server/responses/codex-ws-wire.ts +6 -1
  216. package/src/server/responses/combo-required-tool-contract.ts +103 -0
  217. package/src/server/responses/combo-stream-preflight.ts +8 -1
  218. package/src/server/responses/compact.ts +4 -3
  219. package/src/server/responses/context-overflow.ts +8 -1
  220. package/src/server/responses/core-combo-failure.ts +10 -0
  221. package/src/server/responses/core-combo.ts +23 -15
  222. package/src/server/responses/core-lifetime.ts +3 -0
  223. package/src/server/responses/core-normalize.ts +11 -1
  224. package/src/server/responses/core-options.ts +2 -0
  225. package/src/server/responses/main-hard-lock-routing.ts +60 -44
  226. package/src/server/responses/passthrough-delivery.ts +40 -2
  227. package/src/server/responses/policy-fallback.ts +6 -1
  228. package/src/server/responses/request-compression.ts +12 -7
  229. package/src/server/responses/request-prepare.ts +22 -2
  230. package/src/server/responses/request-sidecar-auth.ts +2 -0
  231. package/src/server/responses/response-effects.ts +22 -10
  232. package/src/server/responses/sidecar-execution.ts +11 -3
  233. package/src/server/stop-teardown.ts +36 -1
  234. package/src/server/ws-bridge.ts +1 -1
  235. package/src/service/desktop-supervision.d.mts +7 -4
  236. package/src/service/desktop-supervision.mjs +90 -13
  237. package/src/service/ownership-mutation-lease.mjs +21 -7
  238. package/src/types/config.ts +8 -2
  239. package/src/types/provider.ts +20 -6
  240. package/src/types/request.ts +10 -0
  241. package/src/types.ts +1 -0
  242. package/src/update/bind-probe.ts +29 -0
  243. package/src/update/job.ts +10 -29
  244. package/src/update/npm-install-job.ps1 +173 -0
  245. package/src/update/npm-install.mjs +70 -0
  246. package/src/update/stop-contract.d.mts +1 -0
  247. package/src/update/stop-contract.mjs +14 -0
  248. package/src/update/stop-decision.d.mts +1 -1
  249. package/src/update/stop-decision.mjs +13 -3
  250. package/src/update/teardown-handover.ts +166 -0
  251. package/src/update/transactional-install.d.mts +14 -3
  252. package/src/update/transactional-install.mjs +33 -7
  253. package/src/usage/expected-prices.ts +64 -31
  254. package/src/usage/timeline.ts +19 -9
  255. package/src/vision/eligibility.ts +15 -5
  256. package/src/vision/plan.ts +2 -2
  257. package/src/web-search/loop.ts +16 -2
  258. package/gui/dist/assets/index-DPeB9HpV.css +0 -1
@@ -380,8 +380,8 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
380
380
  if (wantsKeepNative && typeof body.keepNativeChatGptOnV1 !== "boolean") {
381
381
  return jsonResponse({ error: "body.keepNativeChatGptOnV1 must be a boolean" }, 400);
382
382
  }
383
- if (wantsThreads && (typeof body.maxConcurrentThreadsPerSession !== "number" || !Number.isInteger(body.maxConcurrentThreadsPerSession) || body.maxConcurrentThreadsPerSession < 1)) {
384
- return jsonResponse({ error: "body.maxConcurrentThreadsPerSession must be an integer >= 1" }, 400);
383
+ if (wantsThreads && (typeof body.maxConcurrentThreadsPerSession !== "number" || !Number.isSafeInteger(body.maxConcurrentThreadsPerSession) || body.maxConcurrentThreadsPerSession < 1)) {
384
+ return jsonResponse({ error: "body.maxConcurrentThreadsPerSession must be a safe integer >= 1" }, 400);
385
385
  }
386
386
  // Validate every new field BEFORE any write, so each 400 leaves config untouched.
387
387
  // null unsets the key; "" is a meaningful value for instructions and must not be
@@ -1062,7 +1062,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1062
1062
  rethrowManagementBodyTooLarge(error);
1063
1063
  return jsonResponse({ error: "invalid JSON body" }, 400);
1064
1064
  }
1065
- const { resolveClaudeDesktopApplyMode, observeClaudeDesktopMode, applyDesktopFirstParty, captureDesktopFirstPartyRollback, removeDesktopFirstParty } = await import("../../claude/desktop-first-party");
1065
+ const { resolveClaudeDesktopApplyMode, observeClaudeDesktopMode, applyDesktopFirstParty, withFirstPartySecretsSettled, captureDesktopFirstPartyRollback, removeDesktopFirstPartySettled } = await import("../../claude/desktop-first-party");
1066
1066
  const requested = (parsed as { mode?: unknown } | null)?.mode;
1067
1067
  let desktopMode: "first-party" | "gateway" = resolveClaudeDesktopApplyMode(config, observeClaudeDesktopMode(config));
1068
1068
  if (requested !== undefined) {
@@ -1105,7 +1105,8 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1105
1105
  return await runPickerTransition(config, async ops => {
1106
1106
  const { inspectDesktop3pConfigLibrary, removeDesktop3pStandardPivot } = await import("../../claude/desktop-3p");
1107
1107
  const rollback = captureDesktopFirstPartyRollback(config);
1108
- const applied = applyDesktopFirstParty(config);
1108
+ const { getConfigDir, withConfigDirHardeningSettled } = await import("../../config/paths");
1109
+ const applied = await withFirstPartySecretsSettled(getConfigDir(), () => applyDesktopFirstParty(config));
1109
1110
  if (!applied.ok) {
1110
1111
  const { firstPartyRefusalMessage } = await import("./native-integration-routes");
1111
1112
  return jsonResponse({
@@ -1113,6 +1114,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1113
1114
  code: "claude_desktop_first_party_refused",
1114
1115
  reason: applied.reason,
1115
1116
  path: applied.path,
1117
+ ...(applied.diagnostic ? { diagnostic: applied.diagnostic } : {}),
1116
1118
  }, applied.reason === "foreign_env" || applied.reason === "intercept_disabled" ? 409 : 500);
1117
1119
  }
1118
1120
  // Remove the gateway only after the replacement env was written.
@@ -1122,7 +1124,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1122
1124
  if (library.kind === "gateway_ours" || library.kind === "gateway_drifted") {
1123
1125
  const removed = (deps.removeDesktop3pStandardPivot ?? removeDesktop3pStandardPivot)({ appliedFingerprint, replaceWhileEnabled: true });
1124
1126
  if (!removed.ok) {
1125
- const restored = removed.changed || !applied.changed || rollback();
1127
+ const restored = removed.changed || !applied.changed || await withConfigDirHardeningSettled(getConfigDir(), rollback);
1126
1128
  const modeSaved = !removed.changed || (await persistDesktopModeField(config, "first-party")).ok;
1127
1129
  const warning = [restored ? "" : "first-party settings rollback did not complete",
1128
1130
  modeSaved ? "" : "first-party is active but its mode marker was not saved"].filter(Boolean).join("; ");
@@ -1219,10 +1221,10 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1219
1221
  const committed = persistCommittedDesktopGateway(config, state.profile, result.fingerprint);
1220
1222
  const modeWarning = committed.ok ? undefined : `Gateway applied, but its mode/profile state was not saved (${committed.reason}).`;
1221
1223
  // The durable marker describes the committed gateway even if old-mode cleanup fails.
1222
- const firstPartyRemoved = removeDesktopFirstParty(loadConfig());
1224
+ const firstPartyRemoved = await removeDesktopFirstPartySettled(loadConfig);
1223
1225
  if (!firstPartyRemoved.ok) {
1224
1226
  return { response: jsonResponse({
1225
- error: `Claude Code settings could not be parsed (${firstPartyRemoved.path}); first-party cleanup remains incomplete after gateway apply.`,
1227
+ error: `Claude Code first-party settings cleanup did not complete (${firstPartyRemoved.path}); the gateway was applied.`,
1226
1228
  code: "claude_desktop_first_party_refused", reason: firstPartyRemoved.reason,
1227
1229
  applied: true, saved: committed.ok, mode: "gateway", path: result.path,
1228
1230
  ...(modeWarning ? { warning: modeWarning } : {}),
@@ -1407,7 +1409,10 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1407
1409
  !("fingerprint" in body) || typeof body.fingerprint !== "string" || !/^[a-f0-9]{64}$/.test(body.fingerprint)) {
1408
1410
  return jsonResponse({ error: "fingerprint is required" }, 400);
1409
1411
  }
1410
- return jsonResponse(applyClaudeModelDefaults(config.claudeCode?.tierModels, body.fingerprint));
1412
+ // Fresh admission after the body await: a nested Claude home shares the config-root ACL flight.
1413
+ const fingerprint = body.fingerprint;
1414
+ const { withConfigDirHardeningSettled } = await import("../../config/paths"), { claudeConfigDir } = await import("../../claude/auth-detect");
1415
+ return jsonResponse(await withConfigDirHardeningSettled(claudeConfigDir(), () => applyClaudeModelDefaults(config.claudeCode?.tierModels, fingerprint)));
1411
1416
  } catch (error) {
1412
1417
  rethrowManagementBodyTooLarge(error);
1413
1418
  if (error instanceof ModelDefaultsRecoveryError) return jsonResponse({ error: error.message, code: error.message, backupPath: error.backupPath }, 500);
@@ -1516,10 +1521,10 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1516
1521
  visionSidecar: sidecarAnthropicPoolOptions(config, { ...helperVision, backend: helperVisionBackend }, helperParent),
1517
1522
  },
1518
1523
  ...(webSearchOverride && Object.keys(webSearchOverride).length > 0
1519
- ? { webSearchSidecar: { backend: webSearchOverride.backend, model: webSearchOverride.model, ...(webSearchOverride.anthropicInstance ? { anthropicInstance: webSearchOverride.anthropicInstance } : {}) } }
1524
+ ? { webSearchSidecar: { enabled: webSearchOverride.enabled, backend: webSearchOverride.backend, model: webSearchOverride.model, ...(webSearchOverride.anthropicInstance ? { anthropicInstance: webSearchOverride.anthropicInstance } : {}) } }
1520
1525
  : {}),
1521
1526
  ...(visionOverride && Object.keys(visionOverride).length > 0
1522
- ? { visionSidecar: { backend: visionOverride.backend, model: visionOverride.model, ...(visionOverride.anthropicInstance ? { anthropicInstance: visionOverride.anthropicInstance } : {}) } }
1527
+ ? { visionSidecar: { enabled: visionOverride.enabled, backend: visionOverride.backend, model: visionOverride.model, ...(visionOverride.anthropicInstance ? { anthropicInstance: visionOverride.anthropicInstance } : {}) } }
1523
1528
  : {}),
1524
1529
  fastMode: config.fastMode,
1525
1530
  forceAvailable: [...visibleNativeSlugs(config), ...filterCatalogVisibleModels(models, config).map(catalogModelSlug)],
@@ -1552,7 +1557,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1552
1557
  return jsonResponse({ error: "cliFirstParty must be sent alone", code: "cli_first_party_not_alone" }, 400);
1553
1558
  if (body.cliFirstParty !== undefined) {
1554
1559
  const { claudeInterceptEnabled, claudeInterceptProxyPort, getClaudeInterceptState } = await import("../../claude/intercept/runtime");
1555
- const { captureDesktopFirstPartyRollback, inspectDesktopFirstParty, observeClaudeDesktopMode, resolveClaudeDesktopMode } = await import("../../claude/desktop-first-party");
1560
+ const { captureDesktopFirstPartyRollback, inspectDesktopFirstParty, observeClaudeDesktopMode, resolveClaudeDesktopMode, withFirstPartySecretsSettled } = await import("../../claude/desktop-first-party");
1556
1561
  const { firstPartyDesired, readFirstPartyProxyStatus, reconcileClaudeFirstPartySettings } = await import("../../claude/first-party-settings");
1557
1562
  const { commitClaudeCodeBlock } = await import("../../claude/claude-code-block");
1558
1563
  let bound = (deps.getClaudeInterceptState ?? getClaudeInterceptState)();
@@ -1622,13 +1627,15 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1622
1627
  if (committed.pinnedMode) live.desktopMode = committed.pinnedMode;
1623
1628
  config.claudeCode = live;
1624
1629
  let result: ReturnType<typeof reconcileClaudeFirstPartySettings> | undefined;
1625
- try { result = (deps.reconcileClaudeFirstPartySettings ?? reconcileClaudeFirstPartySettings)(config,
1626
- firstPartyDesired(config, observeClaudeDesktopMode(config))); }
1630
+ const { getConfigDir, withConfigDirHardeningSettled } = await import("../../config/paths");
1631
+ try { result = await withFirstPartySecretsSettled(getConfigDir(), () =>
1632
+ (deps.reconcileClaudeFirstPartySettings ?? reconcileClaudeFirstPartySettings)(config,
1633
+ firstPartyDesired(config, observeClaudeDesktopMode(config)))); }
1627
1634
  catch { /* An unexpected settings failure is mapped after conditional rollback. */ }
1628
1635
  if (!result?.ok) {
1629
1636
  let settingsRestored = true;
1630
1637
  if (body.cliFirstParty) {
1631
- try { settingsRestored = restoreSettings?.() ?? false; } catch { settingsRestored = false; }
1638
+ try { settingsRestored = result?.reason === "ca_unavailable" || await withConfigDirHardeningSettled(getConfigDir(), () => restoreSettings?.() ?? false); } catch { settingsRestored = false; }
1632
1639
  let rollback: ReturnType<typeof mutatePersistedConfig<OcxConfig["claudeCode"]>>;
1633
1640
  try {
1634
1641
  rollback = mutatePersistedConfig(persisted => {
@@ -1650,6 +1657,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1650
1657
  }
1651
1658
  const code = result?.reason ?? "write_failed";
1652
1659
  return jsonResponse({ error: "Claude first-party reconciliation failed", code,
1660
+ ...(result?.diagnostic ? { diagnostic: result.diagnostic } : {}),
1653
1661
  ...(!body.cliFirstParty && code === "unreadable"
1654
1662
  ? { cliFirstParty: false, warnings: ["settings_residual"] } : {}),
1655
1663
  ...(body.cliFirstParty && !settingsRestored
@@ -1673,6 +1681,9 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1673
1681
  const section = body[field];
1674
1682
  if (section === undefined || section === null) continue;
1675
1683
  if (!isPlainObject(section)) return jsonResponse({ error: `${field} must be an object or null` }, 400);
1684
+ if (section.enabled !== undefined && typeof section.enabled !== "boolean") {
1685
+ return jsonResponse({ error: `${field}.enabled must be a boolean` }, 400);
1686
+ }
1676
1687
  // Both overrides now speak their full unions (roadmap 060 web, 170
1677
1688
  // vision revised). Vision's third arm is "routed" (loopback through the
1678
1689
  // proxy's own router), never exa: exa is not an LLM, and accepting an
@@ -1760,8 +1771,9 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
1760
1771
  }
1761
1772
  // The per-field validation above guarantees vision only ever carries the two-member
1762
1773
  // union; the cast is the loop's shared-shape compromise, not a wider write path.
1763
- const requested = section as { backend?: "openai" | "anthropic" | "xai" | "gemini" | "exa" | null; model?: string; anthropicInstance?: AnthropicInstanceId | null };
1774
+ const requested = section as { enabled?: boolean; backend?: "openai" | "anthropic" | "xai" | "gemini" | "exa" | null; model?: string; anthropicInstance?: AnthropicInstanceId | null };
1764
1775
  const override = { ...next[field] } as NonNullable<OcxClaudeCodeConfig[typeof field]>;
1776
+ if (requested.enabled !== undefined) override.enabled = requested.enabled;
1765
1777
  if (requested.anthropicInstance === null) delete override.anthropicInstance;
1766
1778
  else if (isAnthropicInstanceId(requested.anthropicInstance)) override.anthropicInstance = requested.anthropicInstance;
1767
1779
  if (requested.backend === null) delete override.backend;
@@ -222,6 +222,10 @@ export async function handleComboRoutes(ctx: ManagementContext): Promise<Respons
222
222
  const requestedCombo: Record<string, unknown> = body.combo;
223
223
  const effectiveCombo = {
224
224
  ...requestedCombo,
225
+ // Clients that do not expose this opt-in must preserve it on unrelated edits.
226
+ ...(!Object.hasOwn(requestedCombo, "cooldownReprobe") && previous?.cooldownReprobe !== undefined
227
+ ? { cooldownReprobe: previous.cooldownReprobe }
228
+ : {}),
225
229
  ...(!Object.hasOwn(requestedCombo, "decisionQuotaSignals") && requestedCombo.strategy === "jev" && previous?.decisionQuotaSignals !== undefined ? { decisionQuotaSignals: previous.decisionQuotaSignals } : {}),
226
230
  ...(!Object.hasOwn(requestedCombo, "decisionQuotaTiers") && requestedCombo.strategy === "jev" && previous?.decisionQuotaTiers !== undefined ? { decisionQuotaTiers: previous.decisionQuotaTiers } : {}),
227
231
  // The dashboard does not edit the session pin (#7525): an omitted field keeps it on a JEV save.
@@ -331,8 +331,8 @@ export async function syncEnabledClientIntegrations(
331
331
  config,
332
332
  port,
333
333
  }, unattended
334
- ? ["mcode", "pi", "aside", "raycast", "omo", "commandcode", "droid", "opencode", "kilo", "qoder"]
335
- : ["mcode", "pi", "aside", "raycast", "omo", "cline", "commandcode", "droid", "opencode", "kilo", "qoder"],
334
+ ? ["mcode", "pi", "aside", "raycast", "omo", "commandcode", "droid", "opencode", "kilo", "qoder", "qoder-cn", "workbuddy", "workbuddy-ai"]
335
+ : ["mcode", "pi", "aside", "raycast", "omo", "cline", "commandcode", "droid", "opencode", "kilo", "qoder", "qoder-cn", "workbuddy", "workbuddy-ai"],
336
336
  ...unattended ? [{ refreshOnly: true, admit }] as const : []));
337
337
 
338
338
  return out;
@@ -39,7 +39,7 @@ export function isDecisionModelCandidate(row: DiscoveryModelRow, query = ""): bo
39
39
  const term = normalize(query);
40
40
  const haystack = `${row.id} ${row.owned_by ?? ""} ${row.displayName ?? ""}`.toLowerCase();
41
41
  if (term.length > 0) return haystack.includes(term);
42
- return DECISION_MODEL_HINT.test(row.id) || DECISION_MODEL_HINT.test(row.owned_by ?? "");
42
+ return DECISION_MODEL_HINT.test(row.id) || DECISION_MODEL_HINT.test(row.owned_by ?? "") || row.id.toLowerCase().includes("laya");
43
43
  }
44
44
 
45
45
  /**
@@ -53,7 +53,17 @@ export function isDecisionModelCandidate(row: DiscoveryModelRow, query = ""): bo
53
53
  export function systemOneEndpoint(baseUrl: string | undefined): string | null {
54
54
  const trimmed = (baseUrl ?? "").trim().replace(/\/+$/, "");
55
55
  if (!/^https?:\/\//i.test(trimmed)) return null;
56
- return trimmed.endsWith("/systemone") ? trimmed : `${trimmed}/systemone`;
56
+ try {
57
+ const parsed = new URL(trimmed);
58
+ if (parsed.hostname === "ai-gateway.vercel.sh") {
59
+ if (trimmed.endsWith("/decisions")) return trimmed;
60
+ return `${trimmed.replace(/\/systemone$/, "").replace(/\/+$/, "")}/decisions`;
61
+ }
62
+ } catch {
63
+ return null;
64
+ }
65
+ if (trimmed.endsWith("/systemone") || trimmed.endsWith("/decisions")) return trimmed;
66
+ return `${trimmed}/systemone`;
57
67
  }
58
68
 
59
69
  /** Deduplicate by provider+model so a row that appears twice is probed once. */
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Hermes profile selection for the client-integration routes (#7674).
3
+ *
4
+ * A Hermes profile is the same integration in a different home, so this module
5
+ * adds no mutation of its own. It turns a `profile` selector into a request
6
+ * scope (that profile's ownership store and the HERMES_HOME Hermes runs it with)
7
+ * and hands the request back to the generic routes, which then read, plan, write,
8
+ * journal and restore exactly as they do for the default profile.
9
+ *
10
+ * Accepted spellings, all with `profile=<name>`:
11
+ * - `/api/client-integrations/hermes` (GET, PUT)
12
+ * - `/api/client-integrations/{journal,preview,restore,restore/preview}` with `client=hermes`
13
+ *
14
+ * The `profile` selector is removed before the request continues (the Aside
15
+ * handlers treat any `profile` as an Aside account id, and a Hermes name such as
16
+ * `123` is also a valid one), and the generic routes skip every Aside delegation
17
+ * for a scoped request, `profile=default` included. A Hermes-scoped request can
18
+ * therefore never reach an Aside operation, and it sees only Hermes rows.
19
+ */
20
+ import {
21
+ HERMES_DEFAULT_PROFILE,
22
+ HermesProfileError,
23
+ guardedHermesProfileStore,
24
+ hermesProfileBoundary,
25
+ hermesProfileEnv,
26
+ hermesProfilePaths,
27
+ hermesProfileStore,
28
+ listHermesProfiles,
29
+ resolveHermesProfile,
30
+ type HermesProfile,
31
+ } from "../../integrations/hermes-profiles";
32
+ import type { ResolvedIntegrationPaths } from "../../integrations/registry";
33
+ import type { IntegrationStateStore } from "../../integrations/store";
34
+ import type { ExportModel } from "../../clients/config-export";
35
+ import { jsonResponse } from "../auth-cors";
36
+ import type { ManagementContext } from "./context";
37
+
38
+ export interface HermesRequestScope {
39
+ profile: HermesProfile;
40
+ store: IntegrationStateStore;
41
+ env: NodeJS.ProcessEnv;
42
+ /** Named profiles only; the default profile resolves its paths as it always has. */
43
+ resolvedPaths?: ResolvedIntegrationPaths;
44
+ /** Throws a HermesProfileError when the pinned profile no longer holds. */
45
+ assertBoundary: () => void;
46
+ }
47
+
48
+ export interface HermesScopeBase {
49
+ store: IntegrationStateStore;
50
+ env?: NodeJS.ProcessEnv;
51
+ home?: string;
52
+ }
53
+
54
+ export const HERMES_PROFILES_PATH = "/api/client-integrations/hermes/profiles";
55
+ const HERMES_CLIENT_PATH = "/api/client-integrations/hermes";
56
+ const HISTORY_PATHS = [
57
+ "/api/client-integrations/journal",
58
+ "/api/client-integrations/preview",
59
+ "/api/client-integrations/restore",
60
+ "/api/client-integrations/restore/preview",
61
+ ];
62
+
63
+ /*
64
+ * Keyed by the Request object, which every copy of the management context shares.
65
+ * Entries die with the request.
66
+ */
67
+ const scopes = new WeakMap<Request, HermesRequestScope>();
68
+
69
+ export function hermesRequestScope(req: Request): HermesRequestScope | undefined {
70
+ return scopes.get(req);
71
+ }
72
+
73
+ function scopeFor(profile: HermesProfile, base: HermesScopeBase): HermesRequestScope {
74
+ const env = base.env ?? process.env;
75
+ if (profile.name === HERMES_DEFAULT_PROFILE) {
76
+ return { profile, store: base.store, env, assertBoundary: () => {} };
77
+ }
78
+ const store = hermesProfileStore(base.store, profile.name);
79
+ const assertBoundary = hermesProfileBoundary(profile, store);
80
+ return {
81
+ profile, store: guardedHermesProfileStore(store, assertBoundary), env: hermesProfileEnv(profile, env),
82
+ resolvedPaths: hermesProfilePaths(profile), assertBoundary,
83
+ };
84
+ }
85
+
86
+ function refusal(ctx: ManagementContext, error: HermesProfileError): Response {
87
+ return jsonResponse({ error: error.message, code: error.code, clientId: "hermes" }, error.status, ctx.req, ctx.config);
88
+ }
89
+
90
+ /**
91
+ * The context to continue with, a refusal, or null when the request names no
92
+ * Hermes profile. `profile=default` keeps the root store and the default paths.
93
+ */
94
+ export function scopeHermesProfileRequest(ctx: ManagementContext, base: HermesScopeBase): ManagementContext | Response | null {
95
+ const { url, req } = ctx;
96
+ if (!url.searchParams.has("profile")) return null;
97
+ const onClientPath = url.pathname === HERMES_CLIENT_PATH;
98
+ const onHistoryPath = HISTORY_PATHS.includes(url.pathname) && url.searchParams.get("client") === "hermes";
99
+ if (!onClientPath && !onHistoryPath) return null;
100
+ const selectors = url.searchParams.getAll("profile");
101
+ if (selectors.length !== 1) {
102
+ return refusal(ctx, new HermesProfileError("invalid_hermes_profile", 400, "Name exactly one Hermes profile"));
103
+ }
104
+ let scope: HermesRequestScope;
105
+ try { scope = scopeFor(resolveHermesProfile(selectors[0]!, base.env ?? process.env, base.home), base); }
106
+ catch (error) {
107
+ if (error instanceof HermesProfileError) return refusal(ctx, error);
108
+ throw error;
109
+ }
110
+ const next = new URL(url);
111
+ next.searchParams.delete("profile");
112
+ scopes.set(req, scope);
113
+ return { ...ctx, url: next };
114
+ }
115
+
116
+ /**
117
+ * GET /api/client-integrations/hermes/profiles: every profile with its own state.
118
+ *
119
+ * The roster loads first. Each profile's boundary is then checked and its state read with no await
120
+ * in between, and a profile whose boundary does not hold is described from its path alone: reading
121
+ * state also retries snapshot maintenance, which must never run through a store that was refused.
122
+ */
123
+ export async function hermesProfileListResponse(
124
+ ctx: ManagementContext,
125
+ base: HermesScopeBase,
126
+ loadModels: () => Promise<readonly ExportModel[]>,
127
+ read: (scope: HermesRequestScope | null, models: readonly ExportModel[]) => object,
128
+ ): Promise<Response | null> {
129
+ if (ctx.url.pathname !== HERMES_PROFILES_PATH || ctx.req.method !== "GET") return null;
130
+ if ([...ctx.url.searchParams.keys()].length > 0) {
131
+ return refusal(ctx, new HermesProfileError("invalid_hermes_profile", 400, "The profile list takes no selectors"));
132
+ }
133
+ try {
134
+ const models = await loadModels();
135
+ const profiles = listHermesProfiles(base.env ?? process.env, base.home);
136
+ const rows = profiles.map(profile => {
137
+ let scope: HermesRequestScope;
138
+ try { scope = scopeFor(profile, base); }
139
+ catch (error) {
140
+ if (!(error instanceof HermesProfileError)) throw error;
141
+ return {
142
+ clientId: "hermes", configPath: profile.configPath, state: "unsafe", installed: true,
143
+ snapshotCount: -1, retentionDegraded: true, hermesProfile: profile.name, error: error.message,
144
+ };
145
+ }
146
+ return { ...read(scope.resolvedPaths ? scope : null, models), hermesProfile: profile.name };
147
+ });
148
+ return jsonResponse({ profiles: rows }, 200, ctx.req, ctx.config);
149
+ } catch (error) {
150
+ if (error instanceof HermesProfileError) return refusal(ctx, error);
151
+ return jsonResponse({
152
+ error: error instanceof Error ? error.message : String(error),
153
+ code: "integration_internal_error",
154
+ }, 500, ctx.req, ctx.config);
155
+ }
156
+ }
@@ -15,6 +15,8 @@ import {
15
15
  handleAsideProfileRoutes, asideJournalResponse, asideRestoreResponse,
16
16
  asideJournalDeleteResponse, type AsideProfileRouteOptions,
17
17
  } from "./aside-profile-routes";
18
+ import { hermesProfileListResponse, hermesRequestScope, scopeHermesProfileRequest } from "./hermes-profile-routes";
19
+ import { HermesProfileError } from "../../integrations/hermes-profiles";
18
20
  import type { IntegrationIO } from "../../integrations/config-io";
19
21
  import { createClineIO } from "../../integrations/cline-io";
20
22
  import { matchesOperationResult } from "../../integrations/journal";
@@ -79,6 +81,8 @@ export type IntegrationStateEnvelope = {
79
81
  models: Array<{ model: string; label: string; efforts: string[] }>;
80
82
  defaults: Record<string, string>;
81
83
  };
84
+ /** The Hermes profile a profile-scoped read describes (#7674). */
85
+ hermesProfile?: string;
82
86
  } & IntegrationStateRecord;
83
87
 
84
88
  export interface IntegrationStateListEnvelope {
@@ -181,6 +185,37 @@ function pathOverrides(): { env?: NodeJS.ProcessEnv; home?: string } {
181
185
  };
182
186
  }
183
187
 
188
+ /** A selected Hermes profile's environment and explicit target; nothing for any other request. */
189
+ function scopedPathOverrides(ctx: ManagementContext, clientId: IntegrationClientId): Pick<IntegrationWriteInput, "env" | "home" | "resolvedPaths"> {
190
+ const scope = clientId === "hermes" ? hermesRequestScope(ctx.req) : undefined;
191
+ return scope?.resolvedPaths ? { ...pathOverrides(), env: scope.env, resolvedPaths: { ...scope.resolvedPaths } } : pathOverrides();
192
+ }
193
+
194
+ /** Flight keys carry the profile, so a second profile is busy instead of joining the first one's write. */
195
+ function scopedFlightKey(ctx: ManagementContext, key: string): string {
196
+ const scope = hermesRequestScope(ctx.req);
197
+ return scope?.resolvedPaths ? `hermes-profile:${scope.profile.name}:${key}` : key;
198
+ }
199
+
200
+ /** A Hermes-scoped request may only ever see Hermes operations. */
201
+ function outsideHermesScope(ctx: ManagementContext, clientId: IntegrationClientId): boolean {
202
+ return hermesRequestScope(ctx.req) !== undefined && clientId !== "hermes";
203
+ }
204
+
205
+ /** The selected profile's boundary, as a writer refusal; null when it holds or nothing is pinned. */
206
+ function hermesBoundaryRefusal(ctx: ManagementContext): WriteRefused | null {
207
+ const scope = hermesRequestScope(ctx.req);
208
+ try {
209
+ scope?.assertBoundary();
210
+ return null;
211
+ } catch (error) {
212
+ return {
213
+ ok: false, reason: "unsafe", state: "unsafe", clientId: "hermes",
214
+ message: error instanceof Error ? error.message : "Hermes profile cannot be changed safely",
215
+ };
216
+ }
217
+ }
218
+
184
219
  function isPlainRecord(value: unknown): value is Record<string, unknown> {
185
220
  return typeof value === "object" && value !== null && !Array.isArray(value);
186
221
  }
@@ -221,8 +256,10 @@ export function setIntegrationMutationFlightTestHooks(
221
256
  * while handing the writer a separate default store, so a test could not bind
222
257
  * the whole operation to a temp root (A-gate round 12).
223
258
  */
224
- function integrationStore(): IntegrationStateStore {
225
- return integrationMutationTestHooks?.store ?? createIntegrationStateStore();
259
+ function integrationStore(ctx?: ManagementContext): IntegrationStateStore {
260
+ // A selected Hermes profile owns its own store; every other request keeps the root.
261
+ return (ctx ? hermesRequestScope(ctx.req)?.store : undefined)
262
+ ?? integrationMutationTestHooks?.store ?? createIntegrationStateStore();
226
263
  }
227
264
 
228
265
  function asideOptions(ctx: ManagementContext): AsideProfileRouteOptions {
@@ -256,7 +293,7 @@ async function buildIntegrationWriteInput(
256
293
  ...(droidReasoningDefaults === undefined ? {} : { droidReasoningDefaults: { ...droidReasoningDefaults } }),
257
294
  store,
258
295
  io: integrationMutationTestHooks?.io,
259
- ...pathOverrides(),
296
+ ...scopedPathOverrides(ctx, clientId),
260
297
  };
261
298
  }
262
299
 
@@ -288,7 +325,7 @@ async function buildIntegrationPreviewInput(
288
325
  ...(droidReasoningDefaults === undefined ? {} : { droidReasoningDefaults: { ...droidReasoningDefaults } }),
289
326
  store,
290
327
  io: integrationMutationTestHooks?.io,
291
- ...pathOverrides(),
328
+ ...scopedPathOverrides(ctx, clientId),
292
329
  },
293
330
  };
294
331
  }
@@ -328,7 +365,7 @@ function restoreClientScopeResponse(ctx: ManagementContext, opId: string, expect
328
365
  if (expectedClientId === undefined) return null;
329
366
  if (typeof expectedClientId !== "string" || !isIntegrationClientId(expectedClientId)) return invalidClientResponse(ctx);
330
367
  try {
331
- const operation = integrationStore().findOperation(opId);
368
+ const operation = integrationStore(ctx).findOperation(opId);
332
369
  if (!operation) return jsonResponse({ error: "integration operation not found", code: "integration_operation_not_found", opId }, 404, ctx.req, ctx.config);
333
370
  if (operation.clientId !== expectedClientId) return jsonResponse({ error: "integration operation belongs to a different client", code: "integration_client_mismatch" }, 409, ctx.req, ctx.config);
334
371
  return null;
@@ -455,6 +492,10 @@ function stalePlanGuard(
455
492
  }
456
493
 
457
494
  function internalErrorResponse(error: unknown, ctx: ManagementContext): Response {
495
+ // A selected Hermes profile whose boundary stopped holding is a refusal, not a server fault.
496
+ if (error instanceof HermesProfileError) {
497
+ return jsonResponse({ error: error.message, code: error.code, clientId: "hermes" }, error.status, ctx.req, ctx.config);
498
+ }
458
499
  return jsonResponse({
459
500
  error: error instanceof Error ? error.message : String(error),
460
501
  code: "integration_internal_error",
@@ -563,12 +604,14 @@ async function handleJournalDelete(ctx: ManagementContext): Promise<Response> {
563
604
  code: "invalid_op_id",
564
605
  }, 400, req, ctx.config);
565
606
  }
566
- const aside = await asideJournalDeleteResponse(ctx, opId, asideOptions(ctx));
567
- if (aside) return aside;
607
+ if (!hermesRequestScope(ctx.req)) {
608
+ const aside = await asideJournalDeleteResponse(ctx, opId, asideOptions(ctx));
609
+ if (aside) return aside;
610
+ }
568
611
  try {
569
- const store = integrationStore();
612
+ const store = integrationStore(ctx);
570
613
  const operation = store.findOperation(opId);
571
- if (!operation) {
614
+ if (!operation || outsideHermesScope(ctx, operation.clientId)) {
572
615
  // Already retired, or never existed. Both are 404: the tombstone hides
573
616
  // the row from findOperation, so a double-click is idempotent here
574
617
  // rather than a second deletion of something.
@@ -625,6 +668,17 @@ async function handleJournalDelete(ctx: ManagementContext): Promise<Response> {
625
668
  }
626
669
 
627
670
  export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<Response | null> {
671
+ const hermesBase = { store: integrationStore(), ...pathOverrides() };
672
+ const hermesProfiles = await hermesProfileListResponse(ctx, hermesBase, () => loadExportModels(ctx.config),
673
+ (scope, models) => readIntegrationState({
674
+ clientId: "hermes", models, config: ctx.config,
675
+ port: managementInferencePort(ctx), store: scope?.store ?? hermesBase.store, ...pathOverrides(),
676
+ ...(scope?.resolvedPaths ? { env: scope.env, resolvedPaths: { ...scope.resolvedPaths } } : {}),
677
+ }));
678
+ if (hermesProfiles) return hermesProfiles;
679
+ const hermesScoped = scopeHermesProfileRequest(ctx, hermesBase);
680
+ if (hermesScoped instanceof Response) return hermesScoped;
681
+ if (hermesScoped) ctx = hermesScoped;
628
682
  const { req, url } = ctx;
629
683
  const profileOptions = asideOptions(ctx);
630
684
  const aside = await handleAsideProfileRoutes(ctx, profileOptions);
@@ -673,10 +727,10 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
673
727
  if (requestedClient !== null && !isIntegrationClientId(requestedClient)) {
674
728
  return invalidClientResponse(ctx);
675
729
  }
676
- const asideJournal = await asideJournalResponse(ctx, requestedClient, profileOptions);
730
+ const asideJournal = hermesRequestScope(req) ? null : await asideJournalResponse(ctx, requestedClient, profileOptions);
677
731
  if (asideJournal) return asideJournal;
678
732
  try {
679
- const store = integrationStore();
733
+ const store = integrationStore(ctx);
680
734
  const storedOperations = store.listOperations(requestedClient ?? undefined);
681
735
  const newestByClient = new Map<IntegrationClientId, string>();
682
736
  for (const operation of storedOperations) {
@@ -770,6 +824,9 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
770
824
  if (previewClient === "aside") {
771
825
  return jsonResponse({ error: "Use the canonical Aside profile path", code: "invalid_aside_profile_path" }, 400, req, ctx.config);
772
826
  }
827
+ if (outsideHermesScope(ctx, previewClient as IntegrationClientId)) {
828
+ return jsonResponse({ error: "A Hermes profile plan must name the Hermes client", code: "invalid_hermes_profile" }, 400, req, ctx.config);
829
+ }
773
830
  const operation = parsed.operation;
774
831
  if (operation !== "apply" && operation !== "overwrite" && operation !== "disable") {
775
832
  return jsonResponse({
@@ -781,7 +838,7 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
781
838
  if (droidDefaults instanceof Response) return droidDefaults;
782
839
  try {
783
840
  const captured = await buildIntegrationPreviewInput(
784
- previewClient as IntegrationClientId, ctx, integrationStore(), droidDefaults,
841
+ previewClient as IntegrationClientId, ctx, integrationStore(ctx), droidDefaults,
785
842
  );
786
843
  if (!captured) return previewUnavailableResponse(ctx);
787
844
  if (droidDefaults !== undefined) {
@@ -808,14 +865,14 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
808
865
  const scopeResponse = restoreClientScopeResponse(ctx, opId, parsed.expectedClientId, url.pathname === "/api/client-integrations/commandcode/restore/preview" ? "commandcode" : undefined);
809
866
  if (scopeResponse) return scopeResponse;
810
867
  try {
811
- const store = integrationStore();
868
+ const store = integrationStore(ctx);
812
869
  const operation = store.findOperation(opId);
813
870
  /*
814
871
  * Answered as "not found" rather than by reading the row back to the caller. A preview is
815
872
  * reached before any confirmation, so it is the cheapest place to probe journal contents,
816
873
  * and it declines to be one.
817
874
  */
818
- if (!operation) {
875
+ if (!operation || outsideHermesScope(ctx, operation.clientId)) {
819
876
  return jsonResponse({
820
877
  error: "integration operation not found",
821
878
  code: "integration_operation_not_found",
@@ -871,7 +928,8 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
871
928
  }
872
929
  // The binding travels with the request. Dropping it here routed a bound Aside restore into
873
930
  // the unbound path, which executed the mutation while its confirmation went unexamined.
874
- const asideRestore = await asideRestoreResponse(ctx, {
931
+ // A Hermes-scoped restore never delegates: its operation lives in the selected Hermes store.
932
+ const asideRestore = hermesRequestScope(req) ? null : await asideRestoreResponse(ctx, {
875
933
  opId,
876
934
  confirmDrift,
877
935
  ...(parsed.operation === undefined ? {} : { operation: parsed.operation }),
@@ -880,9 +938,9 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
880
938
  if (asideRestore) return asideRestore;
881
939
  let restoreClientId: IntegrationClientId | undefined;
882
940
  try {
883
- const store = integrationStore();
941
+ const store = integrationStore(ctx);
884
942
  const operation = store.findOperation(opId);
885
- if (!operation) {
943
+ if (!operation || outsideHermesScope(ctx, operation.clientId)) {
886
944
  return jsonResponse({
887
945
  error: "integration operation not found",
888
946
  code: "integration_operation_not_found",
@@ -921,11 +979,12 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
921
979
  };
922
980
  const result = await runIntegrationMutationFlight(
923
981
  operation.clientId,
924
- `restore:${opId}:${confirmDrift}`,
982
+ scopedFlightKey(ctx, `restore:${opId}:${confirmDrift}`),
925
983
  writeInput.io?.now ?? Date.now,
926
984
  () => restoreIntegrationCoordinated(restoreInput, {
927
985
  lockSeams: integrationMutationTestHooks?.lockSeams,
928
986
  ...(restoreGuard ? { revalidate: restoreGuard.revalidate } : {}),
987
+ restoreGuard: () => hermesBoundaryRefusal(ctx),
929
988
  }),
930
989
  );
931
990
  const restoreStale = restoreGuard?.response();
@@ -967,8 +1026,9 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
967
1026
 
968
1027
  if (req.method === "GET") {
969
1028
  try {
970
- const input = await buildIntegrationWriteInput(requestedClient, ctx, integrationStore());
1029
+ const input = await buildIntegrationWriteInput(requestedClient, ctx, integrationStore(ctx));
971
1030
  const state = readIntegrationState(input);
1031
+ const scope = hermesRequestScope(req);
972
1032
  // Detection runs only for the client that needs it: `defaults` is a
973
1033
  // process spawn, and no other client's read should pay for it.
974
1034
  const envelope: IntegrationStateEnvelope = requestedClient === "raycast"
@@ -981,7 +1041,7 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
981
1041
  defaults: readOwnedDroidReasoningDefaults(input),
982
1042
  },
983
1043
  }
984
- : state;
1044
+ : scope ? { ...state, hermesProfile: scope.profile.name } : state;
985
1045
  return jsonResponse(envelope, 200, req, ctx.config);
986
1046
  } catch (error) {
987
1047
  return internalErrorResponse(error, ctx);
@@ -1040,11 +1100,11 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
1040
1100
  */
1041
1101
  const boundToggle = binding === "none"
1042
1102
  ? null
1043
- : await buildIntegrationPreviewInput(requestedClient, ctx, integrationStore(), droidDefaults);
1103
+ : await buildIntegrationPreviewInput(requestedClient, ctx, integrationStore(ctx), droidDefaults);
1044
1104
  if (binding !== "none" && boundToggle === null) return previewUnavailableResponse(ctx);
1045
1105
  const input = boundToggle
1046
1106
  ? boundToggle.input
1047
- : await buildIntegrationWriteInput(requestedClient, ctx, integrationStore(), droidDefaults);
1107
+ : await buildIntegrationWriteInput(requestedClient, ctx, integrationStore(ctx), droidDefaults);
1048
1108
  if (droidDefaults !== undefined) {
1049
1109
  const invalid = validateDroidReasoningDefaults(input.models, droidDefaults);
1050
1110
  if (invalid) return invalidDroidDefaultsResponse(ctx, invalid);
@@ -1052,7 +1112,7 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
1052
1112
  const guard = binding === "none" ? null : stalePlanGuard(
1053
1113
  requestedClient,
1054
1114
  ctx,
1055
- integrationStore(),
1115
+ integrationStore(ctx),
1056
1116
  { operation: binding.operation },
1057
1117
  binding.fingerprint,
1058
1118
  boundToggle === null ? null : boundToggle.identity,
@@ -1060,12 +1120,13 @@ export async function handleIntegrationRoutes(ctx: ManagementContext): Promise<R
1060
1120
  );
1061
1121
  const result = await runIntegrationMutationFlight(
1062
1122
  requestedClient,
1063
- parsed.enabled ? (parsed.overwriteConflict === true ? "overwrite" : "apply") : "disable",
1123
+ scopedFlightKey(ctx, parsed.enabled ? (parsed.overwriteConflict === true ? "overwrite" : "apply") : "disable"),
1064
1124
  input.io?.now ?? Date.now,
1065
1125
  () => {
1066
1126
  const options = {
1067
1127
  lockSeams: integrationMutationTestHooks?.lockSeams,
1068
1128
  ...(guard ? { revalidate: guard.revalidate } : {}),
1129
+ guard: () => hermesBoundaryRefusal(ctx),
1069
1130
  };
1070
1131
  if (!parsed.enabled) return disableIntegrationCoordinated(input, options);
1071
1132
  return parsed.overwriteConflict === true
@@ -561,9 +561,9 @@ export async function handleModelRoutes(ctx: ManagementContext): Promise<Respons
561
561
  if (!(error instanceof ClientPathError)) throw error;
562
562
  return jsonResponse({ error: error.message }, 400, req, config);
563
563
  }
564
- if ((requested === "raycast" || requested === "droid" || requested === "qoder") && shouldInjectApiAuthHeader(config)) {
564
+ if ((requested === "raycast" || requested === "droid" || requested === "qoder" || requested === "qoder-cn" || requested === "workbuddy" || requested === "workbuddy-ai") && shouldInjectApiAuthHeader(config)) {
565
565
  return jsonResponse({
566
- error: `${requested === "droid" ? "Factory Droid" : requested === "qoder" ? "Qoder" : "Raycast"} export requires an unauthenticated loopback destination; this listener requires an admission header the client cannot supply.`,
566
+ error: `${requested === "droid" ? "Factory Droid" : requested.startsWith("qoder") ? "Qoder" : requested.startsWith("workbuddy") ? "WorkBuddy" : "Raycast"} export requires an unauthenticated loopback destination; this listener requires an admission header the client cannot supply.`,
567
567
  reason: "non_loopback",
568
568
  }, 400, req, config);
569
569
  }