@kenkaiiii/ggcoder 6.3.0 → 7.0.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 (1121) hide show
  1. package/README.md +9 -8
  2. package/dist/app-sidecar/app-settings.d.ts +1 -1
  3. package/dist/app-sidecar/app-settings.js +3 -4
  4. package/dist/app-sidecar/app-settings.js.map +1 -1
  5. package/dist/app-sidecar/attachments.js +1 -1
  6. package/dist/app-sidecar/attachments.js.map +1 -1
  7. package/dist/app-sidecar/auth-routes.js +2 -5
  8. package/dist/app-sidecar/auth-routes.js.map +1 -1
  9. package/dist/app-sidecar/autopilot-runner.d.ts +8 -8
  10. package/dist/app-sidecar/autopilot-runner.js +8 -8
  11. package/dist/app-sidecar/autopilot-runner.js.map +1 -1
  12. package/dist/app-sidecar/branch-routes.d.ts +8 -1
  13. package/dist/app-sidecar/branch-routes.js +154 -2
  14. package/dist/app-sidecar/branch-routes.js.map +1 -1
  15. package/dist/app-sidecar/detached-sessions.d.ts +7 -10
  16. package/dist/app-sidecar/detached-sessions.js +6 -2
  17. package/dist/app-sidecar/detached-sessions.js.map +1 -1
  18. package/dist/app-sidecar/file-search.js +1 -1
  19. package/dist/app-sidecar/file-search.js.map +1 -1
  20. package/dist/app-sidecar/git-branches.d.ts +18 -1
  21. package/dist/app-sidecar/git-branches.js +24 -6
  22. package/dist/app-sidecar/git-branches.js.map +1 -1
  23. package/dist/app-sidecar/git-ship.d.ts +42 -0
  24. package/dist/app-sidecar/git-ship.js +349 -0
  25. package/dist/app-sidecar/git-ship.js.map +1 -0
  26. package/dist/app-sidecar/git-target.d.ts +2 -2
  27. package/dist/app-sidecar/git-target.js +2 -2
  28. package/dist/app-sidecar/git-target.js.map +1 -1
  29. package/dist/app-sidecar/goal-routes.d.ts +1 -1
  30. package/dist/app-sidecar/goal-routes.js +5 -6
  31. package/dist/app-sidecar/goal-routes.js.map +1 -1
  32. package/dist/app-sidecar/hf-pull-manager.d.ts +5 -4
  33. package/dist/app-sidecar/hf-pull-manager.js +1 -1
  34. package/dist/app-sidecar/hf-pull-manager.js.map +1 -1
  35. package/dist/app-sidecar/history-routes.js +6 -6
  36. package/dist/app-sidecar/history-routes.js.map +1 -1
  37. package/dist/app-sidecar/history.d.ts +2 -2
  38. package/dist/app-sidecar/integration-routes.js +4 -6
  39. package/dist/app-sidecar/integration-routes.js.map +1 -1
  40. package/dist/app-sidecar/keep-awake.d.ts +1 -1
  41. package/dist/app-sidecar/keep-awake.js +1 -1
  42. package/dist/app-sidecar/keep-awake.js.map +1 -1
  43. package/dist/app-sidecar/ken-context.d.ts +2 -2
  44. package/dist/app-sidecar/ken-context.js +1 -1
  45. package/dist/app-sidecar/ken-context.js.map +1 -1
  46. package/dist/app-sidecar/live-preview/dev-url.d.ts +1 -1
  47. package/dist/app-sidecar/live-preview/manager.d.ts +2 -14
  48. package/dist/app-sidecar/live-preview/manager.js.map +1 -1
  49. package/dist/app-sidecar/live-preview/pages.d.ts +21 -1
  50. package/dist/app-sidecar/live-preview/pages.js +138 -4
  51. package/dist/app-sidecar/live-preview/pages.js.map +1 -1
  52. package/dist/app-sidecar/live-preview/routes.d.ts +7 -3
  53. package/dist/app-sidecar/live-preview/routes.js +32 -2
  54. package/dist/app-sidecar/live-preview/routes.js.map +1 -1
  55. package/dist/app-sidecar/live-preview/servers.js +1 -1
  56. package/dist/app-sidecar/live-preview/servers.js.map +1 -1
  57. package/dist/app-sidecar/mcp-routes.js +2 -2
  58. package/dist/app-sidecar/mcp-routes.js.map +1 -1
  59. package/dist/app-sidecar/mcp-rows.d.ts +3 -15
  60. package/dist/app-sidecar/mcp-rows.js +7 -2
  61. package/dist/app-sidecar/mcp-rows.js.map +1 -1
  62. package/dist/app-sidecar/mcp-shell-command.d.ts +1 -1
  63. package/dist/app-sidecar/mcp-shell-command.js +3 -3
  64. package/dist/app-sidecar/mcp-shell-command.js.map +1 -1
  65. package/dist/app-sidecar/mcp-sync.d.ts +2 -2
  66. package/dist/app-sidecar/mcp-sync.js +3 -3
  67. package/dist/app-sidecar/mcp-sync.js.map +1 -1
  68. package/dist/app-sidecar/progress-manager.d.ts +1 -1
  69. package/dist/app-sidecar/progress-manager.js +6 -6
  70. package/dist/app-sidecar/progress-manager.js.map +1 -1
  71. package/dist/app-sidecar/prompt-routes.js +5 -5
  72. package/dist/app-sidecar/prompt-routes.js.map +1 -1
  73. package/dist/app-sidecar/repo-polls.d.ts +3 -3
  74. package/dist/app-sidecar/repo-polls.js +4 -4
  75. package/dist/app-sidecar/repo-polls.js.map +1 -1
  76. package/dist/app-sidecar/route-context.d.ts +17 -17
  77. package/dist/app-sidecar/run-control-routes.js +2 -5
  78. package/dist/app-sidecar/run-control-routes.js.map +1 -1
  79. package/dist/app-sidecar/session-file-routes.d.ts +1 -1
  80. package/dist/app-sidecar/session-file-routes.js +2 -2
  81. package/dist/app-sidecar/session-file-routes.js.map +1 -1
  82. package/dist/app-sidecar/session-routes.js +3 -4
  83. package/dist/app-sidecar/session-routes.js.map +1 -1
  84. package/dist/app-sidecar/session-types.d.ts +11 -13
  85. package/dist/app-sidecar/shell-routes.js +1 -1
  86. package/dist/app-sidecar/shell-routes.js.map +1 -1
  87. package/dist/app-sidecar/shell-runs.js +2 -2
  88. package/dist/app-sidecar/shell-runs.js.map +1 -1
  89. package/dist/app-sidecar/shell-suggestions.d.ts +2 -8
  90. package/dist/app-sidecar/shell-suggestions.js +1 -1
  91. package/dist/app-sidecar/shell-suggestions.js.map +1 -1
  92. package/dist/app-sidecar/task-routes.js +5 -5
  93. package/dist/app-sidecar/task-routes.js.map +1 -1
  94. package/dist/app-sidecar/trophy-manager.d.ts +2 -2
  95. package/dist/app-sidecar/trophy-manager.js +3 -3
  96. package/dist/app-sidecar/trophy-manager.js.map +1 -1
  97. package/dist/app-sidecar/usage.d.ts +1 -1
  98. package/dist/app-sidecar/usage.js +3 -2
  99. package/dist/app-sidecar/usage.js.map +1 -1
  100. package/dist/app-sidecar/workspace-routes.js +4 -4
  101. package/dist/app-sidecar/workspace-routes.js.map +1 -1
  102. package/dist/app-sidecar/worktrees.js +1 -1
  103. package/dist/app-sidecar/worktrees.js.map +1 -1
  104. package/dist/app-sidecar-sessions.d.ts +2 -5
  105. package/dist/app-sidecar-sessions.js +1 -1
  106. package/dist/app-sidecar-sessions.js.map +1 -1
  107. package/dist/app-sidecar.d.ts +1 -1
  108. package/dist/app-sidecar.js +54 -45
  109. package/dist/app-sidecar.js.map +1 -1
  110. package/dist/chat-agents/general.d.ts +1 -1
  111. package/dist/chat-agents/index.d.ts +1 -1
  112. package/dist/chat-agents/jiwa.d.ts +2 -9
  113. package/dist/chat-agents/jiwa.js +1 -0
  114. package/dist/chat-agents/jiwa.js.map +1 -1
  115. package/dist/chat-agents/memory.d.ts +2 -9
  116. package/dist/chat-agents/memory.js +1 -0
  117. package/dist/chat-agents/memory.js.map +1 -1
  118. package/dist/chat-agents/research.d.ts +1 -1
  119. package/dist/chat-agents/shared.d.ts +1 -1
  120. package/dist/chat-agents/shared.js +1 -1
  121. package/dist/chat-agents/shared.js.map +1 -1
  122. package/dist/chat-agents/therapist.d.ts +1 -1
  123. package/dist/chat-agents/types.d.ts +2 -1
  124. package/dist/chat-agents/types.js +6 -1
  125. package/dist/chat-agents/types.js.map +1 -1
  126. package/dist/cli/auth.js +3 -6
  127. package/dist/cli/auth.js.map +1 -1
  128. package/dist/cli/mcp.js +4 -3
  129. package/dist/cli/mcp.js.map +1 -1
  130. package/dist/cli.d.ts +1 -0
  131. package/dist/cli.js +26 -27
  132. package/dist/cli.js.map +1 -1
  133. package/dist/goals-agent/goal-team.d.ts +1 -1
  134. package/dist/goals-agent/goals-agent.d.ts +3 -3
  135. package/dist/goals-agent/goals-agent.js +5 -5
  136. package/dist/goals-agent/goals-agent.js.map +1 -1
  137. package/dist/hf-pull.d.ts +2 -1
  138. package/dist/hf-pull.js +0 -1
  139. package/dist/hf-pull.js.map +1 -1
  140. package/dist/index.d.ts +0 -8
  141. package/dist/index.js +1 -14
  142. package/dist/index.js.map +1 -1
  143. package/dist/modes/acp-autopilot.js +3 -3
  144. package/dist/modes/acp-autopilot.js.map +1 -1
  145. package/dist/modes/acp-goals.d.ts +2 -2
  146. package/dist/modes/acp-goals.js +3 -3
  147. package/dist/modes/acp-goals.js.map +1 -1
  148. package/dist/modes/acp-mode.d.ts +6 -6
  149. package/dist/modes/acp-mode.js +22 -23
  150. package/dist/modes/acp-mode.js.map +1 -1
  151. package/dist/modes/agent-home-mode.js +7 -8
  152. package/dist/modes/agent-home-mode.js.map +1 -1
  153. package/dist/modes/json-mode.js +4 -4
  154. package/dist/modes/json-mode.js.map +1 -1
  155. package/dist/modes/print-mode.js +4 -3
  156. package/dist/modes/print-mode.js.map +1 -1
  157. package/dist/modes/rpc-mode.js +2 -2
  158. package/dist/modes/rpc-mode.js.map +1 -1
  159. package/dist/modes/serve-mode.js +10 -11
  160. package/dist/modes/serve-mode.js.map +1 -1
  161. package/dist/modes/subagent-worker-mode.d.ts +1 -1
  162. package/dist/modes/subagent-worker-mode.js +8 -8
  163. package/dist/modes/subagent-worker-mode.js.map +1 -1
  164. package/dist/motion-agent/motion-agent.d.ts +3 -2
  165. package/dist/motion-agent/motion-agent.js +3 -2
  166. package/dist/motion-agent/motion-agent.js.map +1 -1
  167. package/dist/motion-agent/motion-bundle.d.ts +18 -0
  168. package/dist/motion-agent/motion-bundle.js +34 -0
  169. package/dist/motion-agent/motion-bundle.js.map +1 -0
  170. package/dist/subagent-entry-path.d.ts +1 -0
  171. package/dist/subagent-entry-path.js +13 -0
  172. package/dist/subagent-entry-path.js.map +1 -0
  173. package/dist/subagent-entry.d.ts +1 -1
  174. package/dist/subagent-entry.js +2 -1
  175. package/dist/subagent-entry.js.map +1 -1
  176. package/dist/ui/App.d.ts +8 -8
  177. package/dist/ui/App.js +20 -21
  178. package/dist/ui/App.js.map +1 -1
  179. package/dist/ui/app-items.d.ts +1 -1
  180. package/dist/ui/components/BackgroundTasksBar.d.ts +1 -1
  181. package/dist/ui/components/Banner.js +1 -1
  182. package/dist/ui/components/Banner.js.map +1 -1
  183. package/dist/ui/components/ChatFooterPane.d.ts +1 -1
  184. package/dist/ui/components/ChatScreen.d.ts +4 -4
  185. package/dist/ui/components/Footer.d.ts +1 -1
  186. package/dist/ui/components/Footer.js +1 -1
  187. package/dist/ui/components/Footer.js.map +1 -1
  188. package/dist/ui/components/FooterStatusRow.d.ts +1 -1
  189. package/dist/ui/components/InputArea.d.ts +2 -2
  190. package/dist/ui/components/InputArea.js +2 -2
  191. package/dist/ui/components/InputArea.js.map +1 -1
  192. package/dist/ui/components/ModelSelector.js +1 -1
  193. package/dist/ui/components/ModelSelector.js.map +1 -1
  194. package/dist/ui/components/RewindOverlay.d.ts +1 -1
  195. package/dist/ui/components/RewindOverlay.js.map +1 -1
  196. package/dist/ui/components/SessionSelector.d.ts +1 -1
  197. package/dist/ui/components/SettingsSelector.d.ts +1 -1
  198. package/dist/ui/components/SkillsOverlay.js +2 -2
  199. package/dist/ui/components/SkillsOverlay.js.map +1 -1
  200. package/dist/ui/components/StreamingArea.js +1 -1
  201. package/dist/ui/components/StreamingArea.js.map +1 -1
  202. package/dist/ui/components/TaskPickerMenu.d.ts +1 -1
  203. package/dist/ui/components/ToolExecution.js +1 -1
  204. package/dist/ui/components/ToolExecution.js.map +1 -1
  205. package/dist/ui/error-item.js +2 -2
  206. package/dist/ui/error-item.js.map +1 -1
  207. package/dist/ui/hooks/useAgentLoop.d.ts +2 -2
  208. package/dist/ui/hooks/useAgentLoop.js +8 -8
  209. package/dist/ui/hooks/useAgentLoop.js.map +1 -1
  210. package/dist/ui/hooks/useChatLayoutMeasurements.d.ts +1 -1
  211. package/dist/ui/hooks/useContextCompaction.d.ts +3 -3
  212. package/dist/ui/hooks/useContextCompaction.js +6 -7
  213. package/dist/ui/hooks/useContextCompaction.js.map +1 -1
  214. package/dist/ui/hooks/useModeState.d.ts +2 -2
  215. package/dist/ui/hooks/useModeState.js +2 -2
  216. package/dist/ui/hooks/useModeState.js.map +1 -1
  217. package/dist/ui/hooks/useSessionPersistence.d.ts +1 -1
  218. package/dist/ui/hooks/useSessionPersistence.js +3 -3
  219. package/dist/ui/hooks/useSessionPersistence.js.map +1 -1
  220. package/dist/ui/hooks/useTaskPickerController.d.ts +1 -1
  221. package/dist/ui/hooks/useTaskPickerController.js +1 -1
  222. package/dist/ui/hooks/useTaskPickerController.js.map +1 -1
  223. package/dist/ui/hooks/useTranscriptHistory.d.ts +1 -1
  224. package/dist/ui/item-helpers.js +1 -1
  225. package/dist/ui/item-helpers.js.map +1 -1
  226. package/dist/ui/language-pack-update.d.ts +1 -1
  227. package/dist/ui/language-pack-update.js +1 -1
  228. package/dist/ui/language-pack-update.js.map +1 -1
  229. package/dist/ui/login.js +1 -1
  230. package/dist/ui/login.js.map +1 -1
  231. package/dist/ui/mcp.d.ts +1 -1
  232. package/dist/ui/prompt-routing.d.ts +3 -3
  233. package/dist/ui/prompt-routing.js +3 -3
  234. package/dist/ui/prompt-routing.js.map +1 -1
  235. package/dist/ui/render.d.ts +8 -8
  236. package/dist/ui/sessions.js +1 -1
  237. package/dist/ui/sessions.js.map +1 -1
  238. package/dist/ui/stores/taskbar-store.d.ts +1 -1
  239. package/dist/ui/stores/taskbar-store.js.map +1 -1
  240. package/dist/ui/submit-prompt-command.d.ts +2 -2
  241. package/dist/ui/submit-prompt-command.js +2 -3
  242. package/dist/ui/submit-prompt-command.js.map +1 -1
  243. package/dist/ui/terminal-history-status-renderers.d.ts +1 -1
  244. package/dist/ui/terminal-history.js +2 -3
  245. package/dist/ui/terminal-history.js.map +1 -1
  246. package/dist/ui/theme/theme.d.ts +2 -1
  247. package/dist/ui/theme/theme.js.map +1 -1
  248. package/dist/ui/thinking-level.d.ts +1 -1
  249. package/dist/ui/thinking-level.js +1 -1
  250. package/dist/ui/thinking-level.js.map +1 -1
  251. package/dist/ui/tool-line-summary.js +1 -1
  252. package/dist/ui/tool-line-summary.js.map +1 -1
  253. package/dist/ui/transcript/presentation.js +1 -1
  254. package/dist/ui/transcript/presentation.js.map +1 -1
  255. package/dist/ui/utils/text-utils.js +1 -1
  256. package/dist/ui/utils/text-utils.js.map +1 -1
  257. package/dist/utils/git-overview.d.ts +2 -23
  258. package/dist/utils/git-overview.js +8 -1
  259. package/dist/utils/git-overview.js.map +1 -1
  260. package/package.json +13 -103
  261. package/assets/skills/bulletproof/SKILL.md +0 -132
  262. package/assets/skills/bulletproof/references/agent-surface.md +0 -113
  263. package/assets/skills/bulletproof/references/attack-classes.md +0 -226
  264. package/assets/skills/bulletproof/references/audit-protocol.md +0 -232
  265. package/assets/skills/bulletproof/references/platform-playbooks.md +0 -196
  266. package/assets/skills/bulletproof/references/provenance.md +0 -146
  267. package/assets/skills/bulletproof/references/secure-defaults.md +0 -137
  268. package/assets/skills/bulletproof/references/supply-chain.md +0 -84
  269. package/assets/skills/bulletproof/references/threat-landscape.md +0 -66
  270. package/assets/skills/bulletproof/references/verification.md +0 -74
  271. package/assets/skills/compliance-guard/SKILL.md +0 -115
  272. package/assets/skills/compliance-guard/references/artifacts.md +0 -199
  273. package/assets/skills/compliance-guard/references/eu-uk.md +0 -162
  274. package/assets/skills/compliance-guard/references/exposure-triage.md +0 -177
  275. package/assets/skills/compliance-guard/references/full-review.md +0 -155
  276. package/assets/skills/compliance-guard/references/lawsuit-vectors.md +0 -153
  277. package/assets/skills/compliance-guard/references/provenance.md +0 -135
  278. package/assets/skills/compliance-guard/references/sector-gates.md +0 -187
  279. package/assets/skills/compliance-guard/references/security-baseline.md +0 -117
  280. package/assets/skills/compliance-guard/references/trigger-map.md +0 -177
  281. package/assets/skills/compliance-guard/references/us.md +0 -194
  282. package/assets/skills/durable/SKILL.md +0 -114
  283. package/assets/skills/durable/references/agent-db-safety.md +0 -76
  284. package/assets/skills/durable/references/backups-and-runtime.md +0 -93
  285. package/assets/skills/durable/references/migrations-and-schema.md +0 -87
  286. package/assets/skills/gg-guide/SKILL.md +0 -43
  287. package/assets/skills/gg-guide/references/chat-motion-goals.md +0 -217
  288. package/assets/skills/gg-guide/references/checklist-and-safety.md +0 -177
  289. package/assets/skills/gg-guide/references/code-mode.md +0 -266
  290. package/assets/skills/gg-guide/references/getting-started.md +0 -291
  291. package/assets/skills/gg-guide/references/ken-and-autopilot.md +0 -172
  292. package/assets/skills/gg-guide/references/mcp-and-skills.md +0 -204
  293. package/assets/skills/gg-guide/references/models-and-sign-in.md +0 -200
  294. package/assets/skills/gg-guide/references/sessions-and-history.md +0 -213
  295. package/assets/skills/gg-guide/references/settings.md +0 -193
  296. package/assets/skills/gg-guide/references/troubleshooting-and-data.md +0 -186
  297. package/assets/skills/lean/SKILL.md +0 -117
  298. package/assets/skills/lean/references/memory-and-processes.md +0 -99
  299. package/assets/skills/lean/references/playbooks.md +0 -134
  300. package/dist/app-error.d.ts +0 -22
  301. package/dist/app-error.js +0 -41
  302. package/dist/app-error.js.map +0 -1
  303. package/dist/config.d.ts +0 -90
  304. package/dist/config.js +0 -240
  305. package/dist/config.js.map +0 -1
  306. package/dist/core/acceptance-checks.d.ts +0 -48
  307. package/dist/core/acceptance-checks.js +0 -151
  308. package/dist/core/acceptance-checks.js.map +0 -1
  309. package/dist/core/action-threats.d.ts +0 -68
  310. package/dist/core/action-threats.js +0 -894
  311. package/dist/core/action-threats.js.map +0 -1
  312. package/dist/core/agent-notifications.d.ts +0 -79
  313. package/dist/core/agent-notifications.js +0 -125
  314. package/dist/core/agent-notifications.js.map +0 -1
  315. package/dist/core/agent-session/helpers.d.ts +0 -26
  316. package/dist/core/agent-session/helpers.js +0 -47
  317. package/dist/core/agent-session/helpers.js.map +0 -1
  318. package/dist/core/agent-session/mcp-tools.d.ts +0 -87
  319. package/dist/core/agent-session/mcp-tools.js +0 -227
  320. package/dist/core/agent-session/mcp-tools.js.map +0 -1
  321. package/dist/core/agent-session/run-loop-monitor.d.ts +0 -63
  322. package/dist/core/agent-session/run-loop-monitor.js +0 -164
  323. package/dist/core/agent-session/run-loop-monitor.js.map +0 -1
  324. package/dist/core/agent-session/transcript-markers.d.ts +0 -57
  325. package/dist/core/agent-session/transcript-markers.js +0 -166
  326. package/dist/core/agent-session/transcript-markers.js.map +0 -1
  327. package/dist/core/agent-session/verification-tracker.d.ts +0 -71
  328. package/dist/core/agent-session/verification-tracker.js +0 -295
  329. package/dist/core/agent-session/verification-tracker.js.map +0 -1
  330. package/dist/core/agent-session.d.ts +0 -1398
  331. package/dist/core/agent-session.js +0 -5123
  332. package/dist/core/agent-session.js.map +0 -1
  333. package/dist/core/agents.d.ts +0 -63
  334. package/dist/core/agents.js +0 -160
  335. package/dist/core/agents.js.map +0 -1
  336. package/dist/core/ask-user.d.ts +0 -163
  337. package/dist/core/ask-user.js +0 -178
  338. package/dist/core/ask-user.js.map +0 -1
  339. package/dist/core/auth/index.d.ts +0 -11
  340. package/dist/core/auth/index.js +0 -11
  341. package/dist/core/auth/index.js.map +0 -1
  342. package/dist/core/auth-providers.d.ts +0 -2
  343. package/dist/core/auth-providers.js +0 -5
  344. package/dist/core/auth-providers.js.map +0 -1
  345. package/dist/core/auth-storage.d.ts +0 -1
  346. package/dist/core/auth-storage.js +0 -4
  347. package/dist/core/auth-storage.js.map +0 -1
  348. package/dist/core/auto-update.d.ts +0 -6
  349. package/dist/core/auto-update.js +0 -15
  350. package/dist/core/auto-update.js.map +0 -1
  351. package/dist/core/autopilot-cycle.d.ts +0 -127
  352. package/dist/core/autopilot-cycle.js +0 -182
  353. package/dist/core/autopilot-cycle.js.map +0 -1
  354. package/dist/core/autopilot-gate.d.ts +0 -106
  355. package/dist/core/autopilot-gate.js +0 -192
  356. package/dist/core/autopilot-gate.js.map +0 -1
  357. package/dist/core/autopilot-verdict.d.ts +0 -55
  358. package/dist/core/autopilot-verdict.js +0 -226
  359. package/dist/core/autopilot-verdict.js.map +0 -1
  360. package/dist/core/blocked-packages-file.d.ts +0 -33
  361. package/dist/core/blocked-packages-file.js +0 -274
  362. package/dist/core/blocked-packages-file.js.map +0 -1
  363. package/dist/core/bundled-agents.d.ts +0 -2
  364. package/dist/core/bundled-agents.js +0 -253
  365. package/dist/core/bundled-agents.js.map +0 -1
  366. package/dist/core/cache-diagnostics.d.ts +0 -72
  367. package/dist/core/cache-diagnostics.js +0 -200
  368. package/dist/core/cache-diagnostics.js.map +0 -1
  369. package/dist/core/cache-expiry.d.ts +0 -89
  370. package/dist/core/cache-expiry.js +0 -117
  371. package/dist/core/cache-expiry.js.map +0 -1
  372. package/dist/core/checklist-detection.d.ts +0 -11
  373. package/dist/core/checklist-detection.js +0 -238
  374. package/dist/core/checklist-detection.js.map +0 -1
  375. package/dist/core/checklist-git.d.ts +0 -19
  376. package/dist/core/checklist-git.js +0 -54
  377. package/dist/core/checklist-git.js.map +0 -1
  378. package/dist/core/checklist-items.d.ts +0 -181
  379. package/dist/core/checklist-items.js +0 -230
  380. package/dist/core/checklist-items.js.map +0 -1
  381. package/dist/core/checklist-prompt.d.ts +0 -14
  382. package/dist/core/checklist-prompt.js +0 -64
  383. package/dist/core/checklist-prompt.js.map +0 -1
  384. package/dist/core/checklist-snapshot.d.ts +0 -17
  385. package/dist/core/checklist-snapshot.js +0 -46
  386. package/dist/core/checklist-snapshot.js.map +0 -1
  387. package/dist/core/checklist-store.d.ts +0 -63
  388. package/dist/core/checklist-store.js +0 -273
  389. package/dist/core/checklist-store.js.map +0 -1
  390. package/dist/core/checkout-record.d.ts +0 -22
  391. package/dist/core/checkout-record.js +0 -68
  392. package/dist/core/checkout-record.js.map +0 -1
  393. package/dist/core/checkpoint-store.d.ts +0 -109
  394. package/dist/core/checkpoint-store.js +0 -260
  395. package/dist/core/checkpoint-store.js.map +0 -1
  396. package/dist/core/claude-code/complete.d.ts +0 -35
  397. package/dist/core/claude-code/complete.js +0 -125
  398. package/dist/core/claude-code/complete.js.map +0 -1
  399. package/dist/core/claude-code/events.d.ts +0 -67
  400. package/dist/core/claude-code/events.js +0 -460
  401. package/dist/core/claude-code/events.js.map +0 -1
  402. package/dist/core/claude-code/live-session.d.ts +0 -94
  403. package/dist/core/claude-code/live-session.js +0 -525
  404. package/dist/core/claude-code/live-session.js.map +0 -1
  405. package/dist/core/claude-code/loop.d.ts +0 -9
  406. package/dist/core/claude-code/loop.js +0 -15
  407. package/dist/core/claude-code/loop.js.map +0 -1
  408. package/dist/core/claude-code/session-sync.d.ts +0 -28
  409. package/dist/core/claude-code/session-sync.js +0 -53
  410. package/dist/core/claude-code/session-sync.js.map +0 -1
  411. package/dist/core/claude-code/tool-bridge.d.ts +0 -49
  412. package/dist/core/claude-code/tool-bridge.js +0 -352
  413. package/dist/core/claude-code/tool-bridge.js.map +0 -1
  414. package/dist/core/claude-code/transcripts.d.ts +0 -39
  415. package/dist/core/claude-code/transcripts.js +0 -195
  416. package/dist/core/claude-code/transcripts.js.map +0 -1
  417. package/dist/core/code-retrieval-chunkers.d.ts +0 -26
  418. package/dist/core/code-retrieval-chunkers.js +0 -264
  419. package/dist/core/code-retrieval-chunkers.js.map +0 -1
  420. package/dist/core/code-retrieval.d.ts +0 -18
  421. package/dist/core/code-retrieval.js +0 -124
  422. package/dist/core/code-retrieval.js.map +0 -1
  423. package/dist/core/codex-request-shape.d.ts +0 -7
  424. package/dist/core/codex-request-shape.js +0 -19
  425. package/dist/core/codex-request-shape.js.map +0 -1
  426. package/dist/core/compaction/active-context.d.ts +0 -16
  427. package/dist/core/compaction/active-context.js +0 -20
  428. package/dist/core/compaction/active-context.js.map +0 -1
  429. package/dist/core/compaction/compactor.d.ts +0 -281
  430. package/dist/core/compaction/compactor.js +0 -1452
  431. package/dist/core/compaction/compactor.js.map +0 -1
  432. package/dist/core/compaction/plan-step-policy.d.ts +0 -46
  433. package/dist/core/compaction/plan-step-policy.js +0 -57
  434. package/dist/core/compaction/plan-step-policy.js.map +0 -1
  435. package/dist/core/compaction/policy.d.ts +0 -36
  436. package/dist/core/compaction/policy.js +0 -144
  437. package/dist/core/compaction/policy.js.map +0 -1
  438. package/dist/core/compaction/query-aware-selector.d.ts +0 -32
  439. package/dist/core/compaction/query-aware-selector.js +0 -202
  440. package/dist/core/compaction/query-aware-selector.js.map +0 -1
  441. package/dist/core/compaction/token-estimator.d.ts +0 -36
  442. package/dist/core/compaction/token-estimator.js +0 -180
  443. package/dist/core/compaction/token-estimator.js.map +0 -1
  444. package/dist/core/compaction/tool-result-pruner.d.ts +0 -90
  445. package/dist/core/compaction/tool-result-pruner.js +0 -238
  446. package/dist/core/compaction/tool-result-pruner.js.map +0 -1
  447. package/dist/core/completion-review.d.ts +0 -24
  448. package/dist/core/completion-review.js +0 -2
  449. package/dist/core/completion-review.js.map +0 -1
  450. package/dist/core/context-files.d.ts +0 -8
  451. package/dist/core/context-files.js +0 -46
  452. package/dist/core/context-files.js.map +0 -1
  453. package/dist/core/context-limits.d.ts +0 -40
  454. package/dist/core/context-limits.js +0 -43
  455. package/dist/core/context-limits.js.map +0 -1
  456. package/dist/core/custom-commands.d.ts +0 -18
  457. package/dist/core/custom-commands.js +0 -57
  458. package/dist/core/custom-commands.js.map +0 -1
  459. package/dist/core/destructive-git-guard.d.ts +0 -113
  460. package/dist/core/destructive-git-guard.js +0 -874
  461. package/dist/core/destructive-git-guard.js.map +0 -1
  462. package/dist/core/encode-cwd.d.ts +0 -41
  463. package/dist/core/encode-cwd.js +0 -53
  464. package/dist/core/encode-cwd.js.map +0 -1
  465. package/dist/core/env-delta.d.ts +0 -34
  466. package/dist/core/env-delta.js +0 -84
  467. package/dist/core/env-delta.js.map +0 -1
  468. package/dist/core/event-bus.d.ts +0 -178
  469. package/dist/core/event-bus.js +0 -171
  470. package/dist/core/event-bus.js.map +0 -1
  471. package/dist/core/extensions/loader.d.ts +0 -7
  472. package/dist/core/extensions/loader.js +0 -68
  473. package/dist/core/extensions/loader.js.map +0 -1
  474. package/dist/core/extensions/plugin-bundles.d.ts +0 -13
  475. package/dist/core/extensions/plugin-bundles.js +0 -45
  476. package/dist/core/extensions/plugin-bundles.js.map +0 -1
  477. package/dist/core/extensions/types.d.ts +0 -18
  478. package/dist/core/extensions/types.js +0 -2
  479. package/dist/core/extensions/types.js.map +0 -1
  480. package/dist/core/foreign-session-import.d.ts +0 -119
  481. package/dist/core/foreign-session-import.js +0 -598
  482. package/dist/core/foreign-session-import.js.map +0 -1
  483. package/dist/core/foreign-transcript-blocks.d.ts +0 -50
  484. package/dist/core/foreign-transcript-blocks.js +0 -151
  485. package/dist/core/foreign-transcript-blocks.js.map +0 -1
  486. package/dist/core/frontmatter.d.ts +0 -22
  487. package/dist/core/frontmatter.js +0 -90
  488. package/dist/core/frontmatter.js.map +0 -1
  489. package/dist/core/goal-run-marker.d.ts +0 -32
  490. package/dist/core/goal-run-marker.js +0 -178
  491. package/dist/core/goal-run-marker.js.map +0 -1
  492. package/dist/core/goal-summary.d.ts +0 -32
  493. package/dist/core/goal-summary.js +0 -110
  494. package/dist/core/goal-summary.js.map +0 -1
  495. package/dist/core/goals-store.d.ts +0 -215
  496. package/dist/core/goals-store.js +0 -577
  497. package/dist/core/goals-store.js.map +0 -1
  498. package/dist/core/hashline.d.ts +0 -51
  499. package/dist/core/hashline.js +0 -76
  500. package/dist/core/hashline.js.map +0 -1
  501. package/dist/core/idle-wake.d.ts +0 -62
  502. package/dist/core/idle-wake.js +0 -103
  503. package/dist/core/idle-wake.js.map +0 -1
  504. package/dist/core/index.d.ts +0 -14
  505. package/dist/core/index.js +0 -14
  506. package/dist/core/index.js.map +0 -1
  507. package/dist/core/injection-detect.d.ts +0 -39
  508. package/dist/core/injection-detect.js +0 -241
  509. package/dist/core/injection-detect.js.map +0 -1
  510. package/dist/core/installed-threats.d.ts +0 -23
  511. package/dist/core/installed-threats.js +0 -71
  512. package/dist/core/installed-threats.js.map +0 -1
  513. package/dist/core/internal-diagnostics.d.ts +0 -159
  514. package/dist/core/internal-diagnostics.js +0 -495
  515. package/dist/core/internal-diagnostics.js.map +0 -1
  516. package/dist/core/keep-awake.d.ts +0 -88
  517. package/dist/core/keep-awake.js +0 -251
  518. package/dist/core/keep-awake.js.map +0 -1
  519. package/dist/core/ken-ask-answer.d.ts +0 -24
  520. package/dist/core/ken-ask-answer.js +0 -96
  521. package/dist/core/ken-ask-answer.js.map +0 -1
  522. package/dist/core/ken-context.d.ts +0 -119
  523. package/dist/core/ken-context.js +0 -447
  524. package/dist/core/ken-context.js.map +0 -1
  525. package/dist/core/ken-model.d.ts +0 -45
  526. package/dist/core/ken-model.js +0 -26
  527. package/dist/core/ken-model.js.map +0 -1
  528. package/dist/core/ken-prompt.d.ts +0 -21
  529. package/dist/core/ken-prompt.js +0 -370
  530. package/dist/core/ken-prompt.js.map +0 -1
  531. package/dist/core/language-detector.d.ts +0 -41
  532. package/dist/core/language-detector.js +0 -293
  533. package/dist/core/language-detector.js.map +0 -1
  534. package/dist/core/live-preview.d.ts +0 -26
  535. package/dist/core/live-preview.js +0 -80
  536. package/dist/core/live-preview.js.map +0 -1
  537. package/dist/core/local-endpoint-store.d.ts +0 -53
  538. package/dist/core/local-endpoint-store.js +0 -221
  539. package/dist/core/local-endpoint-store.js.map +0 -1
  540. package/dist/core/logger.d.ts +0 -22
  541. package/dist/core/logger.js +0 -95
  542. package/dist/core/logger.js.map +0 -1
  543. package/dist/core/loop-breaker.d.ts +0 -89
  544. package/dist/core/loop-breaker.js +0 -204
  545. package/dist/core/loop-breaker.js.map +0 -1
  546. package/dist/core/lsp/client.d.ts +0 -206
  547. package/dist/core/lsp/client.js +0 -685
  548. package/dist/core/lsp/client.js.map +0 -1
  549. package/dist/core/lsp/edit-telemetry.d.ts +0 -26
  550. package/dist/core/lsp/edit-telemetry.js +0 -52
  551. package/dist/core/lsp/edit-telemetry.js.map +0 -1
  552. package/dist/core/lsp/format.d.ts +0 -11
  553. package/dist/core/lsp/format.js +0 -30
  554. package/dist/core/lsp/format.js.map +0 -1
  555. package/dist/core/lsp/jsonrpc.d.ts +0 -68
  556. package/dist/core/lsp/jsonrpc.js +0 -153
  557. package/dist/core/lsp/jsonrpc.js.map +0 -1
  558. package/dist/core/lsp/manager.d.ts +0 -188
  559. package/dist/core/lsp/manager.js +0 -576
  560. package/dist/core/lsp/manager.js.map +0 -1
  561. package/dist/core/lsp/pool.d.ts +0 -114
  562. package/dist/core/lsp/pool.js +0 -259
  563. package/dist/core/lsp/pool.js.map +0 -1
  564. package/dist/core/lsp/project-root.d.ts +0 -9
  565. package/dist/core/lsp/project-root.js +0 -75
  566. package/dist/core/lsp/project-root.js.map +0 -1
  567. package/dist/core/lsp/reference-project.d.ts +0 -6
  568. package/dist/core/lsp/reference-project.js +0 -110
  569. package/dist/core/lsp/reference-project.js.map +0 -1
  570. package/dist/core/lsp/servers.d.ts +0 -44
  571. package/dist/core/lsp/servers.js +0 -289
  572. package/dist/core/lsp/servers.js.map +0 -1
  573. package/dist/core/lsp/test-support.d.ts +0 -17
  574. package/dist/core/lsp/test-support.js +0 -27
  575. package/dist/core/lsp/test-support.js.map +0 -1
  576. package/dist/core/mcp/catalog-cache.d.ts +0 -64
  577. package/dist/core/mcp/catalog-cache.js +0 -167
  578. package/dist/core/mcp/catalog-cache.js.map +0 -1
  579. package/dist/core/mcp/client.d.ts +0 -317
  580. package/dist/core/mcp/client.js +0 -1168
  581. package/dist/core/mcp/client.js.map +0 -1
  582. package/dist/core/mcp/content.d.ts +0 -23
  583. package/dist/core/mcp/content.js +0 -194
  584. package/dist/core/mcp/content.js.map +0 -1
  585. package/dist/core/mcp/defaults.d.ts +0 -26
  586. package/dist/core/mcp/defaults.js +0 -81
  587. package/dist/core/mcp/defaults.js.map +0 -1
  588. package/dist/core/mcp/deferred-catalog.d.ts +0 -53
  589. package/dist/core/mcp/deferred-catalog.js +0 -117
  590. package/dist/core/mcp/deferred-catalog.js.map +0 -1
  591. package/dist/core/mcp/elicitation-bridge.d.ts +0 -40
  592. package/dist/core/mcp/elicitation-bridge.js +0 -36
  593. package/dist/core/mcp/elicitation-bridge.js.map +0 -1
  594. package/dist/core/mcp/index.d.ts +0 -16
  595. package/dist/core/mcp/index.js +0 -10
  596. package/dist/core/mcp/index.js.map +0 -1
  597. package/dist/core/mcp/loopback.d.ts +0 -26
  598. package/dist/core/mcp/loopback.js +0 -66
  599. package/dist/core/mcp/loopback.js.map +0 -1
  600. package/dist/core/mcp/oauth-provider.d.ts +0 -55
  601. package/dist/core/mcp/oauth-provider.js +0 -106
  602. package/dist/core/mcp/oauth-provider.js.map +0 -1
  603. package/dist/core/mcp/oauth-store.d.ts +0 -44
  604. package/dist/core/mcp/oauth-store.js +0 -77
  605. package/dist/core/mcp/oauth-store.js.map +0 -1
  606. package/dist/core/mcp/parse-add-command.d.ts +0 -50
  607. package/dist/core/mcp/parse-add-command.js +0 -391
  608. package/dist/core/mcp/parse-add-command.js.map +0 -1
  609. package/dist/core/mcp/resolve-stdio.d.ts +0 -77
  610. package/dist/core/mcp/resolve-stdio.js +0 -359
  611. package/dist/core/mcp/resolve-stdio.js.map +0 -1
  612. package/dist/core/mcp/shared-pool.d.ts +0 -157
  613. package/dist/core/mcp/shared-pool.js +0 -236
  614. package/dist/core/mcp/shared-pool.js.map +0 -1
  615. package/dist/core/mcp/store.d.ts +0 -100
  616. package/dist/core/mcp/store.js +0 -202
  617. package/dist/core/mcp/store.js.map +0 -1
  618. package/dist/core/mcp/tool-guard.d.ts +0 -58
  619. package/dist/core/mcp/tool-guard.js +0 -215
  620. package/dist/core/mcp/tool-guard.js.map +0 -1
  621. package/dist/core/mcp/types.d.ts +0 -57
  622. package/dist/core/mcp/types.js +0 -2
  623. package/dist/core/mcp/types.js.map +0 -1
  624. package/dist/core/message-images.d.ts +0 -11
  625. package/dist/core/message-images.js +0 -52
  626. package/dist/core/message-images.js.map +0 -1
  627. package/dist/core/model-registry.d.ts +0 -1
  628. package/dist/core/model-registry.js +0 -5
  629. package/dist/core/model-registry.js.map +0 -1
  630. package/dist/core/model-unavailable.d.ts +0 -14
  631. package/dist/core/model-unavailable.js +0 -23
  632. package/dist/core/model-unavailable.js.map +0 -1
  633. package/dist/core/network-guard.d.ts +0 -28
  634. package/dist/core/network-guard.js +0 -251
  635. package/dist/core/network-guard.js.map +0 -1
  636. package/dist/core/node-debugger.d.ts +0 -148
  637. package/dist/core/node-debugger.js +0 -642
  638. package/dist/core/node-debugger.js.map +0 -1
  639. package/dist/core/oauth/openai.d.ts +0 -1
  640. package/dist/core/oauth/openai.js +0 -3
  641. package/dist/core/oauth/openai.js.map +0 -1
  642. package/dist/core/oauth/types.d.ts +0 -1
  643. package/dist/core/oauth/types.js +0 -2
  644. package/dist/core/oauth/types.js.map +0 -1
  645. package/dist/core/opencode-catalog-store.d.ts +0 -20
  646. package/dist/core/opencode-catalog-store.js +0 -82
  647. package/dist/core/opencode-catalog-store.js.map +0 -1
  648. package/dist/core/openrouter-catalog-store.d.ts +0 -24
  649. package/dist/core/openrouter-catalog-store.js +0 -140
  650. package/dist/core/openrouter-catalog-store.js.map +0 -1
  651. package/dist/core/package-cooldown.d.ts +0 -69
  652. package/dist/core/package-cooldown.js +0 -297
  653. package/dist/core/package-cooldown.js.map +0 -1
  654. package/dist/core/package-threats.d.ts +0 -92
  655. package/dist/core/package-threats.js +0 -1340
  656. package/dist/core/package-threats.js.map +0 -1
  657. package/dist/core/parked-requests.d.ts +0 -43
  658. package/dist/core/parked-requests.js +0 -34
  659. package/dist/core/parked-requests.js.map +0 -1
  660. package/dist/core/persistent-shell.d.ts +0 -81
  661. package/dist/core/persistent-shell.js +0 -452
  662. package/dist/core/persistent-shell.js.map +0 -1
  663. package/dist/core/plan-delta.d.ts +0 -23
  664. package/dist/core/plan-delta.js +0 -36
  665. package/dist/core/plan-delta.js.map +0 -1
  666. package/dist/core/plan-handoff.d.ts +0 -38
  667. package/dist/core/plan-handoff.js +0 -21
  668. package/dist/core/plan-handoff.js.map +0 -1
  669. package/dist/core/plan-submission-gate.d.ts +0 -28
  670. package/dist/core/plan-submission-gate.js +0 -27
  671. package/dist/core/plan-submission-gate.js.map +0 -1
  672. package/dist/core/platform-clis.d.ts +0 -15
  673. package/dist/core/platform-clis.js +0 -299
  674. package/dist/core/platform-clis.js.map +0 -1
  675. package/dist/core/process-gate.d.ts +0 -61
  676. package/dist/core/process-gate.js +0 -103
  677. package/dist/core/process-gate.js.map +0 -1
  678. package/dist/core/process-manager.d.ts +0 -242
  679. package/dist/core/process-manager.js +0 -902
  680. package/dist/core/process-manager.js.map +0 -1
  681. package/dist/core/progress/engine.d.ts +0 -22
  682. package/dist/core/progress/engine.js +0 -131
  683. package/dist/core/progress/engine.js.map +0 -1
  684. package/dist/core/progress/git-xp.d.ts +0 -15
  685. package/dist/core/progress/git-xp.js +0 -100
  686. package/dist/core/progress/git-xp.js.map +0 -1
  687. package/dist/core/progress/ranks.d.ts +0 -31
  688. package/dist/core/progress/ranks.js +0 -310
  689. package/dist/core/progress/ranks.js.map +0 -1
  690. package/dist/core/progress/rebuild.d.ts +0 -8
  691. package/dist/core/progress/rebuild.js +0 -125
  692. package/dist/core/progress/rebuild.js.map +0 -1
  693. package/dist/core/progress/store.d.ts +0 -34
  694. package/dist/core/progress/store.js +0 -200
  695. package/dist/core/progress/store.js.map +0 -1
  696. package/dist/core/progress/types.d.ts +0 -108
  697. package/dist/core/progress/types.js +0 -3
  698. package/dist/core/progress/types.js.map +0 -1
  699. package/dist/core/project-discovery.d.ts +0 -88
  700. package/dist/core/project-discovery.js +0 -907
  701. package/dist/core/project-discovery.js.map +0 -1
  702. package/dist/core/project-files.d.ts +0 -15
  703. package/dist/core/project-files.js +0 -37
  704. package/dist/core/project-files.js.map +0 -1
  705. package/dist/core/project-health-scan.d.ts +0 -109
  706. package/dist/core/project-health-scan.js +0 -673
  707. package/dist/core/project-health-scan.js.map +0 -1
  708. package/dist/core/project-health-score.d.ts +0 -41
  709. package/dist/core/project-health-score.js +0 -257
  710. package/dist/core/project-health-score.js.map +0 -1
  711. package/dist/core/prompt-command-expansion.d.ts +0 -13
  712. package/dist/core/prompt-command-expansion.js +0 -48
  713. package/dist/core/prompt-command-expansion.js.map +0 -1
  714. package/dist/core/prompt-commands.d.ts +0 -13
  715. package/dist/core/prompt-commands.js +0 -370
  716. package/dist/core/prompt-commands.js.map +0 -1
  717. package/dist/core/radio-players.d.ts +0 -28
  718. package/dist/core/radio-players.js +0 -133
  719. package/dist/core/radio-players.js.map +0 -1
  720. package/dist/core/radio.d.ts +0 -50
  721. package/dist/core/radio.js +0 -480
  722. package/dist/core/radio.js.map +0 -1
  723. package/dist/core/regrounding.d.ts +0 -37
  724. package/dist/core/regrounding.js +0 -89
  725. package/dist/core/regrounding.js.map +0 -1
  726. package/dist/core/resolve-start.d.ts +0 -28
  727. package/dist/core/resolve-start.js +0 -35
  728. package/dist/core/resolve-start.js.map +0 -1
  729. package/dist/core/run-claim.d.ts +0 -36
  730. package/dist/core/run-claim.js +0 -46
  731. package/dist/core/run-claim.js.map +0 -1
  732. package/dist/core/run-lifecycle.d.ts +0 -58
  733. package/dist/core/run-lifecycle.js +0 -104
  734. package/dist/core/run-lifecycle.js.map +0 -1
  735. package/dist/core/run-status.d.ts +0 -17
  736. package/dist/core/run-status.js +0 -28
  737. package/dist/core/run-status.js.map +0 -1
  738. package/dist/core/runtime-mode.d.ts +0 -21
  739. package/dist/core/runtime-mode.js +0 -43
  740. package/dist/core/runtime-mode.js.map +0 -1
  741. package/dist/core/sandbox-domains.d.ts +0 -13
  742. package/dist/core/sandbox-domains.js +0 -76
  743. package/dist/core/sandbox-domains.js.map +0 -1
  744. package/dist/core/sandbox-feedback.d.ts +0 -21
  745. package/dist/core/sandbox-feedback.js +0 -69
  746. package/dist/core/sandbox-feedback.js.map +0 -1
  747. package/dist/core/sandbox.d.ts +0 -106
  748. package/dist/core/sandbox.js +0 -383
  749. package/dist/core/sandbox.js.map +0 -1
  750. package/dist/core/semantic-loop-check.d.ts +0 -58
  751. package/dist/core/semantic-loop-check.js +0 -103
  752. package/dist/core/semantic-loop-check.js.map +0 -1
  753. package/dist/core/session-compaction.d.ts +0 -23
  754. package/dist/core/session-compaction.js +0 -54
  755. package/dist/core/session-compaction.js.map +0 -1
  756. package/dist/core/session-export.d.ts +0 -97
  757. package/dist/core/session-export.js +0 -368
  758. package/dist/core/session-export.js.map +0 -1
  759. package/dist/core/session-history.d.ts +0 -160
  760. package/dist/core/session-history.js +0 -467
  761. package/dist/core/session-history.js.map +0 -1
  762. package/dist/core/session-manager.d.ts +0 -509
  763. package/dist/core/session-manager.js +0 -1367
  764. package/dist/core/session-manager.js.map +0 -1
  765. package/dist/core/session-preview.d.ts +0 -12
  766. package/dist/core/session-preview.js +0 -58
  767. package/dist/core/session-preview.js.map +0 -1
  768. package/dist/core/session-storage.d.ts +0 -78
  769. package/dist/core/session-storage.js +0 -659
  770. package/dist/core/session-storage.js.map +0 -1
  771. package/dist/core/session-summary-index.d.ts +0 -51
  772. package/dist/core/session-summary-index.js +0 -192
  773. package/dist/core/session-summary-index.js.map +0 -1
  774. package/dist/core/settings-manager.d.ts +0 -113
  775. package/dist/core/settings-manager.js +0 -281
  776. package/dist/core/settings-manager.js.map +0 -1
  777. package/dist/core/shared-checkout-guard.d.ts +0 -78
  778. package/dist/core/shared-checkout-guard.js +0 -219
  779. package/dist/core/shared-checkout-guard.js.map +0 -1
  780. package/dist/core/shell-path.d.ts +0 -13
  781. package/dist/core/shell-path.js +0 -175
  782. package/dist/core/shell-path.js.map +0 -1
  783. package/dist/core/shell-threats-popular-packages.d.ts +0 -11
  784. package/dist/core/shell-threats-popular-packages.js +0 -675
  785. package/dist/core/shell-threats-popular-packages.js.map +0 -1
  786. package/dist/core/shell-threats.d.ts +0 -21
  787. package/dist/core/shell-threats.js +0 -235
  788. package/dist/core/shell-threats.js.map +0 -1
  789. package/dist/core/shell.d.ts +0 -54
  790. package/dist/core/shell.js +0 -99
  791. package/dist/core/shell.js.map +0 -1
  792. package/dist/core/shutdown.d.ts +0 -70
  793. package/dist/core/shutdown.js +0 -144
  794. package/dist/core/shutdown.js.map +0 -1
  795. package/dist/core/skill-scan.d.ts +0 -112
  796. package/dist/core/skill-scan.js +0 -781
  797. package/dist/core/skill-scan.js.map +0 -1
  798. package/dist/core/skills.d.ts +0 -100
  799. package/dist/core/skills.js +0 -299
  800. package/dist/core/skills.js.map +0 -1
  801. package/dist/core/slash-commands.d.ts +0 -58
  802. package/dist/core/slash-commands.js +0 -242
  803. package/dist/core/slash-commands.js.map +0 -1
  804. package/dist/core/steering.d.ts +0 -47
  805. package/dist/core/steering.js +0 -65
  806. package/dist/core/steering.js.map +0 -1
  807. package/dist/core/steroids.d.ts +0 -66
  808. package/dist/core/steroids.js +0 -243
  809. package/dist/core/steroids.js.map +0 -1
  810. package/dist/core/stream-diag-level.d.ts +0 -3
  811. package/dist/core/stream-diag-level.js +0 -24
  812. package/dist/core/stream-diag-level.js.map +0 -1
  813. package/dist/core/stream-rules.d.ts +0 -30
  814. package/dist/core/stream-rules.js +0 -151
  815. package/dist/core/stream-rules.js.map +0 -1
  816. package/dist/core/subagent-manager.d.ts +0 -239
  817. package/dist/core/subagent-manager.js +0 -1060
  818. package/dist/core/subagent-manager.js.map +0 -1
  819. package/dist/core/subagent-policy.d.ts +0 -9
  820. package/dist/core/subagent-policy.js +0 -41
  821. package/dist/core/subagent-policy.js.map +0 -1
  822. package/dist/core/subagent-receipt.d.ts +0 -54
  823. package/dist/core/subagent-receipt.js +0 -274
  824. package/dist/core/subagent-receipt.js.map +0 -1
  825. package/dist/core/subagent-store.d.ts +0 -41
  826. package/dist/core/subagent-store.js +0 -284
  827. package/dist/core/subagent-store.js.map +0 -1
  828. package/dist/core/subagent-turn-record.d.ts +0 -18
  829. package/dist/core/subagent-turn-record.js +0 -82
  830. package/dist/core/subagent-turn-record.js.map +0 -1
  831. package/dist/core/tasks-store.d.ts +0 -31
  832. package/dist/core/tasks-store.js +0 -97
  833. package/dist/core/tasks-store.js.map +0 -1
  834. package/dist/core/telegram-config.d.ts +0 -20
  835. package/dist/core/telegram-config.js +0 -52
  836. package/dist/core/telegram-config.js.map +0 -1
  837. package/dist/core/telegram.d.ts +0 -1
  838. package/dist/core/telegram.js +0 -3
  839. package/dist/core/telegram.js.map +0 -1
  840. package/dist/core/temp-paths.d.ts +0 -5
  841. package/dist/core/temp-paths.js +0 -50
  842. package/dist/core/temp-paths.js.map +0 -1
  843. package/dist/core/test-impact.d.ts +0 -73
  844. package/dist/core/test-impact.js +0 -467
  845. package/dist/core/test-impact.js.map +0 -1
  846. package/dist/core/thinking-level.d.ts +0 -1
  847. package/dist/core/thinking-level.js +0 -4
  848. package/dist/core/thinking-level.js.map +0 -1
  849. package/dist/core/threat-feed.d.ts +0 -65
  850. package/dist/core/threat-feed.js +0 -335
  851. package/dist/core/threat-feed.js.map +0 -1
  852. package/dist/core/trophies/catalog-more.d.ts +0 -2
  853. package/dist/core/trophies/catalog-more.js +0 -837
  854. package/dist/core/trophies/catalog-more.js.map +0 -1
  855. package/dist/core/trophies/catalog.d.ts +0 -4
  856. package/dist/core/trophies/catalog.js +0 -649
  857. package/dist/core/trophies/catalog.js.map +0 -1
  858. package/dist/core/trophies/engine.d.ts +0 -70
  859. package/dist/core/trophies/engine.js +0 -347
  860. package/dist/core/trophies/engine.js.map +0 -1
  861. package/dist/core/trophies/store.d.ts +0 -17
  862. package/dist/core/trophies/store.js +0 -113
  863. package/dist/core/trophies/store.js.map +0 -1
  864. package/dist/core/trophies/types.d.ts +0 -119
  865. package/dist/core/trophies/types.js +0 -76
  866. package/dist/core/trophies/types.js.map +0 -1
  867. package/dist/core/ui-adoption.d.ts +0 -32
  868. package/dist/core/ui-adoption.js +0 -302
  869. package/dist/core/ui-adoption.js.map +0 -1
  870. package/dist/core/ui-compatibility.d.ts +0 -10
  871. package/dist/core/ui-compatibility.js +0 -51
  872. package/dist/core/ui-compatibility.js.map +0 -1
  873. package/dist/core/ui-registry.d.ts +0 -101
  874. package/dist/core/ui-registry.js +0 -292
  875. package/dist/core/ui-registry.js.map +0 -1
  876. package/dist/core/user-shell-context.d.ts +0 -8
  877. package/dist/core/user-shell-context.js +0 -12
  878. package/dist/core/user-shell-context.js.map +0 -1
  879. package/dist/core/verification-evidence.d.ts +0 -49
  880. package/dist/core/verification-evidence.js +0 -816
  881. package/dist/core/verification-evidence.js.map +0 -1
  882. package/dist/core/verification-gate.d.ts +0 -77
  883. package/dist/core/verification-gate.js +0 -504
  884. package/dist/core/verification-gate.js.map +0 -1
  885. package/dist/core/verification-snapshot.d.ts +0 -7
  886. package/dist/core/verification-snapshot.js +0 -109
  887. package/dist/core/verification-snapshot.js.map +0 -1
  888. package/dist/core/verify-commands.d.ts +0 -34
  889. package/dist/core/verify-commands.js +0 -203
  890. package/dist/core/verify-commands.js.map +0 -1
  891. package/dist/core/voice-transcriber.d.ts +0 -1
  892. package/dist/core/voice-transcriber.js +0 -4
  893. package/dist/core/voice-transcriber.js.map +0 -1
  894. package/dist/core/workspace-guard.d.ts +0 -56
  895. package/dist/core/workspace-guard.js +0 -334
  896. package/dist/core/workspace-guard.js.map +0 -1
  897. package/dist/session.d.ts +0 -44
  898. package/dist/session.js +0 -105
  899. package/dist/session.js.map +0 -1
  900. package/dist/system-prompt.d.ts +0 -104
  901. package/dist/system-prompt.js +0 -480
  902. package/dist/system-prompt.js.map +0 -1
  903. package/dist/test-support/fake-home.d.ts +0 -19
  904. package/dist/test-support/fake-home.js +0 -37
  905. package/dist/test-support/fake-home.js.map +0 -1
  906. package/dist/test-support/keep-alive.d.ts +0 -14
  907. package/dist/test-support/keep-alive.js +0 -17
  908. package/dist/test-support/keep-alive.js.map +0 -1
  909. package/dist/test-support/slow-git.d.ts +0 -1
  910. package/dist/test-support/slow-git.js +0 -21
  911. package/dist/test-support/slow-git.js.map +0 -1
  912. package/dist/test-support/system-tools.d.ts +0 -6
  913. package/dist/test-support/system-tools.js +0 -36
  914. package/dist/test-support/system-tools.js.map +0 -1
  915. package/dist/tools/ask-user.d.ts +0 -34
  916. package/dist/tools/ask-user.js +0 -99
  917. package/dist/tools/ask-user.js.map +0 -1
  918. package/dist/tools/background-watch-lint.d.ts +0 -18
  919. package/dist/tools/background-watch-lint.js +0 -102
  920. package/dist/tools/background-watch-lint.js.map +0 -1
  921. package/dist/tools/bash-read-evidence.d.ts +0 -23
  922. package/dist/tools/bash-read-evidence.js +0 -180
  923. package/dist/tools/bash-read-evidence.js.map +0 -1
  924. package/dist/tools/bash.d.ts +0 -64
  925. package/dist/tools/bash.js +0 -552
  926. package/dist/tools/bash.js.map +0 -1
  927. package/dist/tools/browser-api.d.ts +0 -27
  928. package/dist/tools/browser-api.js +0 -449
  929. package/dist/tools/browser-api.js.map +0 -1
  930. package/dist/tools/browser-sandbox.d.ts +0 -16
  931. package/dist/tools/browser-sandbox.js +0 -158
  932. package/dist/tools/browser-sandbox.js.map +0 -1
  933. package/dist/tools/browser-session.d.ts +0 -84
  934. package/dist/tools/browser-session.js +0 -304
  935. package/dist/tools/browser-session.js.map +0 -1
  936. package/dist/tools/browser-snapshot.d.ts +0 -19
  937. package/dist/tools/browser-snapshot.js +0 -109
  938. package/dist/tools/browser-snapshot.js.map +0 -1
  939. package/dist/tools/browser.d.ts +0 -11
  940. package/dist/tools/browser.js +0 -106
  941. package/dist/tools/browser.js.map +0 -1
  942. package/dist/tools/checklist.d.ts +0 -49
  943. package/dist/tools/checklist.js +0 -154
  944. package/dist/tools/checklist.js.map +0 -1
  945. package/dist/tools/compress.d.ts +0 -56
  946. package/dist/tools/compress.js +0 -226
  947. package/dist/tools/compress.js.map +0 -1
  948. package/dist/tools/debug.d.ts +0 -54
  949. package/dist/tools/debug.js +0 -230
  950. package/dist/tools/debug.js.map +0 -1
  951. package/dist/tools/document-text.d.ts +0 -6
  952. package/dist/tools/document-text.js +0 -154
  953. package/dist/tools/document-text.js.map +0 -1
  954. package/dist/tools/edit-diff.d.ts +0 -123
  955. package/dist/tools/edit-diff.js +0 -476
  956. package/dist/tools/edit-diff.js.map +0 -1
  957. package/dist/tools/edit-targets.d.ts +0 -10
  958. package/dist/tools/edit-targets.js +0 -31
  959. package/dist/tools/edit-targets.js.map +0 -1
  960. package/dist/tools/edit.d.ts +0 -38
  961. package/dist/tools/edit.js +0 -695
  962. package/dist/tools/edit.js.map +0 -1
  963. package/dist/tools/enter-plan.d.ts +0 -7
  964. package/dist/tools/enter-plan.js +0 -20
  965. package/dist/tools/enter-plan.js.map +0 -1
  966. package/dist/tools/exit-plan.d.ts +0 -7
  967. package/dist/tools/exit-plan.js +0 -51
  968. package/dist/tools/exit-plan.js.map +0 -1
  969. package/dist/tools/find.d.ts +0 -17
  970. package/dist/tools/find.js +0 -100
  971. package/dist/tools/find.js.map +0 -1
  972. package/dist/tools/generate-image.d.ts +0 -83
  973. package/dist/tools/generate-image.js +0 -625
  974. package/dist/tools/generate-image.js.map +0 -1
  975. package/dist/tools/grep-scan.d.ts +0 -96
  976. package/dist/tools/grep-scan.js +0 -283
  977. package/dist/tools/grep-scan.js.map +0 -1
  978. package/dist/tools/grep.d.ts +0 -48
  979. package/dist/tools/grep.js +0 -1013
  980. package/dist/tools/grep.js.map +0 -1
  981. package/dist/tools/html-extract.d.ts +0 -57
  982. package/dist/tools/html-extract.js +0 -130
  983. package/dist/tools/html-extract.js.map +0 -1
  984. package/dist/tools/index.d.ts +0 -198
  985. package/dist/tools/index.js +0 -216
  986. package/dist/tools/index.js.map +0 -1
  987. package/dist/tools/live-preview.d.ts +0 -23
  988. package/dist/tools/live-preview.js +0 -41
  989. package/dist/tools/live-preview.js.map +0 -1
  990. package/dist/tools/ls.d.ts +0 -9
  991. package/dist/tools/ls.js +0 -59
  992. package/dist/tools/ls.js.map +0 -1
  993. package/dist/tools/operations.d.ts +0 -86
  994. package/dist/tools/operations.js +0 -117
  995. package/dist/tools/operations.js.map +0 -1
  996. package/dist/tools/overflow.d.ts +0 -17
  997. package/dist/tools/overflow.js +0 -68
  998. package/dist/tools/overflow.js.map +0 -1
  999. package/dist/tools/path-utils.d.ts +0 -30
  1000. package/dist/tools/path-utils.js +0 -74
  1001. package/dist/tools/path-utils.js.map +0 -1
  1002. package/dist/tools/pdf-extract.d.ts +0 -17
  1003. package/dist/tools/pdf-extract.js +0 -43
  1004. package/dist/tools/pdf-extract.js.map +0 -1
  1005. package/dist/tools/prompt-hints.d.ts +0 -46
  1006. package/dist/tools/prompt-hints.js +0 -171
  1007. package/dist/tools/prompt-hints.js.map +0 -1
  1008. package/dist/tools/read-only-bash.d.ts +0 -31
  1009. package/dist/tools/read-only-bash.js +0 -338
  1010. package/dist/tools/read-only-bash.js.map +0 -1
  1011. package/dist/tools/read-tracker.d.ts +0 -43
  1012. package/dist/tools/read-tracker.js +0 -120
  1013. package/dist/tools/read-tracker.js.map +0 -1
  1014. package/dist/tools/read.d.ts +0 -18
  1015. package/dist/tools/read.js +0 -316
  1016. package/dist/tools/read.js.map +0 -1
  1017. package/dist/tools/redaction-guard.d.ts +0 -10
  1018. package/dist/tools/redaction-guard.js +0 -55
  1019. package/dist/tools/redaction-guard.js.map +0 -1
  1020. package/dist/tools/routine-output.d.ts +0 -39
  1021. package/dist/tools/routine-output.js +0 -281
  1022. package/dist/tools/routine-output.js.map +0 -1
  1023. package/dist/tools/safe-env.d.ts +0 -1
  1024. package/dist/tools/safe-env.js +0 -79
  1025. package/dist/tools/safe-env.js.map +0 -1
  1026. package/dist/tools/session-stats.d.ts +0 -26
  1027. package/dist/tools/session-stats.js +0 -51
  1028. package/dist/tools/session-stats.js.map +0 -1
  1029. package/dist/tools/side-web-search.d.ts +0 -34
  1030. package/dist/tools/side-web-search.js +0 -146
  1031. package/dist/tools/side-web-search.js.map +0 -1
  1032. package/dist/tools/skill.d.ts +0 -12
  1033. package/dist/tools/skill.js +0 -94
  1034. package/dist/tools/skill.js.map +0 -1
  1035. package/dist/tools/source-path.d.ts +0 -8
  1036. package/dist/tools/source-path.js +0 -128
  1037. package/dist/tools/source-path.js.map +0 -1
  1038. package/dist/tools/steroids.d.ts +0 -44
  1039. package/dist/tools/steroids.js +0 -356
  1040. package/dist/tools/steroids.js.map +0 -1
  1041. package/dist/tools/subagent-control.d.ts +0 -5
  1042. package/dist/tools/subagent-control.js +0 -211
  1043. package/dist/tools/subagent-control.js.map +0 -1
  1044. package/dist/tools/subagent-shared.d.ts +0 -110
  1045. package/dist/tools/subagent-shared.js +0 -180
  1046. package/dist/tools/subagent-shared.js.map +0 -1
  1047. package/dist/tools/subagent.d.ts +0 -37
  1048. package/dist/tools/subagent.js +0 -406
  1049. package/dist/tools/subagent.js.map +0 -1
  1050. package/dist/tools/task-output.d.ts +0 -10
  1051. package/dist/tools/task-output.js +0 -74
  1052. package/dist/tools/task-output.js.map +0 -1
  1053. package/dist/tools/task-send.d.ts +0 -11
  1054. package/dist/tools/task-send.js +0 -36
  1055. package/dist/tools/task-send.js.map +0 -1
  1056. package/dist/tools/task-stop.d.ts +0 -8
  1057. package/dist/tools/task-stop.js +0 -15
  1058. package/dist/tools/task-stop.js.map +0 -1
  1059. package/dist/tools/tasks.d.ts +0 -15
  1060. package/dist/tools/tasks.js +0 -94
  1061. package/dist/tools/tasks.js.map +0 -1
  1062. package/dist/tools/tool-search.d.ts +0 -26
  1063. package/dist/tools/tool-search.js +0 -81
  1064. package/dist/tools/tool-search.js.map +0 -1
  1065. package/dist/tools/tool-tiers.d.ts +0 -65
  1066. package/dist/tools/tool-tiers.js +0 -121
  1067. package/dist/tools/tool-tiers.js.map +0 -1
  1068. package/dist/tools/truncate.d.ts +0 -39
  1069. package/dist/tools/truncate.js +0 -242
  1070. package/dist/tools/truncate.js.map +0 -1
  1071. package/dist/tools/ui-adopt.d.ts +0 -16
  1072. package/dist/tools/ui-adopt.js +0 -66
  1073. package/dist/tools/ui-adopt.js.map +0 -1
  1074. package/dist/tools/ui-registry.d.ts +0 -15
  1075. package/dist/tools/ui-registry.js +0 -39
  1076. package/dist/tools/ui-registry.js.map +0 -1
  1077. package/dist/tools/verification-review.d.ts +0 -2
  1078. package/dist/tools/verification-review.js +0 -41
  1079. package/dist/tools/verification-review.js.map +0 -1
  1080. package/dist/tools/web-fetch.d.ts +0 -52
  1081. package/dist/tools/web-fetch.js +0 -986
  1082. package/dist/tools/web-fetch.js.map +0 -1
  1083. package/dist/tools/web-search.d.ts +0 -35
  1084. package/dist/tools/web-search.js +0 -926
  1085. package/dist/tools/web-search.js.map +0 -1
  1086. package/dist/tools/write.d.ts +0 -16
  1087. package/dist/tools/write.js +0 -196
  1088. package/dist/tools/write.js.map +0 -1
  1089. package/dist/types.d.ts +0 -44
  1090. package/dist/types.js +0 -2
  1091. package/dist/types.js.map +0 -1
  1092. package/dist/utils/git.d.ts +0 -102
  1093. package/dist/utils/git.js +0 -325
  1094. package/dist/utils/git.js.map +0 -1
  1095. package/dist/utils/github-ci.d.ts +0 -18
  1096. package/dist/utils/github-ci.js +0 -138
  1097. package/dist/utils/github-ci.js.map +0 -1
  1098. package/dist/utils/github.d.ts +0 -19
  1099. package/dist/utils/github.js +0 -67
  1100. package/dist/utils/github.js.map +0 -1
  1101. package/dist/utils/image.d.ts +0 -166
  1102. package/dist/utils/image.js +0 -673
  1103. package/dist/utils/image.js.map +0 -1
  1104. package/dist/utils/open-browser.d.ts +0 -13
  1105. package/dist/utils/open-browser.js +0 -31
  1106. package/dist/utils/open-browser.js.map +0 -1
  1107. package/dist/utils/plan-steps.d.ts +0 -90
  1108. package/dist/utils/plan-steps.js +0 -209
  1109. package/dist/utils/plan-steps.js.map +0 -1
  1110. package/dist/utils/process.d.ts +0 -48
  1111. package/dist/utils/process.js +0 -175
  1112. package/dist/utils/process.js.map +0 -1
  1113. package/dist/utils/prompt-enhancer.d.ts +0 -53
  1114. package/dist/utils/prompt-enhancer.js +0 -178
  1115. package/dist/utils/prompt-enhancer.js.map +0 -1
  1116. package/dist/utils/text.d.ts +0 -61
  1117. package/dist/utils/text.js +0 -68
  1118. package/dist/utils/text.js.map +0 -1
  1119. package/dist/web.d.ts +0 -5
  1120. package/dist/web.js +0 -5
  1121. package/dist/web.js.map +0 -1
@@ -1,1340 +0,0 @@
1
- /**
2
- * Package-install guard. Blocks only on concrete signals; everything else
3
- * passes silently. A catch is a block with one plain line for the agent.
4
- *
5
- * - Known malware: local threat feed (instant) + OSV querybatch with the exact
6
- * version that would install (name-only queries flag every package that
7
- * ever had one bad release, e.g. chalk/debug).
8
- * - Lockfile installs (`npm ci`, `pnpm install`, `uv sync`, …): every locked
9
- * name@version, cached by lockfile hash.
10
- * - Release age when the manager has no native cooldown (P3).
11
- * - Provenance downgrade: previous version had attestations, this one not (P4).
12
- * - Typosquat: one edit from a popular name AND new / missing / barely used (P5).
13
- *
14
- * Network only for install commands, parallel, one ≤2.5 s deadline, fail-open.
15
- * Clean answers are cached on disk (package-verdicts.json in the GG dir).
16
- */
17
- import { createHash } from "node:crypto";
18
- import fsp from "node:fs/promises";
19
- import { getAppPaths } from "@kenkaiiii/gg-core";
20
- import path from "node:path";
21
- import { log } from "./logger.js";
22
- import { POPULAR_NPM_PACKAGES, POPULAR_PYPI_PACKAGES } from "./shell-threats-popular-packages.js";
23
- import { SAFETY_BLOCK_NOTE } from "./action-threats.js";
24
- import { compareVersions, emptyFeed, feedMatches, loadThreatFeed, writeJsonAtomic, } from "./threat-feed.js";
25
- import { hasNativeCooldown, managerVersion, usesCustomNpmRegistry, usesCustomPypiIndex, } from "./package-cooldown.js";
26
- const OSV_URL = "https://api.osv.dev/v1/querybatch";
27
- /** Full advisories for one version (severity + fixed versions); only asked when flawed. */
28
- const OSV_QUERY_URL = "https://api.osv.dev/v1/query";
29
- const NPM_REGISTRY = "https://registry.npmjs.org";
30
- const NPM_DOWNLOADS = "https://api.npmjs.org/downloads/point/last-week";
31
- const PYPI = "https://pypi.org/pypi";
32
- const TIMEOUT_MS = 2_500;
33
- const OSV_BATCH = 1000;
34
- const DAY_MS = 86_400_000;
35
- const TYPOSQUAT_NEW_DAYS = 90;
36
- const TYPOSQUAT_MIN_WEEKLY = 500;
37
- const NPM_INSTALL = new Set(["add", "install", "i"]);
38
- // Per-process caches; answers are stable within a session.
39
- /**
40
- * OSV answers by `eco:name@version`: MAL ids, whether it has any other
41
- * (vulnerability) advisories, and when asked. Clean answers expire after a day.
42
- */
43
- const osvCache = new Map();
44
- /** Serious-flaw verdicts by `eco:name@version` (detailed OSV query), with when asked. */
45
- const vulnCache = new Map();
46
- const metaCache = new Map();
47
- const lockfileCache = new Map();
48
- // ── Parsing ───────────────────────────────────────────────
49
- /** Split `react@18`, `@a/b@1`, `requests==2.0`, `x[extra]>=1` into name + spec. */
50
- function splitSpec(raw, ecosystem) {
51
- if (ecosystem === "npm") {
52
- const at = raw.indexOf("@", 1);
53
- const name = at === -1 ? raw : raw.slice(0, at);
54
- const spec = at === -1 ? undefined : raw.slice(at + 1) || undefined;
55
- if (spec?.startsWith("npm:") || spec?.includes(":") || spec?.includes("/"))
56
- return null;
57
- return /^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/i.test(name)
58
- ? { name: name.toLowerCase(), spec }
59
- : null;
60
- }
61
- const m = /^([a-z0-9][a-z0-9._-]*)(?:\[[^\]]*\])?(.*)$/i.exec(raw);
62
- if (!m)
63
- return null;
64
- const name = (m[1] ?? "").toLowerCase().replace(/[._]+/g, "-");
65
- const rest = (m[2] ?? "").split(";")[0]?.trim() ?? "";
66
- if (rest.startsWith("@"))
67
- return null; // PEP 508 URL
68
- const pin = /^===?\s*([^\s,*]+)$/.exec(rest);
69
- return { name, spec: pin ? pin[1] : rest || undefined };
70
- }
71
- function tokenize(segment) {
72
- const tokens = segment
73
- .trim()
74
- .split(/\s+/)
75
- .map((t) => t.replace(/^['"]|['"]$/g, ""))
76
- .filter((t) => t.length > 0);
77
- while (tokens[0] === "sudo" || /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[0] ?? ""))
78
- tokens.shift();
79
- return tokens;
80
- }
81
- function segments(command) {
82
- return command.split(/(?:&&|\|\||[;|\n])/);
83
- }
84
- const VALUE_FLAGS = /^(?:-r|-c|-e|--requirement|--constraint|--editable|--registry|-i|--index-url|--extra-index-url|--filter|-F|-C|--dir|--prefix|-w|--workspace|--python|-p|--package|--with|--from)$/;
85
- /** Packages named by install commands in `command`. Local paths/URLs/git are skipped. */
86
- export function parsePackageInstalls(command) {
87
- const refs = [];
88
- for (const segment of segments(command)) {
89
- const [program, sub, ...rest] = tokenize(segment);
90
- let ecosystem = null;
91
- let manager = "npm";
92
- let args = [];
93
- let first = false;
94
- if ((program === "npx" || program === "bunx") && sub !== undefined) {
95
- ecosystem = "npm";
96
- manager = program === "npx" ? "npx" : "bun";
97
- args = [sub, ...rest];
98
- first = true;
99
- }
100
- else if ((program === "pnpm" || program === "yarn" || program === "npm") &&
101
- (sub === "dlx" || sub === "exec") &&
102
- program !== "yarn") {
103
- ecosystem = "npm";
104
- manager = program === "npm" ? "npx" : "pnpm";
105
- args = rest;
106
- first = true;
107
- }
108
- else if ((program === "npm" || program === "pnpm" || program === "yarn" || program === "bun") &&
109
- sub !== undefined &&
110
- NPM_INSTALL.has(sub)) {
111
- ecosystem = "npm";
112
- manager = program;
113
- args = rest;
114
- }
115
- else if ((program === "pip" || program === "pip3") && sub === "install") {
116
- ecosystem = "PyPI";
117
- manager = "pip";
118
- args = rest;
119
- }
120
- else if (program === "pipx" && (sub === "run" || sub === "install")) {
121
- ecosystem = "PyPI";
122
- manager = "pip";
123
- args = rest;
124
- first = sub === "run";
125
- }
126
- else if (program === "uv" && sub === "pip" && rest[0] === "install") {
127
- ecosystem = "PyPI";
128
- manager = "uv";
129
- args = rest.slice(1);
130
- }
131
- else if (program === "uv" && sub === "add") {
132
- ecosystem = "PyPI";
133
- manager = "uv";
134
- args = rest;
135
- }
136
- else if (program === "uvx" && sub !== undefined) {
137
- ecosystem = "PyPI";
138
- manager = "uvx";
139
- args = [sub, ...rest];
140
- first = true;
141
- }
142
- else if (program === "uv" && sub === "tool" && (rest[0] === "run" || rest[0] === "install")) {
143
- ecosystem = "PyPI";
144
- manager = "uvx";
145
- args = rest.slice(1);
146
- first = rest[0] === "run";
147
- }
148
- if (!ecosystem)
149
- continue;
150
- let skipNext = false;
151
- for (const arg of args) {
152
- if (skipNext) {
153
- skipNext = false;
154
- continue;
155
- }
156
- if (arg === "--") {
157
- if (first)
158
- break;
159
- continue;
160
- }
161
- if (VALUE_FLAGS.test(arg)) {
162
- skipNext = true;
163
- continue;
164
- }
165
- if (arg.startsWith("-"))
166
- continue;
167
- const local = /[/\\:]/.test(arg.replace(/^@[^/]+\//, "")) || arg.startsWith(".");
168
- const parsed = local ? null : splitSpec(arg, ecosystem);
169
- if (parsed)
170
- refs.push({ ecosystem, manager, ...parsed });
171
- if (first)
172
- break; // npx/uvx: only the package positional
173
- }
174
- }
175
- return refs;
176
- }
177
- /** No-arg installs that install a whole lockfile. */
178
- export function parseLockfileInstalls(command) {
179
- const out = [];
180
- let dir = "";
181
- for (const segment of segments(command)) {
182
- const tokens = tokenize(segment);
183
- const [program, sub, ...rest] = tokens;
184
- if (program === "cd" && sub !== undefined) {
185
- dir = path.join(dir, sub);
186
- continue;
187
- }
188
- const positional = rest.filter((a) => !a.startsWith("-"));
189
- const at = (file) => path.join(dir, file);
190
- if (program === "npm" &&
191
- (sub === "ci" || ((sub === "install" || sub === "i") && positional.length === 0))) {
192
- out.push({ ecosystem: "npm", manager: "npm", file: at("package-lock.json") });
193
- }
194
- else if (program === "pnpm" &&
195
- (sub === "install" || sub === "i") &&
196
- positional.length === 0) {
197
- out.push({ ecosystem: "npm", manager: "pnpm", file: at("pnpm-lock.yaml") });
198
- }
199
- else if (program === "yarn" &&
200
- (sub === undefined || sub.startsWith("-") || (sub === "install" && positional.length === 0))) {
201
- out.push({ ecosystem: "npm", manager: "yarn", file: at("yarn.lock") });
202
- }
203
- else if (program === "bun" && (sub === "install" || sub === "i") && positional.length === 0) {
204
- out.push({ ecosystem: "npm", manager: "bun", file: at("bun.lock") });
205
- }
206
- else if (program === "uv" && sub === "sync") {
207
- const resolves = rest.some((a) => a === "--upgrade" || a.startsWith("--upgrade-package") || a === "-U" || a === "-P");
208
- out.push({ ecosystem: "PyPI", manager: "uv", file: at("uv.lock"), resolves });
209
- }
210
- else if (((program === "pip" || program === "pip3") && sub === "install") ||
211
- (program === "uv" && sub === "pip" && (rest[0] === "install" || rest[0] === "sync"))) {
212
- const args = program === "uv" ? rest.slice(1) : rest;
213
- for (let i = 0; i < args.length; i++) {
214
- const a = args[i] ?? "";
215
- if ((a === "-r" || a === "--requirement") && args[i + 1]) {
216
- out.push({
217
- ecosystem: "PyPI",
218
- manager: program === "uv" ? "uv" : "pip",
219
- file: at(args[i + 1] ?? ""),
220
- });
221
- }
222
- else if (a.startsWith("--requirement=")) {
223
- out.push({ ecosystem: "PyPI", manager: "pip", file: at(a.slice(14)) });
224
- }
225
- else if (program === "uv" && rest[0] === "sync" && !a.startsWith("-")) {
226
- out.push({ ecosystem: "PyPI", manager: "uv", file: at(a) });
227
- }
228
- }
229
- }
230
- }
231
- return out;
232
- }
233
- /** The line reader met a package-lock shape it can't read exactly. */
234
- class UnsupportedLockShape extends Error {
235
- }
236
- /** Per-line parser for the line-oriented lockfile formats (state kept in the closure). */
237
- function lineParser(base, add) {
238
- if (base === "pnpm-lock.yaml") {
239
- let inPackages = false;
240
- return (line) => {
241
- if (/^\S/.test(line))
242
- inPackages = line === "packages:" || line === "snapshots:";
243
- if (!inPackages)
244
- return;
245
- const m = /^ {2}'?\/?((?:@[^@/'\s]+\/)?[^@/'\s]+)@([^('\s:]+)/.exec(line);
246
- if (m)
247
- add(m[1] ?? "", m[2] ?? "");
248
- };
249
- }
250
- if (base === "yarn.lock") {
251
- let names = [];
252
- return (line) => {
253
- if (/^\S/.test(line) && line.endsWith(":")) {
254
- names = line
255
- .slice(0, -1)
256
- .split(",")
257
- .map((s) => s.trim().replace(/^"|"$/g, ""))
258
- .map((s) => s.slice(0, s.indexOf("@", 1)))
259
- .filter((s) => s.length > 0);
260
- return;
261
- }
262
- const v = /^ {2}version:? "?([^"\s]+)"?/.exec(line);
263
- if (v && names[0])
264
- add(names[0], v[1] ?? "");
265
- };
266
- }
267
- if (base === "bun.lock") {
268
- return (line) => {
269
- const m = /^\s*"[^"]+":\s*\[\s*"((?:@[^@/"]+\/)?[^@/"]+)@([^"]+)"/.exec(line);
270
- if (m)
271
- add(m[1] ?? "", m[2] ?? "");
272
- };
273
- }
274
- if (base === "uv.lock") {
275
- let name = "";
276
- return (line) => {
277
- if (line === "[[package]]")
278
- name = "";
279
- const n = /^name = "([^"]+)"/.exec(line);
280
- if (n)
281
- name = n[1] ?? "";
282
- const v = /^version = "([^"]+)"/.exec(line);
283
- if (v && name)
284
- add(name.replace(/[._]+/g, "-"), v[1] ?? "");
285
- };
286
- }
287
- if (base === "package-lock.json" || base === "npm-shrinkwrap.json") {
288
- // Pretty-printed (2-space) package-lock, read line by line so a huge one
289
- // never needs one long JSON.parse. Same answers as the JSON walk.
290
- let section = "";
291
- let key = null;
292
- let fields = {};
293
- return (line) => {
294
- const top = /^ {2}"([^"]+)": \{/.exec(line);
295
- if (top) {
296
- section = top[1] ?? "";
297
- key = null;
298
- return;
299
- }
300
- if (section !== "packages" && section !== "dependencies")
301
- return;
302
- const open = /^ {4}"((?:[^"\\]|\\.)*)": \{(\}?),?$/.exec(line);
303
- // An entry line we don't fully recognise (hand-formatted, inline
304
- // objects): let the caller fall back to the exact JSON walk.
305
- if (!open && /^ {4}"/.test(line))
306
- throw new UnsupportedLockShape();
307
- if (open) {
308
- key = open[1] ?? "";
309
- fields = {};
310
- if (!open[2])
311
- return;
312
- }
313
- else if (key !== null && /^ {4}\},?$/.test(line)) {
314
- // close: fall through to emit
315
- }
316
- else {
317
- if (key === null)
318
- return;
319
- const f = /^ {6}"(version|name|link)": (?:"((?:[^"\\]|\\.)*)"|(true|false)),?$/.exec(line);
320
- if (!f && /^ {6}"(?:version|name|link)"/.test(line))
321
- throw new UnsupportedLockShape();
322
- if (f?.[1] === "link")
323
- fields.link = f[3] === "true";
324
- else if (f?.[1] === "version")
325
- fields.version = f[2];
326
- else if (f?.[1] === "name")
327
- fields.name = f[2];
328
- return;
329
- }
330
- const k = key ?? "";
331
- key = null;
332
- if (section === "dependencies") {
333
- add(k, fields.version ?? "");
334
- return;
335
- }
336
- const idx = k.lastIndexOf("node_modules/");
337
- if (idx < 0 || fields.link || !fields.version)
338
- return;
339
- add(fields.name ?? k.slice(idx + 13), fields.version);
340
- };
341
- }
342
- // requirements file: only exact pins
343
- return (line) => {
344
- const m = /^\s*([A-Za-z0-9][A-Za-z0-9._-]*)(?:\[[^\]]*\])?\s*===?\s*([^\s;#,]+)/.exec(line);
345
- if (m)
346
- add((m[1] ?? "").replace(/[._]+/g, "-"), m[2] ?? "");
347
- };
348
- }
349
- function lockedCollector() {
350
- const out = new Map();
351
- return {
352
- out,
353
- add: (name, version) => {
354
- if (!name || !/^\d/.test(version))
355
- return;
356
- out.set(`${name}@${version}`, { name: name.toLowerCase(), version });
357
- },
358
- };
359
- }
360
- const stripBom = (raw) => (raw.charCodeAt(0) === 0xfeff ? raw.slice(1) : raw);
361
- const isNpmLock = (base) => base === "package-lock.json" || base === "npm-shrinkwrap.json";
362
- /** A package-lock the line reader handles: 2-space pretty JSON that is complete. */
363
- function npmLockByLines(text) {
364
- return /^\{\r?\n {2}"/.test(text) && /\}\s*$/.test(text);
365
- }
366
- /** JSON walk of a package-lock (minified or odd indentation). */
367
- function parseNpmLockJson(text, add) {
368
- try {
369
- const json = JSON.parse(text);
370
- for (const [key, v] of Object.entries(json.packages ?? {})) {
371
- const idx = key.lastIndexOf("node_modules/");
372
- if (idx < 0 || v.link || !v.version)
373
- continue;
374
- add(v.name ?? key.slice(idx + 13), v.version);
375
- }
376
- for (const [name, v] of Object.entries(json.dependencies ?? {}))
377
- add(name, v.version ?? "");
378
- return true;
379
- }
380
- catch {
381
- return false;
382
- }
383
- }
384
- /** Parse name@version pairs from a lockfile's text. Unknown shapes yield []. */
385
- export function parseLockfile(file, raw) {
386
- const text = stripBom(raw); // BOM (Windows editors)
387
- const base = path.basename(file);
388
- const { add, out } = lockedCollector();
389
- if (isNpmLock(base))
390
- return parseNpmLockJson(text, add) ? [...out.values()] : [];
391
- const onLine = lineParser(base, add);
392
- for (const line of text.split(/\r?\n/))
393
- onLine(line);
394
- return [...out.values()];
395
- }
396
- const SLICE_MS = 4;
397
- const yieldToLoop = () => new Promise((resolve) => setImmediate(resolve));
398
- /**
399
- * `parseLockfile` for the event loop's sake: walks lines in slices of a few
400
- * ms with a yield in between, so a 50k-entry lockfile never stalls the
401
- * sidecar (shared by every app window). Same results.
402
- */
403
- export async function parseLockfileAsync(file, raw) {
404
- const text = stripBom(raw);
405
- const base = path.basename(file);
406
- const { add, out } = lockedCollector();
407
- if (isNpmLock(base) && !npmLockByLines(text)) {
408
- // Truncated (no closing brace) can't be valid JSON: skip the long parse.
409
- if (!/\}\s*$/.test(text))
410
- return [];
411
- return parseNpmLockJson(text, add) ? [...out.values()] : [];
412
- }
413
- try {
414
- await readLinesInSlices(text, lineParser(base, add));
415
- }
416
- catch (err) {
417
- if (!(err instanceof UnsupportedLockShape))
418
- throw err;
419
- const exact = lockedCollector();
420
- return parseNpmLockJson(text, exact.add) ? [...exact.out.values()] : [];
421
- }
422
- return [...out.values()];
423
- }
424
- /** Feed `text` line by line to `onLine`, yielding to the event loop every few ms. */
425
- async function readLinesInSlices(text, onLine) {
426
- let start = 0;
427
- let sliceAt = performance.now();
428
- let n = 0;
429
- while (start <= text.length) {
430
- const nl = text.indexOf("\n", start);
431
- const end = nl < 0 ? text.length : nl;
432
- const line = text.slice(start, end > start && text.charCodeAt(end - 1) === 13 ? end - 1 : end);
433
- onLine(line);
434
- start = end + 1;
435
- if (++n % 128 === 0 && performance.now() - sliceAt > SLICE_MS) {
436
- await yieldToLoop();
437
- sliceAt = performance.now();
438
- }
439
- }
440
- }
441
- /** sha256 of a big text in slices with yields (hashing 13 MB at once is ~20 ms). */
442
- async function hashInSlices(text) {
443
- const h = createHash("sha256");
444
- const step = 1 << 20;
445
- for (let i = 0; i < text.length; i += step) {
446
- h.update(text.slice(i, i + step));
447
- if (i + step < text.length)
448
- await yieldToLoop();
449
- }
450
- return h.digest("hex");
451
- }
452
- // ── Typosquat (local candidate) ──────────────────────────
453
- /** Optimal-string-alignment Damerau-Levenshtein distance. */
454
- export function damerauLevenshtein(a, b) {
455
- const d = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
456
- const at = (i, j) => d[i]?.[j] ?? Number.POSITIVE_INFINITY;
457
- for (let i = 1; i <= a.length; i++) {
458
- const row = d[i];
459
- if (!row)
460
- continue;
461
- for (let j = 1; j <= b.length; j++) {
462
- const cost = a[i - 1] === b[j - 1] ? 0 : 1;
463
- let v = Math.min(at(i - 1, j) + 1, at(i, j - 1) + 1, at(i - 1, j - 1) + cost);
464
- if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
465
- v = Math.min(v, at(i - 2, j - 2) + 1);
466
- }
467
- row[j] = v;
468
- }
469
- }
470
- return at(a.length, b.length);
471
- }
472
- const popularSets = {
473
- npm: new Set(POPULAR_NPM_PACKAGES),
474
- PyPI: new Set(POPULAR_PYPI_PACKAGES),
475
- };
476
- /** The popular name `ref` is one edit away from, or null. Local only. */
477
- export function typosquatCandidate(ref) {
478
- const popular = ref.ecosystem === "npm" ? POPULAR_NPM_PACKAGES : POPULAR_PYPI_PACKAGES;
479
- if (popularSets[ref.ecosystem].has(ref.name))
480
- return null;
481
- return (popular.find((p) => Math.abs(p.length - ref.name.length) <= 1 && damerauLevenshtein(p, ref.name) === 1) ?? null);
482
- }
483
- function isExact(spec) {
484
- return spec !== undefined && /^v?\d+(?:\.\d+)*(?:[-.+][0-9A-Za-z.-]+)?$/.test(spec);
485
- }
486
- function label(ref, version) {
487
- return version ? `${ref.name}@${version}` : ref.name;
488
- }
489
- /** Instant part of the check: parsing, typosquat candidates and local feed hits. */
490
- export function localPackageCheck(command, feedOrLoad) {
491
- const refs = parsePackageInstalls(command);
492
- const lockfiles = refs.length === 0 ? parseLockfileInstalls(command) : [];
493
- if (refs.length === 0 && lockfiles.length === 0) {
494
- return { refs, lockfiles, threats: [], typosquats: [], flagged: new Set(), feed: emptyFeed() };
495
- }
496
- const feed = typeof feedOrLoad === "function" ? feedOrLoad() : feedOrLoad;
497
- const threats = [];
498
- const typosquats = [];
499
- const flagged = new Set();
500
- for (const ref of refs) {
501
- const version = isExact(ref.spec) ? ref.spec.replace(/^v/, "") : undefined;
502
- const ids = feedMatches(feed, ref.ecosystem, ref.name, version);
503
- if (ids.length > 0) {
504
- threats.push(malwareThreat(ref, version, ids, null, 0));
505
- flagged.add(ref.name);
506
- continue;
507
- }
508
- const popular = typosquatCandidate(ref);
509
- if (popular)
510
- typosquats.push({ ref, popular });
511
- }
512
- return { refs, lockfiles, threats, typosquats, flagged, feed };
513
- }
514
- function malwareThreat(ref, version, ids, safe, days) {
515
- const instead = safe
516
- ? `use ${ref.name}@${safe}, the last version older than ${days} days`
517
- : "pick a different version or package";
518
- return {
519
- rule: "malicious-package",
520
- severity: "block",
521
- detail: `${label(ref, version)} is flagged as malware (${ids.join(", ")}); ${instead}.`,
522
- blocked: [
523
- {
524
- ecosystem: ref.ecosystem,
525
- name: ref.name,
526
- ...(version ? { version } : {}),
527
- reason: `known malware (${ids.join(", ")})`,
528
- },
529
- ],
530
- };
531
- }
532
- class NotFound {
533
- }
534
- async function getJson(url, ctx, headers = {}) {
535
- const key = `${headers.accept ?? ""} ${url}`;
536
- let hit = metaCache.get(key);
537
- if (!hit) {
538
- hit = fetchJson(url, { headers }, ctx, true);
539
- metaCache.set(key, hit);
540
- // A failed fetch should be retried next install, not cached.
541
- hit.catch(() => metaCache.delete(key));
542
- }
543
- return hit;
544
- }
545
- /**
546
- * Hosts that just failed or stalled: skipped (fail-open, instantly) for a
547
- * short while so an offline machine or a hung registry costs the deadline
548
- * once, not on every install.
549
- */
550
- const downHosts = new Map();
551
- const DOWN_MS = 2 * 60_000;
552
- /** Key for "nothing answered before the deadline" (offline, dead proxy): every host waits. */
553
- const ALL_HOSTS = "*";
554
- /** After a deadline cut: if no host answered at all, the network itself is down for a while. */
555
- function noteDeadline(ctx) {
556
- if (!ctx.cancelled() && !ctx.reached.value)
557
- downHosts.set(ALL_HOSTS, Date.now() + DOWN_MS);
558
- }
559
- function hostOf(url) {
560
- try {
561
- return new URL(url).host;
562
- }
563
- catch {
564
- return url;
565
- }
566
- }
567
- /** fetch + status + JSON, honouring and feeding the down-host memory. 404 → NotFound when asked. */
568
- async function fetchJson(url, init, ctx, notFound = false) {
569
- const host = hostOf(url);
570
- const down = Math.max(downHosts.get(host) ?? 0, downHosts.get(ALL_HOSTS) ?? 0);
571
- if (Date.now() < down)
572
- throw new Error(`${host} recently unreachable`);
573
- try {
574
- // Raced with the signal too: a fetch that ignores aborts must not hang us.
575
- return await Promise.race([
576
- (async () => {
577
- const res = await ctx.fetch(url, { ...init, signal: ctx.signal });
578
- if (res.status < 500)
579
- ctx.reached.value = true;
580
- if (notFound && res.status === 404)
581
- return new NotFound();
582
- if (!res.ok)
583
- throw new Error(`HTTP ${res.status} for ${url}`);
584
- return res.json();
585
- })(),
586
- deadline(ctx.signal),
587
- ]);
588
- }
589
- catch (err) {
590
- // A cancel by the caller says nothing about the host; a network error,
591
- // 4xx other than 404 (429, proxy 403/407), 5xx, bad JSON or our deadline does.
592
- if (!ctx.cancelled())
593
- downHosts.set(host, Date.now() + DOWN_MS);
594
- throw err;
595
- }
596
- }
597
- const enc = (name) => name.replace("/", "%2F");
598
- /** Abbreviated packument (no publish times); the full one only when times are needed. */
599
- function npmDoc(name, full, ctx) {
600
- const accept = full ? "application/json" : "application/vnd.npm.install-v1+json";
601
- // A full doc already fetched answers abbreviated questions too.
602
- const fullKey = `application/json ${NPM_REGISTRY}/${enc(name)}`;
603
- if (!full && metaCache.has(fullKey))
604
- return getJson(`${NPM_REGISTRY}/${enc(name)}`, ctx, { accept: "application/json" });
605
- return getJson(`${NPM_REGISTRY}/${enc(name)}`, ctx, { accept });
606
- }
607
- function pypiDoc(name, ctx) {
608
- return getJson(`${PYPI}/${name}/json`, ctx);
609
- }
610
- function isStable(v) {
611
- return /^\d+(?:\.\d+)*$/.test(v);
612
- }
613
- /** Highest version satisfying a simple npm range (exact, ^, ~, x, >=). Null if unsupported. */
614
- function maxSatisfying(versions, range) {
615
- const r = range.trim();
616
- const m = /^(\^|~|>=)?\s*v?(\d+)(?:\.(\d+|x|\*))?(?:\.(\d+|x|\*))?$/.exec(r);
617
- if (r === "*" || r === "x" || r === "")
618
- return pickMax(versions.filter(isStable));
619
- if (!m)
620
- return null;
621
- const op = m[1] ?? "";
622
- const nums = [m[2], m[3], m[4]].map((n) => n === undefined || n === "x" || n === "*" ? null : Number(n));
623
- const [maj, min, pat] = nums;
624
- const ok = (v) => {
625
- if (!isStable(v))
626
- return false;
627
- const [a = 0, b = 0, c = 0] = v.split(".").map(Number);
628
- const lo = `${maj ?? 0}.${min ?? 0}.${pat ?? 0}`;
629
- if (compareVersions(v, lo) < 0)
630
- return false;
631
- if (op === ">=")
632
- return true;
633
- if (op === "^") {
634
- if ((maj ?? 0) > 0)
635
- return a === maj;
636
- if ((min ?? 0) > 0)
637
- return a === 0 && b === min;
638
- return a === 0 && b === 0 && (pat === null || c === pat);
639
- }
640
- if (op === "~")
641
- return a === maj && (min === null || b === min);
642
- return a === maj && (min === null || b === min) && (pat === null || c === pat);
643
- };
644
- return pickMax(versions.filter(ok));
645
- }
646
- function pickMax(versions) {
647
- let best = null;
648
- for (const v of versions)
649
- if (best === null || compareVersions(v, best) > 0)
650
- best = v;
651
- return best;
652
- }
653
- async function resolveRef(ref, full, ctx) {
654
- if (ref.ecosystem === "npm") {
655
- const doc = await npmDoc(ref.name, full, ctx);
656
- if (doc instanceof NotFound)
657
- return { ref, version: null, missing: true };
658
- const npm = doc;
659
- const tags = npm["dist-tags"] ?? {};
660
- const all = Object.keys(npm.versions ?? {});
661
- let version;
662
- if (ref.spec === undefined)
663
- version = tags.latest ?? null;
664
- else if (tags[ref.spec])
665
- version = tags[ref.spec] ?? null;
666
- else if (isExact(ref.spec))
667
- version = ref.spec.replace(/^v/, "");
668
- else
669
- version = maxSatisfying(all, ref.spec);
670
- return { ref, version, missing: false, npm, full: npm.time !== undefined };
671
- }
672
- const doc = await pypiDoc(ref.name, ctx);
673
- if (doc instanceof NotFound)
674
- return { ref, version: null, missing: true };
675
- const pypi = doc;
676
- const version = ref.spec === undefined ? (pypi.info?.version ?? null) : isExact(ref.spec) ? ref.spec : null;
677
- return { ref, version, missing: false, pypi };
678
- }
679
- /** Publish time (ms) per version. npm needs the full packument (fetched only when required). */
680
- async function publishTimes(r, ctx) {
681
- const out = new Map();
682
- if (r.ref.ecosystem === "npm") {
683
- const full = r.full ? r.npm : await npmDoc(r.ref.name, true, ctx);
684
- if (!full || full instanceof NotFound)
685
- return out;
686
- for (const [v, t] of Object.entries(full.time ?? {})) {
687
- if (v === "created" || v === "modified")
688
- continue;
689
- out.set(v, Date.parse(t));
690
- }
691
- }
692
- else {
693
- for (const [v, files] of Object.entries(r.pypi?.releases ?? {})) {
694
- const times = files
695
- .filter((f) => !f.yanked)
696
- .map((f) => Date.parse(f.upload_time_iso_8601 ?? ""))
697
- .filter((t) => !Number.isNaN(t));
698
- if (times.length > 0)
699
- out.set(v, Math.min(...times));
700
- }
701
- }
702
- return out;
703
- }
704
- /** Newest stable version published before the cutoff, skipping `bad`. */
705
- /** The compatible release line of a version, as `^` reads it: `5` for 5.6.1, `0.30` for 0.30.4. */
706
- function releaseLine(version) {
707
- const [major = "", minor = ""] = version.replace(/^v/, "").split(".");
708
- return major === "0" ? `0.${minor}` : major;
709
- }
710
- /**
711
- * The version to suggest instead: the newest stable release older than
712
- * `cutoff`, not in `bad`, preferring the same release line as `near` so the
713
- * agent isn't steered into a breaking major upgrade. Falls back to any line.
714
- */
715
- function lastOlderThan(times, cutoff, bad, near) {
716
- const ok = [...times]
717
- .filter(([v, t]) => t <= cutoff && isStable(v) && !bad.has(v))
718
- .map(([v]) => v);
719
- if (near) {
720
- const line = releaseLine(near);
721
- const same = pickMax(ok.filter((v) => releaseLine(v) === line));
722
- if (same)
723
- return same;
724
- }
725
- return pickMax(ok);
726
- }
727
- /** Versions of a package the local feed flags, so a suggestion never names one. */
728
- function feedFlagged(ctx, ref, versions) {
729
- const out = new Set();
730
- for (const v of versions) {
731
- if (feedMatches(ctx.feed, ref.ecosystem, ref.name, v).length > 0)
732
- out.add(v);
733
- }
734
- return out;
735
- }
736
- const VERDICT_FILE = "package-verdicts.json";
737
- const OSV_TTL_MS = DAY_MS;
738
- const MAX_LOCKS = 50;
739
- class VerdictCache {
740
- file;
741
- data = { osvClean: {}, osvFlawed: {}, locks: {} };
742
- loaded = null;
743
- saving = Promise.resolve();
744
- dirty = false;
745
- constructor(file) {
746
- this.file = file;
747
- }
748
- load() {
749
- if (!this.loaded) {
750
- this.loaded = this.file
751
- ? fsp
752
- .readFile(this.file, "utf8")
753
- .then((text) => {
754
- const raw = JSON.parse(text);
755
- this.data = {
756
- osvClean: raw.osvClean ?? {},
757
- osvFlawed: raw.osvFlawed ?? {},
758
- locks: raw.locks ?? {},
759
- };
760
- })
761
- .catch(() => undefined)
762
- : Promise.resolve();
763
- }
764
- return this.loaded;
765
- }
766
- osvFresh(key, now) {
767
- const at = this.data.osvClean[key];
768
- return at !== undefined && now - at < OSV_TTL_MS;
769
- }
770
- markClean(key, now, flawed = false) {
771
- this.data.osvClean[key] = now;
772
- const f = (this.data.osvFlawed ??= {});
773
- if (flawed)
774
- f[key] = now;
775
- else
776
- delete f[key];
777
- this.dirty = true;
778
- }
779
- /** A remembered no-malware answer that also had advisories. */
780
- osvFlawed(key, now) {
781
- const at = this.data.osvFlawed?.[key];
782
- return at !== undefined && now - at < OSV_TTL_MS;
783
- }
784
- lock(key) {
785
- return this.data.locks[key];
786
- }
787
- setLock(key, v) {
788
- this.data.locks[key] = v;
789
- this.dirty = true;
790
- }
791
- /** Write in the background (atomic rename); never on the caller's critical path. */
792
- save(now) {
793
- if (!this.file || !this.dirty)
794
- return;
795
- this.dirty = false;
796
- const file = this.file;
797
- this.saving = this.saving.then(async () => {
798
- const osvClean = Object.fromEntries(Object.entries(this.data.osvClean).filter(([, at]) => now - at < OSV_TTL_MS));
799
- const osvFlawed = Object.fromEntries(Object.entries(this.data.osvFlawed ?? {}).filter(([k]) => k in osvClean));
800
- const locks = Object.fromEntries(Object.entries(this.data.locks)
801
- .sort(([, a], [, b]) => b.at - a.at)
802
- .slice(0, MAX_LOCKS));
803
- this.data = { osvClean, osvFlawed, locks };
804
- try {
805
- await writeJsonAtomic(file, this.data);
806
- }
807
- catch (err) {
808
- log("WARN", "package-threats", `verdict cache write failed: ${String(err)}`);
809
- }
810
- });
811
- }
812
- flush() {
813
- return this.saving;
814
- }
815
- }
816
- const verdictCaches = new Map();
817
- function verdictCache(dir) {
818
- const file = dir === null ? null : path.join(dir, VERDICT_FILE);
819
- const key = file ?? "";
820
- let hit = verdictCaches.get(key);
821
- if (!hit) {
822
- hit = new VerdictCache(file);
823
- verdictCaches.set(key, hit);
824
- }
825
- return hit;
826
- }
827
- const osvKey = (i) => `${i.ecosystem}:${i.name}@${i.version}`;
828
- /** MAL- IDs per `eco:name@version`, one request per 1000 queries, cached (memory + disk). */
829
- /** A remembered OSV answer still holds: malware stays malware; "clean" is re-asked daily. */
830
- function osvKnown(key, now) {
831
- const hit = osvCache.get(key);
832
- if (!hit)
833
- return false;
834
- return hit.ids.length > 0 || now - hit.at < OSV_TTL_MS;
835
- }
836
- async function osvMalware(items, ctx) {
837
- const pending = [
838
- ...new Map(items
839
- .filter((i) => !osvKnown(osvKey(i), ctx.now) && !ctx.cache.osvFresh(osvKey(i), ctx.now))
840
- .map((i) => [osvKey(i), i])).values(),
841
- ];
842
- for (let start = 0; start < pending.length; start += OSV_BATCH) {
843
- const batch = pending.slice(start, start + OSV_BATCH);
844
- const body = (await fetchJson(OSV_URL, {
845
- method: "POST",
846
- headers: { "content-type": "application/json" },
847
- body: JSON.stringify({
848
- queries: batch.map((i) => ({
849
- package: { ecosystem: i.ecosystem, name: i.name },
850
- version: i.version,
851
- })),
852
- }),
853
- }, ctx));
854
- batch.forEach((item, i) => {
855
- const all = (body.results?.[i]?.vulns ?? []).map((v) => v.id ?? "");
856
- const ids = all.filter((id) => id.startsWith("MAL-"));
857
- const flawed = all.some((id) => id !== "" && !id.startsWith("MAL-"));
858
- osvCache.set(osvKey(item), { ids, flawed, at: ctx.now });
859
- // Remembered on disk with whether it had advisories, so a restart
860
- // neither re-asks OSV nor loses the serious-flaw trigger.
861
- if (ids.length === 0)
862
- ctx.cache.markClean(osvKey(item), ctx.now, flawed);
863
- });
864
- }
865
- const out = new Map();
866
- for (const i of items) {
867
- const ids = osvCache.get(osvKey(i))?.ids;
868
- if (ids && ids.length > 0)
869
- out.set(osvKey(i), ids);
870
- }
871
- return out;
872
- }
873
- // ── Serious known flaws ─────────────────────────────────
874
- /**
875
- * Major version, the boundary for a flaw fix: moving 0.21 → 0.34 or 4.17 →
876
- * 4.18 is the normal upgrade path; 0.x → 1.x or 4 → 5 is the breaking one.
877
- * (Not `releaseLine`: under `^`, 0.21 and 0.31 count as different lines, which
878
- * would leave old 0.x packages with no fix to move to.)
879
- */
880
- function majorOf(version) {
881
- return version.replace(/^v/, "").split(".")[0] ?? "";
882
- }
883
- const SERIOUS = new Set(["HIGH", "CRITICAL"]);
884
- /** Did the batch lookup see any non-malware advisory for this exact version? */
885
- function osvFlawed(item, ctx) {
886
- const key = osvKey(item);
887
- const hit = osvCache.get(key);
888
- return hit ? hit.flawed : ctx.cache.osvFlawed(key, ctx.now);
889
- }
890
- /**
891
- * Serious advisories for one exact version (one detailed OSV request, only
892
- * made when the batch lookup already saw advisories). Cached for a day.
893
- */
894
- async function seriousFlaws(item, ctx) {
895
- const key = osvKey(item);
896
- const hit = vulnCache.get(key);
897
- if (hit && ctx.now - hit.at < OSV_TTL_MS)
898
- return hit.verdict;
899
- const body = (await fetchJson(OSV_QUERY_URL, {
900
- method: "POST",
901
- headers: { "content-type": "application/json" },
902
- body: JSON.stringify({
903
- package: { ecosystem: item.ecosystem, name: item.name },
904
- version: item.version,
905
- }),
906
- }, ctx));
907
- const serious = (body.vulns ?? []).filter((v) => !(v.id ?? "").startsWith("MAL-") &&
908
- SERIOUS.has((v.database_specific?.severity ?? "").toUpperCase()));
909
- const verdict = serious.length === 0
910
- ? null
911
- : {
912
- ids: serious.map((v) => v.id ?? "").filter(Boolean),
913
- summary: (serious.find((v) => v.database_specific?.severity?.toUpperCase() === "CRITICAL") ??
914
- serious[0])?.summary?.trim() ?? "",
915
- severity: serious.some((v) => v.database_specific?.severity?.toUpperCase() === "CRITICAL")
916
- ? "CRITICAL"
917
- : "HIGH",
918
- fixes: serious.map((v) => (v.affected ?? [])
919
- .filter((a) => !a.package?.name || a.package.name.toLowerCase() === item.name.toLowerCase())
920
- .flatMap((a) => a.ranges ?? [])
921
- .flatMap((r) => r.events ?? [])
922
- .map((e) => e.fixed)
923
- .filter((f) => typeof f === "string" && f.length > 0)),
924
- };
925
- vulnCache.set(key, { verdict, at: ctx.now });
926
- return verdict;
927
- }
928
- /**
929
- * The version to move to: the newest stable release on `version`'s release
930
- * line that is at or past a fix of EVERY serious advisory (on that line),
931
- * older than the cooldown, and not malware. Null when there is none (no fix
932
- * yet, or only fixed in another major) — then the install is left alone.
933
- */
934
- function fixedOnSameLine(version, verdict, times, cutoff, bad) {
935
- const line = majorOf(version);
936
- const floors = [];
937
- for (const fixes of verdict.fixes) {
938
- const onLine = fixes.filter((f) => majorOf(f) === line && compareVersions(f, version) > 0);
939
- if (onLine.length === 0)
940
- return null; // this flaw isn't fixed on this line
941
- floors.push(onLine.reduce((a, b) => (compareVersions(a, b) <= 0 ? a : b)));
942
- }
943
- const floor = floors.reduce((a, b) => (compareVersions(a, b) >= 0 ? a : b));
944
- const ok = [...times]
945
- .filter(([v, t]) => t <= cutoff &&
946
- isStable(v) &&
947
- !bad.has(v) &&
948
- majorOf(v) === line &&
949
- compareVersions(v, floor) >= 0)
950
- .map(([v]) => v);
951
- return pickMax(ok);
952
- }
953
- function vulnThreat(ref, version, verdict, fixed) {
954
- const what = verdict.summary ? `: ${verdict.summary.replace(/\s+/g, " ").slice(0, 100)}` : "";
955
- const ids = verdict.ids.slice(0, 3).join(", ") + (verdict.ids.length > 3 ? ", …" : "");
956
- return {
957
- rule: "known-vulnerability",
958
- severity: "block",
959
- detail: `${ref.name}@${version} has known ${verdict.severity} security flaws (${ids})${what}; use ${ref.name}@${fixed}, the newest ${majorOf(version)}.x release with those fixed.`,
960
- };
961
- }
962
- /** Swallow network failures: the guard is fail-open (the cooldown still applies). */
963
- async function safe(what, fn) {
964
- try {
965
- return await fn();
966
- }
967
- catch (err) {
968
- log("WARN", "package-threats", `${what} failed, allowing: ${String(err)}`);
969
- return null;
970
- }
971
- }
972
- function resolvedItem(r) {
973
- return { ecosystem: r.ref.ecosystem, name: r.ref.name, version: r.version ?? "" };
974
- }
975
- /**
976
- * Named installs. Everything independent runs at once, so a clean install
977
- * costs one registry round trip (+ one OSV round trip for unpinned refs whose
978
- * version isn't known until the registry answers):
979
- * - registry docs for every ref (full packument only for typosquat
980
- * candidates; abbreviated otherwise),
981
- * - OSV for exactly pinned refs, concurrently with the registry,
982
- * - weekly downloads for npm typosquat candidates,
983
- * - the manager version (native cooldown?) — spawned once per process.
984
- */
985
- async function checkNamed(local, ctx) {
986
- const threats = [];
987
- const refs = local.refs.filter((r) => !local.flagged.has(r.name));
988
- const squats = new Map(local.typosquats.map((t) => [t.ref.name, t.popular]));
989
- const native = new Map();
990
- for (const r of refs) {
991
- if (!native.has(r.manager))
992
- native.set(r.manager, nativeCooldown(r.manager, ctx));
993
- }
994
- const pinned = refs
995
- .filter((r) => isExact(r.spec))
996
- .map((r) => ({
997
- ecosystem: r.ecosystem,
998
- name: r.name,
999
- version: (r.spec ?? "").replace(/^v/, ""),
1000
- }));
1001
- const earlyOsv = pinned.length > 0 ? safe("OSV lookup", () => osvMalware(pinned, ctx)) : null;
1002
- const downloads = new Map(refs
1003
- .filter((r) => r.ecosystem === "npm" && squats.has(r.name))
1004
- .map((r) => [
1005
- r.name,
1006
- safe(`downloads ${r.name}`, () => getJson(`${NPM_DOWNLOADS}/${r.name}`, ctx)),
1007
- ]));
1008
- const resolved = (await Promise.all(refs.map((r) => safe(`lookup ${r.name}`, () => resolveRef(r, squats.has(r.name), ctx))))).filter((r) => r !== null);
1009
- // P5: typosquat → block only if missing, new or barely used.
1010
- const squatted = new Set();
1011
- for (const r of resolved) {
1012
- const popular = squats.get(r.ref.name);
1013
- if (!popular)
1014
- continue;
1015
- const reason = await safe(`typosquat ${r.ref.name}`, () => typosquatReason(r, downloads.get(r.ref.name) ?? Promise.resolve(null), ctx));
1016
- if (reason) {
1017
- squatted.add(r.ref.name);
1018
- threats.push({
1019
- rule: "typosquat",
1020
- severity: "block",
1021
- detail: `${r.ref.name} looks like a typosquat of popular "${popular}" (${reason}); use ${popular} if that is what you meant.`,
1022
- blocked: [
1023
- { ecosystem: r.ref.ecosystem, name: r.ref.name, reason: `lookalike of "${popular}"` },
1024
- ],
1025
- });
1026
- }
1027
- }
1028
- const live = resolved.filter((r) => !r.missing && r.version !== null && !squatted.has(r.ref.name));
1029
- // Malware: local feed with the resolved version, then OSV with exact versions.
1030
- const pinnedKeys = new Set(pinned.map(osvKey));
1031
- const late = live.map(resolvedItem).filter((i) => !pinnedKeys.has(osvKey(i)));
1032
- const [early, rest] = await Promise.all([
1033
- earlyOsv,
1034
- late.length > 0 ? safe("OSV lookup", () => osvMalware(late, ctx)) : null,
1035
- ]);
1036
- const osv = new Map([...(early ?? []), ...(rest ?? [])]);
1037
- const malware = new Set();
1038
- for (const r of live) {
1039
- const version = r.version ?? "";
1040
- const ids = [
1041
- ...new Set([
1042
- ...feedMatches(ctx.feed, r.ref.ecosystem, r.ref.name, version),
1043
- ...(osv.get(osvKey(resolvedItem(r))) ?? []),
1044
- ]),
1045
- ];
1046
- if (ids.length === 0)
1047
- continue;
1048
- malware.add(r.ref.name);
1049
- const times = (await safe("publish times", () => publishTimes(r, ctx))) ?? new Map();
1050
- const cutoff = ctx.now - Math.max(ctx.days, 0) * DAY_MS;
1051
- const bad = feedFlagged(ctx, r.ref, times.keys()).add(version);
1052
- const suggestion = lastOlderThan(times, cutoff, bad, version);
1053
- threats.push(malwareThreat(r.ref, version, ids, suggestion, ctx.days));
1054
- }
1055
- // Serious known flaws: only versions the batch lookup already saw
1056
- // advisories for get the one detailed request; all of them in parallel.
1057
- const vulnChecks = await Promise.all(live
1058
- .filter((r) => !malware.has(r.ref.name) && osvFlawed(resolvedItem(r), ctx))
1059
- .map(async (r) => {
1060
- const version = r.version ?? "";
1061
- const verdict = await safe(`advisories ${r.ref.name}`, () => seriousFlaws(resolvedItem(r), ctx));
1062
- if (!verdict)
1063
- return null;
1064
- const times = await safe("publish times", () => publishTimes(r, ctx));
1065
- if (!times)
1066
- return null;
1067
- const cutoff = ctx.now - Math.max(ctx.days, 0) * DAY_MS;
1068
- const bad = feedFlagged(ctx, r.ref, times.keys()).add(version);
1069
- const fixed = fixedOnSameLine(version, verdict, times, cutoff, bad);
1070
- return fixed
1071
- ? { name: r.ref.name, threat: vulnThreat(r.ref, version, verdict, fixed) }
1072
- : null;
1073
- }));
1074
- const flawed = new Set();
1075
- for (const v of vulnChecks) {
1076
- if (!v)
1077
- continue;
1078
- flawed.add(v.name);
1079
- threats.push(v.threat);
1080
- }
1081
- for (const r of live) {
1082
- if (malware.has(r.ref.name) || flawed.has(r.ref.name))
1083
- continue;
1084
- const version = r.version ?? "";
1085
- // P4: provenance downgrade (npm).
1086
- if (r.npm?.versions) {
1087
- const all = Object.keys(r.npm.versions);
1088
- const prev = pickMax(all.filter((v) => isStable(v) && compareVersions(v, version) < 0));
1089
- const had = prev ? r.npm.versions[prev]?.dist?.attestations : undefined;
1090
- const has = r.npm.versions[version]?.dist?.attestations;
1091
- if (prev && had && !has && r.npm.versions[version]) {
1092
- threats.push({
1093
- rule: "provenance-downgrade",
1094
- severity: "block",
1095
- detail: `${r.ref.name}@${version} was published without the provenance attestation ${r.ref.name}@${prev} had (a hijacked-release signal); use ${r.ref.name}@${prev}.`,
1096
- blocked: [
1097
- {
1098
- ecosystem: r.ref.ecosystem,
1099
- name: r.ref.name,
1100
- version,
1101
- reason: "published without its usual signature (likely hijacked)",
1102
- },
1103
- ],
1104
- });
1105
- continue;
1106
- }
1107
- }
1108
- // P3: own release-age check only when the manager can't enforce the cooldown.
1109
- if (ctx.days > 0 && !(await (native.get(r.ref.manager) ?? Promise.resolve(true)))) {
1110
- const times = (await safe("publish times", () => publishTimes(r, ctx))) ?? new Map();
1111
- const published = times.get(version);
1112
- const cutoff = ctx.now - ctx.days * DAY_MS;
1113
- if (published !== undefined && published > cutoff) {
1114
- const older = lastOlderThan(times, cutoff, feedFlagged(ctx, r.ref, times.keys()), version);
1115
- const hours = Math.max(1, Math.round((ctx.now - published) / 3_600_000));
1116
- const instead = older
1117
- ? `use ${r.ref.name}@${older}, the last version older than ${ctx.days} days`
1118
- : `wait until it is ${ctx.days} days old`;
1119
- threats.push({
1120
- rule: "release-age",
1121
- severity: "block",
1122
- detail: `${r.ref.name}@${version} was published ${hours}h ago (cooldown ${ctx.days} days); ${instead}.`,
1123
- });
1124
- }
1125
- }
1126
- }
1127
- return threats;
1128
- }
1129
- async function nativeCooldown(manager, ctx) {
1130
- const m = manager === "npx" ? "npm" : manager === "uvx" ? "uv" : manager;
1131
- if (m === "uv")
1132
- return true;
1133
- return hasNativeCooldown(m, await ctx.managerVersion(m));
1134
- }
1135
- async function typosquatReason(r, downloads, ctx) {
1136
- if (r.missing)
1137
- return ctx.privateSource(r.ref.ecosystem) ? null : "it does not exist on the registry";
1138
- const times = await publishTimes(r, ctx);
1139
- const first = Math.min(...times.values());
1140
- if (Number.isFinite(first) && ctx.now - first < TYPOSQUAT_NEW_DAYS * DAY_MS) {
1141
- return `first published ${Math.max(0, Math.floor((ctx.now - first) / DAY_MS))} days ago`;
1142
- }
1143
- const dl = (await downloads);
1144
- if (dl &&
1145
- !(dl instanceof NotFound) &&
1146
- typeof dl.downloads === "number" &&
1147
- dl.downloads < TYPOSQUAT_MIN_WEEKLY) {
1148
- return `only ${dl.downloads} downloads last week`;
1149
- }
1150
- return null;
1151
- }
1152
- async function checkLockfile(lock, cwd, ctx) {
1153
- const file = path.resolve(cwd, lock.file);
1154
- let text;
1155
- try {
1156
- text = await fsp.readFile(file, "utf8");
1157
- }
1158
- catch {
1159
- return [];
1160
- }
1161
- const hash = await hashInSlices(text);
1162
- const cacheKey = `${lock.ecosystem}:${hash}:${Object.keys(ctx.feed.entries).length}`;
1163
- const remembered = lockfileCache.get(cacheKey) ?? ctx.cache.lock(cacheKey);
1164
- // A lockfile verdict is re-asked of OSV at most once a day, so a package
1165
- // flagged after the last check is still caught even if the feed is unchanged.
1166
- const cached = remembered && ctx.now - remembered.at < DAY_MS ? remembered : undefined;
1167
- if (cached) {
1168
- lockfileCache.set(cacheKey, cached);
1169
- return cached.threats;
1170
- }
1171
- const pkgs = await parseLockfileAsync(file, text);
1172
- const hits = new Map();
1173
- for (const p of pkgs) {
1174
- const ids = feedMatches(ctx.feed, lock.ecosystem, p.name, p.version);
1175
- if (ids.length > 0)
1176
- hits.set(`${p.name}@${p.version}`, ids);
1177
- }
1178
- const osv = await safe("OSV lockfile lookup", () => osvMalware(pkgs.map((p) => ({ ecosystem: lock.ecosystem, name: p.name, version: p.version })), ctx));
1179
- for (const [key, ids] of osv ?? []) {
1180
- const short = key.slice(key.indexOf(":") + 1);
1181
- hits.set(short, [...new Set([...(hits.get(short) ?? []), ...ids])]);
1182
- }
1183
- const threats = hits.size === 0
1184
- ? []
1185
- : [
1186
- {
1187
- rule: "malicious-package",
1188
- severity: "block",
1189
- packages: [...hits].map(([k, ids]) => `${k} (${ids.join(", ")})`),
1190
- blocked: [...hits].map(([k, ids]) => {
1191
- const at = k.lastIndexOf("@");
1192
- return {
1193
- ecosystem: lock.ecosystem,
1194
- name: k.slice(0, at),
1195
- version: k.slice(at + 1),
1196
- reason: `known malware (${ids.join(", ")})`,
1197
- };
1198
- }),
1199
- detail: `${path.basename(file)} pins malware: ${[...hits]
1200
- .slice(0, 5)
1201
- .map(([k, ids]) => `${k} (${ids.join(", ")})`)
1202
- .join(", ")}${hits.size > 5 ? ` and ${hits.size - 5} more` : ""}; update those packages to a clean version and regenerate the lockfile.`,
1203
- },
1204
- ];
1205
- // Only cache a complete answer (OSV reached); offline answers are retried.
1206
- if (osv !== null) {
1207
- const verdict = { at: ctx.now, threats };
1208
- lockfileCache.set(cacheKey, verdict);
1209
- ctx.cache.setLock(cacheKey, verdict);
1210
- }
1211
- return threats;
1212
- }
1213
- /** Rejects with the deadline so no network wait can stack past it (fail-open). */
1214
- function deadline(signal) {
1215
- return new Promise((_, reject) => {
1216
- if (signal.aborted)
1217
- reject(new Error("package check deadline"));
1218
- signal.addEventListener("abort", () => reject(new Error("package check deadline")), {
1219
- once: true,
1220
- });
1221
- });
1222
- }
1223
- /** Context for one check, under ONE deadline shared by every lookup. */
1224
- function makeCtx(options, feed, command = "") {
1225
- const timeout = AbortSignal.timeout(TIMEOUT_MS);
1226
- const cache = verdictCache(options.cacheDir !== undefined
1227
- ? options.cacheDir
1228
- : process.env.VITEST
1229
- ? null // tests never write to the real GG dir
1230
- : getAppPaths().agentDir);
1231
- return {
1232
- fetch: options.fetch ?? fetch,
1233
- signal: options.signal ? AbortSignal.any([timeout, options.signal]) : timeout,
1234
- cancelled: () => options.signal?.aborted === true,
1235
- reached: { value: false },
1236
- now: (options.now ?? Date.now)(),
1237
- days: options.cooldownDays ?? 2,
1238
- feed,
1239
- cache,
1240
- managerVersion: options.managerVersion ?? ((m) => managerVersion(m, options.cwd)),
1241
- privateSource: (eco) => eco === "npm"
1242
- ? usesCustomNpmRegistry(command, options.cwd ?? process.cwd(), options.env)
1243
- : usesCustomPypiIndex(command, options.env),
1244
- };
1245
- }
1246
- /** Lockfile names checked for already-installed packages, with their ecosystem. */
1247
- export const PROJECT_LOCKFILES = [
1248
- { ecosystem: "npm", manager: "npm", file: "package-lock.json" },
1249
- { ecosystem: "npm", manager: "pnpm", file: "pnpm-lock.yaml" },
1250
- { ecosystem: "npm", manager: "yarn", file: "yarn.lock" },
1251
- { ecosystem: "npm", manager: "bun", file: "bun.lock" },
1252
- { ecosystem: "PyPI", manager: "uv", file: "uv.lock", resolves: true },
1253
- { ecosystem: "PyPI", manager: "pip", file: "requirements.txt" },
1254
- ];
1255
- /**
1256
- * Malware check of one existing lockfile (already-installed packages): the
1257
- * local feed plus one batched OSV lookup, cached by content hash and re-asked
1258
- * at most once a day. No release-age check. Fail-open like every other check.
1259
- */
1260
- export async function checkLockfileMalware(lock, cwd, options = {}) {
1261
- const ctx = makeCtx(options, options.feed ?? loadThreatFeed());
1262
- const work = (async () => {
1263
- await ctx.cache.load();
1264
- return checkLockfile({ ...lock, resolves: true }, cwd, ctx);
1265
- })();
1266
- const out = await Promise.race([work, deadline(ctx.signal)]).catch((err) => {
1267
- log("WARN", "package-threats", `lockfile check cut short: ${String(err)}`);
1268
- noteDeadline(ctx);
1269
- return [];
1270
- });
1271
- ctx.cache.save(ctx.now);
1272
- return out;
1273
- }
1274
- /** Full check for one bash command. Returns blocks only; [] when clean or not an install. */
1275
- export async function checkPackageInstall(command, options = {}) {
1276
- const local = localPackageCheck(command, () => options.feed ?? loadThreatFeed());
1277
- if (local.refs.length === 0 && local.lockfiles.length === 0)
1278
- return [];
1279
- const ctx = makeCtx(options, local.feed, command);
1280
- const cache = ctx.cache;
1281
- const threats = [...local.threats];
1282
- const cwd = options.cwd ?? process.cwd();
1283
- const work = (async () => {
1284
- await cache.load();
1285
- const parts = await Promise.all([
1286
- local.refs.length > 0 ? checkNamed(local, ctx) : [],
1287
- ...local.lockfiles.map((lock) => checkLockfile(lock, cwd, ctx)),
1288
- ]);
1289
- return parts.flat();
1290
- })();
1291
- const out = await Promise.race([work, deadline(ctx.signal)]).catch((err) => {
1292
- log("WARN", "package-threats", `check cut short, allowing: ${String(err)}`);
1293
- noteDeadline(ctx);
1294
- return [];
1295
- });
1296
- cache.save(ctx.now);
1297
- return [...threats, ...out];
1298
- }
1299
- /** One plain line for the agent, or null when nothing blocks. */
1300
- export function packageBlockMessage(threats) {
1301
- const blocks = threats.filter((t) => t.severity === "block");
1302
- if (blocks.length === 0)
1303
- return null;
1304
- return `Blocked install (${blocks[0]?.rule}): ${blocks.map((t) => t.detail).join(" ")} ${SAFETY_BLOCK_NOTE}`;
1305
- }
1306
- /**
1307
- * Check an MCP stdio launch (`npx -y pkg`, `uvx pkg`) before spawning.
1308
- * Returns the block line, or null to allow.
1309
- */
1310
- export async function checkMcpLaunch(command, args, options = {}) {
1311
- const base = path
1312
- .basename(command)
1313
- .toLowerCase()
1314
- .replace(/\.(cmd|exe)$/, "");
1315
- if (!["npx", "uvx", "bunx", "pnpm", "npm", "uv"].includes(base))
1316
- return null;
1317
- const line = [base, ...args].map((a) => (/\s/.test(a) ? `"${a}"` : a)).join(" ");
1318
- // MCP launches get no bun flag, so bunx gets the own age check.
1319
- const versions = options.managerVersion ?? ((m) => managerVersion(m));
1320
- const message = packageBlockMessage(await checkPackageInstall(line, {
1321
- ...options,
1322
- managerVersion: (m) => (m === "bun" ? Promise.resolve(null) : versions(m)),
1323
- }));
1324
- // Shown to the user on the MCP settings row, not to the agent.
1325
- return message?.replace(` ${SAFETY_BLOCK_NOTE}`, "") ?? null;
1326
- }
1327
- /** Wait for pending verdict-cache writes (tests). */
1328
- export async function flushPackageVerdicts() {
1329
- await Promise.all([...verdictCaches.values()].map((c) => c.flush()));
1330
- }
1331
- /** Test hook: forget cached answers (memory only; the disk file is left alone). */
1332
- export function clearPackageThreatCache() {
1333
- osvCache.clear();
1334
- vulnCache.clear();
1335
- metaCache.clear();
1336
- lockfileCache.clear();
1337
- verdictCaches.clear();
1338
- downHosts.clear();
1339
- }
1340
- //# sourceMappingURL=package-threats.js.map