farming-code 2.2.29 → 2.2.32

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 (385) hide show
  1. package/README.md +25 -66
  2. package/README.zh_cn.md +15 -66
  3. package/THIRD_PARTY_NOTICES.md +7 -0
  4. package/backend/acp/{client-services.js → client-services.cjs} +132 -134
  5. package/backend/acp/packaged-claude-acp.cjs +37 -0
  6. package/backend/acp/packaged-codex-acp.cjs +37 -0
  7. package/backend/acp/patch-decisions.cjs +182 -0
  8. package/backend/acp/permission-security.cjs +131 -0
  9. package/backend/{acp-checkpoint-store.js → acp-checkpoint-store.cjs} +90 -59
  10. package/backend/{acp-runtime.js → acp-runtime.cjs} +1219 -1125
  11. package/backend/acp-session-state.cjs +622 -0
  12. package/backend/acp-transcript.cjs +525 -0
  13. package/backend/agent-env.cjs +257 -0
  14. package/backend/agent-extension-discovery.cjs +452 -0
  15. package/backend/agent-extension-inventory.cjs +116 -0
  16. package/backend/agent-json-stream.cjs +283 -0
  17. package/backend/agent-lifecycle-journal.cjs +185 -0
  18. package/backend/{agent-manager.js → agent-manager.cjs} +3116 -4275
  19. package/backend/agent-order-transaction.cjs +85 -0
  20. package/backend/agent-order.cjs +159 -0
  21. package/backend/agent-provider-session.cjs +98 -0
  22. package/backend/agent-runtime-binding.cjs +179 -0
  23. package/backend/agent-session-history.cjs +1022 -0
  24. package/backend/agent-session-inventory.cjs +291 -0
  25. package/backend/async-cache.cjs +104 -0
  26. package/backend/atomic-json-store.cjs +67 -0
  27. package/backend/auth.cjs +261 -0
  28. package/backend/authoritative-inventory-cache.cjs +383 -0
  29. package/backend/business-health.cjs +68 -0
  30. package/backend/chat-runtime.cjs +50 -0
  31. package/backend/claude-settings.cjs +132 -0
  32. package/backend/cli-agents.cjs +435 -0
  33. package/backend/codex-context-window.cjs +196 -0
  34. package/backend/codex-models.cjs +228 -0
  35. package/backend/codex-session-archive.cjs +82 -0
  36. package/backend/codex-session-history.cjs +590 -0
  37. package/backend/{codex-terminal-profile.js → codex-terminal-profile.cjs} +149 -155
  38. package/backend/codex-transcript-sanitizer.cjs +130 -0
  39. package/backend/codex-transcript.cjs +2107 -0
  40. package/backend/command-runner-child.cjs +105 -0
  41. package/backend/config-manager.cjs +1263 -0
  42. package/backend/control-api.cjs +439 -0
  43. package/backend/data/LICENSE.cua +21 -0
  44. package/backend/executable-discovery.cjs +204 -0
  45. package/backend/farming-agent-bootstrap.cjs +81 -0
  46. package/backend/farming-agent-bootstrap.zh_cn.md +6 -2
  47. package/backend/{farming-app-cli.js → farming-app-cli.cjs} +441 -493
  48. package/backend/farming-cli.cjs +414 -0
  49. package/backend/farming-net-pass.cjs +319 -0
  50. package/backend/farming-net-registry.cjs +123 -0
  51. package/backend/farming-net-server.cjs +309 -0
  52. package/backend/farming-session-store.cjs +651 -0
  53. package/backend/git-worktree-info.cjs +181 -0
  54. package/backend/haiku-token.cjs +828 -0
  55. package/backend/index-html.cjs +96 -0
  56. package/backend/input-parts.cjs +68 -0
  57. package/backend/input-routing.cjs +40 -0
  58. package/backend/{local-session-engine.js → local-session-engine.cjs} +276 -282
  59. package/backend/main-agent-skills.cjs +309 -0
  60. package/backend/main-page-session.cjs +132 -0
  61. package/backend/native-pty-controller-generation.cjs +139 -0
  62. package/backend/{native-pty-host-client.js → native-pty-host-client.cjs} +338 -346
  63. package/backend/native-pty-host-identity.cjs +125 -0
  64. package/backend/native-pty-host-path.cjs +68 -0
  65. package/backend/{native-pty-host.js → native-pty-host.cjs} +480 -569
  66. package/backend/native-session-engine.cjs +296 -0
  67. package/backend/network.cjs +57 -0
  68. package/backend/npm-update-helper.cjs +399 -0
  69. package/backend/packaged-node-pty.cjs +120 -0
  70. package/backend/preview-session-manager.cjs +89 -0
  71. package/backend/provider-adapters.cjs +492 -0
  72. package/backend/provider-home-configuration.cjs +211 -0
  73. package/backend/provider-session-id.cjs +79 -0
  74. package/backend/provider-session-service.cjs +333 -0
  75. package/backend/qr-share-tickets.cjs +119 -0
  76. package/backend/resource-broadcast-protocol.cjs +50 -0
  77. package/backend/review-diff-router.cjs +202 -0
  78. package/backend/review-diff-service.cjs +1267 -0
  79. package/backend/review-session-router.cjs +93 -0
  80. package/backend/review-session-service.cjs +470 -0
  81. package/backend/review-session-store.cjs +161 -0
  82. package/backend/review-state-router.cjs +132 -0
  83. package/backend/review-state-store.cjs +299 -0
  84. package/backend/run-history-store.cjs +97 -0
  85. package/backend/runtime-dependency-manager.cjs +893 -0
  86. package/backend/runtime-executable-invocation.cjs +37 -0
  87. package/backend/runtime-observation.cjs +96 -0
  88. package/backend/server-process-identity.cjs +70 -0
  89. package/backend/server.cjs +3356 -0
  90. package/backend/session-engine-bridge.cjs +144 -0
  91. package/backend/session-engine-router.cjs +105 -0
  92. package/backend/session-engine.cjs +64 -0
  93. package/backend/session-stream-protocol.cjs +181 -0
  94. package/backend/shell-busy-integration.cjs +442 -0
  95. package/backend/slash-command-discovery.cjs +423 -0
  96. package/backend/storage-layout.cjs +263 -0
  97. package/backend/system-monitor.cjs +96 -0
  98. package/backend/terminal-attach-checkpoint.cjs +73 -0
  99. package/backend/terminal-exit-quiescence.cjs +57 -0
  100. package/backend/{terminal-reducer-flow-control.js → terminal-reducer-flow-control.cjs} +45 -22
  101. package/backend/terminal-runtime-cleanup.cjs +99 -0
  102. package/backend/{terminal-screen-state.js → terminal-screen-state.cjs} +100 -108
  103. package/backend/{terminal-screen-worker-pool.js → terminal-screen-worker-pool.cjs} +89 -79
  104. package/backend/{terminal-screen-worker-thread.js → terminal-screen-worker-thread.cjs} +64 -65
  105. package/backend/terminal-screen-worker.cjs +352 -0
  106. package/backend/terminal-state-serialization.cjs +147 -0
  107. package/backend/{terminal-status.js → terminal-status.cjs} +137 -187
  108. package/backend/theme-manager.cjs +185 -0
  109. package/backend/update-service.cjs +675 -0
  110. package/backend/usage-forecast.cjs +95 -0
  111. package/backend/{usage-history-client.js → usage-history-client.cjs} +144 -94
  112. package/backend/usage-history-smoke.cjs +85 -0
  113. package/backend/usage-history-worker.cjs +60 -0
  114. package/backend/{usage-monitor.js → usage-monitor.cjs} +363 -390
  115. package/backend/workspace-directory.cjs +239 -0
  116. package/backend/workspace-discovery.cjs +271 -0
  117. package/backend/{workspace-file-router.js → workspace-file-router.cjs} +213 -282
  118. package/backend/{workspace-file-service.js → workspace-file-service.cjs} +1139 -1318
  119. package/backend/workspace-root-registry.cjs +192 -0
  120. package/bin/farming +1 -1
  121. package/config/farming.deploy.env.example +1 -1
  122. package/config/farming.install.env.example +1 -1
  123. package/dist/acp/codex-acp-1.1.4.mjs +405 -8
  124. package/dist/assets/App-BCkdpWB6.css +1 -0
  125. package/dist/assets/App-CRjKpaGp.js +697 -0
  126. package/dist/assets/CodeSelect-Ci8sKZPU.js +1 -0
  127. package/dist/assets/CodeSelect-T2eNzrOc.css +1 -0
  128. package/dist/assets/{FileEditorMarkdownPreview-Cs9cLv8a.js → FileEditorMarkdownPreview-V06QHlAg.js} +55 -55
  129. package/dist/assets/FileEditorPane-BX-Wjg9U.js +2 -0
  130. package/dist/assets/IconGlyphs-YhV7tqd4.js +1 -0
  131. package/dist/assets/ProjectFilesSection-BDT2_r0o.js +12 -0
  132. package/dist/assets/ReviewPage-BqAs5sG1.js +3 -0
  133. package/dist/assets/code-dark-B7eM_9G9.css +1 -0
  134. package/dist/assets/{cssMode-Bdg5RpcJ.js → cssMode-ADdAlxTO.js} +1 -1
  135. package/dist/assets/{editor.api2-D74ufkbr.js → editor.api2-BFLAr0YF.js} +162 -162
  136. package/dist/assets/file-icons-BpeqWkIB.js +1 -0
  137. package/dist/assets/{freemarker2-DfMDJfnE.js → freemarker2-C90q5jrp.js} +1 -1
  138. package/dist/assets/{handlebars-BEdPtzMT.js → handlebars-BwUQcEDq.js} +1 -1
  139. package/dist/assets/{html-B1fPb1QD.js → html-1s3uPKfh.js} +1 -1
  140. package/dist/assets/{htmlMode-CY2ZjHxH.js → htmlMode-xtKD99de.js} +1 -1
  141. package/dist/assets/{index-CQNaZc3l.js → index-C8MchCem.js} +3 -3
  142. package/dist/assets/{javascript-BV2OsWA0.js → javascript-Ph7ijyny.js} +1 -1
  143. package/dist/assets/{jsonMode-zd07aeuX.js → jsonMode-D-jGAnFH.js} +1 -1
  144. package/dist/assets/linkComputer-CbGyI_qx.js +1 -0
  145. package/dist/assets/{liquid-BParI24X.js → liquid-0IamE_cI.js} +1 -1
  146. package/dist/assets/{lspLanguageFeatures-BzredkoV.js → lspLanguageFeatures-BxnQunWF.js} +1 -1
  147. package/dist/assets/main-CLKXa6hf.css +1 -0
  148. package/dist/assets/{mdx-vGzUJN98.js → mdx-DdNmfivn.js} +1 -1
  149. package/dist/assets/{monaco.contribution-BmaeBQEc.js → monaco.contribution-B43jsUs1.js} +2 -2
  150. package/dist/assets/{python-CUwdLgsI.js → python-IAt4X5TS.js} +1 -1
  151. package/dist/assets/{razor-BScebUxU.js → razor-DRkFYW0S.js} +1 -1
  152. package/dist/assets/review-C8-oPKXk.css +1 -0
  153. package/dist/assets/{tsMode-DzUAibXK.js → tsMode-_d_4U2gf.js} +1 -1
  154. package/dist/assets/{typescript-D9EOeM7N.js → typescript-C7zcMq9l.js} +1 -1
  155. package/dist/assets/{workers-DAiomYZM.js → workers-D0nOyJzf.js} +1 -1
  156. package/dist/assets/workspace-editor-model-DND_Y-Bj.js +1 -0
  157. package/dist/assets/workspace-editor-monaco-BPWhgcIB.js +4 -0
  158. package/dist/assets/workspace-editor-monaco-N641qPjX.js +1 -0
  159. package/dist/assets/workspace-view-state-k1bTlJ_Z.js +13 -0
  160. package/dist/assets/{xml-wWl1dhkQ.js → xml-BR-HvxT8.js} +1 -1
  161. package/dist/assets/{yaml-Dc2WDaOZ.js → yaml-YtFQwh4q.js} +1 -1
  162. package/dist/index.html +2 -1
  163. package/extensions/browser/backend/agent-browser-runtime.cjs +1040 -0
  164. package/extensions/browser/backend/agent-capability.cjs +85 -0
  165. package/extensions/browser/backend/browser-mcp-server.cjs +655 -0
  166. package/extensions/browser/backend/browser-resource-manager.cjs +1486 -0
  167. package/extensions/browser/backend/browser-resource-store.cjs +228 -0
  168. package/extensions/browser/backend/browser-router.cjs +203 -0
  169. package/extensions/browser/backend/executable-discovery.cjs +248 -0
  170. package/extensions/browser/backend/farming-browser-client.cjs +116 -0
  171. package/extensions/browser/backend/index.cjs +32 -0
  172. package/extensions/browser/backend/managed-chromium-installer.cjs +833 -0
  173. package/extensions/browser/bin/farming-browser +16 -7
  174. package/extensions/computer/backend/agent-capability.cjs +72 -0
  175. package/extensions/computer/backend/computer-constants.cjs +59 -0
  176. package/extensions/computer/backend/computer-mcp-server.cjs +182 -0
  177. package/extensions/computer/backend/computer-resource-manager.cjs +1219 -0
  178. package/extensions/computer/backend/computer-resource-store.cjs +190 -0
  179. package/extensions/computer/backend/computer-router.cjs +257 -0
  180. package/extensions/computer/backend/cua-tools.json +3067 -0
  181. package/extensions/computer/backend/farming-computer-client.cjs +84 -0
  182. package/extensions/computer/backend/index.cjs +35 -0
  183. package/extensions/computer/backend/isolated-browser-provider.cjs +157 -0
  184. package/extensions/computer/bin/farming-computer +131 -0
  185. package/frontend/farming-net/app.js +255 -262
  186. package/frontend/ghostty-loader.js +24 -20
  187. package/frontend/reading-anchor.js +210 -193
  188. package/frontend/runtime-paths.js +24 -26
  189. package/frontend/session-bridge.js +90 -111
  190. package/frontend/session-modal-bridge.js +184 -302
  191. package/frontend/skin-bridge.js +20 -23
  192. package/frontend/skins/crt/app.js +7686 -7901
  193. package/frontend/skins/crt/effects.js +7 -6
  194. package/frontend/skins/crt/index.html +6 -6
  195. package/frontend/skins/crt/styles/markdown.css +4 -4
  196. package/frontend/terminal-bridge.js +174 -181
  197. package/frontend/terminal-replay.js +320 -345
  198. package/frontend/theme-loader.js +55 -71
  199. package/index.html +1 -0
  200. package/package.json +64 -37
  201. package/shared/backend-connection-status.js +38 -69
  202. package/shared/browser-protocol.js +235 -110
  203. package/shared/websocket-liveness.js +40 -0
  204. package/backend/acp/packaged-claude-acp.js +0 -13
  205. package/backend/acp/packaged-codex-acp.js +0 -13
  206. package/backend/acp/patch-decisions.js +0 -153
  207. package/backend/acp/permission-security.js +0 -108
  208. package/backend/acp-session-state.js +0 -644
  209. package/backend/acp-transcript.js +0 -512
  210. package/backend/agent-env.js +0 -250
  211. package/backend/agent-json-stream.js +0 -268
  212. package/backend/agent-lifecycle-journal.js +0 -133
  213. package/backend/agent-memory-report.js +0 -583
  214. package/backend/agent-order.js +0 -166
  215. package/backend/agent-provider-session.js +0 -76
  216. package/backend/agent-runtime-binding.js +0 -174
  217. package/backend/agent-session-history.js +0 -953
  218. package/backend/async-cache.js +0 -94
  219. package/backend/atomic-json-store.js +0 -37
  220. package/backend/auth.js +0 -251
  221. package/backend/bundle-update-helper.js +0 -113
  222. package/backend/chat-runtime.js +0 -28
  223. package/backend/claude-settings.js +0 -121
  224. package/backend/cli-agents.js +0 -486
  225. package/backend/codex-context-window.js +0 -189
  226. package/backend/codex-models.js +0 -226
  227. package/backend/codex-rollout-follower.js +0 -326
  228. package/backend/codex-session-archive.js +0 -65
  229. package/backend/codex-session-history.js +0 -647
  230. package/backend/codex-transcript-sanitizer.js +0 -115
  231. package/backend/codex-transcript.js +0 -2564
  232. package/backend/command-runner-child.js +0 -67
  233. package/backend/config-manager.js +0 -1133
  234. package/backend/control-api.js +0 -455
  235. package/backend/executable-discovery.js +0 -216
  236. package/backend/farming-agent-bootstrap.js +0 -49
  237. package/backend/farming-cli.js +0 -457
  238. package/backend/farming-net-pass.js +0 -285
  239. package/backend/farming-net-registry.js +0 -112
  240. package/backend/farming-net-server.js +0 -298
  241. package/backend/farming-session-store.js +0 -677
  242. package/backend/git-worktree-info.js +0 -181
  243. package/backend/haiku-token.js +0 -772
  244. package/backend/index-html.js +0 -62
  245. package/backend/input-parts.js +0 -54
  246. package/backend/input-routing.js +0 -24
  247. package/backend/json-cli-runtime.js +0 -275
  248. package/backend/main-agent-skills.js +0 -305
  249. package/backend/main-page-session.js +0 -122
  250. package/backend/native-pty-controller-generation.js +0 -106
  251. package/backend/native-pty-host-identity.js +0 -86
  252. package/backend/native-pty-host-path.js +0 -42
  253. package/backend/native-session-engine.js +0 -268
  254. package/backend/network.js +0 -23
  255. package/backend/npm-update-helper.js +0 -374
  256. package/backend/packaged-node-pty.js +0 -99
  257. package/backend/preview-session-manager.js +0 -68
  258. package/backend/provider-adapters.js +0 -399
  259. package/backend/provider-session-id.js +0 -47
  260. package/backend/provider-session-service.js +0 -345
  261. package/backend/qr-share-tickets.js +0 -100
  262. package/backend/review-diff-router.js +0 -180
  263. package/backend/review-diff-service.js +0 -1270
  264. package/backend/review-session-router.js +0 -74
  265. package/backend/review-session-service.js +0 -446
  266. package/backend/review-session-store.js +0 -151
  267. package/backend/review-state-router.js +0 -116
  268. package/backend/review-state-store.js +0 -286
  269. package/backend/run-history-store.js +0 -67
  270. package/backend/runtime-dependency-manager.js +0 -759
  271. package/backend/runtime-executable-invocation.js +0 -20
  272. package/backend/runtime-observation.js +0 -81
  273. package/backend/server-process-identity.js +0 -47
  274. package/backend/server.js +0 -3267
  275. package/backend/session-engine-bridge.js +0 -129
  276. package/backend/session-engine-router.js +0 -66
  277. package/backend/session-engine.js +0 -39
  278. package/backend/session-stream-protocol.js +0 -185
  279. package/backend/shell-busy-integration.js +0 -472
  280. package/backend/slash-command-discovery.js +0 -433
  281. package/backend/storage-layout.js +0 -190
  282. package/backend/system-monitor.js +0 -77
  283. package/backend/terminal-attach-checkpoint.js +0 -74
  284. package/backend/terminal-exit-quiescence.js +0 -39
  285. package/backend/terminal-runtime-cleanup.js +0 -80
  286. package/backend/terminal-screen-worker.js +0 -337
  287. package/backend/terminal-state-serialization.js +0 -127
  288. package/backend/theme-manager.js +0 -163
  289. package/backend/update-service.js +0 -1545
  290. package/backend/usage-forecast.js +0 -86
  291. package/backend/usage-history-scanner.ts +0 -2718
  292. package/backend/usage-history-smoke.js +0 -64
  293. package/backend/usage-history-worker.js +0 -34
  294. package/backend/workspace-directory.js +0 -232
  295. package/backend/workspace-discovery.js +0 -311
  296. package/backend/workspace-root-registry.js +0 -166
  297. package/dist/assets/App-BKNUILuL.css +0 -1
  298. package/dist/assets/App-Ex2oVVXO.js +0 -693
  299. package/dist/assets/FileEditorPane-CNtuGjQ3.js +0 -2
  300. package/dist/assets/IconGlyphs-BClgag6E.js +0 -1
  301. package/dist/assets/ProjectFilesSection-Cf2BEcAN.js +0 -12
  302. package/dist/assets/ReviewPage-BRuxFaH5.js +0 -3
  303. package/dist/assets/code-dark-BEZTQwYZ.css +0 -1
  304. package/dist/assets/file-icons-BOlcJ0ZF.js +0 -1
  305. package/dist/assets/main-DK9Sy7-c.css +0 -1
  306. package/dist/assets/review-BcnwQtJv.css +0 -1
  307. package/dist/assets/workspace-editor-model-CSGCl21x.js +0 -1
  308. package/dist/assets/workspace-editor-monaco-CJNwbpCy.js +0 -4
  309. package/dist/assets/workspace-editor-monaco-CO9w8YV0.js +0 -1
  310. package/dist/assets/workspace-view-state-BjKPYp0E.js +0 -7
  311. package/extensions/browser/backend/agent-browser-runtime.js +0 -1041
  312. package/extensions/browser/backend/agent-capability.js +0 -55
  313. package/extensions/browser/backend/browser-mcp-server.js +0 -621
  314. package/extensions/browser/backend/browser-resource-manager.js +0 -1309
  315. package/extensions/browser/backend/browser-resource-store.js +0 -190
  316. package/extensions/browser/backend/browser-router.js +0 -133
  317. package/extensions/browser/backend/executable-discovery.js +0 -224
  318. package/extensions/browser/backend/farming-browser-client.js +0 -83
  319. package/extensions/browser/backend/index.js +0 -7
  320. package/extensions/browser/frontend/BrowserSidebarPortals.tsx +0 -360
  321. package/extensions/browser/frontend/BrowserViewer.tsx +0 -500
  322. package/extensions/browser/frontend/browser-resource-state.ts +0 -60
  323. package/extensions/browser/frontend/browser.css +0 -567
  324. package/extensions/browser/frontend/types.ts +0 -31
  325. package/extensions/browser/frontend/useBrowserResources.ts +0 -158
  326. package/frontend/vendor/ghostty-web/index.d.ts +0 -1842
  327. package/shared/backend-connection-status.d.ts +0 -37
  328. package/shared/browser-protocol.d.ts +0 -5
  329. /package/dist/assets/{api-w2x5QfxB.js → api-ByCV9MEr.js} +0 -0
  330. /package/dist/assets/{core-vPkV8P_m.js → core-Czwdx12k.js} +0 -0
  331. /package/dist/assets/{fsharp-DNZNZyEE.js → fsharp-BjPpkoJe.js} +0 -0
  332. /package/dist/assets/{go-_kPJjNc_.js → go-BkIDmSUP.js} +0 -0
  333. /package/dist/assets/{graphql-4HCNVt5g.js → graphql-CCJTpqi1.js} +0 -0
  334. /package/dist/assets/{hcl-C87ymY0o.js → hcl-s4z8lUFg.js} +0 -0
  335. /package/dist/assets/{ini-BYrrGNTc.js → ini-CyUW1I7Z.js} +0 -0
  336. /package/dist/assets/{java-B211rJbk.js → java-CFCcGRiM.js} +0 -0
  337. /package/dist/assets/{julia-DVPsRtBm.js → julia-DQyH_EYb.js} +0 -0
  338. /package/dist/assets/{kotlin-BYyNerjp.js → kotlin-B8hA5O51.js} +0 -0
  339. /package/dist/assets/{less-EC9UblGE.js → less-DaVdaas0.js} +0 -0
  340. /package/dist/assets/{lexon-B1yuUdqW.js → lexon-DLBhPd3y.js} +0 -0
  341. /package/dist/assets/{lua-Bo6GFzxT.js → lua-gB1c_cif.js} +0 -0
  342. /package/dist/assets/{m3-C-Y9cBVI.js → m3-C2T3z3gB.js} +0 -0
  343. /package/dist/assets/{markdown-BHu-wLbe.js → markdown-CKq-Euj1.js} +0 -0
  344. /package/dist/assets/{mips-Dkds26rX.js → mips-Bcs5qIDX.js} +0 -0
  345. /package/dist/assets/{msdax-PU4g-8_g.js → msdax-CBP48FHF.js} +0 -0
  346. /package/dist/assets/{mysql-fPpuGpS7.js → mysql-c7tiPcFj.js} +0 -0
  347. /package/dist/assets/{objective-c-Wy1e5JUf.js → objective-c-D4BZkeEV.js} +0 -0
  348. /package/dist/assets/{pascal-BIXwvrqU.js → pascal-CJDZg0MN.js} +0 -0
  349. /package/dist/assets/{pascaligo-DwR0AtL_.js → pascaligo-Bygi8Ynl.js} +0 -0
  350. /package/dist/assets/{perl-CGHAl8my.js → perl-aS8bkf7E.js} +0 -0
  351. /package/dist/assets/{pgsql-B91M73E2.js → pgsql-CzNAYFYl.js} +0 -0
  352. /package/dist/assets/{php-C70ttrCx.js → php-DOtoEFTT.js} +0 -0
  353. /package/dist/assets/{pla-BNrXaRh0.js → pla-DugRnao1.js} +0 -0
  354. /package/dist/assets/{postiats-Dv2IAZR9.js → postiats-DsXwusKh.js} +0 -0
  355. /package/dist/assets/{powerquery-CkY5Wq7J.js → powerquery-DL3o72oD.js} +0 -0
  356. /package/dist/assets/{powershell-uGIYLU3C.js → powershell-C1qHekys.js} +0 -0
  357. /package/dist/assets/{protobuf-CavfmJu-.js → protobuf-DHgsc-cH.js} +0 -0
  358. /package/dist/assets/{pug-Drqnyitx.js → pug-FZXlE_Iu.js} +0 -0
  359. /package/dist/assets/{qrcode-7uGsTEmi.js → qrcode-DJDTdjL7.js} +0 -0
  360. /package/dist/assets/{qsharp-C7yF-Dti.js → qsharp-bLyhI3DT.js} +0 -0
  361. /package/dist/assets/{r-HXLGP0_-.js → r-DjFGXbAa.js} +0 -0
  362. /package/dist/assets/{redis-C4y6mf2p.js → redis-DSoZ_V6u.js} +0 -0
  363. /package/dist/assets/{redshift-DdQrFPrv.js → redshift-CzkdCsrg.js} +0 -0
  364. /package/dist/assets/{restructuredtext-CBrf2PNj.js → restructuredtext-B_XPrGCQ.js} +0 -0
  365. /package/dist/assets/{ruby-CVtMoX2B.js → ruby-Cry2RneJ.js} +0 -0
  366. /package/dist/assets/{rust-Ckq4sbMP.js → rust-CWzdbFq1.js} +0 -0
  367. /package/dist/assets/{sb-er66OpE3.js → sb-DmofU59h.js} +0 -0
  368. /package/dist/assets/{scala-BdWZz-hH.js → scala-BUC2l-vN.js} +0 -0
  369. /package/dist/assets/{scheme-kTV_s2kP.js → scheme-CNIB_72f.js} +0 -0
  370. /package/dist/assets/{scss-Bymy2VJQ.js → scss-DcL4-NbX.js} +0 -0
  371. /package/dist/assets/{shell-bwEP1LQ1.js → shell-CgAGvSSA.js} +0 -0
  372. /package/dist/assets/{solidity-DCddeBgL.js → solidity-DSkt6O_P.js} +0 -0
  373. /package/dist/assets/{sophia-BMN3AQig.js → sophia--5ytcjDN.js} +0 -0
  374. /package/dist/assets/{sparql-CSXOLjzi.js → sparql-C1Srr7cD.js} +0 -0
  375. /package/dist/assets/{sql-COg8ewmK.js → sql-2k_O5fj7.js} +0 -0
  376. /package/dist/assets/{st-CIaZtBS_.js → st-DCCCPqfz.js} +0 -0
  377. /package/dist/assets/{swift-DXiOhUHu.js → swift-Dd8mAfOt.js} +0 -0
  378. /package/dist/assets/{systemverilog-BTDE6Dr2.js → systemverilog-B0-aZYXu.js} +0 -0
  379. /package/dist/assets/{tcl-B0zy9NvV.js → tcl-CZAZwPVX.js} +0 -0
  380. /package/dist/assets/{twig-D594l4Z1.js → twig-D-Ag0tdS.js} +0 -0
  381. /package/dist/assets/{typespec-XKVjaPqo.js → typespec-B7kTFp0Z.js} +0 -0
  382. /package/dist/assets/{useWorkspaceMenuKeyboard-Bpy_s69Z.js → useWorkspaceMenuKeyboard-uYZpDxhU.js} +0 -0
  383. /package/dist/assets/{vb-B2wYoKRV.js → vb-20w1JPum.js} +0 -0
  384. /package/dist/assets/{wgsl-D0Yf2LbK.js → wgsl-CLJfqFt0.js} +0 -0
  385. /package/dist/assets/{workspace-working-copy-C3FSR3N6.js → workspace-working-copy-Cfz07cOd.js} +0 -0
@@ -1,74 +0,0 @@
1
- const express = require('express');
2
- const { ReviewSessionError } = require('./review-session-service');
3
-
4
- function sendError(res, error) {
5
- if (error instanceof ReviewSessionError) {
6
- res.status(error.statusCode).json({ error: error.message });
7
- return;
8
- }
9
- console.error('Review session API error:', error);
10
- res.status(500).json({ error: 'review session operation failed' });
11
- }
12
-
13
- function createReviewSessionRouter(service) {
14
- const router = express.Router();
15
- router.use(express.json({ limit: '16kb' }));
16
-
17
- router.post('/', async (req, res) => {
18
- try {
19
- res.status(201).json(await service.create({
20
- agentId: req.body?.agentId,
21
- base: req.body?.base,
22
- root: req.body?.root,
23
- ...(req.body?.modifiedWithinDays !== undefined ? { modifiedWithinDays: req.body.modifiedWithinDays } : {}),
24
- ...(req.body?.scope !== undefined ? { scope: req.body.scope } : {}),
25
- ...(req.body?.paths !== undefined ? { paths: req.body.paths } : {}),
26
- }));
27
- } catch (error) {
28
- sendError(res, error);
29
- }
30
- });
31
-
32
- router.post('/acp', async (req, res) => {
33
- try {
34
- res.status(201).json(await service.createFromAcp({
35
- agentId: req.body?.agentId,
36
- itemIds: req.body?.itemIds,
37
- }));
38
- } catch (error) {
39
- sendError(res, error);
40
- }
41
- });
42
-
43
- router.post('/acp/preview', async (req, res) => {
44
- try {
45
- res.json(await service.previewFromAcp({
46
- agentId: req.body?.agentId,
47
- itemIds: req.body?.itemIds,
48
- }));
49
- } catch (error) {
50
- sendError(res, error);
51
- }
52
- });
53
-
54
- router.get('/:reviewId', (req, res) => {
55
- try {
56
- res.json(service.get(req.params.reviewId));
57
- } catch (error) {
58
- sendError(res, error);
59
- }
60
- });
61
-
62
- router.post('/:reviewId/revisions', async (req, res) => {
63
- try {
64
- const result = await service.refresh(req.params.reviewId);
65
- res.status(result.unchanged ? 200 : 201).json(result);
66
- } catch (error) {
67
- sendError(res, error);
68
- }
69
- });
70
-
71
- return router;
72
- }
73
-
74
- module.exports = { createReviewSessionRouter };
@@ -1,446 +0,0 @@
1
- const fs = require('fs');
2
- const os = require('os');
3
- const path = require('path');
4
- const { createTwoFilesPatch, diffLines } = require('diff');
5
- const { OBJECT_ID_PATTERN, REVIEW_ID_PATTERN } = require('./review-session-store');
6
- const { filterWorkingCopyChangeItems, normalizeModifiedWithinDays, normalizeWorkingCopyScope } = require('./review-diff-service');
7
-
8
- const MAX_CAPTURE_FILES = 2000;
9
- const MAX_CAPTURE_PATHS = 256;
10
- const MAX_HISTORICAL_REVIEW_CHARS = 32 * 1024 * 1024;
11
- const MAX_HISTORICAL_PREVIEW_CHARS = 64 * 1024;
12
-
13
- class ReviewSessionError extends Error {
14
- constructor(message, statusCode = 400) {
15
- super(message);
16
- this.name = 'ReviewSessionError';
17
- this.statusCode = statusCode;
18
- }
19
- }
20
-
21
- function changedPathsFromNameStatus(value) {
22
- const tokens = String(value || '').split('\0');
23
- const paths = [];
24
- for (let index = 0; index < tokens.length;) {
25
- const status = tokens[index++];
26
- if (!status) continue;
27
- const firstPath = tokens[index++];
28
- if (firstPath) paths.push(firstPath);
29
- if (status.startsWith('R') || status.startsWith('C')) {
30
- const secondPath = tokens[index++];
31
- if (secondPath) paths.push(secondPath);
32
- }
33
- }
34
- return [...new Set(paths)];
35
- }
36
-
37
- function normalizeCapturePaths(value) {
38
- if (value === undefined) return undefined;
39
- if (!Array.isArray(value) || value.length > MAX_CAPTURE_PATHS) {
40
- throw new ReviewSessionError('review file paths are invalid');
41
- }
42
- if (value.some(candidate => typeof candidate !== 'string')) {
43
- throw new ReviewSessionError('review file paths are invalid');
44
- }
45
- const paths = value.map(candidate => candidate.replace(/\\/g, '/').trim());
46
- if (paths.some(candidate => (
47
- !candidate
48
- || candidate.length > 4096
49
- || candidate.startsWith('/')
50
- || candidate.includes('\0')
51
- || candidate.split('/').some(segment => !segment || segment === '.' || segment === '..')
52
- ))) {
53
- throw new ReviewSessionError('review file paths are invalid');
54
- }
55
- return [...new Set(paths)];
56
- }
57
-
58
- function historicalSidePresence(kind) {
59
- const normalized = String(kind || '').trim().toLowerCase();
60
- return {
61
- base: !['add', 'added', 'create', 'created'].includes(normalized),
62
- head: !['delete', 'deleted', 'remove', 'removed'].includes(normalized),
63
- };
64
- }
65
-
66
- function workspaceRelativeReviewPath(root, candidate) {
67
- if (typeof candidate !== 'string' || !candidate.trim()) return '';
68
- const raw = candidate.trim();
69
- const normalized = raw.replace(/\\/g, '/');
70
- let workspaceRoot = root;
71
- try {
72
- workspaceRoot = fs.realpathSync.native(root);
73
- } catch {
74
- // resolveRoot normally supplies an existing canonical workspace.
75
- }
76
- let absolute = path.isAbsolute(raw)
77
- ? path.resolve(raw)
78
- : path.resolve(workspaceRoot, normalized);
79
- const missingSegments = [];
80
- let existing = absolute;
81
- while (!fs.existsSync(existing) && path.dirname(existing) !== existing) {
82
- missingSegments.unshift(path.basename(existing));
83
- existing = path.dirname(existing);
84
- }
85
- try {
86
- absolute = path.join(fs.realpathSync.native(existing), ...missingSegments);
87
- } catch {
88
- // The normalized path below will reject anything outside the workspace.
89
- }
90
- const relative = path.relative(workspaceRoot, absolute).replace(/\\/g, '/');
91
- if (relative.split('/').includes('.git')) return '';
92
- try {
93
- return normalizeCapturePaths([relative])?.[0] || '';
94
- } catch {
95
- return '';
96
- }
97
- }
98
-
99
- function normalizeHistoricalReviewChanges(root, value, workspaceRoot = root) {
100
- if (!Array.isArray(value)) throw new ReviewSessionError('ACP review changes are invalid');
101
- const changesByPath = new Map();
102
- let totalChars = 0;
103
- for (const rawChange of value) {
104
- if (!rawChange || typeof rawChange !== 'object') continue;
105
- const displayPath = workspaceRelativeReviewPath(workspaceRoot, rawChange.path);
106
- if (!displayPath) continue;
107
- const absolutePath = path.resolve(workspaceRoot, displayPath);
108
- const reviewPath = workspaceRelativeReviewPath(root, absolutePath);
109
- if (!reviewPath) continue;
110
- const oldText = rawChange.oldText == null ? '' : String(rawChange.oldText);
111
- const newText = rawChange.newText == null ? '' : String(rawChange.newText);
112
- totalChars += Buffer.byteLength(oldText, 'utf8') + Buffer.byteLength(newText, 'utf8');
113
- if (totalChars > MAX_HISTORICAL_REVIEW_CHARS) {
114
- throw new ReviewSessionError('ACP review content is too large', 413);
115
- }
116
- const presence = historicalSidePresence(rawChange.kind);
117
- const current = changesByPath.get(reviewPath);
118
- if (!current) {
119
- changesByPath.set(reviewPath, {
120
- basePresent: presence.base,
121
- headPresent: presence.head,
122
- newText,
123
- oldText,
124
- path: reviewPath,
125
- ...(displayPath !== reviewPath ? { displayPath } : {}),
126
- });
127
- continue;
128
- }
129
- current.headPresent = presence.head;
130
- current.newText = newText;
131
- }
132
- const changes = [...changesByPath.values()];
133
- if (changes.length === 0) throw new ReviewSessionError('ACP review has no files inside this workspace');
134
- if (changes.length > MAX_CAPTURE_PATHS) throw new ReviewSessionError('ACP review has too many files', 413);
135
- return changes;
136
- }
137
-
138
- function historicalPreviewChange(change) {
139
- const oldText = change.basePresent ? change.oldText : '';
140
- const newText = change.headPresent ? change.newText : '';
141
- const stats = diffLines(oldText, newText).reduce((result, part) => {
142
- const count = Number(part.count || 0);
143
- if (part.added) result.added += count;
144
- if (part.removed) result.removed += count;
145
- return result;
146
- }, { added: 0, removed: 0 });
147
- const patch = createTwoFilesPatch(change.path, change.path, oldText, newText, 'before', 'after', { context: 3 });
148
- return {
149
- ...stats,
150
- diff: patch.length <= MAX_HISTORICAL_PREVIEW_CHARS
151
- ? patch
152
- : `${patch.slice(0, MAX_HISTORICAL_PREVIEW_CHARS)}\n\n[Diff detail truncated]`,
153
- kind: !change.basePresent ? 'added' : !change.headPresent ? 'deleted' : 'updated',
154
- path: change.displayPath || change.path,
155
- };
156
- }
157
-
158
- function publicRevision(session, revision) {
159
- const previous = revision.previousTree;
160
- return {
161
- base: session.base,
162
- createdAt: revision.createdAt,
163
- fixesBase: previous || session.base,
164
- head: revision.tree,
165
- number: revision.number,
166
- reviewId: session.id,
167
- root: session.root,
168
- ...(session.scope ? { scope: session.scope } : {}),
169
- ...(session.modifiedWithinDays ? { modifiedWithinDays: session.modifiedWithinDays } : {}),
170
- ...(session.paths ? { paths: session.paths } : {}),
171
- };
172
- }
173
-
174
- class ReviewSessionService {
175
- constructor(fileService, sessionStore, reviewStateStore, options = {}) {
176
- this.fileService = fileService;
177
- this.sessionStore = sessionStore;
178
- this.reviewStateStore = reviewStateStore;
179
- this.resolveAgentRoot = options.resolveAgentRoot;
180
- this.resolveAcpReviewChanges = options.resolveAcpReviewChanges;
181
- this.refreshQueues = new Map();
182
- }
183
-
184
- enqueueRefresh(reviewId, operation) {
185
- const previous = this.refreshQueues.get(reviewId) || Promise.resolve();
186
- const next = previous.catch(() => {}).then(operation);
187
- this.refreshQueues.set(reviewId, next);
188
- const cleanup = () => {
189
- if (this.refreshQueues.get(reviewId) === next) this.refreshQueues.delete(reviewId);
190
- };
191
- next.then(cleanup, cleanup);
192
- return next;
193
- }
194
-
195
- async git(root, args, options = {}) {
196
- try {
197
- return await this.fileService.execFile(this.fileService.gitPath, ['-C', root, ...args], {
198
- cwd: root,
199
- maxBuffer: this.fileService.diffMaxBuffer,
200
- timeout: this.fileService.diffTimeoutMs,
201
- ...options,
202
- });
203
- } catch (error) {
204
- if (error?.code === 'ETIMEDOUT') throw new ReviewSessionError('review capture timed out', 504);
205
- throw new ReviewSessionError(String(error?.stderr || error?.message || 'git review capture failed').trim(), 400);
206
- }
207
- }
208
-
209
- async resolveRoot(requestedRoot, agentId) {
210
- if (requestedRoot && agentId) throw new ReviewSessionError('only one review workspace target is allowed');
211
- let candidate = requestedRoot;
212
- if (!candidate && typeof agentId === 'string' && agentId.trim()) {
213
- candidate = this.resolveAgentRoot?.(agentId.trim());
214
- if (!candidate) throw new ReviewSessionError('review agent was not found', 404);
215
- }
216
- if (typeof candidate !== 'string' || !candidate.trim()) {
217
- throw new ReviewSessionError('review workspace target is required');
218
- }
219
- let root;
220
- try {
221
- root = fs.realpathSync.native(path.resolve(candidate));
222
- } catch {
223
- throw new ReviewSessionError('review root does not exist', 404);
224
- }
225
- const { stdout } = await this.git(root, ['rev-parse', '--show-toplevel']);
226
- try {
227
- return fs.realpathSync.native(stdout.trim());
228
- } catch {
229
- throw new ReviewSessionError('review root is not a git repository');
230
- }
231
- }
232
-
233
- async resolveBase(root, base) {
234
- if (typeof base !== 'string' || !base.trim() || base.trim().startsWith('-')) {
235
- throw new ReviewSessionError('review base is required');
236
- }
237
- const { stdout } = await this.git(root, ['rev-parse', '--verify', `${base.trim()}^{commit}`]);
238
- const resolved = stdout.trim();
239
- if (!OBJECT_ID_PATTERN.test(resolved)) throw new ReviewSessionError('review base is invalid');
240
- return resolved;
241
- }
242
-
243
- async captureTreeOnce(root, paths) {
244
- const temporaryDir = fs.mkdtempSync(path.join(os.tmpdir(), 'farming-review-capture-'));
245
- const temporaryIndex = path.join(temporaryDir, 'index');
246
- const env = { ...process.env, GIT_INDEX_FILE: temporaryIndex };
247
- try {
248
- await this.git(root, ['read-tree', 'HEAD'], { env });
249
- if (paths === undefined) {
250
- await this.git(root, ['add', '-A', '--', '.'], { env });
251
- } else if (paths.length > 0) {
252
- await this.git(root, ['add', '-A', '--', ...paths], { env });
253
- }
254
- const { stdout } = await this.git(root, ['write-tree'], { env });
255
- const tree = stdout.trim();
256
- if (!OBJECT_ID_PATTERN.test(tree)) throw new ReviewSessionError('git did not produce a review tree', 500);
257
- return tree;
258
- } finally {
259
- fs.rmSync(temporaryDir, { force: true, recursive: true });
260
- }
261
- }
262
-
263
- async captureStableTree(root, paths) {
264
- const first = await this.captureTreeOnce(root, paths);
265
- const second = await this.captureTreeOnce(root, paths);
266
- if (first !== second) {
267
- throw new ReviewSessionError('workspace changed during review capture; try again when agent writes have settled', 409);
268
- }
269
- return first;
270
- }
271
-
272
- async writeHistoricalTree(root, changes, side, temporaryDir) {
273
- const temporaryIndex = path.join(temporaryDir, `${side}.index`);
274
- const contentFile = path.join(temporaryDir, `${side}.content`);
275
- const env = { ...process.env, GIT_INDEX_FILE: temporaryIndex };
276
- await this.git(root, ['read-tree', '--empty'], { env });
277
- for (const change of changes) {
278
- const present = side === 'base' ? change.basePresent : change.headPresent;
279
- if (!present) continue;
280
- fs.writeFileSync(contentFile, side === 'base' ? change.oldText : change.newText, 'utf8');
281
- const { stdout: blobOutput } = await this.git(root, ['hash-object', '-w', contentFile]);
282
- const blob = blobOutput.trim();
283
- if (!OBJECT_ID_PATTERN.test(blob)) throw new ReviewSessionError('git did not produce a review blob', 500);
284
- await this.git(root, ['update-index', '--add', '--cacheinfo', '100644', blob, change.path], { env });
285
- }
286
- const { stdout } = await this.git(root, ['write-tree'], { env });
287
- const tree = stdout.trim();
288
- if (!OBJECT_ID_PATTERN.test(tree)) throw new ReviewSessionError('git did not produce a review tree', 500);
289
- return tree;
290
- }
291
-
292
- async captureHistoricalTrees(root, changes) {
293
- const temporaryDir = fs.mkdtempSync(path.join(os.tmpdir(), 'farming-review-history-'));
294
- try {
295
- const base = await this.writeHistoricalTree(root, changes, 'base', temporaryDir);
296
- const head = await this.writeHistoricalTree(root, changes, 'head', temporaryDir);
297
- return { base, head };
298
- } finally {
299
- fs.rmSync(temporaryDir, { force: true, recursive: true });
300
- }
301
- }
302
-
303
- async keepRevision(root, reviewId, number, tree) {
304
- await this.git(root, ['update-ref', `refs/farming/reviews/${reviewId}/${number}`, tree]);
305
- }
306
-
307
- async changedPaths(root, base, head) {
308
- const { stdout } = await this.git(root, ['diff', '--name-status', '-z', '--find-renames', base, head]);
309
- return changedPathsFromNameStatus(stdout);
310
- }
311
-
312
- async capturePaths(root, options = {}) {
313
- const requestedPaths = normalizeCapturePaths(options.paths);
314
- if (requestedPaths !== undefined) return requestedPaths;
315
- const scope = normalizeWorkingCopyScope(options.scope);
316
- if (!scope) return undefined;
317
- const changes = await this.fileService.changes(root, { limit: MAX_CAPTURE_FILES });
318
- if (changes.truncated) throw new ReviewSessionError('too many workspace files to capture this review', 413);
319
- const selected = filterWorkingCopyChangeItems(root, changes.items, {
320
- scope,
321
- modifiedWithinDays: options.modifiedWithinDays,
322
- });
323
- return [...new Set(selected.flatMap(change => [change.previousPath, change.path]).filter(Boolean))];
324
- }
325
-
326
- async create({ root: requestedRoot, agentId, base = 'HEAD', scope: requestedScope, modifiedWithinDays: requestedDays, paths: requestedPaths }) {
327
- const root = await this.resolveRoot(requestedRoot, agentId);
328
- const resolvedBase = await this.resolveBase(root, base);
329
- const scope = normalizeWorkingCopyScope(requestedScope);
330
- const explicitPaths = normalizeCapturePaths(requestedPaths);
331
- if (scope && explicitPaths !== undefined) throw new ReviewSessionError('review scope and file paths cannot be combined');
332
- const modifiedWithinDays = scope === 'untracked' ? normalizeModifiedWithinDays(requestedDays) : undefined;
333
- const paths = await this.capturePaths(root, { scope, modifiedWithinDays, paths: explicitPaths });
334
- const tree = await this.captureStableTree(root, paths);
335
- const reviewId = this.sessionStore.newId();
336
- await this.keepRevision(root, reviewId, 1, tree);
337
- const session = this.sessionStore.create({ base: resolvedBase, id: reviewId, root, tree, scope, modifiedWithinDays, paths: explicitPaths });
338
- return publicRevision(session, session.revisions[0]);
339
- }
340
-
341
- async createFromAcp({ agentId, itemIds }) {
342
- if (typeof this.resolveAcpReviewChanges !== 'function') {
343
- throw new ReviewSessionError('ACP review capture is unavailable', 501);
344
- }
345
- const { changes, root } = await this.resolveAcpChanges(agentId, itemIds);
346
- const { base, head } = await this.captureHistoricalTrees(root, changes);
347
- if (base === head) throw new ReviewSessionError('ACP review contains no effective file changes');
348
- const reviewId = this.sessionStore.newId();
349
- await this.git(root, ['update-ref', `refs/farming/reviews/${reviewId}/base`, base]);
350
- await this.keepRevision(root, reviewId, 1, head);
351
- const paths = changes.map(change => change.path);
352
- const session = this.sessionStore.create({ base, id: reviewId, root, tree: head, paths });
353
- return publicRevision(session, session.revisions[0]);
354
- }
355
-
356
- async resolveAcpChanges(agentId, itemIds) {
357
- const requestedWorkspace = typeof agentId === 'string' && agentId.trim()
358
- ? this.resolveAgentRoot?.(agentId.trim())
359
- : '';
360
- let workspaceRoot;
361
- try {
362
- workspaceRoot = requestedWorkspace ? fs.realpathSync.native(path.resolve(requestedWorkspace)) : '';
363
- } catch {
364
- throw new ReviewSessionError('review agent workspace does not exist', 404);
365
- }
366
- const root = await this.resolveRoot(undefined, agentId);
367
- let rawChanges;
368
- try {
369
- rawChanges = await this.resolveAcpReviewChanges(agentId, itemIds);
370
- } catch (error) {
371
- const message = String(error?.message || 'ACP review changes could not be loaded');
372
- const status = message === 'Agent not found' || message === 'ACP tool call not found'
373
- ? 404
374
- : message.includes('invalid') ? 400 : 409;
375
- throw new ReviewSessionError(message, status);
376
- }
377
- const changes = normalizeHistoricalReviewChanges(root, rawChanges, workspaceRoot || root);
378
- return { changes, root };
379
- }
380
-
381
- async previewFromAcp({ agentId, itemIds }) {
382
- const { changes } = await this.resolveAcpChanges(agentId, itemIds);
383
- return { changes: changes.map(historicalPreviewChange) };
384
- }
385
-
386
- async refresh(reviewId) {
387
- if (!REVIEW_ID_PATTERN.test(reviewId)) throw new ReviewSessionError('review session id is invalid');
388
- return this.enqueueRefresh(reviewId, async () => {
389
- const current = this.sessionStore.get(reviewId);
390
- if (!current) throw new ReviewSessionError('review session not found', 404);
391
- const paths = await this.capturePaths(current.root, current);
392
- const tree = await this.captureStableTree(current.root, paths);
393
- const previous = current.revisions[current.revisions.length - 1];
394
- if (previous.tree === tree) return { ...publicRevision(current, previous), changedPaths: [], unchanged: true };
395
- const nextNumber = previous.number + 1;
396
- const changedPaths = await this.changedPaths(current.root, previous.tree, tree);
397
- await this.keepRevision(current.root, reviewId, nextNumber, tree);
398
- const result = this.sessionStore.appendRevision(reviewId, tree);
399
- const next = result.session.revisions[result.session.revisions.length - 1];
400
- this.reviewStateStore?.inheritPatchset?.({
401
- changedPaths,
402
- nextPatchset: tree,
403
- previousPatchset: previous.tree,
404
- reviewId,
405
- });
406
- return { ...publicRevision(result.session, next), changedPaths, unchanged: false };
407
- });
408
- }
409
-
410
- get(reviewId) {
411
- if (!REVIEW_ID_PATTERN.test(reviewId)) throw new ReviewSessionError('review session id is invalid');
412
- const session = this.sessionStore.get(reviewId);
413
- if (!session) throw new ReviewSessionError('review session not found', 404);
414
- const latest = session.revisions[session.revisions.length - 1];
415
- return {
416
- ...publicRevision(session, latest),
417
- revisions: session.revisions.map(revision => publicRevision(session, revision)),
418
- };
419
- }
420
-
421
- assertRange(reviewId, requestedRoot, base, head) {
422
- if (!reviewId) return;
423
- if (!REVIEW_ID_PATTERN.test(reviewId)) throw new ReviewSessionError('review session id is invalid');
424
- const session = this.sessionStore.get(reviewId);
425
- if (!session) throw new ReviewSessionError('review session not found', 404);
426
- let root;
427
- try {
428
- root = fs.realpathSync.native(path.resolve(requestedRoot));
429
- } catch {
430
- throw new ReviewSessionError('review root does not exist', 404);
431
- }
432
- const revisionTrees = session.revisions.map(revision => revision.tree);
433
- const validBase = base === session.base || revisionTrees.includes(base);
434
- if (root !== session.root || !validBase || !revisionTrees.includes(head)) {
435
- throw new ReviewSessionError('review range does not belong to this session', 409);
436
- }
437
- }
438
- }
439
-
440
- module.exports = {
441
- changedPathsFromNameStatus,
442
- normalizeHistoricalReviewChanges,
443
- normalizeCapturePaths,
444
- ReviewSessionError,
445
- ReviewSessionService,
446
- };
@@ -1,151 +0,0 @@
1
- const crypto = require('crypto');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const { atomicWriteJson } = require('./atomic-json-store');
5
- const storageLayout = require('./storage-layout');
6
-
7
- const REVIEW_ID_PATTERN = /^review-[a-f0-9]{32}$/;
8
- const OBJECT_ID_PATTERN = /^[a-f0-9]{40,64}$/;
9
-
10
- function clone(value) {
11
- return JSON.parse(JSON.stringify(value));
12
- }
13
-
14
- function validRevision(value) {
15
- return value
16
- && typeof value === 'object'
17
- && OBJECT_ID_PATTERN.test(value.tree)
18
- && Number.isInteger(value.number)
19
- && value.number > 0
20
- && typeof value.createdAt === 'string'
21
- && (value.previousTree === undefined || OBJECT_ID_PATTERN.test(value.previousTree));
22
- }
23
-
24
- function validStoredPath(value) {
25
- return typeof value === 'string'
26
- && value.length > 0
27
- && value.length <= 4096
28
- && !value.startsWith('/')
29
- && !value.includes('\0')
30
- && value.split(/[\\/]/).every(segment => segment && segment !== '.' && segment !== '..');
31
- }
32
-
33
- function validSession(value) {
34
- return value
35
- && typeof value === 'object'
36
- && REVIEW_ID_PATTERN.test(value.id)
37
- && typeof value.root === 'string'
38
- && path.isAbsolute(value.root)
39
- && OBJECT_ID_PATTERN.test(value.base)
40
- && typeof value.createdAt === 'string'
41
- && typeof value.updatedAt === 'string'
42
- && (value.scope === undefined || value.scope === 'tracked' || value.scope === 'untracked')
43
- && (value.modifiedWithinDays === undefined || (Number.isInteger(value.modifiedWithinDays) && value.modifiedWithinDays >= 1 && value.modifiedWithinDays <= 3650))
44
- && (value.paths === undefined || (
45
- Array.isArray(value.paths)
46
- && value.paths.length <= 256
47
- && value.paths.every(validStoredPath)
48
- ))
49
- && Array.isArray(value.revisions)
50
- && value.revisions.length > 0
51
- && value.revisions.every(validRevision);
52
- }
53
-
54
- function normalizeState(value) {
55
- const sessions = value && typeof value === 'object' && value.sessions && typeof value.sessions === 'object'
56
- ? value.sessions
57
- : {};
58
- return {
59
- sessions: Object.fromEntries(Object.entries(sessions)
60
- .filter(([id, session]) => REVIEW_ID_PATTERN.test(id) && validSession(session) && session.id === id)),
61
- };
62
- }
63
-
64
- class ReviewSessionStore {
65
- constructor(configDir, options = {}) {
66
- this.file = options.file || storageLayout.reviewSessionsFile(configDir);
67
- this.writeJson = typeof options.writeJson === 'function'
68
- ? options.writeJson
69
- : (file, value) => atomicWriteJson(file, value, { trailingNewline: true });
70
- this.state = null;
71
- }
72
-
73
- ensureState() {
74
- if (this.state) return this.state;
75
- try {
76
- this.state = fs.existsSync(this.file)
77
- ? normalizeState(JSON.parse(fs.readFileSync(this.file, 'utf8')))
78
- : { sessions: {} };
79
- } catch (error) {
80
- console.warn('Failed to read Farming review sessions:', error && (error.message || error));
81
- this.state = { sessions: {} };
82
- }
83
- return this.state;
84
- }
85
-
86
- newId() {
87
- return `review-${crypto.randomUUID().replace(/-/g, '')}`;
88
- }
89
-
90
- get(reviewId) {
91
- if (!REVIEW_ID_PATTERN.test(reviewId)) return null;
92
- const session = this.ensureState().sessions[reviewId];
93
- return session ? clone(session) : null;
94
- }
95
-
96
- create({ id, root, base, tree, scope, modifiedWithinDays, paths, createdAt = new Date().toISOString() }) {
97
- if (!REVIEW_ID_PATTERN.test(id) || !path.isAbsolute(root) || !OBJECT_ID_PATTERN.test(base) || !OBJECT_ID_PATTERN.test(tree)) {
98
- throw new TypeError('invalid review session');
99
- }
100
- const currentState = this.ensureState();
101
- if (currentState.sessions[id]) throw new TypeError('review session already exists');
102
- const session = {
103
- base,
104
- createdAt,
105
- id,
106
- revisions: [{ createdAt, number: 1, tree }],
107
- root,
108
- ...(scope === 'tracked' || scope === 'untracked' ? { scope } : {}),
109
- ...(Number.isInteger(modifiedWithinDays) ? { modifiedWithinDays } : {}),
110
- ...(Array.isArray(paths) ? { paths: [...paths] } : {}),
111
- updatedAt: createdAt,
112
- };
113
- const nextState = {
114
- sessions: { ...currentState.sessions, [id]: session },
115
- };
116
- this.writeJson(this.file, nextState);
117
- this.state = nextState;
118
- return clone(session);
119
- }
120
-
121
- appendRevision(reviewId, tree, createdAt = new Date().toISOString()) {
122
- if (!OBJECT_ID_PATTERN.test(tree)) throw new TypeError('invalid review revision');
123
- const currentState = this.ensureState();
124
- const currentSession = currentState.sessions[reviewId];
125
- if (!currentSession) throw new TypeError('review session not found');
126
- const previous = currentSession.revisions[currentSession.revisions.length - 1];
127
- if (previous.tree === tree) return { added: false, session: clone(currentSession) };
128
- const nextSession = {
129
- ...currentSession,
130
- revisions: [...currentSession.revisions, {
131
- createdAt,
132
- number: previous.number + 1,
133
- previousTree: previous.tree,
134
- tree,
135
- }],
136
- updatedAt: createdAt,
137
- };
138
- const nextState = {
139
- sessions: { ...currentState.sessions, [reviewId]: nextSession },
140
- };
141
- this.writeJson(this.file, nextState);
142
- this.state = nextState;
143
- return { added: true, session: clone(nextSession) };
144
- }
145
- }
146
-
147
- module.exports = {
148
- OBJECT_ID_PATTERN,
149
- REVIEW_ID_PATTERN,
150
- ReviewSessionStore,
151
- };