@cybedefend/vibedefend 1.8.2 → 1.9.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 (328) hide show
  1. package/README.md +185 -17
  2. package/dist/auth/auth-store.js +16 -0
  3. package/dist/auth/auth-store.js.map +1 -1
  4. package/dist/clients/antigravity.js +30 -6
  5. package/dist/clients/antigravity.js.map +1 -1
  6. package/dist/clients/claude-code.js +209 -17
  7. package/dist/clients/claude-code.js.map +1 -1
  8. package/dist/clients/codex.js +171 -11
  9. package/dist/clients/codex.js.map +1 -1
  10. package/dist/clients/cursor.js +149 -9
  11. package/dist/clients/cursor.js.map +1 -1
  12. package/dist/clients/dependency-check-wiring.js +24 -0
  13. package/dist/clients/dependency-check-wiring.js.map +1 -0
  14. package/dist/clients/opencode-plugin.js +905 -0
  15. package/dist/clients/opencode-plugin.js.map +1 -0
  16. package/dist/clients/opencode.js +653 -0
  17. package/dist/clients/opencode.js.map +1 -0
  18. package/dist/clients/registry.js +2 -0
  19. package/dist/clients/registry.js.map +1 -1
  20. package/dist/clients/vscode.js +106 -12
  21. package/dist/clients/vscode.js.map +1 -1
  22. package/dist/clients/windsurf.js +9 -1
  23. package/dist/clients/windsurf.js.map +1 -1
  24. package/dist/commands/mcp/index.js +11 -0
  25. package/dist/commands/mcp/index.js.map +1 -1
  26. package/dist/config.js +4 -1
  27. package/dist/config.js.map +1 -1
  28. package/dist/diagnostics.js +22 -3
  29. package/dist/diagnostics.js.map +1 -1
  30. package/dist/doctor.js +26 -1
  31. package/dist/doctor.js.map +1 -1
  32. package/dist/guards-evaluator/command-analysis.js +347 -86
  33. package/dist/guards-evaluator/command-analysis.js.map +1 -1
  34. package/dist/guards-evaluator/command-view.js +116 -16
  35. package/dist/guards-evaluator/command-view.js.map +1 -1
  36. package/dist/guards-evaluator/evaluate.js +185 -41
  37. package/dist/guards-evaluator/evaluate.js.map +1 -1
  38. package/dist/guards-evaluator/file-reads.js +202 -0
  39. package/dist/guards-evaluator/file-reads.js.map +1 -0
  40. package/dist/guards-evaluator/index.js +1 -1
  41. package/dist/guards-evaluator/index.js.map +1 -1
  42. package/dist/guards-evaluator/inline-danger.js +299 -0
  43. package/dist/guards-evaluator/inline-danger.js.map +1 -0
  44. package/dist/guards-evaluator/normalize.js +1186 -55
  45. package/dist/guards-evaluator/normalize.js.map +1 -1
  46. package/dist/guards-evaluator/regex.js +91 -4
  47. package/dist/guards-evaluator/regex.js.map +1 -1
  48. package/dist/guards-evaluator/shell-files.js +587 -0
  49. package/dist/guards-evaluator/shell-files.js.map +1 -0
  50. package/dist/guards-evaluator/triage.js +32 -2
  51. package/dist/guards-evaluator/triage.js.map +1 -1
  52. package/dist/hook-runner.js +25601 -5423
  53. package/dist/hooks/install.js +8 -3
  54. package/dist/hooks/install.js.map +1 -1
  55. package/dist/hooks/runtime/antigravity-session.js +109 -50
  56. package/dist/hooks/runtime/antigravity-session.js.map +1 -1
  57. package/dist/hooks/runtime/apply-patch.js +92 -0
  58. package/dist/hooks/runtime/apply-patch.js.map +1 -0
  59. package/dist/hooks/runtime/caller-gate.js +27 -0
  60. package/dist/hooks/runtime/caller-gate.js.map +1 -0
  61. package/dist/hooks/runtime/code-mode.js +259 -0
  62. package/dist/hooks/runtime/code-mode.js.map +1 -0
  63. package/dist/hooks/runtime/dependency-check/api.js +179 -0
  64. package/dist/hooks/runtime/dependency-check/api.js.map +1 -0
  65. package/dist/hooks/runtime/dependency-check/capabilities.js +99 -0
  66. package/dist/hooks/runtime/dependency-check/capabilities.js.map +1 -0
  67. package/dist/hooks/runtime/dependency-check/checked-packages.js +48 -0
  68. package/dist/hooks/runtime/dependency-check/checked-packages.js.map +1 -0
  69. package/dist/hooks/runtime/dependency-check/commands/cwd.js +154 -0
  70. package/dist/hooks/runtime/dependency-check/commands/cwd.js.map +1 -0
  71. package/dist/hooks/runtime/dependency-check/commands/env.js +99 -0
  72. package/dist/hooks/runtime/dependency-check/commands/env.js.map +1 -0
  73. package/dist/hooks/runtime/dependency-check/commands/flags.js +164 -0
  74. package/dist/hooks/runtime/dependency-check/commands/flags.js.map +1 -0
  75. package/dist/hooks/runtime/dependency-check/commands/managers.js +418 -0
  76. package/dist/hooks/runtime/dependency-check/commands/managers.js.map +1 -0
  77. package/dist/hooks/runtime/dependency-check/commands/peel.js +111 -0
  78. package/dist/hooks/runtime/dependency-check/commands/peel.js.map +1 -0
  79. package/dist/hooks/runtime/dependency-check/commands/shell.js +217 -0
  80. package/dist/hooks/runtime/dependency-check/commands/shell.js.map +1 -0
  81. package/dist/hooks/runtime/dependency-check/commands/types.js +4 -0
  82. package/dist/hooks/runtime/dependency-check/commands/types.js.map +1 -0
  83. package/dist/hooks/runtime/dependency-check/commands.js +34 -0
  84. package/dist/hooks/runtime/dependency-check/commands.js.map +1 -0
  85. package/dist/hooks/runtime/dependency-check/deadlines.js +69 -0
  86. package/dist/hooks/runtime/dependency-check/deadlines.js.map +1 -0
  87. package/dist/hooks/runtime/dependency-check/dispatch.js +344 -0
  88. package/dist/hooks/runtime/dependency-check/dispatch.js.map +1 -0
  89. package/dist/hooks/runtime/dependency-check/entering.js +63 -0
  90. package/dist/hooks/runtime/dependency-check/entering.js.map +1 -0
  91. package/dist/hooks/runtime/dependency-check/exec-cache.js +36 -0
  92. package/dist/hooks/runtime/dependency-check/exec-cache.js.map +1 -0
  93. package/dist/hooks/runtime/dependency-check/git-blob.js +116 -0
  94. package/dist/hooks/runtime/dependency-check/git-blob.js.map +1 -0
  95. package/dist/hooks/runtime/dependency-check/hook.js +418 -0
  96. package/dist/hooks/runtime/dependency-check/hook.js.map +1 -0
  97. package/dist/hooks/runtime/dependency-check/local-store.js +74 -0
  98. package/dist/hooks/runtime/dependency-check/local-store.js.map +1 -0
  99. package/dist/hooks/runtime/dependency-check/lockfile-walk.js +89 -0
  100. package/dist/hooks/runtime/dependency-check/lockfile-walk.js.map +1 -0
  101. package/dist/hooks/runtime/dependency-check/lockfiles/bun.js +153 -0
  102. package/dist/hooks/runtime/dependency-check/lockfiles/bun.js.map +1 -0
  103. package/dist/hooks/runtime/dependency-check/lockfiles/by-name.js +46 -0
  104. package/dist/hooks/runtime/dependency-check/lockfiles/by-name.js.map +1 -0
  105. package/dist/hooks/runtime/dependency-check/lockfiles/cargo.js +91 -0
  106. package/dist/hooks/runtime/dependency-check/lockfiles/cargo.js.map +1 -0
  107. package/dist/hooks/runtime/dependency-check/lockfiles/composer.js +98 -0
  108. package/dist/hooks/runtime/dependency-check/lockfiles/composer.js.map +1 -0
  109. package/dist/hooks/runtime/dependency-check/lockfiles/gemfile.js +88 -0
  110. package/dist/hooks/runtime/dependency-check/lockfiles/gemfile.js.map +1 -0
  111. package/dist/hooks/runtime/dependency-check/lockfiles/go-mod.js +154 -0
  112. package/dist/hooks/runtime/dependency-check/lockfiles/go-mod.js.map +1 -0
  113. package/dist/hooks/runtime/dependency-check/lockfiles/gradle-lockfile.js +27 -0
  114. package/dist/hooks/runtime/dependency-check/lockfiles/gradle-lockfile.js.map +1 -0
  115. package/dist/hooks/runtime/dependency-check/lockfiles/graph.js +131 -0
  116. package/dist/hooks/runtime/dependency-check/lockfiles/graph.js.map +1 -0
  117. package/dist/hooks/runtime/dependency-check/lockfiles/npm.js +107 -0
  118. package/dist/hooks/runtime/dependency-check/lockfiles/npm.js.map +1 -0
  119. package/dist/hooks/runtime/dependency-check/lockfiles/nuget-packages-lock.js +60 -0
  120. package/dist/hooks/runtime/dependency-check/lockfiles/nuget-packages-lock.js.map +1 -0
  121. package/dist/hooks/runtime/dependency-check/lockfiles/pins.js +105 -0
  122. package/dist/hooks/runtime/dependency-check/lockfiles/pins.js.map +1 -0
  123. package/dist/hooks/runtime/dependency-check/lockfiles/pip-report.js +34 -0
  124. package/dist/hooks/runtime/dependency-check/lockfiles/pip-report.js.map +1 -0
  125. package/dist/hooks/runtime/dependency-check/lockfiles/pnpm.js +109 -0
  126. package/dist/hooks/runtime/dependency-check/lockfiles/pnpm.js.map +1 -0
  127. package/dist/hooks/runtime/dependency-check/lockfiles/poetry.js +105 -0
  128. package/dist/hooks/runtime/dependency-check/lockfiles/poetry.js.map +1 -0
  129. package/dist/hooks/runtime/dependency-check/lockfiles/uv.js +181 -0
  130. package/dist/hooks/runtime/dependency-check/lockfiles/uv.js.map +1 -0
  131. package/dist/hooks/runtime/dependency-check/lockfiles/yaml.js +319 -0
  132. package/dist/hooks/runtime/dependency-check/lockfiles/yaml.js.map +1 -0
  133. package/dist/hooks/runtime/dependency-check/lockfiles/yarn-berry.js +71 -0
  134. package/dist/hooks/runtime/dependency-check/lockfiles/yarn-berry.js.map +1 -0
  135. package/dist/hooks/runtime/dependency-check/lockfiles/yarn1.js +144 -0
  136. package/dist/hooks/runtime/dependency-check/lockfiles/yarn1.js.map +1 -0
  137. package/dist/hooks/runtime/dependency-check/manifests/apply.js +110 -0
  138. package/dist/hooks/runtime/dependency-check/manifests/apply.js.map +1 -0
  139. package/dist/hooks/runtime/dependency-check/manifests/diff.js +127 -0
  140. package/dist/hooks/runtime/dependency-check/manifests/diff.js.map +1 -0
  141. package/dist/hooks/runtime/dependency-check/manifests/edit.js +259 -0
  142. package/dist/hooks/runtime/dependency-check/manifests/edit.js.map +1 -0
  143. package/dist/hooks/runtime/dependency-check/manifests/json.js +109 -0
  144. package/dist/hooks/runtime/dependency-check/manifests/json.js.map +1 -0
  145. package/dist/hooks/runtime/dependency-check/manifests/kind.js +40 -0
  146. package/dist/hooks/runtime/dependency-check/manifests/kind.js.map +1 -0
  147. package/dist/hooks/runtime/dependency-check/manifests/patch.js +179 -0
  148. package/dist/hooks/runtime/dependency-check/manifests/patch.js.map +1 -0
  149. package/dist/hooks/runtime/dependency-check/manifests/text.js +665 -0
  150. package/dist/hooks/runtime/dependency-check/manifests/text.js.map +1 -0
  151. package/dist/hooks/runtime/dependency-check/manifests/toml.js +350 -0
  152. package/dist/hooks/runtime/dependency-check/manifests/toml.js.map +1 -0
  153. package/dist/hooks/runtime/dependency-check/manifests.js +14 -0
  154. package/dist/hooks/runtime/dependency-check/manifests.js.map +1 -0
  155. package/dist/hooks/runtime/dependency-check/messages.js +270 -0
  156. package/dist/hooks/runtime/dependency-check/messages.js.map +1 -0
  157. package/dist/hooks/runtime/dependency-check/net-baseline.js +157 -0
  158. package/dist/hooks/runtime/dependency-check/net-baseline.js.map +1 -0
  159. package/dist/hooks/runtime/dependency-check/net-state.js +70 -0
  160. package/dist/hooks/runtime/dependency-check/net-state.js.map +1 -0
  161. package/dist/hooks/runtime/dependency-check/pending-forces.js +54 -0
  162. package/dist/hooks/runtime/dependency-check/pending-forces.js.map +1 -0
  163. package/dist/hooks/runtime/dependency-check/post-tool-use.js +108 -0
  164. package/dist/hooks/runtime/dependency-check/post-tool-use.js.map +1 -0
  165. package/dist/hooks/runtime/dependency-check/ranges.js +369 -0
  166. package/dist/hooks/runtime/dependency-check/ranges.js.map +1 -0
  167. package/dist/hooks/runtime/dependency-check/requirement-files.js +144 -0
  168. package/dist/hooks/runtime/dependency-check/requirement-files.js.map +1 -0
  169. package/dist/hooks/runtime/dependency-check/resolvers/bun.js +38 -0
  170. package/dist/hooks/runtime/dependency-check/resolvers/bun.js.map +1 -0
  171. package/dist/hooks/runtime/dependency-check/resolvers/bundler.js +218 -0
  172. package/dist/hooks/runtime/dependency-check/resolvers/bundler.js.map +1 -0
  173. package/dist/hooks/runtime/dependency-check/resolvers/cargo.js +303 -0
  174. package/dist/hooks/runtime/dependency-check/resolvers/cargo.js.map +1 -0
  175. package/dist/hooks/runtime/dependency-check/resolvers/composer.js +250 -0
  176. package/dist/hooks/runtime/dependency-check/resolvers/composer.js.map +1 -0
  177. package/dist/hooks/runtime/dependency-check/resolvers/config-files.js +27 -0
  178. package/dist/hooks/runtime/dependency-check/resolvers/config-files.js.map +1 -0
  179. package/dist/hooks/runtime/dependency-check/resolvers/direct-only-registry.js +409 -0
  180. package/dist/hooks/runtime/dependency-check/resolvers/direct-only-registry.js.map +1 -0
  181. package/dist/hooks/runtime/dependency-check/resolvers/direct-only.js +290 -0
  182. package/dist/hooks/runtime/dependency-check/resolvers/direct-only.js.map +1 -0
  183. package/dist/hooks/runtime/dependency-check/resolvers/gem.js +89 -0
  184. package/dist/hooks/runtime/dependency-check/resolvers/gem.js.map +1 -0
  185. package/dist/hooks/runtime/dependency-check/resolvers/go.js +313 -0
  186. package/dist/hooks/runtime/dependency-check/resolvers/go.js.map +1 -0
  187. package/dist/hooks/runtime/dependency-check/resolvers/npm.js +81 -0
  188. package/dist/hooks/runtime/dependency-check/resolvers/npm.js.map +1 -0
  189. package/dist/hooks/runtime/dependency-check/resolvers/pip.js +229 -0
  190. package/dist/hooks/runtime/dependency-check/resolvers/pip.js.map +1 -0
  191. package/dist/hooks/runtime/dependency-check/resolvers/pipx.js +8 -0
  192. package/dist/hooks/runtime/dependency-check/resolvers/pipx.js.map +1 -0
  193. package/dist/hooks/runtime/dependency-check/resolvers/pnpm.js +68 -0
  194. package/dist/hooks/runtime/dependency-check/resolvers/pnpm.js.map +1 -0
  195. package/dist/hooks/runtime/dependency-check/resolvers/poetry.js +70 -0
  196. package/dist/hooks/runtime/dependency-check/resolvers/poetry.js.map +1 -0
  197. package/dist/hooks/runtime/dependency-check/resolvers/project.js +208 -0
  198. package/dist/hooks/runtime/dependency-check/resolvers/project.js.map +1 -0
  199. package/dist/hooks/runtime/dependency-check/resolvers/python-index.js +270 -0
  200. package/dist/hooks/runtime/dependency-check/resolvers/python-index.js.map +1 -0
  201. package/dist/hooks/runtime/dependency-check/resolvers/python.js +229 -0
  202. package/dist/hooks/runtime/dependency-check/resolvers/python.js.map +1 -0
  203. package/dist/hooks/runtime/dependency-check/resolvers/registry.js +221 -0
  204. package/dist/hooks/runtime/dependency-check/resolvers/registry.js.map +1 -0
  205. package/dist/hooks/runtime/dependency-check/resolvers/shared.js +440 -0
  206. package/dist/hooks/runtime/dependency-check/resolvers/shared.js.map +1 -0
  207. package/dist/hooks/runtime/dependency-check/resolvers/tree.js +131 -0
  208. package/dist/hooks/runtime/dependency-check/resolvers/tree.js.map +1 -0
  209. package/dist/hooks/runtime/dependency-check/resolvers/uv.js +433 -0
  210. package/dist/hooks/runtime/dependency-check/resolvers/uv.js.map +1 -0
  211. package/dist/hooks/runtime/dependency-check/resolvers/xml-lite.js +132 -0
  212. package/dist/hooks/runtime/dependency-check/resolvers/xml-lite.js.map +1 -0
  213. package/dist/hooks/runtime/dependency-check/resolvers/yarn-berry.js +106 -0
  214. package/dist/hooks/runtime/dependency-check/resolvers/yarn-berry.js.map +1 -0
  215. package/dist/hooks/runtime/dependency-check/sandbox.js +328 -0
  216. package/dist/hooks/runtime/dependency-check/sandbox.js.map +1 -0
  217. package/dist/hooks/runtime/dependency-check/specs.js +171 -0
  218. package/dist/hooks/runtime/dependency-check/specs.js.map +1 -0
  219. package/dist/hooks/runtime/dependency-check/static-view.js +90 -0
  220. package/dist/hooks/runtime/dependency-check/static-view.js.map +1 -0
  221. package/dist/hooks/runtime/dependency-check/stop-net.js +278 -0
  222. package/dist/hooks/runtime/dependency-check/stop-net.js.map +1 -0
  223. package/dist/hooks/runtime/dependency-check/stop-wiring.js +94 -0
  224. package/dist/hooks/runtime/dependency-check/stop-wiring.js.map +1 -0
  225. package/dist/hooks/runtime/dependency-check/tool-call.js +130 -0
  226. package/dist/hooks/runtime/dependency-check/tool-call.js.map +1 -0
  227. package/dist/hooks/runtime/dependency-check/types.js +96 -0
  228. package/dist/hooks/runtime/dependency-check/types.js.map +1 -0
  229. package/dist/hooks/runtime/emit.js +240 -52
  230. package/dist/hooks/runtime/emit.js.map +1 -1
  231. package/dist/hooks/runtime/exit-deadlock-guard.js +24 -8
  232. package/dist/hooks/runtime/exit-deadlock-guard.js.map +1 -1
  233. package/dist/hooks/runtime/fetch-rules.js +78 -29
  234. package/dist/hooks/runtime/fetch-rules.js.map +1 -1
  235. package/dist/hooks/runtime/grep-include.js +228 -0
  236. package/dist/hooks/runtime/grep-include.js.map +1 -0
  237. package/dist/hooks/runtime/pre-compact.js +1 -1
  238. package/dist/hooks/runtime/pre-compact.js.map +1 -1
  239. package/dist/hooks/runtime/pre-invocation.js +3 -3
  240. package/dist/hooks/runtime/pre-invocation.js.map +1 -1
  241. package/dist/hooks/runtime/repo-registry.js +72 -0
  242. package/dist/hooks/runtime/repo-registry.js.map +1 -0
  243. package/dist/hooks/runtime/repo-scope.js +75 -0
  244. package/dist/hooks/runtime/repo-scope.js.map +1 -0
  245. package/dist/hooks/runtime/resolve.js +11 -2
  246. package/dist/hooks/runtime/resolve.js.map +1 -1
  247. package/dist/hooks/runtime/runner-args.js +17 -2
  248. package/dist/hooks/runtime/runner-args.js.map +1 -1
  249. package/dist/hooks/runtime/script-resolve.js +21 -5
  250. package/dist/hooks/runtime/script-resolve.js.map +1 -1
  251. package/dist/hooks/runtime/session-activation.js +71 -18
  252. package/dist/hooks/runtime/session-activation.js.map +1 -1
  253. package/dist/hooks/runtime/session-review.js +184 -88
  254. package/dist/hooks/runtime/session-review.js.map +1 -1
  255. package/dist/hooks/runtime/session-start.js +68 -13
  256. package/dist/hooks/runtime/session-start.js.map +1 -1
  257. package/dist/hooks/runtime/session-writes.js +11 -5
  258. package/dist/hooks/runtime/session-writes.js.map +1 -1
  259. package/dist/hooks/runtime/shell-writes.js +7 -88
  260. package/dist/hooks/runtime/shell-writes.js.map +1 -1
  261. package/dist/hooks/runtime/sniff.js +227 -2
  262. package/dist/hooks/runtime/sniff.js.map +1 -1
  263. package/dist/hooks/runtime/target-resolve.js +32 -17
  264. package/dist/hooks/runtime/target-resolve.js.map +1 -1
  265. package/dist/hooks/runtime/unmapped-tools.js +77 -1
  266. package/dist/hooks/runtime/unmapped-tools.js.map +1 -1
  267. package/dist/hooks/runtime/user-prompt-submit.js +1 -1
  268. package/dist/hooks/runtime/user-prompt-submit.js.map +1 -1
  269. package/dist/hooks/runtime/work-dir.js +3 -0
  270. package/dist/hooks/runtime/work-dir.js.map +1 -1
  271. package/dist/hooks/shim.js +27 -20
  272. package/dist/hooks/shim.js.map +1 -1
  273. package/dist/index.js +46 -10
  274. package/dist/index.js.map +1 -1
  275. package/dist/install-scope.js +12 -0
  276. package/dist/install-scope.js.map +1 -0
  277. package/dist/install.js +188 -78
  278. package/dist/install.js.map +1 -1
  279. package/dist/link.js +55 -5
  280. package/dist/link.js.map +1 -1
  281. package/dist/mcp/config/hook.js +25 -0
  282. package/dist/mcp/config/hook.js.map +1 -1
  283. package/dist/org.js +3 -1
  284. package/dist/org.js.map +1 -1
  285. package/dist/prompts.js +97 -13
  286. package/dist/prompts.js.map +1 -1
  287. package/dist/refresh-hooks.js +67 -15
  288. package/dist/refresh-hooks.js.map +1 -1
  289. package/dist/repo/exclude-block.js +112 -0
  290. package/dist/repo/exclude-block.js.map +1 -0
  291. package/dist/repo/footer.js +93 -0
  292. package/dist/repo/footer.js.map +1 -0
  293. package/dist/repo/git-repo.js +77 -0
  294. package/dist/repo/git-repo.js.map +1 -0
  295. package/dist/repo/guarded-write.js +45 -0
  296. package/dist/repo/guarded-write.js.map +1 -0
  297. package/dist/repo/install-repo.js +508 -0
  298. package/dist/repo/install-repo.js.map +1 -0
  299. package/dist/repo/machine-wiring.js +122 -0
  300. package/dist/repo/machine-wiring.js.map +1 -0
  301. package/dist/repo/mcp-json.js +57 -0
  302. package/dist/repo/mcp-json.js.map +1 -0
  303. package/dist/repo/registry.js +53 -0
  304. package/dist/repo/registry.js.map +1 -0
  305. package/dist/repo/repo-mode-guard.js +83 -0
  306. package/dist/repo/repo-mode-guard.js.map +1 -0
  307. package/dist/repo/repo-setups.js +123 -0
  308. package/dist/repo/repo-setups.js.map +1 -0
  309. package/dist/repo/repo-status.js +283 -0
  310. package/dist/repo/repo-status.js.map +1 -0
  311. package/dist/repo/uninstall-repo.js +56 -0
  312. package/dist/repo/uninstall-repo.js.map +1 -0
  313. package/dist/repo/unsupported.js +14 -0
  314. package/dist/repo/unsupported.js.map +1 -0
  315. package/dist/scan-diff.js +526 -0
  316. package/dist/scan-diff.js.map +1 -0
  317. package/dist/shim.js +9 -7
  318. package/dist/status.js +53 -11
  319. package/dist/status.js.map +1 -1
  320. package/dist/uninstall.js +51 -3
  321. package/dist/uninstall.js.map +1 -1
  322. package/dist/update-check-gate.js +17 -0
  323. package/dist/update-check-gate.js.map +1 -0
  324. package/dist/update.js +6 -1
  325. package/dist/update.js.map +1 -1
  326. package/dist/zip.js +95 -0
  327. package/dist/zip.js.map +1 -0
  328. package/package.json +6 -3
@@ -0,0 +1,270 @@
1
+ import { DEPENDENCY_CHECK_MAX_PACKAGES, } from './types.js';
2
+ export const PREFIX = '[VibeDefend dependency check]';
3
+ export const NOTHING_TOLD = { notVerified: [], incomplete: [], overflow: 0, noDirectory: false };
4
+ export const hasSomethingToTell = (t) => t.notVerified.length > 0 || t.incomplete.length > 0 || t.overflow > 0 || t.noDirectory;
5
+ /** Why nothing was checked at all. */
6
+ export const NOT_CHECKED_REASONS = [
7
+ 'timeout',
8
+ /** The hook's own time ran out before the gateway could be called. */
9
+ 'no_time',
10
+ 'unavailable',
11
+ 'refused',
12
+ 'network',
13
+ 'no_directory',
14
+ 'not_signed_in',
15
+ 'usage_blocked',
16
+ ];
17
+ const NOT_CHECKED = {
18
+ timeout: 'CybeDefend did not answer in time',
19
+ no_time: 'the check could not run in time: the hook had no time left to ask CybeDefend',
20
+ unavailable: 'CybeDefend could not check them right now',
21
+ refused: 'CybeDefend did not accept the request',
22
+ network: 'CybeDefend could not be reached',
23
+ no_directory: 'VibeDefend could not tell which directory the command runs in',
24
+ not_signed_in: 'no CybeDefend sign-in was found on this machine',
25
+ usage_blocked: 'VibeDefend diff scans are paused for your organisation',
26
+ };
27
+ /** Why one package was not verified. */
28
+ const NOT_VERIFIED_WHY = {
29
+ git_or_url: 'a git or URL dependency cannot be matched against known advisories',
30
+ source_only: 'it has no wheel, and the check never builds a source distribution',
31
+ version_range: 'the version it would install could not be known before the install',
32
+ resolution_failed: 'it could not be resolved to a package and version that advisories name',
33
+ resolution_timeout: 'resolving it took longer than the check allows',
34
+ manager_missing: 'the package manager it needs is not available here, or cannot resolve without installing',
35
+ project_code: 'the package manager was not run, so as not to execute project code',
36
+ custom_registry: 'it comes from another registry, which the check does not resolve against',
37
+ workspace_too_large: 'the workspace has more manifests than a check reads',
38
+ include_not_followed: 'it is a file a requirements file includes, which the check does not read',
39
+ };
40
+ /** Why the transitive dependencies were not checked (the direct packages were). */
41
+ const INCOMPLETE_WHY = {
42
+ git_or_url: 'a git or URL dependency cannot be resolved against the registry',
43
+ source_only: 'a package has no wheel, and the check never builds one to read its dependencies',
44
+ version_range: 'the versions that would be installed could not be known in advance',
45
+ resolution_failed: 'the dependency tree could not be resolved',
46
+ resolution_timeout: 'resolving the dependency tree took longer than the check allows',
47
+ manager_missing: 'the package manager is not available here, or cannot resolve the tree without installing',
48
+ project_code: 'the package manager was not run, so as not to execute project code',
49
+ custom_registry: 'the packages come from another registry, which the check does not resolve against',
50
+ workspace_too_large: 'the workspace has more manifests than a check reads',
51
+ include_not_followed: 'a requirements file includes another file, which the check does not read',
52
+ };
53
+ /** Findings listed in full; the rest are counted. */
54
+ const MAX_LISTED_FINDINGS = 25;
55
+ /** Names listed per not-verified reason; the rest are counted. */
56
+ const MAX_LISTED_NAMES = 10;
57
+ const SUMMARY_MAX = 300;
58
+ // ---------------------------------------------------------------------------
59
+ // Server strings, made printable
60
+ // ---------------------------------------------------------------------------
61
+ /** Control, bidirectional and line-breaking characters: never printed. */
62
+ // eslint-disable-next-line no-control-regex
63
+ const UNPRINTABLE_RE = /[\u0000-\u001f\u007f-\u009f\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g;
64
+ /** One line, bounded, credentials of a URL removed. */
65
+ function clean(value, max) {
66
+ if (typeof value !== 'string')
67
+ return '';
68
+ const line = value
69
+ .replace(UNPRINTABLE_RE, ' ')
70
+ .replace(/\/\/[^/@\s]*@/g, '//')
71
+ .replace(/\s+/g, ' ')
72
+ .trim();
73
+ return line.length > max ? `${line.slice(0, max - 3).trimEnd()}...` : line;
74
+ }
75
+ const ADVISORY_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,99}$/;
76
+ const SEVERITIES = new Set(['critical', 'high', 'medium', 'low']);
77
+ function advisoryId(r) {
78
+ return typeof r.advisoryId === 'string' && ADVISORY_ID_RE.test(r.advisoryId) ? r.advisoryId : null;
79
+ }
80
+ /** `YYYY-MM-DD` of an ISO date, or null. */
81
+ function day(value) {
82
+ if (typeof value !== 'string')
83
+ return null;
84
+ const t = Date.parse(value);
85
+ return Number.isFinite(t) ? new Date(t).toISOString().slice(0, 10) : null;
86
+ }
87
+ // ---------------------------------------------------------------------------
88
+ // One finding
89
+ // ---------------------------------------------------------------------------
90
+ /**
91
+ * A finding that blocks because the package is malicious: a blocking finding
92
+ * with a malicious reason no exception covers. An excepted reason no longer
93
+ * blocks (the backend's verdict), so it does not count. The one definition of
94
+ * the hook (only an administrator may lift it) and of the messages.
95
+ */
96
+ export function isMaliciousBlock(f) {
97
+ return f.verdict === 'block' && f.reasons.some((r) => r.kind === 'malicious' && r.exceptedByUserId === undefined);
98
+ }
99
+ function reasonClause(r) {
100
+ const id = advisoryId(r);
101
+ const summary = clean(r.summary, SUMMARY_MAX);
102
+ const quoted = summary !== '' ? `: "${summary}"` : '';
103
+ let clause;
104
+ switch (r.kind) {
105
+ case 'malicious':
106
+ clause = `known malicious package${id ? ` (${id})` : ''}${quoted}`;
107
+ break;
108
+ case 'vulnerable': {
109
+ const severity = typeof r.severity === 'string' && SEVERITIES.has(r.severity) ? `, ${r.severity} severity` : '';
110
+ const fixed = clean(r.fixedVersion, 128);
111
+ clause = `${id ?? 'a known vulnerability'}${severity}${quoted}, ${fixed !== '' ? `fixed in ${fixed}` : 'no fixed version is known'}`;
112
+ break;
113
+ }
114
+ case 'brand_new': {
115
+ const d = day(r.publishedAt);
116
+ clause = `a brand-new package${d ? `, first published on ${d}` : ''}`;
117
+ break;
118
+ }
119
+ case 'recent_version': {
120
+ const d = day(r.publishedAt);
121
+ clause = `this version was published recently${d ? ` (${d})` : ''}, and advisories may not know about it yet`;
122
+ break;
123
+ }
124
+ case 'dates_unavailable':
125
+ clause = 'its publication dates could not be read, so the age checks were left out';
126
+ break;
127
+ case 'invalid_coordinates':
128
+ clause = 'its name or version is not valid for its registry, so it was not checked';
129
+ break;
130
+ default:
131
+ clause = 'flagged by the check';
132
+ }
133
+ return r.exceptedByUserId !== undefined ? `${clause} (accepted for this project)` : clause;
134
+ }
135
+ /** `- name version (direct): clause; clause.` */
136
+ export function findingLine(f) {
137
+ const origin = f.direct ? 'direct' : f.via ? `via ${clean(f.via, 256)}` : 'transitive';
138
+ const clauses = f.reasons.map(reasonClause);
139
+ return `- ${clean(f.name, 256)} ${clean(f.version, 128)} (${origin}): ${clauses.length > 0 ? clauses.join('; ') : 'flagged by the check'}.`;
140
+ }
141
+ function findingLines(findings) {
142
+ const ordered = [...findings.filter((f) => f.verdict === 'block'), ...findings.filter((f) => f.verdict !== 'block')];
143
+ const lines = ordered.slice(0, MAX_LISTED_FINDINGS).map(findingLine);
144
+ const rest = ordered.length - MAX_LISTED_FINDINGS;
145
+ if (rest > 0)
146
+ lines.push(`${rest} more ${rest === 1 ? 'package is' : 'packages are'} not listed here.`);
147
+ return lines;
148
+ }
149
+ // ---------------------------------------------------------------------------
150
+ // What was not checked
151
+ // ---------------------------------------------------------------------------
152
+ export function notCheckedSentence(reason) {
153
+ return `The packages were not checked: ${NOT_CHECKED[reason]}.`;
154
+ }
155
+ export function incompleteSentence(reason) {
156
+ return `The transitive dependencies were not checked: ${INCOMPLETE_WHY[reason]}.`;
157
+ }
158
+ function names(list) {
159
+ const shown = list.slice(0, MAX_LISTED_NAMES).map((n) => clean(n, 256));
160
+ const rest = list.length - shown.length;
161
+ return rest > 0 ? `${shown.join(', ')} and ${rest} more` : shown.join(', ');
162
+ }
163
+ export function toldSentences(t) {
164
+ const out = [];
165
+ if (t.noDirectory)
166
+ out.push(notCheckedSentence('no_directory'));
167
+ const byReason = new Map();
168
+ for (const n of t.notVerified)
169
+ byReason.set(n.reason, [...(byReason.get(n.reason) ?? []), n.name]);
170
+ for (const [reason, list] of byReason)
171
+ out.push(`Not verified (${NOT_VERIFIED_WHY[reason]}): ${names(list)}.`);
172
+ for (const reason of new Set(t.incomplete))
173
+ out.push(incompleteSentence(reason));
174
+ if (t.overflow > 0) {
175
+ const n = t.overflow;
176
+ out.push(`${n} more ${n === 1 ? 'package was' : 'packages were'} not checked: a check holds at most ${DEPENDENCY_CHECK_MAX_PACKAGES.toLocaleString('en-US')} packages.`);
177
+ }
178
+ return out;
179
+ }
180
+ // ---------------------------------------------------------------------------
181
+ // The texts of a decision
182
+ // ---------------------------------------------------------------------------
183
+ const lines = (...parts) => parts.flat().filter((p) => p !== '').join('\n');
184
+ /** An allowed call, with what the agent should know. */
185
+ export function allowText(input) {
186
+ const listed = findingLines(input.findings);
187
+ const told = toldSentences(input.told);
188
+ const forAgent = listed.length > 0 || told.length > 0 || input.notices.length > 0
189
+ ? lines(`${PREFIX} The call can go ahead.`, listed.length > 0 ? ['Notes on the packages it adds:', ...listed] : [], told, input.notices)
190
+ : '';
191
+ return { forUser: input.notices.join(' '), forAgent };
192
+ }
193
+ /** Nothing was checked, for `reason`; the call goes ahead. */
194
+ export function failureText(reason) {
195
+ return { forUser: '', forAgent: `${PREFIX} ${notCheckedSentence(reason)} The call can go ahead.` };
196
+ }
197
+ /** The organisation's diff scan unit is blocked: told once per session, the call goes ahead. */
198
+ export function usageBlockedText(blockSentence) {
199
+ return {
200
+ forUser: blockSentence ?? '',
201
+ forAgent: lines(`${PREFIX} ${notCheckedSentence('usage_blocked')} The call can go ahead.`, blockSentence ?? ''),
202
+ };
203
+ }
204
+ /** A refused, or asked, call. */
205
+ export function blockText(input) {
206
+ const { mode, link } = input;
207
+ const blocking = input.findings.filter((f) => f.verdict === 'block');
208
+ const n = blocking.length;
209
+ const count = `${n} ${n === 1 ? 'package' : 'packages'}`;
210
+ const listed = findingLines(input.findings);
211
+ const told = toldSentences(input.told);
212
+ const stopped = input.action === 'command' ? 'The command was not run' : 'The edit was not applied';
213
+ if (mode === 'ask') {
214
+ const forUser = lines(`VibeDefend: ${count} that this ${input.action} adds did not pass the dependency check.`, listed, 'Allow it only if you accept these packages: your decision applies to the whole project.');
215
+ const forAgent = lines(`${PREFIX} ${count} did not pass the check; the developer is asked whether to go ahead.`, listed, told);
216
+ return { forUser, forAgent };
217
+ }
218
+ if (mode === 'deny_admin') {
219
+ const malicious = blocking.some(isMaliciousBlock);
220
+ const why = malicious ? 'it adds a known malicious package' : `${count} did not pass the check`;
221
+ const forAgent = lines(`${PREFIX} ${stopped}: ${why}.`, listed, told, malicious ? 'Do not install it: choose another package.' : '', `An administrator can authorise it from the dashboard: ${link}`);
222
+ const forUser = lines(`VibeDefend stopped this ${input.action}: ${why}.`, `An administrator can authorise it from the dashboard: ${link}`);
223
+ return { forUser, forAgent };
224
+ }
225
+ const forAgent = lines(`${PREFIX} ${stopped}: ${count} did not pass the check.`, listed, told, 'Use a version without these problems, the fixed version where one is named.', `If these packages are needed as they are, ask the developer to review them in the dashboard: ${link}`, 'Once the developer authorises them for the project there, the same call passes.');
226
+ const forUser = lines(`VibeDefend stopped this ${input.action}: ${count} did not pass the dependency check.`, `Review them, and authorise them for the project if you accept them: ${link}`);
227
+ return { forUser, forAgent };
228
+ }
229
+ /** The dashboard page of a check: its Scan diff row. */
230
+ export function dashboardLink(dashboardBase, projectId, checkId) {
231
+ const base = dashboardBase.replace(/\/+$/, '');
232
+ return `${base}/vibedefend/project/${encodeURIComponent(projectId)}/scan-diff?scan=${encodeURIComponent(checkId)}`;
233
+ }
234
+ const CHANGE_OF = {
235
+ session: 'a lockfile change in this session',
236
+ commit: 'a lockfile change not yet committed',
237
+ mixed: 'a lockfile change',
238
+ };
239
+ const CHANGES_OF = {
240
+ session: 'The lockfile changes of this session',
241
+ commit: 'The lockfile changes not yet committed',
242
+ mixed: 'The lockfile changes',
243
+ };
244
+ /** The net's section of the Stop message: what entered through a lockfile and did not pass. */
245
+ export function lockfileNetFindingsText(findings, scope = 'session') {
246
+ const blocking = findings
247
+ .filter((f) => f.verdict === 'block')
248
+ .map((f) => {
249
+ const reasons = f.reasons.filter((r) => r.blocking);
250
+ return reasons.length > 0 ? { ...f, reasons } : f;
251
+ });
252
+ if (blocking.length === 0)
253
+ return '';
254
+ const n = blocking.length;
255
+ return lines(`${PREFIX} ${n} ${n === 1 ? 'package' : 'packages'} that entered through ${CHANGE_OF[scope]} did not pass the dependency check. The install already ran:`, findingLines(blocking),
256
+ // The change may be the developer's (a command run outside the agent): they decide.
257
+ 'Tell the developer before anything is committed, in the language of your conversation: name each package and its problem, and propose a version without it (the fixed version where one is named) or another package. Do not change the dependencies yourself unless the developer agrees: the change may be theirs.');
258
+ }
259
+ /** The lockfile changes were not checked, for `reason`. */
260
+ export function lockfileNetNotCheckedText(reason, usageSentence = null, scope = 'session') {
261
+ return lines(`${PREFIX} ${CHANGES_OF[scope]} were not checked: ${NOT_CHECKED[reason]}.`, usageSentence ?? '');
262
+ }
263
+ /** Packages that entered through a lockfile and that no check can verify (git, URL). */
264
+ export function lockfileNetNotVerifiedText(notVerified, scope = 'session') {
265
+ if (notVerified.length === 0)
266
+ return '';
267
+ const n = notVerified.length;
268
+ return `${PREFIX} ${n} ${n === 1 ? 'package' : 'packages'} that entered through ${CHANGE_OF[scope]} could not be checked (${NOT_VERIFIED_WHY.git_or_url}): ${names(notVerified.map((x) => x.name))}.`;
269
+ }
270
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../../src/hooks/runtime/dependency-check/messages.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,6BAA6B,GAK9B,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,MAAM,GAAG,+BAA+B,CAAC;AAoBtD,MAAM,CAAC,MAAM,YAAY,GAAS,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,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AAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC1B,OAAO,KAAK,CACV,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,yBAAyB,SAAS,CAAC,KAAK,CAAC,8DAA8D,EACzJ,YAAY,CAAC,QAAQ,CAAC;IACtB,oFAAoF;IACpF,sTAAsT,CACvT,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,yBAAyB,CAAC,MAAwB,EAAE,gBAA+B,IAAI,EAAE,QAAkB,SAAS;IAClI,OAAO,KAAK,CAAC,GAAG,MAAM,IAAI,UAAU,CAAC,KAAK,CAAC,sBAAsB,WAAW,CAAC,MAAM,CAAC,GAAG,EAAE,aAAa,IAAI,EAAE,CAAC,CAAC;AAChH,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,0BAA0B,CAAC,WAAmC,EAAE,QAAkB,SAAS;IACzG,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACxC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC;IAC7B,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,yBAAyB,SAAS,CAAC,KAAK,CAAC,0BAA0B,gBAAgB,CAAC,UAAU,MAAM,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;AACxM,CAAC"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The session's starting point for the Stop-hook net (BACK-262, I1): the
3
+ * packages each lockfile of the repository held when the session started,
4
+ * taken by SessionStart. At Stop, what entered is a lockfile's packages now
5
+ * less those it held then. Without it, the net compares with HEAD, which
6
+ * reports, and bills, in every session a lockfile git does not hold
7
+ * (ignored, untracked) or one changed before the session: the project's
8
+ * existing debt, which the spec's first anti-goal rules out.
9
+ *
10
+ * - Taken once per session: a later SessionStart of the same session (a
11
+ * resume, a compaction, Windsurf's every-turn event) keeps the first.
12
+ * - What is stored, per lockfile (its path relative to the repository): the
13
+ * set of package keys, `ecosystem\0name\0version`. A git or URL package's
14
+ * version is its source, which can carry a URL: it is stored as a hash. No
15
+ * lockfile content, no other path (the repository is named by a hash of
16
+ * its path), no registry URL. A lockfile that could not be read is stored
17
+ * as unknown, and the net compares that one with HEAD.
18
+ * - `complete`: the walk covered the whole tree. A lockfile absent from a
19
+ * complete baseline appeared during the session (all of it entered); absent
20
+ * from an incomplete one, it is compared with HEAD.
21
+ *
22
+ * One file per session under `~/.cybedefend/dependency-net-baselines/`
23
+ * (0700; files 0600, written whole then renamed), named by a hash of the
24
+ * session id, kept 24 h. Best effort: nothing here throws.
25
+ */
26
+ import { createHash } from 'node:crypto';
27
+ import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
28
+ import { join, resolve } from 'node:path';
29
+ import { readLockfileOnDisk, walkLockfiles } from './lockfile-walk.js';
30
+ import { storeDir } from './local-store.js';
31
+ export const NET_BASELINE_DIR = 'dependency-net-baselines';
32
+ export const NET_BASELINE_TTL_MS = 24 * 60 * 60 * 1000;
33
+ /** Keys kept per session, over every lockfile: past it, a lockfile is unknown (compared with HEAD). */
34
+ export const MAX_BASELINE_KEYS = 100_000;
35
+ /** The time SessionStart gives the walk and the reads. */
36
+ export const BASELINE_BUDGET_MS = 3_000;
37
+ const sha256 = (text) => createHash('sha256').update(text).digest('hex');
38
+ /** The key a lockfile node is known by in a baseline. */
39
+ export function baselineKey(node) {
40
+ return `${node.ecosystem}\0${node.name}\0${node.remote ? `#${sha256(node.version).slice(0, 32)}` : node.version}`;
41
+ }
42
+ function rootHash(repoRoot) {
43
+ let path = resolve(repoRoot);
44
+ try {
45
+ path = realpathSync(path);
46
+ }
47
+ catch {
48
+ /* the path as given */
49
+ }
50
+ return sha256(path);
51
+ }
52
+ /** The repository's starting point: every lockfile's package keys. Never throws. */
53
+ export function baselineOf(repoRoot, opts) {
54
+ const now = opts.now ?? Date.now;
55
+ const startedAt = now();
56
+ const expired = () => now() - startedAt > opts.deadlineMs;
57
+ const found = walkLockfiles(repoRoot, expired);
58
+ const lockfiles = {};
59
+ let kept = 0;
60
+ let complete = found.complete;
61
+ for (const rel of found.lockfiles) {
62
+ if (expired()) {
63
+ complete = false;
64
+ break;
65
+ }
66
+ let keys = null;
67
+ try {
68
+ const read = readLockfileOnDisk(repoRoot, rel);
69
+ if (read !== null)
70
+ keys = [...new Set([...read.graph.packages.values()].map(baselineKey))];
71
+ }
72
+ catch {
73
+ keys = null;
74
+ }
75
+ if (keys !== null && kept + keys.length > MAX_BASELINE_KEYS)
76
+ keys = null;
77
+ if (keys !== null)
78
+ kept += keys.length;
79
+ // A lockfile on disk that could not be read is unknown, never "held nothing".
80
+ lockfiles[rel] = keys;
81
+ }
82
+ return { root: rootHash(repoRoot), complete, lockfiles };
83
+ }
84
+ function isBaseline(v) {
85
+ if (typeof v !== 'object' || v === null)
86
+ return false;
87
+ const b = v;
88
+ return (typeof b.root === 'string' &&
89
+ typeof b.complete === 'boolean' &&
90
+ typeof b.lockfiles === 'object' &&
91
+ b.lockfiles !== null &&
92
+ Object.values(b.lockfiles).every((keys) => keys === null || (Array.isArray(keys) && keys.every((k) => typeof k === 'string'))));
93
+ }
94
+ export function makeNetBaselines(opts = {}) {
95
+ const now = opts.now ?? Date.now;
96
+ const dir = () => join(storeDir(opts), NET_BASELINE_DIR);
97
+ const fileOf = (sessionId) => join(dir(), `${sha256(sessionId).slice(0, 32)}.json`);
98
+ const read = (sessionId) => {
99
+ try {
100
+ const file = fileOf(sessionId);
101
+ if (!existsSync(file))
102
+ return null;
103
+ const doc = JSON.parse(readFileSync(file, 'utf8'));
104
+ if (typeof doc.at !== 'number' || now() - doc.at > NET_BASELINE_TTL_MS || doc.at > now() + NET_BASELINE_TTL_MS)
105
+ return null;
106
+ return isBaseline(doc.value) ? doc.value : null;
107
+ }
108
+ catch {
109
+ return null;
110
+ }
111
+ };
112
+ /** Removes the baselines older than a day. Best effort. */
113
+ const sweep = () => {
114
+ try {
115
+ for (const name of readdirSync(dir())) {
116
+ const path = join(dir(), name);
117
+ if (name.endsWith('.json') && now() - statSync(path).mtimeMs > NET_BASELINE_TTL_MS)
118
+ rmSync(path, { force: true });
119
+ }
120
+ }
121
+ catch {
122
+ /* nothing to sweep */
123
+ }
124
+ };
125
+ return {
126
+ get(sessionId, repoRoot) {
127
+ if (sessionId === '')
128
+ return null;
129
+ const b = read(sessionId);
130
+ return b !== null && b.root === rootHash(repoRoot) ? b : null;
131
+ },
132
+ keep(sessionId, repoRoot, take) {
133
+ try {
134
+ if (sessionId === '')
135
+ return;
136
+ const existing = read(sessionId);
137
+ if (existing !== null && existing.root === rootHash(repoRoot))
138
+ return;
139
+ mkdirSync(dir(), { recursive: true, mode: 0o700 });
140
+ sweep();
141
+ const file = fileOf(sessionId);
142
+ const tmp = `${file}.${process.pid}.tmp`;
143
+ try {
144
+ writeFileSync(tmp, JSON.stringify({ at: now(), value: take() }), { encoding: 'utf8', mode: 0o600 });
145
+ renameSync(tmp, file);
146
+ }
147
+ catch {
148
+ rmSync(tmp, { force: true });
149
+ }
150
+ }
151
+ catch {
152
+ /* best effort: without a baseline the net compares with HEAD */
153
+ }
154
+ },
155
+ };
156
+ }
157
+ //# sourceMappingURL=net-baseline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"net-baseline.js","sourceRoot":"","sources":["../../../../src/hooks/runtime/dependency-check/net-baseline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE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70 @@
1
+ /**
2
+ * What the Stop-hook net (E10) already did in a session, or what the
3
+ * PreToolUse hook already told the agent, so the net does not tell or pay
4
+ * twice and does not re-read what has not changed:
5
+ *
6
+ * - `toldNotChecked`: the agent was told once that packages were not
7
+ * checked, by the net or by the PreToolUse hook at a command; a later
8
+ * failure stays silent (the call may still be retried, silently).
9
+ * - `usageBlocked`: a 402 was met, by the net or by the PreToolUse hook; the
10
+ * net makes no further call.
11
+ * - `invalid`: packages the backend answered `invalid_coordinates` on, never
12
+ * sent again (each send is a billed check).
13
+ * - `seen`: per lockfile (repository-relative path), the mtime and size it
14
+ * had when the net last settled it; an unchanged lockfile is skipped
15
+ * without a git read or a parse.
16
+ * - `toldNotVerified`: the git and URL packages already told as not
17
+ * verified (`name\0reason`), so a later lockfile change does not tell
18
+ * them again. Absent in a state written by an older version.
19
+ *
20
+ * `~/.cybedefend/dependency-net-sessions.json`, 24 h, locked like the other
21
+ * local stores. Best effort: it never throws.
22
+ */
23
+ import { join } from 'node:path';
24
+ import { readEntries, storeDir, updateEntries } from './local-store.js';
25
+ export const NET_STATE_FILE = 'dependency-net-sessions.json';
26
+ export const NET_STATE_TTL_MS = 24 * 60 * 60 * 1000;
27
+ const MAX_SESSIONS = 50;
28
+ const MAX_INVALID = 5_000;
29
+ const empty = () => ({ toldNotChecked: false, usageBlocked: false, invalid: [], seen: {}, toldNotVerified: [] });
30
+ const MAX_TOLD = 5_000;
31
+ function isState(v) {
32
+ if (typeof v !== 'object' || v === null)
33
+ return false;
34
+ const s = v;
35
+ return (typeof s.toldNotChecked === 'boolean' &&
36
+ typeof s.usageBlocked === 'boolean' &&
37
+ Array.isArray(s.invalid) &&
38
+ s.invalid.every((k) => typeof k === 'string') &&
39
+ typeof s.seen === 'object' &&
40
+ s.seen !== null &&
41
+ Object.values(s.seen).every((x) => typeof x?.mtimeMs === 'number' && typeof x?.size === 'number') &&
42
+ (s.toldNotVerified === undefined || (Array.isArray(s.toldNotVerified) && s.toldNotVerified.every((k) => typeof k === 'string'))));
43
+ }
44
+ export function makeNetState(opts = {}) {
45
+ const now = opts.now ?? Date.now;
46
+ const file = () => join(storeDir(opts), NET_STATE_FILE);
47
+ return {
48
+ get(sessionId) {
49
+ if (sessionId === '')
50
+ return empty();
51
+ const stored = readEntries(file(), now(), NET_STATE_TTL_MS, isState)[sessionId]?.value;
52
+ return stored === undefined
53
+ ? empty()
54
+ : { ...stored, invalid: [...stored.invalid], seen: { ...stored.seen }, toldNotVerified: [...(stored.toldNotVerified ?? [])] };
55
+ },
56
+ update(sessionId, change) {
57
+ if (sessionId === '')
58
+ return;
59
+ updateEntries(file(), now(), NET_STATE_TTL_MS, MAX_SESSIONS, isState, (all) => {
60
+ const stored = all[sessionId]?.value;
61
+ const state = stored === undefined ? empty() : { ...stored, toldNotVerified: stored.toldNotVerified ?? [] };
62
+ change(state);
63
+ state.invalid = state.invalid.slice(-MAX_INVALID);
64
+ state.toldNotVerified = state.toldNotVerified.slice(-MAX_TOLD);
65
+ all[sessionId] = { at: now(), value: state };
66
+ });
67
+ },
68
+ };
69
+ }
70
+ //# sourceMappingURL=net-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"net-state.js","sourceRoot":"","sources":["../../../../src/hooks/runtime/dependency-check/net-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAqB,MAAM,kBAAkB,CAAC;AAE3F,MAAM,CAAC,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACpD,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,WAAW,GAAG,KAAK,CAAC;AAoB1B,MAAM,KAAK,GAAG,GAAoB,EAAE,CAAC,CAAC,EAAE,c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K,CAAC,CAAC,QAAQ,CAAC,CAAC;gBAC/D,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;YAC/C,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The checks a developer was asked about and has not answered yet, kept
3
+ * between the PreToolUse step that asked and the post-call hook that sees
4
+ * the call run (the developer accepted). That hook takes the entry and
5
+ * reports the force for that check, never for packages it names itself.
6
+ *
7
+ * `~/.cybedefend/dependency-pending-forces.json`, one entry per (client,
8
+ * session, pair key), an hour at most: a question left unanswered longer than
9
+ * that is not a force any more.
10
+ */
11
+ import { join } from 'node:path';
12
+ import { readEntries, storeDir, updateEntries } from './local-store.js';
13
+ export const PENDING_FORCES_FILE = 'dependency-pending-forces.json';
14
+ /** C4 `PENDING_FORCE_TTL_MS`. */
15
+ export const PENDING_FORCE_TTL_MS = 60 * 60 * 1000;
16
+ const MAX_ENTRIES = 200;
17
+ const isPendingForce = (v) => typeof v === 'object' &&
18
+ v !== null &&
19
+ typeof v.projectId === 'string' &&
20
+ typeof v.checkId === 'string' &&
21
+ (v.apiBase === undefined || typeof v.apiBase === 'string') &&
22
+ (v.packages === undefined || Array.isArray(v.packages));
23
+ const keyOf = (k) => JSON.stringify([k.client, k.sessionId, k.pairKey]);
24
+ export function makePendingForces(opts = {}) {
25
+ const now = opts.now ?? Date.now;
26
+ const file = () => join(storeDir(opts), PENDING_FORCES_FILE);
27
+ const max = opts.maxEntries ?? MAX_ENTRIES;
28
+ return {
29
+ record(entry) {
30
+ if (entry.pairKey === '' || entry.checkId === '')
31
+ return;
32
+ updateEntries(file(), now(), PENDING_FORCE_TTL_MS, max, isPendingForce, (all) => {
33
+ const value = { projectId: entry.projectId, checkId: entry.checkId };
34
+ if (entry.apiBase !== undefined)
35
+ value.apiBase = entry.apiBase;
36
+ if (entry.packages !== undefined)
37
+ value.packages = entry.packages;
38
+ all[keyOf(entry)] = { at: now(), value };
39
+ });
40
+ },
41
+ take(key) {
42
+ const k = keyOf(key);
43
+ if (readEntries(file(), now(), PENDING_FORCE_TTL_MS, isPendingForce)[k] === undefined)
44
+ return null;
45
+ let taken = null;
46
+ updateEntries(file(), now(), PENDING_FORCE_TTL_MS, max, isPendingForce, (all) => {
47
+ taken = all[k]?.value ?? null;
48
+ delete all[k];
49
+ });
50
+ return taken;
51
+ },
52
+ };
53
+ }
54
+ //# sourceMappingURL=pending-forces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending-forces.js","sourceRoot":"","sources":["../../../../src/hooks/runtime/dependency-check/pending-forces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAqB,MAAM,kBAAkB,CAAC;AAE3F,MAAM,CAAC,MAAM,mBAAmB,GAAG,gCAAgC,CAAC;AACpE,iCAAiC;AACjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACnD,MAAM,WAAW,GAAG,GAAG,CAAC;AAyBxB,MAAM,cAAc,GAAG,CAAC,CAAU,EAAqB,EAAE,CACvD,OAAO,CAAC,KAAK,QAAQ;IACrB,CAAC,KAAK,IAAI;IACV,OAAQ,CAAkB,CAAC,SAAS,KAAK,QAAQ;IACjD,OAAQ,CAAkB,CAAC,OAAO,KAAK,QAAQ;IAC/C,CAAE,CAAkB,CAAC,OAAO,KAAK,SAAS,IAAI,OAAQ,CAAkB,CAAC,OAAO,KAAK,QAAQ,CAAC;IAC9F,CAAE,CAAkB,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAE,CAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE9F,MAAM,KAAK,GAAG,CAAC,CAAkB,EAAU,EAA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