jishushell 0.6.5 → 0.7.3

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 (1207) hide show
  1. package/apps/anythingllm-container.yaml +16 -170
  2. package/apps/browserless-chromium-container.yaml +16 -10
  3. package/apps/filebrowser-container.yaml +15 -9
  4. package/apps/hermes-container.yaml +20 -5
  5. package/apps/immich-container-lite.yaml +337 -0
  6. package/apps/immich-container.yaml +371 -0
  7. package/apps/jishu-kb-container.yaml +50 -177
  8. package/apps/ollama-binary.yaml +33 -28
  9. package/apps/ollama-cpu-container.yaml +6 -0
  10. package/apps/ollama-with-hollama-binary.yaml +35 -28
  11. package/apps/openclaw-binary.yaml +35 -15
  12. package/apps/openclaw-container.yaml +29 -11
  13. package/apps/openclaw-with-ollama-container.yaml +9 -2
  14. package/apps/openclaw-with-searxng-container.yaml +38 -6
  15. package/apps/searxng-container.yaml +31 -6
  16. package/apps/weknora-container.yaml +26 -21
  17. package/dependencies/jishushell-panel-0.7.3.tgz +0 -0
  18. package/dist/cli/app.js +244 -213
  19. package/dist/cli/app.js.map +1 -1
  20. package/dist/cli/backup.js +15 -12
  21. package/dist/cli/backup.js.map +1 -1
  22. package/dist/cli/core.d.ts +4 -3
  23. package/dist/cli/core.js +392 -227
  24. package/dist/cli/core.js.map +1 -1
  25. package/dist/cli/doctor.d.ts +1 -1
  26. package/dist/cli/doctor.js +113 -10
  27. package/dist/cli/doctor.js.map +1 -1
  28. package/dist/cli/job.js +62 -14
  29. package/dist/cli/job.js.map +1 -1
  30. package/dist/cli/llm.js +80 -11
  31. package/dist/cli/llm.js.map +1 -1
  32. package/dist/cli/managed-list.d.ts +1 -3
  33. package/dist/cli/managed-list.js +18 -16
  34. package/dist/cli/managed-list.js.map +1 -1
  35. package/dist/cli/migrate.d.ts +2 -0
  36. package/dist/cli/migrate.js +160 -0
  37. package/dist/cli/migrate.js.map +1 -0
  38. package/dist/cli.js +1 -0
  39. package/dist/cli.js.map +1 -1
  40. package/dist/config.d.ts +32 -20
  41. package/dist/config.js +132 -51
  42. package/dist/config.js.map +1 -1
  43. package/dist/control.d.ts +6 -6
  44. package/dist/control.js +31 -23
  45. package/dist/control.js.map +1 -1
  46. package/dist/core.d.ts +5 -5
  47. package/dist/core.js +5 -5
  48. package/dist/core.js.map +1 -1
  49. package/dist/install.d.ts +2 -2
  50. package/dist/install.js +78 -37
  51. package/dist/install.js.map +1 -1
  52. package/dist/routes/admin.d.ts +2 -0
  53. package/dist/routes/admin.js +72 -0
  54. package/dist/routes/admin.js.map +1 -0
  55. package/dist/routes/apps.d.ts +1 -1
  56. package/dist/routes/apps.js +101 -193
  57. package/dist/routes/apps.js.map +1 -1
  58. package/dist/routes/auth.js +1 -1
  59. package/dist/routes/auth.js.map +1 -1
  60. package/dist/routes/backup.js +1 -1
  61. package/dist/routes/backup.js.map +1 -1
  62. package/dist/routes/docker.d.ts +2 -0
  63. package/dist/routes/docker.js +58 -0
  64. package/dist/routes/docker.js.map +1 -0
  65. package/dist/routes/external-mounts.d.ts +1 -1
  66. package/dist/routes/external-mounts.js +1 -1
  67. package/dist/routes/external-mounts.js.map +1 -1
  68. package/dist/routes/file-mounts.d.ts +4 -3
  69. package/dist/routes/file-mounts.js +49 -31
  70. package/dist/routes/file-mounts.js.map +1 -1
  71. package/dist/routes/files-organize.d.ts +2 -2
  72. package/dist/routes/files-organize.js +5 -5
  73. package/dist/routes/files-organize.js.map +1 -1
  74. package/dist/routes/files.d.ts +1 -1
  75. package/dist/routes/files.js +1 -1
  76. package/dist/routes/files.js.map +1 -1
  77. package/dist/routes/instances.d.ts +0 -8
  78. package/dist/routes/instances.js +202 -1560
  79. package/dist/routes/instances.js.map +1 -1
  80. package/dist/routes/integration-apps.d.ts +14 -0
  81. package/dist/routes/integration-apps.js +81 -0
  82. package/dist/routes/integration-apps.js.map +1 -0
  83. package/dist/routes/integrations.d.ts +9 -0
  84. package/dist/routes/integrations.js +12 -0
  85. package/dist/routes/integrations.js.map +1 -0
  86. package/dist/routes/llm-proxy.js +26 -3
  87. package/dist/routes/llm-proxy.js.map +1 -1
  88. package/dist/routes/setup.js +53 -38
  89. package/dist/routes/setup.js.map +1 -1
  90. package/dist/routes/system.js +108 -68
  91. package/dist/routes/system.js.map +1 -1
  92. package/dist/routes/webdav.d.ts +1 -1
  93. package/dist/routes/webdav.js +2 -2
  94. package/dist/routes/webdav.js.map +1 -1
  95. package/dist/server.d.ts +6 -0
  96. package/dist/server.js +368 -233
  97. package/dist/server.js.map +1 -1
  98. package/dist/services/app-common/app-compiler.js +186 -0
  99. package/dist/services/app-common/app-compiler.js.map +1 -0
  100. package/dist/services/app-common/app-shared.d.ts +15 -0
  101. package/dist/services/app-common/app-shared.js +64 -0
  102. package/dist/services/app-common/app-shared.js.map +1 -0
  103. package/dist/services/app-common/capability-service.d.ts +45 -0
  104. package/dist/services/app-common/capability-service.js +331 -0
  105. package/dist/services/app-common/capability-service.js.map +1 -0
  106. package/dist/services/app-common/catalog-service.d.ts +59 -0
  107. package/dist/services/app-common/catalog-service.js +318 -0
  108. package/dist/services/app-common/catalog-service.js.map +1 -0
  109. package/dist/services/app-common/create-pipeline.d.ts +26 -0
  110. package/dist/services/app-common/create-pipeline.js +298 -0
  111. package/dist/services/app-common/create-pipeline.js.map +1 -0
  112. package/dist/services/app-common/delete-service.d.ts +5 -0
  113. package/dist/services/app-common/delete-service.js +109 -0
  114. package/dist/services/app-common/delete-service.js.map +1 -0
  115. package/dist/services/app-common/execution-owner.d.ts +23 -0
  116. package/dist/services/app-common/execution-owner.js +124 -0
  117. package/dist/services/app-common/execution-owner.js.map +1 -0
  118. package/dist/services/app-common/execution-service.d.ts +23 -0
  119. package/dist/services/app-common/execution-service.js +105 -0
  120. package/dist/services/app-common/execution-service.js.map +1 -0
  121. package/dist/services/app-common/id-normalizer.d.ts +31 -0
  122. package/dist/services/app-common/id-normalizer.js +83 -0
  123. package/dist/services/app-common/id-normalizer.js.map +1 -0
  124. package/dist/services/app-common/install-store.d.ts +34 -0
  125. package/dist/services/app-common/install-store.js +261 -0
  126. package/dist/services/app-common/install-store.js.map +1 -0
  127. package/dist/services/app-common/instance-store.d.ts +78 -0
  128. package/dist/services/app-common/instance-store.js +498 -0
  129. package/dist/services/app-common/instance-store.js.map +1 -0
  130. package/dist/services/app-common/integration-refs.d.ts +17 -0
  131. package/dist/services/app-common/integration-refs.js +47 -0
  132. package/dist/services/app-common/integration-refs.js.map +1 -0
  133. package/dist/services/app-common/lifecycle-pipeline.d.ts +62 -0
  134. package/dist/services/app-common/lifecycle-pipeline.js +317 -0
  135. package/dist/services/app-common/lifecycle-pipeline.js.map +1 -0
  136. package/dist/services/app-common/lifecycle-scripts.d.ts +38 -0
  137. package/dist/services/app-common/lifecycle-scripts.js +935 -0
  138. package/dist/services/app-common/lifecycle-scripts.js.map +1 -0
  139. package/dist/services/app-common/lifecycle-service.d.ts +68 -0
  140. package/dist/services/app-common/lifecycle-service.js +475 -0
  141. package/dist/services/app-common/lifecycle-service.js.map +1 -0
  142. package/dist/services/app-common/ownership.d.ts +3 -0
  143. package/dist/services/app-common/ownership.js +11 -0
  144. package/dist/services/app-common/ownership.js.map +1 -0
  145. package/dist/services/app-common/paths.d.ts +29 -0
  146. package/dist/services/app-common/paths.js +34 -0
  147. package/dist/services/app-common/paths.js.map +1 -0
  148. package/dist/services/app-common/platform-transform.d.ts +32 -0
  149. package/dist/services/app-common/platform-transform.js +65 -0
  150. package/dist/services/app-common/platform-transform.js.map +1 -0
  151. package/dist/services/app-common/provide-resolver.d.ts +29 -0
  152. package/dist/services/app-common/provide-resolver.js +129 -0
  153. package/dist/services/app-common/provide-resolver.js.map +1 -0
  154. package/dist/services/app-common/remote-spec.d.ts +14 -0
  155. package/dist/services/app-common/remote-spec.js +58 -0
  156. package/dist/services/app-common/remote-spec.js.map +1 -0
  157. package/dist/services/app-common/runtime-builder.d.ts +1 -0
  158. package/dist/services/app-common/runtime-builder.js +2 -0
  159. package/dist/services/app-common/runtime-builder.js.map +1 -0
  160. package/dist/services/app-common/runtime-facts.d.ts +19 -0
  161. package/dist/services/app-common/runtime-facts.js +128 -0
  162. package/dist/services/app-common/runtime-facts.js.map +1 -0
  163. package/dist/services/app-common/service.d.ts +9 -0
  164. package/dist/services/app-common/service.js +10 -0
  165. package/dist/services/app-common/service.js.map +1 -0
  166. package/dist/services/app-common/spec-materializer.d.ts +8 -0
  167. package/dist/services/app-common/spec-materializer.js +295 -0
  168. package/dist/services/app-common/spec-materializer.js.map +1 -0
  169. package/dist/services/app-common/status-refresh.d.ts +33 -0
  170. package/dist/services/app-common/status-refresh.js +771 -0
  171. package/dist/services/app-common/status-refresh.js.map +1 -0
  172. package/dist/services/app-common/task-service.d.ts +29 -0
  173. package/dist/services/app-common/task-service.js +93 -0
  174. package/dist/services/app-common/task-service.js.map +1 -0
  175. package/dist/services/app-common/terminal-session-manager.js +157 -0
  176. package/dist/services/app-common/terminal-session-manager.js.map +1 -0
  177. package/dist/services/app-modules/browserless/routes.d.ts +9 -0
  178. package/dist/services/app-modules/browserless/routes.js +519 -0
  179. package/dist/services/app-modules/browserless/routes.js.map +1 -0
  180. package/dist/services/app-modules/routes.d.ts +2 -0
  181. package/dist/services/app-modules/routes.js +5 -0
  182. package/dist/services/app-modules/routes.js.map +1 -0
  183. package/dist/services/backup/backup-admin.d.ts +95 -0
  184. package/dist/services/backup/backup-admin.js +246 -0
  185. package/dist/services/backup/backup-admin.js.map +1 -0
  186. package/dist/services/backup/backup-manager.d.ts +264 -0
  187. package/dist/services/backup/backup-manager.js +2318 -0
  188. package/dist/services/backup/backup-manager.js.map +1 -0
  189. package/dist/services/backup/backup-verify.js +240 -0
  190. package/dist/services/backup/backup-verify.js.map +1 -0
  191. package/dist/services/capabilities/browser-policy.d.ts +14 -0
  192. package/dist/services/capabilities/browser-policy.js +141 -0
  193. package/dist/services/capabilities/browser-policy.js.map +1 -0
  194. package/dist/services/capabilities/contract.d.ts +49 -0
  195. package/dist/services/capabilities/contract.js +119 -0
  196. package/dist/services/capabilities/contract.js.map +1 -0
  197. package/dist/services/capabilities/endpoint-validator.d.ts +42 -0
  198. package/dist/services/capabilities/endpoint-validator.js +113 -0
  199. package/dist/services/capabilities/endpoint-validator.js.map +1 -0
  200. package/dist/services/capabilities/health.d.ts +16 -0
  201. package/dist/services/capabilities/health.js +121 -0
  202. package/dist/services/capabilities/health.js.map +1 -0
  203. package/dist/services/capabilities/registry.d.ts +56 -0
  204. package/dist/services/capabilities/registry.js +222 -0
  205. package/dist/services/capabilities/registry.js.map +1 -0
  206. package/dist/services/capabilities/sync.d.ts +7 -0
  207. package/dist/services/capabilities/sync.js +223 -0
  208. package/dist/services/capabilities/sync.js.map +1 -0
  209. package/dist/services/capability-proxy/html-rewriters/browserless.d.ts +1 -0
  210. package/dist/services/capability-proxy/html-rewriters/browserless.js +83 -0
  211. package/dist/services/capability-proxy/html-rewriters/browserless.js.map +1 -0
  212. package/dist/services/capability-proxy/html-rewriters/index.d.ts +12 -0
  213. package/dist/services/capability-proxy/html-rewriters/index.js +25 -0
  214. package/dist/services/capability-proxy/html-rewriters/index.js.map +1 -0
  215. package/dist/services/capability-proxy/html-rewriters/jishukb.d.ts +1 -0
  216. package/dist/services/capability-proxy/html-rewriters/jishukb.js +161 -0
  217. package/dist/services/capability-proxy/html-rewriters/jishukb.js.map +1 -0
  218. package/dist/services/capability-proxy/http.d.ts +7 -0
  219. package/dist/services/capability-proxy/http.js +555 -0
  220. package/dist/services/capability-proxy/http.js.map +1 -0
  221. package/dist/services/capability-proxy/terminal.d.ts +4 -0
  222. package/dist/services/capability-proxy/terminal.js +179 -0
  223. package/dist/services/capability-proxy/terminal.js.map +1 -0
  224. package/dist/services/connections/admin.d.ts +80 -0
  225. package/dist/services/connections/admin.js +337 -0
  226. package/dist/services/connections/admin.js.map +1 -0
  227. package/dist/services/connections/apply.d.ts +104 -0
  228. package/dist/services/connections/apply.js +415 -0
  229. package/dist/services/connections/apply.js.map +1 -0
  230. package/dist/services/connections/resolver.d.ts +82 -0
  231. package/dist/services/connections/resolver.js +289 -0
  232. package/dist/services/connections/resolver.js.map +1 -0
  233. package/dist/services/connections/transactor.d.ts +39 -0
  234. package/dist/services/connections/transactor.js +307 -0
  235. package/dist/services/connections/transactor.js.map +1 -0
  236. package/dist/services/files/bootstrap.d.ts +7 -0
  237. package/dist/services/files/bootstrap.js +16 -0
  238. package/dist/services/files/bootstrap.js.map +1 -0
  239. package/dist/services/files/external-mounts.js +187 -0
  240. package/dist/services/files/external-mounts.js.map +1 -0
  241. package/dist/services/files/files-manager.d.ts +265 -0
  242. package/dist/services/files/files-manager.js +1189 -0
  243. package/dist/services/files/files-manager.js.map +1 -0
  244. package/dist/services/files/files-mounts.d.ts +42 -0
  245. package/dist/services/files/files-mounts.js +207 -0
  246. package/dist/services/files/files-mounts.js.map +1 -0
  247. package/dist/services/files/organize/applier.js +218 -0
  248. package/dist/services/files/organize/applier.js.map +1 -0
  249. package/dist/services/files/organize/rules.js +286 -0
  250. package/dist/services/files/organize/rules.js.map +1 -0
  251. package/dist/services/files/organize/scanner.js +366 -0
  252. package/dist/services/files/organize/scanner.js.map +1 -0
  253. package/dist/services/files/organize/store.js +82 -0
  254. package/dist/services/files/organize/store.js.map +1 -0
  255. package/dist/services/files/photos/upload-page.d.ts +2 -0
  256. package/dist/services/files/photos/upload-page.js +248 -0
  257. package/dist/services/files/photos/upload-page.js.map +1 -0
  258. package/dist/services/files/photos/upload-store.d.ts +74 -0
  259. package/dist/services/files/photos/upload-store.js +432 -0
  260. package/dist/services/files/photos/upload-store.js.map +1 -0
  261. package/dist/services/files/webdav/server.d.ts +47 -0
  262. package/dist/services/files/webdav/server.js +329 -0
  263. package/dist/services/files/webdav/server.js.map +1 -0
  264. package/dist/services/files/webdav/xml-builder.js.map +1 -0
  265. package/dist/services/http/proxy-utils.d.ts +7 -0
  266. package/dist/services/http/proxy-utils.js +29 -0
  267. package/dist/services/http/proxy-utils.js.map +1 -0
  268. package/dist/services/http/request-utils.d.ts +3 -0
  269. package/dist/services/http/request-utils.js +23 -0
  270. package/dist/services/http/request-utils.js.map +1 -0
  271. package/dist/services/instances/admin.d.ts +23 -0
  272. package/dist/services/instances/admin.js +218 -0
  273. package/dist/services/instances/admin.js.map +1 -0
  274. package/dist/services/instances/clone.d.ts +26 -0
  275. package/dist/services/instances/clone.js +78 -0
  276. package/dist/services/instances/clone.js.map +1 -0
  277. package/dist/services/instances/config-admin.d.ts +17 -0
  278. package/dist/services/instances/config-admin.js +181 -0
  279. package/dist/services/instances/config-admin.js.map +1 -0
  280. package/dist/services/instances/manager.d.ts +232 -0
  281. package/dist/services/instances/manager.js +1342 -0
  282. package/dist/services/instances/manager.js.map +1 -0
  283. package/dist/services/instances/pairing.d.ts +17 -0
  284. package/dist/services/instances/pairing.js +53 -0
  285. package/dist/services/instances/pairing.js.map +1 -0
  286. package/dist/services/instances/passwords.js +173 -0
  287. package/dist/services/instances/passwords.js.map +1 -0
  288. package/dist/services/instances/status.d.ts +2 -0
  289. package/dist/services/instances/status.js +11 -0
  290. package/dist/services/instances/status.js.map +1 -0
  291. package/dist/services/instances/types.d.ts +21 -0
  292. package/dist/services/instances/types.js +2 -0
  293. package/dist/services/instances/types.js.map +1 -0
  294. package/dist/services/integrations/anythingllm/integration.d.ts +25 -0
  295. package/dist/services/integrations/anythingllm/integration.js +251 -0
  296. package/dist/services/integrations/anythingllm/integration.js.map +1 -0
  297. package/dist/services/integrations/catalog.d.ts +3 -0
  298. package/dist/services/integrations/catalog.js +73 -0
  299. package/dist/services/integrations/catalog.js.map +1 -0
  300. package/dist/services/integrations/custom/integration.d.ts +28 -0
  301. package/dist/services/integrations/custom/integration.js +179 -0
  302. package/dist/services/integrations/custom/integration.js.map +1 -0
  303. package/dist/services/integrations/hermes/integration.d.ts +194 -0
  304. package/dist/services/integrations/hermes/integration.js +1668 -0
  305. package/dist/services/integrations/hermes/integration.js.map +1 -0
  306. package/dist/services/integrations/immich/client.d.ts +93 -0
  307. package/dist/services/integrations/immich/client.js +458 -0
  308. package/dist/services/integrations/immich/client.js.map +1 -0
  309. package/dist/services/integrations/immich/config.d.ts +15 -0
  310. package/dist/services/integrations/immich/config.js +178 -0
  311. package/dist/services/integrations/immich/config.js.map +1 -0
  312. package/dist/services/integrations/immich/discovery.d.ts +9 -0
  313. package/dist/services/integrations/immich/discovery.js +101 -0
  314. package/dist/services/integrations/immich/discovery.js.map +1 -0
  315. package/dist/services/integrations/immich/gallery-renderer.d.ts +5 -0
  316. package/dist/services/integrations/immich/gallery-renderer.js +150 -0
  317. package/dist/services/integrations/immich/gallery-renderer.js.map +1 -0
  318. package/dist/services/integrations/immich/immich-shim.d.ts +11 -0
  319. package/dist/services/integrations/immich/immich-shim.js +439 -0
  320. package/dist/services/integrations/immich/immich-shim.js.map +1 -0
  321. package/dist/services/integrations/immich/integration.d.ts +18 -0
  322. package/dist/services/integrations/immich/integration.js +64 -0
  323. package/dist/services/integrations/immich/integration.js.map +1 -0
  324. package/dist/services/integrations/immich/photo-library.d.ts +4 -0
  325. package/dist/services/integrations/immich/photo-library.js +63 -0
  326. package/dist/services/integrations/immich/photo-library.js.map +1 -0
  327. package/dist/services/integrations/immich/review-executor.d.ts +3 -0
  328. package/dist/services/integrations/immich/review-executor.js +41 -0
  329. package/dist/services/integrations/immich/review-executor.js.map +1 -0
  330. package/dist/services/integrations/immich/review-session-service.d.ts +27 -0
  331. package/dist/services/integrations/immich/review-session-service.js +206 -0
  332. package/dist/services/integrations/immich/review-session-service.js.map +1 -0
  333. package/dist/services/integrations/immich/review-store.d.ts +47 -0
  334. package/dist/services/integrations/immich/review-store.js +347 -0
  335. package/dist/services/integrations/immich/review-store.js.map +1 -0
  336. package/dist/services/integrations/immich/routes.d.ts +7 -0
  337. package/dist/services/integrations/immich/routes.js +363 -0
  338. package/dist/services/integrations/immich/routes.js.map +1 -0
  339. package/dist/services/integrations/immich/types.d.ts +186 -0
  340. package/dist/services/integrations/immich/types.js +2 -0
  341. package/dist/services/integrations/immich/types.js.map +1 -0
  342. package/dist/services/integrations/index.d.ts +41 -0
  343. package/dist/services/integrations/index.js +60 -0
  344. package/dist/services/integrations/index.js.map +1 -0
  345. package/dist/services/integrations/installable/catalog.d.ts +33 -0
  346. package/dist/services/integrations/installable/catalog.js +88 -0
  347. package/dist/services/integrations/installable/catalog.js.map +1 -0
  348. package/dist/services/integrations/installable/index.d.ts +35 -0
  349. package/dist/services/integrations/installable/index.js +170 -0
  350. package/dist/services/integrations/installable/index.js.map +1 -0
  351. package/dist/services/integrations/installable/installers/integration-probes.d.ts +50 -0
  352. package/dist/services/integrations/installable/installers/integration-probes.js +231 -0
  353. package/dist/services/integrations/installable/installers/integration-probes.js.map +1 -0
  354. package/dist/services/integrations/installable/installers/integration.d.ts +30 -0
  355. package/dist/services/integrations/installable/installers/integration.js +283 -0
  356. package/dist/services/integrations/installable/installers/integration.js.map +1 -0
  357. package/dist/services/integrations/installable/installers/registry-probe.js.map +1 -0
  358. package/dist/services/integrations/installable/installers/shell-script.d.ts +46 -0
  359. package/dist/services/integrations/installable/installers/shell-script.js +487 -0
  360. package/dist/services/integrations/installable/installers/shell-script.js.map +1 -0
  361. package/dist/services/integrations/installable/types.d.ts +130 -0
  362. package/dist/services/integrations/installable/types.js +19 -0
  363. package/dist/services/integrations/installable/types.js.map +1 -0
  364. package/dist/services/integrations/jishukb/integration.d.ts +24 -0
  365. package/dist/services/integrations/jishukb/integration.js +300 -0
  366. package/dist/services/integrations/jishukb/integration.js.map +1 -0
  367. package/dist/services/integrations/openclaw/anythingllm-shim.d.ts +46 -0
  368. package/dist/services/integrations/openclaw/anythingllm-shim.js +281 -0
  369. package/dist/services/integrations/openclaw/anythingllm-shim.js.map +1 -0
  370. package/dist/services/integrations/openclaw/drive-shim.js +490 -0
  371. package/dist/services/integrations/openclaw/drive-shim.js.map +1 -0
  372. package/dist/services/integrations/openclaw/integration.d.ts +438 -0
  373. package/dist/services/integrations/openclaw/integration.js +4629 -0
  374. package/dist/services/integrations/openclaw/integration.js.map +1 -0
  375. package/dist/services/integrations/openclaw/jishukb-native-mcp.d.ts +58 -0
  376. package/dist/services/integrations/openclaw/jishukb-native-mcp.js +373 -0
  377. package/dist/services/integrations/openclaw/jishukb-native-mcp.js.map +1 -0
  378. package/dist/services/integrations/openclaw/jishukb-shim.d.ts +52 -0
  379. package/dist/services/integrations/openclaw/jishukb-shim.js +1357 -0
  380. package/dist/services/integrations/openclaw/jishukb-shim.js.map +1 -0
  381. package/dist/services/integrations/openclaw/mcporter-lite.js +276 -0
  382. package/dist/services/integrations/openclaw/mcporter-lite.js.map +1 -0
  383. package/dist/services/integrations/openclaw/mcporter.d.ts +59 -0
  384. package/dist/services/integrations/openclaw/mcporter.js +143 -0
  385. package/dist/services/integrations/openclaw/mcporter.js.map +1 -0
  386. package/dist/services/integrations/openclaw/native-mcp.d.ts +48 -0
  387. package/dist/services/integrations/openclaw/native-mcp.js +125 -0
  388. package/dist/services/integrations/openclaw/native-mcp.js.map +1 -0
  389. package/dist/services/integrations/openclaw/routes.d.ts +21 -0
  390. package/dist/services/integrations/openclaw/routes.js +1194 -0
  391. package/dist/services/integrations/openclaw/routes.js.map +1 -0
  392. package/dist/services/integrations/registry.d.ts +17 -0
  393. package/dist/services/integrations/registry.js +36 -0
  394. package/dist/services/integrations/registry.js.map +1 -0
  395. package/dist/services/integrations/routes.d.ts +2 -0
  396. package/dist/services/integrations/routes.js +9 -0
  397. package/dist/services/integrations/routes.js.map +1 -0
  398. package/dist/services/integrations/types.d.ts +457 -0
  399. package/dist/services/integrations/types.js +2 -0
  400. package/dist/services/integrations/types.js.map +1 -0
  401. package/dist/services/legacy-migrator/classifier.d.ts +44 -0
  402. package/dist/services/legacy-migrator/classifier.js +309 -0
  403. package/dist/services/legacy-migrator/classifier.js.map +1 -0
  404. package/dist/services/legacy-migrator/executor.d.ts +42 -0
  405. package/dist/services/legacy-migrator/executor.js +637 -0
  406. package/dist/services/legacy-migrator/executor.js.map +1 -0
  407. package/dist/services/legacy-migrator/index.d.ts +31 -0
  408. package/dist/services/legacy-migrator/index.js +34 -0
  409. package/dist/services/legacy-migrator/index.js.map +1 -0
  410. package/dist/services/legacy-migrator/planner.d.ts +8 -0
  411. package/dist/services/legacy-migrator/planner.js +154 -0
  412. package/dist/services/legacy-migrator/planner.js.map +1 -0
  413. package/dist/services/legacy-migrator/provider-settings.d.ts +6 -0
  414. package/dist/services/legacy-migrator/provider-settings.js +72 -0
  415. package/dist/services/legacy-migrator/provider-settings.js.map +1 -0
  416. package/dist/services/legacy-migrator/report.d.ts +9 -0
  417. package/dist/services/legacy-migrator/report.js +99 -0
  418. package/dist/services/legacy-migrator/report.js.map +1 -0
  419. package/dist/services/legacy-migrator/scanner.d.ts +13 -0
  420. package/dist/services/legacy-migrator/scanner.js +157 -0
  421. package/dist/services/legacy-migrator/scanner.js.map +1 -0
  422. package/dist/services/legacy-migrator/types.d.ts +97 -0
  423. package/dist/services/legacy-migrator/types.js +23 -0
  424. package/dist/services/legacy-migrator/types.js.map +1 -0
  425. package/dist/services/llm-proxy/instance-proxy.d.ts +17 -1
  426. package/dist/services/llm-proxy/instance-proxy.js +171 -44
  427. package/dist/services/llm-proxy/instance-proxy.js.map +1 -1
  428. package/dist/services/llm-proxy/probe.js +5 -14
  429. package/dist/services/llm-proxy/probe.js.map +1 -1
  430. package/dist/services/llm-proxy/providers.js +23 -31
  431. package/dist/services/llm-proxy/providers.js.map +1 -1
  432. package/dist/services/llm-proxy/ssrf.d.ts +11 -4
  433. package/dist/services/llm-proxy/ssrf.js +45 -7
  434. package/dist/services/llm-proxy/ssrf.js.map +1 -1
  435. package/dist/services/llm-proxy/validate-key.js +16 -37
  436. package/dist/services/llm-proxy/validate-key.js.map +1 -1
  437. package/dist/services/repair/runtime-repair.d.ts +22 -0
  438. package/dist/services/repair/runtime-repair.js +374 -0
  439. package/dist/services/repair/runtime-repair.js.map +1 -0
  440. package/dist/services/runtime/docker-network.d.ts +8 -0
  441. package/dist/services/runtime/docker-network.js +123 -0
  442. package/dist/services/runtime/docker-network.js.map +1 -0
  443. package/dist/services/runtime/driver-registry.d.ts +25 -0
  444. package/dist/services/runtime/driver-registry.js +22 -0
  445. package/dist/services/runtime/driver-registry.js.map +1 -0
  446. package/dist/services/runtime/drivers/nomad.d.ts +261 -0
  447. package/dist/services/runtime/drivers/nomad.js +3122 -0
  448. package/dist/services/runtime/drivers/nomad.js.map +1 -0
  449. package/dist/services/runtime/errors.d.ts +3 -3
  450. package/dist/services/runtime/errors.js +3 -3
  451. package/dist/services/runtime/instance.d.ts +14 -16
  452. package/dist/services/runtime/instance.js +93 -123
  453. package/dist/services/runtime/instance.js.map +1 -1
  454. package/dist/services/runtime/job-id.d.ts +1 -1
  455. package/dist/services/runtime/job-id.js +1 -1
  456. package/dist/services/runtime/mcp-shims/firewall.d.ts +2 -2
  457. package/dist/services/runtime/mcp-shims/firewall.js +2 -2
  458. package/dist/services/runtime/mcp-shims/searxng-shim.d.ts +3 -5
  459. package/dist/services/runtime/mcp-shims/searxng-shim.js +3 -5
  460. package/dist/services/runtime/mcp-shims/searxng-shim.js.map +1 -1
  461. package/dist/services/runtime/mcp-shims/write-mcp-entry.d.ts +20 -20
  462. package/dist/services/runtime/mcp-shims/write-mcp-entry.js +16 -16
  463. package/dist/services/runtime/mcp-shims/write-mcp-entry.js.map +1 -1
  464. package/dist/services/runtime/ownership-marker.d.ts +83 -0
  465. package/dist/services/runtime/ownership-marker.js +109 -0
  466. package/dist/services/runtime/ownership-marker.js.map +1 -0
  467. package/dist/services/runtime/service-manager.d.ts +2 -0
  468. package/dist/services/runtime/service-manager.js +18 -0
  469. package/dist/services/runtime/service-manager.js.map +1 -0
  470. package/dist/services/runtime/types.d.ts +23 -501
  471. package/dist/services/runtime/types.js +0 -12
  472. package/dist/services/runtime/types.js.map +1 -1
  473. package/dist/services/runtime/workload-compiler.d.ts +17 -0
  474. package/dist/services/runtime/workload-compiler.js +550 -0
  475. package/dist/services/runtime/workload-compiler.js.map +1 -0
  476. package/dist/services/runtime/workload-types.d.ts +11 -0
  477. package/dist/services/runtime/workload-types.js +2 -0
  478. package/dist/services/runtime/workload-types.js.map +1 -0
  479. package/dist/services/setup/core-manager.d.ts +50 -0
  480. package/dist/services/setup/core-manager.js +456 -0
  481. package/dist/services/setup/core-manager.js.map +1 -0
  482. package/dist/services/setup/plugin-installer.js +136 -0
  483. package/dist/services/setup/plugin-installer.js.map +1 -0
  484. package/dist/services/setup/setup-manager.d.ts +158 -0
  485. package/dist/services/setup/setup-manager.js +2724 -0
  486. package/dist/services/setup/setup-manager.js.map +1 -0
  487. package/dist/services/system/cli-command.d.ts +5 -0
  488. package/dist/services/system/cli-command.js +18 -0
  489. package/dist/services/system/cli-command.js.map +1 -0
  490. package/dist/services/system/macos-launchd.js +312 -0
  491. package/dist/services/system/macos-launchd.js.map +1 -0
  492. package/dist/services/system/repair-orchestrator.d.ts +71 -0
  493. package/dist/services/system/repair-orchestrator.js +412 -0
  494. package/dist/services/system/repair-orchestrator.js.map +1 -0
  495. package/dist/services/system/runtime-ownership.d.ts +36 -0
  496. package/dist/services/system/runtime-ownership.js +250 -0
  497. package/dist/services/system/runtime-ownership.js.map +1 -0
  498. package/dist/services/system/system-monitor.js +96 -0
  499. package/dist/services/system/system-monitor.js.map +1 -0
  500. package/dist/services/system/system-ollama-provider.d.ts +14 -0
  501. package/dist/services/system/system-ollama-provider.js +129 -0
  502. package/dist/services/system/system-ollama-provider.js.map +1 -0
  503. package/dist/services/system/system-reconciler.d.ts +59 -0
  504. package/dist/services/system/system-reconciler.js +763 -0
  505. package/dist/services/system/system-reconciler.js.map +1 -0
  506. package/dist/services/system/update-manager.d.ts +43 -0
  507. package/dist/services/system/update-manager.js +315 -0
  508. package/dist/services/system/update-manager.js.map +1 -0
  509. package/dist/services/system/upgrade-finalize.d.ts +80 -0
  510. package/dist/services/system/upgrade-finalize.js +507 -0
  511. package/dist/services/system/upgrade-finalize.js.map +1 -0
  512. package/dist/services/tasks/registry.d.ts +44 -0
  513. package/dist/services/tasks/registry.js +90 -0
  514. package/dist/services/tasks/registry.js.map +1 -0
  515. package/dist/services/telemetry/activation.d.ts +6 -2
  516. package/dist/services/telemetry/activation.js +6 -2
  517. package/dist/services/telemetry/activation.js.map +1 -1
  518. package/dist/services/telemetry/heartbeat.d.ts +6 -2
  519. package/dist/services/telemetry/heartbeat.js +6 -2
  520. package/dist/services/telemetry/heartbeat.js.map +1 -1
  521. package/dist/services/workspaces/builder.d.ts +29 -0
  522. package/dist/services/workspaces/builder.js +186 -0
  523. package/dist/services/workspaces/builder.js.map +1 -0
  524. package/dist/types.d.ts +350 -48
  525. package/dist/utils/instance-lock.d.ts +2 -2
  526. package/dist/utils/instance-lock.js +2 -2
  527. package/dist/utils/path-safety.js +1 -1
  528. package/dist/utils/service-user.d.ts +13 -0
  529. package/dist/utils/service-user.js +129 -0
  530. package/dist/utils/service-user.js.map +1 -0
  531. package/install/jishu-install.sh +107 -27
  532. package/install/jishu-uninstall.sh +8 -0
  533. package/install/post-install.sh +162 -185
  534. package/install/post-uninstall.sh +6 -0
  535. package/node_modules/@fastify/static/.github/workflows/ci.yml +1 -1
  536. package/node_modules/@fastify/static/.github/workflows/lock-threads.yml +19 -0
  537. package/node_modules/@fastify/static/LICENSE +1 -3
  538. package/node_modules/@fastify/static/example/server-benchmark.js +39 -0
  539. package/node_modules/@fastify/static/index.js +169 -23
  540. package/node_modules/@fastify/static/lib/dirList.js +20 -6
  541. package/node_modules/@fastify/static/package.json +10 -8
  542. package/node_modules/@fastify/static/test/dir-list.test.js +82 -0
  543. package/node_modules/@fastify/static/test/static.test.js +326 -4
  544. package/node_modules/@fastify/static/types/index.d.ts +0 -4
  545. package/node_modules/@fastify/static/types/index.test-d.ts +1 -1
  546. package/node_modules/brace-expansion/dist/commonjs/index.js +24 -14
  547. package/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -1
  548. package/node_modules/brace-expansion/dist/esm/index.js +24 -14
  549. package/node_modules/brace-expansion/dist/esm/index.js.map +1 -1
  550. package/node_modules/brace-expansion/package.json +2 -2
  551. package/node_modules/content-disposition/README.md +21 -22
  552. package/node_modules/content-disposition/index.js +122 -44
  553. package/node_modules/content-disposition/package.json +16 -20
  554. package/node_modules/fast-uri/index.js +1 -1
  555. package/node_modules/fast-uri/package.json +1 -1
  556. package/node_modules/fast-uri/test/security.test.js +28 -0
  557. package/node_modules/fastify/SECURITY.md +1 -1
  558. package/node_modules/fastify/SPONSORS.md +6 -4
  559. package/node_modules/fastify/docs/Guides/Database.md +0 -28
  560. package/node_modules/fastify/docs/Guides/Ecosystem.md +13 -2
  561. package/node_modules/fastify/docs/Guides/Serverless.md +2 -2
  562. package/node_modules/fastify/docs/Guides/Write-Plugin.md +1 -1
  563. package/node_modules/fastify/docs/Reference/Encapsulation.md +27 -26
  564. package/node_modules/fastify/docs/Reference/Errors.md +10 -4
  565. package/node_modules/fastify/docs/Reference/HTTP2.md +10 -10
  566. package/node_modules/fastify/docs/Reference/Hooks.md +4 -4
  567. package/node_modules/fastify/docs/Reference/Index.md +14 -16
  568. package/node_modules/fastify/docs/Reference/LTS.md +12 -13
  569. package/node_modules/fastify/docs/Reference/Lifecycle.md +9 -8
  570. package/node_modules/fastify/docs/Reference/Logging.md +44 -39
  571. package/node_modules/fastify/docs/Reference/Middleware.md +21 -25
  572. package/node_modules/fastify/docs/Reference/Principles.md +2 -2
  573. package/node_modules/fastify/docs/Reference/Reply.md +6 -1
  574. package/node_modules/fastify/docs/Reference/Request.md +27 -16
  575. package/node_modules/fastify/docs/Reference/Routes.md +5 -2
  576. package/node_modules/fastify/docs/Reference/Server.md +31 -3
  577. package/node_modules/fastify/docs/Reference/Type-Providers.md +29 -5
  578. package/node_modules/fastify/docs/Reference/Validation-and-Serialization.md +15 -2
  579. package/node_modules/fastify/docs/Reference/Warnings.md +7 -6
  580. package/node_modules/fastify/eslint.config.js +7 -2
  581. package/node_modules/fastify/fastify.d.ts +8 -3
  582. package/node_modules/fastify/fastify.js +43 -14
  583. package/node_modules/fastify/lib/content-type-parser.js +13 -1
  584. package/node_modules/fastify/lib/decorate.js +11 -3
  585. package/node_modules/fastify/lib/error-handler.js +4 -3
  586. package/node_modules/fastify/lib/error-serializer.js +59 -59
  587. package/node_modules/fastify/lib/errors.js +16 -1
  588. package/node_modules/fastify/lib/four-oh-four.js +14 -9
  589. package/node_modules/fastify/lib/handle-request.js +11 -5
  590. package/node_modules/fastify/lib/plugin-override.js +2 -1
  591. package/node_modules/fastify/lib/plugin-utils.js +5 -5
  592. package/node_modules/fastify/lib/reply.js +63 -8
  593. package/node_modules/fastify/lib/request.js +14 -4
  594. package/node_modules/fastify/lib/route.js +20 -6
  595. package/node_modules/fastify/lib/schema-controller.js +1 -1
  596. package/node_modules/fastify/lib/schemas.js +37 -30
  597. package/node_modules/fastify/lib/symbols.js +3 -1
  598. package/node_modules/fastify/lib/validation.js +1 -13
  599. package/node_modules/fastify/lib/warnings.js +3 -3
  600. package/node_modules/fastify/package.json +13 -15
  601. package/node_modules/fastify/scripts/validate-ecosystem-links.js +1 -0
  602. package/node_modules/fastify/test/bundler/esbuild/package.json +1 -1
  603. package/node_modules/fastify/test/close-pipelining.test.js +1 -2
  604. package/node_modules/fastify/test/custom-http-server.test.js +38 -0
  605. package/node_modules/fastify/test/decorator-instance-properties.test.js +63 -0
  606. package/node_modules/fastify/test/diagnostics-channel/async-error-handler.test.js +74 -0
  607. package/node_modules/fastify/test/hooks.test.js +23 -0
  608. package/node_modules/fastify/test/http-methods/get.test.js +1 -1
  609. package/node_modules/fastify/test/http2/plain.test.js +135 -0
  610. package/node_modules/fastify/test/http2/secure-with-fallback.test.js +1 -1
  611. package/node_modules/fastify/test/https/https.test.js +1 -2
  612. package/node_modules/fastify/test/internals/errors.test.js +31 -1
  613. package/node_modules/fastify/test/internals/plugin.test.js +3 -1
  614. package/node_modules/fastify/test/internals/request.test.js +27 -3
  615. package/node_modules/fastify/test/internals/schema-controller-perf.test.js +33 -0
  616. package/node_modules/fastify/test/logger/logging.test.js +18 -1
  617. package/node_modules/fastify/test/logger/options.test.js +38 -1
  618. package/node_modules/fastify/test/reply-error.test.js +1 -1
  619. package/node_modules/fastify/test/reply-trailers.test.js +70 -0
  620. package/node_modules/fastify/test/request-media-type.test.js +105 -0
  621. package/node_modules/fastify/test/route-prefix.test.js +34 -0
  622. package/node_modules/fastify/test/router-options.test.js +222 -11
  623. package/node_modules/fastify/test/schema-serialization.test.js +108 -0
  624. package/node_modules/fastify/test/schema-validation.test.js +24 -0
  625. package/node_modules/fastify/test/scripts/validate-ecosystem-links.test.js +40 -57
  626. package/node_modules/fastify/test/throw.test.js +14 -0
  627. package/node_modules/fastify/test/trust-proxy.test.js +21 -0
  628. package/node_modules/fastify/test/types/content-type-parser.tst.ts +70 -0
  629. package/node_modules/fastify/test/types/decorate-request-reply.tst.ts +18 -0
  630. package/node_modules/fastify/test/types/dummy-plugin.mts +9 -0
  631. package/node_modules/fastify/test/types/errors.tst.ts +91 -0
  632. package/node_modules/fastify/test/types/fastify.tst.ts +351 -0
  633. package/node_modules/fastify/test/types/hooks.tst.ts +578 -0
  634. package/node_modules/fastify/test/types/instance.tst.ts +597 -0
  635. package/node_modules/fastify/test/types/logger.tst.ts +276 -0
  636. package/node_modules/fastify/test/types/plugin.tst.ts +96 -0
  637. package/node_modules/fastify/test/types/register.tst.ts +245 -0
  638. package/node_modules/fastify/test/types/reply.tst.ts +297 -0
  639. package/node_modules/fastify/test/types/request.tst.ts +199 -0
  640. package/node_modules/fastify/test/types/route.tst.ts +576 -0
  641. package/node_modules/fastify/test/types/schema.tst.ts +135 -0
  642. package/node_modules/fastify/test/types/serverFactory.tst.ts +37 -0
  643. package/node_modules/fastify/test/types/tsconfig.json +9 -0
  644. package/node_modules/fastify/test/types/type-provider.tst.ts +1219 -0
  645. package/node_modules/fastify/test/types/using.tst.ts +14 -0
  646. package/node_modules/fastify/types/errors.d.ts +3 -0
  647. package/node_modules/fastify/types/request.d.ts +23 -2
  648. package/node_modules/glob/README.md +39 -130
  649. package/node_modules/glob/dist/commonjs/glob.d.ts +8 -0
  650. package/node_modules/glob/dist/commonjs/glob.d.ts.map +1 -1
  651. package/node_modules/glob/dist/commonjs/glob.js +2 -1
  652. package/node_modules/glob/dist/commonjs/glob.js.map +1 -1
  653. package/node_modules/glob/dist/commonjs/index.min.js +4 -0
  654. package/node_modules/glob/dist/commonjs/index.min.js.map +7 -0
  655. package/node_modules/glob/dist/commonjs/pattern.d.ts +3 -0
  656. package/node_modules/glob/dist/commonjs/pattern.d.ts.map +1 -1
  657. package/node_modules/glob/dist/commonjs/pattern.js +4 -0
  658. package/node_modules/glob/dist/commonjs/pattern.js.map +1 -1
  659. package/node_modules/glob/dist/esm/glob.d.ts +8 -0
  660. package/node_modules/glob/dist/esm/glob.d.ts.map +1 -1
  661. package/node_modules/glob/dist/esm/glob.js +2 -1
  662. package/node_modules/glob/dist/esm/glob.js.map +1 -1
  663. package/node_modules/glob/dist/esm/index.min.js +4 -0
  664. package/node_modules/glob/dist/esm/index.min.js.map +7 -0
  665. package/node_modules/glob/dist/esm/pattern.d.ts +3 -0
  666. package/node_modules/glob/dist/esm/pattern.d.ts.map +1 -1
  667. package/node_modules/glob/dist/esm/pattern.js +4 -0
  668. package/node_modules/glob/dist/esm/pattern.js.map +1 -1
  669. package/node_modules/glob/package.json +38 -37
  670. package/node_modules/jishushell-panel/README.md +4 -4
  671. package/node_modules/jishushell-panel/output/dist/server.js +17 -6
  672. package/node_modules/jishushell-panel/output/dist/server.js.map +1 -1
  673. package/node_modules/jishushell-panel/output/public/assets/ApiKeyField-Ce5d1xna.js +1 -0
  674. package/node_modules/jishushell-panel/output/public/assets/Dashboard-BXame3yg.js +1 -0
  675. package/node_modules/jishushell-panel/output/public/assets/HermesChatPanel-BHZtPCJd.js +1 -0
  676. package/node_modules/jishushell-panel/output/public/assets/HermesConfigForm-CB3GbNX9.js +4 -0
  677. package/node_modules/jishushell-panel/output/public/assets/InitPassword-Boab9F6g.js +1 -0
  678. package/node_modules/jishushell-panel/output/public/assets/InstanceDetail-DrIWCqo-.js +14 -0
  679. package/node_modules/jishushell-panel/output/public/assets/Login-CzpOkNau.js +1 -0
  680. package/node_modules/jishushell-panel/output/public/assets/NewInstance-CANXyCcL.js +1 -0
  681. package/node_modules/jishushell-panel/output/public/assets/ProviderRecommendations-BABo9VOC.js +1 -0
  682. package/node_modules/jishushell-panel/output/public/assets/Settings-CKp5XxFh.js +1 -0
  683. package/node_modules/jishushell-panel/output/public/assets/Setup-C7xVDPow.js +1 -0
  684. package/node_modules/jishushell-panel/output/public/assets/WeixinLoginPanel-B765Xz4C.js +1 -0
  685. package/node_modules/jishushell-panel/output/public/assets/api-C70Gt678.js +4 -0
  686. package/node_modules/jishushell-panel/output/public/assets/index-Bs6DSbiR.js +23 -0
  687. package/node_modules/jishushell-panel/output/public/assets/index-DnnqTf7s.css +1 -0
  688. package/node_modules/jishushell-panel/output/public/assets/registry-sWIZsIEF.js +2 -0
  689. package/node_modules/jishushell-panel/output/public/assets/rolldown-runtime-QTnfLwEv.js +1 -0
  690. package/node_modules/jishushell-panel/output/public/assets/setup-task-q21GnI0E.js +1 -0
  691. package/node_modules/jishushell-panel/output/public/assets/usePolling-D4IDOQd_.js +1 -0
  692. package/node_modules/jishushell-panel/output/public/assets/vendor-i18n-Df8aUdv8.js +1 -0
  693. package/node_modules/jishushell-panel/output/public/assets/vendor-react-0L0rjmYG.js +8 -0
  694. package/node_modules/jishushell-panel/output/public/index.html +6 -4
  695. package/node_modules/jishushell-panel/package.json +2 -2
  696. package/node_modules/semver/classes/range.js +17 -4
  697. package/node_modules/semver/package.json +2 -2
  698. package/package.json +12 -64
  699. package/scripts/check-app-path-boundaries.mjs +121 -0
  700. package/scripts/check-app-spec.mjs +123 -29
  701. package/scripts/check-architecture-boundaries.mjs +178 -0
  702. package/scripts/check-colima-launchd.mjs +10 -8
  703. package/scripts/check-integration-isolation.ts +541 -0
  704. package/scripts/check-new-file-tests.mjs +11 -3
  705. package/scripts/check-open-core-boundaries.mjs +60 -10
  706. package/scripts/check-test-layering.sh +1 -1
  707. package/scripts/fixtures/instances/hermes-sample/instance.json +3 -2
  708. package/scripts/fixtures/instances/legacy-openclaw-sample/instance.json +1 -1
  709. package/scripts/local-web-upgrade-test.README +4 -3
  710. package/scripts/local-web-upgrade-test.example.env +2 -2
  711. package/scripts/local-web-upgrade-test.sh +14 -1
  712. package/scripts/pack-gui-and-send-pi.sh +43 -0
  713. package/scripts/perf/instances.js +1 -1
  714. package/scripts/prune-open-core-dist.mjs +89 -2
  715. package/scripts/smoke/hermes-bootstrap.sh +5 -5
  716. package/templates/hermes-entrypoint.sh +19 -29
  717. package/apps/openwebui-container.yaml +0 -97
  718. package/apps/playwright-container.yaml +0 -126
  719. package/dependencies/jishushell-panel-0.6.5.tgz +0 -0
  720. package/dist/crypto-shim.d.ts +0 -1
  721. package/dist/crypto-shim.js +0 -2
  722. package/dist/crypto-shim.js.map +0 -1
  723. package/dist/routes/agent-apps.d.ts +0 -14
  724. package/dist/routes/agent-apps.js +0 -77
  725. package/dist/routes/agent-apps.js.map +0 -1
  726. package/dist/routes/internal.d.ts +0 -2
  727. package/dist/routes/internal.js +0 -55
  728. package/dist/routes/internal.js.map +0 -1
  729. package/dist/routes/openclaw-routes.d.ts +0 -22
  730. package/dist/routes/openclaw-routes.js +0 -1020
  731. package/dist/routes/openclaw-routes.js.map +0 -1
  732. package/dist/routes/runtime.d.ts +0 -15
  733. package/dist/routes/runtime.js +0 -76
  734. package/dist/routes/runtime.js.map +0 -1
  735. package/dist/services/agent-apps/catalog.d.ts +0 -33
  736. package/dist/services/agent-apps/catalog.js +0 -88
  737. package/dist/services/agent-apps/catalog.js.map +0 -1
  738. package/dist/services/agent-apps/index.d.ts +0 -36
  739. package/dist/services/agent-apps/index.js +0 -171
  740. package/dist/services/agent-apps/index.js.map +0 -1
  741. package/dist/services/agent-apps/installers/adapter-probes.d.ts +0 -49
  742. package/dist/services/agent-apps/installers/adapter-probes.js +0 -230
  743. package/dist/services/agent-apps/installers/adapter-probes.js.map +0 -1
  744. package/dist/services/agent-apps/installers/adapter.d.ts +0 -30
  745. package/dist/services/agent-apps/installers/adapter.js +0 -171
  746. package/dist/services/agent-apps/installers/adapter.js.map +0 -1
  747. package/dist/services/agent-apps/installers/registry-probe.js.map +0 -1
  748. package/dist/services/agent-apps/installers/shell-script.d.ts +0 -47
  749. package/dist/services/agent-apps/installers/shell-script.js +0 -488
  750. package/dist/services/agent-apps/installers/shell-script.js.map +0 -1
  751. package/dist/services/agent-apps/types.d.ts +0 -128
  752. package/dist/services/agent-apps/types.js +0 -17
  753. package/dist/services/agent-apps/types.js.map +0 -1
  754. package/dist/services/app/app-compiler.js +0 -185
  755. package/dist/services/app/app-compiler.js.map +0 -1
  756. package/dist/services/app/app-manager.d.ts +0 -184
  757. package/dist/services/app/app-manager.js +0 -2933
  758. package/dist/services/app/app-manager.js.map +0 -1
  759. package/dist/services/app/custom-manager.d.ts +0 -27
  760. package/dist/services/app/custom-manager.js +0 -382
  761. package/dist/services/app/custom-manager.js.map +0 -1
  762. package/dist/services/app/hermes-agent-manager.d.ts +0 -20
  763. package/dist/services/app/hermes-agent-manager.js +0 -299
  764. package/dist/services/app/hermes-agent-manager.js.map +0 -1
  765. package/dist/services/app/id-normalizer.d.ts +0 -27
  766. package/dist/services/app/id-normalizer.js +0 -77
  767. package/dist/services/app/id-normalizer.js.map +0 -1
  768. package/dist/services/app/ollama-manager.d.ts +0 -18
  769. package/dist/services/app/ollama-manager.js +0 -224
  770. package/dist/services/app/ollama-manager.js.map +0 -1
  771. package/dist/services/app/openclaw-manager.d.ts +0 -63
  772. package/dist/services/app/openclaw-manager.js +0 -1215
  773. package/dist/services/app/openclaw-manager.js.map +0 -1
  774. package/dist/services/app/paths.d.ts +0 -27
  775. package/dist/services/app/paths.js +0 -40
  776. package/dist/services/app/paths.js.map +0 -1
  777. package/dist/services/app/platform-transform.d.ts +0 -32
  778. package/dist/services/app/platform-transform.js +0 -65
  779. package/dist/services/app/platform-transform.js.map +0 -1
  780. package/dist/services/app/provide-resolver.d.ts +0 -29
  781. package/dist/services/app/provide-resolver.js +0 -135
  782. package/dist/services/app/provide-resolver.js.map +0 -1
  783. package/dist/services/app/registry.d.ts +0 -17
  784. package/dist/services/app/registry.js +0 -31
  785. package/dist/services/app/registry.js.map +0 -1
  786. package/dist/services/app/remote-spec.d.ts +0 -14
  787. package/dist/services/app/remote-spec.js +0 -58
  788. package/dist/services/app/remote-spec.js.map +0 -1
  789. package/dist/services/app/terminal-session-manager.js +0 -157
  790. package/dist/services/app/terminal-session-manager.js.map +0 -1
  791. package/dist/services/app/types.d.ts +0 -74
  792. package/dist/services/app/types.js +0 -16
  793. package/dist/services/app/types.js.map +0 -1
  794. package/dist/services/app-config-admin.d.ts +0 -17
  795. package/dist/services/app-config-admin.js +0 -177
  796. package/dist/services/app-config-admin.js.map +0 -1
  797. package/dist/services/app-create-from-installed.d.ts +0 -23
  798. package/dist/services/app-create-from-installed.js +0 -75
  799. package/dist/services/app-create-from-installed.js.map +0 -1
  800. package/dist/services/app-passwords.js +0 -173
  801. package/dist/services/app-passwords.js.map +0 -1
  802. package/dist/services/backup-admin.d.ts +0 -101
  803. package/dist/services/backup-admin.js +0 -259
  804. package/dist/services/backup-admin.js.map +0 -1
  805. package/dist/services/backup-manager.d.ts +0 -264
  806. package/dist/services/backup-manager.js +0 -2263
  807. package/dist/services/backup-manager.js.map +0 -1
  808. package/dist/services/backup-verify.js +0 -240
  809. package/dist/services/backup-verify.js.map +0 -1
  810. package/dist/services/capability-endpoint-validator.d.ts +0 -41
  811. package/dist/services/capability-endpoint-validator.js +0 -114
  812. package/dist/services/capability-endpoint-validator.js.map +0 -1
  813. package/dist/services/capability-health.d.ts +0 -16
  814. package/dist/services/capability-health.js +0 -121
  815. package/dist/services/capability-health.js.map +0 -1
  816. package/dist/services/capability-registry.d.ts +0 -29
  817. package/dist/services/capability-registry.js +0 -176
  818. package/dist/services/capability-registry.js.map +0 -1
  819. package/dist/services/capability-sync.d.ts +0 -4
  820. package/dist/services/capability-sync.js +0 -220
  821. package/dist/services/capability-sync.js.map +0 -1
  822. package/dist/services/connection-admin.d.ts +0 -74
  823. package/dist/services/connection-admin.js +0 -287
  824. package/dist/services/connection-admin.js.map +0 -1
  825. package/dist/services/connection-apply.d.ts +0 -91
  826. package/dist/services/connection-apply.js +0 -471
  827. package/dist/services/connection-apply.js.map +0 -1
  828. package/dist/services/connection-resolver.d.ts +0 -65
  829. package/dist/services/connection-resolver.js +0 -281
  830. package/dist/services/connection-resolver.js.map +0 -1
  831. package/dist/services/connection-transactor.d.ts +0 -39
  832. package/dist/services/connection-transactor.js +0 -354
  833. package/dist/services/connection-transactor.js.map +0 -1
  834. package/dist/services/core-manager.d.ts +0 -50
  835. package/dist/services/core-manager.js +0 -411
  836. package/dist/services/core-manager.js.map +0 -1
  837. package/dist/services/external-mounts.js +0 -187
  838. package/dist/services/external-mounts.js.map +0 -1
  839. package/dist/services/files-manager.d.ts +0 -252
  840. package/dist/services/files-manager.js +0 -1156
  841. package/dist/services/files-manager.js.map +0 -1
  842. package/dist/services/files-mounts.d.ts +0 -42
  843. package/dist/services/files-mounts.js +0 -207
  844. package/dist/services/files-mounts.js.map +0 -1
  845. package/dist/services/instance-admin.d.ts +0 -26
  846. package/dist/services/instance-admin.js +0 -218
  847. package/dist/services/instance-admin.js.map +0 -1
  848. package/dist/services/instance-manager.d.ts +0 -192
  849. package/dist/services/instance-manager.js +0 -1289
  850. package/dist/services/instance-manager.js.map +0 -1
  851. package/dist/services/macos-launchd.js +0 -312
  852. package/dist/services/macos-launchd.js.map +0 -1
  853. package/dist/services/nomad-manager.d.ts +0 -307
  854. package/dist/services/nomad-manager.js +0 -3958
  855. package/dist/services/nomad-manager.js.map +0 -1
  856. package/dist/services/organize/applier.js +0 -218
  857. package/dist/services/organize/applier.js.map +0 -1
  858. package/dist/services/organize/rules.js +0 -286
  859. package/dist/services/organize/rules.js.map +0 -1
  860. package/dist/services/organize/scanner.js +0 -366
  861. package/dist/services/organize/scanner.js.map +0 -1
  862. package/dist/services/organize/store.js +0 -82
  863. package/dist/services/organize/store.js.map +0 -1
  864. package/dist/services/plugin-installer.js +0 -128
  865. package/dist/services/plugin-installer.js.map +0 -1
  866. package/dist/services/process-manager.d.ts +0 -25
  867. package/dist/services/process-manager.js +0 -568
  868. package/dist/services/process-manager.js.map +0 -1
  869. package/dist/services/runtime/adapters/custom.d.ts +0 -20
  870. package/dist/services/runtime/adapters/custom.js +0 -188
  871. package/dist/services/runtime/adapters/custom.js.map +0 -1
  872. package/dist/services/runtime/adapters/hermes.d.ts +0 -204
  873. package/dist/services/runtime/adapters/hermes.js +0 -1684
  874. package/dist/services/runtime/adapters/hermes.js.map +0 -1
  875. package/dist/services/runtime/adapters/openclaw-mcporter.d.ts +0 -45
  876. package/dist/services/runtime/adapters/openclaw-mcporter.js +0 -108
  877. package/dist/services/runtime/adapters/openclaw-mcporter.js.map +0 -1
  878. package/dist/services/runtime/adapters/openclaw.d.ts +0 -426
  879. package/dist/services/runtime/adapters/openclaw.js +0 -3975
  880. package/dist/services/runtime/adapters/openclaw.js.map +0 -1
  881. package/dist/services/runtime/index.d.ts +0 -34
  882. package/dist/services/runtime/index.js +0 -51
  883. package/dist/services/runtime/index.js.map +0 -1
  884. package/dist/services/runtime/mcp-shims/anythingllm-shim.d.ts +0 -46
  885. package/dist/services/runtime/mcp-shims/anythingllm-shim.js +0 -281
  886. package/dist/services/runtime/mcp-shims/anythingllm-shim.js.map +0 -1
  887. package/dist/services/runtime/mcp-shims/drive-shim.js +0 -490
  888. package/dist/services/runtime/mcp-shims/drive-shim.js.map +0 -1
  889. package/dist/services/runtime/mcp-shims/jishukb-shim.d.ts +0 -48
  890. package/dist/services/runtime/mcp-shims/jishukb-shim.js +0 -723
  891. package/dist/services/runtime/mcp-shims/jishukb-shim.js.map +0 -1
  892. package/dist/services/runtime/mcp-shims/mcporter-lite.js +0 -276
  893. package/dist/services/runtime/mcp-shims/mcporter-lite.js.map +0 -1
  894. package/dist/services/runtime/migrations.d.ts +0 -23
  895. package/dist/services/runtime/migrations.js +0 -125
  896. package/dist/services/runtime/migrations.js.map +0 -1
  897. package/dist/services/runtime/registry.d.ts +0 -13
  898. package/dist/services/runtime/registry.js +0 -32
  899. package/dist/services/runtime/registry.js.map +0 -1
  900. package/dist/services/runtime-identity.d.ts +0 -13
  901. package/dist/services/runtime-identity.js +0 -166
  902. package/dist/services/runtime-identity.js.map +0 -1
  903. package/dist/services/runtime-repair.d.ts +0 -52
  904. package/dist/services/runtime-repair.js +0 -352
  905. package/dist/services/runtime-repair.js.map +0 -1
  906. package/dist/services/setup-manager.d.ts +0 -158
  907. package/dist/services/setup-manager.js +0 -2740
  908. package/dist/services/setup-manager.js.map +0 -1
  909. package/dist/services/suggestions.d.ts +0 -27
  910. package/dist/services/suggestions.js +0 -133
  911. package/dist/services/suggestions.js.map +0 -1
  912. package/dist/services/system-monitor.js +0 -79
  913. package/dist/services/system-monitor.js.map +0 -1
  914. package/dist/services/system-ollama-provider.d.ts +0 -14
  915. package/dist/services/system-ollama-provider.js +0 -125
  916. package/dist/services/system-ollama-provider.js.map +0 -1
  917. package/dist/services/system-reconciler.d.ts +0 -72
  918. package/dist/services/system-reconciler.js +0 -600
  919. package/dist/services/system-reconciler.js.map +0 -1
  920. package/dist/services/task-registry.d.ts +0 -44
  921. package/dist/services/task-registry.js +0 -76
  922. package/dist/services/task-registry.js.map +0 -1
  923. package/dist/services/types-shim.d.ts +0 -16
  924. package/dist/services/types-shim.js +0 -2
  925. package/dist/services/types-shim.js.map +0 -1
  926. package/dist/services/update-manager.d.ts +0 -47
  927. package/dist/services/update-manager.js +0 -351
  928. package/dist/services/update-manager.js.map +0 -1
  929. package/dist/services/webdav/server.d.ts +0 -24
  930. package/dist/services/webdav/server.js +0 -420
  931. package/dist/services/webdav/server.js.map +0 -1
  932. package/dist/services/webdav/xml-builder.js.map +0 -1
  933. package/dist/services/workspace-builder.d.ts +0 -29
  934. package/dist/services/workspace-builder.js +0 -188
  935. package/dist/services/workspace-builder.js.map +0 -1
  936. package/node_modules/@fastify/static/.github/stale.yml +0 -21
  937. package/node_modules/@isaacs/cliui/LICENSE.md +0 -63
  938. package/node_modules/@isaacs/cliui/README.md +0 -151
  939. package/node_modules/@isaacs/cliui/dist/commonjs/ansi-regex/index.d.ts +0 -4
  940. package/node_modules/@isaacs/cliui/dist/commonjs/ansi-regex/index.d.ts.map +0 -1
  941. package/node_modules/@isaacs/cliui/dist/commonjs/ansi-regex/index.js +0 -16
  942. package/node_modules/@isaacs/cliui/dist/commonjs/ansi-regex/index.js.map +0 -1
  943. package/node_modules/@isaacs/cliui/dist/commonjs/ansi-styles/index.d.ts +0 -34
  944. package/node_modules/@isaacs/cliui/dist/commonjs/ansi-styles/index.d.ts.map +0 -1
  945. package/node_modules/@isaacs/cliui/dist/commonjs/ansi-styles/index.js +0 -170
  946. package/node_modules/@isaacs/cliui/dist/commonjs/ansi-styles/index.js.map +0 -1
  947. package/node_modules/@isaacs/cliui/dist/commonjs/eastasianwidth/index.d.ts +0 -6
  948. package/node_modules/@isaacs/cliui/dist/commonjs/eastasianwidth/index.d.ts.map +0 -1
  949. package/node_modules/@isaacs/cliui/dist/commonjs/eastasianwidth/index.js +0 -307
  950. package/node_modules/@isaacs/cliui/dist/commonjs/eastasianwidth/index.js.map +0 -1
  951. package/node_modules/@isaacs/cliui/dist/commonjs/emoji-regex/index.d.ts +0 -2
  952. package/node_modules/@isaacs/cliui/dist/commonjs/emoji-regex/index.d.ts.map +0 -1
  953. package/node_modules/@isaacs/cliui/dist/commonjs/emoji-regex/index.js +0 -7
  954. package/node_modules/@isaacs/cliui/dist/commonjs/emoji-regex/index.js.map +0 -1
  955. package/node_modules/@isaacs/cliui/dist/commonjs/index.d.ts +0 -41
  956. package/node_modules/@isaacs/cliui/dist/commonjs/index.d.ts.map +0 -1
  957. package/node_modules/@isaacs/cliui/dist/commonjs/index.js +0 -322
  958. package/node_modules/@isaacs/cliui/dist/commonjs/index.js.map +0 -1
  959. package/node_modules/@isaacs/cliui/dist/commonjs/index.min.js +0 -12
  960. package/node_modules/@isaacs/cliui/dist/commonjs/index.min.js.map +0 -7
  961. package/node_modules/@isaacs/cliui/dist/commonjs/package.json +0 -3
  962. package/node_modules/@isaacs/cliui/dist/commonjs/string-width/index.d.ts +0 -5
  963. package/node_modules/@isaacs/cliui/dist/commonjs/string-width/index.d.ts.map +0 -1
  964. package/node_modules/@isaacs/cliui/dist/commonjs/string-width/index.js +0 -49
  965. package/node_modules/@isaacs/cliui/dist/commonjs/string-width/index.js.map +0 -1
  966. package/node_modules/@isaacs/cliui/dist/commonjs/strip-ansi/index.d.ts +0 -2
  967. package/node_modules/@isaacs/cliui/dist/commonjs/strip-ansi/index.d.ts.map +0 -1
  968. package/node_modules/@isaacs/cliui/dist/commonjs/strip-ansi/index.js +0 -8
  969. package/node_modules/@isaacs/cliui/dist/commonjs/strip-ansi/index.js.map +0 -1
  970. package/node_modules/@isaacs/cliui/dist/commonjs/wrap-ansi/index.d.ts +0 -7
  971. package/node_modules/@isaacs/cliui/dist/commonjs/wrap-ansi/index.d.ts.map +0 -1
  972. package/node_modules/@isaacs/cliui/dist/commonjs/wrap-ansi/index.js +0 -176
  973. package/node_modules/@isaacs/cliui/dist/commonjs/wrap-ansi/index.js.map +0 -1
  974. package/node_modules/@isaacs/cliui/dist/esm/ansi-regex/index.d.ts +0 -4
  975. package/node_modules/@isaacs/cliui/dist/esm/ansi-regex/index.d.ts.map +0 -1
  976. package/node_modules/@isaacs/cliui/dist/esm/ansi-regex/index.js +0 -12
  977. package/node_modules/@isaacs/cliui/dist/esm/ansi-regex/index.js.map +0 -1
  978. package/node_modules/@isaacs/cliui/dist/esm/ansi-styles/index.d.ts +0 -34
  979. package/node_modules/@isaacs/cliui/dist/esm/ansi-styles/index.d.ts.map +0 -1
  980. package/node_modules/@isaacs/cliui/dist/esm/ansi-styles/index.js +0 -167
  981. package/node_modules/@isaacs/cliui/dist/esm/ansi-styles/index.js.map +0 -1
  982. package/node_modules/@isaacs/cliui/dist/esm/eastasianwidth/index.d.ts +0 -6
  983. package/node_modules/@isaacs/cliui/dist/esm/eastasianwidth/index.d.ts.map +0 -1
  984. package/node_modules/@isaacs/cliui/dist/esm/eastasianwidth/index.js +0 -299
  985. package/node_modules/@isaacs/cliui/dist/esm/eastasianwidth/index.js.map +0 -1
  986. package/node_modules/@isaacs/cliui/dist/esm/emoji-regex/index.d.ts +0 -2
  987. package/node_modules/@isaacs/cliui/dist/esm/emoji-regex/index.d.ts.map +0 -1
  988. package/node_modules/@isaacs/cliui/dist/esm/emoji-regex/index.js +0 -3
  989. package/node_modules/@isaacs/cliui/dist/esm/emoji-regex/index.js.map +0 -1
  990. package/node_modules/@isaacs/cliui/dist/esm/index.d.ts +0 -41
  991. package/node_modules/@isaacs/cliui/dist/esm/index.d.ts.map +0 -1
  992. package/node_modules/@isaacs/cliui/dist/esm/index.js +0 -317
  993. package/node_modules/@isaacs/cliui/dist/esm/index.js.map +0 -1
  994. package/node_modules/@isaacs/cliui/dist/esm/index.min.js +0 -12
  995. package/node_modules/@isaacs/cliui/dist/esm/index.min.js.map +0 -7
  996. package/node_modules/@isaacs/cliui/dist/esm/package.json +0 -3
  997. package/node_modules/@isaacs/cliui/dist/esm/string-width/index.d.ts +0 -5
  998. package/node_modules/@isaacs/cliui/dist/esm/string-width/index.d.ts.map +0 -1
  999. package/node_modules/@isaacs/cliui/dist/esm/string-width/index.js +0 -46
  1000. package/node_modules/@isaacs/cliui/dist/esm/string-width/index.js.map +0 -1
  1001. package/node_modules/@isaacs/cliui/dist/esm/strip-ansi/index.d.ts +0 -2
  1002. package/node_modules/@isaacs/cliui/dist/esm/strip-ansi/index.d.ts.map +0 -1
  1003. package/node_modules/@isaacs/cliui/dist/esm/strip-ansi/index.js +0 -4
  1004. package/node_modules/@isaacs/cliui/dist/esm/strip-ansi/index.js.map +0 -1
  1005. package/node_modules/@isaacs/cliui/dist/esm/wrap-ansi/index.d.ts +0 -7
  1006. package/node_modules/@isaacs/cliui/dist/esm/wrap-ansi/index.d.ts.map +0 -1
  1007. package/node_modules/@isaacs/cliui/dist/esm/wrap-ansi/index.js +0 -172
  1008. package/node_modules/@isaacs/cliui/dist/esm/wrap-ansi/index.js.map +0 -1
  1009. package/node_modules/@isaacs/cliui/package.json +0 -163
  1010. package/node_modules/content-disposition/HISTORY.md +0 -60
  1011. package/node_modules/cross-spawn/LICENSE +0 -21
  1012. package/node_modules/cross-spawn/README.md +0 -89
  1013. package/node_modules/cross-spawn/index.js +0 -39
  1014. package/node_modules/cross-spawn/lib/enoent.js +0 -59
  1015. package/node_modules/cross-spawn/lib/parse.js +0 -91
  1016. package/node_modules/cross-spawn/lib/util/escape.js +0 -47
  1017. package/node_modules/cross-spawn/lib/util/readShebang.js +0 -23
  1018. package/node_modules/cross-spawn/lib/util/resolveCommand.js +0 -52
  1019. package/node_modules/cross-spawn/package.json +0 -73
  1020. package/node_modules/fastify/test/types/content-type-parser.test-d.ts +0 -72
  1021. package/node_modules/fastify/test/types/decorate-request-reply.test-d.ts +0 -18
  1022. package/node_modules/fastify/test/types/dummy-plugin.ts +0 -9
  1023. package/node_modules/fastify/test/types/errors.test-d.ts +0 -90
  1024. package/node_modules/fastify/test/types/fastify.test-d.ts +0 -352
  1025. package/node_modules/fastify/test/types/hooks.test-d.ts +0 -550
  1026. package/node_modules/fastify/test/types/import.ts +0 -2
  1027. package/node_modules/fastify/test/types/instance.test-d.ts +0 -588
  1028. package/node_modules/fastify/test/types/logger.test-d.ts +0 -277
  1029. package/node_modules/fastify/test/types/plugin.test-d.ts +0 -97
  1030. package/node_modules/fastify/test/types/register.test-d.ts +0 -237
  1031. package/node_modules/fastify/test/types/reply.test-d.ts +0 -254
  1032. package/node_modules/fastify/test/types/request.test-d.ts +0 -188
  1033. package/node_modules/fastify/test/types/route.test-d.ts +0 -553
  1034. package/node_modules/fastify/test/types/schema.test-d.ts +0 -135
  1035. package/node_modules/fastify/test/types/serverFactory.test-d.ts +0 -37
  1036. package/node_modules/fastify/test/types/type-provider.test-d.ts +0 -1213
  1037. package/node_modules/fastify/test/types/using.test-d.ts +0 -17
  1038. package/node_modules/foreground-child/LICENSE +0 -15
  1039. package/node_modules/foreground-child/README.md +0 -128
  1040. package/node_modules/foreground-child/dist/commonjs/all-signals.d.ts +0 -2
  1041. package/node_modules/foreground-child/dist/commonjs/all-signals.d.ts.map +0 -1
  1042. package/node_modules/foreground-child/dist/commonjs/all-signals.js +0 -58
  1043. package/node_modules/foreground-child/dist/commonjs/all-signals.js.map +0 -1
  1044. package/node_modules/foreground-child/dist/commonjs/index.d.ts +0 -58
  1045. package/node_modules/foreground-child/dist/commonjs/index.d.ts.map +0 -1
  1046. package/node_modules/foreground-child/dist/commonjs/index.js +0 -123
  1047. package/node_modules/foreground-child/dist/commonjs/index.js.map +0 -1
  1048. package/node_modules/foreground-child/dist/commonjs/package.json +0 -3
  1049. package/node_modules/foreground-child/dist/commonjs/proxy-signals.d.ts +0 -6
  1050. package/node_modules/foreground-child/dist/commonjs/proxy-signals.d.ts.map +0 -1
  1051. package/node_modules/foreground-child/dist/commonjs/proxy-signals.js +0 -38
  1052. package/node_modules/foreground-child/dist/commonjs/proxy-signals.js.map +0 -1
  1053. package/node_modules/foreground-child/dist/commonjs/watchdog.d.ts +0 -10
  1054. package/node_modules/foreground-child/dist/commonjs/watchdog.d.ts.map +0 -1
  1055. package/node_modules/foreground-child/dist/commonjs/watchdog.js +0 -50
  1056. package/node_modules/foreground-child/dist/commonjs/watchdog.js.map +0 -1
  1057. package/node_modules/foreground-child/dist/esm/all-signals.d.ts +0 -2
  1058. package/node_modules/foreground-child/dist/esm/all-signals.d.ts.map +0 -1
  1059. package/node_modules/foreground-child/dist/esm/all-signals.js +0 -52
  1060. package/node_modules/foreground-child/dist/esm/all-signals.js.map +0 -1
  1061. package/node_modules/foreground-child/dist/esm/index.d.ts +0 -58
  1062. package/node_modules/foreground-child/dist/esm/index.d.ts.map +0 -1
  1063. package/node_modules/foreground-child/dist/esm/index.js +0 -115
  1064. package/node_modules/foreground-child/dist/esm/index.js.map +0 -1
  1065. package/node_modules/foreground-child/dist/esm/package.json +0 -3
  1066. package/node_modules/foreground-child/dist/esm/proxy-signals.d.ts +0 -6
  1067. package/node_modules/foreground-child/dist/esm/proxy-signals.d.ts.map +0 -1
  1068. package/node_modules/foreground-child/dist/esm/proxy-signals.js +0 -34
  1069. package/node_modules/foreground-child/dist/esm/proxy-signals.js.map +0 -1
  1070. package/node_modules/foreground-child/dist/esm/watchdog.d.ts +0 -10
  1071. package/node_modules/foreground-child/dist/esm/watchdog.d.ts.map +0 -1
  1072. package/node_modules/foreground-child/dist/esm/watchdog.js +0 -46
  1073. package/node_modules/foreground-child/dist/esm/watchdog.js.map +0 -1
  1074. package/node_modules/foreground-child/package.json +0 -106
  1075. package/node_modules/glob/dist/esm/bin.d.mts +0 -3
  1076. package/node_modules/glob/dist/esm/bin.d.mts.map +0 -1
  1077. package/node_modules/glob/dist/esm/bin.mjs +0 -346
  1078. package/node_modules/glob/dist/esm/bin.mjs.map +0 -1
  1079. package/node_modules/isexe/.npmignore +0 -2
  1080. package/node_modules/isexe/LICENSE +0 -15
  1081. package/node_modules/isexe/README.md +0 -51
  1082. package/node_modules/isexe/index.js +0 -57
  1083. package/node_modules/isexe/mode.js +0 -41
  1084. package/node_modules/isexe/package.json +0 -31
  1085. package/node_modules/isexe/test/basic.js +0 -221
  1086. package/node_modules/isexe/windows.js +0 -42
  1087. package/node_modules/jackspeak/LICENSE.md +0 -55
  1088. package/node_modules/jackspeak/README.md +0 -394
  1089. package/node_modules/jackspeak/dist/commonjs/index.d.ts +0 -323
  1090. package/node_modules/jackspeak/dist/commonjs/index.d.ts.map +0 -1
  1091. package/node_modules/jackspeak/dist/commonjs/index.js +0 -944
  1092. package/node_modules/jackspeak/dist/commonjs/index.js.map +0 -1
  1093. package/node_modules/jackspeak/dist/commonjs/index.min.js +0 -33
  1094. package/node_modules/jackspeak/dist/commonjs/index.min.js.map +0 -7
  1095. package/node_modules/jackspeak/dist/commonjs/package.json +0 -3
  1096. package/node_modules/jackspeak/dist/esm/index.d.ts +0 -323
  1097. package/node_modules/jackspeak/dist/esm/index.d.ts.map +0 -1
  1098. package/node_modules/jackspeak/dist/esm/index.js +0 -936
  1099. package/node_modules/jackspeak/dist/esm/index.js.map +0 -1
  1100. package/node_modules/jackspeak/dist/esm/index.min.js +0 -33
  1101. package/node_modules/jackspeak/dist/esm/index.min.js.map +0 -7
  1102. package/node_modules/jackspeak/dist/esm/package.json +0 -3
  1103. package/node_modules/jackspeak/package.json +0 -115
  1104. package/node_modules/jishushell-panel/output/public/assets/ApiKeyField-D1i7zWXR.js +0 -1
  1105. package/node_modules/jishushell-panel/output/public/assets/Dashboard-sWIvL43F.js +0 -1
  1106. package/node_modules/jishushell-panel/output/public/assets/HermesChatPanel-DQ8RyvQY.js +0 -1
  1107. package/node_modules/jishushell-panel/output/public/assets/HermesConfigForm-tIbPP1sB.js +0 -4
  1108. package/node_modules/jishushell-panel/output/public/assets/InitPassword-C3Slq3Dd.js +0 -1
  1109. package/node_modules/jishushell-panel/output/public/assets/InstanceDetail-7JqY9tq4.js +0 -92
  1110. package/node_modules/jishushell-panel/output/public/assets/Login-BXLDJlQN.js +0 -1
  1111. package/node_modules/jishushell-panel/output/public/assets/NewInstance-dLc5Xrpx.js +0 -1
  1112. package/node_modules/jishushell-panel/output/public/assets/ProviderRecommendations-DIAXxesl.js +0 -1
  1113. package/node_modules/jishushell-panel/output/public/assets/Settings-Bd5utbBh.js +0 -1
  1114. package/node_modules/jishushell-panel/output/public/assets/Setup-Yn9_20FL.js +0 -1
  1115. package/node_modules/jishushell-panel/output/public/assets/WeixinLoginPanel-C21doQTJ.js +0 -9
  1116. package/node_modules/jishushell-panel/output/public/assets/index-CCkaIEjn.js +0 -20
  1117. package/node_modules/jishushell-panel/output/public/assets/index-D7qxy-Vh.css +0 -1
  1118. package/node_modules/jishushell-panel/output/public/assets/registry-B2ZQZXWL.js +0 -2
  1119. package/node_modules/jishushell-panel/output/public/assets/usePolling-BFZm4do_.js +0 -1
  1120. package/node_modules/jishushell-panel/output/public/assets/vendor-i18n-DqPtOicc.js +0 -9
  1121. package/node_modules/jishushell-panel/output/public/assets/vendor-react-DW5juQin.js +0 -59
  1122. package/node_modules/package-json-from-dist/LICENSE.md +0 -63
  1123. package/node_modules/package-json-from-dist/README.md +0 -110
  1124. package/node_modules/package-json-from-dist/dist/commonjs/index.d.ts +0 -89
  1125. package/node_modules/package-json-from-dist/dist/commonjs/index.d.ts.map +0 -1
  1126. package/node_modules/package-json-from-dist/dist/commonjs/index.js +0 -134
  1127. package/node_modules/package-json-from-dist/dist/commonjs/index.js.map +0 -1
  1128. package/node_modules/package-json-from-dist/dist/commonjs/package.json +0 -3
  1129. package/node_modules/package-json-from-dist/dist/esm/index.d.ts +0 -89
  1130. package/node_modules/package-json-from-dist/dist/esm/index.d.ts.map +0 -1
  1131. package/node_modules/package-json-from-dist/dist/esm/index.js +0 -129
  1132. package/node_modules/package-json-from-dist/dist/esm/index.js.map +0 -1
  1133. package/node_modules/package-json-from-dist/dist/esm/package.json +0 -3
  1134. package/node_modules/package-json-from-dist/package.json +0 -68
  1135. package/node_modules/path-key/index.d.ts +0 -40
  1136. package/node_modules/path-key/index.js +0 -16
  1137. package/node_modules/path-key/license +0 -9
  1138. package/node_modules/path-key/package.json +0 -39
  1139. package/node_modules/path-key/readme.md +0 -61
  1140. package/node_modules/safe-buffer/LICENSE +0 -21
  1141. package/node_modules/safe-buffer/README.md +0 -584
  1142. package/node_modules/safe-buffer/index.d.ts +0 -187
  1143. package/node_modules/safe-buffer/index.js +0 -65
  1144. package/node_modules/safe-buffer/package.json +0 -51
  1145. package/node_modules/shebang-command/index.js +0 -19
  1146. package/node_modules/shebang-command/license +0 -9
  1147. package/node_modules/shebang-command/package.json +0 -34
  1148. package/node_modules/shebang-command/readme.md +0 -34
  1149. package/node_modules/shebang-regex/index.d.ts +0 -22
  1150. package/node_modules/shebang-regex/index.js +0 -2
  1151. package/node_modules/shebang-regex/license +0 -9
  1152. package/node_modules/shebang-regex/package.json +0 -35
  1153. package/node_modules/shebang-regex/readme.md +0 -33
  1154. package/node_modules/signal-exit/LICENSE.txt +0 -16
  1155. package/node_modules/signal-exit/README.md +0 -74
  1156. package/node_modules/signal-exit/dist/cjs/browser.d.ts +0 -12
  1157. package/node_modules/signal-exit/dist/cjs/browser.d.ts.map +0 -1
  1158. package/node_modules/signal-exit/dist/cjs/browser.js +0 -10
  1159. package/node_modules/signal-exit/dist/cjs/browser.js.map +0 -1
  1160. package/node_modules/signal-exit/dist/cjs/index.d.ts +0 -48
  1161. package/node_modules/signal-exit/dist/cjs/index.d.ts.map +0 -1
  1162. package/node_modules/signal-exit/dist/cjs/index.js +0 -279
  1163. package/node_modules/signal-exit/dist/cjs/index.js.map +0 -1
  1164. package/node_modules/signal-exit/dist/cjs/package.json +0 -3
  1165. package/node_modules/signal-exit/dist/cjs/signals.d.ts +0 -29
  1166. package/node_modules/signal-exit/dist/cjs/signals.d.ts.map +0 -1
  1167. package/node_modules/signal-exit/dist/cjs/signals.js +0 -42
  1168. package/node_modules/signal-exit/dist/cjs/signals.js.map +0 -1
  1169. package/node_modules/signal-exit/dist/mjs/browser.d.ts +0 -12
  1170. package/node_modules/signal-exit/dist/mjs/browser.d.ts.map +0 -1
  1171. package/node_modules/signal-exit/dist/mjs/browser.js +0 -4
  1172. package/node_modules/signal-exit/dist/mjs/browser.js.map +0 -1
  1173. package/node_modules/signal-exit/dist/mjs/index.d.ts +0 -48
  1174. package/node_modules/signal-exit/dist/mjs/index.d.ts.map +0 -1
  1175. package/node_modules/signal-exit/dist/mjs/index.js +0 -275
  1176. package/node_modules/signal-exit/dist/mjs/index.js.map +0 -1
  1177. package/node_modules/signal-exit/dist/mjs/package.json +0 -3
  1178. package/node_modules/signal-exit/dist/mjs/signals.d.ts +0 -29
  1179. package/node_modules/signal-exit/dist/mjs/signals.d.ts.map +0 -1
  1180. package/node_modules/signal-exit/dist/mjs/signals.js +0 -39
  1181. package/node_modules/signal-exit/dist/mjs/signals.js.map +0 -1
  1182. package/node_modules/signal-exit/package.json +0 -106
  1183. package/node_modules/which/CHANGELOG.md +0 -166
  1184. package/node_modules/which/LICENSE +0 -15
  1185. package/node_modules/which/README.md +0 -54
  1186. package/node_modules/which/bin/node-which +0 -52
  1187. package/node_modules/which/package.json +0 -43
  1188. package/node_modules/which/which.js +0 -125
  1189. package/scripts/check-adapter-isolation.ts +0 -293
  1190. /package/dist/services/{app → app-common}/app-compiler.d.ts +0 -0
  1191. /package/dist/services/{app → app-common}/terminal-session-manager.d.ts +0 -0
  1192. /package/dist/services/{backup-verify.d.ts → backup/backup-verify.d.ts} +0 -0
  1193. /package/dist/services/{external-mounts.d.ts → files/external-mounts.d.ts} +0 -0
  1194. /package/dist/services/{organize → files/organize}/applier.d.ts +0 -0
  1195. /package/dist/services/{organize → files/organize}/rules.d.ts +0 -0
  1196. /package/dist/services/{organize → files/organize}/scanner.d.ts +0 -0
  1197. /package/dist/services/{organize → files/organize}/store.d.ts +0 -0
  1198. /package/dist/services/{webdav → files/webdav}/xml-builder.d.ts +0 -0
  1199. /package/dist/services/{webdav → files/webdav}/xml-builder.js +0 -0
  1200. /package/dist/services/{app-passwords.d.ts → instances/passwords.d.ts} +0 -0
  1201. /package/dist/services/{agent-apps → integrations/installable}/installers/registry-probe.d.ts +0 -0
  1202. /package/dist/services/{agent-apps → integrations/installable}/installers/registry-probe.js +0 -0
  1203. /package/dist/services/{runtime/mcp-shims → integrations/openclaw}/drive-shim.d.ts +0 -0
  1204. /package/dist/services/{runtime/mcp-shims → integrations/openclaw}/mcporter-lite.d.ts +0 -0
  1205. /package/dist/services/{plugin-installer.d.ts → setup/plugin-installer.d.ts} +0 -0
  1206. /package/dist/services/{macos-launchd.d.ts → system/macos-launchd.d.ts} +0 -0
  1207. /package/dist/services/{system-monitor.d.ts → system/system-monitor.d.ts} +0 -0
@@ -0,0 +1,1342 @@
1
+ import { execFileSync } from "child_process";
2
+ import { chownSync, closeSync, existsSync, openSync, readFileSync, readdirSync, renameSync, statSync, } from "fs";
3
+ import { rm as rmAsync } from "fs/promises";
4
+ import { createServer as netCreateServer } from "net";
5
+ import { networkInterfaces, userInfo } from "os";
6
+ import { dirname, join, resolve } from "path";
7
+ import * as config from "../../config.js";
8
+ import { safeWriteJson } from "../../utils/safe-json.js";
9
+ import { ensureDirContainer, writeSecretFile } from "../../utils/fs.js";
10
+ import { resolveServiceUser as resolveCoreServiceUser } from "../../utils/service-user.js";
11
+ // integrations/index.ts gets imported only for framework-level integration lookups
12
+ // (preferredHostPort allocator seed). Integrations statically import BACK into this
13
+ // file for primitives; that static cycle is safe because no top-level code
14
+ // in integrations references instance-manager exports.
15
+ import { getIntegration } from "../integrations/index.js";
16
+ import { isExecutionOwnerRequiredError, resolveExecutionOwnerFromMetadata, } from "../app-common/execution-owner.js";
17
+ import { buildCanonicalAppInstance, readCanonicalInstance, readSpecSnapshotFromDir, } from "../app-common/instance-store.js";
18
+ import { DEFINITION_FILENAME, INSTANCE_METADATA_FILENAME, MANIFEST_FILENAME, RESOLVED_SPEC_FILENAME, resolveAppDir, } from "../app-common/paths.js";
19
+ function getConfigValue(name) {
20
+ return name in config ? config[name] : undefined;
21
+ }
22
+ function resolveConfigPath(value, fallback) {
23
+ return typeof value === "string" && value.trim() ? value : fallback;
24
+ }
25
+ const JISHUSHELL_HOME = resolveConfigPath(getConfigValue("JISHUSHELL_HOME"), resolve(process.env.HOME ?? userInfo().homedir, ".jishushell"));
26
+ const APPS_DIR = resolveConfigPath(getConfigValue("APPS_DIR"), join(JISHUSHELL_HOME, "apps"));
27
+ const BACKUPS_DIR = resolveConfigPath(getConfigValue("BACKUPS_DIR"), join(JISHUSHELL_HOME, "backups"));
28
+ const getCoreConfigValue = getConfigValue("getCoreConfig");
29
+ const _getCoreConfig = typeof getCoreConfigValue === "function"
30
+ ? getCoreConfigValue
31
+ : () => ({});
32
+ const _configChangeListeners = [];
33
+ export function onConfigChange(listener) {
34
+ _configChangeListeners.push(listener);
35
+ return () => {
36
+ const idx = _configChangeListeners.indexOf(listener);
37
+ if (idx >= 0)
38
+ _configChangeListeners.splice(idx, 1);
39
+ };
40
+ }
41
+ /**
42
+ * Fire the config-change listener fan-out. Integrations call this after
43
+ * `saveNativeConfig()` so LLM proxy / config editors pick up the change.
44
+ */
45
+ export function notifyConfigChange(instanceId) {
46
+ for (const listener of _configChangeListeners) {
47
+ try {
48
+ listener(instanceId);
49
+ }
50
+ catch { /* ignore listener errors */ }
51
+ }
52
+ }
53
+ const ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
54
+ // ── Path helpers (framework-level) ──
55
+ function hasIncompleteAppInstallShadow(dir) {
56
+ const markers = [
57
+ MANIFEST_FILENAME,
58
+ DEFINITION_FILENAME,
59
+ RESOLVED_SPEC_FILENAME,
60
+ INSTANCE_METADATA_FILENAME,
61
+ ].map((fileName) => existsSync(join(dir, fileName)));
62
+ return markers.some(Boolean) && !markers.every(Boolean);
63
+ }
64
+ function resolveInstanceRoot(instanceId) {
65
+ // Step 13: canonical `apps/<id>` only on the runtime path. Un-migrated
66
+ // `instances/<id>` directories must be handled by `jishushell migrate legacy`.
67
+ return resolveAppDir(instanceId);
68
+ }
69
+ export function instanceDir(instanceId) {
70
+ return resolveInstanceRoot(instanceId);
71
+ }
72
+ export function instanceMetaPath(instanceId) {
73
+ return join(instanceDir(instanceId), INSTANCE_METADATA_FILENAME);
74
+ }
75
+ // Default model env file path. Integration-specific resolvers live on the app
76
+ // integration; this helper provides the framework-level fallback.
77
+ export function defaultModelEnvFile(instanceId) {
78
+ return join(instanceDir(instanceId), "model.env");
79
+ }
80
+ export function normalizePath(p) {
81
+ return resolve(p.replace(/^~/, userInfo().homedir));
82
+ }
83
+ // ── Host port allocator ──
84
+ //
85
+ // Domain semantics (canonical port model, per Step 2 of the App Lifecycle
86
+ // Runtime decision):
87
+ // - `hostPort` is the host-side port Core exposes for an instance. Core's
88
+ // allocator is the ONLY decider. Nomad/Docker may not reverse-decide it.
89
+ // - `containerPort` is the in-container listener owned by the workload and
90
+ // must remain stable across host-port reallocations.
91
+ // - The persisted source of truth is `runtime.ports[].hostPort` on each
92
+ // instance's `instance.json`.
93
+ //
94
+ // In-memory reservation table.
95
+ //
96
+ // `_pendingPorts` exists to close the race window between
97
+ // 1. the allocator decided a host port is free, and
98
+ // 2. that decision is durably persisted into `instance.json`.
99
+ //
100
+ // The canonical allocator lifecycle is:
101
+ // - `reserve` (internal): set by `allocateHostPort` before the async
102
+ // `isPortInUse` probe, so a concurrent caller cannot select the same port
103
+ // during the await gap.
104
+ // - `commit`: invoked by the caller AFTER `runtime.ports[].hostPort` is
105
+ // durably written. The reservation slot is freed because durable
106
+ // ownership has taken over.
107
+ // - `release`: invoked by the caller on any failure path before the
108
+ // durable write succeeds. The reservation slot is freed so concurrent /
109
+ // retried allocations can reuse the port.
110
+ //
111
+ // The shape is exposed via the `HostPortAllocation` object returned by
112
+ // `allocateHostPort`. Callers must use that object's `commit()` /
113
+ // `release()` and must NOT lean on the legacy "finally { releasePendingPort
114
+ // } " pattern; that pattern conflates success and failure paths and was
115
+ // explicitly called out as forbidden in Step 2.
116
+ //
117
+ // No cross-process reconcile is required for this table: it is a transient
118
+ // in-memory Map; on Core restart it starts empty. Any port whose durable
119
+ // `runtime.ports[].hostPort` got written before the crash is already owned
120
+ // by the surviving `instance.json`; any port that was only reserved (no
121
+ // durable write yet) is simply lost on restart, which is the correct
122
+ // behaviour — the instance never existed.
123
+ const _pendingPorts = new Map();
124
+ export const INSTANCE_NEEDS_MIGRATION_CODE = "INSTANCE_NEEDS_MIGRATION";
125
+ export class CanonicalRuntimePortRequiredError extends Error {
126
+ code = INSTANCE_NEEDS_MIGRATION_CODE;
127
+ statusCode = 409;
128
+ instanceId;
129
+ constructor(instanceId) {
130
+ super(`Instance '${instanceId}' has no canonical runtime.ports[] host-port allocation. ` +
131
+ "Legacy host-port fields are no longer read on lifecycle/status/proxy paths. " +
132
+ "Run `jishushell system repair-instances` or `jishushell migrate legacy --yes` before retrying.");
133
+ this.name = "CanonicalRuntimePortRequiredError";
134
+ this.instanceId = instanceId;
135
+ }
136
+ }
137
+ export function isCanonicalRuntimePortRequiredError(error) {
138
+ return error instanceof CanonicalRuntimePortRequiredError
139
+ || (!!error
140
+ && typeof error === "object"
141
+ && error.code === INSTANCE_NEEDS_MIGRATION_CODE);
142
+ }
143
+ function reservePendingPort(instanceId, port) {
144
+ _pendingPorts.set(port, instanceId);
145
+ }
146
+ function clearPendingPort(port, instanceId) {
147
+ const owner = _pendingPorts.get(port);
148
+ if (owner == null)
149
+ return;
150
+ if (instanceId && owner !== instanceId)
151
+ return;
152
+ _pendingPorts.delete(port);
153
+ }
154
+ /**
155
+ * Read the primary externally reachable host port out of a persisted runtime record.
156
+ *
157
+ * Runtime hot paths only trust canonical `runtime.ports[].hostPort`.
158
+ * Legacy env/args fallbacks are repair-only readers owned by the migrator or
159
+ * integration repair code and must not be consulted here.
160
+ */
161
+ export function extractPrimaryHostPort(runtime, _integrationKind) {
162
+ if (!runtime)
163
+ return null;
164
+ // Primary: RuntimeSpec.ports[] declaration. Prefer the first externally
165
+ // visible port; fall back to any hostPort only for malformed/legacy records.
166
+ const ports = Array.isArray(runtime.ports) ? runtime.ports : [];
167
+ for (const port of ports) {
168
+ if ((port?.visibility ?? "external") !== "internal" && Number.isInteger(port.hostPort) && port.hostPort > 0) {
169
+ return port.hostPort;
170
+ }
171
+ }
172
+ for (const port of ports) {
173
+ if (Number.isInteger(port?.hostPort) && port.hostPort > 0) {
174
+ return port.hostPort;
175
+ }
176
+ }
177
+ return null;
178
+ }
179
+ function requireCanonicalPrimaryHostPort(instanceId, runtime) {
180
+ const port = extractPrimaryHostPort(runtime);
181
+ if (port)
182
+ return port;
183
+ throw new CanonicalRuntimePortRequiredError(instanceId);
184
+ }
185
+ function usedHostPorts(excludeId, excludeHostPort, options = {}) {
186
+ const ports = new Set();
187
+ for (const inst of listInstances()) {
188
+ const hasIntegration = Array.isArray(inst.integrations)
189
+ && inst.integrations.length > 0;
190
+ const runtimePorts = Array.isArray(inst.runtime?.ports) ? inst.runtime.ports : [];
191
+ const canonicalHostPorts = runtimePorts
192
+ .map((port) => port?.hostPort)
193
+ .filter((port) => Number.isInteger(port) && Number(port) > 0);
194
+ if (options.ignoreIncompleteCanonicalInstanceIds?.has(inst.id)
195
+ && hasIntegration
196
+ && canonicalHostPorts.length === 0) {
197
+ continue;
198
+ }
199
+ if (canonicalHostPorts.length === 0 && hasIntegration) {
200
+ throw new CanonicalRuntimePortRequiredError(inst.id);
201
+ }
202
+ for (const port of canonicalHostPorts) {
203
+ if (inst.id === excludeId && (excludeHostPort == null || port === excludeHostPort))
204
+ continue;
205
+ ports.add(port);
206
+ }
207
+ }
208
+ return ports;
209
+ }
210
+ function safePort(port) {
211
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
212
+ throw new Error(`Invalid port: ${port}`);
213
+ return String(port);
214
+ }
215
+ /**
216
+ * Probes whether a port is currently held by any process on the host.
217
+ *
218
+ * Binds four addresses concurrently — `0.0.0.0`, `127.0.0.1`, `::` (v6-only),
219
+ * and `::1` — and treats the port as busy if any probe returns EADDRINUSE.
220
+ * The single-`0.0.0.0` probe used by the earlier revision was sufficient on
221
+ * Linux (where binding `0.0.0.0` conflicts with any pre-existing loopback
222
+ * listener on the same port) but silently passed on macOS, where BSD socket
223
+ * semantics let a wildcard v4 bind coexist with a `127.0.0.1` listener. A
224
+ * loopback-only service would then be invisible to JishuShell, so port
225
+ * allocation could assign the same host port to a new instance and the
226
+ * workload would silently fail to bind at start time. Probing the loopback
227
+ * addresses directly closes that gap.
228
+ */
229
+ export function isPortInUse(port) {
230
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
231
+ return Promise.resolve(false);
232
+ const probeAt = (host, opts = {}) => new Promise((resolve) => {
233
+ const server = netCreateServer();
234
+ server.once("error", (err) => {
235
+ if (err?.code === "EADDRINUSE")
236
+ return resolve(true);
237
+ // EACCES / EADDRNOTAVAIL / ENOTSUP / EINVAL mean we could not even
238
+ // attempt the bind (restricted port, address family unsupported on
239
+ // this host, etc). Report "not busy" from this probe so one bad
240
+ // locus doesn't falsely block the whole port — the other probes
241
+ // still cover their respective loci.
242
+ if (err?.code && err.code !== "EACCES" && err.code !== "EADDRNOTAVAIL"
243
+ && err.code !== "ENOTSUP" && err.code !== "EINVAL" && err.code !== "EAFNOSUPPORT") {
244
+ console.warn(`[port-probe] bind ${host}:${port} failed with ${err.code}: ${err.message}; treating locus as free`);
245
+ }
246
+ resolve(false);
247
+ });
248
+ server.once("listening", () => {
249
+ server.close(() => resolve(false));
250
+ });
251
+ server.listen({ port, host, ...opts });
252
+ });
253
+ // Run probes sequentially, not in parallel: two probes on the same port
254
+ // collide with each other (the first bind on 0.0.0.0 makes the second
255
+ // bind on 127.0.0.1 hit EADDRINUSE), which would make every port look
256
+ // busy. Short-circuit on the first busy locus to keep the common case
257
+ // (port free) close to single-probe latency.
258
+ return (async () => {
259
+ const loci = [
260
+ ["0.0.0.0", {}],
261
+ ["127.0.0.1", {}],
262
+ ["::", { ipv6Only: true }],
263
+ ["::1", {}],
264
+ ];
265
+ for (const [host, opts] of loci) {
266
+ if (await probeAt(host, opts))
267
+ return true;
268
+ }
269
+ return false;
270
+ })();
271
+ }
272
+ /**
273
+ * Kind-agnostic host-port allocator (canonical port model).
274
+ *
275
+ * Walks upward from `defaultPort` until a free host port is found that is
276
+ * neither held by any canonical runtime port on an existing instance, nor by
277
+ * a pending reservation, nor by any listener on the host. The historical
278
+ * Callers may use it for every external runtime port.
279
+ *
280
+ * Concurrent callers coordinate through `_pendingPorts`: each candidate port
281
+ * is reserved BEFORE the async `isPortInUse` probe so concurrent calls cannot
282
+ * select the same port during the await gap. The returned allocation owns
283
+ * the lifecycle from there: the caller
284
+ * MUST call `commit()` once the chosen port is durably persisted, or
285
+ * `release()` on any failure path. Calling neither leaks the reservation
286
+ * slot until process restart.
287
+ */
288
+ export async function allocateHostPort(instanceId, defaultPort, replacingHostPort, options = {}) {
289
+ const used = usedHostPorts(instanceId, replacingHostPort, options);
290
+ const skipped = [];
291
+ let port = defaultPort;
292
+ while (true) {
293
+ if (port > 65535) {
294
+ throw new Error(`No available host port found (all ports ${defaultPort}-65535 in use)`);
295
+ }
296
+ if (used.has(port) || _pendingPorts.has(port)) {
297
+ skipped.push(port);
298
+ port++;
299
+ continue;
300
+ }
301
+ // Reserve BEFORE the async isPortInUse check to prevent concurrent callers
302
+ // from selecting the same port during the await gap.
303
+ reservePendingPort(instanceId, port);
304
+ const reservation = {
305
+ instanceId,
306
+ port,
307
+ skipped,
308
+ commit: () => {
309
+ clearPendingPort(port, instanceId);
310
+ return port;
311
+ },
312
+ release: () => {
313
+ clearPendingPort(port, instanceId);
314
+ },
315
+ };
316
+ try {
317
+ if (await isPortInUse(port)) {
318
+ reservation.release();
319
+ skipped.push(port);
320
+ port++;
321
+ continue;
322
+ }
323
+ return reservation;
324
+ }
325
+ catch {
326
+ reservation.release();
327
+ // Skip this port on a transient OS error rather than failing the entire
328
+ // allocation — a single bad port check should not prevent instance creation.
329
+ console.warn(`[instance] Port ${port} availability check failed, trying next port`);
330
+ skipped.push(port);
331
+ port++;
332
+ continue;
333
+ }
334
+ }
335
+ }
336
+ /**
337
+ * Legacy by-port release helper.
338
+ *
339
+ * Production code MUST use the `commit()` / `release()` methods on the
340
+ * {@link HostPortAllocation} returned from {@link allocateHostPort};
341
+ * those make the success-vs-failure split explicit, which is the Step 2
342
+ * canonical contract. This function is kept only as a test/facade compatibility
343
+ * export for older call sites that still talk to the allocator by port number.
344
+ * Normal production code should not need it.
345
+ */
346
+ export function releasePendingPort(port) {
347
+ clearPendingPort(port);
348
+ }
349
+ // ── Runtime / config builders ──
350
+ /**
351
+ * When jishushell runs as root (e.g. systemd service), returns the actual
352
+ * non-root user that should own instance files and run workload processes.
353
+ * Returns null when not running as root or when no suitable non-root user is found.
354
+ */
355
+ export function resolveServiceUser() {
356
+ if (typeof process.getuid !== "function" || process.getuid() !== 0)
357
+ return null;
358
+ const user = resolveCoreServiceUser({ jishuHome: JISHUSHELL_HOME });
359
+ return user ? { username: user.username, uid: user.uid, gid: user.gid } : null;
360
+ }
361
+ /**
362
+ * When running as root, chown a file (and its .bak) to the service user so the
363
+ * workload process (running as that user) can read/write its own data files.
364
+ * No-op when not running as root.
365
+ */
366
+ export function chownToServiceUser(...paths) {
367
+ const svc = resolveServiceUser();
368
+ if (!svc)
369
+ return;
370
+ for (const p of paths) {
371
+ for (const f of [p, p + ".bak", p + ".bak.1", p + ".bak.2"]) {
372
+ try {
373
+ if (existsSync(f))
374
+ chownSync(f, svc.uid, svc.gid);
375
+ }
376
+ catch { /* best effort */ }
377
+ }
378
+ }
379
+ }
380
+ // ── Env file helpers ──
381
+ export function parseEnvFile(path) {
382
+ const env = {};
383
+ if (!existsSync(path))
384
+ return env;
385
+ for (let line of readFileSync(path, "utf-8").split("\n")) {
386
+ line = line.trim();
387
+ if (!line || line.startsWith("#"))
388
+ continue;
389
+ if (line.startsWith("export "))
390
+ line = line.slice(7).trimStart();
391
+ if (!line.includes("="))
392
+ continue;
393
+ const eqIdx = line.indexOf("=");
394
+ const key = line.slice(0, eqIdx).trim();
395
+ let value = line.slice(eqIdx + 1).trim();
396
+ if (!ENV_KEY_RE.test(key))
397
+ continue;
398
+ if (value.length >= 2 && value[0] === value[value.length - 1] && (value[0] === "'" || value[0] === '"')) {
399
+ value = value.slice(1, -1);
400
+ }
401
+ env[key] = value;
402
+ }
403
+ return env;
404
+ }
405
+ function quoteEnvValue(value) {
406
+ if (/^[A-Za-z0-9_./:@%+=,-]+$/.test(value))
407
+ return value;
408
+ return JSON.stringify(value);
409
+ }
410
+ export function updateEnvFile(path, updates) {
411
+ ensureDirContainer(dirname(path));
412
+ const existing = existsSync(path) ? readFileSync(path, "utf-8").split("\n") : [];
413
+ const remaining = { ...updates };
414
+ const newLines = [];
415
+ for (const rawLine of existing) {
416
+ const stripped = rawLine.trim();
417
+ const candidate = stripped.startsWith("export ") ? stripped.slice(7).trimStart() : stripped;
418
+ if (!candidate || candidate.startsWith("#") || !candidate.includes("=")) {
419
+ newLines.push(rawLine);
420
+ continue;
421
+ }
422
+ const key = candidate.slice(0, candidate.indexOf("=")).trim();
423
+ if (!ENV_KEY_RE.test(key) || !(key in remaining)) {
424
+ newLines.push(rawLine);
425
+ continue;
426
+ }
427
+ const value = remaining[key];
428
+ delete remaining[key];
429
+ if (value === "")
430
+ continue;
431
+ const prefix = stripped.startsWith("export ") ? "export " : "";
432
+ newLines.push(`${prefix}${key}=${quoteEnvValue(value)}`);
433
+ }
434
+ for (const [key, value] of Object.entries(remaining)) {
435
+ if (!ENV_KEY_RE.test(key) || value === "")
436
+ continue;
437
+ newLines.push(`${key}=${quoteEnvValue(value)}`);
438
+ }
439
+ const output = newLines.join("\n").trimEnd();
440
+ const content = output ? output + "\n" : "";
441
+ // Atomic write: tmp then rename to protect against RPi power loss
442
+ const tmp = path + ".tmp";
443
+ writeSecretFile(tmp, content);
444
+ renameSync(tmp, path);
445
+ chownToServiceUser(path);
446
+ }
447
+ // ── Provider key helpers ──
448
+ export function inferProviderApiKeyEnvName(providerId) {
449
+ let normalized = providerId.replace(/[^A-Za-z0-9]+/g, "_").replace(/^_|_$/g, "").toUpperCase();
450
+ if (!normalized)
451
+ normalized = "JISHUSHELL_PROVIDER";
452
+ return `${normalized}_API_KEY`;
453
+ }
454
+ // ── Public API ──
455
+ /**
456
+ * Probe whether a file is readable by the current process. Used to
457
+ * distinguish "primary missing / corrupted" (recoverable via safeReadJson's
458
+ * .bak chain) from "primary exists but permission denied" (EACCES — the
459
+ * common sudo-script footgun that leaves root-owned files). safeReadJson
460
+ * swallows every read error internally and returns null, so without this
461
+ * probe an unreadable primary looks identical to a truly-gone instance.
462
+ */
463
+ function probeReadable(path) {
464
+ if (!existsSync(path))
465
+ return null;
466
+ try {
467
+ const fd = openSync(path, "r");
468
+ closeSync(fd);
469
+ return null;
470
+ }
471
+ catch (e) {
472
+ return e;
473
+ }
474
+ }
475
+ export function listInstances() {
476
+ const deduped = new Map();
477
+ // Step 13: canonical `apps/<id>` only. Un-migrated `instances/<id>`
478
+ // directories are surfaced exclusively by `jishushell migrate legacy`.
479
+ const rootDir = APPS_DIR;
480
+ if (existsSync(rootDir)) {
481
+ const entries = readdirSync(rootDir).sort();
482
+ for (const name of entries) {
483
+ if (deduped.has(name))
484
+ continue;
485
+ const metaPath = join(rootDir, name, "instance.json");
486
+ const dirPath = join(rootDir, name);
487
+ try {
488
+ if (!statSync(dirPath).isDirectory())
489
+ continue;
490
+ if (hasIncompleteAppInstallShadow(dirPath))
491
+ continue;
492
+ if (!existsSync(metaPath))
493
+ continue;
494
+ // Use safeReadJson so primary instance.json that was corrupted or
495
+ // deleted mid-rename falls back to the .bak chain maintained by
496
+ // safeWriteJson. Without this, an interrupted safeWriteJson call
497
+ // would silently drop the instance from every list/get hot path
498
+ // even though the backup chain still holds valid content on disk.
499
+ const meta = readCanonicalInstance(name);
500
+ if (meta) {
501
+ deduped.set(name, meta);
502
+ continue;
503
+ }
504
+ // safeReadJson → null can mean any of (a) primary missing + no
505
+ // backups, (b) all candidates unparseable, (c) permission denied.
506
+ // (a) and (b) are legitimate "drop from list" cases; (c) is the
507
+ // sudo-script footgun and must be logged loudly so the operator
508
+ // doesn't just see an empty instance list with no hint why.
509
+ const readErr = probeReadable(metaPath);
510
+ if (readErr && readErr.code === "EACCES") {
511
+ console.error(`[instance-manager] cannot read instance '${name}': ${readErr.message}. ` +
512
+ `Check file ownership with: ls -la ${metaPath}`);
513
+ }
514
+ }
515
+ catch (e) {
516
+ // Fallback for failures before the safeReadJson call (e.g. statSync
517
+ // on a directory we can't enter). Still log instead of silently
518
+ // dropping the entry.
519
+ console.error(`[instance-manager] cannot read instance '${name}': ${e.message}`);
520
+ }
521
+ }
522
+ }
523
+ return [...deduped.values()];
524
+ }
525
+ export function getInstance(instanceId) {
526
+ const metaPath = instanceMetaPath(instanceId);
527
+ // Go through safeReadJson so primary missing/corrupted instance.json
528
+ // is still served from the .bak chain. Returning null on "truly gone"
529
+ // (no primary, no backups) keeps the existing 404 behavior intact.
530
+ const meta = readCanonicalInstance(instanceId);
531
+ if (meta) {
532
+ return meta;
533
+ }
534
+ // safeReadJson swallows every read error internally, which is exactly
535
+ // wrong for the EACCES case — a root-owned primary would silently
536
+ // return null and callers would report "Instance not found" instead
537
+ // of the actionable "check file ownership" message. Re-probe to
538
+ // distinguish and throw on permission denial. Missing/corrupted with
539
+ // no backup still returns null (→ 404 upstream).
540
+ const readErr = probeReadable(metaPath);
541
+ if (readErr && readErr.code === "EACCES") {
542
+ throw new Error(`Cannot read instance '${instanceId}' metadata: ${readErr.message}. ` +
543
+ `Check file ownership with: ls -la ${metaPath}`);
544
+ }
545
+ return null;
546
+ }
547
+ export function updateInstance(instanceId, name, description) {
548
+ const meta = getInstance(instanceId);
549
+ if (!meta)
550
+ return null;
551
+ if (name != null)
552
+ meta.name = name;
553
+ if (description != null)
554
+ meta.description = description;
555
+ const snapshot = readSpecSnapshotFromDir(instanceDir(instanceId));
556
+ const next = buildCanonicalAppInstance({
557
+ raw: meta,
558
+ id: instanceId,
559
+ name: meta.name,
560
+ description: meta.description,
561
+ spec: snapshot?.spec ?? null,
562
+ });
563
+ safeWriteJson(instanceMetaPath(instanceId), next);
564
+ chownToServiceUser(instanceMetaPath(instanceId));
565
+ return next;
566
+ }
567
+ export function updateInstanceMeta(instanceId, patch) {
568
+ const metaPath = instanceMetaPath(instanceId);
569
+ const meta = getInstance(instanceId);
570
+ if (!meta)
571
+ throw new Error(`Cannot update unknown instance '${instanceId}'`);
572
+ Object.assign(meta, patch);
573
+ const snapshot = readSpecSnapshotFromDir(instanceDir(instanceId));
574
+ const next = buildCanonicalAppInstance({
575
+ raw: meta,
576
+ id: instanceId,
577
+ name: typeof meta.name === "string" ? meta.name : undefined,
578
+ description: typeof meta.description === "string" ? meta.description : undefined,
579
+ spec: snapshot?.spec ?? null,
580
+ });
581
+ safeWriteJson(metaPath, next);
582
+ chownToServiceUser(metaPath);
583
+ }
584
+ /**
585
+ * Toggle the opt-in "privileged" (native-install-like) profile on an
586
+ * integration-managed docker task. Default (false / absent) keeps the
587
+ * hardened container (cap_drop=ALL, no-new-privileges, read-only rootfs when
588
+ * supported). When enabled, the owning integration's runtime builder relaxes
589
+ * those settings so the workload has native-install-like permissions.
590
+ * Persisted in canonical `instance.json.runtime` so it survives restarts and
591
+ * is reapplied on every Nomad job submit.
592
+ * Returns false when the instance does not exist. Caller must restart the
593
+ * instance for the change to take effect.
594
+ */
595
+ export function setInstancePrivileged(instanceId, privileged) {
596
+ const meta = getInstance(instanceId);
597
+ if (!meta)
598
+ return false;
599
+ const runtime = { ...(meta.runtime ?? {}) };
600
+ if (privileged)
601
+ runtime.privileged = true;
602
+ else
603
+ delete runtime.privileged;
604
+ updateInstanceMeta(instanceId, { runtime });
605
+ return true;
606
+ }
607
+ export async function deleteInstance(instanceId, purgeBackups = false) {
608
+ const d = instanceDir(instanceId);
609
+ if (!existsSync(d))
610
+ return { ok: false, warnings: ["Instance directory not found"] };
611
+ const warnings = [];
612
+ // Cancel auto-backup timer and any queued jobs for this instance
613
+ import("../backup/backup-manager.js").then(({ cancelAutoBackup, getQueueStatus, cancelJob }) => {
614
+ cancelAutoBackup(instanceId);
615
+ // Cancel queued (not yet running) jobs for this instance
616
+ const q = getQueueStatus();
617
+ for (const job of q.queued) {
618
+ if (job.instanceId === instanceId)
619
+ cancelJob(job.id);
620
+ }
621
+ }).catch(() => { });
622
+ // Cache metadata BEFORE deletion so integrations can inspect it after rm.
623
+ const meta = getInstance(instanceId);
624
+ let runtimeIntegrationEntry = null;
625
+ // Integration-owned pre-delete hook. Integrations use this to emit advisories
626
+ // for resources that live outside the instance dir (custom integration
627
+ // homes, named docker volumes, etc). Errors are collected
628
+ // into the response so one integration misbehaving can't block removal.
629
+ try {
630
+ runtimeIntegrationEntry = getRuntimeIntegrationEntry(meta);
631
+ if (runtimeIntegrationEntry && meta) {
632
+ const integration = runtimeIntegrationEntry.integration;
633
+ if (integration.hooks?.onDelete) {
634
+ const hookResult = await integration.hooks.onDelete({ instanceId, meta });
635
+ if (hookResult && Array.isArray(hookResult.warnings)) {
636
+ warnings.push(...hookResult.warnings);
637
+ }
638
+ }
639
+ }
640
+ }
641
+ catch (e) {
642
+ warnings.push(`integration onDelete hook failed: ${e.message}`);
643
+ }
644
+ // Clean up Nomad Variables (async, best-effort)
645
+ if (runtimeIntegrationEntry) {
646
+ const integrationKind = runtimeIntegrationEntry.kind;
647
+ import("../runtime/drivers/nomad.js").then((nm) => {
648
+ nm.purgeIntegrationInstanceVariables(instanceId, integrationKind).catch((e) => {
649
+ console.warn(`[instance] Failed to purge Nomad variables for ${instanceId}:`, e.message);
650
+ });
651
+ }).catch((e) => {
652
+ console.warn(`[instance] Could not load Nomad driver for cleanup:`, e.message);
653
+ });
654
+ }
655
+ // Async rm so the Node event loop stays responsive during large deletes:
656
+ // a fresh instance with a just-installed runtime package can be 1+ GB
657
+ // with hundreds of nested dirs, which takes 30-60s to unlink on SD storage.
658
+ // rmSync would block every other HTTP request for that whole window.
659
+ let dirDeleted = false;
660
+ try {
661
+ await rmAsync(d, { recursive: true, force: true });
662
+ dirDeleted = true;
663
+ }
664
+ catch {
665
+ try {
666
+ execFileSync("sudo", ["rm", "-rf", d], { timeout: 300000 });
667
+ dirDeleted = true;
668
+ }
669
+ catch (e) {
670
+ warnings.push(`Failed to delete instance directory: ${e.message}`);
671
+ }
672
+ }
673
+ // Integration-home orphan warnings are emitted by integration hooks.
674
+ // Handle backups (stored in separate directory, not affected by the
675
+ // instance rm above). Backups can be hundreds of MB each and accumulate
676
+ // across retention windows, so use the same async rm path to keep the
677
+ // event loop responsive.
678
+ const backupDir = join(BACKUPS_DIR, instanceId);
679
+ if (purgeBackups && existsSync(backupDir)) {
680
+ try {
681
+ await rmAsync(backupDir, { recursive: true, force: true });
682
+ }
683
+ catch (e) {
684
+ warnings.push(`Failed to delete backups: ${e.message}`);
685
+ }
686
+ }
687
+ else if (existsSync(backupDir)) {
688
+ warnings.push(`Backups preserved at ${backupDir}`);
689
+ }
690
+ return { ok: dirDeleted, warnings: warnings.length ? warnings : undefined };
691
+ }
692
+ // ── Native config dispatch wrappers ─────────────────────────────────
693
+ // Integrations own the implementation (`getNativeConfig` / `getStoredNativeConfig`
694
+ // / `saveNativeConfig`); these helpers preserve the synchronous public API
695
+ // shape for existing call sites (llm-proxy, routes, backup-manager).
696
+ function runtimeIntegrationKind(meta) {
697
+ if (!meta)
698
+ return null;
699
+ const instanceId = typeof meta.id === "string" && meta.id.trim()
700
+ ? meta.id.trim()
701
+ : typeof meta.instanceId === "string" && meta.instanceId.trim()
702
+ ? meta.instanceId.trim()
703
+ : "<unknown>";
704
+ const owner = resolveExecutionOwnerFromMetadata(instanceId, meta);
705
+ return owner.type === "integration" ? owner.integrationKind : null;
706
+ }
707
+ function getRuntimeIntegrationEntry(meta) {
708
+ const integrationKind = runtimeIntegrationKind(meta);
709
+ if (!integrationKind)
710
+ return null;
711
+ return { kind: integrationKind, integration: getIntegration(integrationKind) };
712
+ }
713
+ export function getConfig(instanceId) {
714
+ const meta = getInstance(instanceId);
715
+ const entry = getRuntimeIntegrationEntry(meta);
716
+ if (!entry)
717
+ return null;
718
+ const integration = entry.integration;
719
+ return typeof integration.getNativeConfig === "function"
720
+ ? integration.getNativeConfig(instanceId)
721
+ : null;
722
+ }
723
+ export function getStoredConfig(instanceId) {
724
+ const meta = getInstance(instanceId);
725
+ const entry = getRuntimeIntegrationEntry(meta);
726
+ if (!entry)
727
+ return null;
728
+ const integration = entry.integration;
729
+ return typeof integration.getStoredNativeConfig === "function"
730
+ ? integration.getStoredNativeConfig(instanceId)
731
+ : null;
732
+ }
733
+ export async function saveConfig(instanceId, config) {
734
+ const meta = getInstance(instanceId);
735
+ const entry = getRuntimeIntegrationEntry(meta);
736
+ if (!entry)
737
+ return false;
738
+ try {
739
+ const integration = entry.integration;
740
+ if (typeof integration.saveNativeConfig !== "function")
741
+ return false;
742
+ // Integrations may return boolean or Promise<boolean>. Awaiting a plain
743
+ // boolean is a no-op, so this handles both. Previously we stripped the
744
+ // Promise and always reported success for async integrations — that masked
745
+ // failures and left callers unable to detect dirty state.
746
+ const result = await integration.saveNativeConfig(instanceId, config);
747
+ return typeof result === "boolean" ? result : true;
748
+ }
749
+ catch (e) {
750
+ console.warn(`[instance-manager] saveConfig dispatch failed for ${instanceId}: ${e.message}`);
751
+ return false;
752
+ }
753
+ }
754
+ // ── Integration-native helper dispatch wrappers ──────────────────────
755
+ // Each helper resolves the app integration for the instance and forwards
756
+ // to the corresponding integration method. Kept here so existing callers
757
+ // (routes, plugin-installer, app service re-exports, tests) stay
758
+ // integration-agnostic.
759
+ /** Dispatch wrapper for `AppIntegration.isChannelPluginInstalled`. */
760
+ export function isChannelPluginInstalled(instanceId, channelId) {
761
+ try {
762
+ const meta = getInstance(instanceId);
763
+ const entry = getRuntimeIntegrationEntry(meta);
764
+ if (!entry)
765
+ return false;
766
+ const integration = entry.integration;
767
+ return typeof integration.isChannelPluginInstalled === "function"
768
+ ? integration.isChannelPluginInstalled(instanceId, channelId)
769
+ : false;
770
+ }
771
+ catch (error) {
772
+ if (isExecutionOwnerRequiredError(error))
773
+ throw error;
774
+ return false;
775
+ }
776
+ }
777
+ export function saveFeishuCredentials(instanceId, creds) {
778
+ const meta = getInstance(instanceId);
779
+ const entry = getRuntimeIntegrationEntry(meta);
780
+ if (!entry) {
781
+ throw new Error(`Instance '${instanceId}' is not backed by an app integration`);
782
+ }
783
+ const a = entry.integration;
784
+ if (typeof a.saveFeishuCredentials !== "function") {
785
+ throw new Error(`Integration "${entry.kind}" does not support Feishu credentials`);
786
+ }
787
+ a.saveFeishuCredentials(instanceId, creds);
788
+ }
789
+ export function saveWeixinCredentials(instanceId, creds) {
790
+ const meta = getInstance(instanceId);
791
+ const entry = getRuntimeIntegrationEntry(meta);
792
+ if (!entry) {
793
+ throw new Error(`Instance '${instanceId}' is not backed by an app integration`);
794
+ }
795
+ const a = entry.integration;
796
+ if (typeof a.saveWeixinCredentials !== "function") {
797
+ throw new Error(`Integration "${entry.kind}" does not support WeChat credentials`);
798
+ }
799
+ a.saveWeixinCredentials(instanceId, creds);
800
+ }
801
+ export function getWeixinAccounts(instanceId) {
802
+ const meta = getInstance(instanceId);
803
+ try {
804
+ const entry = getRuntimeIntegrationEntry(meta);
805
+ if (!entry)
806
+ return [];
807
+ const a = entry.integration;
808
+ return typeof a.getWeixinAccounts === "function"
809
+ ? a.getWeixinAccounts(instanceId)
810
+ : [];
811
+ }
812
+ catch (error) {
813
+ if (isExecutionOwnerRequiredError(error))
814
+ throw error;
815
+ return [];
816
+ }
817
+ }
818
+ export function getInstanceRuntime(instanceId) {
819
+ const meta = getInstance(instanceId);
820
+ if (!meta)
821
+ return {};
822
+ return structuredClone(meta.runtime || {});
823
+ }
824
+ export function getRuntimeEnvFiles(instanceId) {
825
+ const runtime = getInstanceRuntime(instanceId);
826
+ const rawEnvFiles = Array.isArray(runtime.env_files)
827
+ ? runtime.env_files
828
+ : Array.isArray(runtime.envFiles)
829
+ ? runtime.envFiles
830
+ : [];
831
+ const envFiles = rawEnvFiles.map((p) => normalizePath(p)).filter(Boolean);
832
+ return envFiles.length ? envFiles : [defaultModelEnvFile(instanceId)];
833
+ }
834
+ export function getPrimaryHostPort(instanceId) {
835
+ return requireCanonicalPrimaryHostPort(instanceId, getInstanceRuntime(instanceId));
836
+ }
837
+ /**
838
+ * Detect the host address where a published app port is actually listening.
839
+ *
840
+ * Strategy by driver:
841
+ * - raw_exec (Linux/Pi): use `ss` to read the listening address directly.
842
+ * - docker (macOS/bridge): Nomad publishes the port on the Nomad client's
843
+ * interface IP (e.g. 10.x.x.x), NOT 127.0.0.1. Query the Nomad allocation
844
+ * for `AllocatedResources.Shared.Ports[].HostIP`.
845
+ *
846
+ * Result is cached for 30 s to avoid an API call on every proxy request.
847
+ */
848
+ const _gwHostCache = new Map();
849
+ const GW_HOST_CACHE_TTL = 30000;
850
+ const _listeningHostCache = new Map();
851
+ const LISTENING_HOST_CACHE_TTL = 30000;
852
+ export function getListeningHostForPort(port) {
853
+ const cached = _listeningHostCache.get(port);
854
+ if (cached && Date.now() - cached.ts < LISTENING_HOST_CACHE_TTL)
855
+ return cached.host;
856
+ // Linux: ss is universal and parses cleanly. macOS/BSD ships lsof but
857
+ // not ss, so without this fallback execFileSync throws ENOENT, the
858
+ // catch block silently returns 127.0.0.1, and any caller that fans
859
+ // out to the wrong host fails (the capability HTTP proxy in
860
+ // `proxyProvidedCapability`, the gateway-host fallback for raw_exec
861
+ // instances, etc.). On macOS docker driver mode the actual published
862
+ // host can be e.g. 10.188.0.21 via `host_network = "external"`, never
863
+ // loopback — so silently picking 127.0.0.1 leaves the panel fetching
864
+ // a host nothing is listening on.
865
+ const safe = safePort(port);
866
+ const fromSs = () => {
867
+ const hosts = [];
868
+ try {
869
+ const out = execFileSync("ss", ["-tlnH", "sport", "=", ":" + safe], {
870
+ encoding: "utf-8",
871
+ timeout: 3000,
872
+ stdio: ["pipe", "pipe", "pipe"],
873
+ });
874
+ for (const line of out.split("\n")) {
875
+ let match = line.match(/\s([\d.]+):(\d+)\s/);
876
+ if (!match)
877
+ match = line.match(/\s\[([0-9a-fA-F:]+)\]:(\d+)\s/);
878
+ if (match && match[2] === String(port))
879
+ hosts.push(match[1]);
880
+ }
881
+ }
882
+ catch { /* ss not available or no match */ }
883
+ return hosts;
884
+ };
885
+ const fromLsof = () => {
886
+ const hosts = [];
887
+ try {
888
+ // `-FnP` keeps numeric output (no name resolution, no /etc/services).
889
+ // Lines beginning with `n` carry the bind address: e.g. `n10.188.0.21:8080`,
890
+ // `n127.0.0.1:8080`, `n[::1]:8080`, or `n*:8080` for wildcard binds.
891
+ const out = execFileSync("lsof", ["-nP", "-iTCP:" + safe, "-sTCP:LISTEN", "-FnP"], {
892
+ encoding: "utf-8",
893
+ timeout: 3000,
894
+ stdio: ["pipe", "pipe", "pipe"],
895
+ });
896
+ for (const line of out.split("\n")) {
897
+ if (!line.startsWith("n"))
898
+ continue;
899
+ const body = line.slice(1);
900
+ // IPv6 form: [::1]:8080 → strip brackets
901
+ const v6 = body.match(/^\[([0-9a-fA-F:]+)\]:(\d+)$/);
902
+ if (v6 && v6[2] === String(port)) {
903
+ hosts.push(v6[1]);
904
+ continue;
905
+ }
906
+ const idx = body.lastIndexOf(":");
907
+ if (idx <= 0)
908
+ continue;
909
+ const addr = body.slice(0, idx);
910
+ const portPart = body.slice(idx + 1);
911
+ if (portPart === String(port))
912
+ hosts.push(addr === "*" ? "0.0.0.0" : addr);
913
+ }
914
+ }
915
+ catch { /* lsof unavailable or no match */ }
916
+ return hosts;
917
+ };
918
+ let detected = [];
919
+ if (process.platform === "linux") {
920
+ detected = fromSs();
921
+ if (detected.length === 0)
922
+ detected = fromLsof();
923
+ }
924
+ else {
925
+ detected = fromLsof();
926
+ if (detected.length === 0)
927
+ detected = fromSs();
928
+ }
929
+ const unique = [...new Set(detected)];
930
+ const host = unique.length === 0 ? "127.0.0.1" : unique[0] === "0.0.0.0" ? "127.0.0.1" : unique[0];
931
+ _listeningHostCache.set(port, { host, ts: Date.now() });
932
+ return host;
933
+ }
934
+ function getExclusiveLoopbackListenerForPort(port) {
935
+ const safe = safePort(port);
936
+ const hosts = new Set();
937
+ try {
938
+ const out = execFileSync("lsof", ["-nP", "-iTCP:" + safe, "-sTCP:LISTEN", "-FnP"], {
939
+ encoding: "utf-8",
940
+ timeout: 3000,
941
+ stdio: ["pipe", "pipe", "pipe"],
942
+ });
943
+ for (const line of out.split("\n")) {
944
+ if (!line.startsWith("n"))
945
+ continue;
946
+ const body = line.slice(1);
947
+ if (body === `127.0.0.1:${safe}`) {
948
+ hosts.add("127.0.0.1");
949
+ continue;
950
+ }
951
+ if (body === `[::1]:${safe}`) {
952
+ hosts.add("::1");
953
+ continue;
954
+ }
955
+ if (!body.endsWith(`:${safe}`))
956
+ continue;
957
+ const addr = body.startsWith("[")
958
+ ? body.slice(1, body.lastIndexOf("]"))
959
+ : body.slice(0, body.lastIndexOf(":"));
960
+ hosts.add(addr === "*" ? "0.0.0.0" : addr);
961
+ }
962
+ }
963
+ catch { /* lsof unavailable or no match */ }
964
+ try {
965
+ const out = execFileSync("ss", ["-tlnH", "sport", "=", ":" + safe], {
966
+ encoding: "utf-8",
967
+ timeout: 3000,
968
+ stdio: ["pipe", "pipe", "pipe"],
969
+ });
970
+ for (const line of out.split("\n")) {
971
+ const ipv4 = line.match(/\s([\d.]+):(\d+)\s/);
972
+ if (ipv4 && ipv4[2] === String(safe))
973
+ hosts.add(ipv4[1]);
974
+ const ipv6 = line.match(/\s\[([0-9a-fA-F:]+)\]:(\d+)\s/);
975
+ if (ipv6 && ipv6[2] === String(safe))
976
+ hosts.add(ipv6[1]);
977
+ }
978
+ }
979
+ catch { /* ss unavailable or no match */ }
980
+ if (hosts.size === 0)
981
+ return null;
982
+ let hasIpv4Loopback = false;
983
+ let hasIpv6Loopback = false;
984
+ for (const host of hosts) {
985
+ if (host === "127.0.0.1") {
986
+ hasIpv4Loopback = true;
987
+ continue;
988
+ }
989
+ if (host === "::1") {
990
+ hasIpv6Loopback = true;
991
+ continue;
992
+ }
993
+ if (host === "0.0.0.0" || host === "::")
994
+ return null;
995
+ return null;
996
+ }
997
+ if (hasIpv4Loopback)
998
+ return "127.0.0.1";
999
+ if (hasIpv6Loopback)
1000
+ return "::1";
1001
+ return null;
1002
+ }
1003
+ export function getPrimaryIpv4Address() {
1004
+ try {
1005
+ for (const list of Object.values(networkInterfaces())) {
1006
+ for (const iface of list ?? []) {
1007
+ if (!iface.internal && iface.family === "IPv4")
1008
+ return iface.address;
1009
+ }
1010
+ }
1011
+ }
1012
+ catch { /* fall through */ }
1013
+ return "127.0.0.1";
1014
+ }
1015
+ export function getAdvertisedHostForPort(port) {
1016
+ const host = getListeningHostForPort(port);
1017
+ if (host && host !== "127.0.0.1" && host !== "0.0.0.0" && host !== "::1" && host !== "::") {
1018
+ return host;
1019
+ }
1020
+ return getPrimaryIpv4Address();
1021
+ }
1022
+ export function getConnectHostForPort(port) {
1023
+ const host = getListeningHostForPort(port);
1024
+ if (!host || host === "0.0.0.0" || host === "::")
1025
+ return "127.0.0.1";
1026
+ return host;
1027
+ }
1028
+ export async function getPrimaryHostForInstance(instanceId) {
1029
+ const cached = _gwHostCache.get(instanceId);
1030
+ if (cached && Date.now() - cached.ts < GW_HOST_CACHE_TTL)
1031
+ return cached.host;
1032
+ const port = getPrimaryHostPort(instanceId);
1033
+ let result = "127.0.0.1";
1034
+ try {
1035
+ const { getNomadDriver } = await import("../../config.js");
1036
+ if (getNomadDriver() === "docker") {
1037
+ const { getNomadAddr, getNomadToken } = await import("../../config.js");
1038
+ // Dispatch job-id construction through the integration so every runtime
1039
+ // owns its own Nomad job namespace (<kind>-<id>, bare app id, etc.).
1040
+ // Falls back to a generic `jishushell-` prefix only when the integration
1041
+ // lookup fails — that branch should never fire for a registered
1042
+ // agent type.
1043
+ const meta = getInstance(instanceId);
1044
+ let prefix = "jishushell-";
1045
+ try {
1046
+ const a = getRuntimeIntegrationEntry(meta)?.integration;
1047
+ if (a && typeof a.nomadJobPrefix === "string" && a.nomadJobPrefix.length) {
1048
+ prefix = a.nomadJobPrefix;
1049
+ }
1050
+ }
1051
+ catch (error) {
1052
+ if (isExecutionOwnerRequiredError(error))
1053
+ throw error;
1054
+ /* use fallback prefix for non-identity integration failures */
1055
+ }
1056
+ // Avoid double-prefix when the instance ID already carries the
1057
+ // integration prefix. Without this guard we'd double-prefix the id,
1058
+ // get 0 allocs, and fall back
1059
+ // to the 127.0.0.1 default — which silently breaks the gateway
1060
+ // proxy on docker driver where the real HostIP differs.
1061
+ const jid = instanceId.startsWith(prefix) ? instanceId : `${prefix}${instanceId}`;
1062
+ const headers = { "Content-Type": "application/json" };
1063
+ const token = getNomadToken();
1064
+ if (token)
1065
+ headers["X-Nomad-Token"] = token;
1066
+ const resp = await fetch(`${getNomadAddr()}/v1/job/${encodeURIComponent(jid)}/allocations`, {
1067
+ headers,
1068
+ signal: AbortSignal.timeout(5000),
1069
+ });
1070
+ if (resp.ok) {
1071
+ const allocs = await resp.json();
1072
+ const alloc = allocs.find((a) => a.ClientStatus === "running")
1073
+ ?? allocs.find((a) => a.ClientStatus === "pending");
1074
+ if (alloc) {
1075
+ const detail = await fetch(`${getNomadAddr()}/v1/allocation/${encodeURIComponent(alloc.ID)}`, { headers, signal: AbortSignal.timeout(5000) });
1076
+ if (detail.ok) {
1077
+ const d = await detail.json();
1078
+ // Preferred source: AllocatedResources.Shared.Ports (bridge mode).
1079
+ const sharedPorts = d?.AllocatedResources?.Shared?.Ports ?? [];
1080
+ const gwPort = sharedPorts.find((p) => p.Label === "gateway");
1081
+ if (gwPort?.HostIP && gwPort.HostIP !== "0.0.0.0") {
1082
+ result = gwPort.HostIP;
1083
+ }
1084
+ else {
1085
+ // Host mode / task-level reservation: address lives under
1086
+ // AllocatedResources.Tasks.<task>.Networks[*].IP. On Nomad
1087
+ // 1.6.5 with `network_interface = "lo"`, the IP is whichever
1088
+ // address the OS enumerates first — which can be IPv6 `::1`
1089
+ // on systems where lo has both `127.0.0.1/8` and `::1/128`
1090
+ // (the default on most modern Linux distros). Reading it from
1091
+ // here is the authoritative source and matches what nomad
1092
+ // configures the docker-proxy bind to use.
1093
+ //
1094
+ // Scan every task instead of indexing a hardcoded "gateway"
1095
+ // task — integrations are free to name the task whatever they
1096
+ // like, we only require the reserved port carry the
1097
+ // framework-level `gateway` label.
1098
+ const tasksMap = d?.AllocatedResources?.Tasks ?? {};
1099
+ for (const taskName of Object.keys(tasksMap)) {
1100
+ const taskNets = tasksMap[taskName]?.Networks ?? [];
1101
+ const net = taskNets.find((n) => {
1102
+ const rps = n?.ReservedPorts ?? [];
1103
+ return rps.some((p) => p.Label === "gateway");
1104
+ });
1105
+ if (net?.IP && net.IP !== "0.0.0.0") {
1106
+ result = net.IP;
1107
+ break;
1108
+ }
1109
+ }
1110
+ }
1111
+ }
1112
+ }
1113
+ }
1114
+ // If Nomad API resolved a non-default host, cache and return it
1115
+ if (result !== "127.0.0.1") {
1116
+ const localLoopbackHost = getExclusiveLoopbackListenerForPort(port);
1117
+ if (localLoopbackHost) {
1118
+ result = localLoopbackHost;
1119
+ }
1120
+ _gwHostCache.set(instanceId, { host: result, ts: Date.now() });
1121
+ return result;
1122
+ }
1123
+ // Otherwise fall through to ss-based detection
1124
+ }
1125
+ }
1126
+ catch { /* fall through */ }
1127
+ result = getListeningHostForPort(port);
1128
+ _gwHostCache.set(instanceId, { host: result, ts: Date.now() });
1129
+ return result;
1130
+ }
1131
+ const _appPortHostCache = new Map();
1132
+ const APP_PORT_HOST_CACHE_TTL = 30000;
1133
+ /**
1134
+ * Resolve the host IP for a specific port belonging to an app's Nomad job.
1135
+ *
1136
+ * On macOS with Colima + docker driver the container port is bound *inside*
1137
+ * the VM, not on the host. `ss` (or `netstat`) run on the macOS host see
1138
+ * nothing on that port, so `getListeningHostForPort` returns 127.0.0.1 and
1139
+ * the core proxy gets a 502.
1140
+ *
1141
+ * This function mirrors the logic of `getPrimaryHostForInstance` but matches by port
1142
+ * *value* rather than by the "gateway" label, making it suitable for
1143
+ * arbitrary capability ports exposed by app tasks.
1144
+ */
1145
+ export async function getHostForAppPort(instanceId, port) {
1146
+ const cacheKey = `${instanceId}:${port}`;
1147
+ const cached = _appPortHostCache.get(cacheKey);
1148
+ if (cached && Date.now() - cached.ts < APP_PORT_HOST_CACHE_TTL)
1149
+ return cached.host;
1150
+ let result = "127.0.0.1";
1151
+ try {
1152
+ const { getNomadDriver, getNomadAddr, getNomadToken } = await import("../../config.js");
1153
+ if (getNomadDriver() === "docker") {
1154
+ const headers = { "Content-Type": "application/json" };
1155
+ const token = getNomadToken();
1156
+ if (token)
1157
+ headers["X-Nomad-Token"] = token;
1158
+ const resp = await fetch(`${getNomadAddr()}/v1/job/${encodeURIComponent(instanceId)}/allocations`, { headers, signal: AbortSignal.timeout(5000) });
1159
+ if (resp.ok) {
1160
+ const allocs = await resp.json();
1161
+ const alloc = allocs.find((a) => a.ClientStatus === "running")
1162
+ ?? allocs.find((a) => a.ClientStatus === "pending");
1163
+ if (alloc) {
1164
+ const detail = await fetch(`${getNomadAddr()}/v1/allocation/${encodeURIComponent(alloc.ID)}`, { headers, signal: AbortSignal.timeout(5000) });
1165
+ if (detail.ok) {
1166
+ const d = await detail.json();
1167
+ // Bridge / host-network mode: ports listed under Shared.Ports
1168
+ const sharedPorts = d?.AllocatedResources?.Shared?.Ports ?? [];
1169
+ const matched = sharedPorts.find((p) => p.Value === port || p.To === port);
1170
+ if (matched?.HostIP && matched.HostIP !== "0.0.0.0") {
1171
+ result = matched.HostIP;
1172
+ }
1173
+ }
1174
+ }
1175
+ }
1176
+ }
1177
+ }
1178
+ catch { /* fall through to ss-based detection */ }
1179
+ if (result === "127.0.0.1") {
1180
+ result = getListeningHostForPort(port);
1181
+ }
1182
+ _appPortHostCache.set(cacheKey, { host: result, ts: Date.now() });
1183
+ return result;
1184
+ }
1185
+ /**
1186
+ * Wrap an IPv6 literal in brackets for safe URL host-component / Host-header
1187
+ * use. Bare names ("gateway.local") and IPv4 ("127.0.0.1") contain no colon
1188
+ * and pass through unchanged; anything with a colon is an IPv6 literal and
1189
+ * MUST be bracketed before being concatenated with a port, otherwise
1190
+ * `http://::1:18095/` is unparseable.
1191
+ */
1192
+ export function urlHost(host) {
1193
+ return host.includes(":") ? `[${host}]` : host;
1194
+ }
1195
+ export function findInstancesSharingIntegrationHome(instanceId) {
1196
+ const meta = getInstance(instanceId);
1197
+ try {
1198
+ const entry = getRuntimeIntegrationEntry(meta);
1199
+ if (!entry)
1200
+ return [];
1201
+ const a = entry.integration;
1202
+ return typeof a.findInstancesSharingHome === "function"
1203
+ ? a.findInstancesSharingHome(instanceId)
1204
+ : [];
1205
+ }
1206
+ catch (error) {
1207
+ if (isExecutionOwnerRequiredError(error))
1208
+ throw error;
1209
+ return [];
1210
+ }
1211
+ }
1212
+ /**
1213
+ * Re-pick the primary host port for an existing instance and rewrite only the
1214
+ * persisted host-side mapping in `runtime.ports[].hostPort`.
1215
+ *
1216
+ * Used when {@link isPortInUse} reports that the previously-assigned
1217
+ * `hostPort` has been taken by something else between create-time and
1218
+ * start-time (e.g. an unrelated service that grabbed the port at boot, or a
1219
+ * Docker race on the next allocation). The Nomad job spec is rebuilt from
1220
+ * instance metadata on every submit, so updating `instance.json` here is
1221
+ * sufficient — no other files need patching, and the in-container process
1222
+ * listener keeps the same `containerPort`.
1223
+ *
1224
+ * Lifecycle: this is the canonical Step 2 reserve / commit / release flow:
1225
+ * - `allocateHostPort(...)` reserves a candidate hostPort.
1226
+ * - On successful durable persist (`safeWriteJson` of `instance.json`),
1227
+ * `alloc.commit()` retires the reservation; durable ownership has taken
1228
+ * over via `runtime.ports[].hostPort`.
1229
+ * - On any thrown failure, `alloc.release()` frees the slot so concurrent
1230
+ * / retried reallocations can reuse the port.
1231
+ *
1232
+ * Domain note: this function intentionally only rewrites `hostPort`.
1233
+ * Integration-specific `reallocateRuntimePort` implementations and the
1234
+ * generic AppSpec fallback must both preserve the workload's
1235
+ * `containerPort`.
1236
+ *
1237
+ * Scope note: this is a primary-port helper for single-gateway integration
1238
+ * runtimes and legacy compatibility paths. Generic multi-port AppSpec
1239
+ * preflight must not use it as a full conflict check; it should iterate every
1240
+ * external `runtime.ports[]` entry and call `reallocateRuntimeHostPort(...)`
1241
+ * for the specific conflicting task/port.
1242
+ */
1243
+ export async function reallocatePrimaryHostPort(instanceId) {
1244
+ const meta = getInstance(instanceId);
1245
+ if (!meta)
1246
+ throw new Error(`Cannot reallocate port for unknown instance '${instanceId}'`);
1247
+ const entry = getRuntimeIntegrationEntry(meta);
1248
+ const fromPort = requireCanonicalPrimaryHostPort(instanceId, meta.runtime);
1249
+ const alloc = await allocateHostPort(instanceId, entry?.integration.preferredHostPort ?? fromPort, fromPort);
1250
+ let committed = false;
1251
+ try {
1252
+ const runtime = (meta.runtime ?? {});
1253
+ // Delegate kind-specific rewrites to integrations when present. Generic
1254
+ // AppSpec instances rewrite only the first externally visible
1255
+ // `runtime.ports[].hostPort`; never rewrite containerPort.
1256
+ if (typeof entry?.integration.reallocateRuntimePort === "function") {
1257
+ entry.integration.reallocateRuntimePort(runtime, alloc.port);
1258
+ }
1259
+ else if (Array.isArray(runtime.ports) && runtime.ports.length > 0) {
1260
+ let rewritten = false;
1261
+ runtime.ports = runtime.ports.map((port, index) => {
1262
+ if (!rewritten && ((port?.visibility ?? "external") !== "internal" || index === 0)) {
1263
+ rewritten = true;
1264
+ return { ...port, hostPort: alloc.port };
1265
+ }
1266
+ return port;
1267
+ });
1268
+ }
1269
+ else {
1270
+ throw new CanonicalRuntimePortRequiredError(instanceId);
1271
+ }
1272
+ updateInstanceMeta(instanceId, { runtime });
1273
+ // `instance.json` now durably owns the new hostPort; flip the
1274
+ // reservation from `reserve` to `commit` BEFORE follow-up I/O so any
1275
+ // later failure does not leak the reservation slot.
1276
+ alloc.commit();
1277
+ committed = true;
1278
+ console.log(`[instance] ${instanceId}: primary port reallocated ${fromPort} -> ${alloc.port}`);
1279
+ return { from: fromPort, to: alloc.port, skipped: alloc.skipped };
1280
+ }
1281
+ catch (error) {
1282
+ if (!committed)
1283
+ alloc.release();
1284
+ throw error;
1285
+ }
1286
+ }
1287
+ export async function reallocateRuntimeHostPort(instanceId, portRef) {
1288
+ const meta = getInstance(instanceId);
1289
+ if (!meta)
1290
+ throw new Error(`Cannot reallocate port for unknown instance '${instanceId}'`);
1291
+ const runtime = structuredClone((meta.runtime ?? {}));
1292
+ const ports = Array.isArray(runtime.ports) ? runtime.ports : [];
1293
+ const index = ports.findIndex((port) => port?.name === portRef.name
1294
+ && (portRef.taskName == null
1295
+ || port?.taskName === portRef.taskName));
1296
+ if (index < 0) {
1297
+ throw new CanonicalRuntimePortRequiredError(instanceId);
1298
+ }
1299
+ const fromPort = ports[index]?.hostPort;
1300
+ if (!Number.isInteger(fromPort) || fromPort <= 0) {
1301
+ throw new CanonicalRuntimePortRequiredError(instanceId);
1302
+ }
1303
+ const alloc = await allocateHostPort(instanceId, fromPort + 1, fromPort);
1304
+ let committed = false;
1305
+ try {
1306
+ runtime.ports = ports.map((port, portIndex) => portIndex === index ? { ...port, hostPort: alloc.port } : port);
1307
+ updateInstanceMeta(instanceId, { runtime });
1308
+ alloc.commit();
1309
+ committed = true;
1310
+ console.log(`[instance] ${instanceId}: runtime port ${portRef.taskName ? `${portRef.taskName}/` : ""}${portRef.name} ` +
1311
+ `reallocated ${fromPort} -> ${alloc.port}`);
1312
+ return { from: fromPort, to: alloc.port, skipped: alloc.skipped };
1313
+ }
1314
+ catch (error) {
1315
+ if (!committed)
1316
+ alloc.release();
1317
+ throw error;
1318
+ }
1319
+ }
1320
+ export function findInstancesSharingPrimaryHostPort(instanceId) {
1321
+ const targetPort = getPrimaryHostPort(instanceId);
1322
+ return listInstances()
1323
+ .filter((inst) => inst.id !== instanceId)
1324
+ .filter((inst) => extractPrimaryHostPort(inst.runtime) === targetPort)
1325
+ .map((inst) => inst.id);
1326
+ }
1327
+ export function getRuntimeEnv(instanceId) {
1328
+ const runtime = getInstanceRuntime(instanceId);
1329
+ const env = {};
1330
+ for (const envFile of getRuntimeEnvFiles(instanceId)) {
1331
+ Object.assign(env, parseEnvFile(envFile));
1332
+ }
1333
+ for (const [key, value] of Object.entries(runtime.env || {})) {
1334
+ if (value != null)
1335
+ env[key] = String(value);
1336
+ }
1337
+ return env;
1338
+ }
1339
+ // Re-export instanceDir for the Nomad driver under its getInstanceDir alias.
1340
+ export { instanceDir as getInstanceDir };
1341
+ // Integration config-path resolvers are owned by their integration modules.
1342
+ //# sourceMappingURL=manager.js.map