@orion-agents/orion-code 0.3.66 → 0.4.4

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 (384) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +78 -361
  3. package/README.zh-CN.md +71 -262
  4. package/bin/orion +4 -1
  5. package/dist/acp/session-updates.d.ts +35 -0
  6. package/dist/acp/session-updates.js +183 -0
  7. package/dist/acp/sessions.d.ts +32 -0
  8. package/dist/acp/sessions.js +328 -0
  9. package/dist/acp/stdio.d.ts +3 -0
  10. package/dist/acp/stdio.js +59 -0
  11. package/dist/cli.js +136 -185
  12. package/dist/commands/context-tool-command-handlers.d.ts +1 -1
  13. package/dist/commands/context-tool-command-handlers.js +24 -3
  14. package/dist/commands/core-command-handlers.js +10 -18
  15. package/dist/commands/diagnostic-command-handlers.js +58 -48
  16. package/dist/commands/diagnostic-commands.js +0 -12
  17. package/dist/commands/init-command.d.ts +3 -0
  18. package/dist/commands/init-command.js +131 -0
  19. package/dist/commands/model-command-handlers.d.ts +1 -2
  20. package/dist/commands/model-command-handlers.js +15 -100
  21. package/dist/commands/model-commands.js +0 -11
  22. package/dist/commands/registry.js +1 -19
  23. package/dist/commands/rsi-command.d.ts +2 -0
  24. package/dist/commands/rsi-command.js +180 -0
  25. package/dist/commands/session-command-handlers.js +28 -19
  26. package/dist/commands/system-commands.js +0 -1
  27. package/dist/commands/target-command.js +49 -6
  28. package/dist/commands/tool-commands.js +1 -1
  29. package/dist/commands/types.d.ts +4 -10
  30. package/dist/commands/types.js +1 -21
  31. package/dist/commands/workflow-command-handlers.js +13 -4
  32. package/dist/commands/workflow-commands.js +2 -2
  33. package/dist/framework/loop-budget-contract.d.ts +2 -8
  34. package/dist/framework/loop-budget-contract.js +0 -3
  35. package/dist/framework/loop-progress.d.ts +18 -0
  36. package/dist/framework/loop-progress.js +63 -0
  37. package/dist/framework/prompt.d.ts +0 -2
  38. package/dist/framework/prompt.js +9 -27
  39. package/dist/framework/query.d.ts +26 -31
  40. package/dist/framework/query.js +451 -292
  41. package/dist/framework/store.d.ts +6 -10
  42. package/dist/framework/store.js +2 -21
  43. package/dist/framework/tool-call-orchestrator.d.ts +7 -0
  44. package/dist/framework/tool-call-orchestrator.js +8 -3
  45. package/dist/framework/tool-state.d.ts +2 -0
  46. package/dist/framework/tool.d.ts +0 -23
  47. package/dist/framework/verification-command.d.ts +15 -0
  48. package/dist/framework/verification-command.js +32 -0
  49. package/dist/harness/assembler.d.ts +1 -0
  50. package/dist/harness/assembler.js +24 -0
  51. package/dist/harness/capsule.d.ts +1 -1
  52. package/dist/harness/capsule.js +33 -14
  53. package/dist/harness/context-harness.d.ts +37 -12
  54. package/dist/harness/context-harness.js +545 -35
  55. package/dist/harness/contract.js +1 -1
  56. package/dist/harness/drift-guard.d.ts +4 -0
  57. package/dist/harness/drift-guard.js +68 -16
  58. package/dist/harness/index.d.ts +1 -1
  59. package/dist/harness/intent.js +21 -0
  60. package/dist/harness/ledger.d.ts +7 -11
  61. package/dist/harness/ledger.js +50 -9
  62. package/dist/harness/progress-controller.d.ts +12 -7
  63. package/dist/harness/progress-controller.js +96 -29
  64. package/dist/harness/state.js +10 -1
  65. package/dist/harness/stop-controller.d.ts +0 -5
  66. package/dist/harness/stop-controller.js +11 -31
  67. package/dist/harness/task-checklist.d.ts +16 -0
  68. package/dist/harness/task-checklist.js +92 -0
  69. package/dist/harness/types.d.ts +78 -1
  70. package/dist/harness/verification.d.ts +19 -1
  71. package/dist/harness/verification.js +116 -29
  72. package/dist/index.d.ts +1 -1
  73. package/dist/index.js +1 -3
  74. package/dist/print-ui/event-stream.d.ts +43 -0
  75. package/dist/print-ui/event-stream.js +204 -0
  76. package/dist/print-ui/launch.d.ts +12 -1
  77. package/dist/print-ui/launch.js +173 -11
  78. package/dist/product/environment.d.ts +1 -1
  79. package/dist/product/environment.js +1 -1
  80. package/dist/product/identity.d.ts +1 -1
  81. package/dist/product/identity.js +1 -1
  82. package/dist/product/paths.d.ts +3 -2
  83. package/dist/product/paths.js +6 -2
  84. package/dist/runtime/agent-loop.d.ts +12 -2
  85. package/dist/runtime/agent-loop.js +172 -29
  86. package/dist/runtime/agent-runtime-controller.d.ts +14 -4
  87. package/dist/runtime/agent-runtime-controller.js +366 -192
  88. package/dist/runtime/agent-runtime-protocol.d.ts +10 -18
  89. package/dist/runtime/agent-runtime-runner.d.ts +10 -0
  90. package/dist/runtime/builtin-tool-provider.js +5 -1
  91. package/dist/runtime/capability-receipt-journal.js +1 -0
  92. package/dist/runtime/durable-tool-receipt-reader.js +2 -1
  93. package/dist/runtime/first-party-tool-services.d.ts +1 -0
  94. package/dist/runtime/first-party-tool-services.js +2 -12
  95. package/dist/runtime/first-party-tool-universe.d.ts +1 -0
  96. package/dist/runtime/first-party-tool-universe.js +1 -1
  97. package/dist/runtime/followup-queue-store.d.ts +16 -0
  98. package/dist/runtime/followup-queue-store.js +75 -0
  99. package/dist/runtime/goal-lifecycle-v2.d.ts +16 -4
  100. package/dist/runtime/goal-lifecycle-v2.js +217 -39
  101. package/dist/runtime/goal-runtime-coordinator.d.ts +14 -2
  102. package/dist/runtime/goal-runtime-coordinator.js +147 -36
  103. package/dist/runtime/goals/presentation.js +3 -1
  104. package/dist/runtime/goals/types.d.ts +1 -3
  105. package/dist/runtime/goals/types.js +0 -3
  106. package/dist/runtime/loop-budget.d.ts +0 -7
  107. package/dist/runtime/loop-budget.js +8 -52
  108. package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +2 -0
  109. package/dist/runtime/mcp/first-party-mcp-adapter.js +23 -19
  110. package/dist/runtime/model-coordinator.js +2 -5
  111. package/dist/runtime/orion-runtime-v1.d.ts +18 -2
  112. package/dist/runtime/orion-runtime-v1.js +183 -46
  113. package/dist/runtime/orion-session-runner.d.ts +7 -0
  114. package/dist/runtime/orion-session-runner.js +82 -0
  115. package/dist/runtime/plan-review.d.ts +1 -0
  116. package/dist/runtime/plan-review.js +8 -4
  117. package/dist/runtime/product-bootstrap.d.ts +6 -0
  118. package/dist/runtime/product-bootstrap.js +41 -51
  119. package/dist/runtime/product-orion-runtime.js +129 -58
  120. package/dist/runtime/release-receipts.d.ts +24 -133
  121. package/dist/runtime/release-receipts.js +129 -693
  122. package/dist/runtime/rich-text/layout.js +108 -65
  123. package/dist/runtime/rsi/contracts.d.ts +50 -0
  124. package/dist/runtime/rsi/contracts.js +17 -0
  125. package/dist/runtime/rsi/diagnosis.d.ts +46 -0
  126. package/dist/runtime/rsi/diagnosis.js +98 -0
  127. package/dist/runtime/rsi/evaluation-suite.d.ts +25 -0
  128. package/dist/runtime/rsi/evaluation-suite.js +141 -0
  129. package/dist/runtime/rsi/evaluation-worker.d.ts +19 -0
  130. package/dist/runtime/rsi/evaluation-worker.js +64 -0
  131. package/dist/runtime/rsi/evaluation.d.ts +49 -0
  132. package/dist/runtime/rsi/evaluation.js +345 -0
  133. package/dist/runtime/rsi/lifecycle.d.ts +54 -0
  134. package/dist/runtime/rsi/lifecycle.js +279 -0
  135. package/dist/runtime/rsi/proposal.d.ts +39 -0
  136. package/dist/runtime/rsi/proposal.js +312 -0
  137. package/dist/runtime/rsi/receipt.d.ts +28 -0
  138. package/dist/runtime/rsi/receipt.js +138 -0
  139. package/dist/runtime/rsi/skill-state.d.ts +7 -0
  140. package/dist/runtime/rsi/skill-state.js +50 -0
  141. package/dist/runtime/rsi/trajectory.d.ts +19 -0
  142. package/dist/runtime/rsi/trajectory.js +314 -0
  143. package/dist/runtime/rsi/triage.d.ts +274 -0
  144. package/dist/runtime/rsi/triage.js +58 -0
  145. package/dist/runtime/session-composer-control.d.ts +5 -24
  146. package/dist/runtime/session-composer-control.js +27 -189
  147. package/dist/runtime/step-snapshot.d.ts +4 -1
  148. package/dist/runtime/step-snapshot.js +11 -1
  149. package/dist/runtime/subagent-thread-runtime.js +27 -5
  150. package/dist/runtime/subagents/policy.js +0 -1
  151. package/dist/runtime/subagents/production.js +1 -5
  152. package/dist/runtime/subagents/runtime-integration.js +2 -4
  153. package/dist/runtime/subagents/types.d.ts +0 -5
  154. package/dist/runtime/subagents/types.js +0 -2
  155. package/dist/runtime/task-context-recovery.d.ts +55 -0
  156. package/dist/runtime/task-context-recovery.js +349 -0
  157. package/dist/runtime/task-context-service.d.ts +20 -10
  158. package/dist/runtime/task-context-service.js +69 -9
  159. package/dist/runtime/thread-admission.d.ts +3 -1
  160. package/dist/runtime/thread-admission.js +21 -7
  161. package/dist/runtime/thread-event-store.d.ts +2 -2
  162. package/dist/runtime/thread-event-store.js +7 -2
  163. package/dist/runtime/thread-projection.js +4 -2
  164. package/dist/runtime/thread-runtime.d.ts +10 -0
  165. package/dist/runtime/thread-runtime.js +85 -3
  166. package/dist/runtime/thread-session-index.d.ts +8 -0
  167. package/dist/runtime/thread-session-index.js +50 -1
  168. package/dist/runtime/thread-session-view.d.ts +2 -1
  169. package/dist/runtime/thread-session-view.js +4 -0
  170. package/dist/runtime/thread-tool-journal.d.ts +1 -0
  171. package/dist/runtime/thread-tool-journal.js +6 -2
  172. package/dist/runtime/thread-ui-adapter.d.ts +1 -0
  173. package/dist/runtime/thread-ui-adapter.js +89 -22
  174. package/dist/runtime/tool-gateway.d.ts +9 -0
  175. package/dist/runtime/tool-gateway.js +24 -0
  176. package/dist/runtime/tool-receipt-validator.js +4 -0
  177. package/dist/runtime/tool-transcript-entry.d.ts +16 -0
  178. package/dist/runtime/tool-transcript-entry.js +73 -0
  179. package/dist/runtime/turn-commit.d.ts +4 -1
  180. package/dist/runtime/turn-commit.js +19 -15
  181. package/dist/runtime/ui-events.d.ts +15 -1
  182. package/dist/runtime/ui-view-model.d.ts +6 -5
  183. package/dist/runtime/ui-view-model.js +78 -61
  184. package/dist/runtime/workspace-runtime-kernel.js +0 -1
  185. package/dist/runtime/workspace-verification.d.ts +7 -0
  186. package/dist/runtime/workspace-verification.js +83 -0
  187. package/dist/services/atomic-write.d.ts +2 -0
  188. package/dist/services/atomic-write.js +12 -1
  189. package/dist/services/code-review/format.d.ts +4 -1
  190. package/dist/services/code-review/format.js +5 -1
  191. package/dist/services/code-review/runner.d.ts +2 -2
  192. package/dist/services/code-review/runner.js +86 -64
  193. package/dist/services/code-review/snapshot.d.ts +9 -9
  194. package/dist/services/code-review/snapshot.js +182 -166
  195. package/dist/services/compact/auto-compact.d.ts +21 -6
  196. package/dist/services/compact/auto-compact.js +148 -22
  197. package/dist/services/compact/background-candidate.d.ts +33 -0
  198. package/dist/services/compact/background-candidate.js +184 -0
  199. package/dist/services/compact/compact.d.ts +4 -1
  200. package/dist/services/compact/compact.js +30 -3
  201. package/dist/services/compact/coordinator.d.ts +10 -4
  202. package/dist/services/compact/coordinator.js +17 -7
  203. package/dist/services/compact/summary-generator.d.ts +4 -2
  204. package/dist/services/compact/summary-generator.js +17 -3
  205. package/dist/services/config.d.ts +5 -5
  206. package/dist/services/config.js +29 -48
  207. package/dist/services/doctor.js +85 -13
  208. package/dist/services/effort.d.ts +5 -5
  209. package/dist/services/effort.js +5 -11
  210. package/dist/services/file-lock.d.ts +9 -3
  211. package/dist/services/file-lock.js +92 -26
  212. package/dist/services/global-config.d.ts +26 -64
  213. package/dist/services/global-config.js +233 -193
  214. package/dist/services/llm.d.ts +42 -4
  215. package/dist/services/llm.js +177 -45
  216. package/dist/services/model-client-pool.d.ts +15 -9
  217. package/dist/services/model-client-pool.js +62 -33
  218. package/dist/services/model-context.d.ts +2 -1
  219. package/dist/services/model-context.js +15 -9
  220. package/dist/services/model-registry.d.ts +4 -15
  221. package/dist/services/model-registry.js +32 -101
  222. package/dist/services/provider-diagnostics.d.ts +8 -0
  223. package/dist/services/provider-diagnostics.js +17 -12
  224. package/dist/services/provider-resilience/coordinator.d.ts +1 -1
  225. package/dist/services/provider-resilience/coordinator.js +10 -6
  226. package/dist/services/provider-resilience/request-gate.d.ts +3 -0
  227. package/dist/services/provider-resilience/request-gate.js +29 -18
  228. package/dist/services/provider-resilience/types.d.ts +2 -0
  229. package/dist/services/session-storage.d.ts +7 -10
  230. package/dist/services/session-storage.js +57 -30
  231. package/dist/services/settings-coordinator.d.ts +0 -6
  232. package/dist/services/settings-coordinator.js +19 -56
  233. package/dist/services/settings-document-repository.d.ts +3 -10
  234. package/dist/services/settings-document-repository.js +7 -85
  235. package/dist/services/usage-state.d.ts +3 -3
  236. package/dist/services/usage-state.js +11 -42
  237. package/dist/terminal-ui/answer-format.d.ts +14 -0
  238. package/dist/terminal-ui/answer-format.js +119 -0
  239. package/dist/terminal-ui/launch.d.ts +7 -6
  240. package/dist/terminal-ui/launch.js +160 -70
  241. package/dist/terminal-ui/output-queue.d.ts +2 -1
  242. package/dist/terminal-ui/output-queue.js +1 -1
  243. package/dist/terminal-ui/raw-editor.d.ts +2 -1
  244. package/dist/terminal-ui/raw-editor.js +56 -15
  245. package/dist/tools/core/edit-file.js +6 -2
  246. package/dist/tools/core/write-file.js +9 -2
  247. package/dist/tools/lsp.d.ts +16 -1
  248. package/dist/tools/lsp.js +60 -19
  249. package/dist/tools/sandbox.d.ts +1 -1
  250. package/dist/tools/sandbox.js +3 -16
  251. package/dist/tools/todo.d.ts +4 -2
  252. package/dist/tools/todo.js +91 -30
  253. package/dist/tui-core/input-parser.d.ts +1 -0
  254. package/dist/tui-core/input-parser.js +6 -0
  255. package/dist/tui-core/style.d.ts +1 -8
  256. package/dist/tui-core/style.js +3 -110
  257. package/dist/tui-ui/chrome-view-model.d.ts +1 -1
  258. package/dist/tui-ui/chrome-view-model.js +36 -32
  259. package/dist/tui-ui/launch.js +14 -14
  260. package/dist/tui-ui/layout.d.ts +5 -7
  261. package/dist/tui-ui/layout.js +129 -124
  262. package/dist/tui-ui/runner.d.ts +11 -12
  263. package/dist/tui-ui/runner.js +88 -67
  264. package/dist/tui-ui/state.d.ts +0 -11
  265. package/dist/tui-ui/state.js +22 -33
  266. package/dist/tui-ui/terminal-image.js +22 -4
  267. package/dist/tui-ui/transcript-inspector-layout.js +6 -3
  268. package/dist/tui-ui/transcript-inspector.d.ts +1 -0
  269. package/dist/tui-ui/transcript-inspector.js +7 -1
  270. package/dist/tui-ui/transcript-layout.js +42 -6
  271. package/dist/utils/terminal-text.d.ts +11 -0
  272. package/dist/utils/terminal-text.js +114 -0
  273. package/docs/cli-guide.md +575 -0
  274. package/docs/orion.example.yaml +43 -0
  275. package/docs/readme.md +12 -57
  276. package/npm-shrinkwrap.json +484 -1855
  277. package/package.json +13 -63
  278. package/dist/migration/command.d.ts +0 -9
  279. package/dist/migration/command.js +0 -100
  280. package/dist/migration/index.d.ts +0 -7
  281. package/dist/migration/index.js +0 -14
  282. package/dist/migration/migrate.d.ts +0 -19
  283. package/dist/migration/migrate.js +0 -406
  284. package/dist/migration/types.d.ts +0 -55
  285. package/dist/migration/types.js +0 -6
  286. package/dist/services/tool-allowlist.d.ts +0 -110
  287. package/dist/services/tool-allowlist.js +0 -299
  288. package/dist/services/yaml-config.d.ts +0 -57
  289. package/dist/services/yaml-config.js +0 -178
  290. package/dist/web/cli-options.d.ts +0 -17
  291. package/dist/web/cli-options.js +0 -51
  292. package/dist/web/code-review-run-service.d.ts +0 -68
  293. package/dist/web/code-review-run-service.js +0 -228
  294. package/dist/web/context-text.d.ts +0 -17
  295. package/dist/web/context-text.js +0 -40
  296. package/dist/web/errors.d.ts +0 -6
  297. package/dist/web/errors.js +0 -13
  298. package/dist/web/event-hub.d.ts +0 -45
  299. package/dist/web/event-hub.js +0 -370
  300. package/dist/web/file-read-service.d.ts +0 -101
  301. package/dist/web/file-read-service.js +0 -593
  302. package/dist/web/file-write-service.d.ts +0 -16
  303. package/dist/web/file-write-service.js +0 -103
  304. package/dist/web/git-compare-service.d.ts +0 -45
  305. package/dist/web/git-compare-service.js +0 -160
  306. package/dist/web/git-diff-document.d.ts +0 -102
  307. package/dist/web/git-diff-document.js +0 -258
  308. package/dist/web/git-file-source.d.ts +0 -25
  309. package/dist/web/git-file-source.js +0 -21
  310. package/dist/web/git-history-service.d.ts +0 -151
  311. package/dist/web/git-history-service.js +0 -619
  312. package/dist/web/git-index-transaction.d.ts +0 -45
  313. package/dist/web/git-index-transaction.js +0 -174
  314. package/dist/web/git-patch-builder.d.ts +0 -30
  315. package/dist/web/git-patch-builder.js +0 -138
  316. package/dist/web/git-read-model-service.d.ts +0 -452
  317. package/dist/web/git-read-model-service.js +0 -1833
  318. package/dist/web/git-version-service.d.ts +0 -79
  319. package/dist/web/git-version-service.js +0 -279
  320. package/dist/web/host-daemon.d.ts +0 -70
  321. package/dist/web/host-daemon.js +0 -237
  322. package/dist/web/index.d.ts +0 -6
  323. package/dist/web/index.js +0 -28
  324. package/dist/web/launch.d.ts +0 -12
  325. package/dist/web/launch.js +0 -89
  326. package/dist/web/native-directory-picker.d.ts +0 -63
  327. package/dist/web/native-directory-picker.js +0 -169
  328. package/dist/web/protocol.d.ts +0 -705
  329. package/dist/web/protocol.js +0 -639
  330. package/dist/web/review-service.d.ts +0 -22
  331. package/dist/web/review-service.js +0 -68
  332. package/dist/web/server.d.ts +0 -20
  333. package/dist/web/server.js +0 -1453
  334. package/dist/web/session-runtime-registry.d.ts +0 -138
  335. package/dist/web/session-runtime-registry.js +0 -471
  336. package/dist/web/terminal-manager.d.ts +0 -156
  337. package/dist/web/terminal-manager.js +0 -779
  338. package/dist/web/terminal-server.d.ts +0 -8
  339. package/dist/web/terminal-server.js +0 -304
  340. package/dist/web/workbench-controller.d.ts +0 -395
  341. package/dist/web/workbench-controller.js +0 -3077
  342. package/dist/web/workspace-discovery.d.ts +0 -92
  343. package/dist/web/workspace-discovery.js +0 -324
  344. package/dist/web/workspace-mutation-arbiter.d.ts +0 -54
  345. package/dist/web/workspace-mutation-arbiter.js +0 -267
  346. package/dist/web/workspace-open-telemetry.d.ts +0 -55
  347. package/dist/web/workspace-open-telemetry.js +0 -73
  348. package/dist/web-client/assets/FilesPanel-CPDovK_K.js +0 -1
  349. package/dist/web-client/assets/GitPanel-DtU_TD61.js +0 -4
  350. package/dist/web-client/assets/ReviewPanel-vMO7BEA3.js +0 -6
  351. package/dist/web-client/assets/TerminalPanel-C9vDTAlS.js +0 -23
  352. package/dist/web-client/assets/TerminalPanel-DLuoa74B.css +0 -1
  353. package/dist/web-client/assets/index-CABdwh4l.css +0 -1
  354. package/dist/web-client/assets/index-KvshfEbl.js +0 -20
  355. package/dist/web-client/assets/useAutoNotice-IE1g2wcb.js +0 -1
  356. package/dist/web-client/favicon.svg +0 -9
  357. package/dist/web-client/index.html +0 -17
  358. package/docs/architecture/agent-mode-permission-contract.md +0 -87
  359. package/docs/architecture/v0.3.0-web-api.yaml +0 -1340
  360. package/docs/architecture/v0.3.1-web-api.yaml +0 -2338
  361. package/docs/architecture/v0.3.2-web-api.yaml +0 -3029
  362. package/docs/architecture/v0.3.3-web-api.yaml +0 -3205
  363. package/docs/architecture/v0.3.4-stabilization-contract.md +0 -32
  364. package/docs/migration/v0.1.9-to-v0.2.0.md +0 -98
  365. package/docs/migration/v0.2.2-to-v0.3.0-settings.md +0 -114
  366. package/docs/migration/v0.2.2-to-v0.3.0.md +0 -55
  367. package/docs/migration/v0.3.0-to-v0.3.1.md +0 -88
  368. package/docs/migration/v0.3.1-to-v0.3.2.md +0 -94
  369. package/docs/migration/v0.3.2-to-v0.3.3.md +0 -62
  370. package/docs/migration/v0.3.3-to-v0.3.4.md +0 -36
  371. package/docs/orion.example.json +0 -86
  372. package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +0 -1234
  373. package/docs/plan/v0.2.0-release-checklist.md +0 -91
  374. package/docs/plan/v0.3.0-node-runtime-compatibility-plan.md +0 -57
  375. package/docs/plan/v0.3.0-settings-integration-plan.md +0 -740
  376. package/docs/plan/v0.3.0-web-workbench-plan.md +0 -376
  377. package/docs/plan/v0.3.1-web-workbench-professional-shell-plan.md +0 -848
  378. package/docs/plan/v0.3.2-web-workbench-layout-and-composer-plan.md +0 -869
  379. package/docs/plan/v0.3.3-plan.md +0 -1113
  380. package/docs/plan/v0.3.4-stabilization-plan.md +0 -89
  381. package/docs/test/v0.3.1-web-workbench-e2e-plan.md +0 -140
  382. package/docs/test/v0.3.2-web-workbench-e2e-plan.md +0 -100
  383. package/docs/test/v0.3.3-web-workbench-e2e-plan.md +0 -79
  384. package/docs/test/v0.3.4-stabilization-e2e-plan.md +0 -54
@@ -1,619 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GIT_EMPTY_TREE_OID = void 0;
4
- exports.createGitHistoryReader = createGitHistoryReader;
5
- /**
6
- * v0.3.17 S4 — history reading: refs, commit details, commit file lists, search, file history.
7
- *
8
- * Split out of the read model service on purpose (plan §8.2 "读模型服务及拆分服务"): this
9
- * module owns *metadata* about immutable objects, while the service keeps owning the bounded
10
- * diff stream. Nothing here writes to the working tree or the index, which is what the §10
11
- * S4 exit evidence asks for ("无工作区写入的历史浏览").
12
- *
13
- * Correctness rules this module is responsible for (plan G4):
14
- * - a normal commit is compared with its parent; a **root** commit is compared with the
15
- * empty tree instead of failing;
16
- * - a **merge** commit defaults to its first parent, is explicitly marked as a merge, and
17
- * lets the caller pick a different parent;
18
- * - the *commit set* of a two-dot range and the *tree difference* of two commits are
19
- * different things and are never conflated: the commit list comes from `git log`, the
20
- * file list from a tree diff;
21
- * - search runs on the Host across the whole reachable history, never over a rendered page;
22
- * - a pagination cursor is bound to the frozen tip OID **and** a fingerprint of the query,
23
- * so a moved ref invalidates it instead of silently returning a different result set.
24
- */
25
- const crypto_1 = require("crypto");
26
- const redaction_1 = require("../services/redaction");
27
- const errors_1 = require("./errors");
28
- /** `git hash-object -t tree /dev/null` — the canonical empty tree, used for root commits. */
29
- exports.GIT_EMPTY_TREE_OID = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
30
- const REF_LIMIT = 400;
31
- const COMMIT_FILE_LIMIT = 2000;
32
- const SEARCH_PAGE_DEFAULT = 30;
33
- const SEARCH_PAGE_MAX = 100;
34
- const FILE_HISTORY_LIMIT = 200;
35
- const RECORD_SEPARATOR = '\x1e';
36
- const FIELD_SEPARATOR = '\x1f';
37
- /** Metadata half of the list format; `%b` is fetched separately so a body can never be
38
- * mistaken for a separator. */
39
- const LIST_FORMAT = ['%H', '%h', '%ct', '%an', '%s', '%P', '%D'].join(FIELD_SEPARATOR);
40
- function bounded(value, fallback, min, max, name) {
41
- if (value === undefined)
42
- return fallback;
43
- if (!Number.isInteger(value) || value < min || value > max) {
44
- throw new errors_1.WebWorkbenchError(400, `${name} must be an integer from ${min} to ${max}.`);
45
- }
46
- return value;
47
- }
48
- function assertOid(value, name = 'oid') {
49
- // Full or abbreviated SHA-1/SHA-256 hex. Anything else would be passed to git as a
50
- // revision expression, which is exactly the injection surface we refuse.
51
- if (typeof value !== 'string' || !/^[0-9a-f]{4,64}$/iu.test(value)) {
52
- throw new errors_1.WebWorkbenchError(400, `${name} must be a commit hash.`, 'git_revision_invalid');
53
- }
54
- return value;
55
- }
56
- function assertSafeRelativePath(path) {
57
- if (typeof path !== 'string' || !path || path.length > 1024) {
58
- throw new errors_1.WebWorkbenchError(400, 'A file path is required.', 'git_path_invalid');
59
- }
60
- if (path.startsWith('/') || path.includes('\0')) {
61
- throw new errors_1.WebWorkbenchError(400, 'Unsafe Git path.', 'git_path_unsafe');
62
- }
63
- const segments = path.split('/');
64
- if (segments.some(segment => segment === '..' || segment === '.' || segment === '')) {
65
- throw new errors_1.WebWorkbenchError(400, 'Unsafe Git path.', 'git_path_unsafe');
66
- }
67
- return path;
68
- }
69
- /** Bounded, literal-safe search text. Refused rather than escaped so nothing reaches argv. */
70
- function assertSearchText(value, name) {
71
- if (value === undefined)
72
- return undefined;
73
- const trimmed = value.trim();
74
- if (!trimmed)
75
- return undefined;
76
- if (trimmed.length > 200 || /[\0-\x1f\x7f]/u.test(trimmed)) {
77
- throw new errors_1.WebWorkbenchError(400, `${name} is not a valid search term.`, 'git_query_invalid');
78
- }
79
- return trimmed;
80
- }
81
- function refKind(name) {
82
- if (name.startsWith('refs/heads/'))
83
- return 'branch';
84
- if (name.startsWith('refs/tags/'))
85
- return 'tag';
86
- if (name.startsWith('refs/remotes/'))
87
- return 'remote';
88
- return 'other';
89
- }
90
- function shortRefName(name) {
91
- for (const prefix of ['refs/heads/', 'refs/tags/', 'refs/remotes/']) {
92
- if (name.startsWith(prefix))
93
- return name.slice(prefix.length);
94
- }
95
- return name;
96
- }
97
- function parseSummaryRecord(record) {
98
- const fields = record.replace(/^\s+/u, '').split(FIELD_SEPARATOR);
99
- if (fields.length < 7)
100
- return null;
101
- const [id, shortId, committedSeconds, authorName, subject, parents, decoration] = fields;
102
- if (!/^[0-9a-f]{7,64}$/iu.test(id))
103
- return null;
104
- const parentList = parents
105
- .split(' ')
106
- .map(value => value.trim())
107
- .filter(Boolean);
108
- return Object.freeze({
109
- id,
110
- shortId,
111
- subject,
112
- authorName,
113
- // `%ct` is seconds; the protocol exposes ISO so the client never re-implements time.
114
- authoredAt: new Date(Number(committedSeconds) * 1000).toISOString(),
115
- parents: Object.freeze(parentList),
116
- isMerge: parentList.length > 1,
117
- decoration: Object.freeze(decoration
118
- .split(',')
119
- .map(value => value.trim())
120
- .filter(Boolean)),
121
- });
122
- }
123
- function parseSummaryPage(raw) {
124
- return raw
125
- .split(RECORD_SEPARATOR)
126
- .map(record => record.replace(/\s+$/u, ''))
127
- .filter(Boolean)
128
- .map(parseSummaryRecord)
129
- .filter((item) => item !== null);
130
- }
131
- /** One `--numstat -z` record: `added\tdeleted\t path`, or a rename with an empty path field
132
- * followed by the old and new names as their own NUL-terminated fields. */
133
- function parseNumstat(raw) {
134
- const fields = raw.split('\0');
135
- const files = [];
136
- let index = 0;
137
- while (index < fields.length) {
138
- const record = fields[index];
139
- index += 1;
140
- if (!record)
141
- continue;
142
- const [added, deleted, inlinePath] = record.split('\t');
143
- let path = inlinePath ?? '';
144
- let renamedFrom = null;
145
- if (path === '' && index + 1 < fields.length) {
146
- // Rename: the following two fields are the old and the new path.
147
- renamedFrom = fields[index];
148
- path = fields[index + 1];
149
- index += 2;
150
- }
151
- if (!path)
152
- continue;
153
- const binary = added === '-' || deleted === '-';
154
- files.push(Object.freeze({
155
- path,
156
- renamedFrom: renamedFrom || null,
157
- additions: binary ? 0 : Number(added) || 0,
158
- deletions: binary ? 0 : Number(deleted) || 0,
159
- binary,
160
- sensitive: (0, redaction_1.isSensitiveFilePath)(path),
161
- }));
162
- if (files.length >= COMMIT_FILE_LIMIT)
163
- break;
164
- }
165
- return files;
166
- }
167
- function queryFingerprint(query) {
168
- return (0, crypto_1.createHash)('sha256')
169
- .update(JSON.stringify({
170
- message: query.message ?? null,
171
- author: query.author ?? null,
172
- sha: query.sha ?? null,
173
- path: query.path ?? null,
174
- since: query.since ?? null,
175
- until: query.until ?? null,
176
- rev: query.rev ?? null,
177
- }))
178
- .digest('hex')
179
- .slice(0, 16);
180
- }
181
- function createGitHistoryReader(options) {
182
- const { runGit, requireRoot, revision } = options;
183
- /** Resolves a commit to a base tree SHA and a human label for the comparison. */
184
- const resolveBase = async (oid, parentIndex) => {
185
- const parentRaw = (await runGit(['rev-list', '--parents', '-n', '1', oid])).trim();
186
- const parents = parentRaw.split(' ').slice(1).filter(Boolean);
187
- if (parents.length === 0) {
188
- // A root commit has no parent, so the honest comparison is against the empty tree.
189
- return { baseOid: exports.GIT_EMPTY_TREE_OID, baseLabel: '空树(根提交)' };
190
- }
191
- const chosen = parents[Math.min(parentIndex, parents.length - 1)];
192
- return {
193
- baseOid: chosen,
194
- baseLabel: parents.length > 1 ? `父提交 ${parentIndex + 1}/${parents.length}` : '父提交',
195
- };
196
- };
197
- return {
198
- async refs() {
199
- await requireRoot();
200
- const head = (await runGit(['rev-parse', '--verify', '--quiet', 'HEAD']).catch(() => ''))
201
- .toString()
202
- .trim();
203
- // Detached is defined by HEAD being a raw oid rather than a symbolic ref, NOT by
204
- // "no ref points at this oid". Detaching onto a commit that a branch also points at is
205
- // the common case, and the earlier oid-comparison heuristic misreported it as attached.
206
- const symbolicHead = (await runGit(['symbolic-ref', '--quiet', 'HEAD']).catch(() => ''))
207
- .toString()
208
- .trim();
209
- // `for-each-ref` does NOT understand the `%x1f` hex escapes that `git log --format`
210
- // supports — it prints them literally, which silently produced an empty ref list until
211
- // this was caught against real Git. A space is the safe separator here because
212
- // `git check-ref-format` forbids spaces in ref names, and records are newline-delimited.
213
- const raw = await runGit([
214
- 'for-each-ref',
215
- `--count=${REF_LIMIT + 1}`,
216
- '--format=%(refname) %(objectname)',
217
- 'refs/heads',
218
- 'refs/tags',
219
- 'refs/remotes',
220
- ]);
221
- // An explicit loop rather than a map/filter chain: the intermediate shapes (including
222
- // the "skip this record" case) stay visible and typed.
223
- const collected = [];
224
- for (const record of raw.split('\n')) {
225
- const trimmed = record.trim();
226
- if (!trimmed)
227
- continue;
228
- const separator = trimmed.indexOf(' ');
229
- if (separator <= 0)
230
- continue;
231
- const name = trimmed.slice(0, separator);
232
- const oid = trimmed.slice(separator + 1).trim();
233
- collected.push(Object.freeze({
234
- name,
235
- shortName: shortRefName(name),
236
- kind: refKind(name),
237
- oid,
238
- isHead: Boolean(symbolicHead) && name === symbolicHead,
239
- }));
240
- }
241
- collected.sort((left, right) => {
242
- const order = ['branch', 'tag', 'remote', 'other'];
243
- const byKind = order.indexOf(left.kind) - order.indexOf(right.kind);
244
- // Stable inside a kind so the list does not reshuffle between reads.
245
- return byKind !== 0 ? byKind : left.shortName.localeCompare(right.shortName);
246
- });
247
- return Object.freeze({
248
- refs: Object.freeze(collected.slice(0, REF_LIMIT)),
249
- head: head || null,
250
- detached: Boolean(head) && !symbolicHead,
251
- truncated: collected.length > REF_LIMIT,
252
- });
253
- },
254
- async commit(oid, parentIndex = 0) {
255
- const revisionOid = assertOid(oid);
256
- await requireRoot();
257
- if (!Number.isInteger(parentIndex) || parentIndex < 0 || parentIndex > 63) {
258
- throw new errors_1.WebWorkbenchError(400, 'parentIndex is out of range.', 'git_query_invalid');
259
- }
260
- const summaryRaw = await runGit([
261
- 'log',
262
- '-1',
263
- `--format=${LIST_FORMAT}${RECORD_SEPARATOR}`,
264
- revisionOid,
265
- '--',
266
- ]);
267
- const [summary] = parseSummaryPage(summaryRaw);
268
- if (!summary) {
269
- throw new errors_1.WebWorkbenchError(404, 'Commit was not found.', 'git_revision_not_found');
270
- }
271
- if (parentIndex >= Math.max(1, summary.parents.length)) {
272
- throw new errors_1.WebWorkbenchError(400, 'parentIndex exceeds the number of parents.', 'git_query_invalid');
273
- }
274
- // The body is a separate call: a commit message may contain any byte, including the
275
- // separators the list format relies on.
276
- const message = await runGit(['log', '-1', '--format=%B', summary.id]);
277
- const committerRaw = (await runGit([
278
- 'log',
279
- '-1',
280
- `--format=%cn${FIELD_SEPARATOR}%ce${FIELD_SEPARATOR}%cI`,
281
- summary.id,
282
- ])).trim();
283
- const [committerName, authorEmail, committedAt] = committerRaw.split(FIELD_SEPARATOR);
284
- const base = await resolveBase(summary.id, parentIndex);
285
- return Object.freeze({
286
- ...summary,
287
- message: message.replace(/\s+$/u, ''),
288
- committerName: committerName ?? '',
289
- authorEmail: authorEmail ?? '',
290
- committedAt: committedAt ?? summary.authoredAt,
291
- baseOid: base.baseOid,
292
- baseLabel: base.baseLabel,
293
- parentIndex,
294
- });
295
- },
296
- async commitFiles(oid, parentIndex = 0) {
297
- const detail = await this.commit(oid, parentIndex);
298
- const raw = await runGit([
299
- 'diff',
300
- '--numstat',
301
- '-z',
302
- '--no-ext-diff',
303
- '--no-textconv',
304
- detail.baseOid,
305
- detail.id,
306
- ]);
307
- const files = parseNumstat(raw);
308
- let additions = 0;
309
- let deletions = 0;
310
- for (const file of files) {
311
- additions += file.additions;
312
- deletions += file.deletions;
313
- }
314
- return Object.freeze({
315
- commitSha: detail.id,
316
- baseOid: detail.baseOid,
317
- baseLabel: detail.baseLabel,
318
- files: Object.freeze(files),
319
- additions,
320
- deletions,
321
- truncated: files.length >= COMMIT_FILE_LIMIT,
322
- });
323
- },
324
- async history(query) {
325
- const root = await requireRoot();
326
- void root;
327
- const pageSize = bounded(query.pageSize, SEARCH_PAGE_DEFAULT, 1, SEARCH_PAGE_MAX, 'pageSize');
328
- const message = assertSearchText(query.message, 'message');
329
- const author = assertSearchText(query.author, 'author');
330
- const sha = query.sha ? assertOid(query.sha, 'sha') : undefined;
331
- const path = query.path ? assertSafeRelativePath(query.path) : undefined;
332
- const since = assertSearchText(query.since, 'since');
333
- const until = assertSearchText(query.until, 'until');
334
- const rev = query.rev ? assertSearchText(query.rev, 'rev') : undefined;
335
- const tip = (await runGit(['rev-parse', '--verify', '--quiet', rev ?? 'HEAD']).catch(() => ''))
336
- .toString()
337
- .trim();
338
- if (!tip) {
339
- // A repository without commits is an empty history, not an error (plan G4).
340
- return Object.freeze({
341
- items: Object.freeze([]),
342
- nextCursor: null,
343
- tipOid: null,
344
- truncated: false,
345
- });
346
- }
347
- const normalized = {
348
- ...(message ? { message } : {}),
349
- ...(author ? { author } : {}),
350
- ...(sha ? { sha } : {}),
351
- ...(path ? { path } : {}),
352
- ...(since ? { since } : {}),
353
- ...(until ? { until } : {}),
354
- ...(rev ? { rev } : {}),
355
- };
356
- const scopeRevision = await revision();
357
- const fingerprint = queryFingerprint(normalized);
358
- // A SHA is a direct lookup, not a text filter: `git log` cannot filter by object id, and
359
- // faking it with a range expression would silently conflate "the commit set of a range"
360
- // with "one commit" (plan G4). So a SHA query resolves the object, checks it is reachable
361
- // from the current rev, and answers with zero or one item. The other text filters are
362
- // deliberately NOT combined with it, and the API documents that.
363
- if (sha) {
364
- const resolved = (await runGit(['rev-parse', '--verify', '--quiet', `${sha}^{commit}`]).catch(() => ''))
365
- .toString()
366
- .trim();
367
- if (!resolved) {
368
- return Object.freeze({
369
- items: Object.freeze([]),
370
- nextCursor: null,
371
- tipOid: tip,
372
- truncated: false,
373
- });
374
- }
375
- const reachable = await runGit(['merge-base', '--is-ancestor', resolved, tip])
376
- .then(() => true)
377
- // `--is-ancestor` exits 1 for "not an ancestor", which is a normal answer.
378
- .catch(() => false);
379
- if (!reachable) {
380
- return Object.freeze({
381
- items: Object.freeze([]),
382
- nextCursor: null,
383
- tipOid: tip,
384
- truncated: false,
385
- });
386
- }
387
- const single = parseSummaryPage(await runGit(['log', '-1', `--format=${LIST_FORMAT}${RECORD_SEPARATOR}`, resolved, '--']));
388
- return Object.freeze({
389
- items: Object.freeze(single.slice(0, 1)),
390
- nextCursor: null,
391
- tipOid: tip,
392
- truncated: false,
393
- });
394
- }
395
- const offset = query.cursor
396
- ? decodeSearchCursor(query.cursor, { tipOid: tip, revision: scopeRevision, fingerprint })
397
- : 0;
398
- const args = [
399
- 'log',
400
- `--skip=${offset}`,
401
- `--max-count=${pageSize + 1}`,
402
- `--format=${LIST_FORMAT}${RECORD_SEPARATOR}`,
403
- ];
404
- if (message)
405
- args.push(`--grep=${message}`, '--regexp-ignore-case');
406
- if (author)
407
- args.push(`--author=${author}`, '--regexp-ignore-case');
408
- if (since)
409
- args.push(`--since=${since}`);
410
- if (until)
411
- args.push(`--until=${until}`);
412
- // `--full-history` so a path filter does not silently drop merges and simplified side
413
- // branches; the tree difference is reported separately from the commit set (plan G4).
414
- if (path)
415
- args.push('--full-history');
416
- args.push(tip);
417
- if (path)
418
- args.push('--', path);
419
- const raw = await runGit(args);
420
- const all = parseSummaryPage(raw);
421
- const hasMore = all.length > pageSize;
422
- const items = all.slice(0, pageSize);
423
- return Object.freeze({
424
- items: Object.freeze(items),
425
- nextCursor: hasMore
426
- ? encodeSearchCursor({
427
- tipOid: tip,
428
- revision: scopeRevision,
429
- fingerprint,
430
- offset: offset + items.length,
431
- })
432
- : null,
433
- tipOid: tip,
434
- truncated: hasMore,
435
- });
436
- },
437
- async graph(input) {
438
- const limit = bounded(input.limit, 200, 1, 2000, 'limit');
439
- await requireRoot();
440
- // The graph columns are taken verbatim from git rather than recomputed: a hand-rolled
441
- // renderer would be a second implementation of lane assignment, and it would disagree
442
- // with `git log --graph` in exactly the merge cases that matter.
443
- const raw = await runGit([
444
- 'log',
445
- '--graph',
446
- `--max-count=${limit + 1}`,
447
- '--date-order',
448
- '--format=%x1f%H%x1f%h%x1f%s',
449
- ]).catch(() => '');
450
- const rows = [];
451
- for (const line of raw.split('\n')) {
452
- if (!line.trim())
453
- continue;
454
- const separator = line.indexOf('\x1f');
455
- if (separator < 0) {
456
- rows.push(Object.freeze({ graph: line, id: null, shortId: null, subject: '' }));
457
- continue;
458
- }
459
- const graph = line.slice(0, separator);
460
- const fields = line.slice(separator + 1).split('\x1f');
461
- rows.push(Object.freeze({
462
- graph,
463
- id: fields[0] || null,
464
- shortId: fields[1] || null,
465
- subject: fields[2] ?? '',
466
- }));
467
- }
468
- const truncated = rows.length > limit;
469
- return Object.freeze({ rows: Object.freeze(rows.slice(0, limit)), truncated });
470
- },
471
- async blame(input) {
472
- const path = assertSafeRelativePath(input.path);
473
- const limit = bounded(input.limit, 2000, 1, 5000, 'limit');
474
- await requireRoot();
475
- const rev = input.rev ? assertSearchText(input.rev, 'rev') : undefined;
476
- const target = rev ?? null;
477
- const tracked = (await runGit(['rev-parse', '--verify', '--quiet', rev ?? 'HEAD']).catch(() => ''))
478
- .toString()
479
- .trim();
480
- if (!tracked) {
481
- return Object.freeze({
482
- path,
483
- rev: rev ?? null,
484
- lines: Object.freeze([]),
485
- truncated: false,
486
- });
487
- }
488
- // `--porcelain` is machine-readable and stable; the date stays ISO so the client never
489
- // re-implements time. Uncommitted lines show as boundary/not-committed metadata.
490
- const raw = await runGit(['blame', '--porcelain', ...(target ? [target] : []), '--', path]);
491
- const commits = new Map();
492
- const lines = [];
493
- let currentOid = null;
494
- let boundary = false;
495
- let pendingAuthor = '';
496
- let pendingTime = '';
497
- let pendingSummary = '';
498
- let lineNumber = 0;
499
- for (const line of raw.split('\n')) {
500
- if (line.startsWith('\t')) {
501
- if (!currentOid)
502
- continue;
503
- lineNumber += 1;
504
- if (lineNumber > limit)
505
- break;
506
- const known = commits.get(currentOid);
507
- lines.push(Object.freeze({
508
- lineNumber,
509
- commitShort: currentOid.slice(0, 10),
510
- author: known?.author ?? pendingAuthor,
511
- authoredAt: known?.authoredAt ?? pendingTime,
512
- summary: known?.summary ?? pendingSummary,
513
- isBoundary: boundary,
514
- }));
515
- continue;
516
- }
517
- const header = /^([0-9a-f]{40}) \d+ \d+(?: \d+)?$/.exec(line);
518
- if (header) {
519
- currentOid = header[1];
520
- boundary = false;
521
- pendingAuthor = '';
522
- pendingTime = '';
523
- pendingSummary = '';
524
- const cached = commits.get(currentOid);
525
- if (cached) {
526
- pendingAuthor = cached.author;
527
- pendingTime = cached.authoredAt;
528
- pendingSummary = cached.summary;
529
- }
530
- continue;
531
- }
532
- if (!currentOid)
533
- continue;
534
- const separator = line.indexOf(' ');
535
- const key = separator < 0 ? line : line.slice(0, separator);
536
- const value = separator < 0 ? '' : line.slice(separator + 1);
537
- if (key === 'author')
538
- pendingAuthor = value;
539
- else if (key === 'author-time')
540
- pendingTime = new Date(Number(value) * 1000).toISOString();
541
- else if (key === 'summary')
542
- pendingSummary = value;
543
- else if (key === 'boundary')
544
- boundary = true;
545
- if (pendingAuthor && pendingTime && pendingSummary && !commits.has(currentOid)) {
546
- commits.set(currentOid, Object.freeze({
547
- author: pendingAuthor,
548
- authoredAt: pendingTime,
549
- summary: pendingSummary,
550
- }));
551
- }
552
- }
553
- return Object.freeze({
554
- path,
555
- rev: rev ?? null,
556
- lines: Object.freeze(lines),
557
- truncated: lineNumber > limit,
558
- });
559
- },
560
- async fileHistory(input) {
561
- const path = assertSafeRelativePath(input.path);
562
- const limit = bounded(input.limit, SEARCH_PAGE_DEFAULT, 1, FILE_HISTORY_LIMIT, 'limit');
563
- await requireRoot();
564
- const rev = input.rev ? assertSearchText(input.rev, 'rev') : undefined;
565
- const target = rev ?? 'HEAD';
566
- const tracked = (await runGit(['rev-parse', '--verify', '--quiet', target]).catch(() => ''))
567
- .toString()
568
- .trim();
569
- if (!tracked) {
570
- return Object.freeze({ path, items: Object.freeze([]), followed: false, truncated: false });
571
- }
572
- // `--follow` only accepts a single path, which is exactly this case. It explains its own
573
- // limits for copies and complex merges (plan G6) — we surface `followed` rather than
574
- // pretending tracking is complete.
575
- // v0.3.25 #270 — the validated revision must reach the log command: it was
576
- // previously used only for the existence check, so every query walked HEAD.
577
- const raw = await runGit([
578
- 'log',
579
- `--max-count=${limit + 1}`,
580
- `--format=${LIST_FORMAT}${RECORD_SEPARATOR}`,
581
- '--follow',
582
- target,
583
- '--',
584
- path,
585
- ]);
586
- const all = parseSummaryPage(raw);
587
- const items = all.slice(0, limit);
588
- return Object.freeze({
589
- path,
590
- items: Object.freeze(items),
591
- followed: true,
592
- truncated: all.length > limit,
593
- });
594
- },
595
- };
596
- }
597
- function encodeSearchCursor(scope) {
598
- return Buffer.from(JSON.stringify({ v: 1, ...scope }), 'utf8').toString('base64url');
599
- }
600
- function decodeSearchCursor(cursor, expected) {
601
- let parsed;
602
- try {
603
- parsed = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
604
- }
605
- catch {
606
- throw new errors_1.WebWorkbenchError(400, 'History cursor is not valid.', 'git_cursor_invalid');
607
- }
608
- const candidate = parsed;
609
- if (candidate.tipOid !== expected.tipOid ||
610
- candidate.revision !== expected.revision ||
611
- candidate.fingerprint !== expected.fingerprint ||
612
- typeof candidate.offset !== 'number' ||
613
- !Number.isInteger(candidate.offset) ||
614
- candidate.offset < 0) {
615
- throw new errors_1.WebWorkbenchError(409, 'History changed; reload the list before paginating.', 'git_cursor_invalid');
616
- }
617
- return candidate.offset;
618
- }
619
- //# sourceMappingURL=git-history-service.js.map
@@ -1,45 +0,0 @@
1
- export interface GitIndexPaths {
2
- readonly root: string;
3
- /** `git rev-parse --absolute-git-dir`. */
4
- readonly gitDir: string;
5
- /** `git rev-parse --git-path index`, resolved to an absolute path. */
6
- readonly indexPath: string;
7
- }
8
- export interface IndexTransactionContext {
9
- /** Value for `GIT_INDEX_FILE`; the mutation must target this index, not the real one. */
10
- readonly indexFile: string;
11
- readonly env: NodeJS.ProcessEnv;
12
- /** Index digest before the transaction, for post-hoc comparison. */
13
- readonly before: string;
14
- }
15
- /**
16
- * Environment for index writes.
17
- *
18
- * `GIT_CONFIG_GLOBAL` is intentionally *not* pointed at /dev/null here, unlike the read
19
- * path: staging must resolve the user's `core.autocrlf`, filters and `.gitattributes`
20
- * exactly as their own Git would, otherwise we would silently stage different bytes than
21
- * they expect (plan §7.8). Hooks stay disabled — `add`/`apply` must not run user hooks.
22
- */
23
- export declare function writeGitEnvironment(overrides?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
24
- /**
25
- * `-c` prefix for index writes. Hooks are disabled because none of the index mutations run
26
- * hooks; the commit runner uses its own prefix and does not reuse this one.
27
- */
28
- export declare function writeGitPrefix(): string[];
29
- export declare function indexLockPath(indexPath: string): string;
30
- /**
31
- * Runs `work` against a private copy of the index and publishes it atomically.
32
- *
33
- * `verify` receives the temp index path so the caller can assert the mutation actually did
34
- * what it intended (for example that the target path is now staged) before publication.
35
- */
36
- export declare function withIndexTransaction<T>(paths: GitIndexPaths, seed: (context: {
37
- readonly indexFile: string;
38
- readonly env: NodeJS.ProcessEnv;
39
- }) => Promise<void>, work: (context: IndexTransactionContext) => Promise<T>, verify?: (result: T, context: IndexTransactionContext) => Promise<void>): Promise<T>;
40
- /**
41
- * Failure text Git prints when it refuses because the index changed under it. Surfaced so
42
- * callers can report an honest conflict instead of a generic error.
43
- */
44
- export declare function isIndexConflictOutput(text: string): boolean;
45
- //# sourceMappingURL=git-index-transaction.d.ts.map