byterover-cli 2.6.0 → 3.0.1

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 (316) hide show
  1. package/.env.production +1 -0
  2. package/README.md +240 -14
  3. package/dist/agent/core/domain/knowledge/conflict-detector.d.ts +38 -0
  4. package/dist/agent/core/domain/knowledge/conflict-detector.js +71 -0
  5. package/dist/agent/core/domain/knowledge/conflict-resolver.d.ts +17 -0
  6. package/dist/agent/core/domain/knowledge/conflict-resolver.js +118 -0
  7. package/dist/agent/core/domain/knowledge/utils.d.ts +4 -0
  8. package/dist/agent/core/domain/knowledge/utils.js +6 -0
  9. package/dist/agent/core/interfaces/i-curate-service.d.ts +6 -0
  10. package/dist/agent/infra/tools/implementations/curate-tool.d.ts +67 -34
  11. package/dist/agent/infra/tools/implementations/curate-tool.js +294 -47
  12. package/dist/agent/resources/prompts/system-prompt.yml +15 -8
  13. package/dist/agent/resources/tools/code_exec.txt +3 -0
  14. package/dist/agent/resources/tools/curate.txt +12 -3
  15. package/dist/oclif/commands/connectors/install.d.ts +2 -1
  16. package/dist/oclif/commands/connectors/install.js +38 -3
  17. package/dist/oclif/commands/curate/index.d.ts +18 -0
  18. package/dist/oclif/commands/curate/index.js +78 -1
  19. package/dist/oclif/commands/init.d.ts +12 -0
  20. package/dist/oclif/commands/init.js +75 -0
  21. package/dist/oclif/commands/locations.js +1 -1
  22. package/dist/oclif/commands/providers/connect.d.ts +31 -1
  23. package/dist/oclif/commands/providers/connect.js +307 -27
  24. package/dist/oclif/commands/pull.d.ts +1 -0
  25. package/dist/oclif/commands/pull.js +7 -0
  26. package/dist/oclif/commands/push.d.ts +1 -0
  27. package/dist/oclif/commands/push.js +8 -0
  28. package/dist/oclif/commands/review/approve.d.ts +17 -0
  29. package/dist/oclif/commands/review/approve.js +37 -0
  30. package/dist/oclif/commands/review/base-review-decision.d.ts +18 -0
  31. package/dist/oclif/commands/review/base-review-decision.js +71 -0
  32. package/dist/oclif/commands/review/pending.d.ts +13 -0
  33. package/dist/oclif/commands/review/pending.js +94 -0
  34. package/dist/oclif/commands/review/reject.d.ts +17 -0
  35. package/dist/oclif/commands/review/reject.js +38 -0
  36. package/dist/oclif/commands/space/list.d.ts +2 -2
  37. package/dist/oclif/commands/space/list.js +13 -35
  38. package/dist/oclif/commands/space/switch.d.ts +2 -7
  39. package/dist/oclif/commands/space/switch.js +13 -56
  40. package/dist/oclif/commands/status.d.ts +1 -0
  41. package/dist/oclif/commands/status.js +11 -1
  42. package/dist/oclif/commands/vc/add.d.ts +7 -0
  43. package/dist/oclif/commands/vc/add.js +29 -0
  44. package/dist/oclif/commands/vc/branch.d.ts +15 -0
  45. package/dist/oclif/commands/vc/branch.js +70 -0
  46. package/dist/oclif/commands/vc/checkout.d.ts +14 -0
  47. package/dist/oclif/commands/vc/checkout.js +47 -0
  48. package/dist/oclif/commands/vc/clone.d.ts +9 -0
  49. package/dist/oclif/commands/vc/clone.js +61 -0
  50. package/dist/oclif/commands/vc/commit.d.ts +10 -0
  51. package/dist/oclif/commands/vc/commit.js +32 -0
  52. package/dist/oclif/commands/vc/config.d.ts +10 -0
  53. package/dist/oclif/commands/vc/config.js +30 -0
  54. package/dist/oclif/commands/vc/fetch.d.ts +10 -0
  55. package/dist/oclif/commands/vc/fetch.js +42 -0
  56. package/dist/oclif/commands/vc/index.d.ts +6 -0
  57. package/dist/oclif/commands/vc/index.js +8 -0
  58. package/dist/oclif/commands/vc/init.d.ts +6 -0
  59. package/dist/oclif/commands/vc/init.js +25 -0
  60. package/dist/oclif/commands/vc/log.d.ts +13 -0
  61. package/dist/oclif/commands/vc/log.js +48 -0
  62. package/dist/oclif/commands/vc/merge.d.ts +19 -0
  63. package/dist/oclif/commands/vc/merge.js +130 -0
  64. package/dist/oclif/commands/vc/pull.d.ts +13 -0
  65. package/dist/oclif/commands/vc/pull.js +60 -0
  66. package/dist/oclif/commands/vc/push.d.ts +13 -0
  67. package/dist/oclif/commands/vc/push.js +60 -0
  68. package/dist/oclif/commands/vc/remote/add.d.ts +10 -0
  69. package/dist/oclif/commands/vc/remote/add.js +30 -0
  70. package/dist/oclif/commands/vc/remote/index.d.ts +6 -0
  71. package/dist/oclif/commands/vc/remote/index.js +16 -0
  72. package/dist/oclif/commands/vc/remote/set-url.d.ts +10 -0
  73. package/dist/oclif/commands/vc/remote/set-url.js +30 -0
  74. package/dist/oclif/commands/vc/reset.d.ts +13 -0
  75. package/dist/oclif/commands/vc/reset.js +62 -0
  76. package/dist/oclif/commands/vc/status.d.ts +8 -0
  77. package/dist/oclif/commands/vc/status.js +106 -0
  78. package/dist/oclif/hooks/init/validate-brv-config.d.ts +26 -0
  79. package/dist/oclif/hooks/init/validate-brv-config.js +62 -0
  80. package/dist/oclif/lib/daemon-client.d.ts +2 -0
  81. package/dist/oclif/lib/daemon-client.js +36 -10
  82. package/dist/oclif/lib/prompt-utils.d.ts +43 -0
  83. package/dist/oclif/lib/prompt-utils.js +84 -0
  84. package/dist/oclif/lib/spinner.d.ts +8 -0
  85. package/dist/oclif/lib/spinner.js +23 -0
  86. package/dist/oclif/lib/task-client.d.ts +5 -0
  87. package/dist/oclif/lib/task-client.js +15 -2
  88. package/dist/server/config/environment.d.ts +2 -0
  89. package/dist/server/config/environment.js +2 -0
  90. package/dist/server/constants.d.ts +3 -0
  91. package/dist/server/constants.js +9 -0
  92. package/dist/server/core/domain/entities/auth-token.d.ts +2 -0
  93. package/dist/server/core/domain/entities/auth-token.js +7 -1
  94. package/dist/server/core/domain/entities/curate-log-entry.d.ts +11 -0
  95. package/dist/server/core/domain/entities/space.d.ts +4 -0
  96. package/dist/server/core/domain/entities/space.js +8 -0
  97. package/dist/server/core/domain/entities/team.d.ts +2 -0
  98. package/dist/server/core/domain/entities/team.js +4 -0
  99. package/dist/server/core/domain/errors/git-error.d.ts +6 -0
  100. package/dist/server/core/domain/errors/git-error.js +12 -0
  101. package/dist/server/core/domain/errors/task-error.d.ts +4 -0
  102. package/dist/server/core/domain/errors/task-error.js +8 -0
  103. package/dist/server/core/domain/errors/vc-error.d.ts +5 -0
  104. package/dist/server/core/domain/errors/vc-error.js +8 -0
  105. package/dist/server/core/domain/knowledge/markdown-writer.d.ts +4 -1
  106. package/dist/server/core/domain/knowledge/markdown-writer.js +37 -7
  107. package/dist/server/core/domain/transport/schemas.d.ts +6 -6
  108. package/dist/server/core/interfaces/context-tree/i-context-tree-service.d.ts +11 -0
  109. package/dist/server/core/interfaces/process/i-task-lifecycle-hook.d.ts +6 -0
  110. package/dist/server/core/interfaces/services/i-git-service.d.ts +234 -0
  111. package/dist/server/core/interfaces/services/i-git-service.js +1 -0
  112. package/dist/server/core/interfaces/storage/i-curate-log-store.d.ts +5 -0
  113. package/dist/server/core/interfaces/storage/i-review-backup-store.d.ts +19 -0
  114. package/dist/server/core/interfaces/storage/i-review-backup-store.js +1 -0
  115. package/dist/server/core/interfaces/vc/i-vc-git-config-store.d.ts +8 -0
  116. package/dist/server/core/interfaces/vc/i-vc-git-config-store.js +1 -0
  117. package/dist/server/infra/config/auto-init.d.ts +0 -2
  118. package/dist/server/infra/config/auto-init.js +0 -1
  119. package/dist/server/infra/context-tree/file-context-tree-service.d.ts +2 -0
  120. package/dist/server/infra/context-tree/file-context-tree-service.js +13 -0
  121. package/dist/server/infra/daemon/brv-server.js +23 -3
  122. package/dist/server/infra/git/cogit-url.d.ts +17 -0
  123. package/dist/server/infra/git/cogit-url.js +39 -0
  124. package/dist/server/infra/git/git-http-wrapper.d.ts +20 -0
  125. package/dist/server/infra/git/git-http-wrapper.js +334 -0
  126. package/dist/server/infra/git/isomorphic-git-service.d.ts +78 -0
  127. package/dist/server/infra/git/isomorphic-git-service.js +983 -0
  128. package/dist/server/infra/http/review-api-handler.d.ts +13 -0
  129. package/dist/server/infra/http/review-api-handler.js +286 -0
  130. package/dist/server/infra/http/review-ui.d.ts +7 -0
  131. package/dist/server/infra/http/review-ui.js +606 -0
  132. package/dist/server/infra/mcp/tools/brv-curate-tool.d.ts +2 -2
  133. package/dist/server/infra/process/curate-log-handler.d.ts +18 -2
  134. package/dist/server/infra/process/curate-log-handler.js +50 -13
  135. package/dist/server/infra/process/feature-handlers.js +41 -1
  136. package/dist/server/infra/process/task-router.js +16 -0
  137. package/dist/server/infra/space/http-space-service.js +2 -0
  138. package/dist/server/infra/storage/file-curate-log-store.d.ts +10 -0
  139. package/dist/server/infra/storage/file-curate-log-store.js +35 -0
  140. package/dist/server/infra/storage/file-review-backup-store.d.ts +29 -0
  141. package/dist/server/infra/storage/file-review-backup-store.js +121 -0
  142. package/dist/server/infra/transport/handlers/auth-handler.js +9 -5
  143. package/dist/server/infra/transport/handlers/handler-types.d.ts +9 -0
  144. package/dist/server/infra/transport/handlers/handler-types.js +11 -0
  145. package/dist/server/infra/transport/handlers/index.d.ts +4 -0
  146. package/dist/server/infra/transport/handlers/index.js +2 -0
  147. package/dist/server/infra/transport/handlers/init-handler.d.ts +1 -0
  148. package/dist/server/infra/transport/handlers/init-handler.js +13 -1
  149. package/dist/server/infra/transport/handlers/pull-handler.d.ts +3 -0
  150. package/dist/server/infra/transport/handlers/pull-handler.js +5 -1
  151. package/dist/server/infra/transport/handlers/push-handler.d.ts +20 -0
  152. package/dist/server/infra/transport/handlers/push-handler.js +116 -14
  153. package/dist/server/infra/transport/handlers/reset-handler.d.ts +11 -0
  154. package/dist/server/infra/transport/handlers/reset-handler.js +37 -1
  155. package/dist/server/infra/transport/handlers/review-handler.d.ts +35 -0
  156. package/dist/server/infra/transport/handlers/review-handler.js +162 -0
  157. package/dist/server/infra/transport/handlers/space-handler.d.ts +3 -0
  158. package/dist/server/infra/transport/handlers/space-handler.js +4 -1
  159. package/dist/server/infra/transport/handlers/status-handler.d.ts +5 -0
  160. package/dist/server/infra/transport/handlers/status-handler.js +51 -16
  161. package/dist/server/infra/transport/handlers/vc-handler.d.ts +100 -0
  162. package/dist/server/infra/transport/handlers/vc-handler.js +1050 -0
  163. package/dist/server/infra/transport/socket-io-transport-server.d.ts +7 -0
  164. package/dist/server/infra/transport/socket-io-transport-server.js +12 -1
  165. package/dist/server/infra/transport/transport-connector.d.ts +1 -1
  166. package/dist/server/infra/transport/transport-connector.js +2 -1
  167. package/dist/server/infra/vc/file-vc-git-config-store.d.ts +11 -0
  168. package/dist/server/infra/vc/file-vc-git-config-store.js +43 -0
  169. package/dist/server/templates/skill/SKILL.md +167 -33
  170. package/dist/server/utils/curate-result-parser.d.ts +64 -0
  171. package/dist/server/utils/curate-result-parser.js +8 -0
  172. package/dist/server/utils/gitignore.d.ts +9 -0
  173. package/dist/server/utils/gitignore.js +47 -0
  174. package/dist/shared/transport/events/index.d.ts +6 -0
  175. package/dist/shared/transport/events/index.js +3 -0
  176. package/dist/shared/transport/events/init-events.d.ts +8 -0
  177. package/dist/shared/transport/events/init-events.js +1 -0
  178. package/dist/shared/transport/events/push-events.d.ts +6 -0
  179. package/dist/shared/transport/events/review-events.d.ts +41 -0
  180. package/dist/shared/transport/events/review-events.js +5 -0
  181. package/dist/shared/transport/events/vc-events.d.ts +257 -0
  182. package/dist/shared/transport/events/vc-events.js +67 -0
  183. package/dist/shared/transport/types/dto.d.ts +6 -1
  184. package/dist/tui/app/pages/init-project-page.d.ts +9 -0
  185. package/dist/tui/app/pages/init-project-page.js +54 -0
  186. package/dist/tui/app/pages/protected-routes.js +14 -6
  187. package/dist/tui/components/index.d.ts +0 -2
  188. package/dist/tui/components/index.js +0 -1
  189. package/dist/tui/features/activity/hooks/use-activity-logs.js +7 -1
  190. package/dist/tui/features/commands/definitions/index.js +3 -0
  191. package/dist/tui/features/commands/definitions/space-list.js +9 -18
  192. package/dist/tui/features/commands/definitions/space-switch.js +10 -6
  193. package/dist/tui/features/commands/definitions/vc-add.d.ts +2 -0
  194. package/dist/tui/features/commands/definitions/vc-add.js +15 -0
  195. package/dist/tui/features/commands/definitions/vc-branch.d.ts +2 -0
  196. package/dist/tui/features/commands/definitions/vc-branch.js +33 -0
  197. package/dist/tui/features/commands/definitions/vc-checkout.d.ts +2 -0
  198. package/dist/tui/features/commands/definitions/vc-checkout.js +32 -0
  199. package/dist/tui/features/commands/definitions/vc-clone.d.ts +2 -0
  200. package/dist/tui/features/commands/definitions/vc-clone.js +18 -0
  201. package/dist/tui/features/commands/definitions/vc-commit.d.ts +2 -0
  202. package/dist/tui/features/commands/definitions/vc-commit.js +32 -0
  203. package/dist/tui/features/commands/definitions/vc-config.d.ts +2 -0
  204. package/dist/tui/features/commands/definitions/vc-config.js +40 -0
  205. package/dist/tui/features/commands/definitions/vc-fetch.d.ts +2 -0
  206. package/dist/tui/features/commands/definitions/vc-fetch.js +37 -0
  207. package/dist/tui/features/commands/definitions/vc-init.d.ts +2 -0
  208. package/dist/tui/features/commands/definitions/vc-init.js +11 -0
  209. package/dist/tui/features/commands/definitions/vc-log.d.ts +2 -0
  210. package/dist/tui/features/commands/definitions/vc-log.js +25 -0
  211. package/dist/tui/features/commands/definitions/vc-merge.d.ts +2 -0
  212. package/dist/tui/features/commands/definitions/vc-merge.js +48 -0
  213. package/dist/tui/features/commands/definitions/vc-pull.d.ts +2 -0
  214. package/dist/tui/features/commands/definitions/vc-pull.js +42 -0
  215. package/dist/tui/features/commands/definitions/vc-push.d.ts +2 -0
  216. package/dist/tui/features/commands/definitions/vc-push.js +38 -0
  217. package/dist/tui/features/commands/definitions/vc-remote.d.ts +2 -0
  218. package/dist/tui/features/commands/definitions/vc-remote.js +57 -0
  219. package/dist/tui/features/commands/definitions/vc-reset.d.ts +2 -0
  220. package/dist/tui/features/commands/definitions/vc-reset.js +35 -0
  221. package/dist/tui/features/commands/definitions/vc-status.d.ts +2 -0
  222. package/dist/tui/features/commands/definitions/vc-status.js +11 -0
  223. package/dist/tui/features/commands/definitions/vc.d.ts +2 -0
  224. package/dist/tui/features/commands/definitions/vc.js +36 -0
  225. package/dist/tui/features/commands/hooks/use-slash-command-processor.js +5 -5
  226. package/dist/tui/features/log/api/execute-log.d.ts +8 -0
  227. package/dist/tui/features/log/api/execute-log.js +13 -0
  228. package/dist/tui/features/log/components/log-flow.d.ts +14 -0
  229. package/dist/tui/features/log/components/log-flow.js +29 -0
  230. package/dist/tui/features/log/utils/format-log.d.ts +3 -0
  231. package/dist/tui/features/log/utils/format-log.js +42 -0
  232. package/dist/tui/features/onboarding/hooks/use-app-view-mode.d.ts +9 -5
  233. package/dist/tui/features/onboarding/hooks/use-app-view-mode.js +12 -5
  234. package/dist/tui/features/push/components/push-flow.js +9 -2
  235. package/dist/tui/features/reset/components/reset-flow.js +2 -1
  236. package/dist/tui/features/status/components/status-view.js +2 -1
  237. package/dist/tui/features/status/utils/format-status.js +9 -0
  238. package/dist/tui/features/tasks/hooks/use-task-subscriptions.js +11 -0
  239. package/dist/tui/features/tasks/stores/tasks-store.d.ts +10 -0
  240. package/dist/tui/features/tasks/stores/tasks-store.js +16 -0
  241. package/dist/tui/features/vc/add/api/execute-vc-add.d.ts +8 -0
  242. package/dist/tui/features/vc/add/api/execute-vc-add.js +13 -0
  243. package/dist/tui/features/vc/add/components/vc-add-flow.d.ts +7 -0
  244. package/dist/tui/features/vc/add/components/vc-add-flow.js +35 -0
  245. package/dist/tui/features/vc/branch/api/execute-vc-branch.d.ts +8 -0
  246. package/dist/tui/features/vc/branch/api/execute-vc-branch.js +13 -0
  247. package/dist/tui/features/vc/branch/components/vc-branch-flow.d.ts +8 -0
  248. package/dist/tui/features/vc/branch/components/vc-branch-flow.js +53 -0
  249. package/dist/tui/features/vc/branch/utils/format-branch.d.ts +4 -0
  250. package/dist/tui/features/vc/branch/utils/format-branch.js +12 -0
  251. package/dist/tui/features/vc/checkout/api/execute-vc-checkout.d.ts +8 -0
  252. package/dist/tui/features/vc/checkout/api/execute-vc-checkout.js +13 -0
  253. package/dist/tui/features/vc/checkout/components/vc-checkout-flow.d.ts +8 -0
  254. package/dist/tui/features/vc/checkout/components/vc-checkout-flow.js +33 -0
  255. package/dist/tui/features/vc/clone/api/execute-vc-clone.d.ts +8 -0
  256. package/dist/tui/features/vc/clone/api/execute-vc-clone.js +13 -0
  257. package/dist/tui/features/vc/clone/components/vc-clone-flow.d.ts +7 -0
  258. package/dist/tui/features/vc/clone/components/vc-clone-flow.js +79 -0
  259. package/dist/tui/features/vc/commit/api/execute-vc-commit.d.ts +8 -0
  260. package/dist/tui/features/vc/commit/api/execute-vc-commit.js +13 -0
  261. package/dist/tui/features/vc/commit/components/vc-commit-flow.d.ts +7 -0
  262. package/dist/tui/features/vc/commit/components/vc-commit-flow.js +29 -0
  263. package/dist/tui/features/vc/config/api/execute-vc-config.d.ts +8 -0
  264. package/dist/tui/features/vc/config/api/execute-vc-config.js +13 -0
  265. package/dist/tui/features/vc/config/components/vc-config-flow.d.ts +9 -0
  266. package/dist/tui/features/vc/config/components/vc-config-flow.js +30 -0
  267. package/dist/tui/features/vc/fetch/api/execute-vc-fetch.d.ts +8 -0
  268. package/dist/tui/features/vc/fetch/api/execute-vc-fetch.js +13 -0
  269. package/dist/tui/features/vc/fetch/components/vc-fetch-flow.d.ts +8 -0
  270. package/dist/tui/features/vc/fetch/components/vc-fetch-flow.js +75 -0
  271. package/dist/tui/features/vc/init/api/execute-vc-init.d.ts +8 -0
  272. package/dist/tui/features/vc/init/api/execute-vc-init.js +13 -0
  273. package/dist/tui/features/vc/init/components/vc-init-flow.d.ts +10 -0
  274. package/dist/tui/features/vc/init/components/vc-init-flow.js +37 -0
  275. package/dist/tui/features/vc/merge/api/execute-vc-merge.d.ts +8 -0
  276. package/dist/tui/features/vc/merge/api/execute-vc-merge.js +13 -0
  277. package/dist/tui/features/vc/merge/components/vc-merge-flow.d.ts +11 -0
  278. package/dist/tui/features/vc/merge/components/vc-merge-flow.js +72 -0
  279. package/dist/tui/features/vc/pull/api/execute-vc-pull.d.ts +8 -0
  280. package/dist/tui/features/vc/pull/api/execute-vc-pull.js +13 -0
  281. package/dist/tui/features/vc/pull/components/vc-pull-flow.d.ts +9 -0
  282. package/dist/tui/features/vc/pull/components/vc-pull-flow.js +83 -0
  283. package/dist/tui/features/vc/push/api/execute-vc-push.d.ts +8 -0
  284. package/dist/tui/features/vc/push/api/execute-vc-push.js +13 -0
  285. package/dist/tui/features/vc/push/components/vc-push-flow.d.ts +8 -0
  286. package/dist/tui/features/vc/push/components/vc-push-flow.js +83 -0
  287. package/dist/tui/features/vc/remote/api/execute-vc-remote.d.ts +8 -0
  288. package/dist/tui/features/vc/remote/api/execute-vc-remote.js +13 -0
  289. package/dist/tui/features/vc/remote/components/vc-remote-flow.d.ts +9 -0
  290. package/dist/tui/features/vc/remote/components/vc-remote-flow.js +42 -0
  291. package/dist/tui/features/vc/reset/api/execute-vc-reset.d.ts +8 -0
  292. package/dist/tui/features/vc/reset/api/execute-vc-reset.js +13 -0
  293. package/dist/tui/features/vc/reset/components/vc-reset-flow.d.ts +10 -0
  294. package/dist/tui/features/vc/reset/components/vc-reset-flow.js +63 -0
  295. package/dist/tui/features/vc/status/api/execute-vc-status.d.ts +8 -0
  296. package/dist/tui/features/vc/status/api/execute-vc-status.js +13 -0
  297. package/dist/tui/features/vc/status/components/vc-status-flow.d.ts +10 -0
  298. package/dist/tui/features/vc/status/components/vc-status-flow.js +133 -0
  299. package/dist/tui/lib/environment.d.ts +8 -0
  300. package/dist/tui/lib/environment.js +8 -0
  301. package/dist/tui/utils/error-messages.d.ts +5 -1
  302. package/dist/tui/utils/error-messages.js +32 -3
  303. package/oclif.manifest.json +1018 -98
  304. package/package.json +9 -3
  305. package/dist/oclif/hooks/prerun/validate-brv-config-version.d.ts +0 -33
  306. package/dist/oclif/hooks/prerun/validate-brv-config-version.js +0 -86
  307. package/dist/tui/components/init.d.ts +0 -33
  308. package/dist/tui/components/init.js +0 -234
  309. package/dist/tui/features/space/api/get-spaces.d.ts +0 -16
  310. package/dist/tui/features/space/api/get-spaces.js +0 -17
  311. package/dist/tui/features/space/api/switch-space.d.ts +0 -11
  312. package/dist/tui/features/space/api/switch-space.js +0 -24
  313. package/dist/tui/features/space/components/space-list-view.d.ts +0 -12
  314. package/dist/tui/features/space/components/space-list-view.js +0 -56
  315. package/dist/tui/features/space/components/space-switch-flow.d.ts +0 -13
  316. package/dist/tui/features/space/components/space-switch-flow.js +0 -97
@@ -0,0 +1,334 @@
1
+ import { request as httpRequest } from 'isomorphic-git/http/node';
2
+ /**
3
+ * Pktline-encoded service announcement preambles.
4
+ *
5
+ * Git Smart HTTP Protocol v1 requires the info/refs response to start with:
6
+ * <pktline># service=<service>\n
7
+ * 0000
8
+ *
9
+ * Lengths:
10
+ * "# service=git-receive-pack\n" = 27 bytes + 4 prefix = 31 = 0x1f → "001f"
11
+ * "# service=git-upload-pack\n" = 26 bytes + 4 prefix = 30 = 0x1e → "001e"
12
+ */
13
+ const SERVICE_PREAMBLES = {
14
+ 'git-receive-pack': '001f# service=git-receive-pack\n0000',
15
+ 'git-upload-pack': '001e# service=git-upload-pack\n0000',
16
+ };
17
+ /**
18
+ * V2 ls-refs request body (pktline-encoded).
19
+ *
20
+ * Format: command section + delimiter (0001) + argument section + flush (0000)
21
+ * "command=ls-refs\n" = 16 chars + 4 prefix = 20 = 0x14 → "0014"
22
+ * "peel\n" = 5 chars + 4 prefix = 9 = 0x09 → "0009"
23
+ * "symrefs\n" = 8 chars + 4 prefix = 12 = 0x0c → "000c"
24
+ */
25
+ const LS_REFS_REQUEST = Buffer.from('0014command=ls-refs\n00010009peel\n000csymrefs\n0000');
26
+ async function* singleChunk(buffer) {
27
+ yield buffer;
28
+ }
29
+ /** Encode a string as a pktline: 4-char hex length (including the 4 bytes) + content */
30
+ function pktline(content) {
31
+ const len = Buffer.byteLength(content, 'utf8') + 4;
32
+ return len.toString(16).padStart(4, '0') + content;
33
+ }
34
+ /**
35
+ * Parse the ls-refs response body into a list of {sha, name} entries.
36
+ *
37
+ * Each pktline line looks like: "<sha> <refname>\n"
38
+ * or with symref: "<sha> <refname> symref-target:<target>\n"
39
+ */
40
+ async function parseLsRefsBody(body) {
41
+ const refs = [];
42
+ let offset = 0;
43
+ while (offset + 4 <= body.length) {
44
+ const lenHex = body.subarray(offset, offset + 4).toString('ascii');
45
+ const len = Number.parseInt(lenHex, 16);
46
+ if (len === 0)
47
+ break; // flush packet
48
+ if (len < 4)
49
+ break; // malformed pktline — cannot advance safely, treat as end-of-stream
50
+ const line = body
51
+ .subarray(offset + 4, offset + len)
52
+ .toString('utf8')
53
+ .replace(/\n$/, '');
54
+ offset += len;
55
+ const parts = line.split(' ');
56
+ if (parts.length < 2)
57
+ continue;
58
+ const sha = parts[0];
59
+ const name = parts[1];
60
+ const symrefPart = parts.find((p) => p.startsWith('symref-target:'));
61
+ const symref = symrefPart ? symrefPart.slice('symref-target:'.length) : undefined;
62
+ refs.push({ name, sha, symref });
63
+ }
64
+ return refs;
65
+ }
66
+ /**
67
+ * Build a synthetic Git Protocol v1 refs advertisement buffer from a list of refs.
68
+ *
69
+ * Format:
70
+ * <preamble>
71
+ * 0000 ← preamble flush
72
+ * <len><sha> <first-ref>\0<capabilities>\n ← first ref (NUL + caps)
73
+ * <len><sha> <other-ref>\n ← subsequent refs
74
+ * ...
75
+ * 0000 ← end flush
76
+ *
77
+ * If there are no refs, returns just the preamble + two flushes (empty repo case).
78
+ */
79
+ function buildV1RefsAdvertisement(service, refs) {
80
+ const preamble = SERVICE_PREAMBLES[service];
81
+ if (refs.length === 0) {
82
+ // Empty repo: preamble + flush + zero-id capabilities line + flush
83
+ const zeroId = '0'.repeat(40);
84
+ const capsLine = pktline(`${zeroId} capabilities^\0side-band-64k ofs-delta\n`);
85
+ return Buffer.from(preamble + capsLine + '0000');
86
+ }
87
+ // Build capabilities string (v1 format)
88
+ const capabilities = ['side-band-64k', 'ofs-delta', 'agent=git/isomorphic-git'];
89
+ // Add symref for HEAD if we know it
90
+ const headRef = refs.find((r) => r.name === 'HEAD');
91
+ if (headRef?.symref) {
92
+ capabilities.push(`symref=HEAD:${headRef.symref}`);
93
+ }
94
+ else if (headRef) {
95
+ // Infer symref: find a non-HEAD ref with the same SHA as HEAD
96
+ const matchingBranch = refs.find((r) => r.name !== 'HEAD' && r.sha === headRef.sha);
97
+ if (matchingBranch) {
98
+ capabilities.push(`symref=HEAD:${matchingBranch.name}`);
99
+ }
100
+ }
101
+ const capsStr = capabilities.join(' ');
102
+ // Git Protocol v1 requires HEAD to be the first ref (it carries the capabilities line)
103
+ const sorted = [...refs].sort((a, b) => (a.name === 'HEAD' ? -1 : b.name === 'HEAD' ? 1 : 0));
104
+ let body = preamble;
105
+ for (const [i, { name, sha }] of sorted.entries()) {
106
+ // First ref includes NUL + capabilities
107
+ body += i === 0 ? pktline(`${sha} ${name}\0${capsStr}\n`) : pktline(`${sha} ${name}\n`);
108
+ }
109
+ body += '0000';
110
+ return Buffer.from(body);
111
+ }
112
+ /**
113
+ * Detects whether a buffered info/refs response body is a Git Protocol v2
114
+ * capability advertisement (starts with "000eversion 2").
115
+ */
116
+ function isProtocolV2Response(body) {
117
+ return body.subarray(0, 14).toString('ascii') === '000eversion 2\n';
118
+ }
119
+ /**
120
+ * When the server returns a Protocol v2 response for git-upload-pack, isomorphic-git
121
+ * (which requests Protocol v1) cannot use it directly — its v1 fetch logic accesses
122
+ * `remoteHTTP.refs` which is `undefined` for v2 discovery results.
123
+ *
124
+ * This function translates the v2 response to v1 by making a secondary ls-refs POST
125
+ * request, then synthesising a valid Protocol v1 refs advertisement.
126
+ */
127
+ async function translateUploadPackV2ToV1(params, originalResponse) {
128
+ const baseUrl = String(params.url).replace(/\/info\/refs\?service=git-upload-pack.*$/, '');
129
+ // Use native fetch instead of isomorphic-git's httpRequest to avoid the
130
+ // "require is not defined" error that occurs when httpRequest processes a POST
131
+ // body in an ESM context (it lazily loads node:stream via require()).
132
+ let lsBody;
133
+ try {
134
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins -- fetch works on Node >=18, stable from 21
135
+ const fetchResponse = await fetch(`${baseUrl}/git-upload-pack`, {
136
+ body: LS_REFS_REQUEST,
137
+ headers: {
138
+ ...params.headers,
139
+ 'Content-Type': 'application/x-git-upload-pack-request',
140
+ 'Git-Protocol': 'version=2',
141
+ },
142
+ method: 'POST',
143
+ });
144
+ if (!fetchResponse.ok) {
145
+ throw new Error(`HTTP Error: ${fetchResponse.status} ${fetchResponse.statusText}`);
146
+ }
147
+ lsBody = Buffer.from(await fetchResponse.arrayBuffer());
148
+ }
149
+ catch (error) {
150
+ throw new Error(`Failed to translate Git Protocol v2 to v1 (ls-refs POST to ${baseUrl}/git-upload-pack failed): ${error instanceof Error ? error.message : String(error)}`);
151
+ }
152
+ const refs = await parseLsRefsBody(lsBody);
153
+ const v1Body = buildV1RefsAdvertisement('git-upload-pack', refs);
154
+ return { ...originalResponse, body: singleChunk(v1Body) };
155
+ }
156
+ /**
157
+ * Intercept a v1-format git-upload-pack POST from isomorphic-git and convert
158
+ * it to a Git Protocol v2 fetch command, since the CoGit server only handles v2.
159
+ *
160
+ * Parses the v1 pktlines (want/have/done) and re-sends as v2 format using
161
+ * native fetch to avoid the `require is not defined` ESM issue in httpRequest.
162
+ *
163
+ * The v2 packfile response is passed back after stripping the "packfile" section
164
+ * header pktline (if present), so isomorphic-git sees a v1-compatible sideband stream.
165
+ */
166
+ async function interceptUploadPackPost(params) {
167
+ // Buffer the v1 body from isomorphic-git
168
+ const chunks = [];
169
+ for await (const chunk of params.body ?? []) {
170
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
171
+ }
172
+ const v1Body = Buffer.concat(chunks);
173
+ // Parse v1 pktlines: extract want SHAs, have SHAs, and done flag.
174
+ // The first "want" line includes capabilities (e.g. "want <sha> side-band-64k ofs-delta") —
175
+ // we only keep the 40-char SHA; capabilities are dropped since v2 handles them differently.
176
+ const wants = [];
177
+ const haves = [];
178
+ let done = false;
179
+ let offset = 0;
180
+ while (offset + 4 <= v1Body.length) {
181
+ const lenHex = v1Body.subarray(offset, offset + 4).toString('ascii');
182
+ const len = Number.parseInt(lenHex, 16);
183
+ if (len === 0) {
184
+ offset += 4;
185
+ continue;
186
+ }
187
+ if (len < 4)
188
+ break;
189
+ const line = v1Body
190
+ .subarray(offset + 4, offset + len)
191
+ .toString('utf8')
192
+ .replace(/\n$/, '');
193
+ offset += len;
194
+ if (line.startsWith('want ')) {
195
+ wants.push(line.split(' ')[1]); // 40-char SHA only, ignore capabilities
196
+ }
197
+ else if (line.startsWith('have ')) {
198
+ haves.push(line.split(' ')[1]);
199
+ }
200
+ else if (line === 'done') {
201
+ done = true;
202
+ }
203
+ }
204
+ // Build a v2 fetch command body.
205
+ // '0001' is the delim-pkt (Git Protocol v2) that separates the command
206
+ // section from the argument section. '0000' (flush-pkt) would signal
207
+ // end-of-request, causing the server to ignore all want/done arguments.
208
+ let v2 = pktline('command=fetch\n') + '0001';
209
+ for (const sha of wants)
210
+ v2 += pktline(`want ${sha}\n`);
211
+ for (const sha of haves)
212
+ v2 += pktline(`have ${sha}\n`);
213
+ if (done)
214
+ v2 += pktline('done\n');
215
+ v2 += '0000';
216
+ const url = String(params.url);
217
+ let v2ResponseBody;
218
+ let responseHeaders;
219
+ let statusCode;
220
+ let statusMessage;
221
+ try {
222
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins -- fetch works on Node >=18, stable from 21
223
+ const fetchResponse = await fetch(url, {
224
+ body: Buffer.from(v2),
225
+ headers: {
226
+ ...params.headers,
227
+ 'Content-Type': 'application/x-git-upload-pack-request',
228
+ 'Git-Protocol': 'version=2',
229
+ },
230
+ method: 'POST',
231
+ });
232
+ if (!fetchResponse.ok) {
233
+ throw new Error(`HTTP Error: ${fetchResponse.status} ${fetchResponse.statusText}`);
234
+ }
235
+ v2ResponseBody = Buffer.from(await fetchResponse.arrayBuffer());
236
+ responseHeaders = Object.fromEntries(fetchResponse.headers.entries());
237
+ statusCode = fetchResponse.status;
238
+ statusMessage = fetchResponse.statusText;
239
+ }
240
+ catch (error) {
241
+ throw new Error(`Failed to fetch pack data from ${url}: ${error instanceof Error ? error.message : String(error)}`);
242
+ }
243
+ // Strip the v2 "packfile" section header pktline (if present) so that
244
+ // isomorphic-git receives a v1-compatible sideband stream starting with
245
+ // the first real sideband byte (0x01 = packfile data, 0x02 = progress).
246
+ const responseBody = stripV2PackfileSectionHeader(v2ResponseBody);
247
+ return {
248
+ body: singleChunk(responseBody),
249
+ headers: responseHeaders,
250
+ method: 'POST',
251
+ statusCode,
252
+ statusMessage,
253
+ url,
254
+ };
255
+ }
256
+ /**
257
+ * Git Protocol v2 fetch responses wrap the packfile in a "packfile" section.
258
+ * Strip that section-header pktline so isomorphic-git sees a v1-compatible
259
+ * sideband stream (first byte of each pktline is the sideband code).
260
+ */
261
+ function stripV2PackfileSectionHeader(body) {
262
+ if (body.length < 4)
263
+ return body;
264
+ const lenHex = body.subarray(0, 4).toString('ascii');
265
+ const len = Number.parseInt(lenHex, 16);
266
+ if (len < 4 || len > body.length)
267
+ return body;
268
+ // Strip optional sideband-1 prefix byte (0x01 = pack-data band) then check for "packfile\n"
269
+ let payload = body.subarray(4, len);
270
+ if (payload[0] === 0x01)
271
+ payload = payload.subarray(1);
272
+ const content = payload.toString('utf8').replace(/\n$/, '');
273
+ if (content === 'packfile')
274
+ return body.subarray(len);
275
+ return body;
276
+ }
277
+ /**
278
+ * Wraps isomorphic-git's HTTP client to ensure Git Smart HTTP Protocol v1 compliance.
279
+ *
280
+ * ByteRover CoGit exhibits two non-standard behaviours:
281
+ *
282
+ * 1. git-receive-pack (push): Returns a valid pktline ref advertisement with the
283
+ * correct Content-Type, but OMITS the required `# service=git-receive-pack\n`
284
+ * preamble. This wrapper injects the missing preamble.
285
+ *
286
+ * 2. git-upload-pack (fetch/clone): Always returns a Git Protocol v2 capability
287
+ * advertisement, even when the client does not request v2. isomorphic-git uses
288
+ * Protocol v1 internally and cannot use a v2 response for its fetch logic.
289
+ * This wrapper:
290
+ * a. Translates the info/refs v2 response to v1 (ls-refs POST + synthetic refs advertisement)
291
+ * b. Intercepts the subsequent pack-data POST and converts it from v1 to v2 fetch command
292
+ */
293
+ export const gitHttpWrapper = {
294
+ async request(params) {
295
+ const url = String(params.url);
296
+ // Intercept git-upload-pack pack-data POST (not info/refs):
297
+ // isomorphic-git sends v1 want/have/done but the server only understands v2.
298
+ if (url.includes('/git-upload-pack') && !url.includes('/info/refs')) {
299
+ return interceptUploadPackPost(params);
300
+ }
301
+ const response = await httpRequest(params);
302
+ const service = url.includes('/info/refs?service=git-receive-pack')
303
+ ? 'git-receive-pack'
304
+ : url.includes('/info/refs?service=git-upload-pack')
305
+ ? 'git-upload-pack'
306
+ : null;
307
+ if (!service)
308
+ return response;
309
+ const headers = response.headers ?? {};
310
+ const expectedType = `application/x-${service}-advertisement`;
311
+ if (headers['content-type'] !== expectedType)
312
+ return response;
313
+ // Buffer the full body to inspect it
314
+ const chunks = [];
315
+ for await (const chunk of response.body ?? []) {
316
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
317
+ }
318
+ const body = Buffer.concat(chunks);
319
+ // For upload-pack: server forces Protocol v2 → translate to v1 for isomorphic-git
320
+ if (service === 'git-upload-pack' && isProtocolV2Response(body)) {
321
+ return translateUploadPackV2ToV1(params, response);
322
+ }
323
+ const preamble = SERVICE_PREAMBLES[service];
324
+ // If the v1 preamble is already present, return the buffered body as-is
325
+ if (body.toString('utf8', 0, preamble.length) === preamble) {
326
+ return { ...response, body: singleChunk(body) };
327
+ }
328
+ // Inject the missing v1 preamble before the ref advertisement
329
+ return {
330
+ ...response,
331
+ body: singleChunk(Buffer.concat([Buffer.from(preamble), body])),
332
+ };
333
+ },
334
+ };
@@ -0,0 +1,78 @@
1
+ import type { AbortMergeGitParams, AddGitParams, AddRemoteGitParams, AheadBehind, BaseGitParams, CheckoutGitParams, CloneGitParams, CommitGitParams, CreateBranchGitParams, DeleteBranchGitParams, FetchGitParams, GetAheadBehindParams, GetRemoteUrlGitParams, GetTrackingBranchParams, GitBranch, GitCommit, GitConflict, GitRemote, GitStatus, IGitService, InitGitParams, ListBranchesGitParams, LogGitParams, MergeGitParams, MergeResult, PullGitParams, PullResult, PushGitParams, PushResult, RemoveRemoteGitParams, ResetGitParams, ResetResult, SetTrackingBranchParams, TrackingBranch } from '../../core/interfaces/services/i-git-service.js';
2
+ import type { IAuthStateStore } from '../../core/interfaces/state/i-auth-state-store.js';
3
+ export declare class IsomorphicGitService implements IGitService {
4
+ private readonly authStateStore;
5
+ constructor(authStateStore: IAuthStateStore);
6
+ private static isConflictError;
7
+ private static isMergeConflictData;
8
+ abortMerge(params: AbortMergeGitParams): Promise<void>;
9
+ add(params: AddGitParams): Promise<void>;
10
+ addRemote(params: AddRemoteGitParams): Promise<void>;
11
+ checkout(params: CheckoutGitParams): Promise<void>;
12
+ clone(params: CloneGitParams): Promise<void>;
13
+ commit(params: CommitGitParams): Promise<GitCommit>;
14
+ createBranch(params: CreateBranchGitParams): Promise<void>;
15
+ deleteBranch(params: DeleteBranchGitParams): Promise<void>;
16
+ fetch(params: FetchGitParams): Promise<void>;
17
+ getAheadBehind(params: GetAheadBehindParams): Promise<AheadBehind>;
18
+ getConflicts(params: BaseGitParams): Promise<GitConflict[]>;
19
+ getCurrentBranch(params: BaseGitParams): Promise<string | undefined>;
20
+ getFilesWithConflictMarkers(params: BaseGitParams): Promise<string[]>;
21
+ getRemoteUrl(params: GetRemoteUrlGitParams): Promise<string | undefined>;
22
+ getTrackingBranch(params: GetTrackingBranchParams): Promise<TrackingBranch | undefined>;
23
+ init(params: InitGitParams): Promise<void>;
24
+ isAncestor(params: BaseGitParams & {
25
+ ancestor: string;
26
+ commit: string;
27
+ }): Promise<boolean>;
28
+ isEmptyRepository(params: BaseGitParams): Promise<boolean>;
29
+ isInitialized(params: BaseGitParams): Promise<boolean>;
30
+ listBranches(params: ListBranchesGitParams): Promise<GitBranch[]>;
31
+ listRemotes(params: BaseGitParams): Promise<GitRemote[]>;
32
+ log(params: LogGitParams): Promise<GitCommit[]>;
33
+ merge(params: MergeGitParams): Promise<MergeResult>;
34
+ pull(params: PullGitParams): Promise<PullResult>;
35
+ push(params: PushGitParams): Promise<PushResult>;
36
+ removeRemote(params: RemoveRemoteGitParams): Promise<void>;
37
+ reset(params: ResetGitParams): Promise<ResetResult>;
38
+ setTrackingBranch(params: SetTrackingBranchParams): Promise<void>;
39
+ status(params: BaseGitParams): Promise<GitStatus>;
40
+ private buildBasicAuthHeaders;
41
+ private conflictsFromError;
42
+ private getAuthor;
43
+ private getOnAuth;
44
+ private getOnAuthFailure;
45
+ /**
46
+ * Guard against staged changes that would be overwritten by checkout.
47
+ * isomorphic-git's checkout only detects unstaged conflicts — it silently
48
+ * overwrites staged changes, causing data loss. This method fills that gap
49
+ * to match native git behavior.
50
+ */
51
+ private guardStagedConflicts;
52
+ /**
53
+ * Manual merge for unrelated histories (no common ancestor).
54
+ * isomorphic-git throws MergeNotSupportedError because it can't handle
55
+ * base=null at the root tree level. We bypass by combining both trees directly.
56
+ */
57
+ private mergeUnrelatedHistories;
58
+ private parseMatrix;
59
+ private readBlobOid;
60
+ private requireDirectory;
61
+ private requireToken;
62
+ /**
63
+ * Unstage files by resetting their index entries to match HEAD.
64
+ * When filePaths is omitted, unstages all staged files.
65
+ */
66
+ private resetUnstage;
67
+ /**
68
+ * Resolves a ref expression that may include ~N ancestry syntax (e.g. HEAD~2).
69
+ * Falls back to git.resolveRef for plain refs.
70
+ */
71
+ private resolveRefExpression;
72
+ /**
73
+ * Fixes conflict markers written by isomorphic-git to match native git:
74
+ * 1. Replaces `<<<<<<< <branchName>` with `<<<<<<< HEAD`
75
+ * 2. Ensures `\n` before `=======` and `>>>>>>>` (isomorphic-git omits it when content has no trailing newline)
76
+ */
77
+ private rewriteConflictMarkers;
78
+ }