@orion-agents/orion-code 0.3.66 → 0.4.3

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 (370) hide show
  1. package/CHANGELOG.md +81 -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 +34 -0
  6. package/dist/acp/session-updates.js +162 -0
  7. package/dist/acp/sessions.d.ts +32 -0
  8. package/dist/acp/sessions.js +315 -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 +5 -1
  15. package/dist/commands/diagnostic-command-handlers.js +20 -6
  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 +0 -18
  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/tool-commands.js +1 -1
  28. package/dist/commands/types.d.ts +4 -10
  29. package/dist/commands/types.js +1 -21
  30. package/dist/commands/workflow-command-handlers.js +13 -4
  31. package/dist/framework/loop-budget-contract.d.ts +7 -2
  32. package/dist/framework/loop-budget-contract.js +4 -1
  33. package/dist/framework/loop-progress.d.ts +22 -0
  34. package/dist/framework/loop-progress.js +79 -0
  35. package/dist/framework/prompt.d.ts +0 -2
  36. package/dist/framework/prompt.js +9 -27
  37. package/dist/framework/query.d.ts +27 -20
  38. package/dist/framework/query.js +453 -153
  39. package/dist/framework/store.d.ts +6 -10
  40. package/dist/framework/store.js +2 -21
  41. package/dist/framework/tool-call-orchestrator.d.ts +7 -0
  42. package/dist/framework/tool-call-orchestrator.js +8 -3
  43. package/dist/framework/tool-state.d.ts +2 -0
  44. package/dist/framework/tool.d.ts +0 -23
  45. package/dist/framework/verification-command.d.ts +15 -0
  46. package/dist/framework/verification-command.js +32 -0
  47. package/dist/harness/assembler.d.ts +1 -0
  48. package/dist/harness/assembler.js +24 -0
  49. package/dist/harness/capsule.d.ts +1 -1
  50. package/dist/harness/capsule.js +33 -14
  51. package/dist/harness/context-harness.d.ts +31 -12
  52. package/dist/harness/context-harness.js +491 -35
  53. package/dist/harness/contract.js +1 -1
  54. package/dist/harness/drift-guard.d.ts +4 -0
  55. package/dist/harness/drift-guard.js +68 -16
  56. package/dist/harness/intent.js +21 -0
  57. package/dist/harness/ledger.d.ts +6 -11
  58. package/dist/harness/ledger.js +39 -9
  59. package/dist/harness/progress-controller.d.ts +12 -7
  60. package/dist/harness/progress-controller.js +66 -21
  61. package/dist/harness/state.js +9 -1
  62. package/dist/harness/task-checklist.d.ts +16 -0
  63. package/dist/harness/task-checklist.js +95 -0
  64. package/dist/harness/types.d.ts +73 -1
  65. package/dist/harness/verification.d.ts +19 -1
  66. package/dist/harness/verification.js +116 -29
  67. package/dist/index.d.ts +1 -1
  68. package/dist/index.js +1 -3
  69. package/dist/print-ui/event-stream.d.ts +38 -0
  70. package/dist/print-ui/event-stream.js +187 -0
  71. package/dist/print-ui/launch.d.ts +12 -1
  72. package/dist/print-ui/launch.js +173 -11
  73. package/dist/product/environment.d.ts +1 -1
  74. package/dist/product/environment.js +1 -1
  75. package/dist/product/identity.d.ts +1 -1
  76. package/dist/product/identity.js +1 -1
  77. package/dist/product/paths.d.ts +3 -2
  78. package/dist/product/paths.js +6 -2
  79. package/dist/runtime/agent-loop.d.ts +11 -2
  80. package/dist/runtime/agent-loop.js +165 -25
  81. package/dist/runtime/agent-runtime-controller.d.ts +13 -3
  82. package/dist/runtime/agent-runtime-controller.js +347 -183
  83. package/dist/runtime/agent-runtime-protocol.d.ts +10 -18
  84. package/dist/runtime/agent-runtime-runner.d.ts +10 -0
  85. package/dist/runtime/builtin-tool-provider.js +5 -1
  86. package/dist/runtime/capability-receipt-journal.js +1 -0
  87. package/dist/runtime/durable-tool-receipt-reader.js +2 -1
  88. package/dist/runtime/first-party-tool-services.d.ts +1 -0
  89. package/dist/runtime/first-party-tool-services.js +2 -12
  90. package/dist/runtime/first-party-tool-universe.d.ts +1 -0
  91. package/dist/runtime/first-party-tool-universe.js +1 -1
  92. package/dist/runtime/followup-queue-store.d.ts +16 -0
  93. package/dist/runtime/followup-queue-store.js +75 -0
  94. package/dist/runtime/goal-lifecycle-v2.d.ts +11 -1
  95. package/dist/runtime/goal-lifecycle-v2.js +85 -15
  96. package/dist/runtime/goal-runtime-coordinator.d.ts +10 -1
  97. package/dist/runtime/goal-runtime-coordinator.js +81 -24
  98. package/dist/runtime/loop-budget.js +7 -5
  99. package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +2 -0
  100. package/dist/runtime/mcp/first-party-mcp-adapter.js +23 -19
  101. package/dist/runtime/model-coordinator.js +2 -5
  102. package/dist/runtime/orion-runtime-v1.d.ts +18 -2
  103. package/dist/runtime/orion-runtime-v1.js +135 -39
  104. package/dist/runtime/orion-session-runner.d.ts +7 -0
  105. package/dist/runtime/orion-session-runner.js +82 -0
  106. package/dist/runtime/plan-review.d.ts +1 -0
  107. package/dist/runtime/plan-review.js +8 -4
  108. package/dist/runtime/product-bootstrap.d.ts +6 -0
  109. package/dist/runtime/product-bootstrap.js +41 -51
  110. package/dist/runtime/product-orion-runtime.js +128 -52
  111. package/dist/runtime/release-receipts.d.ts +24 -133
  112. package/dist/runtime/release-receipts.js +129 -693
  113. package/dist/runtime/rich-text/layout.js +108 -65
  114. package/dist/runtime/rsi/contracts.d.ts +50 -0
  115. package/dist/runtime/rsi/contracts.js +17 -0
  116. package/dist/runtime/rsi/diagnosis.d.ts +46 -0
  117. package/dist/runtime/rsi/diagnosis.js +98 -0
  118. package/dist/runtime/rsi/evaluation-suite.d.ts +25 -0
  119. package/dist/runtime/rsi/evaluation-suite.js +141 -0
  120. package/dist/runtime/rsi/evaluation-worker.d.ts +19 -0
  121. package/dist/runtime/rsi/evaluation-worker.js +64 -0
  122. package/dist/runtime/rsi/evaluation.d.ts +49 -0
  123. package/dist/runtime/rsi/evaluation.js +351 -0
  124. package/dist/runtime/rsi/lifecycle.d.ts +54 -0
  125. package/dist/runtime/rsi/lifecycle.js +279 -0
  126. package/dist/runtime/rsi/proposal.d.ts +39 -0
  127. package/dist/runtime/rsi/proposal.js +312 -0
  128. package/dist/runtime/rsi/receipt.d.ts +28 -0
  129. package/dist/runtime/rsi/receipt.js +138 -0
  130. package/dist/runtime/rsi/skill-state.d.ts +7 -0
  131. package/dist/runtime/rsi/skill-state.js +50 -0
  132. package/dist/runtime/rsi/trajectory.d.ts +19 -0
  133. package/dist/runtime/rsi/trajectory.js +314 -0
  134. package/dist/runtime/rsi/triage.d.ts +274 -0
  135. package/dist/runtime/rsi/triage.js +58 -0
  136. package/dist/runtime/session-composer-control.d.ts +5 -24
  137. package/dist/runtime/session-composer-control.js +27 -189
  138. package/dist/runtime/step-snapshot.d.ts +1 -0
  139. package/dist/runtime/subagents/policy.js +0 -1
  140. package/dist/runtime/subagents/production.js +1 -1
  141. package/dist/runtime/subagents/runtime-integration.js +2 -4
  142. package/dist/runtime/subagents/types.d.ts +0 -5
  143. package/dist/runtime/subagents/types.js +0 -2
  144. package/dist/runtime/task-context-recovery.d.ts +55 -0
  145. package/dist/runtime/task-context-recovery.js +342 -0
  146. package/dist/runtime/task-context-service.d.ts +16 -10
  147. package/dist/runtime/task-context-service.js +35 -4
  148. package/dist/runtime/thread-admission.d.ts +1 -1
  149. package/dist/runtime/thread-admission.js +12 -6
  150. package/dist/runtime/thread-event-store.d.ts +2 -2
  151. package/dist/runtime/thread-event-store.js +7 -2
  152. package/dist/runtime/thread-projection.js +4 -2
  153. package/dist/runtime/thread-runtime.d.ts +7 -0
  154. package/dist/runtime/thread-runtime.js +43 -0
  155. package/dist/runtime/thread-session-index.d.ts +8 -0
  156. package/dist/runtime/thread-session-index.js +50 -1
  157. package/dist/runtime/thread-session-view.d.ts +2 -1
  158. package/dist/runtime/thread-session-view.js +4 -0
  159. package/dist/runtime/thread-tool-journal.d.ts +1 -0
  160. package/dist/runtime/thread-tool-journal.js +6 -2
  161. package/dist/runtime/thread-ui-adapter.d.ts +1 -0
  162. package/dist/runtime/thread-ui-adapter.js +88 -11
  163. package/dist/runtime/tool-gateway.d.ts +7 -0
  164. package/dist/runtime/tool-gateway.js +20 -0
  165. package/dist/runtime/tool-transcript-entry.d.ts +16 -0
  166. package/dist/runtime/tool-transcript-entry.js +73 -0
  167. package/dist/runtime/turn-commit.d.ts +4 -1
  168. package/dist/runtime/turn-commit.js +19 -15
  169. package/dist/runtime/ui-events.d.ts +12 -0
  170. package/dist/runtime/ui-view-model.d.ts +6 -5
  171. package/dist/runtime/ui-view-model.js +33 -19
  172. package/dist/runtime/workspace-runtime-kernel.js +0 -1
  173. package/dist/services/atomic-write.d.ts +2 -0
  174. package/dist/services/atomic-write.js +12 -1
  175. package/dist/services/code-review/format.d.ts +4 -1
  176. package/dist/services/code-review/format.js +5 -1
  177. package/dist/services/code-review/runner.d.ts +2 -2
  178. package/dist/services/code-review/runner.js +86 -64
  179. package/dist/services/code-review/snapshot.d.ts +9 -9
  180. package/dist/services/code-review/snapshot.js +182 -166
  181. package/dist/services/compact/auto-compact.d.ts +21 -6
  182. package/dist/services/compact/auto-compact.js +148 -22
  183. package/dist/services/compact/background-candidate.d.ts +33 -0
  184. package/dist/services/compact/background-candidate.js +184 -0
  185. package/dist/services/compact/compact.d.ts +4 -1
  186. package/dist/services/compact/compact.js +30 -3
  187. package/dist/services/compact/coordinator.d.ts +10 -4
  188. package/dist/services/compact/coordinator.js +17 -7
  189. package/dist/services/compact/summary-generator.d.ts +4 -2
  190. package/dist/services/compact/summary-generator.js +17 -3
  191. package/dist/services/config.d.ts +5 -5
  192. package/dist/services/config.js +30 -45
  193. package/dist/services/doctor.js +85 -13
  194. package/dist/services/effort.d.ts +5 -5
  195. package/dist/services/effort.js +5 -11
  196. package/dist/services/file-lock.d.ts +9 -3
  197. package/dist/services/file-lock.js +92 -26
  198. package/dist/services/global-config.d.ts +26 -56
  199. package/dist/services/global-config.js +213 -183
  200. package/dist/services/llm.d.ts +40 -4
  201. package/dist/services/llm.js +164 -45
  202. package/dist/services/model-client-pool.d.ts +15 -9
  203. package/dist/services/model-client-pool.js +62 -33
  204. package/dist/services/model-context.d.ts +2 -1
  205. package/dist/services/model-context.js +15 -9
  206. package/dist/services/model-registry.d.ts +4 -15
  207. package/dist/services/model-registry.js +32 -101
  208. package/dist/services/provider-diagnostics.d.ts +7 -0
  209. package/dist/services/provider-diagnostics.js +9 -10
  210. package/dist/services/provider-resilience/coordinator.d.ts +1 -1
  211. package/dist/services/provider-resilience/coordinator.js +10 -6
  212. package/dist/services/provider-resilience/request-gate.d.ts +3 -0
  213. package/dist/services/provider-resilience/request-gate.js +29 -18
  214. package/dist/services/provider-resilience/types.d.ts +2 -0
  215. package/dist/services/session-storage.d.ts +7 -10
  216. package/dist/services/session-storage.js +57 -30
  217. package/dist/services/settings-coordinator.d.ts +0 -6
  218. package/dist/services/settings-coordinator.js +19 -56
  219. package/dist/services/settings-document-repository.d.ts +3 -10
  220. package/dist/services/settings-document-repository.js +7 -85
  221. package/dist/services/usage-state.d.ts +3 -3
  222. package/dist/services/usage-state.js +11 -42
  223. package/dist/terminal-ui/answer-format.d.ts +14 -0
  224. package/dist/terminal-ui/answer-format.js +119 -0
  225. package/dist/terminal-ui/launch.d.ts +7 -6
  226. package/dist/terminal-ui/launch.js +160 -70
  227. package/dist/terminal-ui/output-queue.d.ts +2 -1
  228. package/dist/terminal-ui/output-queue.js +1 -1
  229. package/dist/terminal-ui/raw-editor.d.ts +2 -1
  230. package/dist/terminal-ui/raw-editor.js +56 -15
  231. package/dist/tools/core/edit-file.js +2 -0
  232. package/dist/tools/core/write-file.js +5 -0
  233. package/dist/tools/lsp.d.ts +16 -1
  234. package/dist/tools/lsp.js +60 -19
  235. package/dist/tools/sandbox.d.ts +1 -1
  236. package/dist/tools/sandbox.js +3 -16
  237. package/dist/tools/todo.d.ts +4 -2
  238. package/dist/tools/todo.js +76 -31
  239. package/dist/tui-core/input-parser.d.ts +1 -0
  240. package/dist/tui-core/input-parser.js +6 -0
  241. package/dist/tui-core/style.d.ts +1 -8
  242. package/dist/tui-core/style.js +3 -110
  243. package/dist/tui-ui/chrome-view-model.d.ts +1 -1
  244. package/dist/tui-ui/chrome-view-model.js +22 -27
  245. package/dist/tui-ui/launch.js +14 -14
  246. package/dist/tui-ui/layout.d.ts +5 -7
  247. package/dist/tui-ui/layout.js +129 -124
  248. package/dist/tui-ui/runner.d.ts +11 -12
  249. package/dist/tui-ui/runner.js +88 -67
  250. package/dist/tui-ui/state.d.ts +0 -11
  251. package/dist/tui-ui/state.js +22 -33
  252. package/dist/tui-ui/terminal-image.js +22 -4
  253. package/dist/tui-ui/transcript-inspector-layout.js +6 -3
  254. package/dist/tui-ui/transcript-inspector.d.ts +1 -0
  255. package/dist/tui-ui/transcript-inspector.js +7 -1
  256. package/dist/tui-ui/transcript-layout.js +42 -6
  257. package/dist/utils/terminal-text.d.ts +11 -0
  258. package/dist/utils/terminal-text.js +114 -0
  259. package/docs/cli-guide.md +562 -0
  260. package/docs/orion.example.yaml +42 -0
  261. package/docs/readme.md +12 -57
  262. package/npm-shrinkwrap.json +484 -1855
  263. package/package.json +13 -63
  264. package/dist/migration/command.d.ts +0 -9
  265. package/dist/migration/command.js +0 -100
  266. package/dist/migration/index.d.ts +0 -7
  267. package/dist/migration/index.js +0 -14
  268. package/dist/migration/migrate.d.ts +0 -19
  269. package/dist/migration/migrate.js +0 -406
  270. package/dist/migration/types.d.ts +0 -55
  271. package/dist/migration/types.js +0 -6
  272. package/dist/services/tool-allowlist.d.ts +0 -110
  273. package/dist/services/tool-allowlist.js +0 -299
  274. package/dist/services/yaml-config.d.ts +0 -57
  275. package/dist/services/yaml-config.js +0 -178
  276. package/dist/web/cli-options.d.ts +0 -17
  277. package/dist/web/cli-options.js +0 -51
  278. package/dist/web/code-review-run-service.d.ts +0 -68
  279. package/dist/web/code-review-run-service.js +0 -228
  280. package/dist/web/context-text.d.ts +0 -17
  281. package/dist/web/context-text.js +0 -40
  282. package/dist/web/errors.d.ts +0 -6
  283. package/dist/web/errors.js +0 -13
  284. package/dist/web/event-hub.d.ts +0 -45
  285. package/dist/web/event-hub.js +0 -370
  286. package/dist/web/file-read-service.d.ts +0 -101
  287. package/dist/web/file-read-service.js +0 -593
  288. package/dist/web/file-write-service.d.ts +0 -16
  289. package/dist/web/file-write-service.js +0 -103
  290. package/dist/web/git-compare-service.d.ts +0 -45
  291. package/dist/web/git-compare-service.js +0 -160
  292. package/dist/web/git-diff-document.d.ts +0 -102
  293. package/dist/web/git-diff-document.js +0 -258
  294. package/dist/web/git-file-source.d.ts +0 -25
  295. package/dist/web/git-file-source.js +0 -21
  296. package/dist/web/git-history-service.d.ts +0 -151
  297. package/dist/web/git-history-service.js +0 -619
  298. package/dist/web/git-index-transaction.d.ts +0 -45
  299. package/dist/web/git-index-transaction.js +0 -174
  300. package/dist/web/git-patch-builder.d.ts +0 -30
  301. package/dist/web/git-patch-builder.js +0 -138
  302. package/dist/web/git-read-model-service.d.ts +0 -452
  303. package/dist/web/git-read-model-service.js +0 -1833
  304. package/dist/web/git-version-service.d.ts +0 -79
  305. package/dist/web/git-version-service.js +0 -279
  306. package/dist/web/host-daemon.d.ts +0 -70
  307. package/dist/web/host-daemon.js +0 -237
  308. package/dist/web/index.d.ts +0 -6
  309. package/dist/web/index.js +0 -28
  310. package/dist/web/launch.d.ts +0 -12
  311. package/dist/web/launch.js +0 -89
  312. package/dist/web/native-directory-picker.d.ts +0 -63
  313. package/dist/web/native-directory-picker.js +0 -169
  314. package/dist/web/protocol.d.ts +0 -705
  315. package/dist/web/protocol.js +0 -639
  316. package/dist/web/review-service.d.ts +0 -22
  317. package/dist/web/review-service.js +0 -68
  318. package/dist/web/server.d.ts +0 -20
  319. package/dist/web/server.js +0 -1453
  320. package/dist/web/session-runtime-registry.d.ts +0 -138
  321. package/dist/web/session-runtime-registry.js +0 -471
  322. package/dist/web/terminal-manager.d.ts +0 -156
  323. package/dist/web/terminal-manager.js +0 -779
  324. package/dist/web/terminal-server.d.ts +0 -8
  325. package/dist/web/terminal-server.js +0 -304
  326. package/dist/web/workbench-controller.d.ts +0 -395
  327. package/dist/web/workbench-controller.js +0 -3077
  328. package/dist/web/workspace-discovery.d.ts +0 -92
  329. package/dist/web/workspace-discovery.js +0 -324
  330. package/dist/web/workspace-mutation-arbiter.d.ts +0 -54
  331. package/dist/web/workspace-mutation-arbiter.js +0 -267
  332. package/dist/web/workspace-open-telemetry.d.ts +0 -55
  333. package/dist/web/workspace-open-telemetry.js +0 -73
  334. package/dist/web-client/assets/FilesPanel-CPDovK_K.js +0 -1
  335. package/dist/web-client/assets/GitPanel-DtU_TD61.js +0 -4
  336. package/dist/web-client/assets/ReviewPanel-vMO7BEA3.js +0 -6
  337. package/dist/web-client/assets/TerminalPanel-C9vDTAlS.js +0 -23
  338. package/dist/web-client/assets/TerminalPanel-DLuoa74B.css +0 -1
  339. package/dist/web-client/assets/index-CABdwh4l.css +0 -1
  340. package/dist/web-client/assets/index-KvshfEbl.js +0 -20
  341. package/dist/web-client/assets/useAutoNotice-IE1g2wcb.js +0 -1
  342. package/dist/web-client/favicon.svg +0 -9
  343. package/dist/web-client/index.html +0 -17
  344. package/docs/architecture/agent-mode-permission-contract.md +0 -87
  345. package/docs/architecture/v0.3.0-web-api.yaml +0 -1340
  346. package/docs/architecture/v0.3.1-web-api.yaml +0 -2338
  347. package/docs/architecture/v0.3.2-web-api.yaml +0 -3029
  348. package/docs/architecture/v0.3.3-web-api.yaml +0 -3205
  349. package/docs/architecture/v0.3.4-stabilization-contract.md +0 -32
  350. package/docs/migration/v0.1.9-to-v0.2.0.md +0 -98
  351. package/docs/migration/v0.2.2-to-v0.3.0-settings.md +0 -114
  352. package/docs/migration/v0.2.2-to-v0.3.0.md +0 -55
  353. package/docs/migration/v0.3.0-to-v0.3.1.md +0 -88
  354. package/docs/migration/v0.3.1-to-v0.3.2.md +0 -94
  355. package/docs/migration/v0.3.2-to-v0.3.3.md +0 -62
  356. package/docs/migration/v0.3.3-to-v0.3.4.md +0 -36
  357. package/docs/orion.example.json +0 -86
  358. package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +0 -1234
  359. package/docs/plan/v0.2.0-release-checklist.md +0 -91
  360. package/docs/plan/v0.3.0-node-runtime-compatibility-plan.md +0 -57
  361. package/docs/plan/v0.3.0-settings-integration-plan.md +0 -740
  362. package/docs/plan/v0.3.0-web-workbench-plan.md +0 -376
  363. package/docs/plan/v0.3.1-web-workbench-professional-shell-plan.md +0 -848
  364. package/docs/plan/v0.3.2-web-workbench-layout-and-composer-plan.md +0 -869
  365. package/docs/plan/v0.3.3-plan.md +0 -1113
  366. package/docs/plan/v0.3.4-stabilization-plan.md +0 -89
  367. package/docs/test/v0.3.1-web-workbench-e2e-plan.md +0 -140
  368. package/docs/test/v0.3.2-web-workbench-e2e-plan.md +0 -100
  369. package/docs/test/v0.3.3-web-workbench-e2e-plan.md +0 -79
  370. 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