@superblocksteam/vite-plugin-file-sync 2.0.123-next.0 → 2.0.124-next.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 (271) hide show
  1. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts +16 -1
  2. package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
  3. package/dist/ai-service/agent/prompts/build-base-system-prompt.js +27 -1
  4. package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
  5. package/dist/ai-service/agent/prompts/build-security-scan-prompt.d.ts.map +1 -1
  6. package/dist/ai-service/agent/prompts/build-security-scan-prompt.js +3 -1
  7. package/dist/ai-service/agent/prompts/build-security-scan-prompt.js.map +1 -1
  8. package/dist/ai-service/agent/tools/apis/api-comparator.d.ts.map +1 -1
  9. package/dist/ai-service/agent/tools/apis/api-comparator.js +1 -4
  10. package/dist/ai-service/agent/tools/apis/api-comparator.js.map +1 -1
  11. package/dist/ai-service/agent/tools/apis/api-testing-state.js +7 -0
  12. package/dist/ai-service/agent/tools/apis/api-testing-state.js.map +1 -1
  13. package/dist/ai-service/agent/tools/apis/get-api-docs.d.ts +1 -1
  14. package/dist/ai-service/agent/tools/apis/write-api.d.ts +2 -2
  15. package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts.map +1 -1
  16. package/dist/ai-service/agent/tools/build-capture-screenshot.js +11 -33
  17. package/dist/ai-service/agent/tools/build-capture-screenshot.js.map +1 -1
  18. package/dist/ai-service/agent/tools/build-copy-directory.d.ts +1 -1
  19. package/dist/ai-service/agent/tools/build-finalize.d.ts.map +1 -1
  20. package/dist/ai-service/agent/tools/build-finalize.js +11 -2
  21. package/dist/ai-service/agent/tools/build-finalize.js.map +1 -1
  22. package/dist/ai-service/agent/tools/build-install-packages.d.ts +41 -1
  23. package/dist/ai-service/agent/tools/build-install-packages.d.ts.map +1 -1
  24. package/dist/ai-service/agent/tools/build-install-packages.js +208 -0
  25. package/dist/ai-service/agent/tools/build-install-packages.js.map +1 -1
  26. package/dist/ai-service/agent/tools/build-lookup-npm-package.d.ts +28 -0
  27. package/dist/ai-service/agent/tools/build-lookup-npm-package.d.ts.map +1 -0
  28. package/dist/ai-service/agent/tools/build-lookup-npm-package.js +78 -0
  29. package/dist/ai-service/agent/tools/build-lookup-npm-package.js.map +1 -0
  30. package/dist/ai-service/agent/tools/build-manage-checklist.d.ts +4 -4
  31. package/dist/ai-service/agent/tools/build-navigate-preview.d.ts +16 -0
  32. package/dist/ai-service/agent/tools/build-navigate-preview.d.ts.map +1 -0
  33. package/dist/ai-service/agent/tools/build-navigate-preview.js +68 -0
  34. package/dist/ai-service/agent/tools/build-navigate-preview.js.map +1 -0
  35. package/dist/ai-service/agent/tools/build-write-file.d.ts +1 -1
  36. package/dist/ai-service/agent/tools/databases/dev-database.d.ts +9 -9
  37. package/dist/ai-service/agent/tools/index.d.ts +2 -0
  38. package/dist/ai-service/agent/tools/index.d.ts.map +1 -1
  39. package/dist/ai-service/agent/tools/index.js +2 -0
  40. package/dist/ai-service/agent/tools/index.js.map +1 -1
  41. package/dist/ai-service/agent/tools/integrations/execute-request.d.ts +3 -3
  42. package/dist/ai-service/agent/tools/report-security-findings.d.ts +11 -5
  43. package/dist/ai-service/agent/tools/report-security-findings.d.ts.map +1 -1
  44. package/dist/ai-service/agent/tools/report-security-findings.js +1 -0
  45. package/dist/ai-service/agent/tools/report-security-findings.js.map +1 -1
  46. package/dist/ai-service/agent/tools.d.ts.map +1 -1
  47. package/dist/ai-service/agent/tools.js +3 -1
  48. package/dist/ai-service/agent/tools.js.map +1 -1
  49. package/dist/ai-service/agent/tools2/tools/git.d.ts +2 -2
  50. package/dist/ai-service/agent/tools2/tools/grep.d.ts +2 -2
  51. package/dist/ai-service/agent/tools2/tools/update-test-case-status.d.ts +2 -2
  52. package/dist/ai-service/app-interface/npm-error-parser.d.ts +161 -0
  53. package/dist/ai-service/app-interface/npm-error-parser.d.ts.map +1 -0
  54. package/dist/ai-service/app-interface/npm-error-parser.js +510 -0
  55. package/dist/ai-service/app-interface/npm-error-parser.js.map +1 -0
  56. package/dist/ai-service/app-interface/npm-package-lookup.d.ts +286 -0
  57. package/dist/ai-service/app-interface/npm-package-lookup.d.ts.map +1 -0
  58. package/dist/ai-service/app-interface/npm-package-lookup.js +793 -0
  59. package/dist/ai-service/app-interface/npm-package-lookup.js.map +1 -0
  60. package/dist/ai-service/app-interface/npm-registry.d.ts +735 -47
  61. package/dist/ai-service/app-interface/npm-registry.d.ts.map +1 -1
  62. package/dist/ai-service/app-interface/npm-registry.js +1882 -153
  63. package/dist/ai-service/app-interface/npm-registry.js.map +1 -1
  64. package/dist/ai-service/app-interface/shell.d.ts +118 -1
  65. package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
  66. package/dist/ai-service/app-interface/shell.js +579 -157
  67. package/dist/ai-service/app-interface/shell.js.map +1 -1
  68. package/dist/ai-service/app-skills/manager.d.ts +1 -1
  69. package/dist/ai-service/app-skills/manager.d.ts.map +1 -1
  70. package/dist/ai-service/app-skills/manager.js +39 -7
  71. package/dist/ai-service/app-skills/manager.js.map +1 -1
  72. package/dist/ai-service/checklist/api-migration-checklist-gate.d.ts +9 -0
  73. package/dist/ai-service/checklist/api-migration-checklist-gate.d.ts.map +1 -0
  74. package/dist/ai-service/checklist/api-migration-checklist-gate.js +30 -0
  75. package/dist/ai-service/checklist/api-migration-checklist-gate.js.map +1 -0
  76. package/dist/ai-service/checklist/api-migration-origins.d.ts +4 -0
  77. package/dist/ai-service/checklist/api-migration-origins.d.ts.map +1 -0
  78. package/dist/ai-service/checklist/api-migration-origins.js +8 -0
  79. package/dist/ai-service/checklist/api-migration-origins.js.map +1 -0
  80. package/dist/ai-service/checklist/persisted-checklist-store.d.ts +2 -3
  81. package/dist/ai-service/checklist/persisted-checklist-store.d.ts.map +1 -1
  82. package/dist/ai-service/checklist/persisted-checklist-store.js +6 -7
  83. package/dist/ai-service/checklist/persisted-checklist-store.js.map +1 -1
  84. package/dist/ai-service/context-archive-paths.d.ts +4 -0
  85. package/dist/ai-service/context-archive-paths.d.ts.map +1 -0
  86. package/dist/ai-service/context-archive-paths.js +28 -0
  87. package/dist/ai-service/context-archive-paths.js.map +1 -0
  88. package/dist/ai-service/context-download.d.ts +3 -1
  89. package/dist/ai-service/context-download.d.ts.map +1 -1
  90. package/dist/ai-service/context-download.js +48 -9
  91. package/dist/ai-service/context-download.js.map +1 -1
  92. package/dist/ai-service/context-upload.d.ts +3 -2
  93. package/dist/ai-service/context-upload.d.ts.map +1 -1
  94. package/dist/ai-service/context-upload.js +44 -26
  95. package/dist/ai-service/context-upload.js.map +1 -1
  96. package/dist/ai-service/dev-database-client.d.ts +3 -11
  97. package/dist/ai-service/dev-database-client.d.ts.map +1 -1
  98. package/dist/ai-service/dev-database-client.js.map +1 -1
  99. package/dist/ai-service/features.d.ts +4 -0
  100. package/dist/ai-service/features.d.ts.map +1 -1
  101. package/dist/ai-service/features.js +8 -0
  102. package/dist/ai-service/features.js.map +1 -1
  103. package/dist/ai-service/filter-disabled-tools-for-migration.d.ts.map +1 -1
  104. package/dist/ai-service/filter-disabled-tools-for-migration.js +4 -0
  105. package/dist/ai-service/filter-disabled-tools-for-migration.js.map +1 -1
  106. package/dist/ai-service/index.d.ts +94 -0
  107. package/dist/ai-service/index.d.ts.map +1 -1
  108. package/dist/ai-service/index.js +564 -17
  109. package/dist/ai-service/index.js.map +1 -1
  110. package/dist/ai-service/llm/client.d.ts +38 -3
  111. package/dist/ai-service/llm/client.d.ts.map +1 -1
  112. package/dist/ai-service/llm/client.js +73 -22
  113. package/dist/ai-service/llm/client.js.map +1 -1
  114. package/dist/ai-service/llm/context-v2/adapter.d.ts +3 -1
  115. package/dist/ai-service/llm/context-v2/adapter.d.ts.map +1 -1
  116. package/dist/ai-service/llm/context-v2/adapter.js +11 -11
  117. package/dist/ai-service/llm/context-v2/adapter.js.map +1 -1
  118. package/dist/ai-service/llm/context-v2/compaction/client-side.d.ts +44 -0
  119. package/dist/ai-service/llm/context-v2/compaction/client-side.d.ts.map +1 -0
  120. package/dist/ai-service/llm/context-v2/compaction/client-side.js +170 -0
  121. package/dist/ai-service/llm/context-v2/compaction/client-side.js.map +1 -0
  122. package/dist/ai-service/llm/context-v2/compaction/compaction-strategy.d.ts +56 -0
  123. package/dist/ai-service/llm/context-v2/compaction/compaction-strategy.d.ts.map +1 -0
  124. package/dist/ai-service/llm/context-v2/compaction/compaction-strategy.js +9 -0
  125. package/dist/ai-service/llm/context-v2/compaction/compaction-strategy.js.map +1 -0
  126. package/dist/ai-service/llm/context-v2/compaction/index.d.ts +5 -0
  127. package/dist/ai-service/llm/context-v2/compaction/index.d.ts.map +1 -0
  128. package/dist/ai-service/llm/context-v2/compaction/index.js +3 -0
  129. package/dist/ai-service/llm/context-v2/compaction/index.js.map +1 -0
  130. package/dist/ai-service/llm/context-v2/compaction/server-side.d.ts +30 -0
  131. package/dist/ai-service/llm/context-v2/compaction/server-side.d.ts.map +1 -0
  132. package/dist/ai-service/llm/context-v2/compaction/server-side.js +130 -0
  133. package/dist/ai-service/llm/context-v2/compaction/server-side.js.map +1 -0
  134. package/dist/ai-service/llm/context-v2/context-management.d.ts +203 -0
  135. package/dist/ai-service/llm/context-v2/context-management.d.ts.map +1 -0
  136. package/dist/ai-service/llm/context-v2/context-management.js +183 -0
  137. package/dist/ai-service/llm/context-v2/context-management.js.map +1 -0
  138. package/dist/ai-service/llm/context-v2/context.d.ts +64 -22
  139. package/dist/ai-service/llm/context-v2/context.d.ts.map +1 -1
  140. package/dist/ai-service/llm/context-v2/context.js +233 -157
  141. package/dist/ai-service/llm/context-v2/context.js.map +1 -1
  142. package/dist/ai-service/llm/context-v2/conversation-context.d.ts +24 -7
  143. package/dist/ai-service/llm/context-v2/conversation-context.d.ts.map +1 -1
  144. package/dist/ai-service/llm/context-v2/conversation-context.js +1 -1
  145. package/dist/ai-service/llm/context-v2/index.d.ts +0 -4
  146. package/dist/ai-service/llm/context-v2/index.d.ts.map +1 -1
  147. package/dist/ai-service/llm/context-v2/index.js +0 -4
  148. package/dist/ai-service/llm/context-v2/index.js.map +1 -1
  149. package/dist/ai-service/llm/context-v2/manager.d.ts +24 -3
  150. package/dist/ai-service/llm/context-v2/manager.d.ts.map +1 -1
  151. package/dist/ai-service/llm/context-v2/manager.js +146 -4
  152. package/dist/ai-service/llm/context-v2/manager.js.map +1 -1
  153. package/dist/ai-service/llm/context-v2/migrations/v1-to-v2.d.ts +2 -7
  154. package/dist/ai-service/llm/context-v2/migrations/v1-to-v2.d.ts.map +1 -1
  155. package/dist/ai-service/llm/context-v2/migrations/v1-to-v2.js +5 -73
  156. package/dist/ai-service/llm/context-v2/migrations/v1-to-v2.js.map +1 -1
  157. package/dist/ai-service/llm/context-v2/storage/event-store.d.ts +57 -0
  158. package/dist/ai-service/llm/context-v2/storage/event-store.d.ts.map +1 -0
  159. package/dist/ai-service/llm/context-v2/storage/event-store.js +10 -0
  160. package/dist/ai-service/llm/context-v2/storage/event-store.js.map +1 -0
  161. package/dist/ai-service/llm/context-v2/storage/event-types.d.ts +50 -0
  162. package/dist/ai-service/llm/context-v2/storage/event-types.d.ts.map +1 -0
  163. package/dist/ai-service/llm/context-v2/storage/event-types.js +10 -0
  164. package/dist/ai-service/llm/context-v2/storage/event-types.js.map +1 -0
  165. package/dist/ai-service/llm/context-v2/storage/jsonl-event-store.d.ts +87 -0
  166. package/dist/ai-service/llm/context-v2/storage/jsonl-event-store.d.ts.map +1 -0
  167. package/dist/ai-service/llm/context-v2/storage/jsonl-event-store.js +184 -0
  168. package/dist/ai-service/llm/context-v2/storage/jsonl-event-store.js.map +1 -0
  169. package/dist/ai-service/llm/context-v2/storage/migration.d.ts +49 -0
  170. package/dist/ai-service/llm/context-v2/storage/migration.d.ts.map +1 -0
  171. package/dist/ai-service/llm/context-v2/storage/migration.js +126 -0
  172. package/dist/ai-service/llm/context-v2/storage/migration.js.map +1 -0
  173. package/dist/ai-service/llm/context-v2/types.d.ts +16 -11
  174. package/dist/ai-service/llm/context-v2/types.d.ts.map +1 -1
  175. package/dist/ai-service/llm/context-v2/types.js +2 -2
  176. package/dist/ai-service/llm/context-v2/types.js.map +1 -1
  177. package/dist/ai-service/llm/impl/clark.d.ts +8 -0
  178. package/dist/ai-service/llm/impl/clark.d.ts.map +1 -1
  179. package/dist/ai-service/llm/impl/clark.js +8 -0
  180. package/dist/ai-service/llm/impl/clark.js.map +1 -1
  181. package/dist/ai-service/llm/interaction/adapters/vercel.d.ts.map +1 -1
  182. package/dist/ai-service/llm/interaction/adapters/vercel.js +17 -1
  183. package/dist/ai-service/llm/interaction/adapters/vercel.js.map +1 -1
  184. package/dist/ai-service/llm/provider.d.ts.map +1 -1
  185. package/dist/ai-service/llm/provider.js +1 -3
  186. package/dist/ai-service/llm/provider.js.map +1 -1
  187. package/dist/ai-service/llm/stream/observers/context.d.ts +23 -0
  188. package/dist/ai-service/llm/stream/observers/context.d.ts.map +1 -1
  189. package/dist/ai-service/llm/stream/observers/context.js +62 -0
  190. package/dist/ai-service/llm/stream/observers/context.js.map +1 -1
  191. package/dist/ai-service/llm/tool-context-integrity.d.ts +25 -0
  192. package/dist/ai-service/llm/tool-context-integrity.d.ts.map +1 -0
  193. package/dist/ai-service/llm/tool-context-integrity.js +141 -0
  194. package/dist/ai-service/llm/tool-context-integrity.js.map +1 -0
  195. package/dist/ai-service/skills/system/superblocks-migration/skill.generated.d.ts +1 -1
  196. package/dist/ai-service/skills/system/superblocks-migration/skill.generated.d.ts.map +1 -1
  197. package/dist/ai-service/skills/system/superblocks-migration/skill.generated.js +6 -1
  198. package/dist/ai-service/skills/system/superblocks-migration/skill.generated.js.map +1 -1
  199. package/dist/ai-service/skills/system/third-party-migration/skill.generated.d.ts +1 -1
  200. package/dist/ai-service/skills/system/third-party-migration/skill.generated.d.ts.map +1 -1
  201. package/dist/ai-service/skills/system/third-party-migration/skill.generated.js +3 -2
  202. package/dist/ai-service/skills/system/third-party-migration/skill.generated.js.map +1 -1
  203. package/dist/ai-service/state-machine/clark-fsm.d.ts +23 -2
  204. package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
  205. package/dist/ai-service/state-machine/clark-fsm.js +37 -2
  206. package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
  207. package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -1
  208. package/dist/ai-service/state-machine/handlers/agent-planning.js +29 -2
  209. package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
  210. package/dist/ai-service/state-machine/handlers/awaiting-user.d.ts.map +1 -1
  211. package/dist/ai-service/state-machine/handlers/awaiting-user.js +9 -0
  212. package/dist/ai-service/state-machine/handlers/awaiting-user.js.map +1 -1
  213. package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
  214. package/dist/ai-service/state-machine/handlers/llm-generating.js +25 -2
  215. package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
  216. package/dist/ai-service/state-machine/helpers/fetch-with-reconnect-retry.d.ts +6 -0
  217. package/dist/ai-service/state-machine/helpers/fetch-with-reconnect-retry.d.ts.map +1 -0
  218. package/dist/ai-service/state-machine/helpers/fetch-with-reconnect-retry.js +36 -0
  219. package/dist/ai-service/state-machine/helpers/fetch-with-reconnect-retry.js.map +1 -0
  220. package/dist/ai-service/state-machine/helpers/stable-peer.d.ts +30 -1
  221. package/dist/ai-service/state-machine/helpers/stable-peer.d.ts.map +1 -1
  222. package/dist/ai-service/state-machine/helpers/stable-peer.js +85 -2
  223. package/dist/ai-service/state-machine/helpers/stable-peer.js.map +1 -1
  224. package/dist/ai-service/state-machine/helpers/user-preferences.d.ts +8 -0
  225. package/dist/ai-service/state-machine/helpers/user-preferences.d.ts.map +1 -0
  226. package/dist/ai-service/state-machine/helpers/user-preferences.js +11 -0
  227. package/dist/ai-service/state-machine/helpers/user-preferences.js.map +1 -0
  228. package/dist/ai-service/template-renderer.d.ts +18 -1
  229. package/dist/ai-service/template-renderer.d.ts.map +1 -1
  230. package/dist/ai-service/template-renderer.js +73 -12
  231. package/dist/ai-service/template-renderer.js.map +1 -1
  232. package/dist/ai-service/types.d.ts +157 -0
  233. package/dist/ai-service/types.d.ts.map +1 -1
  234. package/dist/ai-service/types.js +137 -0
  235. package/dist/ai-service/types.js.map +1 -1
  236. package/dist/ai-service/util/llm-config-utils.d.ts +21 -22
  237. package/dist/ai-service/util/llm-config-utils.d.ts.map +1 -1
  238. package/dist/ai-service/util/llm-config-utils.js +40 -67
  239. package/dist/ai-service/util/llm-config-utils.js.map +1 -1
  240. package/dist/file-sync-vite-plugin.d.ts.map +1 -1
  241. package/dist/file-sync-vite-plugin.js +5 -0
  242. package/dist/file-sync-vite-plugin.js.map +1 -1
  243. package/dist/file-system-helpers.d.ts +17 -0
  244. package/dist/file-system-helpers.d.ts.map +1 -1
  245. package/dist/file-system-helpers.js +22 -0
  246. package/dist/file-system-helpers.js.map +1 -1
  247. package/dist/git-service/index.d.ts.map +1 -1
  248. package/dist/git-service/index.js +15 -1
  249. package/dist/git-service/index.js.map +1 -1
  250. package/dist/migration/migration-routes.d.ts.map +1 -1
  251. package/dist/migration/migration-routes.js +26 -3
  252. package/dist/migration/migration-routes.js.map +1 -1
  253. package/dist/migration/translation-prompt.d.ts.map +1 -1
  254. package/dist/migration/translation-prompt.js +5 -0
  255. package/dist/migration/translation-prompt.js.map +1 -1
  256. package/dist/migration-templates/app-fullstack/package.json +2 -2
  257. package/dist/policy-gate-callback-mapper.d.ts +24 -0
  258. package/dist/policy-gate-callback-mapper.d.ts.map +1 -0
  259. package/dist/policy-gate-callback-mapper.js +61 -0
  260. package/dist/policy-gate-callback-mapper.js.map +1 -0
  261. package/dist/policy-gate-runner.d.ts +32 -0
  262. package/dist/policy-gate-runner.d.ts.map +1 -0
  263. package/dist/policy-gate-runner.js +191 -0
  264. package/dist/policy-gate-runner.js.map +1 -0
  265. package/dist/router-parser.d.ts.map +1 -1
  266. package/dist/router-parser.js +107 -11
  267. package/dist/router-parser.js.map +1 -1
  268. package/dist/sync-service/list-dir.d.ts.map +1 -1
  269. package/dist/sync-service/list-dir.js +13 -3
  270. package/dist/sync-service/list-dir.js.map +1 -1
  271. package/package.json +28 -10
@@ -0,0 +1,286 @@
1
+ import type { NpmInstallBlockedReason } from "../types.js";
2
+ import type { NpmRegistryClient } from "./npm-registry.js";
3
+ /**
4
+ * Which registry actually answered (or was going to be hit) for this lookup:
5
+ *
6
+ * - "private": a configured per-org registry (the operator opted in via
7
+ * `superblocks.npm-registry.enabled` and configured a default and/or
8
+ * scoped registries). Includes `stale` cache reads from
9
+ * `NpmRegistryClient`.
10
+ * - "public-npm": npmjs.org — either because no client is wired (SaaS),
11
+ * or `getConfig()` reported `not-configured`. Matches the default
12
+ * `registry=` line in the bootstrapped `.npmrc`.
13
+ * - "fail-closed": we have evidence of a private-registry org but no safe
14
+ * destination for this name right now (hard-fail auth from `getConfig`,
15
+ * transient cold-cache `source: unreachable`, or a configured-but-
16
+ * scoped-only org whose mappings don't cover the requested name and
17
+ * supplies no default). We deliberately do NOT downgrade to public npm
18
+ * in any of these — `available` will be `false` with
19
+ * `reason: "registry_unreachable"` and `registry_host` will be empty.
20
+ *
21
+ * Note for callers (agent/tool): `mode: "public-npm"` + `reason:
22
+ * "registry_unreachable"` is the strong signal that the operator's network
23
+ * blocks egress to npmjs.org without having configured a private registry.
24
+ * `mode: "private"` + `reason: "registry_unreachable"` is the analogous
25
+ * signal for an unreachable per-org registry.
26
+ */
27
+ export type NpmPackageLookupMode = "private" | "public-npm" | "fail-closed";
28
+ /**
29
+ * Normalized result returned by `NpmPackageLookup.lookup`.
30
+ *
31
+ * The `reason` enum reuses `NpmInstallBlockedReason` (APPS-4179) verbatim so
32
+ * downstream prompt logic and evals can treat both tools' failure modes as
33
+ * one taxonomy. `registry_host` names whichever registry actually answered —
34
+ * the per-org default, a scope-mapped private registry, or `registry.npmjs.org`
35
+ * when we intentionally fell through to public npm. The empty string is
36
+ * reserved for `mode: "fail-closed"` where no registry was contacted at all.
37
+ *
38
+ * `recent_versions` is the most-recently-published versions from the
39
+ * registry's `time` map (or, when `time` is absent, semver-descending from
40
+ * `versions`), capped at `RECENT_VERSIONS_CAP`. Lets the agent pick a
41
+ * specific version without burning a second tool call.
42
+ */
43
+ export interface NpmPackageLookupResult {
44
+ available: boolean;
45
+ mode: NpmPackageLookupMode;
46
+ reason?: NpmInstallBlockedReason;
47
+ registry_host: string;
48
+ latest_version?: string;
49
+ recent_versions?: string[];
50
+ }
51
+ export interface NpmPackageLookupDeps {
52
+ /**
53
+ * Per-org npm registry client (APPS-4230). When omitted, lookups fall back
54
+ * to the public npm registry, matching the `.npmrc` we bootstrap into a
55
+ * fresh app (which lists `https://registry.npmjs.org/` as its default).
56
+ */
57
+ client?: NpmRegistryClient;
58
+ /** Inject `fetch` for tests; defaults to `globalThis.fetch`. */
59
+ fetch?: typeof globalThis.fetch;
60
+ /** Clock for deterministic cache-TTL tests; defaults to `Date.now`. */
61
+ now?: () => number;
62
+ /** Cache TTL in ms; defaults to 60s per APPS-4183 spec. */
63
+ ttlMs?: number;
64
+ /** Per-request fetch timeout in ms; defaults to 5s. */
65
+ fetchTimeoutMs?: number;
66
+ /**
67
+ * Skip OTel `ObservableGauge` registration. Tests construct many instances
68
+ * per file; registering a callback on each one would leak callbacks against
69
+ * the process-global meter even after the instance is gone. Production code
70
+ * paths (`build-lookup-npm-package`) leave this unset so the gauge wires up
71
+ * normally.
72
+ */
73
+ skipMetrics?: boolean;
74
+ }
75
+ /**
76
+ * Pre-flight check for npm package availability against the registry
77
+ * Clark's install path would actually use. Designed so the agent can call
78
+ * this BEFORE attempting `npm install` and either skip a doomed install
79
+ * (the registry doesn't carry the package), pick a different package up
80
+ * front, or pick a recent version from `recent_versions` — rather than
81
+ * burning ~30s on a build pod recovering from `NpmInstallBlocked` after
82
+ * the fact.
83
+ *
84
+ * Registry resolution per call (mirrors `npm install`'s scope-mapping):
85
+ *
86
+ * 1. `await client.getConfig()` if a client is wired.
87
+ * - `source: configured | stale` → use `config.scopes[@scope]` for a
88
+ * scoped name; else `config.default`. Both yield `mode: "private"`.
89
+ * If neither matches (scoped-only mappings, no default, no scope
90
+ * match) the result is `mode: "fail-closed"` with
91
+ * `reason: "registry_unreachable"` — see `resolveRegistry`.
92
+ * - `source: not-configured` → public npm (`mode: "public-npm"`).
93
+ * - `source: unreachable`, or `getConfig()` threw → `mode: "fail-closed"`.
94
+ * 2. No client wired → public npm (`mode: "public-npm"`).
95
+ * Matches the default `registry=` line we bootstrap into every app's
96
+ * `.npmrc`.
97
+ *
98
+ * Behaviour matrix (post-resolve):
99
+ *
100
+ * | HTTP 200 | `available: true`, `latest_version`, `recent_versions` |
101
+ * | HTTP 404 | `available: false, reason: not_in_registry` |
102
+ * | HTTP 401 / 403 | `available: false, reason: registry_auth_failed` |
103
+ * | HTTP 5xx / DNS / TCP / TLS / fetch throw | `available: false, reason: registry_unreachable` |
104
+ *
105
+ * `mode: "public-npm"` + `reason: "registry_unreachable"` is the strong
106
+ * signal that the operator's network blocks egress to npmjs.org without
107
+ * a configured private registry; the agent can surface this as a
108
+ * connectivity / configuration issue rather than a missing package.
109
+ * `mode: "fail-closed"` + `reason: "registry_unreachable"` covers the
110
+ * cases where the private-registry config itself is in a bad state
111
+ * (auth, transient unreachable) or doesn't cover the requested name
112
+ * (scoped-only mappings, no default, no scope match).
113
+ *
114
+ * Token hygiene: the token comes back from `client.getConfig()` per call
115
+ * and lives only in a local inside `lookup()`. Nothing token-bearing is
116
+ * stored on the instance, so `JSON.stringify(this)` cannot surface it.
117
+ * Bodies of 4xx/5xx responses are drained without inspection — a hostile
118
+ * registry could echo the submitted token back in a 401 body, and the only
119
+ * way to guarantee the token never reaches the tool output / log / span is
120
+ * to never read those bytes at all.
121
+ *
122
+ * Caching: per-instance, in-memory, keyed on
123
+ * `<normalized-registry-base-url>:<name>` with a 60s TTL. The full base
124
+ * URL (not just the host) is required because Artifactory-style proxies
125
+ * host multiple npm repos under one host (`…/api/npm/repo-a/` vs
126
+ * `…/api/npm/repo-b/`) — keying on host alone would let a 200 or 404
127
+ * from one virtual repo bleed into the other. Per-process (the dev-server
128
+ * runs a single AppShell), no cross-pod sharing — same as
129
+ * `NpmRegistryClient`. Only stable outcomes (`available: true` and
130
+ * `not_in_registry`) are cached; `registry_auth_failed` and
131
+ * `registry_unreachable` are transient and must recover on the next call
132
+ * (otherwise a token rotation or a short network blip would pin the
133
+ * failure for a full minute). The URL-keyed prefix also means a swap
134
+ * between a private registry and the public-npm fallback can't accidentally
135
+ * serve a result from the wrong source. The cache is bounded at
136
+ * `MAX_CACHE_SIZE` entries (APPS-4429): TTL is checked only reactively on
137
+ * read, so without a cap a long session of unique lookups would grow the
138
+ * heap unbounded. On insert at/over the cap, `evictToCapacity` drops expired
139
+ * entries first, then the oldest-expiring live entries, emitting the count
140
+ * on the `cache_evictions` counter.
141
+ *
142
+ * In-flight dedup: concurrent `lookup(name)` calls that miss the cache and
143
+ * resolve to the same cache key share a single fetch — the first caller
144
+ * stores the pending promise in an inflight map; subsequent callers await
145
+ * it instead of firing a second HTTP request. Clark batch-installs (one
146
+ * lookup per package) hit this path regularly. The slot is cleared in
147
+ * `.finally()` so a transient-failure resolution doesn't pin every future
148
+ * caller to the same rejected promise. See `inFlight` for the keying
149
+ * contract (same string as the cache, so two scopes never share a result).
150
+ */
151
+ export declare class NpmPackageLookup {
152
+ private readonly client;
153
+ private readonly fetchImpl;
154
+ private readonly nowFn;
155
+ private readonly ttlMs;
156
+ private readonly fetchTimeoutMs;
157
+ private readonly cache;
158
+ /**
159
+ * In-flight fetches keyed by the same `<normalized-registry-base-url>:<name>`
160
+ * string the cache uses. The first caller for a given key kicks off the
161
+ * fetch and stores the pending promise here; subsequent concurrent callers
162
+ * (Clark batch-installs hit this regularly) await the same promise instead
163
+ * of firing a second HTTP request against the registry. The slot is cleared
164
+ * in `.finally()` regardless of fetch outcome — including the transient
165
+ * failure paths (`registry_auth_failed`, `registry_unreachable`) that the
166
+ * cache deliberately skips — so a single failed fetch can't pin every
167
+ * future caller to the same rejected promise.
168
+ *
169
+ * Keying on the same string as `cache` (not on `name` alone) means
170
+ * concurrent lookups for the same package name routed to different
171
+ * registries (scoped vs. default, or a swap between private and public)
172
+ * each get their own inflight slot and never share a result across trust
173
+ * boundaries.
174
+ */
175
+ private readonly inFlight;
176
+ /**
177
+ * Resolved gauge and bound callback held so `removeCallback` can detach.
178
+ * The gauge handle is captured at construction so `dispose()` always
179
+ * detaches from the same instrument it attached to, even if the global
180
+ * meter provider has been replaced in the meantime.
181
+ */
182
+ private readonly gauge?;
183
+ private readonly gaugeCallback?;
184
+ /**
185
+ * Counter for entries the size cap forces out (see `evictToCapacity`).
186
+ * Cumulative, no labels — same partitioning rationale as the gauge. Held
187
+ * `undefined` when `skipMetrics` is set so tests don't leak instruments
188
+ * against the process-global meter.
189
+ */
190
+ private readonly evictionCounter?;
191
+ constructor(deps?: NpmPackageLookupDeps);
192
+ /**
193
+ * Detach the cache-size gauge callback. Call when retiring a long-lived
194
+ * instance (e.g. tearing down a Clark session that owned its own lookup).
195
+ * The OTel API keeps a strong reference to every registered callback, so
196
+ * letting the instance go out of scope without calling this leaves the
197
+ * callback (and the cache it closes over) alive for the lifetime of the
198
+ * process meter. Production code paths that hold the lookup for the
199
+ * lifetime of the process never need to call this; it exists so tests and
200
+ * future cleanup paths can detach cleanly.
201
+ */
202
+ dispose(): void;
203
+ lookup(name: string): Promise<NpmPackageLookupResult>;
204
+ /**
205
+ * Number of cached entries (successful lookups and `not_in_registry`
206
+ * misses; transient failures aren't cached). Exposed as a gauge for
207
+ * monitoring — keeps the cache footprint visible without poking at
208
+ * private state from outside the class.
209
+ */
210
+ size(): number;
211
+ /**
212
+ * Make room for one new entry when the cache is at/over `MAX_CACHE_SIZE`.
213
+ * Called from the insert path before adding a key that isn't already
214
+ * present.
215
+ *
216
+ * Eviction order, keyed on `expiresAt`:
217
+ *
218
+ * 1. Expired entries first (`expiresAt <= now`). TTL is only checked
219
+ * reactively on read, so a never-re-accessed name's entry would
220
+ * otherwise linger forever; dropping the already-dead ones reclaims
221
+ * space without evicting anything a future read could have used.
222
+ * 2. If that didn't get us under the cap, the oldest-expiring live
223
+ * entries (smallest `expiresAt`) — those are closest to expiry anyway,
224
+ * so they're the cheapest live entries to lose.
225
+ *
226
+ * Sorting the whole keyset is O(n log n), but it only runs once the cache
227
+ * is full (n = `MAX_CACHE_SIZE`) and only on inserts of genuinely-new keys,
228
+ * so it's off the steady-state hot path. Emits the number evicted on the
229
+ * eviction counter so a sustained-eviction-at-flat-size signal is visible
230
+ * in Grafana alongside the existing `cache_size` gauge.
231
+ */
232
+ private evictToCapacity;
233
+ /**
234
+ * Resolve the registry this lookup will hit:
235
+ *
236
+ * - No client wired (SaaS mode): public npm.
237
+ * - `source: not-configured` (operator never opted in): public npm.
238
+ * - `source: configured | stale`, name matches `config.scopes[@scope]`:
239
+ * scoped private registry.
240
+ * - `source: configured | stale`, no scope match, `config.default`
241
+ * present: default private registry.
242
+ *
243
+ * Fail-closed (returns `"fail-closed"`; caller surfaces
244
+ * `registry_unreachable` and never touches the network):
245
+ *
246
+ * - `getConfig()` threw on hard-fail auth (revoked JWT, double 401
247
+ * against the Superblocks server). In that state we'd silently
248
+ * downgrade from "checking the private registry" to "checking
249
+ * public npm" — different trust boundary, different answer. The
250
+ * agent's reasoning about install feasibility depends on which
251
+ * registry actually answered; failing closed surfaces the auth
252
+ * problem instead of hiding it behind a misleading public-npm
253
+ * result.
254
+ * - `source: unreachable` AND `everConfigured === true` (transient
255
+ * cold-cache outage against the Superblocks server for an org that
256
+ * has at some prior point successfully resolved a configured
257
+ * registry). Same trust gap as the throw branch: we don't know the
258
+ * org's current registry state, but the on-disk marker says it has
259
+ * a private registry, so leaking the name to npmjs would be a silent
260
+ * supply-chain leak during the outage window. Symmetric with
261
+ * `syncHomeNpmrc` and `maybeWriteNpmrcForDir`, both of which refuse
262
+ * to act on `unreachable` for the same reason.
263
+ *
264
+ * When `everConfigured` is `false` (greenfield org / no disk marker)
265
+ * or `undefined` (no store wired in — older call sites, test
266
+ * fixtures), we do NOT fail closed. The `unreachable` config is
267
+ * `{ configured: false }`, so we proceed exactly as the install path
268
+ * does (`AppShell.maybeShortCircuitForUnreachable` only blocks when
269
+ * `everConfigured === true`): fall through to public npm. A
270
+ * greenfield org has no private registry, so a metadata lookup
271
+ * against public npm during a config-server outage leaks nothing
272
+ * sensitive — and keeping the lookup aligned with the install gate
273
+ * removes the lookup-vs-install divergence where the lookup reported
274
+ * `fail-closed` while a direct install of the same package would
275
+ * have proceeded (APPS-4425).
276
+ * - `source: configured | stale`, no scope match, no `config.default`.
277
+ * The operator wired scoped-only mappings and the requested name
278
+ * doesn't match any of them — there's no in-policy destination, so
279
+ * answering from npmjs.org would report availability from the wrong
280
+ * trust boundary. Same shape as the other two: surface the gap to
281
+ * the agent rather than silently downgrading.
282
+ */
283
+ private resolveRegistry;
284
+ private fetchAndMap;
285
+ }
286
+ //# sourceMappingURL=npm-package-lookup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-package-lookup.d.ts","sourceRoot":"","sources":["../../../src/ai-service/app-interface/npm-package-lookup.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAqB,MAAM,mBAAmB,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC;AAE5E;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,gEAAgE;IAChE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAmOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGlB;IACJ;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGrB;IACJ;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAEpB;IACX;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAU;gBAE/B,IAAI,GAAE,oBAAyB;IA0B3C;;;;;;;;;OASG;IACH,OAAO,IAAI,IAAI;IAMT,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA+E3D;;;;;OAKG;IACH,IAAI,IAAI,MAAM;IAId;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,eAAe;IAwCvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;YACW,eAAe;YAgFf,WAAW;CA4F1B"}