@runeya/runeya 2.0.158 → 2.0.160

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 (174) hide show
  1. package/agent/index.js +423 -248
  2. package/agent/index.js.map +1 -1
  3. package/agent-manager-KMVSAAEZ.js +13 -0
  4. package/chat-2XMACPWG.js +28 -0
  5. package/{chunk-ETPXJSVC.js → chunk-7QWHH56G.js} +2 -2
  6. package/{chunk-N4ZP7T6L.js → chunk-AKBRIK4Z.js} +4 -4
  7. package/{chunk-SVKR7CYU.js → chunk-CM5OCVUF.js} +4 -4
  8. package/{chunk-NV7MBTNW.js → chunk-DFUOLMOH.js} +5 -5
  9. package/{chunk-L3BEQ75K.js → chunk-EONEQJPD.js} +5 -5
  10. package/{chunk-V7WTXGEJ.js → chunk-ETVH3KQN.js} +6 -6
  11. package/{chunk-4HN2AGBV.js → chunk-KPWYNT4N.js} +215 -24
  12. package/chunk-KPWYNT4N.js.map +1 -0
  13. package/{chunk-TMX3NXMQ.js → chunk-L5M653DB.js} +6 -6
  14. package/{chunk-EZ35ISYR.js → chunk-LQSGSTGA.js} +197 -67
  15. package/chunk-LQSGSTGA.js.map +1 -0
  16. package/{chunk-SGFGQ2EL.js → chunk-VMRDER22.js} +5 -5
  17. package/chunk-VMRDER22.js.map +1 -0
  18. package/{chunk-JAMAGUGN.js → chunk-YRX375BB.js} +2 -2
  19. package/{chunk-N5LP5TPS.js → chunk-Z3HMLODE.js} +2 -2
  20. package/{chunk-DVECWRFG.js → chunk-ZULN5CM7.js} +35 -19
  21. package/chunk-ZULN5CM7.js.map +1 -0
  22. package/{companion-KVAOV52T.js → companion-UNWSLQCL.js} +17 -9
  23. package/{desktop-installer-page-DCS2FLA5.js → desktop-installer-page-N4JMRAAJ.js} +3 -3
  24. package/{desktop-launcher-ER3J7KAW.js → desktop-launcher-O7LFXEYZ.js} +3 -3
  25. package/{environment-resolver-HT6GTSLA.js → environment-resolver-S3QD7UJH.js} +6 -6
  26. package/{external-3QTRN4YV.js → external-5XDY2FMV.js} +3 -3
  27. package/index.js +12 -12
  28. package/{install-gate-WZR3XSN6.js → install-gate-MXRFIBIH.js} +2 -2
  29. package/mcp-server/external.js +160 -63
  30. package/mcp-server/external.js.map +1 -1
  31. package/mcp-server/index.js +160 -63
  32. package/mcp-server/index.js.map +1 -1
  33. package/package.json +1 -1
  34. package/{project-store-6TFAYAWK.js → project-store-HHMB2DIU.js} +7 -7
  35. package/settings-manager-SK7BDCQO.js +10 -0
  36. package/{src-F5SK2AL3.js → src-4XOEKUXK.js} +1168 -897
  37. package/src-4XOEKUXK.js.map +1 -0
  38. package/{src-DBSSIQC7.js → src-LBTF5RDR.js} +46 -2
  39. package/{vault-resolver-G3G5YPNG.js → vault-resolver-DL5FWIGZ.js} +3 -3
  40. package/web/assets/{AgentScalarChatInterface.vue-DgXKqqWC.js → AgentScalarChatInterface.vue-DlQ9QbMY.js} +1 -1
  41. package/web/assets/{AgentTerminalPage-B_cExmB6.js → AgentTerminalPage-BJqwsAx7.js} +1 -1
  42. package/web/assets/{AiChatModals-CNyUOq-o.js → AiChatModals-BDUz4ayE.js} +2 -2
  43. package/web/assets/AppLayout-B371VSKT.js +1 -0
  44. package/web/assets/AppLayout-iUAYhMxU.css +1 -0
  45. package/web/assets/{AuditPage-C8f1gRUr.js → AuditPage-CDmWtBlr.js} +1 -1
  46. package/web/assets/{CloudAccountPage-BC45p4uK.js → CloudAccountPage-Bk8QoNat.js} +1 -1
  47. package/web/assets/{CloudMessagingPage-BCEZdgoe.js → CloudMessagingPage-BYFfDa7H.js} +2 -2
  48. package/web/assets/{DashboardPage-CGtK_iBU.js → DashboardPage-BnmqlmJ6.js} +1 -1
  49. package/web/assets/{DirectoryPickerDialog-Ciy6QiOl.js → DirectoryPickerDialog-BwBzq-Ib.js} +1 -1
  50. package/web/assets/{EditorIcon-Cx11i-sC.js → EditorIcon-DYGui0zm.js} +1 -1
  51. package/web/assets/{EnvironmentForm-Dm5RBLw3.js → EnvironmentForm-D5thrtnK.js} +1 -1
  52. package/web/assets/{EnvironmentFormPage-tEpeq4it.js → EnvironmentFormPage-BvS6f3_v.js} +1 -1
  53. package/web/assets/{EnvironmentListPage-D8ppIAWE.js → EnvironmentListPage-BMpha28O.js} +1 -1
  54. package/web/assets/{FlagChip-UumVjPY9.js → FlagChip-DBj0fpJC.js} +1 -1
  55. package/web/assets/KanbanListPage-CsTOrPbp.js +1 -0
  56. package/web/assets/{KnowledgeListPage-BBhzvW-h.js → KnowledgeListPage-CGLjHGEt.js} +1 -1
  57. package/web/assets/{KnowledgePagePage-Bnnhyxfi.js → KnowledgePagePage-Dqu2hdSi.js} +1 -1
  58. package/web/assets/{LaunchProjectPage-BHbOO-qr.js → LaunchProjectPage-_FRQApLZ.js} +1 -1
  59. package/web/assets/{LaunchServicesPage-CrKG4CUc.js → LaunchServicesPage-ClyWpgrZ.js} +1 -1
  60. package/web/assets/{LaunchShell-BHgU9IFB.js → LaunchShell-DazwHw9x.js} +1 -1
  61. package/web/assets/LogViewer-BGpxumRk.js +3 -0
  62. package/web/assets/{OrgKeyPrompt-CmHBAJRR.js → OrgKeyPrompt-CJNrQ_wO.js} +1 -1
  63. package/web/assets/{ProcessControls-Bs5rpuyG.js → ProcessControls-jj09aiTP.js} +1 -1
  64. package/web/assets/{ProcessDetailPage-BouE6rnn.js → ProcessDetailPage-A-7cwr0N.js} +1 -1
  65. package/web/assets/{ProcessMetrics-DisQYLu6.js → ProcessMetrics-CAiB2nbb.js} +1 -1
  66. package/web/assets/{ProjectCreateDialog-CK-RH0wb.js → ProjectCreateDialog-LOK2KCbC.js} +1 -1
  67. package/web/assets/{ProjectLocationGate-j_EaQ37h.js → ProjectLocationGate-Cycmx3Qp.js} +1 -1
  68. package/web/assets/{ProjectPublishDialog-D7lTBCu_.js → ProjectPublishDialog-BK3lQrM5.js} +1 -1
  69. package/web/assets/{RandomJobTestPage-D11UxER3.js → RandomJobTestPage-D96PVnUs.js} +1 -1
  70. package/web/assets/{ScenarioEditorPage-D0ZyVUSQ.js → ScenarioEditorPage-Dr-vIMo-.js} +1 -1
  71. package/web/assets/{SendToChatDialog-j61mBTkW.js → SendToChatDialog-D4jRJpo9.js} +1 -1
  72. package/web/assets/{ServiceControlsBar-C2E_SEkD.js → ServiceControlsBar-CMMqc5Aj.js} +1 -1
  73. package/web/assets/{ServiceDetailPage-m_oJmvYC.js → ServiceDetailPage-mvyj5ljn.js} +1 -1
  74. package/web/assets/{ServiceFormPage-DyxF-esJ.js → ServiceFormPage-CRPYTrvA.js} +1 -1
  75. package/web/assets/{SettingsPage-BLaufENl.js → SettingsPage-BzvQ7QFy.js} +39 -39
  76. package/web/assets/{SettingsPage-Dsuzjo8r.css → SettingsPage-eID2nZZb.css} +1 -1
  77. package/web/assets/{UnlockPage-BmKWcShW.js → UnlockPage-BOtVWFNI.js} +1 -1
  78. package/web/assets/{VaultMigrationPage-CScIzmKv.js → VaultMigrationPage-B-0XeVkC.js} +1 -1
  79. package/web/assets/{VersionBadge-yfgoumwX.js → VersionBadge-Df5nYt5K.js} +1 -1
  80. package/web/assets/{WikiPage-WQBT7wLD.js → WikiPage-ZZ9OOPF3.js} +1 -1
  81. package/web/assets/WikiView-CR-7T69N.js +1 -0
  82. package/web/assets/{add-scalar-classes-C4A2C4Db.js → add-scalar-classes--DG4NWe_.js} +2 -2
  83. package/web/assets/{agent.store-n7zoFDoU.js → agent.store-B1T86nA6.js} +1 -1
  84. package/web/assets/auth-BBPhEkWy.js +2 -0
  85. package/web/assets/cloud-chat.store-CcnZa3kG.js +1 -0
  86. package/web/assets/cloud-client-DuiKxuIt.js +2 -0
  87. package/web/assets/{cloud-session-sF4HS72U.js → cloud-session-Dj2fMKcz.js} +2 -2
  88. package/web/assets/dist-DWtN-uEL.js +1 -0
  89. package/web/assets/i18n-D9syaX83.js +17 -0
  90. package/web/assets/{index-DozDRY7J.css → index-CchrQcOP.css} +1 -1
  91. package/web/assets/index-CoCePqYs.js +50 -0
  92. package/web/assets/knowledge-host-CRRuuH04.js +7 -0
  93. package/web/assets/knowledge-host-Dcy_zpf6.css +1 -0
  94. package/web/assets/{modal-BE_ZgM3t.js → modal-CiY8ERvc.js} +1 -1
  95. package/web/assets/{notification.store-BCON_qHz.js → notification.store-GxozJ0Vy.js} +1 -1
  96. package/web/assets/pdf-BHDyQiZ-.js +54 -0
  97. package/web/assets/pdf.worker.min-CuFqICzs.js +51 -0
  98. package/web/assets/{project-launch.store-Cd0LhFqV.js → project-launch.store-CNT8Buo8.js} +1 -1
  99. package/web/assets/{project.store-Doqh_upd.js → project.store-C8ckld_2.js} +1 -1
  100. package/web/assets/scenario.store-DgrGUEgB.js +7 -0
  101. package/web/assets/{service.store-BtPdRbHy.js → service.store-C9J8abIo.js} +1 -1
  102. package/web/assets/{settings-scope-BB3H0WrY.js → settings-scope-CI0lqhdd.js} +1 -1
  103. package/web/assets/{settings.store-B51AlAcp.js → settings.store-9PqM27KN.js} +1 -1
  104. package/web/assets/{src-CcVk2-Gw.js → src-B1nAsOcw.js} +1 -1
  105. package/web/assets/src-BR35jQnn.css +1 -0
  106. package/web/assets/src-C1M5hNGI.css +1 -0
  107. package/web/assets/{src-55L4GktS.js → src-C1pDBhwJ.js} +89 -24
  108. package/web/assets/src-D_HTzAKM.js +185 -0
  109. package/web/assets/src-DwxqtlGt.js +1 -0
  110. package/web/assets/src-ZDBDx6hs.css +1 -0
  111. package/web/assets/src-dOj6pCsH.css +1 -0
  112. package/web/assets/{trpc-CcVyWYH-.js → trpc-hVn9TTl9.js} +3 -3
  113. package/web/assets/useEnvVarAutocomplete-CokYA4JJ.js +1 -0
  114. package/web/assets/{useProjectCatalog-BiDVlcdO.js → useProjectCatalog-CYjZYzEn.js} +1 -1
  115. package/web/assets/{useProjectCloudOrg-CjDX0EaT.js → useProjectCloudOrg-GSxgZBKD.js} +1 -1
  116. package/web/assets/{useServiceUrlHost-CVjTMrmw.js → useServiceUrlHost-gLOpBQz6.js} +1 -1
  117. package/web/assets/uuid-D2uso58z.js +1 -0
  118. package/web/assets/w3c-keyname-BOAvb0qz.js +1 -0
  119. package/web/index.html +29 -19
  120. package/agent-manager-KDL4JWZN.js +0 -13
  121. package/chat-H5KZT3O6.js +0 -28
  122. package/chunk-4HN2AGBV.js.map +0 -1
  123. package/chunk-DVECWRFG.js.map +0 -1
  124. package/chunk-EZ35ISYR.js.map +0 -1
  125. package/chunk-SGFGQ2EL.js.map +0 -1
  126. package/settings-manager-OTVXDUJS.js +0 -10
  127. package/src-F5SK2AL3.js.map +0 -1
  128. package/web/assets/AppLayout-B1-D2-jx.css +0 -1
  129. package/web/assets/AppLayout-DPNVmCyo.js +0 -1
  130. package/web/assets/KanbanBoardPage-CamUcYCQ.js +0 -4
  131. package/web/assets/KanbanBoardPage-Cy1VPXZs.css +0 -1
  132. package/web/assets/KanbanListPage-C_DZwAKD.js +0 -1
  133. package/web/assets/LogViewer-DeTRyWSh.js +0 -3
  134. package/web/assets/WikiView-CXXW1EZ1.js +0 -1
  135. package/web/assets/auth-Bh28S0O0.js +0 -2
  136. package/web/assets/cloud-chat.store-C4WdXFzT.js +0 -1
  137. package/web/assets/cloud-client-D7GDcRGa.js +0 -2
  138. package/web/assets/composables-CCbqJqnd.js +0 -1
  139. package/web/assets/dist-Cx_klvkk.js +0 -1
  140. package/web/assets/i18n-B8hHo8g2.js +0 -17
  141. package/web/assets/index-Ccvk-qRh.js +0 -297
  142. package/web/assets/knowledge-host-97o7-gG1.js +0 -7
  143. package/web/assets/knowledge-host-D3fiBt2z.css +0 -1
  144. package/web/assets/scenario-run-overrides-BqTAaZZz.js +0 -1
  145. package/web/assets/scenario.store-Bttan_98.js +0 -7
  146. package/web/assets/shared-sse-Dcj_cNvF.js +0 -1
  147. package/web/assets/src-16-vEwhK.css +0 -1
  148. package/web/assets/src-B-YFvUDL.css +0 -1
  149. package/web/assets/src-DOziuDw8.css +0 -1
  150. package/web/assets/src-IxogYJKL.js +0 -1
  151. package/web/assets/useCloudOrg-43CkkppL.js +0 -1
  152. package/web/assets/useEnvVarAutocomplete-DGB9ZE4S.js +0 -1
  153. package/web/assets/uuid-DfCowYZy.js +0 -1
  154. /package/{agent-manager-KDL4JWZN.js.map → agent-manager-KMVSAAEZ.js.map} +0 -0
  155. /package/{chat-H5KZT3O6.js.map → chat-2XMACPWG.js.map} +0 -0
  156. /package/{chunk-ETPXJSVC.js.map → chunk-7QWHH56G.js.map} +0 -0
  157. /package/{chunk-N4ZP7T6L.js.map → chunk-AKBRIK4Z.js.map} +0 -0
  158. /package/{chunk-SVKR7CYU.js.map → chunk-CM5OCVUF.js.map} +0 -0
  159. /package/{chunk-NV7MBTNW.js.map → chunk-DFUOLMOH.js.map} +0 -0
  160. /package/{chunk-L3BEQ75K.js.map → chunk-EONEQJPD.js.map} +0 -0
  161. /package/{chunk-V7WTXGEJ.js.map → chunk-ETVH3KQN.js.map} +0 -0
  162. /package/{chunk-TMX3NXMQ.js.map → chunk-L5M653DB.js.map} +0 -0
  163. /package/{chunk-JAMAGUGN.js.map → chunk-YRX375BB.js.map} +0 -0
  164. /package/{chunk-N5LP5TPS.js.map → chunk-Z3HMLODE.js.map} +0 -0
  165. /package/{companion-KVAOV52T.js.map → companion-UNWSLQCL.js.map} +0 -0
  166. /package/{desktop-installer-page-DCS2FLA5.js.map → desktop-installer-page-N4JMRAAJ.js.map} +0 -0
  167. /package/{desktop-launcher-ER3J7KAW.js.map → desktop-launcher-O7LFXEYZ.js.map} +0 -0
  168. /package/{environment-resolver-HT6GTSLA.js.map → environment-resolver-S3QD7UJH.js.map} +0 -0
  169. /package/{external-3QTRN4YV.js.map → external-5XDY2FMV.js.map} +0 -0
  170. /package/{install-gate-WZR3XSN6.js.map → install-gate-MXRFIBIH.js.map} +0 -0
  171. /package/{project-store-6TFAYAWK.js.map → project-store-HHMB2DIU.js.map} +0 -0
  172. /package/{settings-manager-OTVXDUJS.js.map → settings-manager-SK7BDCQO.js.map} +0 -0
  173. /package/{src-DBSSIQC7.js.map → src-LBTF5RDR.js.map} +0 -0
  174. /package/{vault-resolver-G3G5YPNG.js.map → vault-resolver-DL5FWIGZ.js.map} +0 -0
@@ -67,16 +67,16 @@ import {
67
67
  soleAccountScope,
68
68
  startCliSession,
69
69
  vaultOfProject
70
- } from "./chunk-DVECWRFG.js";
71
- import "./chunk-SGFGQ2EL.js";
70
+ } from "./chunk-ZULN5CM7.js";
71
+ import "./chunk-VMRDER22.js";
72
72
  import {
73
73
  environmentOverridesStore,
74
74
  environmentResolver,
75
75
  filterEnvForAi
76
- } from "./chunk-L3BEQ75K.js";
76
+ } from "./chunk-EONEQJPD.js";
77
77
  import {
78
78
  settingsManager
79
- } from "./chunk-SVKR7CYU.js";
79
+ } from "./chunk-CM5OCVUF.js";
80
80
  import {
81
81
  CONVERSATIONS_DIRNAME,
82
82
  activeSessionRegistry,
@@ -97,14 +97,14 @@ import {
97
97
  stopClaudeTranscriptWatcher,
98
98
  stopCodexTranscriptWatcher,
99
99
  verifyJwt
100
- } from "./chunk-4HN2AGBV.js";
100
+ } from "./chunk-KPWYNT4N.js";
101
101
  import {
102
102
  LocalProjectRefusedError,
103
103
  ensureDataGitignore,
104
104
  holdsRuneyaProject,
105
105
  projectPathStore,
106
106
  projectStore
107
- } from "./chunk-V7WTXGEJ.js";
107
+ } from "./chunk-ETVH3KQN.js";
108
108
  import {
109
109
  agentManager,
110
110
  agentSpawner,
@@ -116,10 +116,10 @@ import {
116
116
  scheduleSelfRestart,
117
117
  traefikManager,
118
118
  unregisterInstance
119
- } from "./chunk-TMX3NXMQ.js";
119
+ } from "./chunk-L5M653DB.js";
120
120
  import {
121
121
  serviceStore
122
- } from "./chunk-NV7MBTNW.js";
122
+ } from "./chunk-DFUOLMOH.js";
123
123
  import {
124
124
  clearDetached,
125
125
  clearEncryptionKey,
@@ -147,7 +147,7 @@ import {
147
147
  setEncryptionKeyInMemory,
148
148
  setPendingLegacyKey,
149
149
  stableEncryptValue
150
- } from "./chunk-N4ZP7T6L.js";
150
+ } from "./chunk-AKBRIK4Z.js";
151
151
  import {
152
152
  decryptValueWith,
153
153
  encryptValueWith,
@@ -156,11 +156,13 @@ import {
156
156
  whichCommand
157
157
  } from "./chunk-OZBSOSAS.js";
158
158
  import {
159
+ atomicWriteJsonSecure,
159
160
  atomicWriteSecure,
161
+ readJsonFileSafe,
160
162
  renameWithRetry,
161
163
  resolveConversationRunDir,
162
164
  sweepStaleTempFiles
163
- } from "./chunk-JAMAGUGN.js";
165
+ } from "./chunk-YRX375BB.js";
164
166
  import "./chunk-MD3VW4HQ.js";
165
167
  import {
166
168
  allVaultRoots,
@@ -188,7 +190,7 @@ import {
188
190
  rememberOrgName,
189
191
  stampOrgCloud,
190
192
  vaultFor
191
- } from "./chunk-ETPXJSVC.js";
193
+ } from "./chunk-7QWHH56G.js";
192
194
  import {
193
195
  AGENT_LONG_FETCH_TIMEOUT,
194
196
  AGENT_STOP_FETCH_TIMEOUT,
@@ -216,10 +218,17 @@ import {
216
218
  MissingVariableReasonSchema,
217
219
  NotificationPreferencesSchema,
218
220
  SUPPORTED_EDITORS,
221
+ SUPPORT_FEATURES_HEADER,
222
+ SUPPORT_THREAD_FULL,
219
223
  ScenarioGroupSchema,
220
224
  ScenarioNodeSchema,
221
225
  ServiceShortcutSchema,
222
226
  SettingsSchema,
227
+ SupportCreateInputSchema,
228
+ SupportCreatedSchema,
229
+ SupportReplyInputSchema,
230
+ SupportTicketSummarySchema,
231
+ SupportTicketViewSchema,
223
232
  TraefikConfigSchema,
224
233
  UpdateEnvironmentSchema,
225
234
  VariableOverrideSchema,
@@ -230,6 +239,7 @@ import {
230
239
  deriveLauncherIdentity,
231
240
  findUnresolvedReferences,
232
241
  getCollection,
242
+ hasBodyOrFiles,
233
243
  localizePreset,
234
244
  nativeParsers,
235
245
  primaryServiceLink,
@@ -237,13 +247,13 @@ import {
237
247
  serviceSlug,
238
248
  suggestBuiltinReferences,
239
249
  writeEntity
240
- } from "./chunk-EZ35ISYR.js";
250
+ } from "./chunk-LQSGSTGA.js";
241
251
 
242
252
  // ../server/src/create-server.ts
243
253
  import express from "express";
244
254
  import cors from "cors";
245
255
  import { createServer } from "http";
246
- import { join as join18, resolve as resolve4 } from "path";
256
+ import { join as join19, resolve as resolve4 } from "path";
247
257
  import { WebSocketServer } from "ws";
248
258
  import { createExpressMiddleware } from "@trpc/server/adapters/express";
249
259
  import { applyWSSHandler } from "@trpc/server/adapters/ws";
@@ -653,10 +663,162 @@ var changelogRouter = router({
653
663
  })
654
664
  });
655
665
 
656
- // ../server/src/trpc/routers/project.ts
666
+ // ../server/src/trpc/routers/support.ts
667
+ import { join as join2 } from "path";
657
668
  import { z as z5 } from "zod";
658
- import { dirname as dirname2, isAbsolute as isAbsolute2 } from "path";
659
669
  import { TRPCError as TRPCError3 } from "@trpc/server";
670
+ var TOKEN_HEADER = "x-support-token";
671
+ var FEATURES = { [SUPPORT_FEATURES_HEADER]: "files" };
672
+ var tokensFile = () => join2(machineRoot(), "support-tickets.json");
673
+ async function readTokens() {
674
+ const raw = await readJsonFileSafe(tokensFile());
675
+ return Array.isArray(raw?.tickets) ? raw.tickets : [];
676
+ }
677
+ async function rememberToken(entry) {
678
+ const current2 = await readTokens();
679
+ await atomicWriteJsonSecure(tokensFile(), { tickets: [...current2, entry] });
680
+ }
681
+ function cloudBase() {
682
+ return getCloudApiUrl().replace(/\/+$/, "");
683
+ }
684
+ async function anonymousFetch(path, body, token) {
685
+ return fetch(`${cloudBase()}${path}`, {
686
+ method: "POST",
687
+ headers: {
688
+ "Content-Type": "application/json",
689
+ [APP_VERSION_HEADER]: appVersion,
690
+ ...FEATURES,
691
+ ...token ? { [TOKEN_HEADER]: token } : {}
692
+ },
693
+ body: JSON.stringify(body),
694
+ signal: AbortSignal.timeout(15e3)
695
+ });
696
+ }
697
+ async function readJson(res) {
698
+ if (res.status === 404) throw new TRPCError3({ code: "NOT_FOUND", message: "Ticket not found." });
699
+ if (res.status === 429) throw new TRPCError3({ code: "TOO_MANY_REQUESTS", message: "Too many requests, try again later." });
700
+ if (res.status === 400) {
701
+ const body = await res.json().catch(() => null);
702
+ if (body?.code === SUPPORT_THREAD_FULL) throw new TRPCError3({ code: "PRECONDITION_FAILED", message: SUPPORT_THREAD_FULL });
703
+ }
704
+ if (!res.ok) throw new TRPCError3({ code: "BAD_GATEWAY", message: `Support: HTTP ${res.status}` });
705
+ return res.json();
706
+ }
707
+ async function tokenFor(ticketId) {
708
+ const base = cloudBase();
709
+ return (await readTokens()).find((t) => t.ticketId === ticketId && t.cloudUrl === base)?.token;
710
+ }
711
+ async function listTickets(opts = {}) {
712
+ const results = [];
713
+ const accounts = await cloudSessionStore.list();
714
+ const Parsed = z5.object({ tickets: z5.array(SupportTicketSummarySchema) });
715
+ for (const account of accounts) {
716
+ try {
717
+ const res = await cloudFetch("/api/auth/support/ticket/list", { accountId: account.id });
718
+ for (const t of Parsed.parse(await readJson(res)).tickets) results.push({ ...t, accountId: account.id });
719
+ } catch (err) {
720
+ const absent = err instanceof TRPCError3 && err.code === "NOT_FOUND";
721
+ if (opts.strict && !absent) throw err;
722
+ if (!absent) console.warn("[support] list failed for an account:", err instanceof Error ? err.message : err);
723
+ }
724
+ }
725
+ const base = cloudBase();
726
+ const tokens = (await readTokens()).filter((t) => t.cloudUrl === base).map((t) => t.token);
727
+ for (let i = 0; i < tokens.length; i += 50) {
728
+ const res = await anonymousFetch("/api/auth/support/ticket/list-by-token", { tokens: tokens.slice(i, i + 50) });
729
+ for (const t of Parsed.parse(await readJson(res)).tickets) results.push({ ...t, accountId: null });
730
+ }
731
+ const seen = /* @__PURE__ */ new Set();
732
+ return results.filter((t) => seen.has(t.id) ? false : (seen.add(t.id), true)).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
733
+ }
734
+ async function anonymousTicketsStamp() {
735
+ const base = cloudBase();
736
+ const tokens = (await readTokens()).filter((t) => t.cloudUrl === base).map((t) => t.token);
737
+ const Parsed = z5.object({ tickets: z5.array(SupportTicketSummarySchema) });
738
+ const parts = [];
739
+ for (let i = 0; i < tokens.length; i += 50) {
740
+ const res = await anonymousFetch("/api/auth/support/ticket/list-by-token", { tokens: tokens.slice(i, i + 50) });
741
+ for (const t of Parsed.parse(await readJson(res)).tickets) parts.push(`${t.id}@${t.updatedAt}`);
742
+ }
743
+ return parts.sort().join("|");
744
+ }
745
+ async function supportFileFetch(path, init) {
746
+ const supportToken = init.ticketId ? await tokenFor(init.ticketId) : void 0;
747
+ const headers = { [APP_VERSION_HEADER]: appVersion, ...FEATURES };
748
+ if (init.contentType) headers["Content-Type"] = init.contentType;
749
+ let base = cloudBase();
750
+ if (supportToken) {
751
+ headers[TOKEN_HEADER] = supportToken;
752
+ } else if (init.accountId) {
753
+ const token = await cloudSessionStore.getToken(init.accountId);
754
+ if (!token) throw new TRPCError3({ code: "UNAUTHORIZED", message: "Cloud account not linked." });
755
+ headers["Authorization"] = `Bearer ${token}`;
756
+ base = (await cloudSessionStore.getCloudUrl(init.accountId) ?? base).replace(/\/+$/, "");
757
+ }
758
+ return fetch(`${base}${path}`, {
759
+ method: init.method ?? "GET",
760
+ headers,
761
+ ...init.body ? { body: init.body } : {},
762
+ // Un fichier de 55 Mo sur une connexion domestique prend des minutes.
763
+ signal: AbortSignal.timeout(3e5)
764
+ });
765
+ }
766
+ var AccountRef = z5.object({ accountId: z5.string().max(512).optional() });
767
+ var TicketRef = AccountRef.extend({ id: z5.string().uuid() });
768
+ var supportRouter = router({
769
+ /** Les comptes cloud du poste, pour choisir sous quel nom écrire. */
770
+ accounts: protectedProcedure.query(async () => {
771
+ const accounts = await cloudSessionStore.list();
772
+ return accounts.map((a) => ({ id: a.id, email: a.email, name: a.name }));
773
+ }),
774
+ create: protectedProcedure.input(SupportCreateInputSchema.omit({ source: true }).merge(AccountRef)).mutation(async ({ input }) => {
775
+ const { accountId, ...fields } = input;
776
+ const body = { ...fields, source: "app" };
777
+ if (accountId) {
778
+ const res = await cloudFetch("/api/auth/support/ticket/create", { method: "POST", body, accountId, headers: FEATURES });
779
+ return SupportCreatedSchema.parse(await readJson(res)).ticket;
780
+ }
781
+ if ((await cloudSessionStore.list()).length) {
782
+ throw new TRPCError3({ code: "BAD_REQUEST", message: "A cloud account is linked: send the request with it." });
783
+ }
784
+ if (!fields.email) throw new TRPCError3({ code: "BAD_REQUEST", message: "An email is required without an account." });
785
+ const created = SupportCreatedSchema.parse(await readJson(await anonymousFetch("/api/auth/support/ticket/create", body)));
786
+ if (created.accessToken) {
787
+ await rememberToken({ cloudUrl: cloudBase(), ticketId: created.ticket.id, token: created.accessToken });
788
+ }
789
+ return created.ticket;
790
+ }),
791
+ /** Les demandes de ce poste : celles des comptes liés, et celles envoyées sans compte. */
792
+ list: protectedProcedure.query(() => listTickets()),
793
+ /** Le nombre de demandes avec une réponse non lue : la pastille de la barre du bas. */
794
+ unreadCount: protectedProcedure.query(async () => {
795
+ try {
796
+ return (await listTickets({ strict: true })).filter((t) => t.unread).length;
797
+ } catch (err) {
798
+ console.warn("[support] unreadCount failed:", err instanceof Error ? err.message : err);
799
+ throw err;
800
+ }
801
+ }),
802
+ /** `peek` : consulter sans marquer comme lu (relecture sur signal, onglet caché). */
803
+ get: protectedProcedure.input(TicketRef.extend({ peek: z5.boolean().optional() })).query(async ({ input }) => {
804
+ const token = await tokenFor(input.id);
805
+ const body = { id: input.id, ...input.peek ? { peek: true } : {} };
806
+ const res = token || !input.accountId ? await anonymousFetch("/api/auth/support/ticket/get", body, token) : await cloudFetch("/api/auth/support/ticket/get", { method: "POST", body, accountId: input.accountId, headers: FEATURES });
807
+ return z5.object({ ticket: SupportTicketViewSchema }).parse(await readJson(res)).ticket;
808
+ }),
809
+ reply: protectedProcedure.input(TicketRef.merge(SupportReplyInputSchema)).mutation(async ({ input }) => {
810
+ if (!hasBodyOrFiles(input)) throw new TRPCError3({ code: "BAD_REQUEST", message: "A message needs text or a file." });
811
+ const token = await tokenFor(input.id);
812
+ const body = { id: input.id, body: input.body, ...input.attachmentIds?.length ? { attachmentIds: input.attachmentIds } : {} };
813
+ const res = token || !input.accountId ? await anonymousFetch("/api/auth/support/ticket/reply", body, token) : await cloudFetch("/api/auth/support/ticket/reply", { method: "POST", body, accountId: input.accountId, headers: FEATURES });
814
+ return z5.object({ ticket: SupportTicketViewSchema }).parse(await readJson(res)).ticket;
815
+ })
816
+ });
817
+
818
+ // ../server/src/trpc/routers/project.ts
819
+ import { z as z6 } from "zod";
820
+ import { dirname as dirname2, isAbsolute as isAbsolute2 } from "path";
821
+ import { TRPCError as TRPCError4 } from "@trpc/server";
660
822
 
661
823
  // ../server/src/services/current-project.ts
662
824
  var current = null;
@@ -702,7 +864,7 @@ import { mkdir } from "fs/promises";
702
864
  // ../server/src/services/master-password.ts
703
865
  import { randomBytes, createCipheriv, createDecipheriv } from "crypto";
704
866
  import { readFile, writeFile, chmod, stat } from "fs/promises";
705
- import { join as join2 } from "path";
867
+ import { join as join3 } from "path";
706
868
  import { Entry } from "@napi-rs/keyring";
707
869
  import { hashRaw as argon2HashRaw } from "@node-rs/argon2";
708
870
  var KEYRING_SERVICE = "runeya";
@@ -735,7 +897,7 @@ function aesDecrypt(key, data) {
735
897
  }
736
898
  async function getPepperFromFile(dataDir) {
737
899
  try {
738
- const raw = await readKeyFile(join2(dataDir, PEPPER_FILENAME));
900
+ const raw = await readKeyFile(join3(dataDir, PEPPER_FILENAME));
739
901
  const hex = raw.toString("utf-8").trim();
740
902
  if (/^[0-9a-f]{64}$/i.test(hex)) return Buffer.from(hex, "hex");
741
903
  } catch {
@@ -743,7 +905,7 @@ async function getPepperFromFile(dataDir) {
743
905
  return null;
744
906
  }
745
907
  async function writePepperToFile(dataDir, pepper) {
746
- const filePath = join2(dataDir, PEPPER_FILENAME);
908
+ const filePath = join3(dataDir, PEPPER_FILENAME);
747
909
  const tmpPath = filePath + ".tmp";
748
910
  await writeFile(tmpPath, pepper.toString("hex"), "utf-8");
749
911
  await chmod(tmpPath, 384);
@@ -794,14 +956,14 @@ async function writeEncryptedKey(dataDir, masterPassword, encryptionKey, pepperD
794
956
  const payload = aesEncrypt(derivedKey, encryptionKey);
795
957
  const fileContent = Buffer.concat([salt, payload]);
796
958
  const encoded = fileContent.toString("base64");
797
- const filePath = join2(dataDir, ENCRYPTED_KEY_FILENAME);
959
+ const filePath = join3(dataDir, ENCRYPTED_KEY_FILENAME);
798
960
  const tmpPath = filePath + ".tmp";
799
961
  await writeFile(tmpPath, encoded, "utf-8");
800
962
  await chmod(tmpPath, 384);
801
963
  await renameWithRetry(tmpPath, filePath);
802
964
  }
803
965
  async function readEncryptedKey(dataDir, masterPassword, pepperDir = dataDir) {
804
- const filePath = join2(dataDir, ENCRYPTED_KEY_FILENAME);
966
+ const filePath = join3(dataDir, ENCRYPTED_KEY_FILENAME);
805
967
  const raw = await readKeyFile(filePath);
806
968
  const fileContent = Buffer.from(raw.toString("utf-8").trim(), "base64");
807
969
  const salt = fileContent.subarray(0, 16);
@@ -821,13 +983,13 @@ async function getPepperFromKeychain(dataDir) {
821
983
  }
822
984
  async function writeVerifyFile(dataDir, encryptionKey) {
823
985
  const payload = aesEncrypt(encryptionKey, Buffer.from(CANARY_PLAINTEXT, "utf-8"));
824
- const filePath = join2(dataDir, VERIFY_FILENAME);
986
+ const filePath = join3(dataDir, VERIFY_FILENAME);
825
987
  const tmpPath = filePath + ".tmp";
826
988
  await writeFile(tmpPath, payload.toString("base64"), "utf-8");
827
989
  await renameWithRetry(tmpPath, filePath);
828
990
  }
829
991
  async function verifyEncryptionKey(dataDir, encryptionKey) {
830
- const filePath = join2(dataDir, VERIFY_FILENAME);
992
+ const filePath = join3(dataDir, VERIFY_FILENAME);
831
993
  const raw = await readKeyFile(filePath);
832
994
  if (!matchesCanary(raw.toString("utf-8"), encryptionKey)) {
833
995
  throw new Error("Cl\xE9 d'encryption incorrecte");
@@ -843,14 +1005,14 @@ function matchesCanary(canaryBase64, encryptionKey) {
843
1005
  }
844
1006
  async function readVerifyFile(dataDir) {
845
1007
  try {
846
- return (await readKeyFile(join2(dataDir, VERIFY_FILENAME))).toString("utf-8").trim();
1008
+ return (await readKeyFile(join3(dataDir, VERIFY_FILENAME))).toString("utf-8").trim();
847
1009
  } catch {
848
1010
  return null;
849
1011
  }
850
1012
  }
851
1013
  async function hasVerifyFile(dataDir) {
852
1014
  try {
853
- await stat(join2(dataDir, VERIFY_FILENAME));
1015
+ await stat(join3(dataDir, VERIFY_FILENAME));
854
1016
  return true;
855
1017
  } catch {
856
1018
  return false;
@@ -858,7 +1020,7 @@ async function hasVerifyFile(dataDir) {
858
1020
  }
859
1021
  async function hasEncryptedKeyFile(dataDir) {
860
1022
  try {
861
- await stat(join2(dataDir, ENCRYPTED_KEY_FILENAME));
1023
+ await stat(join3(dataDir, ENCRYPTED_KEY_FILENAME));
862
1024
  return true;
863
1025
  } catch {
864
1026
  return false;
@@ -999,7 +1161,7 @@ async function assertReadable(orgId) {
999
1161
  await assertOrgVaultReadable(orgId);
1000
1162
  } catch (err) {
1001
1163
  if (err instanceof OrgVaultUnreadableError) {
1002
- throw new TRPCError3({ code: "FORBIDDEN", message: err.message });
1164
+ throw new TRPCError4({ code: "FORBIDDEN", message: err.message });
1003
1165
  }
1004
1166
  throw err;
1005
1167
  }
@@ -1019,10 +1181,10 @@ var projectRouter = router({
1019
1181
  * `orgId` names which project — the same id can exist in several
1020
1182
  * organizations. Left out, the id must answer for exactly one project.
1021
1183
  */
1022
- get: protectedProcedure.input(z5.object({ id: z5.string().max(128), orgId: z5.string().max(128).nullable().optional() })).query(async ({ input }) => {
1184
+ get: protectedProcedure.input(z6.object({ id: z6.string().max(128), orgId: z6.string().max(128).nullable().optional() })).query(async ({ input }) => {
1023
1185
  const project = await projectStore.get(input);
1024
1186
  if (!project) {
1025
- throw new TRPCError3({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1187
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1026
1188
  }
1027
1189
  await assertReadable(project.orgId);
1028
1190
  return project;
@@ -1033,23 +1195,23 @@ var projectRouter = router({
1033
1195
  * Environments are intentionally excluded — they carry secret values that
1034
1196
  * stay local.
1035
1197
  */
1036
- export: protectedProcedure.input(z5.object({ id: z5.string().max(128), orgId: z5.string().max(128).nullable().optional() })).query(async ({ input }) => {
1198
+ export: protectedProcedure.input(z6.object({ id: z6.string().max(128), orgId: z6.string().max(128).nullable().optional() })).query(async ({ input }) => {
1037
1199
  const project = await projectStore.get(input);
1038
1200
  if (!project) {
1039
- throw new TRPCError3({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1201
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1040
1202
  }
1041
1203
  await assertReadable(project.orgId);
1042
1204
  const services = (await Promise.all(project.serviceIds.map((sid) => serviceStore.getSanitized(sid)))).filter((s) => s !== null);
1043
1205
  return { project, services };
1044
1206
  }),
1045
1207
  create: protectedProcedure.input(
1046
- z5.object({
1047
- name: z5.string().min(1).max(200),
1048
- description: z5.string().max(1e4).optional(),
1049
- orgId: z5.string().max(128).nullable().optional(),
1050
- serviceIds: z5.array(z5.string().max(128)).max(1e4).optional(),
1208
+ z6.object({
1209
+ name: z6.string().min(1).max(200),
1210
+ description: z6.string().max(1e4).optional(),
1211
+ orgId: z6.string().max(128).nullable().optional(),
1212
+ serviceIds: z6.array(z6.string().max(128)).max(1e4).optional(),
1051
1213
  /** Le dossier d'un projet local. Omis : le dossier de lancement. */
1052
- localPath: z5.string().min(1).max(4096).refine(isAbsolute2, "Chemin absolu attendu").optional()
1214
+ localPath: z6.string().min(1).max(4096).refine(isAbsolute2, "Chemin absolu attendu").optional()
1053
1215
  })
1054
1216
  ).mutation(async ({ input }) => {
1055
1217
  const { localPath, ...fields } = input;
@@ -1063,9 +1225,9 @@ var projectRouter = router({
1063
1225
  }, fields.orgId ? void 0 : localPath);
1064
1226
  } catch (err) {
1065
1227
  if (err instanceof LocalProjectRefusedError) {
1066
- throw new TRPCError3({ code: "CONFLICT", message: err.code, cause: err });
1228
+ throw new TRPCError4({ code: "CONFLICT", message: err.code, cause: err });
1067
1229
  }
1068
- throw new TRPCError3({ code: "CONFLICT", message: err.message });
1230
+ throw new TRPCError4({ code: "CONFLICT", message: err.message });
1069
1231
  }
1070
1232
  const localEnv = await environmentStore.create({
1071
1233
  projectId: project.id,
@@ -1084,38 +1246,38 @@ var projectRouter = router({
1084
1246
  return result;
1085
1247
  }),
1086
1248
  update: protectedProcedure.input(
1087
- z5.object({
1088
- id: z5.string().max(128),
1089
- name: z5.string().min(1).max(200).optional(),
1090
- description: z5.string().max(1e4).optional(),
1091
- orgId: z5.string().max(128).nullable().optional(),
1092
- serviceIds: z5.array(z5.string().max(128)).max(1e4).optional(),
1093
- groupOrder: z5.array(z5.string().max(200)).max(100).optional()
1249
+ z6.object({
1250
+ id: z6.string().max(128),
1251
+ name: z6.string().min(1).max(200).optional(),
1252
+ description: z6.string().max(1e4).optional(),
1253
+ orgId: z6.string().max(128).nullable().optional(),
1254
+ serviceIds: z6.array(z6.string().max(128)).max(1e4).optional(),
1255
+ groupOrder: z6.array(z6.string().max(200)).max(100).optional()
1094
1256
  })
1095
1257
  ).mutation(async ({ input }) => {
1096
1258
  const project = await projectStore.update(input);
1097
1259
  if (!project) {
1098
- throw new TRPCError3({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1260
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1099
1261
  }
1100
1262
  await auditService.log({ userId: "local", action: "update", entityType: "project", entityId: input.id });
1101
1263
  return project;
1102
1264
  }),
1103
- delete: protectedProcedure.input(z5.object({ id: z5.string().max(128), orgId: z5.string().max(128).nullable().optional() })).mutation(async ({ input }) => {
1265
+ delete: protectedProcedure.input(z6.object({ id: z6.string().max(128), orgId: z6.string().max(128).nullable().optional() })).mutation(async ({ input }) => {
1104
1266
  const deleted = await projectStore.delete(input);
1105
1267
  if (!deleted) {
1106
- throw new TRPCError3({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1268
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1107
1269
  }
1108
1270
  await auditService.log({ userId: "local", action: "delete", entityType: "project", entityId: input.id });
1109
1271
  return { success: true };
1110
1272
  }),
1111
- addService: protectedProcedure.input(z5.object({
1112
- projectId: z5.string().max(128),
1113
- orgId: z5.string().max(128).nullable().optional(),
1114
- serviceId: z5.string().max(128)
1273
+ addService: protectedProcedure.input(z6.object({
1274
+ projectId: z6.string().max(128),
1275
+ orgId: z6.string().max(128).nullable().optional(),
1276
+ serviceId: z6.string().max(128)
1115
1277
  })).mutation(async ({ input }) => {
1116
1278
  const project = await attachServiceToProject({ id: input.projectId, orgId: input.orgId }, input.serviceId);
1117
1279
  if (!project) {
1118
- throw new TRPCError3({ code: "NOT_FOUND", message: `Project ${input.projectId} not found` });
1280
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Project ${input.projectId} not found` });
1119
1281
  }
1120
1282
  await auditService.log({
1121
1283
  userId: "local",
@@ -1126,17 +1288,17 @@ var projectRouter = router({
1126
1288
  });
1127
1289
  return project;
1128
1290
  }),
1129
- removeService: protectedProcedure.input(z5.object({
1130
- projectId: z5.string().max(128),
1131
- orgId: z5.string().max(128).nullable().optional(),
1132
- serviceId: z5.string().max(128)
1291
+ removeService: protectedProcedure.input(z6.object({
1292
+ projectId: z6.string().max(128),
1293
+ orgId: z6.string().max(128).nullable().optional(),
1294
+ serviceId: z6.string().max(128)
1133
1295
  })).mutation(async ({ input }) => {
1134
1296
  const project = await projectStore.removeService(
1135
1297
  { id: input.projectId, orgId: input.orgId },
1136
1298
  input.serviceId
1137
1299
  );
1138
1300
  if (!project) {
1139
- throw new TRPCError3({ code: "NOT_FOUND", message: `Project ${input.projectId} not found` });
1301
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Project ${input.projectId} not found` });
1140
1302
  }
1141
1303
  await auditService.log({
1142
1304
  userId: "local",
@@ -1147,21 +1309,21 @@ var projectRouter = router({
1147
1309
  });
1148
1310
  return project;
1149
1311
  }),
1150
- setActiveEnvironment: protectedProcedure.input(z5.object({
1151
- projectId: z5.string().max(128),
1152
- orgId: z5.string().max(128).nullable().optional(),
1153
- environmentId: z5.string().max(128)
1312
+ setActiveEnvironment: protectedProcedure.input(z6.object({
1313
+ projectId: z6.string().max(128),
1314
+ orgId: z6.string().max(128).nullable().optional(),
1315
+ environmentId: z6.string().max(128)
1154
1316
  })).mutation(async ({ input }) => {
1155
1317
  const project = await projectStore.get({ id: input.projectId, orgId: input.orgId });
1156
1318
  if (!project) {
1157
- throw new TRPCError3({ code: "NOT_FOUND", message: `Project ${input.projectId} not found` });
1319
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Project ${input.projectId} not found` });
1158
1320
  }
1159
1321
  const environment = await environmentStore.get(input.environmentId);
1160
1322
  if (!environment) {
1161
- throw new TRPCError3({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
1323
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
1162
1324
  }
1163
1325
  if (environment.projectId !== input.projectId) {
1164
- throw new TRPCError3({ code: "FORBIDDEN", message: "Environment does not belong to this project" });
1326
+ throw new TRPCError4({ code: "FORBIDDEN", message: "Environment does not belong to this project" });
1165
1327
  }
1166
1328
  const runningServices = [];
1167
1329
  for (const serviceId of project.serviceIds) {
@@ -1186,7 +1348,7 @@ var projectRouter = router({
1186
1348
  input.environmentId
1187
1349
  );
1188
1350
  if (!updated) {
1189
- throw new TRPCError3({ code: "INTERNAL_SERVER_ERROR", message: "Failed to set active environment" });
1351
+ throw new TRPCError4({ code: "INTERNAL_SERVER_ERROR", message: "Failed to set active environment" });
1190
1352
  }
1191
1353
  for (const serviceId of project.serviceIds) {
1192
1354
  const service2 = await serviceStore.get(serviceId);
@@ -1235,7 +1397,7 @@ var projectRouter = router({
1235
1397
  * système s'en sert, pour montrer les services du projet ouvert plutôt que
1236
1398
  * ceux de toute la machine.
1237
1399
  */
1238
- setCurrent: protectedProcedure.input(z5.object({ id: z5.string().max(128), orgId: z5.string().max(128).nullable().default(null) }).nullable()).mutation(({ input }) => {
1400
+ setCurrent: protectedProcedure.input(z6.object({ id: z6.string().max(128), orgId: z6.string().max(128).nullable().default(null) }).nullable()).mutation(({ input }) => {
1239
1401
  setCurrentProject(input ? { id: input.id, orgId: input.orgId } : null);
1240
1402
  return { ok: true };
1241
1403
  }),
@@ -1251,13 +1413,13 @@ var projectRouter = router({
1251
1413
  * des secrets déchiffrés : elles servent à détecter la référence, et
1252
1414
  * s'arrêtent là.
1253
1415
  */
1254
- graph: protectedProcedure.input(z5.object({
1255
- id: z5.string().min(1).max(128),
1256
- orgId: z5.string().max(128).nullable().optional()
1416
+ graph: protectedProcedure.input(z6.object({
1417
+ id: z6.string().min(1).max(128),
1418
+ orgId: z6.string().max(128).nullable().optional()
1257
1419
  })).query(async ({ ctx, input }) => {
1258
1420
  const project = await projectStore.get(input);
1259
1421
  if (!project) {
1260
- throw new TRPCError3({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1422
+ throw new TRPCError4({ code: "NOT_FOUND", message: `Project ${input.id} not found` });
1261
1423
  }
1262
1424
  await assertReadable(project.orgId);
1263
1425
  const allowed = getAllowedServiceIds(ctx);
@@ -1298,14 +1460,14 @@ var projectRouter = router({
1298
1460
  * un outil IA lancé hors de Runeya (`runeya mcp`), qui sait seulement dans
1299
1461
  * quel dossier il tourne.
1300
1462
  */
1301
- containing: protectedProcedure.input(z5.object({ path: z5.string().min(1).max(4096) })).query(async ({ input }) => {
1463
+ containing: protectedProcedure.input(z6.object({ path: z6.string().min(1).max(4096) })).query(async ({ input }) => {
1302
1464
  const ref = projectContaining(await localProjectPaths(), input.path);
1303
1465
  const project = ref ? await projectStore.get(ref).catch(() => null) : null;
1304
1466
  return project ? { projectId: project.id, orgId: project.orgId ?? null, name: project.name } : null;
1305
1467
  }),
1306
- getLocalPath: protectedProcedure.input(z5.object({
1307
- id: z5.string().min(1).max(128),
1308
- orgId: z5.string().max(128).nullable().optional()
1468
+ getLocalPath: protectedProcedure.input(z6.object({
1469
+ id: z6.string().min(1).max(128),
1470
+ orgId: z6.string().max(128).nullable().optional()
1309
1471
  })).query(async ({ input }) => {
1310
1472
  return { path: await projectPathStore.get(input) };
1311
1473
  }),
@@ -1317,34 +1479,34 @@ var projectRouter = router({
1317
1479
  * makes services run against the wrong code.
1318
1480
  */
1319
1481
  /** Ajouter à la liste le projet local déjà présent dans un dossier. */
1320
- importLocal: protectedProcedure.input(z5.object({ path: z5.string().min(1).max(4096).refine(isAbsolute2, "Chemin absolu attendu") })).mutation(async ({ input }) => {
1482
+ importLocal: protectedProcedure.input(z6.object({ path: z6.string().min(1).max(4096).refine(isAbsolute2, "Chemin absolu attendu") })).mutation(async ({ input }) => {
1321
1483
  try {
1322
1484
  const project = await projectStore.importLocal(input.path);
1323
1485
  await auditService.log({ userId: "local", action: "update", entityType: "project", entityId: project.id, metadata: { importedFrom: input.path } });
1324
1486
  return project;
1325
1487
  } catch (err) {
1326
1488
  if (err instanceof LocalProjectRefusedError) {
1327
- throw new TRPCError3({ code: "CONFLICT", message: err.code, cause: err });
1489
+ throw new TRPCError4({ code: "CONFLICT", message: err.code, cause: err });
1328
1490
  }
1329
1491
  throw err;
1330
1492
  }
1331
1493
  }),
1332
- setLocalPath: protectedProcedure.input(z5.object({
1333
- id: z5.string().min(1).max(128),
1334
- orgId: z5.string().max(128).nullable().optional(),
1335
- path: z5.string().min(1).max(4096)
1494
+ setLocalPath: protectedProcedure.input(z6.object({
1495
+ id: z6.string().min(1).max(128),
1496
+ orgId: z6.string().max(128).nullable().optional(),
1497
+ path: z6.string().min(1).max(4096)
1336
1498
  })).mutation(async ({ input }) => {
1337
1499
  const project = await projectStore.get(input);
1338
- if (!project) throw new TRPCError3({ code: "NOT_FOUND", message: "Projet introuvable" });
1500
+ if (!project) throw new TRPCError4({ code: "NOT_FOUND", message: "Projet introuvable" });
1339
1501
  if (await holdsRuneyaProject(input.path)) {
1340
- throw new TRPCError3({
1502
+ throw new TRPCError4({
1341
1503
  code: "CONFLICT",
1342
1504
  message: "Ce r\xE9pertoire contient d\xE9j\xE0 un projet Runeya"
1343
1505
  });
1344
1506
  }
1345
1507
  const taken = await projectStore.projectAtPath(input.path, project);
1346
1508
  if (taken) {
1347
- throw new TRPCError3({
1509
+ throw new TRPCError4({
1348
1510
  code: "CONFLICT",
1349
1511
  message: "Un autre projet est d\xE9j\xE0 rattach\xE9 \xE0 ce r\xE9pertoire"
1350
1512
  });
@@ -1413,8 +1575,8 @@ var projectRouter = router({
1413
1575
  });
1414
1576
 
1415
1577
  // ../server/src/trpc/routers/agent.ts
1416
- import { z as z6 } from "zod";
1417
- import { TRPCError as TRPCError4 } from "@trpc/server";
1578
+ import { z as z7 } from "zod";
1579
+ import { TRPCError as TRPCError5 } from "@trpc/server";
1418
1580
  var SUBSCRIPTION_QUEUE_MAX = LOG_BUFFER_SIZE;
1419
1581
  var agentRouter = router({
1420
1582
  /** List all registered agents with their connection status */
@@ -1422,10 +1584,10 @@ var agentRouter = router({
1422
1584
  return agentManager.listAgents();
1423
1585
  }),
1424
1586
  /** Get a single agent's config and status */
1425
- get: protectedProcedure.input(z6.object({ id: z6.string().max(128) })).query(({ input }) => {
1587
+ get: protectedProcedure.input(z7.object({ id: z7.string().max(128) })).query(({ input }) => {
1426
1588
  const agent = agentManager.getAgent(input.id);
1427
1589
  if (!agent) {
1428
- throw new TRPCError4({ code: "NOT_FOUND", message: `Agent ${input.id} not found` });
1590
+ throw new TRPCError5({ code: "NOT_FOUND", message: `Agent ${input.id} not found` });
1429
1591
  }
1430
1592
  return {
1431
1593
  config: { ...agent.config, passphrase: "***" },
@@ -1434,10 +1596,10 @@ var agentRouter = router({
1434
1596
  }),
1435
1597
  /** Test connectivity to an agent given url + passphrase */
1436
1598
  testConnection: protectedProcedure.input(
1437
- z6.object({
1438
- url: z6.string().url().max(2048),
1439
- passphrase: z6.string().min(1).max(1024).optional(),
1440
- agentId: z6.string().max(128).optional()
1599
+ z7.object({
1600
+ url: z7.string().url().max(2048),
1601
+ passphrase: z7.string().min(1).max(1024).optional(),
1602
+ agentId: z7.string().max(128).optional()
1441
1603
  })
1442
1604
  ).mutation(async ({ input }) => {
1443
1605
  let passphrase = input.passphrase;
@@ -1445,13 +1607,13 @@ var agentRouter = router({
1445
1607
  if (!passphrase && input.agentId) {
1446
1608
  const agent = agentManager.getAgentConfig(input.agentId);
1447
1609
  if (!agent) {
1448
- throw new TRPCError4({ code: "NOT_FOUND", message: "Agent not found" });
1610
+ throw new TRPCError5({ code: "NOT_FOUND", message: "Agent not found" });
1449
1611
  }
1450
1612
  passphrase = agent.passphrase;
1451
1613
  targetUrl = agent.url;
1452
1614
  }
1453
1615
  if (!passphrase) {
1454
- throw new TRPCError4({ code: "BAD_REQUEST", message: "Passphrase is required" });
1616
+ throw new TRPCError5({ code: "BAD_REQUEST", message: "Passphrase is required" });
1455
1617
  }
1456
1618
  const url = new URL("/api/trpc/health.check", targetUrl);
1457
1619
  try {
@@ -1474,13 +1636,13 @@ var agentRouter = router({
1474
1636
  }),
1475
1637
  /** Register a new agent */
1476
1638
  register: protectedProcedure.input(
1477
- z6.object({
1478
- name: z6.string().min(1).max(100),
1479
- url: z6.string().url().max(2048),
1480
- passphrase: z6.string().min(1).max(1024),
1639
+ z7.object({
1640
+ name: z7.string().min(1).max(100),
1641
+ url: z7.string().url().max(2048),
1642
+ passphrase: z7.string().min(1).max(1024),
1481
1643
  // À quelle organisation rattacher l'agent. Absent = la machine, ce que
1482
1644
  // font l'agent local et tout client antérieur à ce champ.
1483
- orgId: z6.string().min(1).max(128).nullable().optional()
1645
+ orgId: z7.string().min(1).max(128).nullable().optional()
1484
1646
  })
1485
1647
  ).mutation(async ({ input }) => {
1486
1648
  const config = await agentManager.register(
@@ -1493,13 +1655,13 @@ var agentRouter = router({
1493
1655
  }),
1494
1656
  /** Update an existing agent */
1495
1657
  update: protectedProcedure.input(
1496
- z6.object({
1497
- id: z6.string().max(128),
1498
- name: z6.string().min(1).max(100).optional(),
1499
- url: z6.string().url().max(2048).optional(),
1500
- passphrase: z6.string().min(1).max(1024).optional(),
1501
- passthroughEnv: z6.array(
1502
- z6.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).max(256)
1658
+ z7.object({
1659
+ id: z7.string().max(128),
1660
+ name: z7.string().min(1).max(100).optional(),
1661
+ url: z7.string().url().max(2048).optional(),
1662
+ passphrase: z7.string().min(1).max(1024).optional(),
1663
+ passthroughEnv: z7.array(
1664
+ z7.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).max(256)
1503
1665
  ).max(100).optional()
1504
1666
  })
1505
1667
  ).mutation(async ({ input }) => {
@@ -1510,17 +1672,17 @@ var agentRouter = router({
1510
1672
  } catch (err) {
1511
1673
  if (err instanceof Error) {
1512
1674
  if (err.message.includes("not found")) {
1513
- throw new TRPCError4({ code: "NOT_FOUND", message: err.message });
1675
+ throw new TRPCError5({ code: "NOT_FOUND", message: err.message });
1514
1676
  }
1515
1677
  if (err.message.includes("Cannot modify")) {
1516
- throw new TRPCError4({ code: "FORBIDDEN", message: err.message });
1678
+ throw new TRPCError5({ code: "FORBIDDEN", message: err.message });
1517
1679
  }
1518
1680
  }
1519
1681
  throw err;
1520
1682
  }
1521
1683
  }),
1522
1684
  /** Get resolved passthrough env values from an agent */
1523
- getPassthroughEnv: protectedProcedure.input(z6.object({ id: z6.string().max(128) })).query(async ({ input }) => {
1685
+ getPassthroughEnv: protectedProcedure.input(z7.object({ id: z7.string().max(128) })).query(async ({ input }) => {
1524
1686
  try {
1525
1687
  return await agentManager.agentQuery(input.id, "config.getPassthroughEnv");
1526
1688
  } catch {
@@ -1528,16 +1690,16 @@ var agentRouter = router({
1528
1690
  }
1529
1691
  }),
1530
1692
  /** Remove a registered agent */
1531
- remove: protectedProcedure.input(z6.object({ id: z6.string().max(128) })).mutation(async ({ input }) => {
1693
+ remove: protectedProcedure.input(z7.object({ id: z7.string().max(128) })).mutation(async ({ input }) => {
1532
1694
  try {
1533
1695
  const removed = await agentManager.remove(input.id);
1534
1696
  if (!removed) {
1535
- throw new TRPCError4({ code: "NOT_FOUND", message: `Agent ${input.id} not found` });
1697
+ throw new TRPCError5({ code: "NOT_FOUND", message: `Agent ${input.id} not found` });
1536
1698
  }
1537
1699
  return { success: true };
1538
1700
  } catch (err) {
1539
1701
  if (err instanceof Error && err.message === "Cannot remove the local agent") {
1540
- throw new TRPCError4({ code: "FORBIDDEN", message: err.message });
1702
+ throw new TRPCError5({ code: "FORBIDDEN", message: err.message });
1541
1703
  }
1542
1704
  throw err;
1543
1705
  }
@@ -1575,16 +1737,16 @@ var agentRouter = router({
1575
1737
  });
1576
1738
 
1577
1739
  // ../server/src/trpc/routers/process.ts
1578
- import { z as z7 } from "zod";
1579
- import { TRPCError as TRPCError6 } from "@trpc/server";
1740
+ import { z as z8 } from "zod";
1741
+ import { TRPCError as TRPCError7 } from "@trpc/server";
1580
1742
 
1581
1743
  // ../server/src/services/process-control.ts
1582
- import { TRPCError as TRPCError5 } from "@trpc/server";
1744
+ import { TRPCError as TRPCError6 } from "@trpc/server";
1583
1745
  async function resolveTarget(processId, fallbackAgentId) {
1584
1746
  const service2 = await serviceStore.get(processId) ?? null;
1585
1747
  const agentId = (service2 ? await resolveEffectiveAgentId(service2) : null) ?? fallbackAgentId ?? null;
1586
1748
  if (!agentId) {
1587
- throw new TRPCError5({ code: "BAD_REQUEST", message: "NO_AGENT_FOR_SERVICE" });
1749
+ throw new TRPCError6({ code: "BAD_REQUEST", message: "NO_AGENT_FOR_SERVICE" });
1588
1750
  }
1589
1751
  return { agentId, service: service2 };
1590
1752
  }
@@ -1599,7 +1761,7 @@ async function callAgent(fn, fallbackMessage) {
1599
1761
  try {
1600
1762
  return await fn();
1601
1763
  } catch (err) {
1602
- throw new TRPCError5({
1764
+ throw new TRPCError6({
1603
1765
  code: "INTERNAL_SERVER_ERROR",
1604
1766
  message: isAgentUnreachable(err) ? "AGENT_UNREACHABLE" : err?.message ?? fallbackMessage
1605
1767
  });
@@ -1614,7 +1776,7 @@ async function assertEnvironmentComplete(service2) {
1614
1776
  activeEnvironmentId: project.activeEnvironmentId
1615
1777
  });
1616
1778
  if (missing.length === 0) return;
1617
- throw new TRPCError5({
1779
+ throw new TRPCError6({
1618
1780
  code: "PRECONDITION_FAILED",
1619
1781
  message: `Missing environment variables: ${missing.map((m) => m.key).join(", ")}`,
1620
1782
  cause: { missingVariables: missing, environmentId: project.activeEnvironmentId }
@@ -1749,13 +1911,13 @@ async function* forwardLogBatches(agentId, processId) {
1749
1911
  }
1750
1912
  var processRouter = router({
1751
1913
  /** List all processes across all connected agents */
1752
- list: protectedProcedure.meta({ openapi: { method: "GET", path: "/processes", tags: ["processes"], summary: "List all processes", protect: true } }).output(z7.any()).query(() => listAllProcesses()),
1914
+ list: protectedProcedure.meta({ openapi: { method: "GET", path: "/processes", tags: ["processes"], summary: "List all processes", protect: true } }).output(z8.any()).query(() => listAllProcesses()),
1753
1915
  /** Get a single process from a specific agent */
1754
- get: protectedProcedure.meta({ openapi: { method: "GET", path: "/processes/{agentId}/{id}", tags: ["processes"], summary: "Get a process by agent and ID", protect: true } }).input(z7.object({ agentId: z7.string().max(128), id: z7.string().max(128) })).output(z7.any()).query(async ({ input, ctx }) => {
1916
+ get: protectedProcedure.meta({ openapi: { method: "GET", path: "/processes/{agentId}/{id}", tags: ["processes"], summary: "Get a process by agent and ID", protect: true } }).input(z8.object({ agentId: z8.string().max(128), id: z8.string().max(128) })).output(z8.any()).query(async ({ input, ctx }) => {
1755
1917
  requireServiceAction(ctx, input.id, "service:read");
1756
1918
  const status = agentManager.getStatus(input.agentId);
1757
1919
  if (!status) {
1758
- throw new TRPCError6({ code: "NOT_FOUND", message: `Agent ${input.agentId} not found` });
1920
+ throw new TRPCError7({ code: "NOT_FOUND", message: `Agent ${input.agentId} not found` });
1759
1921
  }
1760
1922
  const proc = await agentManager.agentQuery(input.agentId, "process.get", { id: input.id });
1761
1923
  return { ...proc, agentId: input.agentId };
@@ -1765,37 +1927,37 @@ var processRouter = router({
1765
1927
  * (or restarted). This avoids pushing configs for every service at agent boot,
1766
1928
  * which would be wasteful when many services are never started.
1767
1929
  * The deploy call is idempotent — creates the process if missing, updates config if it exists. */
1768
- start: protectedProcedure.meta({ openapi: { method: "POST", path: "/processes/{agentId}/{processId}/start", tags: ["processes"], summary: "Start a process", protect: true } }).input(z7.object({ agentId: z7.string().max(128).optional(), processId: z7.string().max(128) })).output(z7.any()).mutation(async ({ input, ctx }) => {
1930
+ start: protectedProcedure.meta({ openapi: { method: "POST", path: "/processes/{agentId}/{processId}/start", tags: ["processes"], summary: "Start a process", protect: true } }).input(z8.object({ agentId: z8.string().max(128).optional(), processId: z8.string().max(128) })).output(z8.any()).mutation(async ({ input, ctx }) => {
1769
1931
  requireServiceAction(ctx, input.processId, "service:start");
1770
1932
  return startProcess(input.processId, input.agentId);
1771
1933
  }),
1772
1934
  /** Stop a process on an agent */
1773
- stop: protectedProcedure.meta({ openapi: { method: "POST", path: "/processes/{agentId}/{processId}/stop", tags: ["processes"], summary: "Stop a process", protect: true } }).input(z7.object({ agentId: z7.string().max(128), processId: z7.string().max(128) })).output(z7.any()).mutation(async ({ input, ctx }) => {
1935
+ stop: protectedProcedure.meta({ openapi: { method: "POST", path: "/processes/{agentId}/{processId}/stop", tags: ["processes"], summary: "Stop a process", protect: true } }).input(z8.object({ agentId: z8.string().max(128), processId: z8.string().max(128) })).output(z8.any()).mutation(async ({ input, ctx }) => {
1774
1936
  requireServiceAction(ctx, input.processId, "service:stop");
1775
1937
  return stopProcess(input.processId, input.agentId);
1776
1938
  }),
1777
1939
  /** Restart a process on an agent.
1778
1940
  * Sends stop → deploy (latest resolved config) → start so that
1779
1941
  * config/variable changes take effect. Same lazy deploy pattern as start. */
1780
- restart: protectedProcedure.meta({ openapi: { method: "POST", path: "/processes/{agentId}/{processId}/restart", tags: ["processes"], summary: "Restart a process", protect: true } }).input(z7.object({ agentId: z7.string().max(128).optional(), processId: z7.string().max(128) })).output(z7.any()).mutation(async ({ input, ctx }) => {
1942
+ restart: protectedProcedure.meta({ openapi: { method: "POST", path: "/processes/{agentId}/{processId}/restart", tags: ["processes"], summary: "Restart a process", protect: true } }).input(z8.object({ agentId: z8.string().max(128).optional(), processId: z8.string().max(128) })).output(z8.any()).mutation(async ({ input, ctx }) => {
1781
1943
  requireServiceAction(ctx, input.processId, "service:restart");
1782
1944
  return restartProcess(input.processId, input.agentId);
1783
1945
  }),
1784
1946
  /** Get buffered logs for a process from an agent */
1785
- logs: protectedProcedure.meta({ openapi: { method: "GET", path: "/processes/{agentId}/{processId}/logs", tags: ["processes"], summary: "Get buffered logs for a process", protect: true } }).input(z7.object({ agentId: z7.string().max(128), processId: z7.string().max(128) })).output(z7.any()).query(async ({ input, ctx }) => {
1947
+ logs: protectedProcedure.meta({ openapi: { method: "GET", path: "/processes/{agentId}/{processId}/logs", tags: ["processes"], summary: "Get buffered logs for a process", protect: true } }).input(z8.object({ agentId: z8.string().max(128), processId: z8.string().max(128) })).output(z8.any()).query(async ({ input, ctx }) => {
1786
1948
  requireServiceAction(ctx, input.processId, "logs:read");
1787
1949
  return agentManager.agentQuery(input.agentId, "process.logs", { id: input.processId });
1788
1950
  }),
1789
1951
  /** Clear buffered logs for a process on an agent */
1790
- clearLogBuffer: protectedProcedure.input(z7.object({ agentId: z7.string().max(128), processId: z7.string().max(128) })).mutation(async ({ input }) => {
1952
+ clearLogBuffer: protectedProcedure.input(z8.object({ agentId: z8.string().max(128), processId: z8.string().max(128) })).mutation(async ({ input }) => {
1791
1953
  await agentManager.agentMutation(input.agentId, "process.clearLogBuffer", { id: input.processId });
1792
1954
  await auditService.log({ userId: "local", action: "clearLogBuffer", entityType: "process", entityId: input.processId, metadata: { agentId: input.agentId } });
1793
1955
  return { success: true };
1794
1956
  }),
1795
1957
  /** Execute a shortcut command on an agent, streaming output into the process log */
1796
- executeShortcut: protectedProcedure.input(z7.object({
1797
- agentId: z7.string().max(128),
1798
- processId: z7.string().max(128),
1958
+ executeShortcut: protectedProcedure.input(z8.object({
1959
+ agentId: z8.string().max(128),
1960
+ processId: z8.string().max(128),
1799
1961
  shortcut: ServiceShortcutSchema
1800
1962
  })).mutation(async ({ input }) => {
1801
1963
  const service2 = await serviceStore.get(input.processId);
@@ -1823,12 +1985,12 @@ var processRouter = router({
1823
1985
  return result;
1824
1986
  }),
1825
1987
  /** Execute an ad-hoc command on an agent, streaming output into the process log */
1826
- executeAdHocCommand: protectedProcedure.input(z7.object({
1827
- agentId: z7.string().max(128),
1828
- processId: z7.string().max(128),
1829
- command: z7.string().min(1).max(4096),
1830
- cwd: z7.string().max(4096).optional(),
1831
- commandId: z7.string().max(128).optional()
1988
+ executeAdHocCommand: protectedProcedure.input(z8.object({
1989
+ agentId: z8.string().max(128),
1990
+ processId: z8.string().max(128),
1991
+ command: z8.string().min(1).max(4096),
1992
+ cwd: z8.string().max(4096).optional(),
1993
+ commandId: z8.string().max(128).optional()
1832
1994
  })).mutation(async ({ input }) => {
1833
1995
  const service2 = await serviceStore.get(input.processId);
1834
1996
  if (service2) {
@@ -1862,25 +2024,25 @@ var processRouter = router({
1862
2024
  return result;
1863
2025
  }),
1864
2026
  /** Cancel a running shortcut command on an agent */
1865
- cancelShortcut: protectedProcedure.input(z7.object({
1866
- agentId: z7.string().max(128),
1867
- processId: z7.string().max(128),
1868
- shortcutId: z7.string().max(128)
2027
+ cancelShortcut: protectedProcedure.input(z8.object({
2028
+ agentId: z8.string().max(128),
2029
+ processId: z8.string().max(128),
2030
+ shortcutId: z8.string().max(128)
1869
2031
  })).mutation(async ({ input }) => {
1870
2032
  await agentManager.agentMutation(input.agentId, "process.cancelShortcut", { id: input.processId, shortcutId: input.shortcutId });
1871
2033
  return { success: true };
1872
2034
  }),
1873
2035
  /** Cancel a running ad-hoc command on an agent */
1874
- cancelAdHocCommand: protectedProcedure.input(z7.object({
1875
- agentId: z7.string().max(128),
1876
- processId: z7.string().max(128),
1877
- commandId: z7.string().max(128).optional()
2036
+ cancelAdHocCommand: protectedProcedure.input(z8.object({
2037
+ agentId: z8.string().max(128),
2038
+ processId: z8.string().max(128),
2039
+ commandId: z8.string().max(128).optional()
1878
2040
  })).mutation(async ({ input }) => {
1879
2041
  await agentManager.agentMutation(input.agentId, "process.cancelAdHocCommand", { id: input.processId, commandId: input.commandId });
1880
2042
  return { success: true };
1881
2043
  }),
1882
2044
  /** Get current metrics for a process from an agent */
1883
- metrics: protectedProcedure.input(z7.object({ agentId: z7.string().max(128), processId: z7.string().max(128) })).query(async ({ input }) => {
2045
+ metrics: protectedProcedure.input(z8.object({ agentId: z8.string().max(128), processId: z8.string().max(128) })).query(async ({ input }) => {
1884
2046
  return agentManager.agentQuery(input.agentId, "process.metrics", { id: input.processId });
1885
2047
  }),
1886
2048
  /**
@@ -1888,7 +2050,7 @@ var processRouter = router({
1888
2050
  * Forwards batched events from the AgentWSBridge in real-time.
1889
2051
  * Historical logs are fetched separately via process.logs query.
1890
2052
  */
1891
- onLog: protectedProcedure.input(z7.object({ agentId: z7.string().max(128), processId: z7.string().max(128) })).subscription(async function* ({ input, ctx }) {
2053
+ onLog: protectedProcedure.input(z8.object({ agentId: z8.string().max(128), processId: z8.string().max(128) })).subscription(async function* ({ input, ctx }) {
1892
2054
  requireServiceAction(ctx, input.processId, "logs:read");
1893
2055
  yield* forwardLogBatches(input.agentId, input.processId);
1894
2056
  }),
@@ -1897,9 +2059,9 @@ var processRouter = router({
1897
2059
  * Input is optional — omit agentId/processId for global monitoring (dashboard).
1898
2060
  * Forwards events from the AgentWSBridge in real-time.
1899
2061
  */
1900
- onStatus: protectedProcedure.input(z7.object({
1901
- agentId: z7.string().max(128).optional(),
1902
- processId: z7.string().max(128).optional()
2062
+ onStatus: protectedProcedure.input(z8.object({
2063
+ agentId: z8.string().max(128).optional(),
2064
+ processId: z8.string().max(128).optional()
1903
2065
  }).optional()).subscription(async function* ({ input, ctx }) {
1904
2066
  const allowedIds = getAllowedServiceIds(ctx);
1905
2067
  if (input?.processId) requireServiceAction(ctx, input.processId, "service:status");
@@ -1927,9 +2089,9 @@ var processRouter = router({
1927
2089
  });
1928
2090
  }),
1929
2091
  /** Subscribe to real-time metrics for a process. */
1930
- onMetrics: protectedProcedure.input(z7.object({
1931
- agentId: z7.string().max(128).optional(),
1932
- processId: z7.string().max(128).optional()
2092
+ onMetrics: protectedProcedure.input(z8.object({
2093
+ agentId: z8.string().max(128).optional(),
2094
+ processId: z8.string().max(128).optional()
1933
2095
  }).optional()).subscription(async function* ({ input, ctx }) {
1934
2096
  const allowedIds = getAllowedServiceIds(ctx);
1935
2097
  if (input?.processId) requireServiceAction(ctx, input.processId, "service:status");
@@ -1941,9 +2103,9 @@ var processRouter = router({
1941
2103
  });
1942
2104
  }),
1943
2105
  /** Subscribe to real-time health status changes. */
1944
- onHealth: protectedProcedure.input(z7.object({
1945
- agentId: z7.string().max(128).optional(),
1946
- processId: z7.string().max(128).optional()
2106
+ onHealth: protectedProcedure.input(z8.object({
2107
+ agentId: z8.string().max(128).optional(),
2108
+ processId: z8.string().max(128).optional()
1947
2109
  }).optional()).subscription(async function* ({ input, ctx }) {
1948
2110
  const allowedIds = getAllowedServiceIds(ctx);
1949
2111
  if (input?.processId) requireServiceAction(ctx, input.processId, "service:healthcheck");
@@ -1957,21 +2119,21 @@ var processRouter = router({
1957
2119
  });
1958
2120
 
1959
2121
  // ../server/src/trpc/routers/audit.ts
1960
- import { z as z8 } from "zod";
2122
+ import { z as z9 } from "zod";
1961
2123
  var auditRouter = router({
1962
- list: protectedProcedure.input(z8.object({
1963
- action: z8.string().max(50).optional(),
1964
- entityType: z8.string().max(50).optional(),
1965
- entityId: z8.string().max(100).optional(),
1966
- limit: z8.number().int().positive().max(100).default(50),
1967
- offset: z8.number().int().nonnegative().default(0)
2124
+ list: protectedProcedure.input(z9.object({
2125
+ action: z9.string().max(50).optional(),
2126
+ entityType: z9.string().max(50).optional(),
2127
+ entityId: z9.string().max(100).optional(),
2128
+ limit: z9.number().int().positive().max(100).default(50),
2129
+ offset: z9.number().int().nonnegative().default(0)
1968
2130
  }).optional()).query(async ({ input }) => {
1969
2131
  return auditService.list(input ?? {});
1970
2132
  })
1971
2133
  });
1972
2134
 
1973
2135
  // ../server/src/trpc/routers/setup.ts
1974
- import { z as z9 } from "zod";
2136
+ import { z as z10 } from "zod";
1975
2137
  var setupRouter = router({
1976
2138
  /**
1977
2139
  * Check if encryption key is required (project initialized but no key).
@@ -2068,9 +2230,9 @@ var setupRouter = router({
2068
2230
  * une validation de la clé à adopter rendait le parcours impossible : vert
2069
2231
  * quand le geste est inutile, rouge sinon.
2070
2232
  */
2071
- checkOrgKeyLocal: protectedProcedure.input(z9.object({
2072
- orgId: z9.string().min(1).max(128),
2073
- keyHex: z9.string().length(64).regex(/^[0-9a-f]+$/i, "Invalid hex format")
2233
+ checkOrgKeyLocal: protectedProcedure.input(z10.object({
2234
+ orgId: z10.string().min(1).max(128),
2235
+ keyHex: z10.string().length(64).regex(/^[0-9a-f]+$/i, "Invalid hex format")
2074
2236
  })).query(async ({ input }) => {
2075
2237
  const canary = await readVerifyFile(orgVaultRoot(input.orgId));
2076
2238
  const locked = isVaultLocked(input.orgId);
@@ -2087,8 +2249,8 @@ var setupRouter = router({
2087
2249
  * Spawns the local agent if in local-simple mode.
2088
2250
  */
2089
2251
  submitEncryptionKey: publicProcedure.input(
2090
- z9.object({
2091
- keyHex: z9.string().length(64).regex(/^[0-9a-f]+$/i, "Invalid hex format")
2252
+ z10.object({
2253
+ keyHex: z10.string().length(64).regex(/^[0-9a-f]+$/i, "Invalid hex format")
2092
2254
  })
2093
2255
  ).mutation(async ({ input }) => {
2094
2256
  try {
@@ -2106,8 +2268,8 @@ var setupRouter = router({
2106
2268
 
2107
2269
  // ../server/src/trpc/routers/environment.ts
2108
2270
  import { randomUUID } from "crypto";
2109
- import { z as z10 } from "zod";
2110
- import { TRPCError as TRPCError7 } from "@trpc/server";
2271
+ import { z as z11 } from "zod";
2272
+ import { TRPCError as TRPCError8 } from "@trpc/server";
2111
2273
 
2112
2274
  // ../server/src/services/ai-variable-write.ts
2113
2275
  var AiVariableWriteError = class extends Error {
@@ -2186,29 +2348,29 @@ async function builtinsForEnvironment(environment) {
2186
2348
  return own ? values : Object.fromEntries(Object.entries(values).filter(([name]) => name.startsWith("services.")));
2187
2349
  }
2188
2350
  var environmentRouter = router({
2189
- list: protectedProcedure.input(z10.object({
2190
- projectId: z10.string().max(128),
2191
- orgId: z10.string().max(128).nullable().optional()
2351
+ list: protectedProcedure.input(z11.object({
2352
+ projectId: z11.string().max(128),
2353
+ orgId: z11.string().max(128).nullable().optional()
2192
2354
  })).query(async ({ input }) => {
2193
2355
  return await environmentStore.list(input.projectId, input.orgId);
2194
2356
  }),
2195
- get: protectedProcedure.input(z10.object({ id: z10.string().max(128) })).query(async ({ input }) => {
2357
+ get: protectedProcedure.input(z11.object({ id: z11.string().max(128) })).query(async ({ input }) => {
2196
2358
  const env2 = await environmentStore.get(input.id);
2197
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.id} not found` });
2359
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.id} not found` });
2198
2360
  return env2;
2199
2361
  }),
2200
- listByScope: protectedProcedure.input(z10.object({
2201
- projectId: z10.string().max(128),
2202
- orgId: z10.string().max(128).nullable().optional(),
2203
- scope: z10.enum(["global", "service"])
2362
+ listByScope: protectedProcedure.input(z11.object({
2363
+ projectId: z11.string().max(128),
2364
+ orgId: z11.string().max(128).nullable().optional(),
2365
+ scope: z11.enum(["global", "service"])
2204
2366
  })).query(async ({ input }) => {
2205
2367
  return await environmentStore.listByScope(input.projectId, input.scope, input.orgId);
2206
2368
  }),
2207
- findServiceEnvironment: protectedProcedure.input(z10.object({ serviceId: z10.string().max(128), globalEnvId: z10.string().max(128) })).query(async ({ input }) => {
2369
+ findServiceEnvironment: protectedProcedure.input(z11.object({ serviceId: z11.string().max(128), globalEnvId: z11.string().max(128) })).query(async ({ input }) => {
2208
2370
  return await environmentStore.findServiceEnvironment(input.serviceId, input.globalEnvId);
2209
2371
  }),
2210
2372
  create: protectedProcedure.input(CreateEnvironmentSchema.extend({
2211
- orgId: z10.string().max(128).nullable().optional()
2373
+ orgId: z11.string().max(128).nullable().optional()
2212
2374
  })).mutation(async ({ input }) => {
2213
2375
  const { orgId, ...environment } = input;
2214
2376
  const target = { id: input.projectId, orgId };
@@ -2244,9 +2406,9 @@ var environmentRouter = router({
2244
2406
  }),
2245
2407
  update: protectedProcedure.input(UpdateEnvironmentSchema).mutation(async ({ input }) => {
2246
2408
  const existing = await environmentStore.get(input.id);
2247
- if (!existing) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.id} not found` });
2409
+ if (!existing) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.id} not found` });
2248
2410
  const env2 = await environmentStore.update(input);
2249
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.id} not found` });
2411
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.id} not found` });
2250
2412
  if (env2.scope === "global" && input.name && input.name !== existing.name) {
2251
2413
  const project = await projectStore.get(environmentStore.projectRefOf(env2) ?? env2.projectId);
2252
2414
  if (project) {
@@ -2260,24 +2422,24 @@ var environmentRouter = router({
2260
2422
  }
2261
2423
  return env2;
2262
2424
  }),
2263
- delete: protectedProcedure.input(z10.object({ id: z10.string().max(128) })).mutation(async ({ input }) => {
2425
+ delete: protectedProcedure.input(z11.object({ id: z11.string().max(128) })).mutation(async ({ input }) => {
2264
2426
  const env2 = await environmentStore.get(input.id);
2265
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.id} not found` });
2427
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.id} not found` });
2266
2428
  if (env2.immutable) {
2267
- throw new TRPCError7({ code: "FORBIDDEN", message: "Cannot delete immutable environment" });
2429
+ throw new TRPCError8({ code: "FORBIDDEN", message: "Cannot delete immutable environment" });
2268
2430
  }
2269
2431
  if (env2.scope === "global") {
2270
2432
  await environmentStore.deleteByActivateOn(input.id);
2271
2433
  }
2272
2434
  const deleted = await environmentStore.delete(input.id);
2273
- if (!deleted) throw new TRPCError7({ code: "INTERNAL_SERVER_ERROR", message: "Failed to delete environment" });
2435
+ if (!deleted) throw new TRPCError8({ code: "INTERNAL_SERVER_ERROR", message: "Failed to delete environment" });
2274
2436
  await projectStore.removeEnvironment(environmentStore.projectRefOf(env2) ?? env2.projectId, input.id);
2275
2437
  return { success: true };
2276
2438
  }),
2277
- resolve: protectedProcedure.input(z10.object({ environmentId: z10.string().max(128) })).query(async ({ input, ctx }) => {
2439
+ resolve: protectedProcedure.input(z11.object({ environmentId: z11.string().max(128) })).query(async ({ input, ctx }) => {
2278
2440
  const { includeSecrets } = requireEnvAction(ctx, input.environmentId, "env:read");
2279
2441
  const env2 = await environmentStore.get(input.environmentId);
2280
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2442
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2281
2443
  const resolved = await environmentResolver.resolveEnvironmentWithSources(input.environmentId);
2282
2444
  if (!includeSecrets) {
2283
2445
  const sanitized = { ...resolved };
@@ -2293,10 +2455,10 @@ var environmentRouter = router({
2293
2455
  }
2294
2456
  return resolved;
2295
2457
  }),
2296
- resolveFlat: protectedProcedure.meta({ openapi: { method: "GET", path: "/environments/{environmentId}/resolve-flat", tags: ["environments"], summary: "Resolve environment variables as a flat key-value map", protect: true } }).input(z10.object({ environmentId: z10.string().max(128) })).output(z10.record(z10.string(), z10.string())).query(async ({ input, ctx }) => {
2458
+ resolveFlat: protectedProcedure.meta({ openapi: { method: "GET", path: "/environments/{environmentId}/resolve-flat", tags: ["environments"], summary: "Resolve environment variables as a flat key-value map", protect: true } }).input(z11.object({ environmentId: z11.string().max(128) })).output(z11.record(z11.string(), z11.string())).query(async ({ input, ctx }) => {
2297
2459
  const { includeSecrets } = requireEnvAction(ctx, input.environmentId, "env:read");
2298
2460
  const env2 = await environmentStore.get(input.environmentId);
2299
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2461
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2300
2462
  const { env: resolved, envSecrets } = await environmentResolver.resolveEnvironment(input.environmentId);
2301
2463
  const result = {};
2302
2464
  for (const [key, value] of Object.entries(resolved)) {
@@ -2318,10 +2480,10 @@ var environmentRouter = router({
2318
2480
  * motif. C'est ce que l'assistant de complétion affiche, et il n'a pas
2319
2481
  * besoin de connaître ce qui est déjà rempli ailleurs.
2320
2482
  */
2321
- missingVariables: protectedProcedure.input(z10.object({ environmentId: z10.string().max(128) })).query(async ({ input, ctx }) => {
2483
+ missingVariables: protectedProcedure.input(z11.object({ environmentId: z11.string().max(128) })).query(async ({ input, ctx }) => {
2322
2484
  requireEnvAction(ctx, input.environmentId, "env:read");
2323
2485
  const env2 = await environmentStore.get(input.environmentId);
2324
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2486
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2325
2487
  const missing = await environmentResolver.findMissingForActiveEnvironment(input.environmentId);
2326
2488
  return missing.filter((item) => canEnvAction(ctx, item.environmentId, "env:read"));
2327
2489
  }),
@@ -2340,17 +2502,17 @@ var environmentRouter = router({
2340
2502
  * poste, en recopiant depuis la définition la forme (`pre`, `post`) et le
2341
2503
  * caractère secret que la surcharge ne porte pas d'elle-même.
2342
2504
  */
2343
- fillVariable: protectedProcedure.input(z10.object({
2344
- environmentId: z10.string().max(128),
2345
- variableId: z10.string().max(128),
2346
- value: z10.string().max(8192),
2505
+ fillVariable: protectedProcedure.input(z11.object({
2506
+ environmentId: z11.string().max(128),
2507
+ variableId: z11.string().max(128),
2508
+ value: z11.string().max(8192),
2347
2509
  reason: MissingVariableReasonSchema
2348
2510
  })).mutation(async ({ input, ctx }) => {
2349
2511
  requireEnvAction(ctx, input.environmentId, "env:write");
2350
2512
  const env2 = await environmentStore.get(input.environmentId);
2351
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2513
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2352
2514
  const variable = env2.variables[input.variableId];
2353
- if (!variable) throw new TRPCError7({ code: "NOT_FOUND", message: `Variable ${input.variableId} not found` });
2515
+ if (!variable) throw new TRPCError8({ code: "NOT_FOUND", message: `Variable ${input.variableId} not found` });
2354
2516
  const slot = variable.value;
2355
2517
  if (input.reason === "overrideOnly") {
2356
2518
  await environmentOverridesStore.setOverride(input.variableId, {
@@ -2362,11 +2524,11 @@ var environmentRouter = router({
2362
2524
  ...variable,
2363
2525
  value: { ...slot, value: input.value }
2364
2526
  });
2365
- if (!result) throw new TRPCError7({ code: "INTERNAL_SERVER_ERROR", message: "Failed to fill variable" });
2527
+ if (!result) throw new TRPCError8({ code: "INTERNAL_SERVER_ERROR", message: "Failed to fill variable" });
2366
2528
  return { success: true };
2367
2529
  }),
2368
- setOverride: protectedProcedure.input(z10.object({
2369
- variableId: z10.string().max(128),
2530
+ setOverride: protectedProcedure.input(z11.object({
2531
+ variableId: z11.string().max(128),
2370
2532
  // Only the value slot: the env var name comes from the variable
2371
2533
  // definition (a `key` sent by an older client is stripped here).
2372
2534
  variable: VariableOverrideSchema
@@ -2374,8 +2536,8 @@ var environmentRouter = router({
2374
2536
  await environmentOverridesStore.setOverride(input.variableId, input.variable);
2375
2537
  return { success: true };
2376
2538
  }),
2377
- removeOverride: protectedProcedure.input(z10.object({
2378
- variableId: z10.string().max(128)
2539
+ removeOverride: protectedProcedure.input(z11.object({
2540
+ variableId: z11.string().max(128)
2379
2541
  })).mutation(async ({ input }) => {
2380
2542
  await environmentOverridesStore.removeOverride(input.variableId);
2381
2543
  return { success: true };
@@ -2383,16 +2545,16 @@ var environmentRouter = router({
2383
2545
  getOverrides: protectedProcedure.query(async () => {
2384
2546
  return await environmentOverridesStore.getAll();
2385
2547
  }),
2386
- upsertVariable: protectedProcedure.meta({ openapi: { method: "PUT", path: "/environments/{environmentId}/variables/{variableId}", tags: ["environments"], summary: "Upsert a variable in an environment", protect: true } }).output(z10.any()).input(z10.object({
2387
- environmentId: z10.string().max(128),
2388
- variableId: z10.string().max(128),
2548
+ upsertVariable: protectedProcedure.meta({ openapi: { method: "PUT", path: "/environments/{environmentId}/variables/{variableId}", tags: ["environments"], summary: "Upsert a variable in an environment", protect: true } }).output(z11.any()).input(z11.object({
2549
+ environmentId: z11.string().max(128),
2550
+ variableId: z11.string().max(128),
2389
2551
  variable: VariableSchema
2390
2552
  })).mutation(async ({ input, ctx }) => {
2391
2553
  requireEnvAction(ctx, input.environmentId, "env:write");
2392
2554
  const env2 = await environmentStore.get(input.environmentId);
2393
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2555
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2394
2556
  const result = await environmentStore.upsertVariable(input.environmentId, input.variableId, input.variable);
2395
- if (!result) throw new TRPCError7({ code: "INTERNAL_SERVER_ERROR", message: "Failed to update variable" });
2557
+ if (!result) throw new TRPCError8({ code: "INTERNAL_SERVER_ERROR", message: "Failed to update variable" });
2396
2558
  return result;
2397
2559
  }),
2398
2560
  /**
@@ -2400,15 +2562,15 @@ var environmentRouter = router({
2400
2562
  * hérite de qui, lequel est actif — sans aucune valeur (`describeEnvironmentsForAi`).
2401
2563
  * Une clé d'API n'y voit que les environnements qu'elle peut lire.
2402
2564
  */
2403
- listForAi: protectedProcedure.input(z10.object({
2404
- projectId: z10.string().max(128),
2405
- orgId: z10.string().max(128).nullable().optional()
2565
+ listForAi: protectedProcedure.input(z11.object({
2566
+ projectId: z11.string().max(128),
2567
+ orgId: z11.string().max(128).nullable().optional()
2406
2568
  })).query(async ({ input, ctx }) => {
2407
2569
  const project = await projectStore.get({
2408
2570
  id: input.projectId,
2409
2571
  ...input.orgId !== void 0 ? { orgId: input.orgId } : {}
2410
2572
  });
2411
- if (!project) throw new TRPCError7({ code: "NOT_FOUND", message: `Project ${input.projectId} not found` });
2573
+ if (!project) throw new TRPCError8({ code: "NOT_FOUND", message: `Project ${input.projectId} not found` });
2412
2574
  const environments = (await environmentStore.list(input.projectId, input.orgId)).filter((env2) => canEnvAction(ctx, env2.id, "env:read"));
2413
2575
  const serviceNames = {};
2414
2576
  for (const serviceId of project.serviceIds) {
@@ -2424,10 +2586,10 @@ var environmentRouter = router({
2424
2586
  * remplies — elles dépendent du service qui les reçoit — mais une référence
2425
2587
  * qui ne correspond à rien est nommée.
2426
2588
  */
2427
- resolveForAi: protectedProcedure.input(z10.object({ environmentId: z10.string().max(128) })).query(async ({ input, ctx }) => {
2589
+ resolveForAi: protectedProcedure.input(z11.object({ environmentId: z11.string().max(128) })).query(async ({ input, ctx }) => {
2428
2590
  requireEnvAction(ctx, input.environmentId, "env:read");
2429
2591
  const env2 = await environmentStore.get(input.environmentId);
2430
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2592
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2431
2593
  const [resolved, shared] = await Promise.all([
2432
2594
  environmentResolver.resolveEnvironment(input.environmentId),
2433
2595
  environmentResolver.resolveAiSharedKeys(input.environmentId)
@@ -2449,29 +2611,29 @@ var environmentRouter = router({
2449
2611
  * pas un secret public et ne le partage jamais avec les IA. La réponse ne
2450
2612
  * porte aucune valeur : ce qui vient d'être écrit peut être un secret.
2451
2613
  */
2452
- setVariableBlind: protectedProcedure.input(z10.object({
2453
- environmentId: z10.string().max(128),
2454
- key: z10.string().min(1).max(256),
2455
- value: z10.string().max(8192).optional(),
2456
- pre: z10.string().max(8192).optional(),
2457
- post: z10.string().max(8192).optional(),
2458
- isSecret: z10.boolean().optional(),
2459
- description: z10.string().max(2e3).optional()
2614
+ setVariableBlind: protectedProcedure.input(z11.object({
2615
+ environmentId: z11.string().max(128),
2616
+ key: z11.string().min(1).max(256),
2617
+ value: z11.string().max(8192).optional(),
2618
+ pre: z11.string().max(8192).optional(),
2619
+ post: z11.string().max(8192).optional(),
2620
+ isSecret: z11.boolean().optional(),
2621
+ description: z11.string().max(2e3).optional()
2460
2622
  })).mutation(async ({ input, ctx }) => {
2461
2623
  requireEnvAction(ctx, input.environmentId, "env:write");
2462
2624
  const env2 = await environmentStore.get(input.environmentId);
2463
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2625
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2464
2626
  const found = Object.entries(env2.variables).find(([, v]) => v.key === input.key);
2465
2627
  const variableId = found?.[0] ?? randomUUID();
2466
2628
  let variable;
2467
2629
  try {
2468
2630
  variable = planAiVariableWrite(found?.[1], input);
2469
2631
  } catch (err) {
2470
- if (err instanceof AiVariableWriteError) throw new TRPCError7({ code: "FORBIDDEN", message: err.message });
2632
+ if (err instanceof AiVariableWriteError) throw new TRPCError8({ code: "FORBIDDEN", message: err.message });
2471
2633
  throw err;
2472
2634
  }
2473
2635
  const result = await environmentStore.upsertVariable(input.environmentId, variableId, variable);
2474
- if (!result) throw new TRPCError7({ code: "INTERNAL_SERVER_ERROR", message: "Failed to write variable" });
2636
+ if (!result) throw new TRPCError8({ code: "INTERNAL_SERVER_ERROR", message: "Failed to write variable" });
2475
2637
  const written = `${variable.value.pre}${variable.value.value}${variable.value.post}`;
2476
2638
  let suggestions = [];
2477
2639
  if (!variable.value.isSecret) {
@@ -2497,26 +2659,26 @@ var environmentRouter = router({
2497
2659
  * une route dédiée parce que `update` rend l'environnement entier, valeurs
2498
2660
  * comprises.
2499
2661
  */
2500
- setInheritanceBlind: protectedProcedure.input(z10.object({ environmentId: z10.string().max(128), inherit: z10.boolean() })).mutation(async ({ input, ctx }) => {
2662
+ setInheritanceBlind: protectedProcedure.input(z11.object({ environmentId: z11.string().max(128), inherit: z11.boolean() })).mutation(async ({ input, ctx }) => {
2501
2663
  requireEnvAction(ctx, input.environmentId, "env:write");
2502
2664
  const env2 = await environmentStore.get(input.environmentId);
2503
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2665
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2504
2666
  if (env2.scope !== "service" || !env2.activateOn) {
2505
- throw new TRPCError7({ code: "BAD_REQUEST", message: `Environment ${input.environmentId} is not a service environment: only those inherit from, or are isolated from, the global environment that activates them` });
2667
+ throw new TRPCError8({ code: "BAD_REQUEST", message: `Environment ${input.environmentId} is not a service environment: only those inherit from, or are isolated from, the global environment that activates them` });
2506
2668
  }
2507
2669
  const updated = await environmentStore.update({ id: env2.id, parentIds: input.inherit ? [env2.activateOn] : [] });
2508
- if (!updated) throw new TRPCError7({ code: "INTERNAL_SERVER_ERROR", message: "Failed to update inheritance" });
2670
+ if (!updated) throw new TRPCError8({ code: "INTERNAL_SERVER_ERROR", message: "Failed to update inheritance" });
2509
2671
  return { environmentId: env2.id, isolated: !input.inherit };
2510
2672
  }),
2511
2673
  /** Retirer une variable par son nom, pour le compte d'une IA : la réponse ne porte aucune valeur. */
2512
- removeVariableBlind: protectedProcedure.input(z10.object({ environmentId: z10.string().max(128), key: z10.string().min(1).max(256) })).mutation(async ({ input, ctx }) => {
2674
+ removeVariableBlind: protectedProcedure.input(z11.object({ environmentId: z11.string().max(128), key: z11.string().min(1).max(256) })).mutation(async ({ input, ctx }) => {
2513
2675
  requireEnvAction(ctx, input.environmentId, "env:write");
2514
2676
  const env2 = await environmentStore.get(input.environmentId);
2515
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2677
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2516
2678
  const found = Object.entries(env2.variables).find(([, v]) => v.key === input.key);
2517
- if (!found) throw new TRPCError7({ code: "NOT_FOUND", message: `Variable ${input.key} not found in environment ${input.environmentId}` });
2679
+ if (!found) throw new TRPCError8({ code: "NOT_FOUND", message: `Variable ${input.key} not found in environment ${input.environmentId}` });
2518
2680
  const result = await environmentStore.removeVariable(input.environmentId, found[0]);
2519
- if (!result) throw new TRPCError7({ code: "INTERNAL_SERVER_ERROR", message: "Failed to remove variable" });
2681
+ if (!result) throw new TRPCError8({ code: "INTERNAL_SERVER_ERROR", message: "Failed to remove variable" });
2520
2682
  return { environmentId: input.environmentId, key: input.key, removed: true };
2521
2683
  }),
2522
2684
  /**
@@ -2524,12 +2686,12 @@ var environmentRouter = router({
2524
2686
  * define it, and variables that reference it through {{environment.KEY}}.
2525
2687
  * Used by the UI to warn before editing a shared variable from a resolved view.
2526
2688
  */
2527
- keyUsages: protectedProcedure.input(z10.object({
2528
- projectId: z10.string().max(128),
2529
- orgId: z10.string().max(128).nullable().optional(),
2530
- key: z10.string().min(1).max(256),
2689
+ keyUsages: protectedProcedure.input(z11.object({
2690
+ projectId: z11.string().max(128),
2691
+ orgId: z11.string().max(128).nullable().optional(),
2692
+ key: z11.string().min(1).max(256),
2531
2693
  /** Environment holding the variable about to be edited — enables inherited-impact detection */
2532
- environmentId: z10.string().max(128).optional()
2694
+ environmentId: z11.string().max(128).optional()
2533
2695
  })).query(async ({ input }) => {
2534
2696
  const environments = await environmentStore.list(input.projectId, input.orgId);
2535
2697
  const services = await serviceStore.list();
@@ -2586,24 +2748,24 @@ var environmentRouter = router({
2586
2748
  }
2587
2749
  return { definedIn, referencedBy, inheritedBy };
2588
2750
  }),
2589
- removeVariable: protectedProcedure.input(z10.object({
2590
- environmentId: z10.string().max(128),
2591
- variableId: z10.string().max(128)
2751
+ removeVariable: protectedProcedure.input(z11.object({
2752
+ environmentId: z11.string().max(128),
2753
+ variableId: z11.string().max(128)
2592
2754
  })).mutation(async ({ input }) => {
2593
2755
  const env2 = await environmentStore.get(input.environmentId);
2594
- if (!env2) throw new TRPCError7({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2756
+ if (!env2) throw new TRPCError8({ code: "NOT_FOUND", message: `Environment ${input.environmentId} not found` });
2595
2757
  const result = await environmentStore.removeVariable(input.environmentId, input.variableId);
2596
- if (!result) throw new TRPCError7({ code: "INTERNAL_SERVER_ERROR", message: "Failed to remove variable" });
2758
+ if (!result) throw new TRPCError8({ code: "INTERNAL_SERVER_ERROR", message: "Failed to remove variable" });
2597
2759
  return result;
2598
2760
  })
2599
2761
  });
2600
2762
 
2601
2763
  // ../server/src/trpc/routers/settings.ts
2602
2764
  import { promises as dns } from "dns";
2603
- import { z as z11 } from "zod";
2604
- import { TRPCError as TRPCError8 } from "@trpc/server";
2765
+ import { z as z12 } from "zod";
2766
+ import { TRPCError as TRPCError9 } from "@trpc/server";
2605
2767
  var notificationPreferencesShape = NotificationPreferencesSchema.shape;
2606
- var NotificationPreferencesPatchSchema = z11.object(
2768
+ var NotificationPreferencesPatchSchema = z12.object(
2607
2769
  Object.fromEntries(
2608
2770
  Object.entries(notificationPreferencesShape).map(([key, field]) => [key, field.unwrap().optional()])
2609
2771
  )
@@ -2619,8 +2781,8 @@ function maskApiKey2(plaintext) {
2619
2781
  return plaintext.slice(0, 4) + "****" + plaintext.slice(-4);
2620
2782
  }
2621
2783
  var ScopeShape = {
2622
- orgId: z11.string().max(128).nullable().optional(),
2623
- projectId: z11.string().max(128).optional()
2784
+ orgId: z12.string().max(128).nullable().optional(),
2785
+ projectId: z12.string().max(128).optional()
2624
2786
  };
2625
2787
  async function scopeOf(input) {
2626
2788
  return input?.orgId ?? await vaultOfProject(input?.projectId);
@@ -2667,11 +2829,11 @@ var settingsRouter = router({
2667
2829
  * celle de l'onglet qui bascule, ne sont pas coupées. Le choix est mémorisé
2668
2830
  * dans les réglages, donc conservé au prochain démarrage.
2669
2831
  */
2670
- setLanMode: protectedProcedure.input(z11.object({ enabled: z11.boolean() })).mutation(async ({ input }) => {
2832
+ setLanMode: protectedProcedure.input(z12.object({ enabled: z12.boolean() })).mutation(async ({ input }) => {
2671
2833
  try {
2672
2834
  return await setLanMode(input.enabled);
2673
2835
  } catch (err) {
2674
- throw new TRPCError8({
2836
+ throw new TRPCError9({
2675
2837
  code: "INTERNAL_SERVER_ERROR",
2676
2838
  message: `Impossible de changer l'adresse d'\xE9coute : ${err.message}`
2677
2839
  });
@@ -2692,7 +2854,7 @@ var settingsRouter = router({
2692
2854
  /**
2693
2855
  * Get notification preferences
2694
2856
  */
2695
- getNotificationPreferences: protectedProcedure.input(z11.object(ScopeShape).optional()).query(async ({ input }) => {
2857
+ getNotificationPreferences: protectedProcedure.input(z12.object(ScopeShape).optional()).query(async ({ input }) => {
2696
2858
  const priv = await settingsManager.getPrivateSettings(await scopeOf(input));
2697
2859
  return NotificationPreferencesSchema.parse(priv.notifications ?? {});
2698
2860
  }),
@@ -2721,7 +2883,7 @@ var settingsRouter = router({
2721
2883
  * parseur d'organisation se modifie pour toute l'équipe, et l'interface doit
2722
2884
  * pouvoir le dire avant que quelqu'un le change sans le savoir.
2723
2885
  */
2724
- listParsers: protectedProcedure.input(z11.object(ScopeShape).optional()).query(async ({ input }) => {
2886
+ listParsers: protectedProcedure.input(z12.object(ScopeShape).optional()).query(async ({ input }) => {
2725
2887
  const vault = await scopeOf(input);
2726
2888
  return listWithOrigin(await logParserStore.list(vault), vault);
2727
2889
  }),
@@ -2733,7 +2895,7 @@ var settingsRouter = router({
2733
2895
  * retard — affichant une liste dans laquelle le parseur qu'un service vient
2734
2896
  * de référencer n'existe pas encore.
2735
2897
  */
2736
- onParsersChanged: protectedProcedure.input(z11.object(ScopeShape).optional()).subscription(async function* ({ input, signal }) {
2898
+ onParsersChanged: protectedProcedure.input(z12.object(ScopeShape).optional()).subscription(async function* ({ input, signal }) {
2737
2899
  const vault = await scopeOf(input);
2738
2900
  let pending = true;
2739
2901
  let wake = null;
@@ -2771,10 +2933,10 @@ var settingsRouter = router({
2771
2933
  /**
2772
2934
  * Get single parser by ID
2773
2935
  */
2774
- getParser: protectedProcedure.input(z11.object({ id: z11.string().max(128), ...ScopeShape })).query(async ({ input }) => {
2936
+ getParser: protectedProcedure.input(z12.object({ id: z12.string().max(128), ...ScopeShape })).query(async ({ input }) => {
2775
2937
  const parser = await logParserStore.get(input.id, await scopeOf(input));
2776
2938
  if (!parser) {
2777
- throw new TRPCError8({ code: "NOT_FOUND", message: `Parser not found: ${input.id}` });
2939
+ throw new TRPCError9({ code: "NOT_FOUND", message: `Parser not found: ${input.id}` });
2778
2940
  }
2779
2941
  return parser;
2780
2942
  }),
@@ -2790,7 +2952,7 @@ var settingsRouter = router({
2790
2952
  ).mutation(async ({ input }) => {
2791
2953
  const { orgId, projectId, ...fields } = input;
2792
2954
  if (!fields.code.trim()) {
2793
- throw new TRPCError8({ code: "BAD_REQUEST", message: "Parser code cannot be empty" });
2955
+ throw new TRPCError9({ code: "BAD_REQUEST", message: "Parser code cannot be empty" });
2794
2956
  }
2795
2957
  return logParserStore.create(fields, await scopeOf({ orgId, projectId }));
2796
2958
  }),
@@ -2805,27 +2967,27 @@ var settingsRouter = router({
2805
2967
  ).mutation(async ({ input }) => {
2806
2968
  const { id, orgId, projectId, ...patch } = input;
2807
2969
  if (id.startsWith("native:")) {
2808
- throw new TRPCError8({ code: "FORBIDDEN", message: "Cannot modify built-in parsers" });
2970
+ throw new TRPCError9({ code: "FORBIDDEN", message: "Cannot modify built-in parsers" });
2809
2971
  }
2810
2972
  if (patch.code !== void 0 && !patch.code.trim()) {
2811
- throw new TRPCError8({ code: "BAD_REQUEST", message: "Parser code cannot be empty" });
2973
+ throw new TRPCError9({ code: "BAD_REQUEST", message: "Parser code cannot be empty" });
2812
2974
  }
2813
2975
  const updated = await logParserStore.update(id, patch, await scopeOf({ orgId, projectId }));
2814
2976
  if (!updated) {
2815
- throw new TRPCError8({ code: "NOT_FOUND", message: `Parser not found: ${id}` });
2977
+ throw new TRPCError9({ code: "NOT_FOUND", message: `Parser not found: ${id}` });
2816
2978
  }
2817
2979
  return updated;
2818
2980
  }),
2819
2981
  /**
2820
2982
  * Delete parser by ID
2821
2983
  */
2822
- deleteParser: protectedProcedure.input(z11.object({ id: z11.string().max(128), ...ScopeShape })).mutation(async ({ input }) => {
2984
+ deleteParser: protectedProcedure.input(z12.object({ id: z12.string().max(128), ...ScopeShape })).mutation(async ({ input }) => {
2823
2985
  if (input.id.startsWith("native:")) {
2824
- throw new TRPCError8({ code: "FORBIDDEN", message: "Cannot delete built-in parsers" });
2986
+ throw new TRPCError9({ code: "FORBIDDEN", message: "Cannot delete built-in parsers" });
2825
2987
  }
2826
2988
  const deleted = await logParserStore.delete(input.id, await scopeOf(input));
2827
2989
  if (!deleted) {
2828
- throw new TRPCError8({ code: "NOT_FOUND", message: `Parser not found: ${input.id}` });
2990
+ throw new TRPCError9({ code: "NOT_FOUND", message: `Parser not found: ${input.id}` });
2829
2991
  }
2830
2992
  return { deleted: true };
2831
2993
  }),
@@ -2861,15 +3023,15 @@ var settingsRouter = router({
2861
3023
  defaultPrompt: companionDefaultPrompt()
2862
3024
  };
2863
3025
  }),
2864
- setCompanionSettings: protectedProcedure.input(z11.object({
2865
- enabledByDefault: z11.boolean().optional(),
3026
+ setCompanionSettings: protectedProcedure.input(z12.object({
3027
+ enabledByDefault: z12.boolean().optional(),
2866
3028
  // Rejeté au-delà, jamais tronqué : un prompt coupé produirait des
2867
3029
  // relectures incohérentes sans rien signaler.
2868
- prompt: z11.string().max(2e4).optional(),
3030
+ prompt: z12.string().max(2e4).optional(),
2869
3031
  /** Chaîne vide = retirer le défaut. */
2870
- runner: z11.enum(["claude-code", "codex", ""]).optional(),
2871
- model: z11.string().max(200).optional(),
2872
- effort: z11.enum(["low", "normal", "high", ""]).optional()
3032
+ runner: z12.enum(["claude-code", "codex", ""]).optional(),
3033
+ model: z12.string().max(200).optional(),
3034
+ effort: z12.enum(["low", "normal", "high", ""]).optional()
2873
3035
  })).mutation(async ({ input }) => {
2874
3036
  const settings = await settingsManager.getSettings();
2875
3037
  const current2 = settings.companion ?? { enabledByDefault: false };
@@ -2891,7 +3053,7 @@ var settingsRouter = router({
2891
3053
  /**
2892
3054
  * List AI providers (API keys are masked)
2893
3055
  */
2894
- listAIProviders: protectedProcedure.input(z11.object(ScopeShape).optional()).query(async ({ input }) => {
3056
+ listAIProviders: protectedProcedure.input(z12.object(ScopeShape).optional()).query(async ({ input }) => {
2895
3057
  const vault = await scopeOf(input);
2896
3058
  const priv = await settingsManager.getPrivateSettings(vault);
2897
3059
  return (priv.aiProviders ?? []).map((p) => {
@@ -2909,16 +3071,16 @@ var settingsRouter = router({
2909
3071
  /**
2910
3072
  * Create AI provider
2911
3073
  */
2912
- createAIProvider: protectedProcedure.input(z11.object({
2913
- name: z11.string().min(1).max(200),
3074
+ createAIProvider: protectedProcedure.input(z12.object({
3075
+ name: z12.string().min(1).max(200),
2914
3076
  provider: AIProviderSchema.shape.provider,
2915
- apiKey: z11.string().max(500).optional(),
3077
+ apiKey: z12.string().max(500).optional(),
2916
3078
  // optional for providers like Ollama
2917
- model: z11.string().max(200).optional(),
3079
+ model: z12.string().max(200).optional(),
2918
3080
  ...ScopeShape
2919
3081
  })).mutation(async ({ input }) => {
2920
3082
  if (input.provider !== "ollama" && !input.apiKey?.trim()) {
2921
- throw new TRPCError8({ code: "BAD_REQUEST", message: "Une cl\xE9 API est requise pour ce provider." });
3083
+ throw new TRPCError9({ code: "BAD_REQUEST", message: "Une cl\xE9 API est requise pour ce provider." });
2922
3084
  }
2923
3085
  const vault = await scopeOf(input);
2924
3086
  const priv = await settingsManager.getPrivateSettings(vault);
@@ -2947,19 +3109,19 @@ var settingsRouter = router({
2947
3109
  /**
2948
3110
  * Update AI provider (apiKey optional — omit to keep existing)
2949
3111
  */
2950
- updateAIProvider: protectedProcedure.input(z11.object({
2951
- id: z11.string().min(1).max(128),
2952
- name: z11.string().min(1).max(200).optional(),
3112
+ updateAIProvider: protectedProcedure.input(z12.object({
3113
+ id: z12.string().min(1).max(128),
3114
+ name: z12.string().min(1).max(200).optional(),
2953
3115
  provider: AIProviderSchema.shape.provider.optional(),
2954
- apiKey: z11.string().min(1).max(500).optional(),
2955
- model: z11.string().max(200).optional(),
3116
+ apiKey: z12.string().min(1).max(500).optional(),
3117
+ model: z12.string().max(200).optional(),
2956
3118
  ...ScopeShape
2957
3119
  })).mutation(async ({ input }) => {
2958
3120
  const vault = await scopeOf(input);
2959
3121
  const priv = await settingsManager.getPrivateSettings(vault);
2960
3122
  const providers = priv.aiProviders ?? [];
2961
3123
  const idx = providers.findIndex((p) => p.id === input.id);
2962
- if (idx === -1) throw new TRPCError8({ code: "NOT_FOUND", message: `AI provider not found: ${input.id}` });
3124
+ if (idx === -1) throw new TRPCError9({ code: "NOT_FOUND", message: `AI provider not found: ${input.id}` });
2963
3125
  const existing = providers[idx];
2964
3126
  const encryptedApiKey = input.apiKey ? stableEncryptValue(input.apiKey, existing.encryptedApiKey, vault) : existing.encryptedApiKey;
2965
3127
  const updated = {
@@ -2985,12 +3147,12 @@ var settingsRouter = router({
2985
3147
  /**
2986
3148
  * Delete AI provider
2987
3149
  */
2988
- deleteAIProvider: protectedProcedure.input(z11.object({ id: z11.string().min(1).max(128), ...ScopeShape })).mutation(async ({ input }) => {
3150
+ deleteAIProvider: protectedProcedure.input(z12.object({ id: z12.string().min(1).max(128), ...ScopeShape })).mutation(async ({ input }) => {
2989
3151
  const vault = await scopeOf(input);
2990
3152
  const priv = await settingsManager.getPrivateSettings(vault);
2991
3153
  const providers = priv.aiProviders ?? [];
2992
3154
  const filtered = providers.filter((p) => p.id !== input.id);
2993
- if (filtered.length === providers.length) throw new TRPCError8({ code: "NOT_FOUND", message: `AI provider not found: ${input.id}` });
3155
+ if (filtered.length === providers.length) throw new TRPCError9({ code: "NOT_FOUND", message: `AI provider not found: ${input.id}` });
2994
3156
  const deletedWasActive = providers.find((p) => p.id === input.id)?.active ?? false;
2995
3157
  if (deletedWasActive && filtered.length > 0) filtered[0].active = true;
2996
3158
  await settingsManager.savePrivateSettings({ ...priv, aiProviders: filtered }, vault);
@@ -2999,12 +3161,12 @@ var settingsRouter = router({
2999
3161
  /**
3000
3162
  * Set one provider as active (clears active flag on all others)
3001
3163
  */
3002
- setActiveAIProvider: protectedProcedure.input(z11.object({ id: z11.string().min(1).max(128), ...ScopeShape })).mutation(async ({ input }) => {
3164
+ setActiveAIProvider: protectedProcedure.input(z12.object({ id: z12.string().min(1).max(128), ...ScopeShape })).mutation(async ({ input }) => {
3003
3165
  const vault = await scopeOf(input);
3004
3166
  const priv = await settingsManager.getPrivateSettings(vault);
3005
3167
  const providers = priv.aiProviders ?? [];
3006
3168
  const idx = providers.findIndex((p) => p.id === input.id);
3007
- if (idx === -1) throw new TRPCError8({ code: "NOT_FOUND", message: `AI provider not found: ${input.id}` });
3169
+ if (idx === -1) throw new TRPCError9({ code: "NOT_FOUND", message: `AI provider not found: ${input.id}` });
3008
3170
  const updated = providers.map((p) => ({ ...p, active: p.id === input.id }));
3009
3171
  await settingsManager.savePrivateSettings({ ...priv, aiProviders: updated }, vault);
3010
3172
  return { id: input.id, active: true };
@@ -3015,7 +3177,7 @@ var settingsRouter = router({
3015
3177
  /**
3016
3178
  * Get Traefik config for a specific agent (never returns credentials or cert key in plain text)
3017
3179
  */
3018
- getAgentTraefikConfig: protectedProcedure.input(z11.object({ agentId: z11.string().max(128) })).query(async ({ input }) => {
3180
+ getAgentTraefikConfig: protectedProcedure.input(z12.object({ agentId: z12.string().max(128) })).query(async ({ input }) => {
3019
3181
  const raw = agentStore.getTraefikConfig(input.agentId);
3020
3182
  const parsed = raw ? TraefikConfigSchema.safeParse(raw) : null;
3021
3183
  const config = parsed?.success ? parsed.data : null;
@@ -3035,16 +3197,16 @@ var settingsRouter = router({
3035
3197
  /**
3036
3198
  * Update Traefik config for a specific agent (credentials are encrypted before saving)
3037
3199
  */
3038
- updateAgentTraefikConfig: protectedProcedure.input(z11.object({
3039
- agentId: z11.string().max(128),
3040
- enabled: z11.boolean().optional(),
3041
- acmeEmail: z11.string().email().max(256).optional(),
3042
- wildcardDomain: z11.string().max(253).optional(),
3043
- httpPort: z11.number().int().min(1).max(65535).optional(),
3044
- httpsPort: z11.number().int().min(1).max(65535).optional(),
3045
- dnsProvider: z11.string().max(64).optional(),
3046
- dnsCredentials: z11.record(z11.string().max(64), z11.string().max(2048)).optional(),
3047
- acmeStaging: z11.boolean().optional()
3200
+ updateAgentTraefikConfig: protectedProcedure.input(z12.object({
3201
+ agentId: z12.string().max(128),
3202
+ enabled: z12.boolean().optional(),
3203
+ acmeEmail: z12.string().email().max(256).optional(),
3204
+ wildcardDomain: z12.string().max(253).optional(),
3205
+ httpPort: z12.number().int().min(1).max(65535).optional(),
3206
+ httpsPort: z12.number().int().min(1).max(65535).optional(),
3207
+ dnsProvider: z12.string().max(64).optional(),
3208
+ dnsCredentials: z12.record(z12.string().max(64), z12.string().max(2048)).optional(),
3209
+ acmeStaging: z12.boolean().optional()
3048
3210
  })).mutation(async ({ input }) => {
3049
3211
  const { agentId, ...fields } = input;
3050
3212
  const raw = agentStore.getTraefikConfig(agentId);
@@ -3073,13 +3235,13 @@ var settingsRouter = router({
3073
3235
  /**
3074
3236
  * Get Traefik config files content for a specific agent
3075
3237
  */
3076
- getAgentTraefikConfigFiles: protectedProcedure.input(z11.object({ agentId: z11.string().max(128) })).query(async ({ input }) => {
3238
+ getAgentTraefikConfigFiles: protectedProcedure.input(z12.object({ agentId: z12.string().max(128) })).query(async ({ input }) => {
3077
3239
  return agentManager.agentQuery(
3078
3240
  input.agentId,
3079
3241
  "config.getTraefikConfigFiles"
3080
3242
  );
3081
3243
  }),
3082
- getAgentTraefikFileTree: protectedProcedure.input(z11.object({ agentId: z11.string().max(128) })).query(async ({ input }) => {
3244
+ getAgentTraefikFileTree: protectedProcedure.input(z12.object({ agentId: z12.string().max(128) })).query(async ({ input }) => {
3083
3245
  return agentManager.agentQuery(
3084
3246
  input.agentId,
3085
3247
  "config.getTraefikFileTree"
@@ -3088,7 +3250,7 @@ var settingsRouter = router({
3088
3250
  /**
3089
3251
  * Get Traefik container logs for a specific agent (snapshot)
3090
3252
  */
3091
- getAgentTraefikLogs: protectedProcedure.input(z11.object({ agentId: z11.string().max(128), lines: z11.number().int().min(1).max(500).default(100) })).query(async ({ input }) => {
3253
+ getAgentTraefikLogs: protectedProcedure.input(z12.object({ agentId: z12.string().max(128), lines: z12.number().int().min(1).max(500).default(100) })).query(async ({ input }) => {
3092
3254
  const result = await agentManager.agentQuery(
3093
3255
  input.agentId,
3094
3256
  "config.getTraefikLogs",
@@ -3099,7 +3261,7 @@ var settingsRouter = router({
3099
3261
  /**
3100
3262
  * Stream Traefik logs in real-time (subscription, yields new lines every 500ms)
3101
3263
  */
3102
- streamAgentTraefikLogs: protectedProcedure.input(z11.object({ agentId: z11.string().max(128) })).subscription(async function* ({ input, signal }) {
3264
+ streamAgentTraefikLogs: protectedProcedure.input(z12.object({ agentId: z12.string().max(128) })).subscription(async function* ({ input, signal }) {
3103
3265
  let seen = 0;
3104
3266
  while (!signal?.aborted) {
3105
3267
  try {
@@ -3122,11 +3284,11 @@ var settingsRouter = router({
3122
3284
  /**
3123
3285
  * Restart Traefik container on a specific agent (re-pushes config first to handle agent restarts)
3124
3286
  */
3125
- restartAgentTraefik: protectedProcedure.input(z11.object({ agentId: z11.string().max(128) })).mutation(async ({ input }) => {
3287
+ restartAgentTraefik: protectedProcedure.input(z12.object({ agentId: z12.string().max(128) })).mutation(async ({ input }) => {
3126
3288
  const raw = agentStore.getTraefikConfig(input.agentId);
3127
3289
  const parsed = raw ? TraefikConfigSchema.safeParse(raw) : null;
3128
3290
  const config = parsed?.success ? parsed.data : null;
3129
- if (!config?.enabled) throw new TRPCError8({ code: "BAD_REQUEST", message: "Traefik non activ\xE9 sur cet agent" });
3291
+ if (!config?.enabled) throw new TRPCError9({ code: "BAD_REQUEST", message: "Traefik non activ\xE9 sur cet agent" });
3130
3292
  const decrypted = { ...config, dnsCredentials: traefikManager.decryptDnsCredentials(config.dnsCredentials ?? {}) };
3131
3293
  await agentManager.agentMutation(input.agentId, "config.initTraefikConfig", decrypted, 5e3);
3132
3294
  await agentManager.agentMutation(input.agentId, "config.restartTraefik", void 0, 3e4);
@@ -3135,11 +3297,11 @@ var settingsRouter = router({
3135
3297
  /**
3136
3298
  * Force certificate renewal for a specific agent (wipes acme.json + restarts container)
3137
3299
  */
3138
- renewAgentTraefikCert: protectedProcedure.input(z11.object({ agentId: z11.string().max(128) })).mutation(async ({ input }) => {
3300
+ renewAgentTraefikCert: protectedProcedure.input(z12.object({ agentId: z12.string().max(128) })).mutation(async ({ input }) => {
3139
3301
  const raw = agentStore.getTraefikConfig(input.agentId);
3140
3302
  const parsed = raw ? TraefikConfigSchema.safeParse(raw) : null;
3141
3303
  const config = parsed?.success ? parsed.data : null;
3142
- if (!config?.enabled) throw new TRPCError8({ code: "BAD_REQUEST", message: "Traefik non activ\xE9 sur cet agent" });
3304
+ if (!config?.enabled) throw new TRPCError9({ code: "BAD_REQUEST", message: "Traefik non activ\xE9 sur cet agent" });
3143
3305
  const decrypted = { ...config, dnsCredentials: traefikManager.decryptDnsCredentials(config.dnsCredentials ?? {}) };
3144
3306
  await agentManager.agentMutation(input.agentId, "config.initTraefikConfig", decrypted, 5e3);
3145
3307
  await agentManager.agentMutation(input.agentId, "config.renewTraefikCert", void 0, 3e4);
@@ -3148,7 +3310,7 @@ var settingsRouter = router({
3148
3310
  /**
3149
3311
  * Validate Traefik configuration for a specific agent
3150
3312
  */
3151
- validateAgentTraefikConfig: protectedProcedure.input(z11.object({ agentId: z11.string().max(128) })).query(async ({ input }) => {
3313
+ validateAgentTraefikConfig: protectedProcedure.input(z12.object({ agentId: z12.string().max(128) })).query(async ({ input }) => {
3152
3314
  const raw = agentStore.getTraefikConfig(input.agentId);
3153
3315
  const parsed = raw ? TraefikConfigSchema.safeParse(raw) : null;
3154
3316
  const config = parsed?.success ? parsed.data : null;
@@ -3250,12 +3412,12 @@ var settingsRouter = router({
3250
3412
  * Test parser code: compile and run it against sample logs, return per-line results
3251
3413
  */
3252
3414
  testParser: protectedProcedure.input(
3253
- z11.object({
3254
- code: z11.string().max(5e4),
3255
- sampleLogs: z11.array(
3256
- z11.object({
3257
- raw: z11.string().max(16384),
3258
- stream: z11.enum(["stdout", "stderr"])
3415
+ z12.object({
3416
+ code: z12.string().max(5e4),
3417
+ sampleLogs: z12.array(
3418
+ z12.object({
3419
+ raw: z12.string().max(16384),
3420
+ stream: z12.enum(["stdout", "stderr"])
3259
3421
  })
3260
3422
  ).max(100).default([])
3261
3423
  })
@@ -3271,7 +3433,7 @@ var settingsRouter = router({
3271
3433
  updatedAt: /* @__PURE__ */ new Date()
3272
3434
  }]);
3273
3435
  } catch (err) {
3274
- throw new TRPCError8({
3436
+ throw new TRPCError9({
3275
3437
  code: "BAD_REQUEST",
3276
3438
  message: err instanceof Error ? err.message : String(err)
3277
3439
  });
@@ -3299,30 +3461,30 @@ var settingsRouter = router({
3299
3461
  });
3300
3462
 
3301
3463
  // ../server/src/trpc/routers/editor.ts
3302
- import { z as z13 } from "zod";
3303
- import { TRPCError as TRPCError9 } from "@trpc/server";
3464
+ import { z as z14 } from "zod";
3465
+ import { TRPCError as TRPCError10 } from "@trpc/server";
3304
3466
  import { execFile as execFile3, spawn as spawn2 } from "child_process";
3305
3467
  import { stat as stat2 } from "fs/promises";
3306
- import { resolve as resolve2, join as join4 } from "path";
3468
+ import { resolve as resolve2, join as join5 } from "path";
3307
3469
  import { homedir as homedir2 } from "os";
3308
3470
 
3309
3471
  // ../server/src/services/user-config-manager.ts
3310
3472
  import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2, chmod as chmod2 } from "fs/promises";
3311
- import { join as join3 } from "path";
3473
+ import { join as join4 } from "path";
3312
3474
  import { homedir } from "os";
3313
- import { z as z12 } from "zod";
3314
- var CONFIG_DIR = join3(homedir(), ".runeya");
3475
+ import { z as z13 } from "zod";
3476
+ var CONFIG_DIR = join4(homedir(), ".runeya");
3315
3477
  var CONFIG_FILE = "runeya.conf";
3316
- var EditorPreferencesSchema = z12.object({
3317
- default: z12.string().max(64).optional()
3318
- }).catchall(z12.string().max(64)).refine((obj) => Object.keys(obj).length <= 500, "Too many editor preferences");
3319
- var ProjectSettingsSchema = z12.object({
3320
- settings: z12.object({
3478
+ var EditorPreferencesSchema = z13.object({
3479
+ default: z13.string().max(64).optional()
3480
+ }).catchall(z13.string().max(64)).refine((obj) => Object.keys(obj).length <= 500, "Too many editor preferences");
3481
+ var ProjectSettingsSchema = z13.object({
3482
+ settings: z13.object({
3321
3483
  editors: EditorPreferencesSchema.optional()
3322
3484
  }).optional()
3323
3485
  });
3324
- var UserConfigSchema = z12.record(
3325
- z12.string().max(128),
3486
+ var UserConfigSchema = z13.record(
3487
+ z13.string().max(128),
3326
3488
  ProjectSettingsSchema
3327
3489
  ).refine((obj) => Object.keys(obj).length <= 100, "Too many projects in config");
3328
3490
  function configKey(ref) {
@@ -3335,7 +3497,7 @@ var UserConfigManager = class {
3335
3497
  }
3336
3498
  async atomicWrite(data) {
3337
3499
  await this.ensureDir();
3338
- const filePath = join3(CONFIG_DIR, CONFIG_FILE);
3500
+ const filePath = join4(CONFIG_DIR, CONFIG_FILE);
3339
3501
  const tmpPath = filePath + ".tmp";
3340
3502
  await writeFile2(tmpPath, JSON.stringify(data, null, 2), "utf-8");
3341
3503
  await renameWithRetry(tmpPath, filePath);
@@ -3344,7 +3506,7 @@ var UserConfigManager = class {
3344
3506
  async getConfig() {
3345
3507
  if (!this.config) {
3346
3508
  try {
3347
- const raw = await readFile2(join3(CONFIG_DIR, CONFIG_FILE), "utf-8");
3509
+ const raw = await readFile2(join4(CONFIG_DIR, CONFIG_FILE), "utf-8");
3348
3510
  const parsed = UserConfigSchema.safeParse(JSON.parse(raw));
3349
3511
  this.config = parsed.success ? parsed.data : {};
3350
3512
  } catch {
@@ -3393,7 +3555,7 @@ async function getServiceCwd(serviceId) {
3393
3555
  const services = await serviceStore.list();
3394
3556
  const service2 = services.find((s) => s.id === serviceId);
3395
3557
  if (!service2) {
3396
- throw new TRPCError9({ code: "NOT_FOUND", message: "Service not found" });
3558
+ throw new TRPCError10({ code: "NOT_FOUND", message: "Service not found" });
3397
3559
  }
3398
3560
  return resolveCwd(await resolveWorkspaceCwd({ serviceId }));
3399
3561
  }
@@ -3414,19 +3576,19 @@ var editorRouter = router({
3414
3576
  );
3415
3577
  return results;
3416
3578
  }),
3417
- getPreferences: protectedProcedure.input(z13.object({
3418
- projectId: z13.string().max(128),
3419
- orgId: z13.string().max(128).nullable().optional()
3579
+ getPreferences: protectedProcedure.input(z14.object({
3580
+ projectId: z14.string().max(128),
3581
+ orgId: z14.string().max(128).nullable().optional()
3420
3582
  })).query(async ({ input }) => {
3421
3583
  return userConfigManager.getEditorPreferences({ id: input.projectId, orgId: input.orgId });
3422
3584
  }),
3423
- setDefault: protectedProcedure.input(z13.object({
3424
- projectId: z13.string().max(128),
3425
- orgId: z13.string().max(128).nullable().optional(),
3426
- editorKey: z13.string().max(64)
3585
+ setDefault: protectedProcedure.input(z14.object({
3586
+ projectId: z14.string().max(128),
3587
+ orgId: z14.string().max(128).nullable().optional(),
3588
+ editorKey: z14.string().max(64)
3427
3589
  })).mutation(async ({ input }) => {
3428
3590
  if (!EDITOR_BY_KEY.has(input.editorKey)) {
3429
- throw new TRPCError9({ code: "BAD_REQUEST", message: `Unknown editor: ${input.editorKey}` });
3591
+ throw new TRPCError10({ code: "BAD_REQUEST", message: `Unknown editor: ${input.editorKey}` });
3430
3592
  }
3431
3593
  await userConfigManager.setEditorPreference(
3432
3594
  { id: input.projectId, orgId: input.orgId },
@@ -3435,14 +3597,14 @@ var editorRouter = router({
3435
3597
  );
3436
3598
  return { success: true };
3437
3599
  }),
3438
- setServiceEditor: protectedProcedure.input(z13.object({
3439
- projectId: z13.string().max(128),
3440
- orgId: z13.string().max(128).nullable().optional(),
3441
- serviceId: z13.string().max(128),
3442
- editorKey: z13.string().max(64)
3600
+ setServiceEditor: protectedProcedure.input(z14.object({
3601
+ projectId: z14.string().max(128),
3602
+ orgId: z14.string().max(128).nullable().optional(),
3603
+ serviceId: z14.string().max(128),
3604
+ editorKey: z14.string().max(64)
3443
3605
  })).mutation(async ({ input }) => {
3444
3606
  if (!EDITOR_BY_KEY.has(input.editorKey)) {
3445
- throw new TRPCError9({ code: "BAD_REQUEST", message: `Unknown editor: ${input.editorKey}` });
3607
+ throw new TRPCError10({ code: "BAD_REQUEST", message: `Unknown editor: ${input.editorKey}` });
3446
3608
  }
3447
3609
  await userConfigManager.setEditorPreference(
3448
3610
  { id: input.projectId, orgId: input.orgId },
@@ -3451,10 +3613,10 @@ var editorRouter = router({
3451
3613
  );
3452
3614
  return { success: true };
3453
3615
  }),
3454
- removeServiceEditor: protectedProcedure.input(z13.object({
3455
- projectId: z13.string().max(128),
3456
- orgId: z13.string().max(128).nullable().optional(),
3457
- serviceId: z13.string().max(128)
3616
+ removeServiceEditor: protectedProcedure.input(z14.object({
3617
+ projectId: z14.string().max(128),
3618
+ orgId: z14.string().max(128).nullable().optional(),
3619
+ serviceId: z14.string().max(128)
3458
3620
  })).mutation(async ({ input }) => {
3459
3621
  await userConfigManager.removeEditorPreference(
3460
3622
  { id: input.projectId, orgId: input.orgId },
@@ -3462,21 +3624,21 @@ var editorRouter = router({
3462
3624
  );
3463
3625
  return { success: true };
3464
3626
  }),
3465
- open: protectedProcedure.input(z13.object({
3466
- editorKey: z13.string().max(64),
3467
- path: z13.string().max(4096)
3627
+ open: protectedProcedure.input(z14.object({
3628
+ editorKey: z14.string().max(64),
3629
+ path: z14.string().max(4096)
3468
3630
  })).mutation(async ({ input }) => {
3469
3631
  const editor = EDITOR_BY_KEY.get(input.editorKey);
3470
3632
  if (!editor) {
3471
- throw new TRPCError9({ code: "BAD_REQUEST", message: `Unknown editor: ${input.editorKey}` });
3633
+ throw new TRPCError10({ code: "BAD_REQUEST", message: `Unknown editor: ${input.editorKey}` });
3472
3634
  }
3473
3635
  const expanded = input.path.replace(/^~(\/|$)/, `${process.env["HOME"] ?? "/tmp"}$1`).replace(/\$\{(\w+)\}|\$(\w+)/g, (_, a, b) => process.env[a || b] ?? "");
3474
3636
  const resolvedPath = resolve2(expanded || ".");
3475
3637
  try {
3476
3638
  await stat2(resolvedPath);
3477
3639
  } catch (err) {
3478
- if (err instanceof TRPCError9) throw err;
3479
- throw new TRPCError9({ code: "BAD_REQUEST", message: `Path does not exist: ${resolvedPath}` });
3640
+ if (err instanceof TRPCError10) throw err;
3641
+ throw new TRPCError10({ code: "BAD_REQUEST", message: `Path does not exist: ${resolvedPath}` });
3480
3642
  }
3481
3643
  const invocation = resolveCliInvocation(editor.command, [resolvedPath]);
3482
3644
  const child = spawn2(invocation.command, invocation.args, {
@@ -3488,24 +3650,24 @@ var editorRouter = router({
3488
3650
  child.unref();
3489
3651
  return { success: true };
3490
3652
  }),
3491
- openFile: protectedProcedure.input(z13.object({
3492
- editorKey: z13.string().max(64),
3493
- serviceId: z13.string().max(128),
3494
- relativePath: z13.string().max(4096)
3653
+ openFile: protectedProcedure.input(z14.object({
3654
+ editorKey: z14.string().max(64),
3655
+ serviceId: z14.string().max(128),
3656
+ relativePath: z14.string().max(4096)
3495
3657
  })).mutation(async ({ input }) => {
3496
3658
  const editor = EDITOR_BY_KEY.get(input.editorKey);
3497
3659
  if (!editor) {
3498
- throw new TRPCError9({ code: "BAD_REQUEST", message: `Unknown editor: ${input.editorKey}` });
3660
+ throw new TRPCError10({ code: "BAD_REQUEST", message: `Unknown editor: ${input.editorKey}` });
3499
3661
  }
3500
3662
  const cwd = await getServiceCwd(input.serviceId);
3501
- const filePath = join4(cwd, input.relativePath);
3663
+ const filePath = join5(cwd, input.relativePath);
3502
3664
  if (!filePath.startsWith(cwd)) {
3503
- throw new TRPCError9({ code: "BAD_REQUEST", message: "Path traversal not allowed" });
3665
+ throw new TRPCError10({ code: "BAD_REQUEST", message: "Path traversal not allowed" });
3504
3666
  }
3505
3667
  try {
3506
3668
  await stat2(filePath);
3507
3669
  } catch {
3508
- throw new TRPCError9({ code: "BAD_REQUEST", message: `File does not exist: ${filePath}` });
3670
+ throw new TRPCError10({ code: "BAD_REQUEST", message: `File does not exist: ${filePath}` });
3509
3671
  }
3510
3672
  const invocation = resolveCliInvocation(editor.command, [filePath]);
3511
3673
  const child = spawn2(invocation.command, invocation.args, {
@@ -3520,57 +3682,57 @@ var editorRouter = router({
3520
3682
  });
3521
3683
 
3522
3684
  // ../server/src/trpc/routers/api-keys.ts
3523
- import { z as z14 } from "zod";
3524
- import { TRPCError as TRPCError10 } from "@trpc/server";
3685
+ import { z as z15 } from "zod";
3686
+ import { TRPCError as TRPCError11 } from "@trpc/server";
3525
3687
  import { mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
3526
- import { join as join5, dirname as dirname3 } from "path";
3688
+ import { join as join6, dirname as dirname3 } from "path";
3527
3689
  var ALLOWED_SKILL_PATHS = /* @__PURE__ */ new Set([
3528
3690
  ".claude/skills/runeya/SKILL.md",
3529
3691
  ".cursor/rules/runeya.mdc",
3530
3692
  ".windsurf/rules/runeya.md"
3531
3693
  ]);
3532
- var KeyInputSchema = z14.object({
3533
- name: z14.string().min(1).max(200),
3694
+ var KeyInputSchema = z15.object({
3695
+ name: z15.string().min(1).max(200),
3534
3696
  scopes: ApiKeyScopeSchema,
3535
- isPublic: z14.boolean().default(false)
3697
+ isPublic: z15.boolean().default(false)
3536
3698
  });
3537
3699
  var apiKeysRouter = router({
3538
3700
  list: protectedProcedure.query(() => apiKeyStore.list()),
3539
- create: protectedProcedure.input(KeyInputSchema.extend({ orgId: z14.string().min(1).max(128).nullable().optional() })).mutation(
3701
+ create: protectedProcedure.input(KeyInputSchema.extend({ orgId: z15.string().min(1).max(128).nullable().optional() })).mutation(
3540
3702
  ({ input }) => apiKeyStore.create(input.name, input.scopes, input.isPublic, input.orgId ?? null)
3541
3703
  ),
3542
3704
  /**
3543
3705
  * Renvoie le secret d'une seule clé, sur demande explicite. `list` ne le
3544
3706
  * contient pas : une clé ne doit jamais être re-servie en masse.
3545
3707
  */
3546
- reveal: protectedProcedure.input(z14.object({ id: z14.string().max(128) })).query(async ({ input }) => {
3708
+ reveal: protectedProcedure.input(z15.object({ id: z15.string().max(128) })).query(async ({ input }) => {
3547
3709
  const key = await apiKeyStore.reveal(input.id);
3548
- if (!key) throw new TRPCError10({ code: "NOT_FOUND", message: "API key not found" });
3710
+ if (!key) throw new TRPCError11({ code: "NOT_FOUND", message: "API key not found" });
3549
3711
  return { key };
3550
3712
  }),
3551
- update: protectedProcedure.input(KeyInputSchema.extend({ id: z14.string().max(128) })).mutation(async ({ input }) => {
3713
+ update: protectedProcedure.input(KeyInputSchema.extend({ id: z15.string().max(128) })).mutation(async ({ input }) => {
3552
3714
  const updated = await apiKeyStore.update(input.id, input.name, input.scopes, input.isPublic);
3553
- if (!updated) throw new TRPCError10({ code: "NOT_FOUND", message: "API key not found" });
3715
+ if (!updated) throw new TRPCError11({ code: "NOT_FOUND", message: "API key not found" });
3554
3716
  return maskApiKey(updated);
3555
3717
  }),
3556
- remove: protectedProcedure.input(z14.object({ id: z14.string().max(128) })).mutation(async ({ input }) => {
3718
+ remove: protectedProcedure.input(z15.object({ id: z15.string().max(128) })).mutation(async ({ input }) => {
3557
3719
  const removed = await apiKeyStore.remove(input.id);
3558
- if (!removed) throw new TRPCError10({ code: "NOT_FOUND", message: "API key not found" });
3720
+ if (!removed) throw new TRPCError11({ code: "NOT_FOUND", message: "API key not found" });
3559
3721
  return { success: true };
3560
3722
  }),
3561
- renewKey: protectedProcedure.input(z14.object({ id: z14.string().max(128) })).mutation(async ({ input }) => {
3723
+ renewKey: protectedProcedure.input(z15.object({ id: z15.string().max(128) })).mutation(async ({ input }) => {
3562
3724
  const renewed = await apiKeyStore.renewKey(input.id);
3563
- if (!renewed) throw new TRPCError10({ code: "NOT_FOUND", message: "API key not found" });
3725
+ if (!renewed) throw new TRPCError11({ code: "NOT_FOUND", message: "API key not found" });
3564
3726
  return renewed;
3565
3727
  }),
3566
- writeSkillFile: protectedProcedure.input(z14.object({
3567
- relativePath: z14.string().max(256),
3568
- content: z14.string().max(32768)
3728
+ writeSkillFile: protectedProcedure.input(z15.object({
3729
+ relativePath: z15.string().max(256),
3730
+ content: z15.string().max(32768)
3569
3731
  })).mutation(async ({ input }) => {
3570
3732
  if (!ALLOWED_SKILL_PATHS.has(input.relativePath)) {
3571
- throw new TRPCError10({ code: "BAD_REQUEST", message: "Chemin non autoris\xE9" });
3733
+ throw new TRPCError11({ code: "BAD_REQUEST", message: "Chemin non autoris\xE9" });
3572
3734
  }
3573
- const abs = join5(await resolveWorkspaceCwd({}), input.relativePath);
3735
+ const abs = join6(await resolveWorkspaceCwd({}), input.relativePath);
3574
3736
  await mkdir3(dirname3(abs), { recursive: true });
3575
3737
  await writeFile3(abs, input.content, { encoding: "utf-8", mode: 420 });
3576
3738
  return { path: input.relativePath };
@@ -3578,133 +3740,133 @@ var apiKeysRouter = router({
3578
3740
  });
3579
3741
 
3580
3742
  // ../server/src/trpc/routers/git.ts
3581
- import { z as z15 } from "zod";
3582
- import { TRPCError as TRPCError11 } from "@trpc/server";
3743
+ import { z as z16 } from "zod";
3744
+ import { TRPCError as TRPCError12 } from "@trpc/server";
3583
3745
  import Anthropic from "@anthropic-ai/sdk";
3584
3746
  import OpenAI from "openai";
3585
- var SERVICE_ID_SCHEMA = z15.string().max(128);
3586
- var SAFE_PATH_SCHEMA = z15.string().min(1).max(4096).refine((p) => !p.startsWith("/") && !p.includes("../"), {
3747
+ var SERVICE_ID_SCHEMA = z16.string().max(128);
3748
+ var SAFE_PATH_SCHEMA = z16.string().min(1).max(4096).refine((p) => !p.startsWith("/") && !p.includes("../"), {
3587
3749
  message: "Path must be relative and not traverse up"
3588
3750
  });
3589
- var REMOTE_SCHEMA = z15.string().min(1).max(128).regex(/^[a-zA-Z0-9_\-.]+$/);
3590
- var BRANCH_SCHEMA = z15.string().min(1).max(256).regex(/^[a-zA-Z0-9._\-/]+$/);
3751
+ var REMOTE_SCHEMA = z16.string().min(1).max(128).regex(/^[a-zA-Z0-9_\-.]+$/);
3752
+ var BRANCH_SCHEMA = z16.string().min(1).max(256).regex(/^[a-zA-Z0-9._\-/]+$/);
3591
3753
  async function resolveServiceContext(serviceId) {
3592
3754
  const service2 = await serviceStore.get(serviceId);
3593
3755
  if (!service2) {
3594
- throw new TRPCError11({ code: "NOT_FOUND", message: "Service not found" });
3756
+ throw new TRPCError12({ code: "NOT_FOUND", message: "Service not found" });
3595
3757
  }
3596
3758
  const agentId = await resolveEffectiveAgentId(service2);
3597
3759
  if (!agentId) {
3598
- throw new TRPCError11({ code: "BAD_REQUEST", message: "No agent configured for this service" });
3760
+ throw new TRPCError12({ code: "BAD_REQUEST", message: "No agent configured for this service" });
3599
3761
  }
3600
3762
  return { agentId, cwd: await resolveWorkspaceCwd({ serviceId }) };
3601
3763
  }
3602
3764
  var gitTargetShape = {
3603
3765
  serviceId: SERVICE_ID_SCHEMA.optional(),
3604
- agentId: z15.string().max(128).optional(),
3766
+ agentId: z16.string().max(128).optional(),
3605
3767
  /** Anchors on a project when no service is targeted (e.g. from the AI chat). */
3606
- projectId: z15.string().max(128).optional(),
3768
+ projectId: z16.string().max(128).optional(),
3607
3769
  /** Son organisation : un id de projet seul peut en nommer un par organisation. */
3608
- orgId: z15.string().max(128).nullable().optional()
3770
+ orgId: z16.string().max(128).nullable().optional()
3609
3771
  };
3610
3772
  async function resolveGitContext(input) {
3611
3773
  if (input.serviceId) return resolveServiceContext(input.serviceId);
3612
3774
  const agentId = input.agentId ?? agentManager.getDefaultAgentId();
3613
3775
  if (!agentId) {
3614
- throw new TRPCError11({ code: "BAD_REQUEST", message: "No agent available" });
3776
+ throw new TRPCError12({ code: "BAD_REQUEST", message: "No agent available" });
3615
3777
  }
3616
3778
  const cwd = await resolveAgentCwd({ projectId: input.projectId, orgId: input.orgId }) ?? ".";
3617
3779
  return { agentId, cwd };
3618
3780
  }
3619
3781
  var gitRouter = router({
3620
3782
  /** Get full git status */
3621
- status: protectedProcedure.input(z15.object({ ...gitTargetShape })).query(async ({ input }) => {
3783
+ status: protectedProcedure.input(z16.object({ ...gitTargetShape })).query(async ({ input }) => {
3622
3784
  const { agentId, cwd } = await resolveGitContext(input);
3623
3785
  return agentManager.agentQuery(agentId, "git.status", { cwd });
3624
3786
  }),
3625
3787
  /** Get commit log */
3626
- log: protectedProcedure.input(z15.object({ ...gitTargetShape, limit: z15.number().int().min(1).max(200).default(50) })).query(async ({ input }) => {
3788
+ log: protectedProcedure.input(z16.object({ ...gitTargetShape, limit: z16.number().int().min(1).max(200).default(50) })).query(async ({ input }) => {
3627
3789
  const { agentId, cwd } = await resolveGitContext(input);
3628
3790
  return agentManager.agentQuery(agentId, "git.log", { cwd, limit: input.limit });
3629
3791
  }),
3630
3792
  /** List local and remote branches */
3631
- branches: protectedProcedure.input(z15.object({ ...gitTargetShape })).query(async ({ input }) => {
3793
+ branches: protectedProcedure.input(z16.object({ ...gitTargetShape })).query(async ({ input }) => {
3632
3794
  const { agentId, cwd } = await resolveGitContext(input);
3633
3795
  return agentManager.agentQuery(agentId, "git.branches", { cwd });
3634
3796
  }),
3635
3797
  /** Checkout a branch */
3636
- checkout: protectedProcedure.input(z15.object({ ...gitTargetShape, branch: BRANCH_SCHEMA, create: z15.boolean().default(false) })).mutation(async ({ input }) => {
3798
+ checkout: protectedProcedure.input(z16.object({ ...gitTargetShape, branch: BRANCH_SCHEMA, create: z16.boolean().default(false) })).mutation(async ({ input }) => {
3637
3799
  const { agentId, cwd } = await resolveGitContext(input);
3638
3800
  return agentManager.agentMutation(agentId, "git.checkout", { cwd, branch: input.branch, create: input.create });
3639
3801
  }),
3640
3802
  /** Stage files */
3641
- stage: protectedProcedure.input(z15.object({ ...gitTargetShape, paths: z15.array(SAFE_PATH_SCHEMA).min(1).max(500) })).mutation(async ({ input }) => {
3803
+ stage: protectedProcedure.input(z16.object({ ...gitTargetShape, paths: z16.array(SAFE_PATH_SCHEMA).min(1).max(500) })).mutation(async ({ input }) => {
3642
3804
  const { agentId, cwd } = await resolveGitContext(input);
3643
3805
  return agentManager.agentMutation(agentId, "git.stage", { cwd, paths: input.paths });
3644
3806
  }),
3645
3807
  /** Stage all files */
3646
- stageAll: protectedProcedure.input(z15.object({ ...gitTargetShape })).mutation(async ({ input }) => {
3808
+ stageAll: protectedProcedure.input(z16.object({ ...gitTargetShape })).mutation(async ({ input }) => {
3647
3809
  const { agentId, cwd } = await resolveGitContext(input);
3648
3810
  return agentManager.agentMutation(agentId, "git.stageAll", { cwd });
3649
3811
  }),
3650
3812
  /** Unstage files */
3651
- unstage: protectedProcedure.input(z15.object({ ...gitTargetShape, paths: z15.array(SAFE_PATH_SCHEMA).min(1).max(500) })).mutation(async ({ input }) => {
3813
+ unstage: protectedProcedure.input(z16.object({ ...gitTargetShape, paths: z16.array(SAFE_PATH_SCHEMA).min(1).max(500) })).mutation(async ({ input }) => {
3652
3814
  const { agentId, cwd } = await resolveGitContext(input);
3653
3815
  return agentManager.agentMutation(agentId, "git.unstage", { cwd, paths: input.paths });
3654
3816
  }),
3655
3817
  /** Unstage all files */
3656
- unstageAll: protectedProcedure.input(z15.object({ ...gitTargetShape })).mutation(async ({ input }) => {
3818
+ unstageAll: protectedProcedure.input(z16.object({ ...gitTargetShape })).mutation(async ({ input }) => {
3657
3819
  const { agentId, cwd } = await resolveGitContext(input);
3658
3820
  return agentManager.agentMutation(agentId, "git.unstageAll", { cwd });
3659
3821
  }),
3660
3822
  /** Commit staged changes */
3661
- commit: protectedProcedure.input(z15.object({ ...gitTargetShape, message: z15.string().min(1).max(4096) })).mutation(async ({ input }) => {
3823
+ commit: protectedProcedure.input(z16.object({ ...gitTargetShape, message: z16.string().min(1).max(4096) })).mutation(async ({ input }) => {
3662
3824
  const { agentId, cwd } = await resolveGitContext(input);
3663
3825
  return agentManager.agentMutation(agentId, "git.commit", { cwd, message: input.message });
3664
3826
  }),
3665
3827
  /** Push to remote */
3666
- push: protectedProcedure.input(z15.object({ ...gitTargetShape, remote: REMOTE_SCHEMA.default("origin"), setUpstream: z15.boolean().default(false) })).mutation(async ({ input }) => {
3828
+ push: protectedProcedure.input(z16.object({ ...gitTargetShape, remote: REMOTE_SCHEMA.default("origin"), setUpstream: z16.boolean().default(false) })).mutation(async ({ input }) => {
3667
3829
  const { agentId, cwd } = await resolveGitContext(input);
3668
3830
  return agentManager.agentMutation(agentId, "git.push", { cwd, remote: input.remote, setUpstream: input.setUpstream });
3669
3831
  }),
3670
3832
  /** Pull from remote */
3671
- pull: protectedProcedure.input(z15.object({ ...gitTargetShape, remote: REMOTE_SCHEMA.default("origin") })).mutation(async ({ input }) => {
3833
+ pull: protectedProcedure.input(z16.object({ ...gitTargetShape, remote: REMOTE_SCHEMA.default("origin") })).mutation(async ({ input }) => {
3672
3834
  const { agentId, cwd } = await resolveGitContext(input);
3673
3835
  return agentManager.agentMutation(agentId, "git.pull", { cwd, remote: input.remote });
3674
3836
  }),
3675
3837
  /** Fetch from remote */
3676
- fetch: protectedProcedure.input(z15.object({ ...gitTargetShape, remote: REMOTE_SCHEMA.default("origin") })).mutation(async ({ input }) => {
3838
+ fetch: protectedProcedure.input(z16.object({ ...gitTargetShape, remote: REMOTE_SCHEMA.default("origin") })).mutation(async ({ input }) => {
3677
3839
  const { agentId, cwd } = await resolveGitContext(input);
3678
3840
  return agentManager.agentMutation(agentId, "git.fetch", { cwd, remote: input.remote });
3679
3841
  }),
3680
3842
  /** Get diff for a file or the whole index */
3681
- diff: protectedProcedure.input(z15.object({
3843
+ diff: protectedProcedure.input(z16.object({
3682
3844
  ...gitTargetShape,
3683
- path: z15.string().max(4096).optional(),
3684
- staged: z15.boolean().default(false),
3685
- untracked: z15.boolean().default(false)
3845
+ path: z16.string().max(4096).optional(),
3846
+ staged: z16.boolean().default(false),
3847
+ untracked: z16.boolean().default(false)
3686
3848
  })).query(async ({ input }) => {
3687
3849
  const { agentId, cwd } = await resolveGitContext(input);
3688
3850
  return agentManager.agentQuery(agentId, "git.diff", { cwd, path: input.path, staged: input.staged, untracked: input.untracked });
3689
3851
  }),
3690
3852
  /** Discard changes to working tree files */
3691
- discard: protectedProcedure.input(z15.object({ ...gitTargetShape, paths: z15.array(SAFE_PATH_SCHEMA).min(1).max(500) })).mutation(async ({ input }) => {
3853
+ discard: protectedProcedure.input(z16.object({ ...gitTargetShape, paths: z16.array(SAFE_PATH_SCHEMA).min(1).max(500) })).mutation(async ({ input }) => {
3692
3854
  const { agentId, cwd } = await resolveGitContext(input);
3693
3855
  return agentManager.agentMutation(agentId, "git.discard", { cwd, paths: input.paths });
3694
3856
  }),
3695
3857
  /** Generate a commit message from staged diffs using AI (diff fetched from agent, AI runs on server) */
3696
- generateCommitMessage: protectedProcedure.input(z15.object({ ...gitTargetShape, providerId: OptionalProviderIdSchema, model: z15.string().max(200).optional() })).mutation(async ({ input }) => {
3858
+ generateCommitMessage: protectedProcedure.input(z16.object({ ...gitTargetShape, providerId: OptionalProviderIdSchema, model: z16.string().max(200).optional() })).mutation(async ({ input }) => {
3697
3859
  const { agentId, cwd } = await resolveGitContext(input);
3698
3860
  const { diff } = await agentManager.agentQuery(agentId, "git.stagedDiff", { cwd });
3699
3861
  if (!diff.trim()) {
3700
- throw new TRPCError11({ code: "BAD_REQUEST", message: "No staged changes to generate a commit message from" });
3862
+ throw new TRPCError12({ code: "BAD_REQUEST", message: "No staged changes to generate a commit message from" });
3701
3863
  }
3702
3864
  const active = await getActiveProvider(
3703
3865
  input.providerId,
3704
3866
  input.orgId ?? await vaultOfProject(input.projectId)
3705
3867
  );
3706
3868
  if (!active) {
3707
- throw new TRPCError11({ code: "BAD_REQUEST", message: "No AI provider configured" });
3869
+ throw new TRPCError12({ code: "BAD_REQUEST", message: "No AI provider configured" });
3708
3870
  }
3709
3871
  const systemPrompt = `You are a git commit message generator. Given a git diff, write a concise and meaningful conventional commit message (e.g. feat:, fix:, refactor:, chore:, docs:, style:, test:).
3710
3872
  Rules:
@@ -3737,45 +3899,45 @@ Rules:
3737
3899
  });
3738
3900
  return { message: res.choices[0]?.message?.content?.trim() ?? "" };
3739
3901
  }
3740
- throw new TRPCError11({ code: "BAD_REQUEST", message: "Unsupported AI provider" });
3902
+ throw new TRPCError12({ code: "BAD_REQUEST", message: "Unsupported AI provider" });
3741
3903
  }),
3742
3904
  /** Merge a branch into the current branch */
3743
- merge: protectedProcedure.input(z15.object({ ...gitTargetShape, branch: BRANCH_SCHEMA, noFf: z15.boolean().default(false) })).mutation(async ({ input }) => {
3905
+ merge: protectedProcedure.input(z16.object({ ...gitTargetShape, branch: BRANCH_SCHEMA, noFf: z16.boolean().default(false) })).mutation(async ({ input }) => {
3744
3906
  const { agentId, cwd } = await resolveGitContext(input);
3745
3907
  return agentManager.agentMutation(agentId, "git.merge", { cwd, branch: input.branch, noFf: input.noFf });
3746
3908
  }),
3747
3909
  /** Rebase current branch onto another branch */
3748
- rebase: protectedProcedure.input(z15.object({ ...gitTargetShape, branch: BRANCH_SCHEMA })).mutation(async ({ input }) => {
3910
+ rebase: protectedProcedure.input(z16.object({ ...gitTargetShape, branch: BRANCH_SCHEMA })).mutation(async ({ input }) => {
3749
3911
  const { agentId, cwd } = await resolveGitContext(input);
3750
3912
  return agentManager.agentMutation(agentId, "git.rebase", { cwd, branch: input.branch });
3751
3913
  }),
3752
3914
  /** List stash entries */
3753
- stashList: protectedProcedure.input(z15.object({ ...gitTargetShape })).query(async ({ input }) => {
3915
+ stashList: protectedProcedure.input(z16.object({ ...gitTargetShape })).query(async ({ input }) => {
3754
3916
  const { agentId, cwd } = await resolveGitContext(input);
3755
3917
  return agentManager.agentQuery(agentId, "git.stashList", { cwd });
3756
3918
  }),
3757
3919
  /** Stash current changes */
3758
- stashPush: protectedProcedure.input(z15.object({ ...gitTargetShape, message: z15.string().max(4096).optional(), includeUntracked: z15.boolean().default(true) })).mutation(async ({ input }) => {
3920
+ stashPush: protectedProcedure.input(z16.object({ ...gitTargetShape, message: z16.string().max(4096).optional(), includeUntracked: z16.boolean().default(true) })).mutation(async ({ input }) => {
3759
3921
  const { agentId, cwd } = await resolveGitContext(input);
3760
3922
  return agentManager.agentMutation(agentId, "git.stashPush", { cwd, message: input.message, includeUntracked: input.includeUntracked });
3761
3923
  }),
3762
3924
  /** Pop a stash entry */
3763
- stashPop: protectedProcedure.input(z15.object({ ...gitTargetShape, index: z15.number().int().min(0).max(1e3).default(0) })).mutation(async ({ input }) => {
3925
+ stashPop: protectedProcedure.input(z16.object({ ...gitTargetShape, index: z16.number().int().min(0).max(1e3).default(0) })).mutation(async ({ input }) => {
3764
3926
  const { agentId, cwd } = await resolveGitContext(input);
3765
3927
  return agentManager.agentMutation(agentId, "git.stashPop", { cwd, index: input.index });
3766
3928
  }),
3767
3929
  /** Apply a stash entry without dropping it */
3768
- stashApply: protectedProcedure.input(z15.object({ ...gitTargetShape, index: z15.number().int().min(0).max(1e3).default(0) })).mutation(async ({ input }) => {
3930
+ stashApply: protectedProcedure.input(z16.object({ ...gitTargetShape, index: z16.number().int().min(0).max(1e3).default(0) })).mutation(async ({ input }) => {
3769
3931
  const { agentId, cwd } = await resolveGitContext(input);
3770
3932
  return agentManager.agentMutation(agentId, "git.stashApply", { cwd, index: input.index });
3771
3933
  }),
3772
3934
  /** Drop a stash entry */
3773
- stashDrop: protectedProcedure.input(z15.object({ ...gitTargetShape, index: z15.number().int().min(0).max(1e3).default(0) })).mutation(async ({ input }) => {
3935
+ stashDrop: protectedProcedure.input(z16.object({ ...gitTargetShape, index: z16.number().int().min(0).max(1e3).default(0) })).mutation(async ({ input }) => {
3774
3936
  const { agentId, cwd } = await resolveGitContext(input);
3775
3937
  return agentManager.agentMutation(agentId, "git.stashDrop", { cwd, index: input.index });
3776
3938
  }),
3777
3939
  /** Watch .git/ for changes and stream updated status */
3778
- onStatusChange: protectedProcedure.input(z15.object({ ...gitTargetShape })).subscription(async function* ({ input }) {
3940
+ onStatusChange: protectedProcedure.input(z16.object({ ...gitTargetShape })).subscription(async function* ({ input }) {
3779
3941
  const { agentId, cwd } = await resolveGitContext(input);
3780
3942
  const queue = [];
3781
3943
  let resolve5 = null;
@@ -3802,7 +3964,7 @@ Rules:
3802
3964
  }
3803
3965
  );
3804
3966
  } catch (err) {
3805
- throw new TRPCError11({
3967
+ throw new TRPCError12({
3806
3968
  code: "BAD_REQUEST",
3807
3969
  message: `Cannot subscribe to git status: ${err.message}`
3808
3970
  });
@@ -3822,7 +3984,7 @@ Rules:
3822
3984
  }
3823
3985
  }),
3824
3986
  /** List remotes */
3825
- remotes: protectedProcedure.input(z15.object({ ...gitTargetShape })).query(async ({ input }) => {
3987
+ remotes: protectedProcedure.input(z16.object({ ...gitTargetShape })).query(async ({ input }) => {
3826
3988
  const { agentId, cwd } = await resolveGitContext(input);
3827
3989
  return agentManager.agentQuery(agentId, "git.remotes", { cwd });
3828
3990
  })
@@ -3830,41 +3992,41 @@ Rules:
3830
3992
 
3831
3993
  // ../server/src/trpc/routers/scenario.ts
3832
3994
  import { randomUUID as randomUUID3 } from "crypto";
3833
- import { TRPCError as TRPCError14 } from "@trpc/server";
3834
- import { z as z16 } from "zod";
3995
+ import { TRPCError as TRPCError15 } from "@trpc/server";
3996
+ import { z as z17 } from "zod";
3835
3997
 
3836
3998
  // ../server/src/trpc/crud-procedure-utils.ts
3837
- import { TRPCError as TRPCError12 } from "@trpc/server";
3999
+ import { TRPCError as TRPCError13 } from "@trpc/server";
3838
4000
  async function getOrNotFound(getter, notFoundMessage) {
3839
4001
  const entity = await getter();
3840
- if (!entity) throw new TRPCError12({ code: "NOT_FOUND", message: notFoundMessage });
4002
+ if (!entity) throw new TRPCError13({ code: "NOT_FOUND", message: notFoundMessage });
3841
4003
  return entity;
3842
4004
  }
3843
4005
  async function createOrBadRequest(creator) {
3844
4006
  try {
3845
4007
  return await creator();
3846
4008
  } catch (err) {
3847
- throw new TRPCError12({ code: "BAD_REQUEST", message: err.message });
4009
+ throw new TRPCError13({ code: "BAD_REQUEST", message: err.message });
3848
4010
  }
3849
4011
  }
3850
4012
  async function updateOrThrow(updater, notFoundMessage) {
3851
4013
  try {
3852
4014
  const entity = await updater();
3853
- if (!entity) throw new TRPCError12({ code: "NOT_FOUND", message: notFoundMessage });
4015
+ if (!entity) throw new TRPCError13({ code: "NOT_FOUND", message: notFoundMessage });
3854
4016
  return entity;
3855
4017
  } catch (err) {
3856
- if (err instanceof TRPCError12) throw err;
3857
- throw new TRPCError12({ code: "BAD_REQUEST", message: err.message });
4018
+ if (err instanceof TRPCError13) throw err;
4019
+ throw new TRPCError13({ code: "BAD_REQUEST", message: err.message });
3858
4020
  }
3859
4021
  }
3860
4022
  async function deleteOrNotFound(deleter, notFoundMessage) {
3861
4023
  const deleted = await deleter();
3862
- if (!deleted) throw new TRPCError12({ code: "NOT_FOUND", message: notFoundMessage });
4024
+ if (!deleted) throw new TRPCError13({ code: "NOT_FOUND", message: notFoundMessage });
3863
4025
  return { ok: true };
3864
4026
  }
3865
4027
 
3866
4028
  // ../server/src/trpc/ai-generation-procedure-utils.ts
3867
- import { TRPCError as TRPCError13 } from "@trpc/server";
4029
+ import { TRPCError as TRPCError14 } from "@trpc/server";
3868
4030
 
3869
4031
  // ../server/src/services/ai-generation.ts
3870
4032
  import Anthropic2 from "@anthropic-ai/sdk";
@@ -3920,7 +4082,7 @@ async function* streamProviderText(input) {
3920
4082
  // ../server/src/trpc/ai-generation-procedure-utils.ts
3921
4083
  async function* streamWithActiveProvider(opts) {
3922
4084
  const active = await getActiveProvider(opts.providerId, opts.vault);
3923
- if (!active) throw new TRPCError13({ code: "BAD_REQUEST", message: "Aucun fournisseur IA configur\xE9" });
4085
+ if (!active) throw new TRPCError14({ code: "BAD_REQUEST", message: "Aucun fournisseur IA configur\xE9" });
3924
4086
  const { provider, plaintextKey } = active;
3925
4087
  const model = opts.model || provider.model || DEFAULT_MODELS[provider.provider] || "";
3926
4088
  try {
@@ -3938,7 +4100,7 @@ async function* streamWithActiveProvider(opts) {
3938
4100
  yield { type: "done", text: "" };
3939
4101
  } catch (err) {
3940
4102
  if (String(err?.message ?? "").startsWith("Unsupported provider:")) {
3941
- throw new TRPCError13({ code: "BAD_REQUEST", message: `Fournisseur non support\xE9: ${provider.provider}` });
4103
+ throw new TRPCError14({ code: "BAD_REQUEST", message: `Fournisseur non support\xE9: ${provider.provider}` });
3942
4104
  }
3943
4105
  throw err;
3944
4106
  }
@@ -3947,7 +4109,7 @@ async function* streamWithActiveProvider(opts) {
3947
4109
  // ../server/src/services/scenario-runner.ts
3948
4110
  import { mkdir as mkdir4 } from "fs/promises";
3949
4111
  import { randomUUID as randomUUID2 } from "crypto";
3950
- import { join as join6 } from "path";
4112
+ import { join as join7 } from "path";
3951
4113
 
3952
4114
  // ../server/src/services/scenario-presets-fr.ts
3953
4115
  var lines = (...l) => l.join("\n");
@@ -5666,8 +5828,8 @@ async function nodeRuneyaAccess(conversationId) {
5666
5828
  let injectedEnv;
5667
5829
  if (ref?.id) {
5668
5830
  try {
5669
- const { projectStore: projectStore2 } = await import("./project-store-6TFAYAWK.js");
5670
- const { environmentResolver: environmentResolver2 } = await import("./environment-resolver-HT6GTSLA.js");
5831
+ const { projectStore: projectStore2 } = await import("./project-store-HHMB2DIU.js");
5832
+ const { environmentResolver: environmentResolver2 } = await import("./environment-resolver-S3QD7UJH.js");
5671
5833
  const project = await projectStore2.get(ref.orgId ? { id: ref.id, orgId: ref.orgId } : ref.id);
5672
5834
  if (project?.activeEnvironmentId) {
5673
5835
  const injected = await environmentResolver2.resolveAiInjectedEnv(project.activeEnvironmentId);
@@ -5806,7 +5968,7 @@ async function appendNodeOutput(conversationId, node, output) {
5806
5968
  if (!dir) return;
5807
5969
  const slug = node.label.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 60) || "member";
5808
5970
  const safeId = node.id.replace(/[^a-z0-9_-]/gi, "-").slice(0, 80);
5809
- const filePath = join6(dir, `${slug}_${safeId}.md`);
5971
+ const filePath = join7(dir, `${slug}_${safeId}.md`);
5810
5972
  const content = `## Output
5811
5973
 
5812
5974
  ${output}
@@ -5821,7 +5983,7 @@ async function appendToReadme(conversationId, bus, text) {
5821
5983
  try {
5822
5984
  await mkdir4(dir, { recursive: true });
5823
5985
  const { appendFile } = await import("fs/promises");
5824
- await appendFile(join6(dir, "README.md"), line, "utf-8");
5986
+ await appendFile(join7(dir, "README.md"), line, "utf-8");
5825
5987
  } catch {
5826
5988
  }
5827
5989
  publishToBus(bus, { type: "readme_append", text: line });
@@ -5841,7 +6003,7 @@ async function writeFinalMd(conversationId, bus, userRequest, content) {
5841
6003
 
5842
6004
  ${content}
5843
6005
  `;
5844
- const filePath = join6(dir, "FINAL.md");
6006
+ const filePath = join7(dir, "FINAL.md");
5845
6007
  await atomicWriteSecure(filePath, fullContent);
5846
6008
  await appendToReadme(
5847
6009
  conversationId,
@@ -6521,29 +6683,29 @@ Modify the scenario. Keep existing ids when possible.`;
6521
6683
  return `Generate an scenario org-chart based on: ${userPrompt}`;
6522
6684
  }
6523
6685
  var ScopeShape2 = {
6524
- orgId: z16.string().max(128).nullable().optional(),
6686
+ orgId: z17.string().max(128).nullable().optional(),
6525
6687
  projectId: Id128Schema.optional()
6526
6688
  };
6527
6689
  async function scopeOf2(input) {
6528
6690
  return input?.orgId ?? await vaultOfProject(input?.projectId);
6529
6691
  }
6530
6692
  var scenarioRouter = router({
6531
- list: protectedProcedure.input(z16.object(ScopeShape2).optional()).query(async ({ input }) => scenarioStore.list(await scopeOf2(input))),
6532
- get: protectedProcedure.input(z16.object({ id: Id128Schema, ...ScopeShape2 })).query(async ({ input }) => getOrNotFound(
6693
+ list: protectedProcedure.input(z17.object(ScopeShape2).optional()).query(async ({ input }) => scenarioStore.list(await scopeOf2(input))),
6694
+ get: protectedProcedure.input(z17.object({ id: Id128Schema, ...ScopeShape2 })).query(async ({ input }) => getOrNotFound(
6533
6695
  async () => scenarioStore.get(input.id, await scopeOf2(input)),
6534
6696
  "Scenario not found"
6535
6697
  )),
6536
- create: protectedProcedure.input(z16.object({
6698
+ create: protectedProcedure.input(z17.object({
6537
6699
  name: NameSchema,
6538
- icon: z16.string().max(64).optional(),
6700
+ icon: z17.string().max(64).optional(),
6539
6701
  description: DescriptionSchema.optional(),
6540
6702
  leaderId: Id128Schema,
6541
- groups: z16.array(ScenarioGroupSchema).max(100).optional(),
6542
- nodes: z16.array(ScenarioNodeSchema).min(1).max(500),
6543
- traversalMode: z16.enum(["hierarchical", "topological"]).optional(),
6544
- presetId: z16.string().max(128).optional(),
6545
- locale: z16.string().max(16).optional(),
6546
- isPublished: z16.boolean().optional(),
6703
+ groups: z17.array(ScenarioGroupSchema).max(100).optional(),
6704
+ nodes: z17.array(ScenarioNodeSchema).min(1).max(500),
6705
+ traversalMode: z17.enum(["hierarchical", "topological"]).optional(),
6706
+ presetId: z17.string().max(128).optional(),
6707
+ locale: z17.string().max(16).optional(),
6708
+ isPublished: z17.boolean().optional(),
6547
6709
  ...ScopeShape2
6548
6710
  })).mutation(({ input }) => {
6549
6711
  const now = Date.now();
@@ -6563,18 +6725,18 @@ var scenarioRouter = router({
6563
6725
  updatedAt: now
6564
6726
  }, await scopeOf2(input)));
6565
6727
  }),
6566
- update: protectedProcedure.input(z16.object({
6728
+ update: protectedProcedure.input(z17.object({
6567
6729
  id: Id128Schema,
6568
6730
  name: NameSchema.optional(),
6569
- icon: z16.string().max(64).optional(),
6731
+ icon: z17.string().max(64).optional(),
6570
6732
  description: DescriptionSchema.optional(),
6571
6733
  leaderId: Id128Schema.optional(),
6572
- groups: z16.array(ScenarioGroupSchema).max(100).optional(),
6573
- nodes: z16.array(ScenarioNodeSchema).min(1).max(500).optional(),
6574
- traversalMode: z16.enum(["hierarchical", "topological"]).optional(),
6575
- presetId: z16.string().max(128).optional(),
6576
- locale: z16.string().max(16).optional(),
6577
- isPublished: z16.boolean().optional(),
6734
+ groups: z17.array(ScenarioGroupSchema).max(100).optional(),
6735
+ nodes: z17.array(ScenarioNodeSchema).min(1).max(500).optional(),
6736
+ traversalMode: z17.enum(["hierarchical", "topological"]).optional(),
6737
+ presetId: z17.string().max(128).optional(),
6738
+ locale: z17.string().max(16).optional(),
6739
+ isPublished: z17.boolean().optional(),
6578
6740
  ...ScopeShape2
6579
6741
  })).mutation(({ input }) => updateOrThrow(
6580
6742
  async () => scenarioStore.update(input.id, {
@@ -6592,26 +6754,26 @@ var scenarioRouter = router({
6592
6754
  }, await scopeOf2(input)),
6593
6755
  "Scenario not found"
6594
6756
  )),
6595
- delete: protectedProcedure.input(z16.object({ id: Id128Schema, ...ScopeShape2 })).mutation(({ input }) => deleteOrNotFound(
6757
+ delete: protectedProcedure.input(z17.object({ id: Id128Schema, ...ScopeShape2 })).mutation(({ input }) => deleteOrNotFound(
6596
6758
  async () => scenarioStore.delete(input.id, await scopeOf2(input)),
6597
6759
  "Scenario not found"
6598
6760
  )),
6599
- run: protectedProcedure.input(z16.object({
6761
+ run: protectedProcedure.input(z17.object({
6600
6762
  conversationId: ConversationIdSchema,
6601
6763
  scenarioId: Id128Schema,
6602
- userRequest: z16.string().max(1e5),
6603
- runnerOverride: z16.enum(["claude-code", "codex"]).optional(),
6764
+ userRequest: z17.string().max(1e5),
6765
+ runnerOverride: z17.enum(["claude-code", "codex"]).optional(),
6604
6766
  modelOverride: Id128Schema.optional(),
6605
6767
  agentId: Id128Schema.optional(),
6606
6768
  /** Anchors the run's working directory on the project it belongs to. */
6607
6769
  projectId: Id128Schema.optional(),
6608
6770
  /** Son organisation : sans elle, un id partagé désignerait un projet au hasard. */
6609
- orgId: z16.string().max(128).nullable().optional(),
6610
- resume: z16.boolean().optional()
6771
+ orgId: z17.string().max(128).nullable().optional(),
6772
+ resume: z17.boolean().optional()
6611
6773
  })).subscription(async function* ({ input, signal }) {
6612
6774
  const vault = await scopeOf2(input);
6613
6775
  const scenario = await scenarioStore.get(input.scenarioId, vault);
6614
- if (!scenario) throw new TRPCError14({ code: "NOT_FOUND", message: "Scenario not found" });
6776
+ if (!scenario) throw new TRPCError15({ code: "NOT_FOUND", message: "Scenario not found" });
6615
6777
  const canStart = input.userRequest.trim().length > 0 || !!input.resume;
6616
6778
  if (!isScenarioRunning(input.conversationId) && canStart) {
6617
6779
  let userRequest = input.userRequest;
@@ -6628,41 +6790,41 @@ var scenarioRouter = router({
6628
6790
  }
6629
6791
  yield* tapBus(input.conversationId, signal ?? new AbortController().signal);
6630
6792
  }),
6631
- stop: protectedProcedure.input(z16.object({ conversationId: ConversationIdSchema })).mutation(({ input }) => {
6793
+ stop: protectedProcedure.input(z17.object({ conversationId: ConversationIdSchema })).mutation(({ input }) => {
6632
6794
  abortScenario(input.conversationId);
6633
6795
  return { ok: true };
6634
6796
  }),
6635
- sendNodeInput: protectedProcedure.input(z16.object({
6797
+ sendNodeInput: protectedProcedure.input(z17.object({
6636
6798
  conversationId: ConversationIdSchema,
6637
6799
  nodeId: Id128Schema,
6638
- text: z16.string().min(1).max(1e5)
6800
+ text: z17.string().min(1).max(1e5)
6639
6801
  })).mutation(({ input }) => {
6640
6802
  const resolved = resolveNodeInput(input.conversationId, input.nodeId, input.text);
6641
- if (!resolved) throw new TRPCError14({ code: "NOT_FOUND", message: "No pending input request for this node" });
6803
+ if (!resolved) throw new TRPCError15({ code: "NOT_FOUND", message: "No pending input request for this node" });
6642
6804
  return { ok: true };
6643
6805
  }),
6644
- isRunning: protectedProcedure.input(z16.object({ conversationId: ConversationIdSchema })).query(({ input }) => ({ running: isScenarioRunning(input.conversationId) })),
6645
- runState: protectedProcedure.input(z16.object({ conversationId: ConversationIdSchema })).query(({ input }) => {
6806
+ isRunning: protectedProcedure.input(z17.object({ conversationId: ConversationIdSchema })).query(({ input }) => ({ running: isScenarioRunning(input.conversationId) })),
6807
+ runState: protectedProcedure.input(z17.object({ conversationId: ConversationIdSchema })).query(({ input }) => {
6646
6808
  const runState = scenarioRunStore.getRunState(input.conversationId);
6647
6809
  return runState ?? { nodeStates: {}, nodeOutputs: {}, activeNodeId: void 0 };
6648
6810
  }),
6649
- getPersistedRunState: protectedProcedure.input(z16.object({ conversationId: ConversationIdSchema })).query(async ({ input }) => {
6811
+ getPersistedRunState: protectedProcedure.input(z17.object({ conversationId: ConversationIdSchema })).query(async ({ input }) => {
6650
6812
  return await scenarioRunStore.loadPersistedRunState(input.conversationId);
6651
6813
  }),
6652
- getReadme: protectedProcedure.input(z16.object({ conversationId: ConversationIdSchema })).query(async ({ input }) => {
6814
+ getReadme: protectedProcedure.input(z17.object({ conversationId: ConversationIdSchema })).query(async ({ input }) => {
6653
6815
  return await scenarioRunStore.readReadme(input.conversationId);
6654
6816
  }),
6655
- getSnapshot: protectedProcedure.input(z16.object({ conversationId: ConversationIdSchema })).query(async ({ input }) => {
6817
+ getSnapshot: protectedProcedure.input(z17.object({ conversationId: ConversationIdSchema })).query(async ({ input }) => {
6656
6818
  return await scenarioRunStore.loadScenarioSnapshot(input.conversationId);
6657
6819
  }),
6658
- streamGenerateWithAI: protectedProcedure.input(z16.object({
6659
- prompt: z16.string().min(1).max(1e4),
6820
+ streamGenerateWithAI: protectedProcedure.input(z17.object({
6821
+ prompt: z17.string().min(1).max(1e4),
6660
6822
  providerId: OptionalProviderIdSchema,
6661
- model: z16.string().max(200).optional(),
6662
- current: z16.object({
6823
+ model: z17.string().max(200).optional(),
6824
+ current: z17.object({
6663
6825
  leaderId: Id128Schema,
6664
- groups: z16.array(ScenarioGroupSchema).max(100),
6665
- nodes: z16.array(ScenarioNodeSchema).max(500)
6826
+ groups: z17.array(ScenarioGroupSchema).max(100),
6827
+ nodes: z17.array(ScenarioNodeSchema).max(500)
6666
6828
  }).optional()
6667
6829
  })).subscription(async function* ({ input, signal }) {
6668
6830
  const userMessage = buildScenarioUserMessage(input.prompt, input.current);
@@ -6675,7 +6837,7 @@ var scenarioRouter = router({
6675
6837
  signal: signal ?? void 0
6676
6838
  });
6677
6839
  }),
6678
- streamRunEvents: protectedProcedure.input(z16.object({ conversationId: ConversationIdSchema })).subscription(async function* ({ input }) {
6840
+ streamRunEvents: protectedProcedure.input(z17.object({ conversationId: ConversationIdSchema })).subscription(async function* ({ input }) {
6679
6841
  const convId = input.conversationId;
6680
6842
  const runState = scenarioRunStore.getRunState(convId);
6681
6843
  if (runState) {
@@ -6689,24 +6851,24 @@ var scenarioRouter = router({
6689
6851
  * open a debug PTY with `claude --resume <sessionId>` on the right agent.
6690
6852
  * Falls back to the persisted run-state for past nodes.
6691
6853
  */
6692
- getNodeSession: protectedProcedure.input(z16.object({
6854
+ getNodeSession: protectedProcedure.input(z17.object({
6693
6855
  conversationId: ConversationIdSchema,
6694
6856
  nodeId: Id128Schema
6695
6857
  })).query(async ({ input }) => {
6696
6858
  return await scenarioRunStore.getNodeSessionPersistent(input.conversationId, input.nodeId);
6697
6859
  }),
6698
6860
  listPresets: protectedProcedure.query(() => listPresets()),
6699
- getPreset: protectedProcedure.input(z16.object({ id: Id128Schema })).query(({ input }) => {
6861
+ getPreset: protectedProcedure.input(z17.object({ id: Id128Schema })).query(({ input }) => {
6700
6862
  const preset = getPreset(input.id);
6701
- if (!preset) throw new TRPCError14({ code: "NOT_FOUND", message: "Preset not found" });
6863
+ if (!preset) throw new TRPCError15({ code: "NOT_FOUND", message: "Preset not found" });
6702
6864
  return preset;
6703
6865
  })
6704
6866
  });
6705
6867
 
6706
6868
  // ../server/src/trpc/routers/debug.ts
6707
6869
  import { randomUUID as randomUUID4 } from "crypto";
6708
- import { TRPCError as TRPCError15 } from "@trpc/server";
6709
- import { z as z17 } from "zod";
6870
+ import { TRPCError as TRPCError16 } from "@trpc/server";
6871
+ import { z as z18 } from "zod";
6710
6872
  var MAX_BUFFER2 = 300;
6711
6873
  var jobs = /* @__PURE__ */ new Map();
6712
6874
  function publish(job, event) {
@@ -6763,9 +6925,9 @@ async function* tapJob(job, signal) {
6763
6925
  }
6764
6926
  }
6765
6927
  var debugRouter = router({
6766
- startRandomJob: protectedProcedure.input(z17.object({
6767
- intervalMs: z17.number().int().min(100).max(5e3).optional(),
6768
- maxTicks: z17.number().int().min(1).max(1e4).optional()
6928
+ startRandomJob: protectedProcedure.input(z18.object({
6929
+ intervalMs: z18.number().int().min(100).max(5e3).optional(),
6930
+ maxTicks: z18.number().int().min(1).max(1e4).optional()
6769
6931
  }).optional()).mutation(({ input }) => {
6770
6932
  const jobId = randomUUID4();
6771
6933
  const intervalMs = input?.intervalMs ?? 400;
@@ -6799,15 +6961,15 @@ var debugRouter = router({
6799
6961
  jobs.set(jobId, job);
6800
6962
  return { jobId, intervalMs, maxTicks, startedAt: job.startedAt };
6801
6963
  }),
6802
- streamRandomJob: protectedProcedure.input(z17.object({ jobId: z17.string().max(128) })).subscription(async function* ({ input, signal }) {
6964
+ streamRandomJob: protectedProcedure.input(z18.object({ jobId: z18.string().max(128) })).subscription(async function* ({ input, signal }) {
6803
6965
  const job = jobs.get(input.jobId);
6804
6966
  if (!job) {
6805
- throw new TRPCError15({ code: "NOT_FOUND", message: "Random job not found" });
6967
+ throw new TRPCError16({ code: "NOT_FOUND", message: "Random job not found" });
6806
6968
  }
6807
6969
  yield* tapJob(job, signal ?? new AbortController().signal);
6808
6970
  }),
6809
- stopRandomJob: protectedProcedure.input(z17.object({ jobId: z17.string().max(128) })).mutation(({ input }) => ({ ok: stopJob(input.jobId, "stopped") })),
6810
- randomJobStatus: protectedProcedure.input(z17.object({ jobId: z17.string().max(128) })).query(({ input }) => {
6971
+ stopRandomJob: protectedProcedure.input(z18.object({ jobId: z18.string().max(128) })).mutation(({ input }) => ({ ok: stopJob(input.jobId, "stopped") })),
6972
+ randomJobStatus: protectedProcedure.input(z18.object({ jobId: z18.string().max(128) })).query(({ input }) => {
6811
6973
  const job = jobs.get(input.jobId);
6812
6974
  return {
6813
6975
  running: !!job && !job.done,
@@ -6817,8 +6979,8 @@ var debugRouter = router({
6817
6979
  });
6818
6980
 
6819
6981
  // ../server/src/trpc/routers/diagnostics.ts
6820
- import { z as z18 } from "zod";
6821
- import { TRPCError as TRPCError16 } from "@trpc/server";
6982
+ import { z as z19 } from "zod";
6983
+ import { TRPCError as TRPCError17 } from "@trpc/server";
6822
6984
 
6823
6985
  // ../server/src/services/log-buffer.ts
6824
6986
  import { EventEmitter } from "events";
@@ -6889,7 +7051,7 @@ function onEntry(listener) {
6889
7051
  // ../server/src/trpc/routers/diagnostics.ts
6890
7052
  var diagnosticsRouter = router({
6891
7053
  /** Backlog for a client that just opened the panel. */
6892
- recentLogs: protectedProcedure.input(z18.object({ limit: z18.number().int().min(1).max(2e3).default(500) }).optional()).query(({ input }) => recentEntries(input?.limit ?? 500)),
7054
+ recentLogs: protectedProcedure.input(z19.object({ limit: z19.number().int().min(1).max(2e3).default(500) }).optional()).query(({ input }) => recentEntries(input?.limit ?? 500)),
6893
7055
  /**
6894
7056
  * Live log stream.
6895
7057
  *
@@ -6898,7 +7060,7 @@ var diagnosticsRouter = router({
6898
7060
  * silently loses lines, which is precisely what someone watching a boot
6899
7061
  * failure cannot afford.
6900
7062
  */
6901
- streamLogs: protectedProcedure.input(z18.object({ afterSeq: z18.number().int().nonnegative().default(0) }).optional()).subscription(async function* ({ input, signal }) {
7063
+ streamLogs: protectedProcedure.input(z19.object({ afterSeq: z19.number().int().nonnegative().default(0) }).optional()).subscription(async function* ({ input, signal }) {
6902
7064
  for (const entry of entriesSince(input?.afterSeq ?? 0)) yield entry;
6903
7065
  const queue = [];
6904
7066
  let wake = null;
@@ -6932,18 +7094,18 @@ var diagnosticsRouter = router({
6932
7094
  * refused. That is what keeps this from being a way to signal arbitrary
6933
7095
  * processes with the server's privileges.
6934
7096
  */
6935
- killInstance: protectedProcedure.input(z18.object({ pid: z18.number().int().positive() })).mutation(async ({ input }) => {
7097
+ killInstance: protectedProcedure.input(z19.object({ pid: z19.number().int().positive() })).mutation(async ({ input }) => {
6936
7098
  try {
6937
7099
  return await killInstance(input.pid);
6938
7100
  } catch (err) {
6939
7101
  const reason = err.message;
6940
7102
  if (reason === "instance-not-found") {
6941
- throw new TRPCError16({ code: "NOT_FOUND", message: "No live Runeya instance with this pid." });
7103
+ throw new TRPCError17({ code: "NOT_FOUND", message: "No live Runeya instance with this pid." });
6942
7104
  }
6943
7105
  if (reason === "instance-is-current") {
6944
- throw new TRPCError16({ code: "BAD_REQUEST", message: "This instance cannot stop itself." });
7106
+ throw new TRPCError17({ code: "BAD_REQUEST", message: "This instance cannot stop itself." });
6945
7107
  }
6946
- throw new TRPCError16({ code: "INTERNAL_SERVER_ERROR", message: reason });
7108
+ throw new TRPCError17({ code: "INTERNAL_SERVER_ERROR", message: reason });
6947
7109
  }
6948
7110
  }),
6949
7111
  /**
@@ -6960,7 +7122,7 @@ var diagnosticsRouter = router({
6960
7122
  * reproductible : instance trop ancienne pour avoir publié sa ligne de
6961
7123
  * commande, ou lancée avec un secret que le registre ne conserve pas.
6962
7124
  */
6963
- restartInstance: protectedProcedure.input(z18.object({ pid: z18.number().int().positive() })).mutation(async ({ input }) => {
7125
+ restartInstance: protectedProcedure.input(z19.object({ pid: z19.number().int().positive() })).mutation(async ({ input }) => {
6964
7126
  try {
6965
7127
  if (input.pid === process.pid) {
6966
7128
  const { relauncherPid, port } = await scheduleSelfRestart();
@@ -6970,39 +7132,39 @@ var diagnosticsRouter = router({
6970
7132
  } catch (err) {
6971
7133
  const reason = err.message;
6972
7134
  if (reason === "instance-not-found") {
6973
- throw new TRPCError16({ code: "NOT_FOUND", message: "No live Runeya instance with this pid." });
7135
+ throw new TRPCError17({ code: "NOT_FOUND", message: "No live Runeya instance with this pid." });
6974
7136
  }
6975
7137
  if (reason.startsWith("instance-not-restartable:")) {
6976
- throw new TRPCError16({
7138
+ throw new TRPCError17({
6977
7139
  code: "BAD_REQUEST",
6978
7140
  message: `This instance cannot be restarted (${reason.split(":")[1]}).`
6979
7141
  });
6980
7142
  }
6981
- throw new TRPCError16({ code: "INTERNAL_SERVER_ERROR", message: reason });
7143
+ throw new TRPCError17({ code: "INTERNAL_SERVER_ERROR", message: reason });
6982
7144
  }
6983
7145
  })
6984
7146
  });
6985
7147
 
6986
7148
  // ../server/src/trpc/routers/mcp-pairing.ts
6987
- import { z as z20 } from "zod";
6988
- import { TRPCError as TRPCError17 } from "@trpc/server";
7149
+ import { z as z21 } from "zod";
7150
+ import { TRPCError as TRPCError18 } from "@trpc/server";
6989
7151
 
6990
7152
  // ../server/src/services/mcp-pairing.ts
6991
7153
  import { createHash, randomBytes as randomBytes2, randomInt, randomUUID as randomUUID5, timingSafeEqual } from "crypto";
6992
7154
  import { readFile as readFile3 } from "fs/promises";
6993
- import { z as z19 } from "zod";
7155
+ import { z as z20 } from "zod";
6994
7156
  var REQUEST_TTL_MS = 2 * 60 * 1e3;
6995
7157
  var MCP_TOKEN_TTL = "15m";
6996
7158
  var FILE = "mcp-clients.json";
6997
- var McpClientSchema = z19.object({
6998
- id: z19.string().uuid(),
6999
- name: z19.string().min(1).max(100),
7000
- cwd: z19.string().max(4096),
7159
+ var McpClientSchema = z20.object({
7160
+ id: z20.string().uuid(),
7161
+ name: z20.string().min(1).max(100),
7162
+ cwd: z20.string().max(4096),
7001
7163
  /** SHA-256 du secret, en hexadécimal. */
7002
- secretHash: z19.string().regex(/^[0-9a-f]{64}$/),
7003
- createdAt: z19.string().max(64)
7164
+ secretHash: z20.string().regex(/^[0-9a-f]{64}$/),
7165
+ createdAt: z20.string().max(64)
7004
7166
  });
7005
- var McpClientsFileSchema = z19.object({ clients: z19.array(McpClientSchema).max(500) });
7167
+ var McpClientsFileSchema = z20.object({ clients: z20.array(McpClientSchema).max(500) });
7006
7168
  function hashSecret(secret) {
7007
7169
  return createHash("sha256").update(secret).digest("hex");
7008
7170
  }
@@ -7132,35 +7294,35 @@ var mcpPairing = new McpPairing(() => keyedFilePath(FILE));
7132
7294
  // ../server/src/trpc/routers/mcp-pairing.ts
7133
7295
  function asBadRequest(fn) {
7134
7296
  return Promise.resolve().then(fn).catch((err) => {
7135
- throw new TRPCError17({ code: "BAD_REQUEST", message: err.message });
7297
+ throw new TRPCError18({ code: "BAD_REQUEST", message: err.message });
7136
7298
  });
7137
7299
  }
7138
7300
  var mcpPairingRouter = router({
7139
- request: publicProcedure.input(z20.object({ name: z20.string().min(1).max(100), cwd: z20.string().max(4096) })).mutation(({ ctx, input }) => {
7301
+ request: publicProcedure.input(z21.object({ name: z21.string().min(1).max(100), cwd: z21.string().max(4096) })).mutation(({ ctx, input }) => {
7140
7302
  requireLoopback(ctx);
7141
7303
  if (isCiMode()) {
7142
- throw new TRPCError17({
7304
+ throw new TRPCError18({
7143
7305
  code: "PRECONDITION_FAILED",
7144
7306
  message: "Runeya tourne en mode CI : l'appairage y est d\xE9sactiv\xE9. Passe une cl\xE9 d'API dans RUNEYA_API_TOKEN."
7145
7307
  });
7146
7308
  }
7147
7309
  return asBadRequest(() => mcpPairing.request(input.name, input.cwd));
7148
7310
  }),
7149
- status: publicProcedure.input(z20.object({ requestId: z20.string().uuid() })).query(({ ctx, input }) => {
7311
+ status: publicProcedure.input(z21.object({ requestId: z21.string().uuid() })).query(({ ctx, input }) => {
7150
7312
  requireLoopback(ctx);
7151
7313
  return mcpPairing.status(input.requestId);
7152
7314
  }),
7153
- exchange: publicProcedure.input(z20.object({ secret: z20.string().min(1).max(200) })).mutation(({ ctx, input }) => {
7315
+ exchange: publicProcedure.input(z21.object({ secret: z21.string().min(1).max(200) })).mutation(({ ctx, input }) => {
7154
7316
  requireLoopback(ctx);
7155
7317
  return mcpPairing.exchange(input.secret).then((token) => ({ token })).catch(() => {
7156
- throw new TRPCError17({ code: "UNAUTHORIZED", message: "Unknown or revoked MCP pairing." });
7318
+ throw new TRPCError18({ code: "UNAUTHORIZED", message: "Unknown or revoked MCP pairing." });
7157
7319
  });
7158
7320
  }),
7159
7321
  pending: protectedProcedure.query(({ ctx }) => {
7160
7322
  requireHuman(ctx);
7161
7323
  return mcpPairing.pending();
7162
7324
  }),
7163
- decide: protectedProcedure.input(z20.object({ requestId: z20.string().uuid(), approve: z20.boolean() })).mutation(({ ctx, input }) => {
7325
+ decide: protectedProcedure.input(z21.object({ requestId: z21.string().uuid(), approve: z21.boolean() })).mutation(({ ctx, input }) => {
7164
7326
  requireHuman(ctx);
7165
7327
  return asBadRequest(() => mcpPairing.decide(input.requestId, input.approve));
7166
7328
  }),
@@ -7168,22 +7330,22 @@ var mcpPairingRouter = router({
7168
7330
  requireHuman(ctx);
7169
7331
  return mcpPairing.list();
7170
7332
  }),
7171
- revoke: protectedProcedure.input(z20.object({ id: z20.string().uuid() })).mutation(({ ctx, input }) => {
7333
+ revoke: protectedProcedure.input(z21.object({ id: z21.string().uuid() })).mutation(({ ctx, input }) => {
7172
7334
  requireHuman(ctx);
7173
7335
  return mcpPairing.revoke(input.id);
7174
7336
  })
7175
7337
  });
7176
7338
 
7177
7339
  // ../server/src/trpc/routers/ai-clients.ts
7178
- import { z as z21 } from "zod";
7179
- import { TRPCError as TRPCError18 } from "@trpc/server";
7340
+ import { z as z22 } from "zod";
7341
+ import { TRPCError as TRPCError19 } from "@trpc/server";
7180
7342
 
7181
7343
  // ../server/src/services/ai-client-mcp.ts
7182
7344
  import { execFile as execFile4 } from "child_process";
7183
7345
  import { existsSync as existsSync2, readdirSync } from "fs";
7184
7346
  import { mkdir as mkdir5, readFile as readFile4, realpath } from "fs/promises";
7185
7347
  import { homedir as homedir3 } from "os";
7186
- import { dirname as dirname4, join as join7 } from "path";
7348
+ import { dirname as dirname4, join as join8 } from "path";
7187
7349
  var SERVER_NAME = "runeya";
7188
7350
  function mcpEntry(override = env.MCP_COMMAND ?? null, home = env.HOME_DIR, platform = process.platform) {
7189
7351
  const [command, ...args] = override ? override.split(/\s+/) : ["runeya"];
@@ -7197,9 +7359,9 @@ function envFlags(flag, entry) {
7197
7359
  return Object.entries(entry.env ?? {}).flatMap(([k, v]) => [flag, `${k}=${v}`]);
7198
7360
  }
7199
7361
  function vscodeUserDir(home) {
7200
- if (process.platform === "darwin") return join7(home, "Library", "Application Support", "Code", "User");
7201
- if (process.platform === "win32") return join7(process.env["APPDATA"] ?? join7(home, "AppData", "Roaming"), "Code", "User");
7202
- return join7(home, ".config", "Code", "User");
7362
+ if (process.platform === "darwin") return join8(home, "Library", "Application Support", "Code", "User");
7363
+ if (process.platform === "win32") return join8(process.env["APPDATA"] ?? join8(home, "AppData", "Roaming"), "Code", "User");
7364
+ return join8(home, ".config", "Code", "User");
7203
7365
  }
7204
7366
  function listDir(dir) {
7205
7367
  try {
@@ -7209,14 +7371,14 @@ function listDir(dir) {
7209
7371
  }
7210
7372
  }
7211
7373
  function claudeDesktopDir(home, platform = process.platform, vars = process.env, exists4 = existsSync2, list = listDir) {
7212
- if (platform === "darwin") return join7(home, "Library", "Application Support", "Claude");
7374
+ if (platform === "darwin") return join8(home, "Library", "Application Support", "Claude");
7213
7375
  if (platform === "win32") {
7214
- const packages = join7(vars["LOCALAPPDATA"] ?? join7(home, "AppData", "Local"), "Packages");
7215
- const store = list(packages).filter((name) => name.startsWith("Claude_")).map((name) => join7(packages, name, "LocalCache", "Roaming", "Claude")).find(exists4);
7376
+ const packages = join8(vars["LOCALAPPDATA"] ?? join8(home, "AppData", "Local"), "Packages");
7377
+ const store = list(packages).filter((name) => name.startsWith("Claude_")).map((name) => join8(packages, name, "LocalCache", "Roaming", "Claude")).find(exists4);
7216
7378
  if (store) return store;
7217
- return join7(vars["APPDATA"] ?? join7(home, "AppData", "Roaming"), "Claude");
7379
+ return join8(vars["APPDATA"] ?? join8(home, "AppData", "Roaming"), "Claude");
7218
7380
  }
7219
- return join7(home, ".config", "Claude");
7381
+ return join8(home, ".config", "Claude");
7220
7382
  }
7221
7383
  var AI_CLIENTS = [
7222
7384
  {
@@ -7224,7 +7386,7 @@ var AI_CLIENTS = [
7224
7386
  label: "Claude Code",
7225
7387
  kind: "cli",
7226
7388
  binary: "claude",
7227
- configFile: (home) => join7(home, ".claude.json"),
7389
+ configFile: (home) => join8(home, ".claude.json"),
7228
7390
  isInstalled: (content) => {
7229
7391
  try {
7230
7392
  const servers2 = JSON.parse(content).mcpServers;
@@ -7242,33 +7404,33 @@ var AI_CLIENTS = [
7242
7404
  label: "Codex",
7243
7405
  kind: "cli",
7244
7406
  binary: "codex",
7245
- configFile: (home) => join7(home, ".codex", "config.toml"),
7407
+ configFile: (home) => join8(home, ".codex", "config.toml"),
7246
7408
  isInstalled: (content) => new RegExp(`^\\s*\\[mcp_servers\\.${SERVER_NAME}\\]`, "m").test(content),
7247
7409
  addArgs: (e) => ["mcp", "add", ...envFlags("--env", e), SERVER_NAME, "--", e.command, ...e.args],
7248
7410
  removeArgs: ["mcp", "remove", SERVER_NAME]
7249
7411
  },
7250
- { id: "cursor", label: "Cursor", kind: "json", detectDir: (h) => join7(h, ".cursor"), configFile: (h) => join7(h, ".cursor", "mcp.json") },
7251
- { id: "gemini", label: "Gemini CLI", kind: "json", detectDir: (h) => join7(h, ".gemini"), configFile: (h) => join7(h, ".gemini", "settings.json") },
7412
+ { id: "cursor", label: "Cursor", kind: "json", detectDir: (h) => join8(h, ".cursor"), configFile: (h) => join8(h, ".cursor", "mcp.json") },
7413
+ { id: "gemini", label: "Gemini CLI", kind: "json", detectDir: (h) => join8(h, ".gemini"), configFile: (h) => join8(h, ".gemini", "settings.json") },
7252
7414
  {
7253
7415
  id: "windsurf",
7254
7416
  label: "Windsurf",
7255
7417
  kind: "json",
7256
- detectDir: (h) => join7(h, ".codeium", "windsurf"),
7257
- configFile: (h) => join7(h, ".codeium", "windsurf", "mcp_config.json")
7418
+ detectDir: (h) => join8(h, ".codeium", "windsurf"),
7419
+ configFile: (h) => join8(h, ".codeium", "windsurf", "mcp_config.json")
7258
7420
  },
7259
7421
  {
7260
7422
  id: "claude-desktop",
7261
7423
  label: "Claude Desktop",
7262
7424
  kind: "json",
7263
7425
  detectDir: claudeDesktopDir,
7264
- configFile: (h) => join7(claudeDesktopDir(h), "claude_desktop_config.json")
7426
+ configFile: (h) => join8(claudeDesktopDir(h), "claude_desktop_config.json")
7265
7427
  },
7266
7428
  {
7267
7429
  id: "vscode",
7268
7430
  label: "VS Code",
7269
7431
  kind: "json",
7270
7432
  detectDir: vscodeUserDir,
7271
- configFile: (h) => join7(vscodeUserDir(h), "mcp.json"),
7433
+ configFile: (h) => join8(vscodeUserDir(h), "mcp.json"),
7272
7434
  serversKey: "servers",
7273
7435
  entryFields: { type: "stdio" }
7274
7436
  }
@@ -7362,25 +7524,25 @@ async function setAiClientMcp(id, present, home = homedir3()) {
7362
7524
  }
7363
7525
 
7364
7526
  // ../server/src/trpc/routers/ai-clients.ts
7365
- var AiClientIdSchema = z21.enum(["claude-code", "codex", "cursor", "gemini", "windsurf", "claude-desktop", "vscode"]);
7527
+ var AiClientIdSchema = z22.enum(["claude-code", "codex", "cursor", "gemini", "windsurf", "claude-desktop", "vscode"]);
7366
7528
  var aiClientsRouter = router({
7367
7529
  list: protectedProcedure.query(({ ctx }) => {
7368
7530
  requireHuman(ctx);
7369
7531
  return listAiClients();
7370
7532
  }),
7371
- setInstalled: protectedProcedure.input(z21.object({ id: AiClientIdSchema, installed: z21.boolean() })).mutation(async ({ ctx, input }) => {
7533
+ setInstalled: protectedProcedure.input(z22.object({ id: AiClientIdSchema, installed: z22.boolean() })).mutation(async ({ ctx, input }) => {
7372
7534
  requireHuman(ctx);
7373
7535
  try {
7374
7536
  await setAiClientMcp(input.id, input.installed);
7375
7537
  } catch (err) {
7376
- throw new TRPCError18({ code: "BAD_REQUEST", message: err.message });
7538
+ throw new TRPCError19({ code: "BAD_REQUEST", message: err.message });
7377
7539
  }
7378
7540
  return listAiClients();
7379
7541
  })
7380
7542
  });
7381
7543
 
7382
7544
  // ../server/src/trpc/routers/kanban-queue.ts
7383
- import { z as z22 } from "zod";
7545
+ import { z as z23 } from "zod";
7384
7546
 
7385
7547
  // ../server/src/services/kanban-queue.ts
7386
7548
  import { randomUUID as randomUUID6 } from "crypto";
@@ -7572,38 +7734,38 @@ var kanbanQueue = new KanbanQueueService();
7572
7734
  // ../server/src/trpc/routers/kanban-queue.ts
7573
7735
  var kanbanQueueRouter = router({
7574
7736
  getState: protectedProcedure.query(() => kanbanQueue.getState()),
7575
- add: protectedProcedure.input(z22.object({
7576
- boardId: z22.string().max(128),
7577
- cardId: z22.string().max(128),
7578
- runner: z22.enum(["claude-code", "codex"]).optional(),
7579
- model: z22.string().max(128).optional(),
7580
- scenarioId: z22.string().max(128).optional(),
7737
+ add: protectedProcedure.input(z23.object({
7738
+ boardId: z23.string().max(128),
7739
+ cardId: z23.string().max(128),
7740
+ runner: z23.enum(["claude-code", "codex"]).optional(),
7741
+ model: z23.string().max(128).optional(),
7742
+ scenarioId: z23.string().max(128).optional(),
7581
7743
  // Le projet ouvert quand la carte a été mise en file : la conversation
7582
7744
  // qui en naîtra lui appartient, plutôt que de rester orpheline et de
7583
7745
  // s'afficher dans tous les projets.
7584
- projectId: z22.string().max(128).optional(),
7585
- orgId: z22.string().max(128).nullable().optional()
7746
+ projectId: z23.string().max(128).optional(),
7747
+ orgId: z23.string().max(128).nullable().optional()
7586
7748
  })).mutation(({ input }) => kanbanQueue.add(input)),
7587
- addColumn: protectedProcedure.input(z22.object({
7588
- boardId: z22.string().max(128),
7589
- columnId: z22.string().max(128),
7749
+ addColumn: protectedProcedure.input(z23.object({
7750
+ boardId: z23.string().max(128),
7751
+ columnId: z23.string().max(128),
7590
7752
  // Les cartes visibles côté écran : une colonne filtrée n'envoie qu'elles.
7591
- cardIds: z22.array(z22.string().max(128)).max(5e3).optional(),
7592
- runner: z22.enum(["claude-code", "codex"]).optional(),
7593
- model: z22.string().max(128).optional(),
7594
- scenarioId: z22.string().max(128).optional(),
7595
- projectId: z22.string().max(128).optional(),
7596
- orgId: z22.string().max(128).nullable().optional()
7753
+ cardIds: z23.array(z23.string().max(128)).max(5e3).optional(),
7754
+ runner: z23.enum(["claude-code", "codex"]).optional(),
7755
+ model: z23.string().max(128).optional(),
7756
+ scenarioId: z23.string().max(128).optional(),
7757
+ projectId: z23.string().max(128).optional(),
7758
+ orgId: z23.string().max(128).nullable().optional()
7597
7759
  })).mutation(async ({ input }) => {
7598
7760
  const { boardId, columnId, ...options } = input;
7599
7761
  return kanbanQueue.addColumn(boardId, columnId, options);
7600
7762
  }),
7601
- remove: protectedProcedure.input(z22.object({ itemId: z22.string().max(128) })).mutation(({ input }) => ({ removed: kanbanQueue.remove(input.itemId) })),
7763
+ remove: protectedProcedure.input(z23.object({ itemId: z23.string().max(128) })).mutation(({ input }) => ({ removed: kanbanQueue.remove(input.itemId) })),
7602
7764
  stopAll: protectedProcedure.mutation(() => {
7603
7765
  kanbanQueue.stopAll();
7604
7766
  return { ok: true };
7605
7767
  }),
7606
- setMaxConcurrent: protectedProcedure.input(z22.object({ max: z22.number().int().min(1).max(20) })).mutation(({ input }) => {
7768
+ setMaxConcurrent: protectedProcedure.input(z23.object({ max: z23.number().int().min(1).max(20) })).mutation(({ input }) => {
7607
7769
  kanbanQueue.setMaxConcurrent(input.max);
7608
7770
  return kanbanQueue.getState();
7609
7771
  }),
@@ -7640,13 +7802,13 @@ var kanbanQueueRouter = router({
7640
7802
  import { mkdir as mkdir6, readdir, rm, stat as stat3, writeFile as writeFile4 } from "fs/promises";
7641
7803
  import { createHash as createHash2 } from "crypto";
7642
7804
  import { tmpdir } from "os";
7643
- import { join as join8 } from "path";
7644
- import { z as z23 } from "zod";
7645
- import { TRPCError as TRPCError19 } from "@trpc/server";
7805
+ import { join as join9 } from "path";
7806
+ import { z as z24 } from "zod";
7807
+ import { TRPCError as TRPCError20 } from "@trpc/server";
7646
7808
  var protectedProcedure2 = protectedProcedure.use(async ({ next }) => {
7647
7809
  const result = await next();
7648
7810
  if (!result.ok && result.error.cause instanceof KanbanUnavailableError) {
7649
- throw new TRPCError19({
7811
+ throw new TRPCError20({
7650
7812
  code: "PRECONDITION_FAILED",
7651
7813
  message: result.error.message,
7652
7814
  cause: result.error.cause
@@ -7694,14 +7856,14 @@ function safeDecode(value) {
7694
7856
  }
7695
7857
  var MAX_ATTACHMENT_BYTES = 55 * 1024 * 1024;
7696
7858
  function attachmentCacheDir() {
7697
- return join8(tmpdir(), "runeya-kanban-attachments");
7859
+ return join9(tmpdir(), "runeya-kanban-attachments");
7698
7860
  }
7699
7861
  var ATTACHMENT_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
7700
7862
  async function purgeStaleAttachments(dir, ttlMs = ATTACHMENT_CACHE_TTL_MS) {
7701
7863
  try {
7702
7864
  const cutoff = Date.now() - ttlMs;
7703
7865
  for (const name of await readdir(dir)) {
7704
- const path = join8(dir, name);
7866
+ const path = join9(dir, name);
7705
7867
  const info = await stat3(path).catch(() => null);
7706
7868
  if (info && info.mtimeMs < cutoff) await rm(path, { force: true });
7707
7869
  }
@@ -7709,14 +7871,14 @@ async function purgeStaleAttachments(dir, ttlMs = ATTACHMENT_CACHE_TTL_MS) {
7709
7871
  }
7710
7872
  }
7711
7873
  function attachmentCacheDirs() {
7712
- return [attachmentCacheDir(), join8(machineRoot(), "kanban-attachments")];
7874
+ return [attachmentCacheDir(), join9(machineRoot(), "kanban-attachments")];
7713
7875
  }
7714
7876
  async function storeAttachment(id, name, body, dirs = attachmentCacheDirs()) {
7715
7877
  const refusals = [];
7716
7878
  for (const dir of dirs) {
7717
7879
  try {
7718
7880
  await mkdir6(dir, { recursive: true });
7719
- const path = join8(dir, safeLocalName(id, name));
7881
+ const path = join9(dir, safeLocalName(id, name));
7720
7882
  await writeFile4(path, body);
7721
7883
  void purgeStaleAttachments(dir);
7722
7884
  return path;
@@ -7724,7 +7886,7 @@ async function storeAttachment(id, name, body, dirs = attachmentCacheDirs()) {
7724
7886
  refusals.push(`${dir} (${err instanceof Error ? err.message : String(err)})`);
7725
7887
  }
7726
7888
  }
7727
- throw new TRPCError19({
7889
+ throw new TRPCError20({
7728
7890
  code: "INTERNAL_SERVER_ERROR",
7729
7891
  message: `Impossible d'\xE9crire la pi\xE8ce jointe sur cette machine. Emplacements essay\xE9s : ${refusals.join(" ; ")}. V\xE9rifiez les droits d'\xE9criture, ou l'espace disque.`
7730
7892
  });
@@ -7745,9 +7907,9 @@ var kanbanRouter = router({
7745
7907
  * card graph, so listing them in full would be megabytes to answer "which
7746
7908
  * boards exist?". Use `getBoard` for the cards of one.
7747
7909
  */
7748
- listBoards: protectedProcedure2.input(z23.object({
7749
- includeArchived: z23.boolean().optional(),
7750
- organizationId: z23.string().max(128).optional()
7910
+ listBoards: protectedProcedure2.input(z24.object({
7911
+ includeArchived: z24.boolean().optional(),
7912
+ organizationId: z24.string().max(128).optional()
7751
7913
  }).optional()).query(async ({ input }) => {
7752
7914
  const { organizationId, boards } = await kanbanStore.list(
7753
7915
  input?.includeArchived ?? false,
@@ -7773,7 +7935,7 @@ var kanbanRouter = router({
7773
7935
  };
7774
7936
  }),
7775
7937
  /** One board: its columns, and the cards in each. */
7776
- getBoard: protectedProcedure2.input(z23.object({ boardId: z23.string().max(128) })).query(async ({ input }) => {
7938
+ getBoard: protectedProcedure2.input(z24.object({ boardId: z24.string().max(128) })).query(async ({ input }) => {
7777
7939
  const board = await kanbanStore.get(input.boardId);
7778
7940
  if (!board) return { board: null };
7779
7941
  const { links } = await kanbanStore.cardLinks(input.boardId);
@@ -7812,12 +7974,12 @@ var kanbanRouter = router({
7812
7974
  * organization — or one board when `boardId` is given. Archived boards are
7813
7975
  * left out: they are what the team decided to stop looking at.
7814
7976
  */
7815
- searchCards: protectedProcedure2.input(z23.object({
7816
- query: z23.string().max(256).optional(),
7817
- createdBy: z23.string().min(1).max(200).optional(),
7818
- boardId: z23.string().max(128).optional(),
7819
- limit: z23.number().int().min(1).max(100).optional(),
7820
- organizationId: z23.string().max(128).optional()
7977
+ searchCards: protectedProcedure2.input(z24.object({
7978
+ query: z24.string().max(256).optional(),
7979
+ createdBy: z24.string().min(1).max(200).optional(),
7980
+ boardId: z24.string().max(128).optional(),
7981
+ limit: z24.number().int().min(1).max(100).optional(),
7982
+ organizationId: z24.string().max(128).optional()
7821
7983
  }).refine((i) => !!i.query?.trim() || !!i.createdBy?.trim(), { message: "query or createdBy is required." })).query(async ({ input }) => {
7822
7984
  return kanbanStore.searchCards(input);
7823
7985
  }),
@@ -7825,10 +7987,10 @@ var kanbanRouter = router({
7825
7987
  * Les conversations de support liées à une carte, avec leur fil — ce que
7826
7988
  * le client a écrit à l'équipe, séparé des commentaires de la carte.
7827
7989
  */
7828
- getCardConversations: protectedProcedure2.input(z23.object({
7829
- boardId: z23.string().max(128),
7830
- cardId: z23.string().max(128),
7831
- limit: z23.number().int().min(1).max(500).optional()
7990
+ getCardConversations: protectedProcedure2.input(z24.object({
7991
+ boardId: z24.string().max(128),
7992
+ cardId: z24.string().max(128),
7993
+ limit: z24.number().int().min(1).max(500).optional()
7832
7994
  })).query(async ({ input }) => {
7833
7995
  const conversations = await kanbanStore.cardConversations(input.boardId, input.cardId);
7834
7996
  const limit = input.limit ?? 100;
@@ -7841,13 +8003,13 @@ var kanbanRouter = router({
7841
8003
  };
7842
8004
  }),
7843
8005
  /** Chercher une conversation chez les fournisseurs de l'organisation (lecture seule côté fournisseur). */
7844
- searchConversations: protectedProcedure2.input(z23.object({ boardId: z23.string().max(128), query: z23.string().trim().min(1).max(500) })).query(async ({ input }) => ({ results: await kanbanStore.searchConversations(input.boardId, input.query) })),
8006
+ searchConversations: protectedProcedure2.input(z24.object({ boardId: z24.string().max(128), query: z24.string().trim().min(1).max(500) })).query(async ({ input }) => ({ results: await kanbanStore.searchConversations(input.boardId, input.query) })),
7845
8007
  /** Lier une conversation trouvée à une carte. N'écrit rien chez le fournisseur. */
7846
- linkConversation: protectedProcedure2.input(z23.object({
7847
- boardId: z23.string().max(128),
7848
- cardId: z23.string().max(128),
7849
- connectionId: z23.string().max(128),
7850
- externalId: z23.string().max(128)
8008
+ linkConversation: protectedProcedure2.input(z24.object({
8009
+ boardId: z24.string().max(128),
8010
+ cardId: z24.string().max(128),
8011
+ connectionId: z24.string().max(128),
8012
+ externalId: z24.string().max(128)
7851
8013
  })).mutation(async ({ input }) => ({ conversations: await kanbanStore.linkConversation(input) })),
7852
8014
  /**
7853
8015
  * Le fil de commentaires d'une carte, relu à la demande.
@@ -7858,10 +8020,10 @@ var kanbanRouter = router({
7858
8020
  * qu'un `commentCount`, et rien n'en donnait le texte. Cette route est la
7859
8021
  * relecture, pour une seule carte : c'est le journal qui pèse, pas le reste.
7860
8022
  */
7861
- getCardComments: protectedProcedure2.input(z23.object({
7862
- boardId: z23.string().max(128),
7863
- cardId: z23.string().max(128),
7864
- limit: z23.number().int().min(1).max(200).optional()
8023
+ getCardComments: protectedProcedure2.input(z24.object({
8024
+ boardId: z24.string().max(128),
8025
+ cardId: z24.string().max(128),
8026
+ limit: z24.number().int().min(1).max(200).optional()
7865
8027
  })).query(async ({ input }) => {
7866
8028
  const history = await kanbanStore.cardHistory(input.boardId, input.cardId);
7867
8029
  const comments = history.filter((e) => e.type === "comment");
@@ -7890,18 +8052,18 @@ var kanbanRouter = router({
7890
8052
  * `getBoard` en donne déjà l'essentiel carte par carte ; cette route sert
7891
8053
  * quand c'est l'arbre lui-même qu'on veut, dates et auteurs compris.
7892
8054
  */
7893
- getCardLinks: protectedProcedure2.input(z23.object({ boardId: z23.string().max(128) })).query(async ({ input }) => kanbanStore.cardLinks(input.boardId)),
8055
+ getCardLinks: protectedProcedure2.input(z24.object({ boardId: z24.string().max(128) })).query(async ({ input }) => kanbanStore.cardLinks(input.boardId)),
7894
8056
  /**
7895
8057
  * Rattacher une carte à une carte parente, ou l'en détacher.
7896
8058
  *
7897
8059
  * Sans `parentCardId`, le lien est retiré. Le parent peut vivre sur un autre
7898
8060
  * tableau : `parentBoardId` le désigne alors, sinon c'est celui de la carte.
7899
8061
  */
7900
- setCardParent: protectedProcedure2.input(z23.object({
7901
- boardId: z23.string().max(128),
7902
- cardId: z23.string().max(128),
7903
- parentCardId: z23.string().max(128).optional(),
7904
- parentBoardId: z23.string().max(128).optional()
8062
+ setCardParent: protectedProcedure2.input(z24.object({
8063
+ boardId: z24.string().max(128),
8064
+ cardId: z24.string().max(128),
8065
+ parentCardId: z24.string().max(128).optional(),
8066
+ parentBoardId: z24.string().max(128).optional()
7905
8067
  })).mutation(async ({ input }) => {
7906
8068
  const ok = await kanbanStore.setCardParent(
7907
8069
  input.boardId,
@@ -7909,7 +8071,7 @@ var kanbanRouter = router({
7909
8071
  input.parentCardId ? { boardId: input.parentBoardId ?? input.boardId, cardId: input.parentCardId } : null
7910
8072
  );
7911
8073
  if (!ok) {
7912
- throw new TRPCError19({ code: "BAD_REQUEST", message: "The cloud refused the link (unknown card, or a cycle)." });
8074
+ throw new TRPCError20({ code: "BAD_REQUEST", message: "The cloud refused the link (unknown card, or a cycle)." });
7913
8075
  }
7914
8076
  return { ok: true };
7915
8077
  }),
@@ -7918,48 +8080,48 @@ var kanbanRouter = router({
7918
8080
  * `boardId` est le tableau où on la pose (ou d'où on la retire) ; la carte
7919
8081
  * reste sur son tableau d'origine.
7920
8082
  */
7921
- getCardPlacements: protectedProcedure2.input(z23.object({ boardId: z23.string().max(128), cardId: z23.string().max(128) })).query(async ({ input }) => ({ placements: await kanbanStore.cardPlacements(input.boardId, input.cardId) })),
7922
- placeCard: protectedProcedure2.input(z23.object({ boardId: z23.string().max(128), cardId: z23.string().max(128), column: z23.string().min(1).max(200) })).mutation(async ({ input }) => {
8083
+ getCardPlacements: protectedProcedure2.input(z24.object({ boardId: z24.string().max(128), cardId: z24.string().max(128) })).query(async ({ input }) => ({ placements: await kanbanStore.cardPlacements(input.boardId, input.cardId) })),
8084
+ placeCard: protectedProcedure2.input(z24.object({ boardId: z24.string().max(128), cardId: z24.string().max(128), column: z24.string().min(1).max(200) })).mutation(async ({ input }) => {
7923
8085
  const res = await kanbanStore.placeCard(input.boardId, input.cardId, input.column);
7924
8086
  if (!res.ok) {
7925
- throw new TRPCError19({
8087
+ throw new TRPCError20({
7926
8088
  code: "BAD_REQUEST",
7927
8089
  message: res.reason ?? "The cloud refused the placement (unknown card or column, archived card, or already on this board)."
7928
8090
  });
7929
8091
  }
7930
8092
  return { ok: true };
7931
8093
  }),
7932
- unplaceCard: protectedProcedure2.input(z23.object({ boardId: z23.string().max(128), cardId: z23.string().max(128) })).mutation(async ({ input }) => {
8094
+ unplaceCard: protectedProcedure2.input(z24.object({ boardId: z24.string().max(128), cardId: z24.string().max(128) })).mutation(async ({ input }) => {
7933
8095
  if (!await kanbanStore.unplaceCard(input.boardId, input.cardId)) {
7934
- throw new TRPCError19({ code: "NOT_FOUND", message: "This card is not placed on this board." });
8096
+ throw new TRPCError20({ code: "NOT_FOUND", message: "This card is not placed on this board." });
7935
8097
  }
7936
8098
  return { ok: true };
7937
8099
  }),
7938
- moveCard: protectedProcedure2.input(z23.object({
7939
- boardId: z23.string().max(128),
7940
- cardId: z23.string().max(128),
7941
- targetColumn: z23.string().max(256)
8100
+ moveCard: protectedProcedure2.input(z24.object({
8101
+ boardId: z24.string().max(128),
8102
+ cardId: z24.string().max(128),
8103
+ targetColumn: z24.string().max(256)
7942
8104
  })).mutation(async ({ input }) => {
7943
8105
  await executeKanbanCommands(input.boardId, input.cardId, [
7944
8106
  { type: "move_card", columnTitle: input.targetColumn }
7945
8107
  ]);
7946
8108
  return { ok: true };
7947
8109
  }),
7948
- addComment: protectedProcedure2.input(z23.object({
7949
- boardId: z23.string().max(128),
7950
- cardId: z23.string().max(128),
7951
- comment: z23.string().max(1e5)
8110
+ addComment: protectedProcedure2.input(z24.object({
8111
+ boardId: z24.string().max(128),
8112
+ cardId: z24.string().max(128),
8113
+ comment: z24.string().max(1e5)
7952
8114
  })).mutation(async ({ input }) => {
7953
8115
  await executeKanbanCommands(input.boardId, input.cardId, [
7954
8116
  { type: "add_comment", comment: input.comment }
7955
8117
  ]);
7956
8118
  return { ok: true };
7957
8119
  }),
7958
- addCard: protectedProcedure2.input(z23.object({
7959
- boardId: z23.string().max(128),
7960
- column: z23.string().max(256),
7961
- title: z23.string().max(512),
7962
- content: z23.string().max(2e4).optional()
8120
+ addCard: protectedProcedure2.input(z24.object({
8121
+ boardId: z24.string().max(128),
8122
+ column: z24.string().max(256),
8123
+ title: z24.string().max(512),
8124
+ content: z24.string().max(2e4).optional()
7963
8125
  })).mutation(async ({ input }) => {
7964
8126
  await executeKanbanBoardCommands(input.boardId, [
7965
8127
  { type: "add_card", columnTitle: input.column, cardTitle: input.title, cardContent: input.content }
@@ -7972,7 +8134,7 @@ var kanbanRouter = router({
7972
8134
  * `getBoard` rapatrie le tableau entier pour n'en regarder qu'une ; et il ne
7973
8135
  * porte pas les cartes rangées. Une carte s'adresse par son identifiant.
7974
8136
  */
7975
- getCard: protectedProcedure2.input(z23.object({ boardId: z23.string().max(128), cardId: z23.string().max(128) })).query(async ({ input }) => {
8137
+ getCard: protectedProcedure2.input(z24.object({ boardId: z24.string().max(128), cardId: z24.string().max(128) })).query(async ({ input }) => {
7976
8138
  const found = await kanbanStore.card(input.boardId, input.cardId);
7977
8139
  if (!found) throw new Error(`Carte ${input.cardId} introuvable sur le tableau ${input.boardId}.`);
7978
8140
  return { ...summarizeCard(found.card, input.boardId, ""), columnId: found.columnId };
@@ -7983,16 +8145,16 @@ var kanbanRouter = router({
7983
8145
  * endroit (`buildKanbanCardPrompt`). L'outil le reçoit comme un message, pas
7984
8146
  * comme une consigne système : il guide le travail sans en avoir la force.
7985
8147
  */
7986
- cardContext: protectedProcedure2.input(z23.object({
7987
- boardId: z23.string().max(128),
7988
- cardId: z23.string().max(128),
7989
- projectId: z23.string().max(128).optional(),
7990
- orgId: z23.string().max(128).optional()
8148
+ cardContext: protectedProcedure2.input(z24.object({
8149
+ boardId: z24.string().max(128),
8150
+ cardId: z24.string().max(128),
8151
+ projectId: z24.string().max(128).optional(),
8152
+ orgId: z24.string().max(128).optional()
7991
8153
  })).query(async ({ input }) => {
7992
8154
  const board = await kanbanStore.get(input.boardId);
7993
- if (!board) throw new TRPCError19({ code: "NOT_FOUND", message: `Tableau ${input.boardId} introuvable.` });
8155
+ if (!board) throw new TRPCError20({ code: "NOT_FOUND", message: `Tableau ${input.boardId} introuvable.` });
7994
8156
  if (!board.columns.some((col) => col.cards.some((c) => c.id === input.cardId))) {
7995
- throw new TRPCError19({ code: "NOT_FOUND", message: `Carte ${input.cardId} introuvable sur le tableau ${input.boardId}.` });
8157
+ throw new TRPCError20({ code: "NOT_FOUND", message: `Carte ${input.cardId} introuvable sur le tableau ${input.boardId}.` });
7996
8158
  }
7997
8159
  const scope = {
7998
8160
  ...input.projectId ? { projectId: input.projectId } : {},
@@ -8009,16 +8171,16 @@ var kanbanRouter = router({
8009
8171
  * Un champ absent n'est pas touché ; `null` l'efface. La distinction compte —
8010
8172
  * changer un titre ne doit pas vider une couleur.
8011
8173
  */
8012
- updateCard: protectedProcedure2.input(z23.object({
8013
- boardId: z23.string().max(128),
8014
- cardId: z23.string().max(128),
8015
- title: z23.string().min(1).max(512).optional(),
8016
- content: z23.string().max(1e5).optional(),
8017
- priority: z23.number().int().min(1).max(10).nullable().optional(),
8018
- color: z23.string().max(32).nullable().optional(),
8019
- groups: z23.array(z23.string().min(1).max(60)).max(30).optional(),
8020
- deadline: z23.string().regex(/^\d{4}-\d{2}-\d{2}$/).nullable().optional(),
8021
- assignees: z23.array(z23.string().max(128)).max(50).optional()
8174
+ updateCard: protectedProcedure2.input(z24.object({
8175
+ boardId: z24.string().max(128),
8176
+ cardId: z24.string().max(128),
8177
+ title: z24.string().min(1).max(512).optional(),
8178
+ content: z24.string().max(1e5).optional(),
8179
+ priority: z24.number().int().min(1).max(10).nullable().optional(),
8180
+ color: z24.string().max(32).nullable().optional(),
8181
+ groups: z24.array(z24.string().min(1).max(60)).max(30).optional(),
8182
+ deadline: z24.string().regex(/^\d{4}-\d{2}-\d{2}$/).nullable().optional(),
8183
+ assignees: z24.array(z24.string().max(128)).max(50).optional()
8022
8184
  })).mutation(async ({ input }) => {
8023
8185
  const { boardId, cardId, content, ...rest } = input;
8024
8186
  const patch = { ...rest };
@@ -8029,10 +8191,10 @@ var kanbanRouter = router({
8029
8191
  return summarizeCard(card, boardId, "");
8030
8192
  }),
8031
8193
  /** Ranger une carte, ou la reprendre. */
8032
- setCardArchived: protectedProcedure2.input(z23.object({
8033
- boardId: z23.string().max(128),
8034
- cardId: z23.string().max(128),
8035
- archived: z23.boolean()
8194
+ setCardArchived: protectedProcedure2.input(z24.object({
8195
+ boardId: z24.string().max(128),
8196
+ cardId: z24.string().max(128),
8197
+ archived: z24.boolean()
8036
8198
  })).mutation(async ({ input }) => {
8037
8199
  const ok = await kanbanStore.setCardArchived(input.boardId, input.cardId, input.archived);
8038
8200
  if (!ok) throw new Error(`La carte ${input.cardId} n'a pas pu \xEAtre ${input.archived ? "archiv\xE9e" : "reprise"}.`);
@@ -8044,48 +8206,48 @@ var kanbanRouter = router({
8044
8206
  * Sans cette liste, assigner revient à deviner un identifiant — et l'agent
8045
8207
  * n'a aucun moyen de le trouver.
8046
8208
  */
8047
- listMembers: protectedProcedure2.input(z23.object({ organizationId: z23.string().max(128).optional() })).query(async ({ input }) => ({ members: await kanbanStore.members(input.organizationId) })),
8209
+ listMembers: protectedProcedure2.input(z24.object({ organizationId: z24.string().max(128).optional() })).query(async ({ input }) => ({ members: await kanbanStore.members(input.organizationId) })),
8048
8210
  /**
8049
8211
  * Fetch one card attachment from the cloud and drop it on this machine, so an
8050
8212
  * agent can open it with its own file tools. The bytes never go through the
8051
8213
  * prompt: the card context lists the attachments, this returns a path.
8052
8214
  */
8053
- downloadAttachment: protectedProcedure2.input(z23.object({
8054
- attachmentId: z23.string().max(128),
8215
+ downloadAttachment: protectedProcedure2.input(z24.object({
8216
+ attachmentId: z24.string().max(128),
8055
8217
  // La pièce jointe appartient à une organisation : la nommer dit sous quel
8056
8218
  // compte la demander.
8057
- orgId: z23.string().max(128).optional(),
8219
+ orgId: z24.string().max(128).optional(),
8058
8220
  // À défaut, le tableau d'où vient la carte suffit : il désigne un compte
8059
8221
  // comme le fait n'importe quel autre appel du kanban. Sans lui, la route
8060
8222
  // retombait sur le compte unique du poste et refusait de servir dès qu'il
8061
8223
  // y en avait plusieurs — alors que l'agent, qui n'a qu'un identifiant de
8062
8224
  // fichier, n'avait aucun moyen de nommer l'organisation.
8063
- boardId: z23.string().max(128).optional()
8225
+ boardId: z24.string().max(128).optional()
8064
8226
  })).mutation(async ({ input }) => {
8065
8227
  const id = input.attachmentId;
8066
8228
  if (!ATTACHMENT_ID_REGEX.test(id)) {
8067
- throw new TRPCError19({ code: "BAD_REQUEST", message: "Invalid attachment id" });
8229
+ throw new TRPCError20({ code: "BAD_REQUEST", message: "Invalid attachment id" });
8068
8230
  }
8069
8231
  const res = await cloudFetch2(`/api/kanban/file/${id}`, {
8070
8232
  timeoutMs: 12e4,
8071
8233
  accountId: await attachmentScope(input)
8072
8234
  });
8073
8235
  if (res.status === 404) {
8074
- throw new TRPCError19({ code: "NOT_FOUND", message: `Attachment ${id} not found` });
8236
+ throw new TRPCError20({ code: "NOT_FOUND", message: `Attachment ${id} not found` });
8075
8237
  }
8076
8238
  if (!res.ok) {
8077
- throw new TRPCError19({
8239
+ throw new TRPCError20({
8078
8240
  code: res.status === 403 ? "FORBIDDEN" : "INTERNAL_SERVER_ERROR",
8079
8241
  message: `Cloud refused the attachment (HTTP ${res.status})`
8080
8242
  });
8081
8243
  }
8082
8244
  const declared = Number(res.headers.get("content-length") ?? 0);
8083
8245
  if (declared > MAX_ATTACHMENT_BYTES) {
8084
- throw new TRPCError19({ code: "PAYLOAD_TOO_LARGE", message: "Attachment too large to download" });
8246
+ throw new TRPCError20({ code: "PAYLOAD_TOO_LARGE", message: "Attachment too large to download" });
8085
8247
  }
8086
8248
  const body = Buffer.from(await res.arrayBuffer());
8087
8249
  if (body.length > MAX_ATTACHMENT_BYTES) {
8088
- throw new TRPCError19({ code: "PAYLOAD_TOO_LARGE", message: "Attachment too large to download" });
8250
+ throw new TRPCError20({ code: "PAYLOAD_TOO_LARGE", message: "Attachment too large to download" });
8089
8251
  }
8090
8252
  const contentType = res.headers.get("content-type") ?? "application/octet-stream";
8091
8253
  const disposition = res.headers.get("content-disposition") ?? "";
@@ -8097,10 +8259,10 @@ var kanbanRouter = router({
8097
8259
  });
8098
8260
 
8099
8261
  // ../server/src/trpc/routers/knowledge.ts
8100
- import { z as z24 } from "zod";
8101
- import { TRPCError as TRPCError20 } from "@trpc/server";
8262
+ import { z as z25 } from "zod";
8263
+ import { TRPCError as TRPCError21 } from "@trpc/server";
8102
8264
  var protectedProcedure3 = protectedProcedure.use(({ ctx, next }) => {
8103
- if (ctx.callerType === "api") throw new TRPCError20({ code: "FORBIDDEN", message: "An API key cannot use the knowledge base." });
8265
+ if (ctx.callerType === "api") throw new TRPCError21({ code: "FORBIDDEN", message: "An API key cannot use the knowledge base." });
8104
8266
  return next();
8105
8267
  });
8106
8268
  var accountOfObject = /* @__PURE__ */ new Map();
@@ -8118,7 +8280,7 @@ async function orgScope(explicit) {
8118
8280
  const organizationId = await resolveOrganizationId(explicit);
8119
8281
  return { organizationId, accountId: await accountForOrgScope(organizationId) };
8120
8282
  } catch (err) {
8121
- if (err instanceof KanbanUnavailableError) throw new TRPCError20({ code: "PRECONDITION_FAILED", message: err.message });
8283
+ if (err instanceof KanbanUnavailableError) throw new TRPCError21({ code: "PRECONDITION_FAILED", message: err.message });
8122
8284
  throw err;
8123
8285
  }
8124
8286
  }
@@ -8134,7 +8296,7 @@ async function call(path, accountId, init = {}) {
8134
8296
  const res = await cloudFetch2(`/api/auth${path}`, { ...init, accountId });
8135
8297
  if (!res.ok) {
8136
8298
  const body = await res.json().catch(() => null);
8137
- throw new TRPCError20({
8299
+ throw new TRPCError21({
8138
8300
  code: STATUS[res.status] ?? "PRECONDITION_FAILED",
8139
8301
  message: body?.message ?? `Le cloud a r\xE9pondu HTTP ${res.status} sur ${path}.`
8140
8302
  });
@@ -8157,7 +8319,7 @@ async function accountOf(id, probe) {
8157
8319
  return res?.ok ? a.id : null;
8158
8320
  }));
8159
8321
  const owner = owners.find((o) => !!o);
8160
- if (!owner) throw new TRPCError20({ code: "NOT_FOUND", message: `Aucun compte li\xE9 \xE0 ce poste ne conna\xEEt ${id}.` });
8322
+ if (!owner) throw new TRPCError21({ code: "NOT_FOUND", message: `Aucun compte li\xE9 \xE0 ce poste ne conna\xEEt ${id}.` });
8161
8323
  rememberAccount(id, owner);
8162
8324
  return owner;
8163
8325
  }
@@ -8165,7 +8327,7 @@ var pageAccount = (pageId) => accountOf(pageId, (id) => `/knowledge/page?pageId=
8165
8327
  async function spaceAccount(spaceId) {
8166
8328
  const { accountId } = await knownAccount(spaceId);
8167
8329
  if (accountId) return accountId;
8168
- throw new TRPCError20({ code: "BAD_REQUEST", message: `Espace ${spaceId} inconnu de ce poste : appelez knowledge_list_spaces avec son organizationId d'abord.` });
8330
+ throw new TRPCError21({ code: "BAD_REQUEST", message: `Espace ${spaceId} inconnu de ce poste : appelez knowledge_list_spaces avec son organizationId d'abord.` });
8169
8331
  }
8170
8332
  function remember(ids, accountId) {
8171
8333
  for (const id of ids) rememberAccount(id, accountId);
@@ -8175,13 +8337,13 @@ var qs = (params) => new URLSearchParams(Object.entries(params).flatMap(([k, v])
8175
8337
  return [[k, Array.isArray(v) ? v.join(",") : String(v)]];
8176
8338
  })).toString();
8177
8339
  var knowledgeRouter = router({
8178
- listSpaces: protectedProcedure3.input(z24.object({ organizationId: z24.string().max(128).optional() })).query(async ({ input }) => {
8340
+ listSpaces: protectedProcedure3.input(z25.object({ organizationId: z25.string().max(128).optional() })).query(async ({ input }) => {
8179
8341
  const { organizationId, accountId } = await orgScope(input.organizationId);
8180
8342
  const res = await call(`/knowledge/space/list?${qs({ organizationId })}`, accountId);
8181
8343
  remember(res.spaces.map((s) => s.id), accountId);
8182
8344
  return { organizationId, cloud: await cloudOf(accountId), ...res };
8183
8345
  }),
8184
- search: protectedProcedure3.input(KnowledgeSearchInputSchema.extend({ organizationId: z24.string().max(128).optional() })).query(async ({ input }) => {
8346
+ search: protectedProcedure3.input(KnowledgeSearchInputSchema.extend({ organizationId: z25.string().max(128).optional() })).query(async ({ input }) => {
8185
8347
  const { organizationId, accountId } = await orgScope(input.organizationId);
8186
8348
  const res = await call(`/knowledge/search?${qs({
8187
8349
  organizationId,
@@ -8198,36 +8360,36 @@ var knowledgeRouter = router({
8198
8360
  remember(res.hits.map((h) => h.id), accountId);
8199
8361
  return { organizationId, cloud: await cloudOf(accountId), ...res };
8200
8362
  }),
8201
- listThemes: protectedProcedure3.input(z24.object({ organizationId: z24.string().max(128).optional(), spaceId: KnowledgeIdSchema.optional() })).query(async ({ input }) => {
8363
+ listThemes: protectedProcedure3.input(z25.object({ organizationId: z25.string().max(128).optional(), spaceId: KnowledgeIdSchema.optional() })).query(async ({ input }) => {
8202
8364
  const { organizationId, accountId } = await orgScope(input.organizationId);
8203
8365
  const res = await call(`/knowledge/themes?${qs({ organizationId, spaceId: input.spaceId })}`, accountId);
8204
8366
  remember(res.themes.map((t) => t.id), accountId);
8205
8367
  return res;
8206
8368
  }),
8207
- getPage: protectedProcedure3.input(z24.object({ pageId: KnowledgeIdSchema })).query(async ({ input }) => call(`/knowledge/page?${qs({ pageId: input.pageId })}`, await pageAccount(input.pageId))),
8208
- getNeighbors: protectedProcedure3.input(z24.object({
8369
+ getPage: protectedProcedure3.input(z25.object({ pageId: KnowledgeIdSchema })).query(async ({ input }) => call(`/knowledge/page?${qs({ pageId: input.pageId })}`, await pageAccount(input.pageId))),
8370
+ getNeighbors: protectedProcedure3.input(z25.object({
8209
8371
  pageId: KnowledgeIdSchema,
8210
- depth: z24.number().int().min(1).max(KNOWLEDGE_LIMITS.neighborsDepth).optional(),
8211
- kinds: z24.array(KnowledgeEdgeKindSchema).optional(),
8212
- includeObsolete: z24.boolean().optional()
8372
+ depth: z25.number().int().min(1).max(KNOWLEDGE_LIMITS.neighborsDepth).optional(),
8373
+ kinds: z25.array(KnowledgeEdgeKindSchema).optional(),
8374
+ includeObsolete: z25.boolean().optional()
8213
8375
  })).query(async ({ input }) => {
8214
8376
  const accountId = await pageAccount(input.pageId);
8215
8377
  const res = await call(`/knowledge/page/neighbors?${qs(input)}`, accountId);
8216
8378
  remember(res.nodes.map((n) => n.id), accountId);
8217
8379
  return res;
8218
8380
  }),
8219
- getRelated: protectedProcedure3.input(z24.object({
8220
- pageIds: z24.array(KnowledgeIdSchema).min(1).max(10),
8221
- limit: z24.number().int().min(1).max(KNOWLEDGE_LIMITS.relatedPages).optional(),
8222
- includeObsolete: z24.boolean().optional()
8381
+ getRelated: protectedProcedure3.input(z25.object({
8382
+ pageIds: z25.array(KnowledgeIdSchema).min(1).max(10),
8383
+ limit: z25.number().int().min(1).max(KNOWLEDGE_LIMITS.relatedPages).optional(),
8384
+ includeObsolete: z25.boolean().optional()
8223
8385
  })).query(async ({ input }) => {
8224
8386
  const accountId = await pageAccount(input.pageIds[0]);
8225
8387
  const res = await call(`/knowledge/related?${qs(input)}`, accountId);
8226
8388
  remember(res.pages.map((p) => p.id), accountId);
8227
8389
  return res;
8228
8390
  }),
8229
- getHistory: protectedProcedure3.input(z24.object({ pageId: KnowledgeIdSchema })).query(async ({ input }) => call(`/knowledge/page/history?${qs(input)}`, await pageAccount(input.pageId))),
8230
- getVersion: protectedProcedure3.input(z24.object({ pageId: KnowledgeIdSchema, at: z24.iso.datetime(), compare: z24.boolean().optional() })).query(async ({ input }) => call(`/knowledge/page/version?${qs(input)}`, await pageAccount(input.pageId))),
8391
+ getHistory: protectedProcedure3.input(z25.object({ pageId: KnowledgeIdSchema })).query(async ({ input }) => call(`/knowledge/page/history?${qs(input)}`, await pageAccount(input.pageId))),
8392
+ getVersion: protectedProcedure3.input(z25.object({ pageId: KnowledgeIdSchema, at: z25.iso.datetime(), compare: z25.boolean().optional() })).query(async ({ input }) => call(`/knowledge/page/version?${qs(input)}`, await pageAccount(input.pageId))),
8231
8393
  createPage: protectedProcedure3.input(KnowledgeCreatePageInputSchema).mutation(async ({ input }) => {
8232
8394
  const accountId = await spaceAccount(input.spaceId);
8233
8395
  const res = await call("/knowledge/page/create", accountId, { method: "POST", body: input });
@@ -8242,21 +8404,21 @@ var knowledgeRouter = router({
8242
8404
  });
8243
8405
 
8244
8406
  // ../server/src/trpc/routers/terminal.ts
8245
- import { z as z25 } from "zod";
8246
- import { TRPCError as TRPCError21 } from "@trpc/server";
8407
+ import { z as z26 } from "zod";
8408
+ import { TRPCError as TRPCError22 } from "@trpc/server";
8247
8409
  var terminalRouter = router({
8248
8410
  /** Create a PTY shell session on the target agent */
8249
- create: protectedProcedure.input(z25.object({
8250
- agentId: z25.string().max(128),
8251
- cwd: z25.string().max(512).optional(),
8411
+ create: protectedProcedure.input(z26.object({
8412
+ agentId: z26.string().max(128),
8413
+ cwd: z26.string().max(512).optional(),
8252
8414
  /** Anchors the terminal when no explicit cwd is given. */
8253
- serviceId: z25.string().max(128).optional(),
8254
- projectId: z25.string().max(128).optional(),
8415
+ serviceId: z26.string().max(128).optional(),
8416
+ projectId: z26.string().max(128).optional(),
8255
8417
  /** L'organisation du projet : un id seul peut en nommer un par organisation. */
8256
- orgId: z25.string().max(128).nullable().optional(),
8257
- cols: z25.number().int().min(1).max(512).optional(),
8258
- rows: z25.number().int().min(1).max(256).optional(),
8259
- title: z25.string().max(128).optional()
8418
+ orgId: z26.string().max(128).nullable().optional(),
8419
+ cols: z26.number().int().min(1).max(512).optional(),
8420
+ rows: z26.number().int().min(1).max(256).optional(),
8421
+ title: z26.string().max(128).optional()
8260
8422
  })).mutation(async ({ input }) => {
8261
8423
  const result = await agentManager.agentMutation(
8262
8424
  input.agentId,
@@ -8277,17 +8439,17 @@ var terminalRouter = router({
8277
8439
  return result;
8278
8440
  }),
8279
8441
  /** Les sessions PTY encore vivantes sur l'agent (onglets à retrouver) */
8280
- list: protectedProcedure.input(z25.object({ agentId: z25.string().max(128) })).query(async ({ input }) => {
8442
+ list: protectedProcedure.input(z26.object({ agentId: z26.string().max(128) })).query(async ({ input }) => {
8281
8443
  return agentManager.agentQuery(
8282
8444
  input.agentId,
8283
8445
  "terminal.list"
8284
8446
  );
8285
8447
  }),
8286
8448
  /** Renommer un onglet */
8287
- rename: protectedProcedure.input(z25.object({
8288
- agentId: z25.string().max(128),
8289
- sessionId: z25.string().max(128),
8290
- title: z25.string().max(128)
8449
+ rename: protectedProcedure.input(z26.object({
8450
+ agentId: z26.string().max(128),
8451
+ sessionId: z26.string().max(128),
8452
+ title: z26.string().max(128)
8291
8453
  })).mutation(async ({ input }) => {
8292
8454
  await agentManager.agentMutation(
8293
8455
  input.agentId,
@@ -8297,10 +8459,10 @@ var terminalRouter = router({
8297
8459
  return { ok: true };
8298
8460
  }),
8299
8461
  /** Send keystrokes / data to a PTY session */
8300
- write: protectedProcedure.input(z25.object({
8301
- agentId: z25.string().max(128),
8302
- sessionId: z25.string().max(128),
8303
- data: z25.string().max(65536)
8462
+ write: protectedProcedure.input(z26.object({
8463
+ agentId: z26.string().max(128),
8464
+ sessionId: z26.string().max(128),
8465
+ data: z26.string().max(65536)
8304
8466
  })).mutation(async ({ input }) => {
8305
8467
  await agentManager.agentMutation(
8306
8468
  input.agentId,
@@ -8310,11 +8472,11 @@ var terminalRouter = router({
8310
8472
  return { ok: true };
8311
8473
  }),
8312
8474
  /** Resize the PTY */
8313
- resize: protectedProcedure.input(z25.object({
8314
- agentId: z25.string().max(128),
8315
- sessionId: z25.string().max(128),
8316
- cols: z25.number().int().min(1).max(512),
8317
- rows: z25.number().int().min(1).max(256)
8475
+ resize: protectedProcedure.input(z26.object({
8476
+ agentId: z26.string().max(128),
8477
+ sessionId: z26.string().max(128),
8478
+ cols: z26.number().int().min(1).max(512),
8479
+ rows: z26.number().int().min(1).max(256)
8318
8480
  })).mutation(async ({ input }) => {
8319
8481
  await agentManager.agentMutation(
8320
8482
  input.agentId,
@@ -8324,9 +8486,9 @@ var terminalRouter = router({
8324
8486
  return { ok: true };
8325
8487
  }),
8326
8488
  /** Destroy a PTY session */
8327
- destroy: protectedProcedure.input(z25.object({
8328
- agentId: z25.string().max(128),
8329
- sessionId: z25.string().max(128)
8489
+ destroy: protectedProcedure.input(z26.object({
8490
+ agentId: z26.string().max(128),
8491
+ sessionId: z26.string().max(128)
8330
8492
  })).mutation(async ({ input }) => {
8331
8493
  await agentManager.agentMutation(
8332
8494
  input.agentId,
@@ -8336,11 +8498,11 @@ var terminalRouter = router({
8336
8498
  return { ok: true };
8337
8499
  }),
8338
8500
  /** Stream PTY output — proxied via AgentWSBridge dynamic subscription */
8339
- onData: protectedProcedure.input(z25.object({
8340
- agentId: z25.string().max(128),
8341
- sessionId: z25.string().max(128),
8501
+ onData: protectedProcedure.input(z26.object({
8502
+ agentId: z26.string().max(128),
8503
+ sessionId: z26.string().max(128),
8342
8504
  /** Rejouer l'historique de la session avant le flux temps réel. */
8343
- replay: z25.boolean().optional()
8505
+ replay: z26.boolean().optional()
8344
8506
  })).subscription(async function* ({ input }) {
8345
8507
  const queue = [];
8346
8508
  let resolve5 = null;
@@ -8367,7 +8529,7 @@ var terminalRouter = router({
8367
8529
  }
8368
8530
  );
8369
8531
  } catch (err) {
8370
- throw new TRPCError21({
8532
+ throw new TRPCError22({
8371
8533
  code: "BAD_REQUEST",
8372
8534
  message: `Cannot subscribe to terminal: ${err.message}`
8373
8535
  });
@@ -8389,11 +8551,11 @@ var terminalRouter = router({
8389
8551
  });
8390
8552
 
8391
8553
  // ../server/src/trpc/routers/utility.ts
8392
- import { z as z26 } from "zod";
8554
+ import { z as z27 } from "zod";
8393
8555
  var MAX_WAIT_MS = 5 * 60 * 1e3;
8394
8556
  var utilityRouter = router({
8395
- wait: protectedProcedure.input(z26.object({
8396
- ms: z26.number().int().min(0).max(MAX_WAIT_MS)
8557
+ wait: protectedProcedure.input(z27.object({
8558
+ ms: z27.number().int().min(0).max(MAX_WAIT_MS)
8397
8559
  })).mutation(async ({ input }) => {
8398
8560
  await new Promise((resolve5) => setTimeout(resolve5, input.ms));
8399
8561
  return { waited: input.ms };
@@ -8401,15 +8563,15 @@ var utilityRouter = router({
8401
8563
  });
8402
8564
 
8403
8565
  // ../server/src/trpc/routers/wiki.ts
8404
- import { z as z27 } from "zod";
8405
- import { TRPCError as TRPCError22 } from "@trpc/server";
8566
+ import { z as z28 } from "zod";
8567
+ import { TRPCError as TRPCError23 } from "@trpc/server";
8406
8568
  import { readFile as readFile5, readdir as readdir2, stat as stat4, realpath as realpath2, writeFile as writeFile5, mkdir as mkdir7, rename, rm as rm2 } from "fs/promises";
8407
- import { resolve as resolvePath, join as join9, relative as relative2, sep, dirname as dirname5 } from "path";
8408
- var SCOPE_SCHEMA = z27.union([
8409
- z27.literal("global"),
8410
- z27.string().regex(/^service:[A-Za-z0-9_-]{1,128}$/, "Invalid service scope")
8569
+ import { resolve as resolvePath, join as join10, relative as relative2, sep, dirname as dirname5 } from "path";
8570
+ var SCOPE_SCHEMA = z28.union([
8571
+ z28.literal("global"),
8572
+ z28.string().regex(/^service:[A-Za-z0-9_-]{1,128}$/, "Invalid service scope")
8411
8573
  ]);
8412
- var REL_PATH_SCHEMA = z27.string().min(1).max(512).regex(/^[A-Za-z0-9_./-]+$/).refine((p) => !p.includes("..") && !p.startsWith("/"), {
8574
+ var REL_PATH_SCHEMA = z28.string().min(1).max(512).regex(/^[A-Za-z0-9_./-]+$/).refine((p) => !p.includes("..") && !p.startsWith("/"), {
8413
8575
  message: "Path must be a relative path without traversal"
8414
8576
  });
8415
8577
  var MAX_FILES = 500;
@@ -8429,36 +8591,36 @@ var IGNORED_DIRS = /* @__PURE__ */ new Set([
8429
8591
  "target",
8430
8592
  "out"
8431
8593
  ]);
8432
- var DocsEntrySchema = z27.lazy(() => z27.union([
8433
- z27.object({ type: z27.literal("file"), name: z27.string(), path: z27.string() }),
8434
- z27.object({ type: z27.literal("dir"), name: z27.string(), path: z27.string(), children: z27.array(DocsEntrySchema) })
8594
+ var DocsEntrySchema = z28.lazy(() => z28.union([
8595
+ z28.object({ type: z28.literal("file"), name: z28.string(), path: z28.string() }),
8596
+ z28.object({ type: z28.literal("dir"), name: z28.string(), path: z28.string(), children: z28.array(DocsEntrySchema) })
8435
8597
  ]));
8436
8598
  async function resolveScope(scope) {
8437
8599
  if (scope === "global") {
8438
8600
  const settings = await settingsManager.getSettings();
8439
8601
  const sub = (settings.globalDocsPath?.trim() || "wiki").replace(/^[\\/]+|[\\/]+$/g, "");
8440
8602
  if (sub.includes("..") || sub.includes("\0")) {
8441
- throw new TRPCError22({ code: "BAD_REQUEST", message: "Sous-chemin invalide" });
8603
+ throw new TRPCError23({ code: "BAD_REQUEST", message: "Sous-chemin invalide" });
8442
8604
  }
8443
8605
  const dataDirAbs = resolvePath(env.DATA_DIR);
8444
8606
  await mkdir7(dataDirAbs, { recursive: true });
8445
8607
  const base = dirname5(await realpath2(dataDirAbs));
8446
8608
  const target = resolvePath(base, sub);
8447
8609
  if (target !== base && !(target + sep).startsWith(base + sep)) {
8448
- throw new TRPCError22({ code: "FORBIDDEN", message: "Hors du dossier de donn\xE9es du serveur" });
8610
+ throw new TRPCError23({ code: "FORBIDDEN", message: "Hors du dossier de donn\xE9es du serveur" });
8449
8611
  }
8450
8612
  await mkdir7(target, { recursive: true });
8451
8613
  const root = await realpath2(target);
8452
8614
  if (root !== base && !(root + sep).startsWith(base + sep)) {
8453
- throw new TRPCError22({ code: "FORBIDDEN", message: "Le dossier wiki r\xE9sout hors du dossier de donn\xE9es" });
8615
+ throw new TRPCError23({ code: "FORBIDDEN", message: "Le dossier wiki r\xE9sout hors du dossier de donn\xE9es" });
8454
8616
  }
8455
8617
  return { mode: "local", root };
8456
8618
  }
8457
8619
  const serviceId = scope.slice("service:".length);
8458
8620
  const service2 = await serviceStore.get(serviceId);
8459
- if (!service2) throw new TRPCError22({ code: "NOT_FOUND", message: "Service introuvable" });
8621
+ if (!service2) throw new TRPCError23({ code: "NOT_FOUND", message: "Service introuvable" });
8460
8622
  const agentId = await resolveEffectiveAgentId(service2);
8461
- if (!agentId) throw new TRPCError22({ code: "BAD_REQUEST", message: "Aucun agent configur\xE9 pour ce service" });
8623
+ if (!agentId) throw new TRPCError23({ code: "BAD_REQUEST", message: "Aucun agent configur\xE9 pour ce service" });
8462
8624
  const cwd = await resolveWorkspaceCwd({ serviceId, override: service2.docsPath?.trim() || void 0 });
8463
8625
  return { mode: "agent", agentId, cwd };
8464
8626
  }
@@ -8474,7 +8636,7 @@ async function walkLocal(root, dir, depth, counter) {
8474
8636
  for (const e of entries2) {
8475
8637
  if (counter.n >= MAX_FILES) break;
8476
8638
  if (e.name.startsWith(".") && e.name !== ".") continue;
8477
- const abs = join9(dir, e.name);
8639
+ const abs = join10(dir, e.name);
8478
8640
  const rel = relative2(root, abs).split(sep).join("/");
8479
8641
  if (e.isDirectory()) {
8480
8642
  if (IGNORED_DIRS.has(e.name)) continue;
@@ -8493,7 +8655,7 @@ async function walkLocal(root, dir, depth, counter) {
8493
8655
  }
8494
8656
  async function resolveSafeLocal(root, relPath, requireExist) {
8495
8657
  if (relPath.includes("..") || relPath.startsWith("/")) {
8496
- throw new TRPCError22({ code: "BAD_REQUEST", message: "Chemin invalide" });
8658
+ throw new TRPCError23({ code: "BAD_REQUEST", message: "Chemin invalide" });
8497
8659
  }
8498
8660
  const target = resolvePath(root, relPath);
8499
8661
  if (requireExist) {
@@ -8501,10 +8663,10 @@ async function resolveSafeLocal(root, relPath, requireExist) {
8501
8663
  try {
8502
8664
  real = await realpath2(target);
8503
8665
  } catch {
8504
- throw new TRPCError22({ code: "NOT_FOUND", message: "Chemin introuvable" });
8666
+ throw new TRPCError23({ code: "NOT_FOUND", message: "Chemin introuvable" });
8505
8667
  }
8506
8668
  if (real !== root && !(real + sep).startsWith(root + sep)) {
8507
- throw new TRPCError22({ code: "FORBIDDEN", message: "Hors du dossier autoris\xE9" });
8669
+ throw new TRPCError23({ code: "FORBIDDEN", message: "Hors du dossier autoris\xE9" });
8508
8670
  }
8509
8671
  return real;
8510
8672
  }
@@ -8516,12 +8678,12 @@ async function resolveSafeLocal(root, relPath, requireExist) {
8516
8678
  realParent = parent;
8517
8679
  }
8518
8680
  if (realParent !== root && !(realParent + sep).startsWith(root + sep)) {
8519
- throw new TRPCError22({ code: "FORBIDDEN", message: "Hors du dossier autoris\xE9" });
8681
+ throw new TRPCError23({ code: "FORBIDDEN", message: "Hors du dossier autoris\xE9" });
8520
8682
  }
8521
8683
  return resolvePath(realParent, target.slice(parent.length).replace(/^[\\/]+/, ""));
8522
8684
  }
8523
8685
  var wikiRouter = router({
8524
- list: protectedProcedure.input(z27.object({ scope: SCOPE_SCHEMA })).output(z27.object({ root: z27.string(), entries: z27.array(DocsEntrySchema), truncated: z27.boolean() })).query(async ({ input }) => {
8686
+ list: protectedProcedure.input(z28.object({ scope: SCOPE_SCHEMA })).output(z28.object({ root: z28.string(), entries: z28.array(DocsEntrySchema), truncated: z28.boolean() })).query(async ({ input }) => {
8525
8687
  const target = await resolveScope(input.scope);
8526
8688
  if (target.mode === "agent") {
8527
8689
  return agentManager.agentQuery(target.agentId, "wiki.listRepoMarkdown", { cwd: target.cwd });
@@ -8530,9 +8692,9 @@ var wikiRouter = router({
8530
8692
  const entries2 = await walkLocal(target.root, target.root, 0, counter);
8531
8693
  return { root: target.root, entries: entries2, truncated: counter.n >= MAX_FILES };
8532
8694
  }),
8533
- read: protectedProcedure.input(z27.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA })).output(z27.object({ path: z27.string(), content: z27.string() })).query(async ({ input }) => {
8695
+ read: protectedProcedure.input(z28.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA })).output(z28.object({ path: z28.string(), content: z28.string() })).query(async ({ input }) => {
8534
8696
  if (!/\.(md|markdown)$/i.test(input.path)) {
8535
- throw new TRPCError22({ code: "BAD_REQUEST", message: "Seuls les .md/.markdown sont autoris\xE9s" });
8697
+ throw new TRPCError23({ code: "BAD_REQUEST", message: "Seuls les .md/.markdown sont autoris\xE9s" });
8536
8698
  }
8537
8699
  const target = await resolveScope(input.scope);
8538
8700
  if (target.mode === "agent") {
@@ -8540,14 +8702,14 @@ var wikiRouter = router({
8540
8702
  }
8541
8703
  const file = await resolveSafeLocal(target.root, input.path, true);
8542
8704
  const s = await stat4(file);
8543
- if (!s.isFile()) throw new TRPCError22({ code: "BAD_REQUEST", message: "Pas un fichier" });
8544
- if (s.size > MAX_FILE_BYTES) throw new TRPCError22({ code: "PAYLOAD_TOO_LARGE", message: "Fichier trop volumineux" });
8705
+ if (!s.isFile()) throw new TRPCError23({ code: "BAD_REQUEST", message: "Pas un fichier" });
8706
+ if (s.size > MAX_FILE_BYTES) throw new TRPCError23({ code: "PAYLOAD_TOO_LARGE", message: "Fichier trop volumineux" });
8545
8707
  const content = await readFile5(file, "utf-8");
8546
8708
  return { path: input.path, content };
8547
8709
  }),
8548
- write: protectedProcedure.input(z27.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA, content: z27.string().max(5e6) })).mutation(async ({ input }) => {
8710
+ write: protectedProcedure.input(z28.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA, content: z28.string().max(5e6) })).mutation(async ({ input }) => {
8549
8711
  if (!/\.(md|markdown)$/i.test(input.path)) {
8550
- throw new TRPCError22({ code: "BAD_REQUEST", message: "Seuls les .md/.markdown sont autoris\xE9s" });
8712
+ throw new TRPCError23({ code: "BAD_REQUEST", message: "Seuls les .md/.markdown sont autoris\xE9s" });
8551
8713
  }
8552
8714
  const target = await resolveScope(input.scope);
8553
8715
  if (target.mode === "agent") {
@@ -8558,9 +8720,9 @@ var wikiRouter = router({
8558
8720
  await writeFile5(file, input.content, "utf-8");
8559
8721
  return { path: input.path, ok: true };
8560
8722
  }),
8561
- createFile: protectedProcedure.input(z27.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA })).mutation(async ({ input }) => {
8723
+ createFile: protectedProcedure.input(z28.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA })).mutation(async ({ input }) => {
8562
8724
  if (!/\.(md|markdown)$/i.test(input.path)) {
8563
- throw new TRPCError22({ code: "BAD_REQUEST", message: "Seuls les .md/.markdown sont autoris\xE9s" });
8725
+ throw new TRPCError23({ code: "BAD_REQUEST", message: "Seuls les .md/.markdown sont autoris\xE9s" });
8564
8726
  }
8565
8727
  const target = await resolveScope(input.scope);
8566
8728
  if (target.mode === "agent") {
@@ -8569,15 +8731,15 @@ var wikiRouter = router({
8569
8731
  const file = await resolveSafeLocal(target.root, input.path, false);
8570
8732
  try {
8571
8733
  await stat4(file);
8572
- throw new TRPCError22({ code: "CONFLICT", message: "Fichier d\xE9j\xE0 existant" });
8734
+ throw new TRPCError23({ code: "CONFLICT", message: "Fichier d\xE9j\xE0 existant" });
8573
8735
  } catch (err) {
8574
- if (err instanceof TRPCError22) throw err;
8736
+ if (err instanceof TRPCError23) throw err;
8575
8737
  }
8576
8738
  await mkdir7(dirname5(file), { recursive: true });
8577
8739
  await writeFile5(file, "", "utf-8");
8578
8740
  return { path: input.path, ok: true };
8579
8741
  }),
8580
- createDir: protectedProcedure.input(z27.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA })).mutation(async ({ input }) => {
8742
+ createDir: protectedProcedure.input(z28.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA })).mutation(async ({ input }) => {
8581
8743
  const target = await resolveScope(input.scope);
8582
8744
  if (target.mode === "agent") {
8583
8745
  return agentManager.agentMutation(target.agentId, "wiki.createDir", { cwd: target.cwd, path: input.path });
@@ -8586,7 +8748,7 @@ var wikiRouter = router({
8586
8748
  await mkdir7(dir, { recursive: true });
8587
8749
  return { path: input.path, ok: true };
8588
8750
  }),
8589
- rename: protectedProcedure.input(z27.object({ scope: SCOPE_SCHEMA, fromPath: REL_PATH_SCHEMA, toPath: REL_PATH_SCHEMA })).mutation(async ({ input }) => {
8751
+ rename: protectedProcedure.input(z28.object({ scope: SCOPE_SCHEMA, fromPath: REL_PATH_SCHEMA, toPath: REL_PATH_SCHEMA })).mutation(async ({ input }) => {
8590
8752
  const target = await resolveScope(input.scope);
8591
8753
  if (target.mode === "agent") {
8592
8754
  return agentManager.agentMutation(target.agentId, "wiki.renamePath", { cwd: target.cwd, fromPath: input.fromPath, toPath: input.toPath });
@@ -8595,34 +8757,34 @@ var wikiRouter = router({
8595
8757
  const to = await resolveSafeLocal(target.root, input.toPath, false);
8596
8758
  try {
8597
8759
  await stat4(to);
8598
- throw new TRPCError22({ code: "CONFLICT", message: "La cible existe d\xE9j\xE0" });
8760
+ throw new TRPCError23({ code: "CONFLICT", message: "La cible existe d\xE9j\xE0" });
8599
8761
  } catch (err) {
8600
- if (err instanceof TRPCError22) throw err;
8762
+ if (err instanceof TRPCError23) throw err;
8601
8763
  }
8602
8764
  await mkdir7(dirname5(to), { recursive: true });
8603
8765
  await rename(from, to);
8604
8766
  return { fromPath: input.fromPath, toPath: input.toPath, ok: true };
8605
8767
  }),
8606
- ensureRoot: protectedProcedure.input(z27.object({ scope: SCOPE_SCHEMA })).mutation(async ({ input }) => {
8768
+ ensureRoot: protectedProcedure.input(z28.object({ scope: SCOPE_SCHEMA })).mutation(async ({ input }) => {
8607
8769
  if (input.scope === "global") {
8608
8770
  await resolveScope("global");
8609
8771
  return { ok: true };
8610
8772
  }
8611
8773
  const serviceId = input.scope.slice("service:".length);
8612
8774
  const service2 = await serviceStore.get(serviceId);
8613
- if (!service2) throw new TRPCError22({ code: "NOT_FOUND", message: "Service introuvable" });
8775
+ if (!service2) throw new TRPCError23({ code: "NOT_FOUND", message: "Service introuvable" });
8614
8776
  const agentId = await resolveEffectiveAgentId(service2);
8615
- if (!agentId) throw new TRPCError22({ code: "BAD_REQUEST", message: "Aucun agent configur\xE9" });
8777
+ if (!agentId) throw new TRPCError23({ code: "BAD_REQUEST", message: "Aucun agent configur\xE9" });
8616
8778
  const cwd = await resolveWorkspaceCwd({ serviceId, override: service2.docsPath?.trim() || void 0 });
8617
8779
  return agentManager.agentMutation(agentId, "wiki.ensureRoot", { cwd });
8618
8780
  }),
8619
- delete: protectedProcedure.input(z27.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA })).mutation(async ({ input }) => {
8781
+ delete: protectedProcedure.input(z28.object({ scope: SCOPE_SCHEMA, path: REL_PATH_SCHEMA })).mutation(async ({ input }) => {
8620
8782
  const target = await resolveScope(input.scope);
8621
8783
  if (target.mode === "agent") {
8622
8784
  return agentManager.agentMutation(target.agentId, "wiki.deletePath", { cwd: target.cwd, path: input.path });
8623
8785
  }
8624
8786
  const fp = await resolveSafeLocal(target.root, input.path, true);
8625
- if (fp === target.root) throw new TRPCError22({ code: "FORBIDDEN", message: "Impossible de supprimer la racine" });
8787
+ if (fp === target.root) throw new TRPCError23({ code: "FORBIDDEN", message: "Impossible de supprimer la racine" });
8626
8788
  await rm2(fp, { recursive: true, force: true });
8627
8789
  return { path: input.path, ok: true };
8628
8790
  })
@@ -8644,14 +8806,14 @@ var configRouter = router({
8644
8806
  });
8645
8807
 
8646
8808
  // ../server/src/trpc/routers/cloud-sync.ts
8647
- import { z as z28 } from "zod";
8648
- import { TRPCError as TRPCError23 } from "@trpc/server";
8809
+ import { z as z29 } from "zod";
8810
+ import { TRPCError as TRPCError24 } from "@trpc/server";
8649
8811
 
8650
8812
  // ../server/src/services/org-sync-scope.ts
8651
8813
  import { access } from "fs/promises";
8652
- import { join as join10 } from "path";
8814
+ import { join as join11 } from "path";
8653
8815
  async function isMaterialized(root) {
8654
- return access(join10(root, "project.json")).then(() => true, () => false);
8816
+ return access(join11(root, "project.json")).then(() => true, () => false);
8655
8817
  }
8656
8818
  async function orgsToSync() {
8657
8819
  const [stamps, stampedAccounts, accounts] = await Promise.all([
@@ -8733,12 +8895,12 @@ import * as Y2 from "yjs";
8733
8895
  // ../server/src/services/sync-doc-cache.ts
8734
8896
  import { readFileSync as readFileSync2, renameSync, rmSync, writeFileSync, mkdirSync } from "fs";
8735
8897
  import { readFile as readFile6 } from "fs/promises";
8736
- import { dirname as dirname6, join as join11 } from "path";
8898
+ import { dirname as dirname6, join as join12 } from "path";
8737
8899
  import { randomUUID as randomUUID7 } from "crypto";
8738
8900
  import * as Y from "yjs";
8739
8901
  var FILE2 = "sync-doc.bin";
8740
8902
  function cachePath(orgId) {
8741
- return join11(orgVaultRoot(orgId), FILE2);
8903
+ return join12(orgVaultRoot(orgId), FILE2);
8742
8904
  }
8743
8905
  async function readSyncDoc(orgId) {
8744
8906
  try {
@@ -9750,7 +9912,7 @@ var cloudSyncBridge = new CloudSyncBridge();
9750
9912
 
9751
9913
  // ../server/src/services/key-adoption.ts
9752
9914
  import { readdir as readdir3, readFile as readFile7, writeFile as writeFile6, mkdir as mkdir9, copyFile, rename as rename2, stat as stat5 } from "fs/promises";
9753
- import { dirname as dirname7, join as join12 } from "path";
9915
+ import { dirname as dirname7, join as join13 } from "path";
9754
9916
  import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, randomBytes as randomBytes3 } from "crypto";
9755
9917
  var ALGORITHM = "aes-256-gcm";
9756
9918
  function isAgentTriplet(value) {
@@ -9817,7 +9979,7 @@ async function jsonNamesIn(dir) {
9817
9979
  async function jsonFilesIn(root) {
9818
9980
  const names = await jsonNamesIn(root);
9819
9981
  for (const sub of ENCRYPTED_SUBDIRS) {
9820
- names.push(...(await jsonNamesIn(join12(root, sub))).map((n) => join12(sub, n)));
9982
+ names.push(...(await jsonNamesIn(join13(root, sub))).map((n) => join13(sub, n)));
9821
9983
  }
9822
9984
  return names;
9823
9985
  }
@@ -9855,7 +10017,7 @@ async function adoptOrgKey(orgId, newKey, masterPassword, now) {
9855
10017
  const touchedRoots = /* @__PURE__ */ new Set();
9856
10018
  for (const vaultRoot of await rootsOfOrg(orgId)) {
9857
10019
  for (const name of await jsonFilesIn(vaultRoot)) {
9858
- const path = join12(vaultRoot, name);
10020
+ const path = join13(vaultRoot, name);
9859
10021
  let parsed;
9860
10022
  try {
9861
10023
  parsed = JSON.parse(await readFile7(path, "utf-8"));
@@ -9872,15 +10034,15 @@ async function adoptOrgKey(orgId, newKey, masterPassword, now) {
9872
10034
  const stamp = now.toISOString().replace(/[:.]/g, "-").substring(0, 19);
9873
10035
  const backups = [];
9874
10036
  for (const vaultRoot of touchedRoots) {
9875
- const backupDir = join12(vaultRoot, `backup-key-${stamp}`);
10037
+ const backupDir = join13(vaultRoot, `backup-key-${stamp}`);
9876
10038
  await mkdir9(backupDir, { recursive: true });
9877
10039
  for (const name of await jsonFilesIn(vaultRoot)) {
9878
- await mkdir9(dirname7(join12(backupDir, name)), { recursive: true });
9879
- await copyFile(join12(vaultRoot, name), join12(backupDir, name));
10040
+ await mkdir9(dirname7(join13(backupDir, name)), { recursive: true });
10041
+ await copyFile(join13(vaultRoot, name), join13(backupDir, name));
9880
10042
  }
9881
10043
  for (const name of [".encryption.key.enc", ".runeya-verify"]) {
9882
- if (await exists(join12(vaultRoot, name))) {
9883
- await copyFile(join12(vaultRoot, name), join12(backupDir, name));
10044
+ if (await exists(join13(vaultRoot, name))) {
10045
+ await copyFile(join13(vaultRoot, name), join13(backupDir, name));
9884
10046
  }
9885
10047
  }
9886
10048
  backups.push(backupDir);
@@ -9935,7 +10097,7 @@ async function assertOrgReadable(orgId) {
9935
10097
  await assertOrgVaultReadable(orgId);
9936
10098
  } catch (err) {
9937
10099
  if (err instanceof OrgVaultUnreadableError) {
9938
- throw new TRPCError23({ code: "FORBIDDEN", message: err.message });
10100
+ throw new TRPCError24({ code: "FORBIDDEN", message: err.message });
9939
10101
  }
9940
10102
  throw err;
9941
10103
  }
@@ -9945,10 +10107,10 @@ async function assertOrgKey(orgId) {
9945
10107
  await reconcileOrgCanary(orgId);
9946
10108
  } catch (err) {
9947
10109
  if (err instanceof OrgKeyMismatchError) {
9948
- throw new TRPCError23({ code: "FORBIDDEN", message: err.message });
10110
+ throw new TRPCError24({ code: "FORBIDDEN", message: err.message });
9949
10111
  }
9950
10112
  if (err instanceof CanaryUnavailableError) {
9951
- throw new TRPCError23({ code: "PRECONDITION_FAILED", message: err.message });
10113
+ throw new TRPCError24({ code: "PRECONDITION_FAILED", message: err.message });
9952
10114
  }
9953
10115
  throw err;
9954
10116
  }
@@ -9965,14 +10127,14 @@ var cloudSyncRouter = router({
9965
10127
  * "open this project" is the whole gesture.
9966
10128
  */
9967
10129
  trackProject: protectedProcedure.input(
9968
- z28.object({
9969
- orgId: z28.string().min(1).max(128),
9970
- cloudUrl: z28.string().url().max(2048),
9971
- projectId: z28.string().min(1).max(128),
10130
+ z29.object({
10131
+ orgId: z29.string().min(1).max(128),
10132
+ cloudUrl: z29.string().url().max(2048),
10133
+ projectId: z29.string().min(1).max(128),
9972
10134
  // Le compte sous lequel cette organisation a été listée. Tamponné avec
9973
10135
  // elle : c'est ce qui permettra à tout appel ultérieur de retrouver le
9974
10136
  // bon token sans qu'on ait à le lui redire.
9975
- accountId: z28.string().max(64).optional()
10137
+ accountId: z29.string().max(64).optional()
9976
10138
  })
9977
10139
  ).mutation(async ({ input }) => {
9978
10140
  await assertOrgReadable(input.orgId);
@@ -9994,7 +10156,7 @@ var cloudSyncRouter = router({
9994
10156
  return { pulled, state: syncState(input.orgId) };
9995
10157
  } catch (err) {
9996
10158
  if (err instanceof ProjectHeldElsewhereError) {
9997
- throw new TRPCError23({ code: "CONFLICT", message: err.code, cause: err });
10159
+ throw new TRPCError24({ code: "CONFLICT", message: err.code, cause: err });
9998
10160
  }
9999
10161
  throw err;
10000
10162
  }
@@ -10013,22 +10175,22 @@ var cloudSyncRouter = router({
10013
10175
  * fusionné.
10014
10176
  */
10015
10177
  publishProject: protectedProcedure.input(
10016
- z28.object({
10017
- orgId: z28.string().min(1).max(128),
10018
- cloudUrl: z28.string().url().max(2048),
10019
- projectId: z28.string().min(1).max(128),
10178
+ z29.object({
10179
+ orgId: z29.string().min(1).max(128),
10180
+ cloudUrl: z29.string().url().max(2048),
10181
+ projectId: z29.string().min(1).max(128),
10020
10182
  // Le compte sous lequel cette organisation a été listée. Tamponné avec
10021
10183
  // elle : c'est ce qui permettra à tout appel ultérieur de retrouver le
10022
10184
  // bon token sans qu'on ait à le lui redire.
10023
- accountId: z28.string().max(64).optional()
10185
+ accountId: z29.string().max(64).optional()
10024
10186
  })
10025
10187
  ).mutation(async ({ input }) => {
10026
10188
  const local = await projectStore.get({ id: input.projectId, orgId: null });
10027
10189
  if (!local) {
10028
- throw new TRPCError23({ code: "NOT_FOUND", message: "PROJECT_NOT_LOCAL" });
10190
+ throw new TRPCError24({ code: "NOT_FOUND", message: "PROJECT_NOT_LOCAL" });
10029
10191
  }
10030
10192
  if (await projectStore.get({ id: input.projectId, orgId: input.orgId })) {
10031
- throw new TRPCError23({ code: "CONFLICT", message: "PROJECT_ALREADY_IN_ORG" });
10193
+ throw new TRPCError24({ code: "CONFLICT", message: "PROJECT_ALREADY_IN_ORG" });
10032
10194
  }
10033
10195
  await assertOrgReadable(input.orgId);
10034
10196
  const connected = cloudSyncBridge.states().some((s) => s.orgId === input.orgId);
@@ -10053,7 +10215,7 @@ var cloudSyncRouter = router({
10053
10215
  await cloudSyncBridge.followProject(input.orgId, input.projectId);
10054
10216
  } catch (err) {
10055
10217
  if (err instanceof ProjectHeldElsewhereError) {
10056
- throw new TRPCError23({ code: "CONFLICT", message: err.code, cause: err });
10218
+ throw new TRPCError24({ code: "CONFLICT", message: err.code, cause: err });
10057
10219
  }
10058
10220
  throw err;
10059
10221
  }
@@ -10067,16 +10229,16 @@ var cloudSyncRouter = router({
10067
10229
  * publié. Le cloud, lui, ne peut pas répondre — il n'a que du chiffré sous
10068
10230
  * les yeux — donc le canari est rapatrié et jugé ici.
10069
10231
  */
10070
- checkOrgKey: protectedProcedure.input(z28.object({
10071
- orgId: z28.string().min(1).max(128),
10072
- keyHex: z28.string().length(64).regex(/^[0-9a-f]+$/i)
10232
+ checkOrgKey: protectedProcedure.input(z29.object({
10233
+ orgId: z29.string().min(1).max(128),
10234
+ keyHex: z29.string().length(64).regex(/^[0-9a-f]+$/i)
10073
10235
  })).query(async ({ input }) => {
10074
10236
  const res = await cloudFetch2(
10075
10237
  `/api/auth/organization/canary?organizationId=${encodeURIComponent(input.orgId)}`,
10076
10238
  { method: "GET", accountId: await accountForOrgScope(input.orgId) }
10077
10239
  );
10078
10240
  if (!res.ok) {
10079
- throw new TRPCError23({ code: "BAD_GATEWAY", message: await cloudMessage(res) || `CANARY_READ_FAILED (${res.status})` });
10241
+ throw new TRPCError24({ code: "BAD_GATEWAY", message: await cloudMessage(res) || `CANARY_READ_FAILED (${res.status})` });
10080
10242
  }
10081
10243
  const { canary } = await res.json();
10082
10244
  if (typeof canary !== "string") return { matches: false, published: false };
@@ -10091,7 +10253,7 @@ var cloudSyncRouter = router({
10091
10253
  * que l'interface puisse proposer ni l'adoption ni la remise à zéro — le seul
10092
10254
  * chemin qui la répare. Rien n'est écrit ici, ni sur le disque ni sur le cloud.
10093
10255
  */
10094
- orgKeyStatus: protectedProcedure.input(z28.object({ orgId: z28.string().min(1).max(128) })).query(async ({ input }) => {
10256
+ orgKeyStatus: protectedProcedure.input(z29.object({ orgId: z29.string().min(1).max(128) })).query(async ({ input }) => {
10095
10257
  const key = getEncryptionKey(input.orgId);
10096
10258
  if (!key) return { status: "unknown" };
10097
10259
  const res = await cloudFetch2(
@@ -10114,10 +10276,10 @@ var cloudSyncRouter = router({
10114
10276
  * Bornée au coffre de l'organisation et à ceux de ses projets : les autres
10115
10277
  * organisations et la machine gardent leur clé.
10116
10278
  */
10117
- adoptOrgKey: protectedProcedure.input(z28.object({
10118
- orgId: z28.string().min(1).max(128),
10119
- keyHex: z28.string().length(64).regex(/^[0-9a-f]+$/i),
10120
- masterPassword: z28.string().min(1).max(1024)
10279
+ adoptOrgKey: protectedProcedure.input(z29.object({
10280
+ orgId: z29.string().min(1).max(128),
10281
+ keyHex: z29.string().length(64).regex(/^[0-9a-f]+$/i),
10282
+ masterPassword: z29.string().min(1).max(1024)
10121
10283
  })).mutation(async ({ input }) => {
10122
10284
  const report = await adoptOrgKey(
10123
10285
  input.orgId,
@@ -10147,14 +10309,14 @@ var cloudSyncRouter = router({
10147
10309
  * Ce qui a déjà été synchronisé sous l'ancienne clé de référence reste
10148
10310
  * illisible : aucune clé d'ici ne l'ouvre. L'interface le dit avant.
10149
10311
  */
10150
- resetOrgKey: protectedProcedure.input(z28.object({
10151
- orgId: z28.string().min(1).max(128),
10152
- masterPassword: z28.string().min(1).max(1024)
10312
+ resetOrgKey: protectedProcedure.input(z29.object({
10313
+ orgId: z29.string().min(1).max(128),
10314
+ masterPassword: z29.string().min(1).max(1024)
10153
10315
  })).mutation(async ({ input }) => {
10154
10316
  const { keyHex } = await resetOrgKeyToFresh(input.orgId, input.masterPassword, /* @__PURE__ */ new Date());
10155
10317
  const canary = await readVerifyFile(orgVaultRoot(input.orgId));
10156
10318
  if (!canary) {
10157
- throw new TRPCError23({
10319
+ throw new TRPCError24({
10158
10320
  code: "PRECONDITION_FAILED",
10159
10321
  message: "Le coffre de cette organisation n'a pas re\xE7u sa cl\xE9."
10160
10322
  });
@@ -10166,7 +10328,7 @@ var cloudSyncRouter = router({
10166
10328
  });
10167
10329
  if (!res.ok) {
10168
10330
  const detail = await cloudMessage(res);
10169
- throw new TRPCError23({
10331
+ throw new TRPCError24({
10170
10332
  code: res.status === 403 ? "FORBIDDEN" : "BAD_GATEWAY",
10171
10333
  message: detail || `ORG_KEY_RESET_FAILED (${res.status})`
10172
10334
  });
@@ -10182,9 +10344,9 @@ var cloudSyncRouter = router({
10182
10344
  * every other member and for this one on another machine.
10183
10345
  */
10184
10346
  untrackProject: protectedProcedure.input(
10185
- z28.object({
10186
- orgId: z28.string().min(1).max(128),
10187
- projectId: z28.string().min(1).max(128)
10347
+ z29.object({
10348
+ orgId: z29.string().min(1).max(128),
10349
+ projectId: z29.string().min(1).max(128)
10188
10350
  })
10189
10351
  ).mutation(async ({ input }) => {
10190
10352
  await cloudSyncBridge.unfollowProject(input.orgId, input.projectId);
@@ -10200,9 +10362,9 @@ var cloudSyncRouter = router({
10200
10362
  * membre, ce qui évite d'effacer les fichiers si le cloud a refusé l'ordre.
10201
10363
  */
10202
10364
  deleteProjectFromOrg: protectedProcedure.input(
10203
- z28.object({
10204
- orgId: z28.string().min(1).max(128),
10205
- projectId: z28.string().min(1).max(128)
10365
+ z29.object({
10366
+ orgId: z29.string().min(1).max(128),
10367
+ projectId: z29.string().min(1).max(128)
10206
10368
  })
10207
10369
  ).mutation(async ({ input }) => {
10208
10370
  let res;
@@ -10215,8 +10377,8 @@ var cloudSyncRouter = router({
10215
10377
  accountId: await accountForOrgScope(input.orgId)
10216
10378
  });
10217
10379
  } catch (err) {
10218
- if (err instanceof TRPCError23 && err.code === "PRECONDITION_FAILED") {
10219
- throw new TRPCError23({ code: "PRECONDITION_FAILED", message: "CLOUD_NOT_LINKED" });
10380
+ if (err instanceof TRPCError24 && err.code === "PRECONDITION_FAILED") {
10381
+ throw new TRPCError24({ code: "PRECONDITION_FAILED", message: "CLOUD_NOT_LINKED" });
10220
10382
  }
10221
10383
  throw err;
10222
10384
  }
@@ -10224,12 +10386,12 @@ var cloudSyncRouter = router({
10224
10386
  const detail = await cloudMessage(res);
10225
10387
  if (res.status === 403) {
10226
10388
  const code = /not a member/i.test(detail) ? "PROJECT_NOT_MEMBER" : "PROJECT_DELETE_FORBIDDEN";
10227
- throw new TRPCError23({ code: "FORBIDDEN", message: code, cause: new Error(detail) });
10389
+ throw new TRPCError24({ code: "FORBIDDEN", message: code, cause: new Error(detail) });
10228
10390
  }
10229
10391
  if (res.status === 404) {
10230
- throw new TRPCError23({ code: "NOT_FOUND", message: "PROJECT_NOT_IN_ORG", cause: new Error(detail) });
10392
+ throw new TRPCError24({ code: "NOT_FOUND", message: "PROJECT_NOT_IN_ORG", cause: new Error(detail) });
10231
10393
  }
10232
- throw new TRPCError23({
10394
+ throw new TRPCError24({
10233
10395
  code: "BAD_GATEWAY",
10234
10396
  message: detail || `PROJECT_DELETE_FAILED (${res.status})`
10235
10397
  });
@@ -10258,10 +10420,10 @@ var cloudSyncRouter = router({
10258
10420
  * d'un autre. Même forme que `rememberOrgNames`, et pour la même raison :
10259
10421
  * ce que seul le cloud sait, on le recopie quand il le dit.
10260
10422
  */
10261
- rememberOrgAccounts: protectedProcedure.input(z28.object({
10262
- orgs: z28.array(z28.object({
10263
- orgId: z28.string().min(1).max(128),
10264
- accountId: z28.string().min(1).max(64)
10423
+ rememberOrgAccounts: protectedProcedure.input(z29.object({
10424
+ orgs: z29.array(z29.object({
10425
+ orgId: z29.string().min(1).max(128),
10426
+ accountId: z29.string().min(1).max(64)
10265
10427
  })).max(200)
10266
10428
  })).mutation(async ({ input }) => {
10267
10429
  const candidates = /* @__PURE__ */ new Map();
@@ -10288,10 +10450,10 @@ var cloudSyncRouter = router({
10288
10450
  }
10289
10451
  return { remembered };
10290
10452
  }),
10291
- rememberOrgNames: protectedProcedure.input(z28.object({
10292
- orgs: z28.array(z28.object({
10293
- orgId: z28.string().min(1).max(128),
10294
- name: z28.string().min(1).max(100)
10453
+ rememberOrgNames: protectedProcedure.input(z29.object({
10454
+ orgs: z29.array(z29.object({
10455
+ orgId: z29.string().min(1).max(128),
10456
+ name: z29.string().min(1).max(100)
10295
10457
  })).max(200)
10296
10458
  })).mutation(async ({ input }) => {
10297
10459
  for (const { orgId, name } of input.orgs) await rememberOrgName(orgId, name);
@@ -10321,7 +10483,7 @@ var cloudSyncRouter = router({
10321
10483
  * Un 404 efface le logo retenu — l'organisation en a retiré un — tandis qu'un
10322
10484
  * réseau muet laisse en place ce qui est déjà là : hors ligne, on garde.
10323
10485
  */
10324
- cacheOrgLogos: protectedProcedure.input(z28.object({ orgIds: z28.array(z28.string().min(1).max(128)).max(200) })).mutation(async ({ input }) => {
10486
+ cacheOrgLogos: protectedProcedure.input(z29.object({ orgIds: z29.array(z29.string().min(1).max(128)).max(200) })).mutation(async ({ input }) => {
10325
10487
  let cached = 0;
10326
10488
  for (const orgId of input.orgIds) {
10327
10489
  const base = await orgCloudUrl(orgId);
@@ -10379,13 +10541,13 @@ var cloudSyncRouter = router({
10379
10541
  // ../server/src/trpc/routers/filesystem.ts
10380
10542
  import { readdir as readdir4, stat as stat6 } from "fs/promises";
10381
10543
  import { homedir as homedir4 } from "os";
10382
- import { isAbsolute as isAbsolute3, join as join13, resolve as resolve3, dirname as dirname8, basename } from "path";
10383
- import { z as z29 } from "zod";
10544
+ import { isAbsolute as isAbsolute3, join as join14, resolve as resolve3, dirname as dirname8, basename } from "path";
10545
+ import { z as z30 } from "zod";
10384
10546
  var MAX_ENTRIES2 = 500;
10385
- var PATH_SCHEMA = z29.string().min(1).max(4096);
10547
+ var PATH_SCHEMA = z30.string().min(1).max(4096);
10386
10548
  function safeResolve(input) {
10387
10549
  if (input.includes("\0")) throw new Error("Chemin invalide");
10388
- const expanded = input.startsWith("~") ? join13(homedir4(), input.slice(1)) : input;
10550
+ const expanded = input.startsWith("~") ? join14(homedir4(), input.slice(1)) : input;
10389
10551
  if (!isAbsolute3(expanded)) throw new Error("Le chemin doit \xEAtre absolu");
10390
10552
  return resolve3(expanded);
10391
10553
  }
@@ -10406,7 +10568,7 @@ var filesystemRouter = router({
10406
10568
  * Hidden entries are skipped: they are noise for choosing a workspace, and
10407
10569
  * `.runeya` itself would invite placing a project inside another's data.
10408
10570
  */
10409
- listDirectories: protectedProcedure.input(z29.object({ path: PATH_SCHEMA })).query(async ({ input }) => {
10571
+ listDirectories: protectedProcedure.input(z30.object({ path: PATH_SCHEMA })).query(async ({ input }) => {
10410
10572
  const dir = safeResolve(input.path);
10411
10573
  const info = await stat6(dir).catch(() => null);
10412
10574
  if (!info?.isDirectory()) {
@@ -10421,7 +10583,7 @@ var filesystemRouter = router({
10421
10583
  const truncated = names.length > MAX_ENTRIES2;
10422
10584
  const entries2 = [];
10423
10585
  for (const name of names.slice(0, MAX_ENTRIES2)) {
10424
- const path = join13(dir, name);
10586
+ const path = join14(dir, name);
10425
10587
  entries2.push({ name, path, hasRuneyaProject: await holdsRuneyaProject(path) });
10426
10588
  }
10427
10589
  return {
@@ -10439,7 +10601,7 @@ var filesystemRouter = router({
10439
10601
  * qui s'y trouve, ou rien (déjà dans la liste, lié à un projet d'organisation,
10440
10602
  * racine machine).
10441
10603
  */
10442
- checkLocalProjectTarget: protectedProcedure.input(z29.object({ path: PATH_SCHEMA })).query(async ({ input }) => {
10604
+ checkLocalProjectTarget: protectedProcedure.input(z30.object({ path: PATH_SCHEMA })).query(async ({ input }) => {
10443
10605
  const dir = safeResolve(input.path);
10444
10606
  const info = await stat6(dir).catch(() => null);
10445
10607
  if (!info?.isDirectory()) return { path: dir, status: "missing", projectName: null };
@@ -10451,10 +10613,10 @@ var filesystemRouter = router({
10451
10613
  * Two projects in one directory is what makes services run against the wrong
10452
10614
  * code, so a directory that already holds one is refused outright.
10453
10615
  */
10454
- checkProjectTarget: protectedProcedure.input(z29.object({
10616
+ checkProjectTarget: protectedProcedure.input(z30.object({
10455
10617
  path: PATH_SCHEMA,
10456
- projectId: z29.string().min(1).max(128),
10457
- orgId: z29.string().max(128).nullable().optional()
10618
+ projectId: z30.string().min(1).max(128),
10619
+ orgId: z30.string().max(128).nullable().optional()
10458
10620
  })).query(async ({ input }) => {
10459
10621
  const dir = safeResolve(input.path);
10460
10622
  const info = await stat6(dir).catch(() => null);
@@ -10473,9 +10635,9 @@ var filesystemRouter = router({
10473
10635
  });
10474
10636
 
10475
10637
  // ../server/src/trpc/routers/desktop.ts
10476
- import { z as z30 } from "zod";
10638
+ import { z as z31 } from "zod";
10477
10639
  import { isAbsolute as isAbsolute5 } from "path";
10478
- import { TRPCError as TRPCError24 } from "@trpc/server";
10640
+ import { TRPCError as TRPCError25 } from "@trpc/server";
10479
10641
 
10480
10642
  // ../server/src/services/desktop-launcher.ts
10481
10643
  import { execFile as execFile5 } from "child_process";
@@ -10559,53 +10721,53 @@ var desktopRouter = router({
10559
10721
  * dessinée par le serveur. Sans cette annonce elle garderait la teinte figée
10560
10722
  * du fichier livré avec le CLI. Rien n'est persisté — voir `tray-accent.ts`.
10561
10723
  */
10562
- setTrayAccent: protectedProcedure.input(z30.object({
10724
+ setTrayAccent: protectedProcedure.input(z31.object({
10563
10725
  // `#rgb` ou `#rrggbb` : la forme est vérifiée ici, pas rabotée plus loin.
10564
- color: z30.string().regex(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/).nullable()
10726
+ color: z31.string().regex(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/).nullable()
10565
10727
  })).mutation(({ input }) => {
10566
10728
  setTrayAccent(input.color);
10567
10729
  return { ok: true };
10568
10730
  }),
10569
- installLauncher: protectedProcedure.input(z30.object({
10570
- name: z30.string().trim().min(1).max(120),
10731
+ installLauncher: protectedProcedure.input(z31.object({
10732
+ name: z31.string().trim().min(1).max(120),
10571
10733
  /**
10572
10734
  * `null` : raccourci global, sans dossier épinglé. Sinon un chemin
10573
10735
  * absolu, refusé autrement : le dossier devient un argument positionnel
10574
10736
  * du CLI, où une valeur commençant par un tiret passerait pour un drapeau.
10575
10737
  */
10576
- workingDir: z30.string().max(4096).refine(isAbsolute5, {
10738
+ workingDir: z31.string().max(4096).refine(isAbsolute5, {
10577
10739
  message: "Le dossier de travail doit \xEAtre un chemin absolu."
10578
10740
  }).nullable(),
10579
- port: z30.number().int().min(1).max(65535),
10580
- agentPort: z30.number().int().min(1).max(65535),
10741
+ port: z31.number().int().min(1).max(65535),
10742
+ agentPort: z31.number().int().min(1).max(65535),
10581
10743
  /** Projet ouvert directement par le raccourci (`--project`). Absent : liste des projets. */
10582
- projectId: z30.string().max(128).regex(LAUNCHER_PROJECT_ID_PATTERN).nullable().optional()
10744
+ projectId: z31.string().max(128).regex(LAUNCHER_PROJECT_ID_PATTERN).nullable().optional()
10583
10745
  })).mutation(async ({ input }) => {
10584
10746
  try {
10585
10747
  return await installLauncher(input);
10586
10748
  } catch (err) {
10587
10749
  const message = err.message;
10588
10750
  if (message === "launcher-working-dir-not-absolute") {
10589
- throw new TRPCError24({
10751
+ throw new TRPCError25({
10590
10752
  code: "BAD_REQUEST",
10591
10753
  message: "Le dossier de travail doit \xEAtre un chemin absolu."
10592
10754
  });
10593
10755
  }
10594
10756
  if (message === "launcher-unavailable") {
10595
- throw new TRPCError24({
10757
+ throw new TRPCError25({
10596
10758
  code: "PRECONDITION_FAILED",
10597
10759
  message: "Cette Runeya ne sait pas o\xF9 trouver son CLI : cr\xE9ez le raccourci avec `runeya install-desktop`."
10598
10760
  });
10599
10761
  }
10600
- throw new TRPCError24({ code: "INTERNAL_SERVER_ERROR", message });
10762
+ throw new TRPCError25({ code: "INTERNAL_SERVER_ERROR", message });
10601
10763
  }
10602
10764
  })
10603
10765
  });
10604
10766
 
10605
10767
  // ../server/src/trpc/routers/mcp-ready.ts
10606
- import { z as z31 } from "zod";
10768
+ import { z as z32 } from "zod";
10607
10769
  var mcpReadyRouter = router({
10608
- signal: protectedProcedure.input(z31.object({ id: z31.string().min(1).max(128) })).mutation(({ input }) => {
10770
+ signal: protectedProcedure.input(z32.object({ id: z32.string().min(1).max(128) })).mutation(({ input }) => {
10609
10771
  signalMcpReady(input.id);
10610
10772
  return { ok: true };
10611
10773
  })
@@ -10617,6 +10779,7 @@ var appRouter = router({
10617
10779
  session: sessionRouter,
10618
10780
  appUpdate: appUpdateRouter,
10619
10781
  changelog: changelogRouter,
10782
+ support: supportRouter,
10620
10783
  diagnostics: diagnosticsRouter,
10621
10784
  mcpPairing: mcpPairingRouter,
10622
10785
  mcpReady: mcpReadyRouter,
@@ -10711,7 +10874,7 @@ async function ensureFilePermissions() {
10711
10874
 
10712
10875
  // ../server/src/services/vault-migration.ts
10713
10876
  import { readdir as readdir5, readFile as readFile8, writeFile as writeFile7, mkdir as mkdir10, copyFile as copyFile2, unlink, rename as rename3, stat as stat8 } from "fs/promises";
10714
- import { join as join14 } from "path";
10877
+ import { join as join15 } from "path";
10715
10878
  var KEY_FILES = [".encryption.key.enc", ".runeya-verify"];
10716
10879
  var MACHINE_FILES = [
10717
10880
  "agents.json",
@@ -10741,17 +10904,17 @@ async function openLegacyVault(legacyRoot, masterPassword) {
10741
10904
  }
10742
10905
  async function migrateLegacyVault(legacyRoot, machineRootDir, legacyKey, machineKey, now) {
10743
10906
  const stamp = now.toISOString().replace(/[:.]/g, "-").substring(0, 19);
10744
- const backupDir = join14(legacyRoot, `backup-${stamp}`);
10907
+ const backupDir = join15(legacyRoot, `backup-${stamp}`);
10745
10908
  await mkdir10(backupDir, { recursive: true });
10746
10909
  const jsonFiles = await vaultJsonFiles(legacyRoot);
10747
10910
  for (const name of [...jsonFiles, ...KEY_FILES]) {
10748
- if (await exists2(join14(legacyRoot, name))) {
10749
- await copyFile2(join14(legacyRoot, name), join14(backupDir, name));
10911
+ if (await exists2(join15(legacyRoot, name))) {
10912
+ await copyFile2(join15(legacyRoot, name), join15(backupDir, name));
10750
10913
  }
10751
10914
  }
10752
10915
  const rekeyed = [];
10753
10916
  for (const name of jsonFiles) {
10754
- const raw = await readFile8(join14(legacyRoot, name), "utf-8");
10917
+ const raw = await readFile8(join15(legacyRoot, name), "utf-8");
10755
10918
  let parsed;
10756
10919
  try {
10757
10920
  parsed = JSON.parse(raw);
@@ -10761,13 +10924,13 @@ async function migrateLegacyVault(legacyRoot, machineRootDir, legacyKey, machine
10761
10924
  const counter = { n: 0 };
10762
10925
  const converted = rekeyValue(parsed, legacyKey, machineKey, counter);
10763
10926
  if (counter.n === 0) continue;
10764
- const tmp = join14(legacyRoot, `${name}.tmp`);
10927
+ const tmp = join15(legacyRoot, `${name}.tmp`);
10765
10928
  await writeFile7(tmp, JSON.stringify(converted, null, 2), "utf-8");
10766
- await rename3(tmp, join14(legacyRoot, name));
10929
+ await rename3(tmp, join15(legacyRoot, name));
10767
10930
  rekeyed.push({ file: name, values: counter.n });
10768
10931
  }
10769
10932
  for (const { file, values } of rekeyed) {
10770
- const parsed = JSON.parse(await readFile8(join14(legacyRoot, file), "utf-8"));
10933
+ const parsed = JSON.parse(await readFile8(join15(legacyRoot, file), "utf-8"));
10771
10934
  const check = { n: 0 };
10772
10935
  rekeyValue(parsed, machineKey, machineKey, check);
10773
10936
  if (check.n !== values) {
@@ -10780,9 +10943,9 @@ async function migrateLegacyVault(legacyRoot, machineRootDir, legacyKey, machine
10780
10943
  const moved = [];
10781
10944
  const skipped = [];
10782
10945
  for (const name of MACHINE_FILES) {
10783
- const from = join14(legacyRoot, name);
10946
+ const from = join15(legacyRoot, name);
10784
10947
  if (!await exists2(from)) continue;
10785
- const to = join14(machineRootDir, name);
10948
+ const to = join15(machineRootDir, name);
10786
10949
  if (await exists2(to)) {
10787
10950
  skipped.push(name);
10788
10951
  continue;
@@ -10792,7 +10955,7 @@ async function migrateLegacyVault(legacyRoot, machineRootDir, legacyKey, machine
10792
10955
  moved.push(name);
10793
10956
  }
10794
10957
  for (const name of KEY_FILES) {
10795
- const path = join14(legacyRoot, name);
10958
+ const path = join15(legacyRoot, name);
10796
10959
  if (await exists2(path)) await unlink(path);
10797
10960
  }
10798
10961
  return { backupDir, rekeyed, moved, skipped };
@@ -10800,7 +10963,7 @@ async function migrateLegacyVault(legacyRoot, machineRootDir, legacyKey, machine
10800
10963
 
10801
10964
  // ../server/src/services/settings-migration.ts
10802
10965
  import { readFile as readFile9, writeFile as writeFile8, rename as rename4, unlink as unlink2, mkdir as mkdir11, chmod as chmod4, stat as stat9 } from "fs/promises";
10803
- import { join as join15 } from "path";
10966
+ import { join as join16 } from "path";
10804
10967
  var SETTINGS_FILE = "settings.json";
10805
10968
  var SETTINGS_PRIVATE_FILE = "settings.private.json";
10806
10969
  async function exists3(path) {
@@ -10814,7 +10977,7 @@ async function legacySource(filename) {
10814
10977
  }
10815
10978
  async function moveInto(root, filename, from) {
10816
10979
  await mkdir11(root, { recursive: true });
10817
- const to = join15(root, filename);
10980
+ const to = join16(root, filename);
10818
10981
  const contents = await readFile9(from, "utf-8");
10819
10982
  const tmp = to + ".tmp";
10820
10983
  await writeFile8(tmp, contents, "utf-8");
@@ -10839,7 +11002,7 @@ async function migrateSettingsIntoVaults() {
10839
11002
  const orgId = orgs[0];
10840
11003
  const root = orgVaultRoot(orgId);
10841
11004
  for (const { filename, from } of sources) {
10842
- if (await exists3(join15(root, filename))) continue;
11005
+ if (await exists3(join16(root, filename))) continue;
10843
11006
  await moveInto(root, filename, from);
10844
11007
  report.files.push(filename);
10845
11008
  }
@@ -10862,7 +11025,7 @@ import {
10862
11025
  access as access2,
10863
11026
  readdir as readdir6
10864
11027
  } from "fs/promises";
10865
- import { join as join16, dirname as dirname9 } from "path";
11028
+ import { join as join17, dirname as dirname9 } from "path";
10866
11029
  var _require = createRequire(import.meta.url);
10867
11030
  var PARSER_ID_MAP = {
10868
11031
  "stack-monitor-parser-jsons": "native:json",
@@ -11004,7 +11167,7 @@ async function atomicWrite(path, data) {
11004
11167
  }
11005
11168
  async function runLegacyMigration(dataDir) {
11006
11169
  const legacyRoot = env.DATA_DIR;
11007
- const legacyKeyPath = join16(legacyRoot, "dbs", "encryption-key.json");
11170
+ const legacyKeyPath = join17(legacyRoot, "dbs", "encryption-key.json");
11008
11171
  try {
11009
11172
  await access2(legacyKeyPath);
11010
11173
  } catch {
@@ -11015,17 +11178,17 @@ async function runLegacyMigration(dataDir) {
11015
11178
  const legacyTmp = `${legacyRoot}-tmp`;
11016
11179
  await rename5(legacyRoot, legacyTmp);
11017
11180
  await mkdir12(dataDir, { recursive: true });
11018
- const legacyOld = join16(dataDir, `backup-${timestamp}`);
11181
+ const legacyOld = join17(dataDir, `backup-${timestamp}`);
11019
11182
  await rename5(legacyTmp, legacyOld);
11020
11183
  console.log(`[legacy-migration] Legacy data backed up to ${legacyOld}`);
11021
- const keyJson = JSON.parse(await readFile10(join16(legacyOld, "dbs", "encryption-key.json"), "utf-8"));
11184
+ const keyJson = JSON.parse(await readFile10(join17(legacyOld, "dbs", "encryption-key.json"), "utf-8"));
11022
11185
  const sodium = await getSodium();
11023
11186
  const sodiumKey = sodium.from_base64(keyJson.encryptionKey);
11024
11187
  const keyBuffer = Buffer.from(sodiumKey);
11025
11188
  const runyeaKeyHex = keyBuffer.toString("hex");
11026
11189
  await setEncryptionKey(runyeaKeyHex);
11027
11190
  console.log("[legacy-migration] Encryption key loaded in memory (temporary)");
11028
- const dbsDir = join16(legacyOld, "dbs");
11191
+ const dbsDir = join17(legacyOld, "dbs");
11029
11192
  async function readEncrypted(filePath) {
11030
11193
  try {
11031
11194
  return await decryptLegacyFile(filePath, sodiumKey, sodium);
@@ -11034,29 +11197,29 @@ async function runLegacyMigration(dataDir) {
11034
11197
  return null;
11035
11198
  }
11036
11199
  }
11037
- const envsDir = join16(dbsDir, "envs");
11200
+ const envsDir = join17(dbsDir, "envs");
11038
11201
  const envFiles = (await readdir6(envsDir).catch(() => [])).filter((f) => f.endsWith(".encrypted.json"));
11039
11202
  const legacyEnvs = {};
11040
11203
  for (const file of envFiles) {
11041
11204
  const name = file.replace(".encrypted.json", "");
11042
- legacyEnvs[name] = await readEncrypted(join16(envsDir, file));
11205
+ legacyEnvs[name] = await readEncrypted(join17(envsDir, file));
11043
11206
  }
11044
- const servicesDir = join16(dbsDir, "services");
11207
+ const servicesDir = join17(dbsDir, "services");
11045
11208
  const serviceFiles = (await readdir6(servicesDir).catch(() => [])).filter((f) => f.endsWith(".encrypted.json"));
11046
11209
  const legacyServices = {};
11047
11210
  for (const file of serviceFiles) {
11048
11211
  const name = file.replace(".encrypted.json", "");
11049
11212
  if (!name) continue;
11050
- const data = await readEncrypted(join16(servicesDir, file));
11213
+ const data = await readEncrypted(join17(servicesDir, file));
11051
11214
  if (data?.label) legacyServices[name] = data;
11052
11215
  }
11053
- const overridesDir = join16(dbsDir, "overrides");
11216
+ const overridesDir = join17(dbsDir, "overrides");
11054
11217
  const overrideFiles = (await readdir6(overridesDir).catch(() => [])).filter((f) => f.endsWith(".encrypted.json"));
11055
11218
  const legacyServiceOverrides = {};
11056
11219
  const legacyEnvOverrides = {};
11057
11220
  for (const file of overrideFiles) {
11058
11221
  const baseName = file.replace(".encrypted.json", "");
11059
- const data = await readEncrypted(join16(overridesDir, file));
11222
+ const data = await readEncrypted(join17(overridesDir, file));
11060
11223
  if (!data) continue;
11061
11224
  if (baseName.endsWith("-envs")) {
11062
11225
  legacyServiceOverrides[baseName.slice(0, -5)] = data;
@@ -11064,11 +11227,11 @@ async function runLegacyMigration(dataDir) {
11064
11227
  legacyEnvOverrides[baseName.slice(0, -12)] = data;
11065
11228
  }
11066
11229
  }
11067
- const parsersDir = join16(dbsDir, "parsers");
11230
+ const parsersDir = join17(dbsDir, "parsers");
11068
11231
  const parserFiles = (await readdir6(parsersDir).catch(() => [])).filter((f) => f.endsWith(".encrypted.json"));
11069
11232
  const legacyParsers = [];
11070
11233
  for (const file of parserFiles) {
11071
- const data = await readEncrypted(join16(parsersDir, file));
11234
+ const data = await readEncrypted(join17(parsersDir, file));
11072
11235
  if (data?.id) legacyParsers.push(data);
11073
11236
  }
11074
11237
  const projectMonoId = randomUUID9();
@@ -11409,7 +11572,7 @@ async function runLegacyMigration(dataDir) {
11409
11572
  }
11410
11573
  let existingSettings = {};
11411
11574
  try {
11412
- existingSettings = JSON.parse(await readFile10(join16(dataDir, "settings.json"), "utf-8"));
11575
+ existingSettings = JSON.parse(await readFile10(join17(dataDir, "settings.json"), "utf-8"));
11413
11576
  } catch {
11414
11577
  }
11415
11578
  const migratedParsers = legacyParsers.map((p) => ({
@@ -11430,11 +11593,11 @@ ${p.transform ?? ""}`,
11430
11593
  ...migratedParsers
11431
11594
  ]
11432
11595
  };
11433
- await atomicWrite(join16(dataDir, "projects.json"), runeProjects);
11434
- await atomicWrite(join16(dataDir, "services.json"), runeServices);
11435
- await atomicWrite(join16(dataDir, "environments.json"), runeEnvs);
11436
- await atomicWrite(join16(dataDir, "environment-overrides.json"), flatOverrides);
11437
- await atomicWrite(join16(dataDir, "settings.json"), newSettings);
11596
+ await atomicWrite(join17(dataDir, "projects.json"), runeProjects);
11597
+ await atomicWrite(join17(dataDir, "services.json"), runeServices);
11598
+ await atomicWrite(join17(dataDir, "environments.json"), runeEnvs);
11599
+ await atomicWrite(join17(dataDir, "environment-overrides.json"), flatOverrides);
11600
+ await atomicWrite(join17(dataDir, "settings.json"), newSettings);
11438
11601
  const svcEnvCount = runeEnvs.filter((e) => e.scope === "service").length;
11439
11602
  console.log(`[legacy-migration] Written: ${runeProjects.length} projects, ${runeServices.length} services, ${runeEnvs.length} environments (${svcEnvCount} service-scoped)`);
11440
11603
  console.log(`[legacy-migration] Overrides: ${Object.keys(flatOverrides).length}, custom parsers: ${migratedParsers.length} (all disabled \u2014 rewrite required)`);
@@ -11448,7 +11611,7 @@ async function findLegacyKeyInBackup(dataDir) {
11448
11611
  const entries2 = await readdir6(dataDir);
11449
11612
  const backupDirs = entries2.filter((e) => e.startsWith("backup-")).sort((a, b) => a < b ? -1 : a > b ? 1 : 0).reverse();
11450
11613
  for (const dir of backupDirs) {
11451
- const keyJsonPath = join16(dataDir, dir, "dbs", "encryption-key.json");
11614
+ const keyJsonPath = join17(dataDir, dir, "dbs", "encryption-key.json");
11452
11615
  try {
11453
11616
  const raw = await readFile10(keyJsonPath, "utf-8");
11454
11617
  const parsed = JSON.parse(raw);
@@ -11471,8 +11634,8 @@ async function runOverrideOnlyMigration(dataDir) {
11471
11634
  const { resolve: resolve5 } = await import("path");
11472
11635
  const abDataDir = resolve5(dataDir);
11473
11636
  const candidateDirs = [
11474
- join16(dirname9(env.DATA_DIR), ".runeya", "dbs", "overrides"),
11475
- join16(abDataDir, "dbs", "overrides")
11637
+ join17(dirname9(env.DATA_DIR), ".runeya", "dbs", "overrides"),
11638
+ join17(abDataDir, "dbs", "overrides")
11476
11639
  ];
11477
11640
  let overridesDir = null;
11478
11641
  let overrideFiles = [];
@@ -11488,7 +11651,7 @@ async function runOverrideOnlyMigration(dataDir) {
11488
11651
  }
11489
11652
  }
11490
11653
  if (!overridesDir || overrideFiles.length === 0) return false;
11491
- const legacyKeyPath = join16(overridesDir, "..", "encryption-key.json");
11654
+ const legacyKeyPath = join17(overridesDir, "..", "encryption-key.json");
11492
11655
  try {
11493
11656
  await access2(legacyKeyPath);
11494
11657
  return false;
@@ -11506,7 +11669,7 @@ async function runOverrideOnlyMigration(dataDir) {
11506
11669
  const envNameToId = {};
11507
11670
  let envsRaw;
11508
11671
  try {
11509
- envsRaw = JSON.parse(await readFile10(join16(abDataDir, "environments.json"), "utf-8"));
11672
+ envsRaw = JSON.parse(await readFile10(join17(abDataDir, "environments.json"), "utf-8"));
11510
11673
  for (const _env of envsRaw) {
11511
11674
  const env2 = _env;
11512
11675
  if (env2["name"] && env2["id"]) {
@@ -11525,7 +11688,7 @@ async function runOverrideOnlyMigration(dataDir) {
11525
11688
  let servicesRaw = [];
11526
11689
  const serviceNameToId = {};
11527
11690
  try {
11528
- servicesRaw = JSON.parse(await readFile10(join16(abDataDir, "services.json"), "utf-8"));
11691
+ servicesRaw = JSON.parse(await readFile10(join17(abDataDir, "services.json"), "utf-8"));
11529
11692
  for (const _svc of servicesRaw) {
11530
11693
  const svc = _svc;
11531
11694
  if (svc["name"] && svc["id"]) serviceNameToId[svc["name"]] = svc["id"];
@@ -11542,7 +11705,7 @@ async function runOverrideOnlyMigration(dataDir) {
11542
11705
  const envName = baseName.slice(0, -"-environment".length);
11543
11706
  let data;
11544
11707
  try {
11545
- data = await decryptLegacyFile(join16(overridesDir, file), sodiumKey, sodium);
11708
+ data = await decryptLegacyFile(join17(overridesDir, file), sodiumKey, sodium);
11546
11709
  } catch (err) {
11547
11710
  console.warn(`[override-migration] Failed to decrypt ${file}: ${err.message}`);
11548
11711
  continue;
@@ -11569,7 +11732,7 @@ async function runOverrideOnlyMigration(dataDir) {
11569
11732
  }
11570
11733
  }
11571
11734
  if (Object.keys(flatOverrides).length > 0) {
11572
- await atomicWrite(join16(abDataDir, "environment-overrides.json"), flatOverrides);
11735
+ await atomicWrite(join17(abDataDir, "environment-overrides.json"), flatOverrides);
11573
11736
  console.log(`[override-migration] Written ${Object.keys(flatOverrides).length} override(s) to environment-overrides.json`);
11574
11737
  }
11575
11738
  let envsModified = false;
@@ -11579,7 +11742,7 @@ async function runOverrideOnlyMigration(dataDir) {
11579
11742
  const serviceName = baseName.slice(0, -"-envs".length);
11580
11743
  let data;
11581
11744
  try {
11582
- data = await decryptLegacyFile(join16(overridesDir, file), sodiumKey, sodium);
11745
+ data = await decryptLegacyFile(join17(overridesDir, file), sodiumKey, sodium);
11583
11746
  } catch (err) {
11584
11747
  console.warn(`[override-migration] Failed to decrypt ${file}: ${err.message}`);
11585
11748
  continue;
@@ -11638,7 +11801,7 @@ async function runOverrideOnlyMigration(dataDir) {
11638
11801
  }
11639
11802
  }
11640
11803
  if (envsModified) {
11641
- await atomicWrite(join16(abDataDir, "environments.json"), envsRaw);
11804
+ await atomicWrite(join17(abDataDir, "environments.json"), envsRaw);
11642
11805
  console.log("[override-migration] Merged service overrides into environments.json");
11643
11806
  }
11644
11807
  const migratedDir = overridesDir.replace(/overrides$/, "overrides-migrated");
@@ -11653,7 +11816,7 @@ async function runOverrideOnlyMigration(dataDir) {
11653
11816
  }
11654
11817
 
11655
11818
  // ../server/src/services/server-state.ts
11656
- import { join as join17 } from "path";
11819
+ import { join as join18 } from "path";
11657
11820
  import { stat as stat10 } from "fs/promises";
11658
11821
  var ENCRYPTED_KEY_FILENAME2 = ".encryption.key.enc";
11659
11822
  var VERIFY_FILENAME2 = ".runeya-verify";
@@ -11663,22 +11826,22 @@ async function getServerState() {
11663
11826
  let hasVerify = false;
11664
11827
  let hasData = false;
11665
11828
  try {
11666
- await stat10(join17(dataDir, ENCRYPTED_KEY_FILENAME2));
11829
+ await stat10(join18(dataDir, ENCRYPTED_KEY_FILENAME2));
11667
11830
  hasEncFile = true;
11668
11831
  } catch {
11669
11832
  }
11670
11833
  try {
11671
- await stat10(join17(dataDir, VERIFY_FILENAME2));
11834
+ await stat10(join18(dataDir, VERIFY_FILENAME2));
11672
11835
  hasVerify = true;
11673
11836
  } catch {
11674
11837
  }
11675
11838
  try {
11676
- await stat10(join17(dataDir, "projects.json"));
11839
+ await stat10(join18(dataDir, "projects.json"));
11677
11840
  hasData = true;
11678
11841
  } catch {
11679
11842
  }
11680
11843
  try {
11681
- await stat10(join17(dataDir, "project.json"));
11844
+ await stat10(join18(dataDir, "project.json"));
11682
11845
  hasData = true;
11683
11846
  } catch {
11684
11847
  }
@@ -12191,7 +12354,7 @@ async function createLocalServer() {
12191
12354
  machineRoot(),
12192
12355
  ...orgRoots,
12193
12356
  ...vaultRoots,
12194
- ...[machineRoot(), ...vaultRoots].map((root) => join18(root, CONVERSATIONS_DIRNAME))
12357
+ ...[machineRoot(), ...vaultRoots].map((root) => join19(root, CONVERSATIONS_DIRNAME))
12195
12358
  ]);
12196
12359
  if (removed > 0) console.log(`[server] ${removed} fichier(s) temporaire(s) orphelin(s) retir\xE9(s)`);
12197
12360
  })().catch((err) => console.warn("[server] Temp file sweep failed:", err));
@@ -12446,6 +12609,114 @@ async function createLocalServer() {
12446
12609
  });
12447
12610
  proxyCloudStream("/api/cloud/chat/stream", "/api/chat/stream");
12448
12611
  proxyCloudStream("/api/cloud/kanban/stream", "/api/kanban/stream");
12612
+ const supportFileScope = (req) => ({
12613
+ ...typeof req.query["ticketId"] === "string" ? { ticketId: req.query["ticketId"] } : {},
12614
+ ...typeof req.query["accountId"] === "string" ? { accountId: req.query["accountId"] } : {}
12615
+ });
12616
+ app.post("/api/cloud/support/file", express.raw({ type: () => true, limit: "64mb" }), async (req, res) => {
12617
+ try {
12618
+ await verifyJwt(typeof req.query["token"] === "string" ? req.query["token"] : "");
12619
+ } catch {
12620
+ res.status(401).end();
12621
+ return;
12622
+ }
12623
+ const name = typeof req.query["name"] === "string" ? req.query["name"] : "file";
12624
+ try {
12625
+ const upstream = await supportFileFetch(`/api/support/file?${new URLSearchParams({ name }).toString()}`, {
12626
+ method: "POST",
12627
+ body: req.body,
12628
+ contentType: String(req.headers["content-type"] ?? "application/octet-stream"),
12629
+ ...supportFileScope(req)
12630
+ });
12631
+ res.status(upstream.status).json(await upstream.json().catch(() => ({})));
12632
+ } catch {
12633
+ res.status(502).json({ error: "upload-failed" });
12634
+ }
12635
+ });
12636
+ app.get("/api/cloud/support/file/:id", async (req, res) => {
12637
+ try {
12638
+ await verifyJwt(typeof req.query["token"] === "string" ? req.query["token"] : "");
12639
+ } catch {
12640
+ res.status(401).end();
12641
+ return;
12642
+ }
12643
+ try {
12644
+ const upstream = await supportFileFetch(`/api/support/file/${encodeURIComponent(req.params.id)}`, supportFileScope(req));
12645
+ if (!upstream.ok) {
12646
+ res.status(upstream.status).end();
12647
+ return;
12648
+ }
12649
+ res.set("Content-Type", upstream.headers.get("content-type") ?? "application/octet-stream");
12650
+ const disposition = upstream.headers.get("content-disposition");
12651
+ if (disposition) res.set("Content-Disposition", disposition);
12652
+ res.set("X-Content-Type-Options", "nosniff");
12653
+ res.set("Content-Security-Policy", "default-src 'none'; sandbox");
12654
+ res.send(Buffer.from(await upstream.arrayBuffer()));
12655
+ } catch {
12656
+ res.status(502).end();
12657
+ }
12658
+ });
12659
+ app.get("/api/cloud/support/stream", async (req, res) => {
12660
+ const jwt = typeof req.query["token"] === "string" ? req.query["token"] : "";
12661
+ try {
12662
+ await verifyJwt(jwt);
12663
+ } catch {
12664
+ res.status(401).end();
12665
+ return;
12666
+ }
12667
+ if (req.destroyed || res.closed) return;
12668
+ const stop = new AbortController();
12669
+ res.writeHead(200, { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", Connection: "keep-alive", "X-Accel-Buffering": "no" });
12670
+ res.write(": connected\n\n");
12671
+ const signal = () => {
12672
+ if (!res.writableEnded) res.write("data: changed\n\n");
12673
+ };
12674
+ const followAccount = async (accountId) => {
12675
+ while (!stop.signal.aborted) {
12676
+ try {
12677
+ const token = await cloudSessionStore.getToken(accountId);
12678
+ if (!token) return;
12679
+ const base = (await cloudSessionStore.getCloudUrl(accountId) ?? getCloudApiUrl()).replace(/\/+$/, "");
12680
+ const upstream = await fetch(`${base}/api/support/stream`, {
12681
+ headers: { Authorization: `Bearer ${token}`, [APP_VERSION_HEADER]: appVersion, Accept: "text/event-stream" },
12682
+ signal: stop.signal
12683
+ });
12684
+ if (upstream.status === 404) return;
12685
+ if (!upstream.ok || !upstream.body) throw new Error(`support stream: HTTP ${upstream.status}`);
12686
+ const reader = upstream.body.getReader();
12687
+ const decoder = new TextDecoder();
12688
+ for (; ; ) {
12689
+ const { done, value } = await reader.read();
12690
+ if (done) break;
12691
+ if (decoder.decode(value, { stream: true }).includes("data:")) signal();
12692
+ }
12693
+ } catch (err) {
12694
+ if (!stop.signal.aborted) console.warn("[support] stream: upstream failed, retrying in 5 s:", err instanceof Error ? err.message : err);
12695
+ }
12696
+ if (!stop.signal.aborted) await new Promise((r) => setTimeout(r, 5e3));
12697
+ }
12698
+ };
12699
+ for (const account of await cloudSessionStore.list()) void followAccount(account.id);
12700
+ let lastStamp = null;
12701
+ const pollAnonymous = async () => {
12702
+ try {
12703
+ const stamp = await anonymousTicketsStamp();
12704
+ if (lastStamp !== null && stamp !== lastStamp) signal();
12705
+ lastStamp = stamp;
12706
+ } catch {
12707
+ }
12708
+ };
12709
+ void pollAnonymous();
12710
+ const anonymousTimer = setInterval(() => void pollAnonymous(), 2e4);
12711
+ const ping = setInterval(() => {
12712
+ if (!res.writableEnded) res.write(": ping\n\n");
12713
+ }, 25e3);
12714
+ req.on("close", () => {
12715
+ stop.abort();
12716
+ clearInterval(anonymousTimer);
12717
+ clearInterval(ping);
12718
+ });
12719
+ });
12449
12720
  app.get("/api/cloud/knowledge/page/:pageId/stream", async (req, res) => {
12450
12721
  if (!KnowledgeIdSchema.safeParse(req.params.pageId).success) {
12451
12722
  res.status(400).end();
@@ -12899,7 +13170,7 @@ async function createLocalServer() {
12899
13170
  ]);
12900
13171
  console.log("[server] Shutdown complete");
12901
13172
  };
12902
- const { initCompanion } = await import("./companion-KVAOV52T.js");
13173
+ const { initCompanion } = await import("./companion-UNWSLQCL.js");
12903
13174
  initCompanion();
12904
13175
  return { app, server, wss, shutdown };
12905
13176
  }
@@ -13030,7 +13301,7 @@ function onTrayServicesChanged(listener) {
13030
13301
 
13031
13302
  // ../server/src/services/tray-icon.ts
13032
13303
  import { mkdir as mkdir13, writeFile as writeFile10, rename as rename6 } from "fs/promises";
13033
- import { join as join19 } from "path";
13304
+ import { join as join20 } from "path";
13034
13305
 
13035
13306
  // ../server/src/services/png-to-ico.ts
13036
13307
  function isPng(bytes) {
@@ -13190,7 +13461,7 @@ var FETCH_TIMEOUT_MS = 3e3;
13190
13461
  var CACHE_TTL_MS = 10 * 6e4;
13191
13462
  var cache2 = /* @__PURE__ */ new Map();
13192
13463
  function trayIconDir() {
13193
- return join19(machineRoot(), "tray-icons");
13464
+ return join20(machineRoot(), "tray-icons");
13194
13465
  }
13195
13466
  async function resolveTrayIcon(platform = process.platform) {
13196
13467
  const orgId = getCurrentProject()?.orgId;
@@ -13219,7 +13490,7 @@ async function renderThemedIcon(platform) {
13219
13490
  async function writeTrayIcon(stem, png, platform) {
13220
13491
  const dir = trayIconDir();
13221
13492
  await mkdir13(dir, { recursive: true });
13222
- const path = join19(dir, stem);
13493
+ const path = join20(dir, stem);
13223
13494
  if (platform === "win32") {
13224
13495
  const ico = pngToIco(png);
13225
13496
  return ico ? writeAtomic(`${path}.ico`, ico) : null;
@@ -13354,4 +13625,4 @@ export {
13354
13625
  stopProcess,
13355
13626
  userPrefix
13356
13627
  };
13357
- //# sourceMappingURL=src-F5SK2AL3.js.map
13628
+ //# sourceMappingURL=src-4XOEKUXK.js.map