@andrew.ng/symbion 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (417) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/apps/daemon/dist/boot/menu.d.ts +11 -0
  4. package/apps/daemon/dist/boot/menu.d.ts.map +1 -0
  5. package/apps/daemon/dist/boot/menu.js +32 -0
  6. package/apps/daemon/dist/boot/menu.js.map +1 -0
  7. package/apps/daemon/dist/fs/folderPick.d.ts +13 -0
  8. package/apps/daemon/dist/fs/folderPick.d.ts.map +1 -0
  9. package/apps/daemon/dist/fs/folderPick.js +4 -0
  10. package/apps/daemon/dist/fs/folderPick.js.map +1 -0
  11. package/apps/daemon/dist/fs/listDir.d.ts +13 -0
  12. package/apps/daemon/dist/fs/listDir.d.ts.map +1 -0
  13. package/apps/daemon/dist/fs/listDir.js +121 -0
  14. package/apps/daemon/dist/fs/listDir.js.map +1 -0
  15. package/apps/daemon/dist/fs/readTargetFiles.d.ts +20 -0
  16. package/apps/daemon/dist/fs/readTargetFiles.d.ts.map +1 -0
  17. package/apps/daemon/dist/fs/readTargetFiles.js +76 -0
  18. package/apps/daemon/dist/fs/readTargetFiles.js.map +1 -0
  19. package/apps/daemon/dist/fs/writeFiles.d.ts +32 -0
  20. package/apps/daemon/dist/fs/writeFiles.d.ts.map +1 -0
  21. package/apps/daemon/dist/fs/writeFiles.js +93 -0
  22. package/apps/daemon/dist/fs/writeFiles.js.map +1 -0
  23. package/apps/daemon/dist/git/status.d.ts +11 -0
  24. package/apps/daemon/dist/git/status.d.ts.map +1 -0
  25. package/apps/daemon/dist/git/status.js +30 -0
  26. package/apps/daemon/dist/git/status.js.map +1 -0
  27. package/apps/daemon/dist/index.d.ts +2 -0
  28. package/apps/daemon/dist/index.d.ts.map +1 -0
  29. package/apps/daemon/dist/index.js +69 -0
  30. package/apps/daemon/dist/index.js.map +1 -0
  31. package/apps/daemon/dist/llm/anthropicProvider.d.ts +26 -0
  32. package/apps/daemon/dist/llm/anthropicProvider.d.ts.map +1 -0
  33. package/apps/daemon/dist/llm/anthropicProvider.js +90 -0
  34. package/apps/daemon/dist/llm/anthropicProvider.js.map +1 -0
  35. package/apps/daemon/dist/llm/geminiProvider.d.ts +25 -0
  36. package/apps/daemon/dist/llm/geminiProvider.d.ts.map +1 -0
  37. package/apps/daemon/dist/llm/geminiProvider.js +89 -0
  38. package/apps/daemon/dist/llm/geminiProvider.js.map +1 -0
  39. package/apps/daemon/dist/llm/installInstructions.d.ts +40 -0
  40. package/apps/daemon/dist/llm/installInstructions.d.ts.map +1 -0
  41. package/apps/daemon/dist/llm/installInstructions.js +80 -0
  42. package/apps/daemon/dist/llm/installInstructions.js.map +1 -0
  43. package/apps/daemon/dist/llm/ollamaProvider.d.ts +55 -0
  44. package/apps/daemon/dist/llm/ollamaProvider.d.ts.map +1 -0
  45. package/apps/daemon/dist/llm/ollamaProvider.js +213 -0
  46. package/apps/daemon/dist/llm/ollamaProvider.js.map +1 -0
  47. package/apps/daemon/dist/llm/openaiProvider.d.ts +25 -0
  48. package/apps/daemon/dist/llm/openaiProvider.d.ts.map +1 -0
  49. package/apps/daemon/dist/llm/openaiProvider.js +90 -0
  50. package/apps/daemon/dist/llm/openaiProvider.js.map +1 -0
  51. package/apps/daemon/dist/llm/providerStatus.d.ts +60 -0
  52. package/apps/daemon/dist/llm/providerStatus.d.ts.map +1 -0
  53. package/apps/daemon/dist/llm/providerStatus.js +88 -0
  54. package/apps/daemon/dist/llm/providerStatus.js.map +1 -0
  55. package/apps/daemon/dist/llm/registry.d.ts +14 -0
  56. package/apps/daemon/dist/llm/registry.d.ts.map +1 -0
  57. package/apps/daemon/dist/llm/registry.js +35 -0
  58. package/apps/daemon/dist/llm/registry.js.map +1 -0
  59. package/apps/daemon/dist/llm/remoteProvider.d.ts +25 -0
  60. package/apps/daemon/dist/llm/remoteProvider.d.ts.map +1 -0
  61. package/apps/daemon/dist/llm/remoteProvider.js +88 -0
  62. package/apps/daemon/dist/llm/remoteProvider.js.map +1 -0
  63. package/apps/daemon/dist/llm/secrets.d.ts +55 -0
  64. package/apps/daemon/dist/llm/secrets.d.ts.map +1 -0
  65. package/apps/daemon/dist/llm/secrets.js +167 -0
  66. package/apps/daemon/dist/llm/secrets.js.map +1 -0
  67. package/apps/daemon/dist/llm/types.d.ts +50 -0
  68. package/apps/daemon/dist/llm/types.d.ts.map +1 -0
  69. package/apps/daemon/dist/llm/types.js +16 -0
  70. package/apps/daemon/dist/llm/types.js.map +1 -0
  71. package/apps/daemon/dist/net/findOpenPort.d.ts +26 -0
  72. package/apps/daemon/dist/net/findOpenPort.d.ts.map +1 -0
  73. package/apps/daemon/dist/net/findOpenPort.js +37 -0
  74. package/apps/daemon/dist/net/findOpenPort.js.map +1 -0
  75. package/apps/daemon/dist/rpc/contract.d.ts +10 -0
  76. package/apps/daemon/dist/rpc/contract.d.ts.map +1 -0
  77. package/apps/daemon/dist/rpc/contract.js +2 -0
  78. package/apps/daemon/dist/rpc/contract.js.map +1 -0
  79. package/apps/daemon/dist/rpc/guard.d.ts +18 -0
  80. package/apps/daemon/dist/rpc/guard.d.ts.map +1 -0
  81. package/apps/daemon/dist/rpc/guard.js +75 -0
  82. package/apps/daemon/dist/rpc/guard.js.map +1 -0
  83. package/apps/daemon/dist/rpc/handlers.d.ts +118 -0
  84. package/apps/daemon/dist/rpc/handlers.d.ts.map +1 -0
  85. package/apps/daemon/dist/rpc/handlers.js +694 -0
  86. package/apps/daemon/dist/rpc/handlers.js.map +1 -0
  87. package/apps/daemon/dist/rpc/pathStyle.d.ts +27 -0
  88. package/apps/daemon/dist/rpc/pathStyle.d.ts.map +1 -0
  89. package/apps/daemon/dist/rpc/pathStyle.js +43 -0
  90. package/apps/daemon/dist/rpc/pathStyle.js.map +1 -0
  91. package/apps/daemon/dist/rpc/rpcError.d.ts +13 -0
  92. package/apps/daemon/dist/rpc/rpcError.d.ts.map +1 -0
  93. package/apps/daemon/dist/rpc/rpcError.js +16 -0
  94. package/apps/daemon/dist/rpc/rpcError.js.map +1 -0
  95. package/apps/daemon/dist/server.d.ts +18 -0
  96. package/apps/daemon/dist/server.d.ts.map +1 -0
  97. package/apps/daemon/dist/server.js +208 -0
  98. package/apps/daemon/dist/server.js.map +1 -0
  99. package/apps/daemon/dist/store/publishLog.d.ts +6 -0
  100. package/apps/daemon/dist/store/publishLog.d.ts.map +1 -0
  101. package/apps/daemon/dist/store/publishLog.js +27 -0
  102. package/apps/daemon/dist/store/publishLog.js.map +1 -0
  103. package/apps/daemon/dist/store/store.d.ts +35 -0
  104. package/apps/daemon/dist/store/store.d.ts.map +1 -0
  105. package/apps/daemon/dist/store/store.js +129 -0
  106. package/apps/daemon/dist/store/store.js.map +1 -0
  107. package/apps/daemon/dist/templates/githubFetch.d.ts +49 -0
  108. package/apps/daemon/dist/templates/githubFetch.d.ts.map +1 -0
  109. package/apps/daemon/dist/templates/githubFetch.js +168 -0
  110. package/apps/daemon/dist/templates/githubFetch.js.map +1 -0
  111. package/apps/web/out/404.html +1 -0
  112. package/apps/web/out/_next/static/IIw50lkv8jQuwHOBZJifS/_buildManifest.js +1 -0
  113. package/apps/web/out/_next/static/IIw50lkv8jQuwHOBZJifS/_ssgManifest.js +1 -0
  114. package/apps/web/out/_next/static/chunks/1dd3208c-6a745fea7bd2124a.js +1 -0
  115. package/apps/web/out/_next/static/chunks/426-deb95a16531d3b4b.js +25 -0
  116. package/apps/web/out/_next/static/chunks/528-6e64508688610bfe.js +2 -0
  117. package/apps/web/out/_next/static/chunks/656-fd1628581ad77b01.js +1 -0
  118. package/apps/web/out/_next/static/chunks/777-d587bc7cc0fc6be8.js +1 -0
  119. package/apps/web/out/_next/static/chunks/990-f2445c68c17fa077.js +1 -0
  120. package/apps/web/out/_next/static/chunks/app/_not-found/page-e0d77774c4eb9aef.js +1 -0
  121. package/apps/web/out/_next/static/chunks/app/layout-e5023aba6634ce53.js +1 -0
  122. package/apps/web/out/_next/static/chunks/app/page-a545c902535ac2e3.js +1 -0
  123. package/apps/web/out/_next/static/chunks/app/settings/page-a68ed4ae2ccb8840.js +1 -0
  124. package/apps/web/out/_next/static/chunks/app/templates/page-e5f0cefb905e5b72.js +1 -0
  125. package/apps/web/out/_next/static/chunks/baeaa4ff-28d2e32e4dd119b9.js +1 -0
  126. package/apps/web/out/_next/static/chunks/eb0351e1-329719bc902eaf71.js +1 -0
  127. package/apps/web/out/_next/static/chunks/framework-3664cab31236a9fa.js +1 -0
  128. package/apps/web/out/_next/static/chunks/main-app-d515c42ecb17b8e8.js +1 -0
  129. package/apps/web/out/_next/static/chunks/main-ff24788874d4ec1b.js +1 -0
  130. package/apps/web/out/_next/static/chunks/pages/_app-10a93ab5b7c32eb3.js +1 -0
  131. package/apps/web/out/_next/static/chunks/pages/_error-2d792b2a41857be4.js +1 -0
  132. package/apps/web/out/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  133. package/apps/web/out/_next/static/chunks/webpack-ae7ee8fe97fdceba.js +1 -0
  134. package/apps/web/out/_next/static/css/0a42edcfc2beb916.css +3 -0
  135. package/apps/web/out/_next/static/css/a275cc2b185e04f8.css +1 -0
  136. package/apps/web/out/_next/static/media/011e180705008d6f-s.woff2 +0 -0
  137. package/apps/web/out/_next/static/media/20535187d867b7b9-s.woff2 +0 -0
  138. package/apps/web/out/_next/static/media/26d4368bf94c0ec4-s.p.woff2 +0 -0
  139. package/apps/web/out/_next/static/media/2801417b65625cf5-s.woff2 +0 -0
  140. package/apps/web/out/_next/static/media/28793f5c5e3d822d-s.woff2 +0 -0
  141. package/apps/web/out/_next/static/media/5356a6a4f2c8c8d8-s.woff2 +0 -0
  142. package/apps/web/out/_next/static/media/58f386aa6b1a2a92-s.woff2 +0 -0
  143. package/apps/web/out/_next/static/media/73cb51aac9c97f90-s.woff2 +0 -0
  144. package/apps/web/out/_next/static/media/7b19b489dc6743ba-s.woff2 +0 -0
  145. package/apps/web/out/_next/static/media/7ba5fb2a8c88521c-s.woff2 +0 -0
  146. package/apps/web/out/_next/static/media/92eeb95d069020cc-s.woff2 +0 -0
  147. package/apps/web/out/_next/static/media/98e207f02528a563-s.p.woff2 +0 -0
  148. package/apps/web/out/_next/static/media/99dcf268bda04fe5-s.woff2 +0 -0
  149. package/apps/web/out/_next/static/media/b3bf17a9041d9433-s.woff2 +0 -0
  150. package/apps/web/out/_next/static/media/c9c3823090ec8b55-s.woff2 +0 -0
  151. package/apps/web/out/_next/static/media/d26bbd13d6b70f89-s.woff2 +0 -0
  152. package/apps/web/out/_next/static/media/d29838c109ef09b4-s.woff2 +0 -0
  153. package/apps/web/out/_next/static/media/d3ebbfd689654d3a-s.p.woff2 +0 -0
  154. package/apps/web/out/_next/static/media/db96af6b531dc71f-s.p.woff2 +0 -0
  155. package/apps/web/out/_next/static/media/e40af3453d7c920a-s.woff2 +0 -0
  156. package/apps/web/out/_next/static/media/ef4d5661765d0e49-s.woff2 +0 -0
  157. package/apps/web/out/index.html +1 -0
  158. package/apps/web/out/index.txt +6 -0
  159. package/apps/web/out/settings.html +1 -0
  160. package/apps/web/out/settings.txt +6 -0
  161. package/apps/web/out/templates.html +1 -0
  162. package/apps/web/out/templates.txt +6 -0
  163. package/bin/symbion.mjs +41 -0
  164. package/node_modules/@symbion/core/dist/adapters/claude.d.ts +3 -0
  165. package/node_modules/@symbion/core/dist/adapters/claude.d.ts.map +1 -0
  166. package/node_modules/@symbion/core/dist/adapters/claude.js +43 -0
  167. package/node_modules/@symbion/core/dist/adapters/claude.js.map +1 -0
  168. package/node_modules/@symbion/core/dist/adapters/codex.d.ts +3 -0
  169. package/node_modules/@symbion/core/dist/adapters/codex.d.ts.map +1 -0
  170. package/node_modules/@symbion/core/dist/adapters/codex.js +58 -0
  171. package/node_modules/@symbion/core/dist/adapters/codex.js.map +1 -0
  172. package/node_modules/@symbion/core/dist/adapters/registry.d.ts +5 -0
  173. package/node_modules/@symbion/core/dist/adapters/registry.d.ts.map +1 -0
  174. package/node_modules/@symbion/core/dist/adapters/registry.js +14 -0
  175. package/node_modules/@symbion/core/dist/adapters/registry.js.map +1 -0
  176. package/node_modules/@symbion/core/dist/adapters/types.d.ts +34 -0
  177. package/node_modules/@symbion/core/dist/adapters/types.d.ts.map +1 -0
  178. package/node_modules/@symbion/core/dist/adapters/types.js +2 -0
  179. package/node_modules/@symbion/core/dist/adapters/types.js.map +1 -0
  180. package/node_modules/@symbion/core/dist/diff/conflict.d.ts +19 -0
  181. package/node_modules/@symbion/core/dist/diff/conflict.d.ts.map +1 -0
  182. package/node_modules/@symbion/core/dist/diff/conflict.js +20 -0
  183. package/node_modules/@symbion/core/dist/diff/conflict.js.map +1 -0
  184. package/node_modules/@symbion/core/dist/diff/diff.d.ts +44 -0
  185. package/node_modules/@symbion/core/dist/diff/diff.d.ts.map +1 -0
  186. package/node_modules/@symbion/core/dist/diff/diff.js +124 -0
  187. package/node_modules/@symbion/core/dist/diff/diff.js.map +1 -0
  188. package/node_modules/@symbion/core/dist/generate/bodyPrompt.d.ts +27 -0
  189. package/node_modules/@symbion/core/dist/generate/bodyPrompt.d.ts.map +1 -0
  190. package/node_modules/@symbion/core/dist/generate/bodyPrompt.js +55 -0
  191. package/node_modules/@symbion/core/dist/generate/bodyPrompt.js.map +1 -0
  192. package/node_modules/@symbion/core/dist/generate/description.d.ts +18 -0
  193. package/node_modules/@symbion/core/dist/generate/description.d.ts.map +1 -0
  194. package/node_modules/@symbion/core/dist/generate/description.js +164 -0
  195. package/node_modules/@symbion/core/dist/generate/description.js.map +1 -0
  196. package/node_modules/@symbion/core/dist/index.d.ts +23 -0
  197. package/node_modules/@symbion/core/dist/index.d.ts.map +1 -0
  198. package/node_modules/@symbion/core/dist/index.js +24 -0
  199. package/node_modules/@symbion/core/dist/index.js.map +1 -0
  200. package/node_modules/@symbion/core/dist/ir/refs.d.ts +11 -0
  201. package/node_modules/@symbion/core/dist/ir/refs.d.ts.map +1 -0
  202. package/node_modules/@symbion/core/dist/ir/refs.js +25 -0
  203. package/node_modules/@symbion/core/dist/ir/refs.js.map +1 -0
  204. package/node_modules/@symbion/core/dist/ir/types.d.ts +107 -0
  205. package/node_modules/@symbion/core/dist/ir/types.d.ts.map +1 -0
  206. package/node_modules/@symbion/core/dist/ir/types.js +19 -0
  207. package/node_modules/@symbion/core/dist/ir/types.js.map +1 -0
  208. package/node_modules/@symbion/core/dist/ir/validate.d.ts +13 -0
  209. package/node_modules/@symbion/core/dist/ir/validate.d.ts.map +1 -0
  210. package/node_modules/@symbion/core/dist/ir/validate.js +114 -0
  211. package/node_modules/@symbion/core/dist/ir/validate.js.map +1 -0
  212. package/node_modules/@symbion/core/dist/parse/scan.d.ts +47 -0
  213. package/node_modules/@symbion/core/dist/parse/scan.d.ts.map +1 -0
  214. package/node_modules/@symbion/core/dist/parse/scan.js +109 -0
  215. package/node_modules/@symbion/core/dist/parse/scan.js.map +1 -0
  216. package/node_modules/@symbion/core/dist/render/frontmatter.d.ts +29 -0
  217. package/node_modules/@symbion/core/dist/render/frontmatter.d.ts.map +1 -0
  218. package/node_modules/@symbion/core/dist/render/frontmatter.js +99 -0
  219. package/node_modules/@symbion/core/dist/render/frontmatter.js.map +1 -0
  220. package/node_modules/@symbion/core/dist/render/marker.d.ts +30 -0
  221. package/node_modules/@symbion/core/dist/render/marker.d.ts.map +1 -0
  222. package/node_modules/@symbion/core/dist/render/marker.js +48 -0
  223. package/node_modules/@symbion/core/dist/render/marker.js.map +1 -0
  224. package/node_modules/@symbion/core/dist/render/render.d.ts +12 -0
  225. package/node_modules/@symbion/core/dist/render/render.d.ts.map +1 -0
  226. package/node_modules/@symbion/core/dist/render/render.js +10 -0
  227. package/node_modules/@symbion/core/dist/render/render.js.map +1 -0
  228. package/node_modules/@symbion/core/dist/runcommand/render.d.ts +13 -0
  229. package/node_modules/@symbion/core/dist/runcommand/render.d.ts.map +1 -0
  230. package/node_modules/@symbion/core/dist/runcommand/render.js +19 -0
  231. package/node_modules/@symbion/core/dist/runcommand/render.js.map +1 -0
  232. package/node_modules/@symbion/core/dist/templates/authorSource.d.ts +55 -0
  233. package/node_modules/@symbion/core/dist/templates/authorSource.d.ts.map +1 -0
  234. package/node_modules/@symbion/core/dist/templates/authorSource.js +24 -0
  235. package/node_modules/@symbion/core/dist/templates/authorSource.js.map +1 -0
  236. package/node_modules/@symbion/core/dist/templates/matchAuthorFolders.d.ts +28 -0
  237. package/node_modules/@symbion/core/dist/templates/matchAuthorFolders.d.ts.map +1 -0
  238. package/node_modules/@symbion/core/dist/templates/matchAuthorFolders.js +54 -0
  239. package/node_modules/@symbion/core/dist/templates/matchAuthorFolders.js.map +1 -0
  240. package/node_modules/@symbion/core/dist/templates/parseTemplate.d.ts +42 -0
  241. package/node_modules/@symbion/core/dist/templates/parseTemplate.d.ts.map +1 -0
  242. package/node_modules/@symbion/core/dist/templates/parseTemplate.js +56 -0
  243. package/node_modules/@symbion/core/dist/templates/parseTemplate.js.map +1 -0
  244. package/node_modules/@symbion/core/dist/templates/templateListItem.d.ts +39 -0
  245. package/node_modules/@symbion/core/dist/templates/templateListItem.d.ts.map +1 -0
  246. package/node_modules/@symbion/core/dist/templates/templateListItem.js +2 -0
  247. package/node_modules/@symbion/core/dist/templates/templateListItem.js.map +1 -0
  248. package/node_modules/@symbion/core/dist/util/sha256.d.ts +9 -0
  249. package/node_modules/@symbion/core/dist/util/sha256.d.ts.map +1 -0
  250. package/node_modules/@symbion/core/dist/util/sha256.js +91 -0
  251. package/node_modules/@symbion/core/dist/util/sha256.js.map +1 -0
  252. package/node_modules/@symbion/core/dist/version/semver.d.ts +18 -0
  253. package/node_modules/@symbion/core/dist/version/semver.d.ts.map +1 -0
  254. package/node_modules/@symbion/core/dist/version/semver.js +53 -0
  255. package/node_modules/@symbion/core/dist/version/semver.js.map +1 -0
  256. package/node_modules/@symbion/core/package.json +14 -0
  257. package/node_modules/@symbion/rpc-types/dist/index.d.ts +444 -0
  258. package/node_modules/@symbion/rpc-types/dist/index.d.ts.map +1 -0
  259. package/node_modules/@symbion/rpc-types/dist/index.js +2 -0
  260. package/node_modules/@symbion/rpc-types/dist/index.js.map +1 -0
  261. package/node_modules/@symbion/rpc-types/package.json +11 -0
  262. package/node_modules/yaml/dist/cli.d.ts +8 -0
  263. package/node_modules/yaml/dist/cli.mjs +201 -0
  264. package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
  265. package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
  266. package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
  267. package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
  268. package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
  269. package/node_modules/yaml/dist/compose/compose-node.js +112 -0
  270. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  271. package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
  272. package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
  273. package/node_modules/yaml/dist/compose/composer.js +224 -0
  274. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  275. package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
  276. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  277. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
  278. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  279. package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
  280. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  281. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  282. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  283. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
  284. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  285. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +227 -0
  286. package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
  287. package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
  288. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  289. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  290. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  291. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
  292. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  293. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  294. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  295. package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
  296. package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
  297. package/node_modules/yaml/dist/doc/Document.js +337 -0
  298. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  299. package/node_modules/yaml/dist/doc/anchors.js +76 -0
  300. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  301. package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
  302. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  303. package/node_modules/yaml/dist/doc/createNode.js +90 -0
  304. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  305. package/node_modules/yaml/dist/doc/directives.js +178 -0
  306. package/node_modules/yaml/dist/errors.d.ts +21 -0
  307. package/node_modules/yaml/dist/errors.js +62 -0
  308. package/node_modules/yaml/dist/index.d.ts +25 -0
  309. package/node_modules/yaml/dist/index.js +50 -0
  310. package/node_modules/yaml/dist/log.d.ts +3 -0
  311. package/node_modules/yaml/dist/log.js +19 -0
  312. package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
  313. package/node_modules/yaml/dist/nodes/Alias.js +118 -0
  314. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  315. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  316. package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
  317. package/node_modules/yaml/dist/nodes/Node.js +40 -0
  318. package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
  319. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  320. package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
  321. package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
  322. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  323. package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
  324. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  325. package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
  326. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  327. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
  328. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  329. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  330. package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
  331. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  332. package/node_modules/yaml/dist/options.d.ts +350 -0
  333. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  334. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  335. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  336. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  337. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  338. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  339. package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
  340. package/node_modules/yaml/dist/parse/cst.js +112 -0
  341. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  342. package/node_modules/yaml/dist/parse/lexer.js +723 -0
  343. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  344. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  345. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  346. package/node_modules/yaml/dist/parse/parser.js +980 -0
  347. package/node_modules/yaml/dist/public-api.d.ts +44 -0
  348. package/node_modules/yaml/dist/public-api.js +107 -0
  349. package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
  350. package/node_modules/yaml/dist/schema/Schema.js +39 -0
  351. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  352. package/node_modules/yaml/dist/schema/common/map.js +19 -0
  353. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  354. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  355. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  356. package/node_modules/yaml/dist/schema/common/seq.js +19 -0
  357. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  358. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  359. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  360. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  361. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  362. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  363. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  364. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  365. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  366. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  367. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  368. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  369. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  370. package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
  371. package/node_modules/yaml/dist/schema/tags.js +99 -0
  372. package/node_modules/yaml/dist/schema/types.d.ts +92 -0
  373. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  374. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
  375. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  376. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  377. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  378. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  379. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  380. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  381. package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  382. package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
  383. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
  384. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  385. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  386. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  387. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  388. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
  389. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  390. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
  391. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  392. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  393. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  394. package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
  395. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  396. package/node_modules/yaml/dist/stringify/stringify.js +132 -0
  397. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  398. package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
  399. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  400. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  401. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  402. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  403. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  404. package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
  405. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  406. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  407. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  408. package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
  409. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  410. package/node_modules/yaml/dist/test-events.js +134 -0
  411. package/node_modules/yaml/dist/util.d.ts +16 -0
  412. package/node_modules/yaml/dist/util.js +28 -0
  413. package/node_modules/yaml/dist/visit.d.ts +102 -0
  414. package/node_modules/yaml/dist/visit.js +236 -0
  415. package/node_modules/yaml/package.json +20 -0
  416. package/node_modules/yaml/util.js +2 -0
  417. package/package.json +39 -0
@@ -0,0 +1,88 @@
1
+ /**
2
+ * RemoteProvider — stub-grade in v1 per STATE §9 ("doesn't need a finished
3
+ * provider-switch UI" but the interface/seam must be real, not a TODO).
4
+ * Implements the same LlmProvider interface against Anthropic's Messages API
5
+ * shape, as a concrete placeholder for "some remote vendor."
6
+ *
7
+ * The API key is read EXCLUSIVELY from process.env.SYMBION_REMOTE_LLM_API_KEY
8
+ * at call time — never persisted to disk, never accepted as a request param,
9
+ * never read from apps/web. If unset, generate() throws LlmError("auth", ...)
10
+ * immediately, with NO network call attempted (TC-D7).
11
+ */
12
+ import { LlmError } from "./types.js";
13
+ export const REMOTE_API_KEY_ENV_VAR = "SYMBION_REMOTE_LLM_API_KEY";
14
+ const REMOTE_DEFAULT_BASE_URL = "https://api.anthropic.com/v1/messages";
15
+ const REMOTE_MODELS = [
16
+ { id: "claude-haiku-4-5", label: "Claude Haiku 4.5 (nhanh)", tier: "fast" },
17
+ { id: "claude-sonnet-4-5", label: "Claude Sonnet 4.5 (cân bằng)", tier: "balanced" },
18
+ { id: "claude-opus-4-1", label: "Claude Opus 4.1 (tốt nhất)", tier: "best" },
19
+ ];
20
+ export class RemoteProvider {
21
+ id = "remote";
22
+ baseUrl;
23
+ constructor(opts = {}) {
24
+ this.baseUrl = opts.baseUrl ?? REMOTE_DEFAULT_BASE_URL;
25
+ }
26
+ listModels() {
27
+ return REMOTE_MODELS;
28
+ }
29
+ async generate(req) {
30
+ const apiKey = process.env[REMOTE_API_KEY_ENV_VAR];
31
+ if (!apiKey) {
32
+ throw new LlmError("auth", "Thiếu hoặc sai cấu hình API key cho remote provider.");
33
+ }
34
+ const controller = new AbortController();
35
+ const timer = setTimeout(() => controller.abort(), req.timeoutMs);
36
+ try {
37
+ let res;
38
+ try {
39
+ res = await fetch(this.baseUrl, {
40
+ method: "POST",
41
+ headers: {
42
+ "Content-Type": "application/json",
43
+ "x-api-key": apiKey,
44
+ "anthropic-version": "2023-06-01",
45
+ },
46
+ body: JSON.stringify({
47
+ model: req.model,
48
+ system: req.systemPrompt,
49
+ max_tokens: 4096,
50
+ messages: [{ role: "user", content: req.userPrompt }],
51
+ }),
52
+ signal: controller.signal,
53
+ });
54
+ }
55
+ catch {
56
+ if (controller.signal.aborted) {
57
+ throw new LlmError("timeout", `Quá thời gian chờ (${req.timeoutMs}ms) khi gọi remote provider.`);
58
+ }
59
+ throw new LlmError("network", "Lỗi mạng khi gọi remote provider.");
60
+ }
61
+ if (res.status === 401 || res.status === 403) {
62
+ throw new LlmError("auth", "Thiếu hoặc sai cấu hình API key cho remote provider.");
63
+ }
64
+ if (res.status === 429) {
65
+ throw new LlmError("rate-limit", "Bị giới hạn tần suất gọi — thử lại sau.");
66
+ }
67
+ if (!res.ok) {
68
+ throw new LlmError("invalid-response", `Remote provider trả về lỗi HTTP ${res.status}.`);
69
+ }
70
+ let json;
71
+ try {
72
+ json = (await res.json());
73
+ }
74
+ catch {
75
+ throw new LlmError("invalid-response", "Phản hồi không hợp lệ từ remote provider (không phải JSON).");
76
+ }
77
+ const text = json.content?.[0]?.text;
78
+ if (typeof text !== "string") {
79
+ throw new LlmError("invalid-response", "Phản hồi không hợp lệ từ remote provider.");
80
+ }
81
+ return { text };
82
+ }
83
+ finally {
84
+ clearTimeout(timer);
85
+ }
86
+ }
87
+ }
88
+ //# sourceMappingURL=remoteProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA2C,CAAC;YACtE,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,QAAQ,CAAC,kBAAkB,EAAE,6DAA6D,CAAC,CAAC;YACxG,CAAC;YAED,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;YACrC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC7B,MAAM,IAAI,QAAQ,CAAC,kBAAkB,EAAE,2CAA2C,CAAC,CAAC;YACtF,CAAC;YAED,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,55 @@
1
+ export declare const CURRENT_PROVIDERS_SCHEMA_VERSION: 1;
2
+ export type ApiKeyProviderId = "openai" | "anthropic" | "gemini";
3
+ export type ProviderId = "ollama" | ApiKeyProviderId;
4
+ export interface ProvidersConfig {
5
+ schemaVersion: 1;
6
+ /** null = no active provider selected yet (fresh install / all keys cleared). */
7
+ activeProviderId: ProviderId | null;
8
+ providers: Partial<Record<ApiKeyProviderId, {
9
+ apiKey: string;
10
+ model: string;
11
+ }>>;
12
+ }
13
+ declare const DEFAULT_PROVIDERS_CONFIG: ProvidersConfig;
14
+ export declare function providersConfigPath(): string;
15
+ /**
16
+ * loadProvidersConfig — read + parse + validate. Fail-soft contract per
17
+ * STATE §3.3: missing file, corrupt JSON, missing/wrong schemaVersion, or a
18
+ * future (greater than current) schemaVersion ALL resolve to the default
19
+ * empty config — NEVER throws, NEVER crashes the daemon. Does NOT eagerly
20
+ * create the file on a missing-file read (deliberate departure from
21
+ * loadGlobalConfig()'s eager-write behavior — see STATE §3.3 rationale).
22
+ */
23
+ export declare function loadProvidersConfig(): ProvidersConfig;
24
+ /**
25
+ * saveProvidersConfig — atomic temp->rename write (reuses store.ts's exact
26
+ * primitive), with 0o600 file permissions (owner read/write only).
27
+ */
28
+ export declare function saveProvidersConfig(config: ProvidersConfig): void;
29
+ export declare class ProviderNotConfiguredError extends Error {
30
+ constructor(providerId: string);
31
+ }
32
+ /** setProviderKey — upserts one provider's entry. Never logs `apiKey`. */
33
+ export declare function setProviderKey(providerId: ApiKeyProviderId, apiKey: string, model: string): ProvidersConfig;
34
+ /**
35
+ * clearProviderKey — removes one provider's stored key/model. If it was
36
+ * active, resets activeProviderId to null (NOT a fallback to ollama — STATE
37
+ * §5's explicit "no automatic fallback" rule extends here).
38
+ */
39
+ export declare function clearProviderKey(providerId: ApiKeyProviderId): ProvidersConfig;
40
+ /**
41
+ * setActiveProvider — validates the provider has a stored key (or is
42
+ * "ollama", which needs none) before accepting; throws
43
+ * ProviderNotConfiguredError otherwise (surfaced as RPC invalid-params by the
44
+ * handler, not a silent no-op).
45
+ */
46
+ export declare function setActiveProvider(providerId: ProviderId): ProvidersConfig;
47
+ /**
48
+ * maskKey — "sk-...ab12" style masking (last 4 chars only, fixed prefix
49
+ * ellipsis). The ONLY function permitted to touch a raw key for display.
50
+ * Never throws; never returns the raw string unmasked, even for very short
51
+ * inputs (TC-S7).
52
+ */
53
+ export declare function maskKey(apiKey: string): string;
54
+ export { DEFAULT_PROVIDERS_CONFIG };
55
+ //# sourceMappingURL=secrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/llm/secrets.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,gCAAgC,EAAG,CAAU,CAAC;AAE3D,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AACjE,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,gBAAgB,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,CAAC,CAAC;IACjB,iFAAiF;IACjF,gBAAgB,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CACjF;AAED,QAAA,MAAM,wBAAwB,EAAE,eAI/B,CAAC;AAOF,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAYD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,eAAe,CA+DrD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAEjE;AAED,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,UAAU,EAAE,MAAM;CAI/B;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAK3G;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,gBAAgB,GAAG,eAAe,CAQ9E;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe,CAQzE;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAM9C;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
@@ -0,0 +1,167 @@
1
+ /**
2
+ * secrets.ts — owns the on-disk `providers.json` file (API keys + active
3
+ * provider selection) under the user-level config dir, per
4
+ * docs/loops/multi-provider-settings-STATE.md §3.2/§3.3.
5
+ *
6
+ * Daemon-only. Never imported by packages/core or apps/web. Plaintext-at-rest
7
+ * is the locked v1 decision (flagged to /cso, see STATE §9) — this module
8
+ * adds only an OS file-permission guard (0o600) on top of that, no encryption.
9
+ *
10
+ * `maskKey()` is the ONLY function in this codebase permitted to touch a raw
11
+ * key for display purposes — every RPC result shape must pass keys through
12
+ * it before crossing into JSON (handlers.ts never serializes a raw apiKey).
13
+ */
14
+ import { existsSync, readFileSync } from "node:fs";
15
+ import { join } from "node:path";
16
+ import { globalConfigDir, atomicWriteJson } from "../store/store.js";
17
+ export const CURRENT_PROVIDERS_SCHEMA_VERSION = 1;
18
+ const DEFAULT_PROVIDERS_CONFIG = {
19
+ schemaVersion: CURRENT_PROVIDERS_SCHEMA_VERSION,
20
+ activeProviderId: null,
21
+ providers: {},
22
+ };
23
+ function defaultConfig() {
24
+ // Fresh object each call — callers mutate the returned config freely.
25
+ return { schemaVersion: CURRENT_PROVIDERS_SCHEMA_VERSION, activeProviderId: null, providers: {} };
26
+ }
27
+ export function providersConfigPath() {
28
+ return join(globalConfigDir(), "providers.json");
29
+ }
30
+ const API_KEY_PROVIDER_IDS = new Set(["openai", "anthropic", "gemini"]);
31
+ function isApiKeyProviderId(id) {
32
+ return API_KEY_PROVIDER_IDS.has(id);
33
+ }
34
+ function isValidProviderId(id) {
35
+ return typeof id === "string" && (id === "ollama" || isApiKeyProviderId(id));
36
+ }
37
+ /**
38
+ * loadProvidersConfig — read + parse + validate. Fail-soft contract per
39
+ * STATE §3.3: missing file, corrupt JSON, missing/wrong schemaVersion, or a
40
+ * future (greater than current) schemaVersion ALL resolve to the default
41
+ * empty config — NEVER throws, NEVER crashes the daemon. Does NOT eagerly
42
+ * create the file on a missing-file read (deliberate departure from
43
+ * loadGlobalConfig()'s eager-write behavior — see STATE §3.3 rationale).
44
+ */
45
+ export function loadProvidersConfig() {
46
+ const absPath = providersConfigPath();
47
+ if (!existsSync(absPath)) {
48
+ return defaultConfig();
49
+ }
50
+ let rawText;
51
+ try {
52
+ rawText = readFileSync(absPath, "utf-8");
53
+ }
54
+ catch (err) {
55
+ console.warn(`[symbion] providers.json không thể đọc được, dùng cấu hình rỗng mặc định: ${err.message}`);
56
+ return defaultConfig();
57
+ }
58
+ let raw;
59
+ try {
60
+ raw = JSON.parse(rawText);
61
+ }
62
+ catch {
63
+ console.warn("[symbion] providers.json chứa JSON không hợp lệ — dùng cấu hình rỗng mặc định.");
64
+ return defaultConfig();
65
+ }
66
+ if (typeof raw !== "object" || raw === null) {
67
+ console.warn("[symbion] providers.json có cấu trúc không hợp lệ — dùng cấu hình rỗng mặc định.");
68
+ return defaultConfig();
69
+ }
70
+ const record = raw;
71
+ const schemaVersion = record["schemaVersion"];
72
+ if (typeof schemaVersion !== "number") {
73
+ console.warn("[symbion] providers.json thiếu schemaVersion — dùng cấu hình rỗng mặc định.");
74
+ return defaultConfig();
75
+ }
76
+ if (schemaVersion > CURRENT_PROVIDERS_SCHEMA_VERSION) {
77
+ // Distinguishable warning from the "corrupt" cases above, per STATE §3.3 case 4 —
78
+ // written by a future Symbion version; refuse to silently downgrade-interpret it.
79
+ console.warn(`[symbion] providers.json có schemaVersion=${schemaVersion} (mới hơn phiên bản hiện tại) — dùng cấu hình rỗng mặc định.`);
80
+ return defaultConfig();
81
+ }
82
+ const activeProviderIdRaw = record["activeProviderId"];
83
+ const activeProviderId = activeProviderIdRaw === null
84
+ ? null
85
+ : isValidProviderId(activeProviderIdRaw)
86
+ ? activeProviderIdRaw
87
+ : null;
88
+ const providersRaw = record["providers"];
89
+ const providers = {};
90
+ if (typeof providersRaw === "object" && providersRaw !== null) {
91
+ for (const [id, value] of Object.entries(providersRaw)) {
92
+ if (!isApiKeyProviderId(id))
93
+ continue;
94
+ if (typeof value !== "object" || value === null)
95
+ continue;
96
+ const entry = value;
97
+ if (typeof entry["apiKey"] !== "string" || typeof entry["model"] !== "string")
98
+ continue;
99
+ providers[id] = { apiKey: entry["apiKey"], model: entry["model"] };
100
+ }
101
+ }
102
+ return { schemaVersion: CURRENT_PROVIDERS_SCHEMA_VERSION, activeProviderId, providers };
103
+ }
104
+ /**
105
+ * saveProvidersConfig — atomic temp->rename write (reuses store.ts's exact
106
+ * primitive), with 0o600 file permissions (owner read/write only).
107
+ */
108
+ export function saveProvidersConfig(config) {
109
+ atomicWriteJson(providersConfigPath(), config, { mode: 0o600, dirMode: 0o700 });
110
+ }
111
+ export class ProviderNotConfiguredError extends Error {
112
+ constructor(providerId) {
113
+ super(`Chưa cấu hình API key cho nhà cung cấp này: ${providerId}`);
114
+ this.name = "ProviderNotConfiguredError";
115
+ }
116
+ }
117
+ /** setProviderKey — upserts one provider's entry. Never logs `apiKey`. */
118
+ export function setProviderKey(providerId, apiKey, model) {
119
+ const config = loadProvidersConfig();
120
+ config.providers[providerId] = { apiKey, model };
121
+ saveProvidersConfig(config);
122
+ return config;
123
+ }
124
+ /**
125
+ * clearProviderKey — removes one provider's stored key/model. If it was
126
+ * active, resets activeProviderId to null (NOT a fallback to ollama — STATE
127
+ * §5's explicit "no automatic fallback" rule extends here).
128
+ */
129
+ export function clearProviderKey(providerId) {
130
+ const config = loadProvidersConfig();
131
+ delete config.providers[providerId];
132
+ if (config.activeProviderId === providerId) {
133
+ config.activeProviderId = null;
134
+ }
135
+ saveProvidersConfig(config);
136
+ return config;
137
+ }
138
+ /**
139
+ * setActiveProvider — validates the provider has a stored key (or is
140
+ * "ollama", which needs none) before accepting; throws
141
+ * ProviderNotConfiguredError otherwise (surfaced as RPC invalid-params by the
142
+ * handler, not a silent no-op).
143
+ */
144
+ export function setActiveProvider(providerId) {
145
+ const config = loadProvidersConfig();
146
+ if (providerId !== "ollama" && !config.providers[providerId]) {
147
+ throw new ProviderNotConfiguredError(providerId);
148
+ }
149
+ config.activeProviderId = providerId;
150
+ saveProvidersConfig(config);
151
+ return config;
152
+ }
153
+ /**
154
+ * maskKey — "sk-...ab12" style masking (last 4 chars only, fixed prefix
155
+ * ellipsis). The ONLY function permitted to touch a raw key for display.
156
+ * Never throws; never returns the raw string unmasked, even for very short
157
+ * inputs (TC-S7).
158
+ */
159
+ export function maskKey(apiKey) {
160
+ if (apiKey.length <= 4) {
161
+ return "*".repeat(apiKey.length);
162
+ }
163
+ const last4 = apiKey.slice(-4);
164
+ return `...${last4}`;
165
+ }
166
+ export { DEFAULT_PROVIDERS_CONFIG };
167
+ //# sourceMappingURL=secrets.js.map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AC,CAAC,CAAC;IAC/B,OAAO,MAAM,KAAK,EAAE,CAAC;AACvB,CAAC;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * LlmProvider — the seam every model-inference call in apps/daemon goes through.
3
+ * No fs/network code lives in packages/core; this interface and its concrete
4
+ * adapters (ollamaProvider.ts, anthropicProvider.ts, openaiProvider.ts,
5
+ * geminiProvider.ts) are daemon-only, per docs/loops/auto-generate-body-STATE.md
6
+ * §10.1 and widened per docs/loops/multi-provider-settings-STATE.md §3.2.
7
+ */
8
+ export interface LlmGenerateRequest {
9
+ systemPrompt: string;
10
+ userPrompt: string;
11
+ /** provider-specific model id. */
12
+ model: string;
13
+ /** budget for the whole request, enforced via AbortController (not setTimeout-only). */
14
+ timeoutMs: number;
15
+ /** caps output tokens when set — used by status-check pings to bound cost; omitted means provider default. */
16
+ maxTokens?: number;
17
+ }
18
+ export interface LlmGenerateResult {
19
+ text: string;
20
+ }
21
+ export type LlmErrorCode = "timeout" | "network" | "auth" | "rate-limit" | "invalid-response" | "provider-not-running"
22
+ /** active provider has no key/never configured — distinct from "auth" (key present but
23
+ * rejected by the provider). New in docs/loops/multi-provider-settings-STATE.md §3.2. */
24
+ | "not-configured" | "unknown";
25
+ export declare class LlmError extends Error {
26
+ code: LlmErrorCode;
27
+ constructor(code: LlmErrorCode, message: string);
28
+ }
29
+ export interface LlmModelOption {
30
+ id: string;
31
+ label: string;
32
+ /** Optional — per docs/loops/ollama-dynamic-models-STATE.md §6.3, dynamically-discovered
33
+ * Ollama models with no confidently-parseable parameter-count hint in their tag name have
34
+ * no tier (honest "unknown" rather than a guessed default). The 3 cloud providers' static
35
+ * entries always set this. */
36
+ tier?: "fast" | "balanced" | "best";
37
+ }
38
+ export interface LlmProvider {
39
+ id: "ollama" | "openai" | "anthropic" | "gemini";
40
+ /**
41
+ * Static/hardcoded for the 3 cloud providers (openai/anthropic/gemini) — per STATE §9 of
42
+ * multi-provider-settings-STATE.md, unchanged. For Ollama, this now performs a real
43
+ * `GET /api/tags` network call against the local Ollama instance (per
44
+ * docs/loops/ollama-dynamic-models-STATE.md §6.1/§6.2) — async for ALL 4 providers so the
45
+ * interface has one shape, no special-casing by provider id at any call site.
46
+ */
47
+ listModels(): Promise<LlmModelOption[]>;
48
+ generate(req: LlmGenerateRequest): Promise<LlmGenerateResult>;
49
+ }
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/llm/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,SAAS,EAAE,MAAM,CAAC;IAClB,8GAA8G;IAC9G,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,SAAS,GACT,MAAM,GACN,YAAY,GACZ,kBAAkB,GAClB,sBAAsB;AACxB;0FAC0F;GACxF,gBAAgB,GAChB,SAAS,CAAC;AAEd,qBAAa,QAAS,SAAQ,KAAK;IACjC,IAAI,EAAE,YAAY,CAAC;gBACP,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM;CAKhD;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd;;;mCAG+B;IAC/B,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;IACjD;;;;;;OAMG;IACH,UAAU,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACxC,QAAQ,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC/D"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * LlmProvider — the seam every model-inference call in apps/daemon goes through.
3
+ * No fs/network code lives in packages/core; this interface and its concrete
4
+ * adapters (ollamaProvider.ts, anthropicProvider.ts, openaiProvider.ts,
5
+ * geminiProvider.ts) are daemon-only, per docs/loops/auto-generate-body-STATE.md
6
+ * §10.1 and widened per docs/loops/multi-provider-settings-STATE.md §3.2.
7
+ */
8
+ export class LlmError extends Error {
9
+ code;
10
+ constructor(code, message) {
11
+ super(message);
12
+ this.code = code;
13
+ this.name = "LlmError";
14
+ }
15
+ }
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/llm/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6BH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,IAAI,CAAe;IACnB,YAAY,IAAkB,EAAE,OAAe;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * findOpenPort — E15 port-scan retry. Extracted as a standalone, named,
3
+ * exported function with an injectable `tryBind` so it's unit-testable
4
+ * without binding real sockets (the default `tryBind` does bind a real
5
+ * socket via `startServer`/an http server in production call sites).
6
+ */
7
+ export interface FindOpenPortOptions {
8
+ /** max number of ports to try (inclusive of the start port) before giving up. */
9
+ maxAttempts?: number;
10
+ }
11
+ /** Error code Node uses for "address already in use". */
12
+ export declare const EADDRINUSE = "EADDRINUSE";
13
+ /**
14
+ * Scans forward from `startPort`, calling `tryBind(port)` for each candidate.
15
+ * `tryBind` should attempt to bind/listen and resolve with the bound handle,
16
+ * or reject with an error carrying `.code === "EADDRINUSE"` if the port is
17
+ * taken (any other rejection is rethrown immediately — not retried).
18
+ *
19
+ * Returns `{ port, handle }` for the first port that successfully binds.
20
+ * Throws if no open port is found within `maxAttempts`.
21
+ */
22
+ export declare function findOpenPort<T>(startPort: number, tryBind: (port: number) => Promise<T>, options?: FindOpenPortOptions): Promise<{
23
+ port: number;
24
+ handle: T;
25
+ }>;
26
+ //# sourceMappingURL=findOpenPort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOpenPort.d.ts","sourceRoot":"","sources":["../../src/net/findOpenPort.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,mBAAmB;IAClC,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,yDAAyD;AACzD,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACrC,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAmBtC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * findOpenPort — E15 port-scan retry. Extracted as a standalone, named,
3
+ * exported function with an injectable `tryBind` so it's unit-testable
4
+ * without binding real sockets (the default `tryBind` does bind a real
5
+ * socket via `startServer`/an http server in production call sites).
6
+ */
7
+ /** Error code Node uses for "address already in use". */
8
+ export const EADDRINUSE = "EADDRINUSE";
9
+ /**
10
+ * Scans forward from `startPort`, calling `tryBind(port)` for each candidate.
11
+ * `tryBind` should attempt to bind/listen and resolve with the bound handle,
12
+ * or reject with an error carrying `.code === "EADDRINUSE"` if the port is
13
+ * taken (any other rejection is rethrown immediately — not retried).
14
+ *
15
+ * Returns `{ port, handle }` for the first port that successfully binds.
16
+ * Throws if no open port is found within `maxAttempts`.
17
+ */
18
+ export async function findOpenPort(startPort, tryBind, options = {}) {
19
+ const maxAttempts = options.maxAttempts ?? 20;
20
+ let port = startPort;
21
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
22
+ try {
23
+ const handle = await tryBind(port);
24
+ return { port, handle };
25
+ }
26
+ catch (err) {
27
+ const code = err?.code;
28
+ if (code === EADDRINUSE) {
29
+ port += 1;
30
+ continue;
31
+ }
32
+ throw err;
33
+ }
34
+ }
35
+ throw new Error(`Không tìm được cổng trống bắt đầu từ ${startPort} (đã thử ${maxAttempts} cổng).`);
36
+ }
37
+ //# sourceMappingURL=findOpenPort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findOpenPort.js","sourceRoot":"","sources":["../../src/net/findOpenPort.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,yDAAyD;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,SAAiB,EACjB,OAAqC,EACrC,UAA+B,EAAE;IAEjC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;IAC9C,IAAI,IAAI,GAAG,SAAS,CAAC;IAErB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;YACnC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC1B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,GAAI,GAAyC,EAAE,IAAI,CAAC;YAC9D,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;gBACxB,IAAI,IAAI,CAAC,CAAC;gBACV,SAAS;YACX,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,SAAS,YAAY,WAAW,SAAS,CAAC,CAAC;AACrG,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shared RPC request/response types — the contract between apps/daemon and apps/web.
3
+ * The actual shapes live in the type-only `@symbion/rpc-types` package so both
4
+ * the daemon (Node) and the web client (browser bundle) consume the exact
5
+ * same definitions with no hand-mirroring / drift risk. This file just
6
+ * re-exports them for daemon-local call sites that import from
7
+ * "./contract" (or "../rpc/contract").
8
+ */
9
+ export type { PingParams, PingResult, BrowseFolderParams, BrowseFolderResult, ValidatePathParams, ValidatePathResult, ListDirParams, ListDirEntry, ListDirResult, MakeDirParams, MakeDirResult, ListProjectsParams, ListProjectsResult, CreateProjectParams, CreateProjectResult, LoadProjectParams, LoadProjectResult, SaveArtifactParams, SaveArtifactResult, DeleteArtifactParams, DeleteArtifactResult, UpdateSettingsParams, UpdateSettingsResult, ScanClaudeDirParams, ScanClaudeDirResult, ImportArtifactsParams, ImportArtifactsResult, ApplyTemplateParams, ApplyTemplateResult, FetchAuthorTemplatesParams, FetchAuthorTemplatesResult, FetchAuthorTemplatesOutcome, RenderParams, RenderResult, ComputeDiffParams, ComputeDiffResult, WriteFileSelection, WriteParams, WriteResult, GitStatusParams, GitStatusResult, RenderRunCommandParams, RenderRunCommandResult, LlmModelOption, ListModelsParams, ListModelsResult, ListModelsOutcome, GenerateBodyParams, GenerateBodyResult, HostEnvironment, InstallInstructions, CheckProviderStatusParams, CheckProviderStatusResult, ProviderId, LlmErrorCode, ProviderDescriptor, ListProvidersParams, ListProvidersResult, SaveProviderKeyParams, SaveProviderKeyResult, ClearProviderKeyParams, ClearProviderKeyResult, SetActiveProviderParams, SetActiveProviderResult, RpcMethod, RpcRequest, RpcErrorBody, } from "@symbion/rpc-types";
10
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/rpc/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,YAAY,EACV,UAAU,EACV,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC3B,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,SAAS,EACT,UAAU,EACV,YAAY,GACb,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/rpc/contract.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ export declare class PathConfinementError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ /**
5
+ * resolveConfinedPath — the filesystem analogue of "no DELETE without WHERE".
6
+ * Resolves `relPath` against `projectRoot` and guarantees the result stays
7
+ * inside the project root. Rejects:
8
+ * - `..` traversal that escapes the root
9
+ * - absolute paths (relPath must be relative)
10
+ * - symlinks whose real target resolves outside the root (checked on the
11
+ * deepest EXISTING ancestor directory, since the leaf file may not exist yet)
12
+ *
13
+ * Throws PathConfinementError on any violation. Never returns a path outside root.
14
+ */
15
+ export declare function resolveConfinedPath(projectRoot: string, relPath: string): string;
16
+ /** Defense-in-depth: ensure a candidate relPath does not contain raw `..` segments at all. */
17
+ export declare function rejectTraversalSegments(relPath: string): void;
18
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/rpc/guard.ts"],"names":[],"mappings":"AAIA,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAoDhF;AAED,8FAA8F;AAC9F,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAK7D"}
@@ -0,0 +1,75 @@
1
+ import { realpathSync, existsSync } from "node:fs";
2
+ import { dirname, isAbsolute, normalize, relative, resolve } from "node:path";
3
+ import { isWindowsStyleAbsolute } from "./pathStyle.js";
4
+ export class PathConfinementError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "PathConfinementError";
8
+ }
9
+ }
10
+ /**
11
+ * resolveConfinedPath — the filesystem analogue of "no DELETE without WHERE".
12
+ * Resolves `relPath` against `projectRoot` and guarantees the result stays
13
+ * inside the project root. Rejects:
14
+ * - `..` traversal that escapes the root
15
+ * - absolute paths (relPath must be relative)
16
+ * - symlinks whose real target resolves outside the root (checked on the
17
+ * deepest EXISTING ancestor directory, since the leaf file may not exist yet)
18
+ *
19
+ * Throws PathConfinementError on any violation. Never returns a path outside root.
20
+ */
21
+ export function resolveConfinedPath(projectRoot, relPath) {
22
+ // Closes the Windows-style-traversal gap unconditionally for every caller,
23
+ // regardless of whether that caller also remembers to call
24
+ // rejectTraversalSegments separately.
25
+ rejectTraversalSegments(relPath);
26
+ if (isAbsolute(relPath) || isWindowsStyleAbsolute(relPath)) {
27
+ throw new PathConfinementError(`Đường dẫn tuyệt đối không được phép: ${relPath}`);
28
+ }
29
+ const root = resolve(projectRoot);
30
+ const candidate = resolve(root, relPath);
31
+ const normalizedCandidate = normalize(candidate);
32
+ // Must resolve to a location inside root (or equal to root, which we disallow for files).
33
+ const rel = relative(root, normalizedCandidate);
34
+ if (rel.startsWith("..") || isAbsolute(rel)) {
35
+ throw new PathConfinementError(`Đường dẫn vượt ra ngoài project root: ${relPath}`);
36
+ }
37
+ if (rel === "") {
38
+ throw new PathConfinementError(`Đường dẫn không hợp lệ (trỏ vào chính project root): ${relPath}`);
39
+ }
40
+ // Symlink-escape check: walk up from the deepest existing ancestor directory and
41
+ // verify its realpath is still inside root's realpath. Catches the case where an
42
+ // intermediate directory is a symlink pointing outside the project.
43
+ let realRoot;
44
+ try {
45
+ realRoot = realpathSync(root);
46
+ }
47
+ catch {
48
+ // project root itself doesn't exist (shouldn't normally happen) — fail closed.
49
+ throw new PathConfinementError(`Project root không tồn tại: ${root}`);
50
+ }
51
+ let probe = dirname(normalizedCandidate);
52
+ while (probe !== root && probe.length >= root.length) {
53
+ if (existsSync(probe)) {
54
+ const realProbe = realpathSync(probe);
55
+ const relReal = relative(realRoot, realProbe);
56
+ if (relReal.startsWith("..") || isAbsolute(relReal)) {
57
+ throw new PathConfinementError(`Symlink trỏ ra ngoài project root: ${relPath}`);
58
+ }
59
+ break;
60
+ }
61
+ const parent = dirname(probe);
62
+ if (parent === probe)
63
+ break;
64
+ probe = parent;
65
+ }
66
+ return normalizedCandidate;
67
+ }
68
+ /** Defense-in-depth: ensure a candidate relPath does not contain raw `..` segments at all. */
69
+ export function rejectTraversalSegments(relPath) {
70
+ const segments = relPath.split(/[\\/]/);
71
+ if (segments.includes("..")) {
72
+ throw new PathConfinementError(`Đường dẫn chứa ".." không được phép: ${relPath}`);
73
+ }
74
+ }
75
+ //# sourceMappingURL=guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/rpc/guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAmB,EAAE,OAAe;IACtE,2EAA2E;IAC3E,2DAA2D;IAC3D,sCAAsC;IACtC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAEjC,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,oBAAoB,CAAC,wCAAwC,OAAO,EAAE,CAAC,CAAC;IACpF,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,MAAM,mBAAmB,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;IAEjD,0FAA0F;IAC1F,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAChD,IA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