@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,77 @@
1
+ // Working-tree resolution for repo mode. Imported by the hook runtime bundle:
2
+ // only node:* builtins here.
3
+ import { spawnSync } from 'node:child_process';
4
+ import { realpathSync } from 'node:fs';
5
+ import { resolve } from 'node:path';
6
+ export class NotAGitRepositoryError extends Error {
7
+ constructor(path) {
8
+ super(`${path} is not inside a git repository. Repo mode needs git: run it from the repository you want to protect.`);
9
+ this.name = 'NotAGitRepositoryError';
10
+ }
11
+ }
12
+ const defaultGit = (args, cwd) => {
13
+ const r = spawnSync('git', args, { cwd, encoding: 'utf8', timeout: 5000 });
14
+ // A spawn failure, timeout or signal has no exit status: report -1, which
15
+ // git never returns, so callers cannot mistake it for "exit 1".
16
+ return { status: r.status ?? -1, stdout: r.stdout ?? '' };
17
+ };
18
+ function real(p) {
19
+ try {
20
+ return realpathSync(p);
21
+ }
22
+ catch {
23
+ return resolve(p);
24
+ }
25
+ }
26
+ function worktreeRecords(cwd, git) {
27
+ const r = git(['worktree', 'list', '--porcelain'], cwd);
28
+ if (r.status !== 0)
29
+ return [];
30
+ const records = [];
31
+ let current = null;
32
+ for (const line of r.stdout.split('\n')) {
33
+ if (line.startsWith('worktree ')) {
34
+ current = { path: line.slice('worktree '.length), bare: false };
35
+ records.push(current);
36
+ }
37
+ else if (line === 'bare' && current) {
38
+ current.bare = true;
39
+ }
40
+ }
41
+ return records;
42
+ }
43
+ export function resolveWorkingTree(path, git = defaultGit) {
44
+ const start = resolve(path);
45
+ const r = git(['rev-parse', '--show-toplevel', '--git-dir', '--git-common-dir'], start);
46
+ if (r.status !== 0)
47
+ throw new NotAGitRepositoryError(path);
48
+ const lines = r.stdout.split('\n').filter((l) => l.length > 0);
49
+ if (lines.length < 3)
50
+ throw new NotAGitRepositoryError(path);
51
+ const [top, gitDir, commonDir] = lines;
52
+ const root = real(resolve(start, top));
53
+ const gitDirAbs = real(resolve(start, gitDir));
54
+ const gitCommonDir = real(resolve(start, commonDir));
55
+ const first = worktreeRecords(root, git)[0];
56
+ return {
57
+ root,
58
+ gitCommonDir,
59
+ isLinkedWorktree: gitDirAbs !== gitCommonDir,
60
+ mainCheckoutRoot: first && !first.bare ? real(first.path) : null,
61
+ };
62
+ }
63
+ /**
64
+ * Whether git tracks `relPath`. Fails toward "do not touch": only git's exit 1
65
+ * (the pathspec matched nothing) means untracked; exit 0 and any other outcome
66
+ * (git missing, timeout, a git error) count as tracked.
67
+ */
68
+ export function isTracked(tree, relPath, git = defaultGit) {
69
+ return git(['ls-files', '--error-unmatch', '--', relPath], tree.root).status !== 1;
70
+ }
71
+ export function listWorktreeRoots(tree, git = defaultGit) {
72
+ const roots = worktreeRecords(tree.root, git)
73
+ .filter((w) => !w.bare)
74
+ .map((w) => real(w.path));
75
+ return roots.length > 0 ? roots : [tree.root];
76
+ }
77
+ //# sourceMappingURL=git-repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-repo.js","sourceRoot":"","sources":["../../src/repo/git-repo.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,45 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { parseJsonc, writeJson } from '../json-file.js';
4
+ import { trackedReason } from './unsupported.js';
5
+ /**
6
+ * Edit a JSON file of a repository. A file git tracks, or one that cannot be
7
+ * read as a JSON object, is never touched: the caller reports the reason.
8
+ * An empty file counts as `{}`. Never goes through `readJson`, whose fallback
9
+ * would replace what the user wrote.
10
+ */
11
+ export function editRepoJson(root, rel, isTracked, mutate) {
12
+ if (isTracked(root, rel))
13
+ return { ok: false, reason: trackedReason(rel) };
14
+ const abs = join(root, rel);
15
+ const unreadable = {
16
+ ok: false,
17
+ reason: `${rel} could not be read as JSON: VibeDefend left it alone`,
18
+ };
19
+ let data = {};
20
+ if (existsSync(abs)) {
21
+ let raw;
22
+ try {
23
+ raw = readFileSync(abs, 'utf8');
24
+ }
25
+ catch {
26
+ return unreadable;
27
+ }
28
+ if (raw.trim()) {
29
+ let parsed;
30
+ try {
31
+ parsed = parseJsonc(raw, rel);
32
+ }
33
+ catch {
34
+ return unreadable;
35
+ }
36
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
37
+ return unreadable;
38
+ data = parsed;
39
+ }
40
+ }
41
+ mutate(data);
42
+ writeJson(abs, data);
43
+ return { ok: true, file: { root, rel } };
44
+ }
45
+ //# sourceMappingURL=guarded-write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guarded-write.js","sourceRoot":"","sources":["../../src/repo/guarded-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,GAAW,EACX,SAAuC,EACvC,MAAyB;IAEzB,IAAI,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3E,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC5B,MAAM,UAAU,GAAG;QACjB,EAAE,EAAE,KAAc;QAClB,MAAM,EAAE,GAAG,GAAG,sDAAsD;KACrE,CAAC;IACF,IAAI,IAAI,GAAM,EAAO,CAAC;IACtB,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,IAAI,GAAW,CAAC;QAChB,IAAI,CAAC;YACH,GAAG,GAAG,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YACf,IAAI,MAAe,CAAC;YACpB,IAAI,CAAC;gBACH,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAChC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,UAAU,CAAC;YACpB,CAAC;YACD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;gBAAE,OAAO,UAAU,CAAC;YAC9F,IAAI,GAAG,MAAW,CAAC;QACrB,CAAC;IACH,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,CAAC;IACb,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACrB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,508 @@
1
+ /**
2
+ * `vibedefend install --repo`: set VibeDefend up for one repository (its main
3
+ * checkout and the worktrees the user wires) and nowhere else.
4
+ *
5
+ * Flow for a repository not registered yet, or a re-run in a registered
6
+ * working tree:
7
+ * 0. Resolve the working tree (refused outside git), then the global CLI
8
+ * hand-off of an npx run.
9
+ * 1. Region; a region other than the one of the registered repositories asks
10
+ * to switch them all, before anything signs in. Then sign-in and the
11
+ * organization gate. A confirmed switch is completed right after the
12
+ * sign-in (hook runtime and every registered working tree's MCP server),
13
+ * so no later abort leaves the repositories on a session that is gone.
14
+ * 2. Machine-wide wiring: listed, and the user asked whether to remove it.
15
+ * 3. Project link, when neither the working tree, its main checkout nor
16
+ * the registry entry gives the project. A link file git tracks is never
17
+ * rewritten.
18
+ * 4. Agent picker (repo-capable agents only), hook settings without the
19
+ * activation question. An abort here removes the link this run made.
20
+ * 5. Write: the machine-wide wiring the user agreed to remove, then the hook
21
+ * runtime in repo scope, the agents' files in the working tree (an agent
22
+ * left out leaves every working tree), the registry entry, then the
23
+ * exclude block.
24
+ * 6. Footer.
25
+ *
26
+ * In a working tree not registered yet of a registered repository (a linked
27
+ * worktree, typically), steps 1, 3 and 4 are skipped: the repository's
28
+ * agents, region and hook settings are reused, with no question unless
29
+ * machine-wide wiring is found again.
30
+ */
31
+ import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs';
32
+ import { join } from 'node:path';
33
+ import { confirm as confirmImpl } from '@inquirer/prompts';
34
+ import { sameMcpUrl } from '../clients/mcp-url.js';
35
+ import { ALL_ADAPTERS } from '../clients/registry.js';
36
+ import { HOOK_DEFAULTS } from '../config.js';
37
+ import { resolveHookConfigFrom } from '../doctor.js';
38
+ import { installGlobalCliAndHandOff } from '../global-cli.js';
39
+ import { installHookRuntime } from '../hooks/install.js';
40
+ import { loadRuntimeConfig } from '../hooks/runtime/config.js';
41
+ import { findRepo, loadRepoRegistry, repoRegistryPath, } from '../hooks/runtime/repo-registry.js';
42
+ import { ensureLinkIgnored, ensureSignedIn } from '../install.js';
43
+ import { runLinkCommand } from '../link.js';
44
+ import { askHookConfig as askHookConfigImpl, askRepoClientSelection as askRepoClientSelectionImpl, } from '../prompts.js';
45
+ import { stampInstalledVersion } from '../self-update.js';
46
+ import { trustedMcpNames } from '../uninstall.js';
47
+ import { home, isUserCancellation, log } from '../utils.js';
48
+ import { pkg } from '../version.js';
49
+ import { assertExcludeBlockEditable, MalformedExcludeBlockError, readExcludeBlock, removeExcludeBlock, writeExcludeBlock, } from './exclude-block.js';
50
+ import { renderRepoFooter, renderRepoModeNotice, repoModeOffList } from './footer.js';
51
+ import { NotAGitRepositoryError, resolveWorkingTree } from './git-repo.js';
52
+ import { detectMachineWiring as detectMachineWiringImpl, isMachineWired, removeMachineWiring as removeMachineWiringImpl, SYNC_HOOK_LABEL, } from './machine-wiring.js';
53
+ import { unwireSharedMcpJson } from './mcp-json.js';
54
+ import { saveRepoRegistry, upsertWorkingTree } from './registry.js';
55
+ import { defaultRepoIsTracked, defaultRepoRun, LINK_FILE_REL, registeredTree } from './repo-setups.js';
56
+ import { trackedReason } from './unsupported.js';
57
+ function errorMessage(e) {
58
+ return e instanceof Error ? e.message : String(e);
59
+ }
60
+ function repoAdapter(id) {
61
+ const adapter = ALL_ADAPTERS.find((a) => a.id === id);
62
+ return adapter?.repo ? adapter : null;
63
+ }
64
+ /** One piece; an adapter that throws (a malformed file, EACCES) leaves it off, with the error. */
65
+ function wirePiece(client, piece, wire) {
66
+ try {
67
+ return wire();
68
+ }
69
+ catch (e) {
70
+ if (isUserCancellation(e))
71
+ throw e;
72
+ return { client, piece, state: 'off', files: [], reason: errorMessage(e) };
73
+ }
74
+ }
75
+ /**
76
+ * Wire the hooks and the MCP server of each client in one working tree. When
77
+ * neither Claude Code nor VS Code Copilot is among them, our entry leaves the
78
+ * shared `.mcp.json`.
79
+ */
80
+ export function wireWorkingTree(tree, clients, ctx,
81
+ /** Our server names, read before this run wrote a new region. */
82
+ mcpNames = trustedMcpNames()) {
83
+ const full = { ...ctx, tree };
84
+ const pieces = [];
85
+ for (const id of clients) {
86
+ const adapter = repoAdapter(id);
87
+ if (adapter === null)
88
+ continue;
89
+ pieces.push(wirePiece(id, 'hooks', () => adapter.repo.wireHooks(full)));
90
+ pieces.push(wirePiece(id, 'mcp', () => adapter.repo.wireMcp(full)));
91
+ }
92
+ if (!clients.includes('claude-code') && !clients.includes('vscode')) {
93
+ try {
94
+ unwireSharedMcpJson(tree.root, mcpNames, ctx.isTracked);
95
+ }
96
+ catch (e) {
97
+ log.warn(`Could not take the CybeDefend server out of .mcp.json: ${errorMessage(e)}`);
98
+ }
99
+ }
100
+ return pieces;
101
+ }
102
+ /** The project of the working tree's `.cybedefend/config.json`, or `null`. */
103
+ function linkedProject(root) {
104
+ const file = join(root, '.cybedefend', 'config.json');
105
+ if (!existsSync(file))
106
+ return null;
107
+ try {
108
+ const { projectId } = JSON.parse(readFileSync(file, 'utf8'));
109
+ return typeof projectId === 'string' && projectId.trim() !== '' ? projectId : null;
110
+ }
111
+ catch {
112
+ return null;
113
+ }
114
+ }
115
+ /** The real link flow, on the region just picked and in repo scope. */
116
+ async function linkWorkingTree(root, region) {
117
+ // The runtime config is only written at the end of the install: hand the
118
+ // link the region just picked (no second region question) and the repo
119
+ // scope (the link goes into the exclude block, never into .gitignore).
120
+ const runtime = {
121
+ region,
122
+ hooks: { ...HOOK_DEFAULTS },
123
+ installedVersion: pkg.version,
124
+ installScope: 'repo',
125
+ };
126
+ // This install is setting the repository up: the link must not say it is off.
127
+ const result = await runLinkCommand({ path: root }, { cwd: root, loadRuntimeConfig: () => runtime, isRepoSetUp: () => true });
128
+ if (result === null) {
129
+ throw new Error('No project was linked, and repo mode needs one. Run `vibedefend install --repo` again to pick it.');
130
+ }
131
+ return result.projectId;
132
+ }
133
+ /**
134
+ * List the machine-wide wiring and ask whether to remove it. Returns `null`
135
+ * on no, else what was found; {@link removeAgreedMachineWiring} removes it
136
+ * once the other questions are answered.
137
+ */
138
+ async function askMachineWiring(region, deps, confirm, opts = {}) {
139
+ const wiring = (deps.detectMachineWiring ?? detectMachineWiringImpl)(region);
140
+ if (!isMachineWired(wiring))
141
+ return wiring;
142
+ const names = [
143
+ ...wiring.agents.map((a) => a.label),
144
+ ...(wiring.proxyServers > 0 ? ['the MCP proxy'] : []),
145
+ ...(wiring.syncHook ? [SYNC_HOOK_LABEL] : []),
146
+ ].join(', ');
147
+ const remove = await confirm({
148
+ message: `VibeDefend is set up machine-wide for ${names}. Repo mode needs that removed. Remove it now?`,
149
+ default: true,
150
+ });
151
+ if (!remove) {
152
+ log.info(opts.regionSwitched
153
+ ? `This repository was not set up: repo mode needs the machine-wide setup removed first. The registered repositories now use ${region.label}.`
154
+ : 'Nothing was written: repo mode needs the machine-wide setup removed first.');
155
+ return null;
156
+ }
157
+ return wiring;
158
+ }
159
+ /** Remove the machine-wide wiring the user agreed to remove (nothing when none was found). */
160
+ async function removeAgreedMachineWiring(wiring, deps, mcpNames) {
161
+ if (!isMachineWired(wiring))
162
+ return;
163
+ const removal = await (deps.removeMachineWiring ?? ((w) => removeMachineWiringImpl(w, { mcpNames })))(wiring);
164
+ const removedNames = [
165
+ ...wiring.agents.filter((a) => removal.removed.includes(a.id)).map((a) => a.label),
166
+ ...(removal.syncHookRemoved ? [SYNC_HOOK_LABEL] : []),
167
+ ];
168
+ if (removedNames.length > 0)
169
+ log.ok(`Machine-wide setup removed: ${removedNames.join(', ')}`);
170
+ for (const error of removal.errors) {
171
+ if (error.id === 'sync-hook') {
172
+ log.warn(`Could not remove ${SYNC_HOOK_LABEL}: ${error.error}.`);
173
+ continue;
174
+ }
175
+ log.warn(`Could not remove the machine-wide setup of ${error.label}: ${error.error}. ` +
176
+ 'VibeDefend still runs there in every folder: fix it, then run `vibedefend install --repo` again.');
177
+ }
178
+ if (!removal.proxyComplete) {
179
+ log.warn('The MCP proxy is still in front of some MCP servers: run `vibedefend unwrap`.');
180
+ }
181
+ }
182
+ /** Registry entry, then the exclude block computed from it. */
183
+ function record(registry, registryPath, tree, repo, pieces, extraFiles = []) {
184
+ const next = upsertWorkingTree(registry, { gitCommonDir: tree.gitCommonDir, ...repo }, {
185
+ root: tree.root,
186
+ files: [...pieces.flatMap((p) => p.files), ...extraFiles],
187
+ off: pieces
188
+ .filter((p) => p.state === 'off')
189
+ .map((p) => ({ client: p.client, piece: p.piece, reason: p.reason ?? '' })),
190
+ });
191
+ saveRepoRegistry(next, registryPath);
192
+ writeExcludeBlock(tree.gitCommonDir, findRepo(next, tree.gitCommonDir)?.excluded ?? ['/.cybedefend/']);
193
+ return next;
194
+ }
195
+ /**
196
+ * After a region switch: re-point the MCP server of the agents each
197
+ * registered working tree was set up with.
198
+ */
199
+ function repointTrees(registry, ctx) {
200
+ for (const repo of registry.repos) {
201
+ for (const { root } of repo.workingTrees) {
202
+ const tree = registeredTree(repo, root);
203
+ if (tree === null) {
204
+ log.warn(`${root} no longer exists: skipped.`);
205
+ continue;
206
+ }
207
+ for (const id of repo.clients) {
208
+ const adapter = repoAdapter(id);
209
+ if (adapter === null)
210
+ continue;
211
+ const piece = wirePiece(id, 'mcp', () => adapter.repo.wireMcp({ ...ctx, tree }));
212
+ if (piece.state === 'off') {
213
+ log.warn(`${adapter.label} in ${root} still uses the previous region: ${piece.reason}`);
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+ /**
220
+ * Take the agents left out of the new selection out of every other
221
+ * registered working tree, and drop their files and off pieces from that
222
+ * tree's registry entry. `touched` holds what the current tree's unwire
223
+ * changed: a worktree's Claude Code hooks live in the main checkout, so one
224
+ * tree's unwire can change a file another tree's entry lists. When the
225
+ * shared `.mcp.json` of a tree lost our server while an agent that reads it
226
+ * stays wired there, the server is put back.
227
+ */
228
+ function unwireFromOtherTrees(registry, current, change, repoInfo, ctx, mcpNames) {
229
+ const entry = findRepo(registry, current.gitCommonDir);
230
+ if (entry === null || change.removed.length === 0)
231
+ return registry;
232
+ const touched = [...change.touched];
233
+ const others = [];
234
+ for (const recorded of entry.workingTrees) {
235
+ if (recorded.root === current.root)
236
+ continue;
237
+ const tree = registeredTree(entry, recorded.root);
238
+ if (tree === null)
239
+ continue;
240
+ others.push({ recorded, tree });
241
+ for (const id of change.removed) {
242
+ const adapter = repoAdapter(id);
243
+ if (adapter === null)
244
+ continue;
245
+ try {
246
+ touched.push(...adapter.repo.unwire(tree, mcpNames, ctx.run, ctx.isTracked));
247
+ log.ok(`${adapter.label} removed from ${recorded.root}`);
248
+ }
249
+ catch (e) {
250
+ log.warn(`Could not remove ${adapter.label} from ${recorded.root}: ${errorMessage(e)}`);
251
+ }
252
+ }
253
+ }
254
+ const same = (a, b) => a.root === b.root && a.rel === b.rel;
255
+ const shared = change.kept.find((id) => id === 'claude-code' || id === 'vscode');
256
+ let next = registry;
257
+ for (const { recorded, tree } of others) {
258
+ const files = recorded.files.filter((f) => !touched.some((t) => same(t, f)));
259
+ const sharedAdapter = shared === undefined ? null : repoAdapter(shared);
260
+ if (sharedAdapter !== null && touched.some((t) => same(t, { root: tree.root, rel: '.mcp.json' }))) {
261
+ const piece = wirePiece(shared, 'mcp', () => sharedAdapter.repo.wireMcp({ ...ctx, tree }));
262
+ for (const f of piece.files)
263
+ if (!files.some((g) => same(g, f)))
264
+ files.push(f);
265
+ }
266
+ next = upsertWorkingTree(next, { gitCommonDir: entry.gitCommonDir, ...repoInfo }, {
267
+ root: recorded.root,
268
+ files,
269
+ off: recorded.off.filter((o) => !change.removed.includes(o.client)),
270
+ });
271
+ }
272
+ return next;
273
+ }
274
+ /** The exclude block as it was, put back; no block when there was none. */
275
+ function restoreExcludeBlock(gitCommonDir, patterns) {
276
+ if (patterns.length === 0)
277
+ removeExcludeBlock(gitCommonDir);
278
+ else
279
+ writeExcludeBlock(gitCommonDir, patterns);
280
+ }
281
+ /** Delete a link file this run created, and its folder when nothing else is in it. */
282
+ function removeCreatedLink(root) {
283
+ rmSync(join(root, LINK_FILE_REL), { force: true });
284
+ const folder = join(root, '.cybedefend');
285
+ try {
286
+ if (readdirSync(folder).length === 0)
287
+ rmSync(folder, { recursive: true, force: true });
288
+ }
289
+ catch {
290
+ // Already gone.
291
+ }
292
+ }
293
+ function finish(tree, pieces, machine) {
294
+ const report = {
295
+ tree,
296
+ pieces,
297
+ off: repoModeOffList(),
298
+ machineProfile: machine.claudeProfileDir,
299
+ worktree: tree.isLinkedWorktree,
300
+ };
301
+ console.log();
302
+ console.log(renderRepoFooter(report));
303
+ console.log();
304
+ return report;
305
+ }
306
+ export async function runRepoInstall(opts = {}, deps = {}) {
307
+ const confirm = deps.confirm ?? confirmImpl;
308
+ const exit = deps.exit ?? ((code) => process.exit(code));
309
+ const registryPath = deps.registryPath ?? repoRegistryPath();
310
+ const run = deps.run ?? defaultRepoRun;
311
+ const isTracked = defaultRepoIsTracked;
312
+ let tree;
313
+ try {
314
+ tree = resolveWorkingTree(opts.path ?? deps.cwd ?? process.cwd());
315
+ }
316
+ catch (e) {
317
+ if (!(e instanceof NotAGitRepositoryError))
318
+ throw e;
319
+ log.err(e.message);
320
+ exit(1);
321
+ return null; // In tests `exit` is a spy — never continue past an abort.
322
+ }
323
+ // ⓪ npx / dlx run: install the CLI globally and hand it this repository.
324
+ if (opts.globalCli) {
325
+ const installGlobalCli = deps.installGlobalCli ?? installGlobalCliAndHandOff;
326
+ const outcome = installGlobalCli(['--repo', tree.root, ...(opts.force ? ['--force'] : [])]);
327
+ if (outcome.kind === 'handed-off') {
328
+ exit(outcome.exitCode);
329
+ return null;
330
+ }
331
+ }
332
+ // Said before any question, on every path (the npx parent above never gets here).
333
+ console.log(renderRepoModeNotice(tree.root));
334
+ console.log();
335
+ // The exclude block is written last: an exclude file it cannot rewrite
336
+ // safely stops the install here, before anything is written.
337
+ try {
338
+ assertExcludeBlockEditable(tree.gitCommonDir);
339
+ }
340
+ catch (e) {
341
+ if (!(e instanceof MalformedExcludeBlockError))
342
+ throw e;
343
+ log.err(e.message);
344
+ exit(1);
345
+ return null;
346
+ }
347
+ // Our MCP server names, read before this run writes a new region: a server
348
+ // registered under the previous region's name is still ours to remove.
349
+ const mcpNames = trustedMcpNames();
350
+ const registry = loadRepoRegistry(registryPath);
351
+ const entry = findRepo(registry, tree.gitCommonDir);
352
+ const runtime = loadRuntimeConfig();
353
+ // A working tree not registered yet of a registered repository: reuse its
354
+ // choices, ask nothing.
355
+ if (!opts.force &&
356
+ entry !== null &&
357
+ runtime?.installScope === 'repo' &&
358
+ runtime.region &&
359
+ !entry.workingTrees.some((t) => t.root === tree.root)) {
360
+ const region = runtime.region;
361
+ const machine = await askMachineWiring(region, deps, confirm);
362
+ if (machine === null)
363
+ return null;
364
+ await removeAgreedMachineWiring(machine, deps, mcpNames);
365
+ log.step(`Setting up ${tree.root} with the agents of this repository`);
366
+ const clients = entry.clients.filter((id) => repoAdapter(id) !== null);
367
+ const pieces = wireWorkingTree(tree, clients, { region, hooks: resolveHookConfigFrom(runtime.hooks), isTracked, run }, mcpNames);
368
+ const { projectId, installedAt } = entry;
369
+ record(registry, registryPath, tree, { projectId, installedAt, clients: entry.clients }, pieces);
370
+ return finish(tree, pieces, machine);
371
+ }
372
+ log.step(`VibeDefend for this repository only: ${tree.root}`);
373
+ // ① Region, then sign-in. A region switch is asked before the sign-in: the
374
+ // stored session is shared by the regions, so signing in elsewhere and then
375
+ // aborting would leave every registered repository on a dead session.
376
+ const previous = runtime?.region ?? null;
377
+ let repoint = false;
378
+ const region = await ensureSignedIn(deps, {
379
+ force: opts.force,
380
+ beforeSignIn: async (picked) => {
381
+ if (registry.repos.length === 0 ||
382
+ typeof previous?.mcpUrl !== 'string' ||
383
+ sameMcpUrl(previous.mcpUrl, picked.mcpUrl)) {
384
+ return true;
385
+ }
386
+ const n = registry.repos.length;
387
+ repoint = await confirm({
388
+ message: `VibeDefend is set up for ${n === 1 ? '1 repository' : `${n} repositories`} on ${previous.label}. Switch ${n === 1 ? 'it' : 'them all'} to ${picked.label}?`,
389
+ default: true,
390
+ });
391
+ if (!repoint)
392
+ log.info('Nothing was changed: one region serves every repository of this machine.');
393
+ return repoint;
394
+ },
395
+ });
396
+ if (region === null)
397
+ return null;
398
+ // The stored session now belongs to the new region: complete the switch the
399
+ // user confirmed before any other question can abort, so the hooks and every
400
+ // registered working tree's MCP server follow the session.
401
+ if (repoint) {
402
+ log.step(`Switching the registered repositories to ${region.label}`);
403
+ const current = resolveHookConfigFrom(runtime?.hooks);
404
+ installHookRuntime({ region, hooks: current, installedVersion: pkg.version, installScope: 'repo' });
405
+ repointTrees(registry, { region, hooks: current, isTracked, run });
406
+ }
407
+ // ② Machine-wide wiring: asked now, removed once every question is answered.
408
+ const machine = await askMachineWiring(region, deps, confirm, { regionSwitched: repoint });
409
+ if (machine === null)
410
+ return null;
411
+ // ③ Project link: repo mode resolves the project from it, never from the git
412
+ // origin. A worktree has no link of its own: it uses the main checkout's,
413
+ // else the repository's registered project, as the hooks do. Only a
414
+ // repository with no project yet runs the link flow.
415
+ let projectId = linkedProject(tree.root) ??
416
+ (tree.mainCheckoutRoot !== null ? linkedProject(tree.mainCheckoutRoot) : null) ??
417
+ (entry?.projectId || null);
418
+ // A link file the team shares is never rewritten: the project then comes
419
+ // from the environment, or the install stops with nothing written.
420
+ if (projectId === null && isTracked(tree.root, '.cybedefend/config.json')) {
421
+ const fromEnv = process.env.CYBEDEFEND_PROJECT_ID?.trim();
422
+ if (!fromEnv) {
423
+ log.err(`${trackedReason('.cybedefend/config.json')}, and it names no project. ` +
424
+ 'Set CYBEDEFEND_PROJECT_ID to your project id, or add the project id to that file with your team, ' +
425
+ 'then run `vibedefend install --repo` again.');
426
+ exit(1);
427
+ return null;
428
+ }
429
+ projectId = fromEnv;
430
+ }
431
+ const linkExisted = existsSync(join(tree.root, LINK_FILE_REL));
432
+ const excludeBefore = readExcludeBlock(tree.gitCommonDir);
433
+ // What the link step adds (the link file, its exclude line) goes again if
434
+ // the install stops before writing.
435
+ const undoLink = () => {
436
+ try {
437
+ if (!linkExisted && existsSync(join(tree.root, LINK_FILE_REL)))
438
+ removeCreatedLink(tree.root);
439
+ restoreExcludeBlock(tree.gitCommonDir, excludeBefore);
440
+ }
441
+ catch (e) {
442
+ log.warn(`Could not remove the project link this run made: ${errorMessage(e)}`);
443
+ }
444
+ };
445
+ let clients;
446
+ let hooks;
447
+ try {
448
+ if (projectId === null) {
449
+ log.step('Link this repository to a CybeDefend project');
450
+ projectId = await (deps.runLink ?? ((root) => linkWorkingTree(root, region)))(tree.root);
451
+ }
452
+ ensureLinkIgnored(tree.root, 'repo');
453
+ // ④ Agents and hook settings.
454
+ const askRepoClientSelection = deps.askRepoClientSelection ?? askRepoClientSelectionImpl;
455
+ const selected = await askRepoClientSelection(entry ? { current: (entry.clients ?? []) } : {});
456
+ clients = selected.filter((id) => repoAdapter(id) !== null);
457
+ if (clients.length === 0) {
458
+ undoLink();
459
+ log.info('No agent selected, so no agent was set up. To remove VibeDefend from this repository, run `vibedefend uninstall --repo`.');
460
+ return null;
461
+ }
462
+ // A re-run offers the earlier answers, as the machine-wide install does.
463
+ hooks = await (deps.askHookConfig ?? askHookConfigImpl)(runtime?.hooks ?? null, {
464
+ askActivation: false,
465
+ });
466
+ }
467
+ catch (e) {
468
+ undoLink();
469
+ throw e;
470
+ }
471
+ // A link this install created is recorded, so uninstall can restore
472
+ // `git status`; one that was already there, or an earlier run recorded
473
+ // (kept), is the user's call.
474
+ const recordedBefore = entry?.workingTrees
475
+ .find((t) => t.root === tree.root)
476
+ ?.files.some((f) => f.rel === LINK_FILE_REL);
477
+ const linkFiles = (!linkExisted || recordedBefore) && existsSync(join(tree.root, LINK_FILE_REL))
478
+ ? [{ root: tree.root, rel: LINK_FILE_REL }]
479
+ : [];
480
+ // ⑤ Write: first the machine-wide setup the user agreed to remove.
481
+ await removeAgreedMachineWiring(machine, deps, mcpNames);
482
+ log.step('Installing the hook runner');
483
+ installHookRuntime({ region, hooks, installedVersion: pkg.version, installScope: 'repo' });
484
+ const ctx = { region, hooks, isTracked, run };
485
+ const previousClients = (entry?.clients ?? []);
486
+ const removed = previousClients.filter((id) => !clients.includes(id));
487
+ const touched = [];
488
+ for (const id of removed) {
489
+ const adapter = repoAdapter(id);
490
+ if (adapter === null)
491
+ continue;
492
+ try {
493
+ touched.push(...adapter.repo.unwire(tree, mcpNames, run, isTracked));
494
+ log.ok(`${adapter.label} removed from this working tree`);
495
+ }
496
+ catch (e) {
497
+ log.warn(`Could not remove ${adapter.label} from this working tree: ${errorMessage(e)}`);
498
+ }
499
+ }
500
+ const repoInfo = { projectId, installedAt: entry?.installedAt ?? new Date().toISOString(), clients };
501
+ const withOthers = unwireFromOtherTrees(registry, tree, { removed, kept: previousClients.filter((id) => clients.includes(id)), touched }, repoInfo, ctx, mcpNames);
502
+ log.step(`Setting up ${tree.root}`);
503
+ const pieces = wireWorkingTree(tree, clients, ctx, mcpNames);
504
+ record(withOthers, registryPath, tree, repoInfo, pieces, linkFiles);
505
+ stampInstalledVersion(home, pkg.version);
506
+ return finish(tree, pieces, machine);
507
+ }
508
+ //# sourceMappingURL=install-repo.js.map