diffing 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -7
- package/dist/cli-agent-BatQgghr.mjs +499 -0
- package/dist/cli-agent-BwZE05CQ.mjs +499 -0
- package/dist/cli-agent-CKE1Cvor.mjs +513 -0
- package/dist/cli-agent-CLvCYpmH.mjs +499 -0
- package/dist/cli-agent-CX8Fa1Ph.mjs +499 -0
- package/dist/cli-agent-SILzesQP.mjs +513 -0
- package/dist/cli-agent-USzLoAit.mjs +499 -0
- package/dist/cli-gh-BV5az425.mjs +147 -0
- package/dist/cli-gh-Bo6fOHQR.mjs +147 -0
- package/dist/cli-gh-D1LoWJl-.mjs +147 -0
- package/dist/cli-gh-D1sIZ-jX.mjs +147 -0
- package/dist/cli-gh-DROAJlHi.mjs +147 -0
- package/dist/cli-gh-DiT8BWwu.mjs +147 -0
- package/dist/cli.mjs +97 -3381
- package/dist/client/assets/{angular-html-DIKVmS-w.js → angular-html-CDZ9SrQX.js} +1 -1
- package/dist/client/assets/{angular-ts-DK13mfBQ.js → angular-ts-CNMbVia5.js} +1 -1
- package/dist/client/assets/{apl-NVZUxqwo.js → apl-BqNxQgsm.js} +1 -1
- package/dist/client/assets/{arc-kijUuucY.js → arc-BrMp-_55.js} +1 -1
- package/dist/client/assets/{architectureDiagram-3BPJPVTR-Dup-CzBS.js → architectureDiagram-3BPJPVTR-BIZJkdXp.js} +1 -1
- package/dist/client/assets/{astro-RPdCumat.js → astro-r55-Uy0e.js} +1 -1
- package/dist/client/assets/{blade-_ubz_KMD.js → blade-F8SZw05t.js} +1 -1
- package/dist/client/assets/{blockDiagram-GPEHLZMM-Cl0-G1MY.js → blockDiagram-GPEHLZMM-DlzFca7z.js} +1 -1
- package/dist/client/assets/{c-IEKcSTtW.js → c-DMmuyoXv.js} +1 -1
- package/dist/client/assets/{c4Diagram-AAUBKEIU-C3T6FV-K.js → c4Diagram-AAUBKEIU-BqJFYdcn.js} +1 -1
- package/dist/client/assets/channel-DVxVbqCb.js +1 -0
- package/dist/client/assets/{chunk-2J33WTMH-B5MFxFjX.js → chunk-2J33WTMH-CRN3t_Zt.js} +1 -1
- package/dist/client/assets/{chunk-3OPIFGDE-DWxCOZgI.js → chunk-3OPIFGDE-Bb8pGWXE.js} +1 -1
- package/dist/client/assets/{chunk-4BX2VUAB-DWdovlBC.js → chunk-4BX2VUAB--s6olL4E.js} +1 -1
- package/dist/client/assets/{chunk-55IACEB6-CFSaZijP.js → chunk-55IACEB6-C-iaNYfB.js} +1 -1
- package/dist/client/assets/{chunk-5ZQYHXKU-BH_cLkIj.js → chunk-5ZQYHXKU-Bvzi1CUr.js} +1 -1
- package/dist/client/assets/{chunk-727SXJPM-BbsJC2PT.js → chunk-727SXJPM-CjoyjZeg.js} +1 -1
- package/dist/client/assets/{chunk-AQP2D5EJ-tFAP6fC1.js → chunk-AQP2D5EJ-BJJOqjwm.js} +1 -1
- package/dist/client/assets/{chunk-BSJP7CBP-BGuhsdwy.js → chunk-BSJP7CBP-A0UL_0xV.js} +1 -1
- package/dist/client/assets/{chunk-CSCIHK7Q-DXSJWhsY.js → chunk-CSCIHK7Q-DW570vKT.js} +1 -1
- package/dist/client/assets/{chunk-FMBD7UC4-6vBylg_I.js → chunk-FMBD7UC4-CzNJ-Iy-.js} +1 -1
- package/dist/client/assets/{chunk-KSCS5N6A-C7iBFsUg.js → chunk-KSCS5N6A-DCbYTAZg.js} +1 -1
- package/dist/client/assets/{chunk-L5ZTLDWV-CRU3nvaK.js → chunk-L5ZTLDWV-BMdyyjjc.js} +1 -1
- package/dist/client/assets/{chunk-LZXEDZCA-6ppA-_4h.js → chunk-LZXEDZCA-BENQV-I4.js} +2 -2
- package/dist/client/assets/{chunk-ND2GUHAM-D1cTmgHe.js → chunk-ND2GUHAM-C1y3WzOx.js} +1 -1
- package/dist/client/assets/{chunk-NZK2D7GU-CpUab6v7.js → chunk-NZK2D7GU-BkBT6O_M.js} +1 -1
- package/dist/client/assets/{chunk-O5CBEL6O-cDxBycWe.js → chunk-O5CBEL6O-jdz4J9aA.js} +1 -1
- package/dist/client/assets/chunk-QZHKN3VN-mumapnEV.js +1 -0
- package/dist/client/assets/chunk-WU5MYG2G-Bsqs8ZKl.js +1 -0
- package/dist/client/assets/{chunk-XPW4576I-CI9GEEdy.js → chunk-XPW4576I-Bf8OI8wY.js} +1 -1
- package/dist/client/assets/classDiagram-4FO5ZUOK-CKaaw3uU.js +1 -0
- package/dist/client/assets/classDiagram-v2-Q7XG4LA2-BxwzeqDR.js +1 -0
- package/dist/client/assets/{cobol-BVhbHJgp.js → cobol-BanHX5pe.js} +1 -1
- package/dist/client/assets/{coffee-gY6asS_B.js → coffee-CACo0LEP.js} +1 -1
- package/dist/client/assets/{cose-bilkent-S5V4N54A-BOs7zxZa.js → cose-bilkent-S5V4N54A-7mNCsL0j.js} +1 -1
- package/dist/client/assets/{cpp-el3R6exS.js → cpp-4Kwtmkwn.js} +1 -1
- package/dist/client/assets/{crystal-D2_0btIo.js → crystal-D1kAaPsE.js} +1 -1
- package/dist/client/assets/{css-DtPe7dg4.js → css-CCMEBYEn.js} +1 -1
- package/dist/client/assets/{dagre-BM42HDAG-CR_0cBOz.js → dagre-BM42HDAG-BTEYZegB.js} +1 -1
- package/dist/client/assets/{diagram-2AECGRRQ-D9um0wp2.js → diagram-2AECGRRQ-Cj_XZNTN.js} +1 -1
- package/dist/client/assets/{diagram-5GNKFQAL-Dx0TEfBJ.js → diagram-5GNKFQAL-DVTFfYPd.js} +1 -1
- package/dist/client/assets/{diagram-KO2AKTUF-DjBHOuUD.js → diagram-KO2AKTUF-C7BU5Ncp.js} +1 -1
- package/dist/client/assets/{diagram-LMA3HP47-CK2MO5Gx.js → diagram-LMA3HP47-06rwT7mb.js} +1 -1
- package/dist/client/assets/{diagram-OG6HWLK6-CANQancN.js → diagram-OG6HWLK6-COEuKA9B.js} +1 -1
- package/dist/client/assets/{dist-DGlwcsQQ.js → dist-C-G1vI6B.js} +1 -1
- package/dist/client/assets/{edge-Ch_PYBsB.js → edge-BV-WbkC9.js} +1 -1
- package/dist/client/assets/{elixir-DEJrJATq.js → elixir-C6pMvu6H.js} +1 -1
- package/dist/client/assets/{elm-Brlko4-d.js → elm-D8LnUrCG.js} +1 -1
- package/dist/client/assets/{erDiagram-TEJ5UH35-Dnfrs6yk.js → erDiagram-TEJ5UH35-SPxPVg85.js} +1 -1
- package/dist/client/assets/{erb-DQPphNua.js → erb-C6ADBE0Q.js} +1 -1
- package/dist/client/assets/{flowDiagram-I6XJVG4X-BNMdFtjG.js → flowDiagram-I6XJVG4X-DyEhCtUv.js} +1 -1
- package/dist/client/assets/{ganttDiagram-6RSMTGT7-X-fPXz_A.js → ganttDiagram-6RSMTGT7-fj-zRHIk.js} +1 -1
- package/dist/client/assets/{git-rebase-BpS915SI.js → git-rebase-BhYZ4R3x.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-PVQCEYII-CRN_dRXM.js → gitGraphDiagram-PVQCEYII-CpUJh4CR.js} +1 -1
- package/dist/client/assets/{glimmer-js-DZDngVuD.js → glimmer-js-D2CVO-NF.js} +1 -1
- package/dist/client/assets/{glimmer-ts-DKNjJvyp.js → glimmer-ts-BjYisPeM.js} +1 -1
- package/dist/client/assets/{glsl-C-Y1tHoU.js → glsl-qP0lyfIY.js} +1 -1
- package/dist/client/assets/{graphql-DYVBNazO.js → graphql-BZE_lBur.js} +1 -1
- package/dist/client/assets/{hack-DewKAtLe.js → hack-C6KM9SLG.js} +1 -1
- package/dist/client/assets/{haml-CIA_AeXu.js → haml-BT3JKqL8.js} +1 -1
- package/dist/client/assets/{handlebars-Bade6JXX.js → handlebars-SHKYyRQ6.js} +1 -1
- package/dist/client/assets/{html-C4hhbuGp.js → html-CAc9HUGa.js} +1 -1
- package/dist/client/assets/{html-derivative-BXfztBtv.js → html-derivative-Cu6n_YRN.js} +1 -1
- package/dist/client/assets/{http-Cq90-CTl.js → http-o21PuOy8.js} +1 -1
- package/dist/client/assets/{hurl-DklQHYoa.js → hurl-ClrxMWQi.js} +1 -1
- package/dist/client/assets/{index-j9gqGQit.js → index-BPI8nJUS.js} +98 -98
- package/dist/client/assets/index-F_YfUisJ.css +1 -0
- package/dist/client/assets/{infoDiagram-5YYISTIA-Ht-AcvP4.js → infoDiagram-5YYISTIA-DDYGwUUs.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-k_l70iFb.js → ishikawaDiagram-YF4QCWOH-Benmqbm6.js} +1 -1
- package/dist/client/assets/{java-BMUwLm1h.js → java-Bmlmy6B3.js} +1 -1
- package/dist/client/assets/{javascript-B8nPCUVp.js → javascript-Bdrc0lyI.js} +1 -1
- package/dist/client/assets/{jinja-CkxiRcB3.js → jinja-DBkct7nV.js} +1 -1
- package/dist/client/assets/{jison-CFnN5uQs.js → jison-Tb1xkShc.js} +1 -1
- package/dist/client/assets/{journeyDiagram-JHISSGLW-C98PUC9Y.js → journeyDiagram-JHISSGLW-CCkv1GnE.js} +1 -1
- package/dist/client/assets/{json-B7HNnjIx.js → json-DwLxGyui.js} +1 -1
- package/dist/client/assets/{jsx-BfVPuW3i.js → jsx-DWSSTqEB.js} +1 -1
- package/dist/client/assets/{julia-Bj0ETGjT.js → julia-LUN3XhcV.js} +1 -1
- package/dist/client/assets/{just-CqIe_c9k.js → just-C6LrD5tm.js} +1 -1
- package/dist/client/assets/{kanban-definition-UN3LZRKU-BE-uvH7w.js → kanban-definition-UN3LZRKU-CQSBf6Ys.js} +1 -1
- package/dist/client/assets/{latex-Cvy8E64e.js → latex-aaU-rirg.js} +1 -1
- package/dist/client/assets/{line-BpooNUgm.js → line-DG7hZYkR.js} +1 -1
- package/dist/client/assets/{linear-CM6ZoyCp.js → linear-A5s-ps1u.js} +1 -1
- package/dist/client/assets/{liquid-x09l8QqE.js → liquid-BhVOoUfG.js} +1 -1
- package/dist/client/assets/{lua-BSlDLjt5.js → lua-BTF9vmdD.js} +1 -1
- package/dist/client/assets/{marko-CoNMQlTn.js → marko-DlwBrpd_.js} +1 -1
- package/dist/client/assets/{mdc-BSzVESPu.js → mdc-H8mdhEag.js} +1 -1
- package/dist/client/assets/{mermaid-parser.core-BDXJMxHu.js → mermaid-parser.core-BKvEMhB3.js} +1 -1
- package/dist/client/assets/{mermaid.core-Dw-_vXTc.js → mermaid.core-BaDGp29W.js} +3 -3
- package/dist/client/assets/{mindmap-definition-RKZ34NQL-BTxGT8rM.js → mindmap-definition-RKZ34NQL-BCrf7cJv.js} +1 -1
- package/dist/client/assets/{nginx-CBhJTj0i.js → nginx-DoaqXoFJ.js} +1 -1
- package/dist/client/assets/{nim-CtHbOBlO.js → nim-DqoAP4Np.js} +1 -1
- package/dist/client/assets/{perl-DLMzG3tu.js → perl-D1ou0isN.js} +1 -1
- package/dist/client/assets/{php-KomVR3Hz.js → php-DL6kQj3i.js} +1 -1
- package/dist/client/assets/{pieDiagram-4H26LBE5-BBUObAJW.js → pieDiagram-4H26LBE5-CF0X4ECG.js} +1 -1
- package/dist/client/assets/{pug-T4SRLx8P.js → pug-Bn3xDPVT.js} +1 -1
- package/dist/client/assets/{qml-DJdSRUmU.js → qml-CaA5S6hT.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-W4KKPZXB-B7vvauZv.js → quadrantDiagram-W4KKPZXB-A76pK4Cy.js} +1 -1
- package/dist/client/assets/{r-CwuTg9lK.js → r-DuUvfJBZ.js} +1 -1
- package/dist/client/assets/{razor-Ch4dgsGY.js → razor-DOv4xAWl.js} +1 -1
- package/dist/client/assets/{regexp-D2GTwJE0.js → regexp-DXetztjB.js} +1 -1
- package/dist/client/assets/{requirementDiagram-4Y6WPE33-DpcNiR3Y.js → requirementDiagram-4Y6WPE33-Cju--fB8.js} +1 -1
- package/dist/client/assets/{rst-D78f0DyR.js → rst-CDn5EUee.js} +1 -1
- package/dist/client/assets/{ruby-BUcw6ITs.js → ruby-40qcnJX-.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-5OEKKPKP-ChzSQD2O.js → sankeyDiagram-5OEKKPKP-CvkQY1O-.js} +1 -1
- package/dist/client/assets/{sas-DoT2JDsj.js → sas-D3a9oRtu.js} +1 -1
- package/dist/client/assets/{scss-B6G_d-6b.js → scss-BJ8ZKq49.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-3UESZ5HK-CzkdL8s7.js → sequenceDiagram-3UESZ5HK-DKU8lZlC.js} +1 -1
- package/dist/client/assets/{shellscript-DI252Bga.js → shellscript-yTgK8aYT.js} +1 -1
- package/dist/client/assets/{shellsession-BuO_s8FQ.js → shellsession-DrVaQSNg.js} +1 -1
- package/dist/client/assets/{soy-DZTZJTEE.js → soy-BasCadaZ.js} +1 -1
- package/dist/client/assets/{sql-C4isoJr_.js → sql-COJH6ALP.js} +1 -1
- package/dist/client/assets/{src-BMvz5HE8.js → src-BokBJ4oL.js} +1 -1
- package/dist/client/assets/{stata-Dhu6qITh.js → stata-Ble9lhMp.js} +1 -1
- package/dist/client/assets/{stateDiagram-AJRCARHV-DvYcrdap.js → stateDiagram-AJRCARHV-9IU9PT8A.js} +1 -1
- package/dist/client/assets/stateDiagram-v2-BHNVJYJU-Ce46Lf8G.js +1 -0
- package/dist/client/assets/{surrealql-CSDpq5j3.js → surrealql-BZ5cQJLk.js} +1 -1
- package/dist/client/assets/{svelte-C4ITAvxr.js → svelte-CLa9l6VK.js} +1 -1
- package/dist/client/assets/{templ-BTgKA9-7.js → templ-DVKkE2Tb.js} +1 -1
- package/dist/client/assets/{tex-Dg4N9ndP.js → tex-BET3iISl.js} +1 -1
- package/dist/client/assets/{timeline-definition-PNZ67QCA-Djt5Lwk2.js → timeline-definition-PNZ67QCA-CkkYIhNz.js} +1 -1
- package/dist/client/assets/{ts-tags-BufYnYos.js → ts-tags-D5fPAs5W.js} +1 -1
- package/dist/client/assets/{tsx-DmkFP0sw.js → tsx-CfNzz9iB.js} +1 -1
- package/dist/client/assets/{twig-BJv_IWYK.js → twig-_Ml9CBGK.js} +1 -1
- package/dist/client/assets/{typescript-BKp05Qme.js → typescript-DMiV0dhX.js} +1 -1
- package/dist/client/assets/{vennDiagram-CIIHVFJN-DDVADTIa.js → vennDiagram-CIIHVFJN-HUv6L4Dt.js} +1 -1
- package/dist/client/assets/{vue-BsHXCXzh.js → vue-BcbmWIQt.js} +1 -1
- package/dist/client/assets/{vue-html-CCsH-lmo.js → vue-html-CcUgk6WA.js} +1 -1
- package/dist/client/assets/{vue-vine-B5P1JXxo.js → vue-vine-BbIBT3jy.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-YWT4CUSO-yeVKWvtX.js → wardleyDiagram-YWT4CUSO-avUfWkuC.js} +1 -1
- package/dist/client/assets/{xml-CFkhYff0.js → xml-9mtlBTUG.js} +1 -1
- package/dist/client/assets/{xsl-Dc5XRzm6.js → xsl-Dm8BN5j0.js} +1 -1
- package/dist/client/assets/{xychartDiagram-2RQKCTM6--8Ik-9v0.js → xychartDiagram-2RQKCTM6-BSZPOH7-.js} +1 -1
- package/dist/client/assets/{yaml-BTCCxCxi.js → yaml-Ccz1qKlL.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/mcp-B6mCC7D3.mjs +1047 -0
- package/dist/mcp-BMTZLQuB.mjs +758 -0
- package/dist/mcp-BUF2nEL7.mjs +1036 -0
- package/dist/mcp-Bpx76OGU.mjs +945 -0
- package/dist/mcp-C1T7LI0H.mjs +1036 -0
- package/dist/mcp-C4Bjmf9m.mjs +1047 -0
- package/dist/mcp-CFxcdEcJ.mjs +733 -0
- package/dist/mcp-CwjThGi2.mjs +913 -0
- package/dist/mcp-D4OsB9lt.mjs +1047 -0
- package/dist/mcp-DJ2batvt.mjs +913 -0
- package/dist/mcp-D_LGvBTw.mjs +1047 -0
- package/dist/mcp-Ds_lPX_o.mjs +913 -0
- package/dist/plan-format-B6nbAw_c.mjs +132 -0
- package/dist/server-95UE5bgh.mjs +3367 -0
- package/dist/server-B0cS95Lf.mjs +3488 -0
- package/dist/server-Bj-6KlK5.mjs +3367 -0
- package/dist/server-Bpf84Il0.mjs +3367 -0
- package/dist/server-CYSpLbdA.mjs +3360 -0
- package/dist/server-ChT2DCaR.mjs +3701 -0
- package/dist/server-DJxysGxV.mjs +3701 -0
- package/dist/server-Dov7jbV3.mjs +3367 -0
- package/dist/server-eQ2E4Axo.mjs +3367 -0
- package/dist/server-lock-C_wPtEsH.mjs +909 -0
- package/dist/server-lock-Cbu3qHdu.mjs +924 -0
- package/dist/server-lock-D32inEn9.mjs +924 -0
- package/dist/server-lock-Ddcat0HF.mjs +851 -0
- package/dist/server-lock-Dq_1CJaF.mjs +1047 -0
- package/dist/server-lock-Ujbcgq28.mjs +954 -0
- package/dist/update-check-CXeSZANo.mjs +129 -0
- package/package.json +3 -2
- package/dist/client/assets/channel-CpWSvbvQ.js +0 -1
- package/dist/client/assets/chunk-QZHKN3VN-HhMIifwl.js +0 -1
- package/dist/client/assets/chunk-WU5MYG2G-CvIzXEms.js +0 -1
- package/dist/client/assets/classDiagram-4FO5ZUOK-DFu-dNVy.js +0 -1
- package/dist/client/assets/classDiagram-v2-Q7XG4LA2-D7Xcgo6q.js +0 -1
- package/dist/client/assets/index-CMyunQt6.css +0 -1
- package/dist/client/assets/stateDiagram-v2-BHNVJYJU-D5igY81I.js +0 -1
|
@@ -0,0 +1,909 @@
|
|
|
1
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
2
|
+
import { basename, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { parseSync } from "editorconfig";
|
|
9
|
+
//#region src/lib/path.ts
|
|
10
|
+
function decodeAndNormalize(p) {
|
|
11
|
+
let decoded = p;
|
|
12
|
+
try {
|
|
13
|
+
decoded = decodeURIComponent(p);
|
|
14
|
+
} catch {}
|
|
15
|
+
return decoded.replace(/\\/g, "/");
|
|
16
|
+
}
|
|
17
|
+
function toSafeRelativePath(filePath, baseDir) {
|
|
18
|
+
const normalized = decodeAndNormalize(filePath);
|
|
19
|
+
if (normalized.includes("..") || normalized.includes("\0")) return null;
|
|
20
|
+
const resolved = resolve(baseDir, normalized);
|
|
21
|
+
const resolvedBase = resolve(baseDir);
|
|
22
|
+
if (!(resolved === resolvedBase || resolved.startsWith(resolvedBase + sep))) return null;
|
|
23
|
+
return relative(resolvedBase, resolved);
|
|
24
|
+
}
|
|
25
|
+
function isSafePath(relativePath, baseDir) {
|
|
26
|
+
return toSafeRelativePath(relativePath, baseDir) !== null;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/lib/git.ts
|
|
30
|
+
const execFileAsync = promisify(execFile);
|
|
31
|
+
function splitLines(content) {
|
|
32
|
+
return content.split(/\r\n|\n|\r/);
|
|
33
|
+
}
|
|
34
|
+
function isBinaryFile(absolutePath) {
|
|
35
|
+
try {
|
|
36
|
+
const buffer = readFileSync(absolutePath);
|
|
37
|
+
const bytesToCheck = Math.min(buffer.length, 8192);
|
|
38
|
+
for (let i = 0; i < bytesToCheck; i++) if (buffer[i] === 0) return true;
|
|
39
|
+
return false;
|
|
40
|
+
} catch {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function getFileContent(filePath, version) {
|
|
45
|
+
const root = getRepoRoot();
|
|
46
|
+
const relPath = toSafeRelativePath(filePath, root);
|
|
47
|
+
if (!relPath) return null;
|
|
48
|
+
const resolved = resolve(root, relPath);
|
|
49
|
+
if (version === "new") try {
|
|
50
|
+
return readFileSync(resolved);
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
return execFileSync("git", ["show", `HEAD:${relPath}`], {
|
|
56
|
+
stdio: "pipe",
|
|
57
|
+
maxBuffer: 50 * 1024 * 1024
|
|
58
|
+
});
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let cachedRepoRoot = null;
|
|
64
|
+
const editorConfigCache = /* @__PURE__ */ new Map();
|
|
65
|
+
function isGitRepo() {
|
|
66
|
+
try {
|
|
67
|
+
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], { stdio: "pipe" });
|
|
68
|
+
return true;
|
|
69
|
+
} catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function getRepoRoot() {
|
|
74
|
+
if (cachedRepoRoot !== null) return cachedRepoRoot;
|
|
75
|
+
cachedRepoRoot = execFileSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf-8" }).trim();
|
|
76
|
+
return cachedRepoRoot;
|
|
77
|
+
}
|
|
78
|
+
function getRepoName() {
|
|
79
|
+
return basename(getRepoRoot());
|
|
80
|
+
}
|
|
81
|
+
function getBranchName() {
|
|
82
|
+
try {
|
|
83
|
+
return execFileSync("git", [
|
|
84
|
+
"rev-parse",
|
|
85
|
+
"--abbrev-ref",
|
|
86
|
+
"HEAD"
|
|
87
|
+
], {
|
|
88
|
+
stdio: "pipe",
|
|
89
|
+
encoding: "utf-8"
|
|
90
|
+
}).trim();
|
|
91
|
+
} catch {
|
|
92
|
+
return "";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const DIFF_FLAGS = ["--no-ext-diff", "--no-color"];
|
|
96
|
+
function getTabSizeForFiles(filePaths) {
|
|
97
|
+
const root = getRepoRoot();
|
|
98
|
+
const result = {};
|
|
99
|
+
for (const filePath of filePaths) try {
|
|
100
|
+
const config = parseSync(join(root, filePath), { cache: editorConfigCache });
|
|
101
|
+
const size = config.tab_width ?? (config.indent_size === "tab" ? void 0 : config.indent_size);
|
|
102
|
+
if (typeof size === "number") result[filePath] = size;
|
|
103
|
+
} catch {}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
async function getRepoRootAsync() {
|
|
107
|
+
if (cachedRepoRoot !== null) return cachedRepoRoot;
|
|
108
|
+
try {
|
|
109
|
+
const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf-8" });
|
|
110
|
+
cachedRepoRoot = stdout.trim();
|
|
111
|
+
return cachedRepoRoot;
|
|
112
|
+
} catch {
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function getUntrackedFilePathsAsync() {
|
|
117
|
+
try {
|
|
118
|
+
const { stdout } = await execFileAsync("git", [
|
|
119
|
+
"ls-files",
|
|
120
|
+
"--others",
|
|
121
|
+
"--exclude-standard"
|
|
122
|
+
], {
|
|
123
|
+
encoding: "utf-8",
|
|
124
|
+
maxBuffer: 50 * 1024 * 1024
|
|
125
|
+
});
|
|
126
|
+
const trimmed = stdout.trim();
|
|
127
|
+
return trimmed ? trimmed.split("\n") : [];
|
|
128
|
+
} catch {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function getUntrackedFilesDiffAsync() {
|
|
133
|
+
const root = await getRepoRootAsync();
|
|
134
|
+
const filePaths = await getUntrackedFilePathsAsync();
|
|
135
|
+
if (filePaths.length === 0) return "";
|
|
136
|
+
const patches = [];
|
|
137
|
+
const fileDiffPromises = filePaths.map(async (file) => {
|
|
138
|
+
const absolutePath = join(root, file);
|
|
139
|
+
if (isBinaryFile(absolutePath)) return [
|
|
140
|
+
`diff --git a/${file} b/${file}`,
|
|
141
|
+
"new file mode 100644",
|
|
142
|
+
"index 0000000..0000001",
|
|
143
|
+
`Binary files /dev/null and b/${file} differ`
|
|
144
|
+
].join("\n");
|
|
145
|
+
else try {
|
|
146
|
+
const lines = splitLines(await readFile(absolutePath, "utf-8"));
|
|
147
|
+
const diffLines = lines.map((l) => `+${l}`);
|
|
148
|
+
return [
|
|
149
|
+
`diff --git a/${file} b/${file}`,
|
|
150
|
+
"new file mode 100644",
|
|
151
|
+
"index 0000000..0000001",
|
|
152
|
+
"--- /dev/null",
|
|
153
|
+
`+++ b/${file}`,
|
|
154
|
+
`@@ -0,0 +1,${lines.length} @@`,
|
|
155
|
+
...diffLines
|
|
156
|
+
].join("\n");
|
|
157
|
+
} catch {
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const results = await Promise.all(fileDiffPromises);
|
|
162
|
+
for (const r of results) if (r) patches.push(r);
|
|
163
|
+
return patches.length > 0 ? "\n" + patches.join("\n") : "";
|
|
164
|
+
}
|
|
165
|
+
async function getCustomGitDiffAsync(args) {
|
|
166
|
+
try {
|
|
167
|
+
const { stdout } = await execFileAsync("git", [
|
|
168
|
+
"diff",
|
|
169
|
+
...DIFF_FLAGS,
|
|
170
|
+
...args
|
|
171
|
+
], {
|
|
172
|
+
encoding: "utf-8",
|
|
173
|
+
maxBuffer: 50 * 1024 * 1024
|
|
174
|
+
});
|
|
175
|
+
return stdout;
|
|
176
|
+
} catch {
|
|
177
|
+
return "";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function getGitDiffAsync(options = {}) {
|
|
181
|
+
const unstagedPromise = execFileAsync("git", ["diff", ...DIFF_FLAGS], {
|
|
182
|
+
encoding: "utf-8",
|
|
183
|
+
maxBuffer: 50 * 1024 * 1024
|
|
184
|
+
}).then(({ stdout }) => stdout).catch(() => "");
|
|
185
|
+
const stagedPromise = options.staged ? execFileAsync("git", [
|
|
186
|
+
"diff",
|
|
187
|
+
...DIFF_FLAGS,
|
|
188
|
+
"--staged"
|
|
189
|
+
], {
|
|
190
|
+
encoding: "utf-8",
|
|
191
|
+
maxBuffer: 50 * 1024 * 1024
|
|
192
|
+
}).then(({ stdout }) => stdout).catch(() => "") : Promise.resolve("");
|
|
193
|
+
const untrackedPromise = options.untracked ? getUntrackedFilesDiffAsync() : Promise.resolve("");
|
|
194
|
+
const [unstaged, staged, untrackedPatch] = await Promise.all([
|
|
195
|
+
unstagedPromise,
|
|
196
|
+
stagedPromise,
|
|
197
|
+
untrackedPromise
|
|
198
|
+
]);
|
|
199
|
+
const parts = [];
|
|
200
|
+
if (unstaged) parts.push(unstaged);
|
|
201
|
+
if (staged) parts.push(staged);
|
|
202
|
+
if (untrackedPatch) parts.push(untrackedPatch);
|
|
203
|
+
return parts.join("\n");
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Lists every file the working tree knows about (tracked + untracked,
|
|
207
|
+
* excluding standard-ignored paths). Used by the Phase D file viewer to
|
|
208
|
+
* power a path picker.
|
|
209
|
+
*/
|
|
210
|
+
function listRepoFiles() {
|
|
211
|
+
try {
|
|
212
|
+
const tracked = execFileSync("git", ["ls-files"], {
|
|
213
|
+
encoding: "utf-8",
|
|
214
|
+
maxBuffer: 100 * 1024 * 1024
|
|
215
|
+
}).trim();
|
|
216
|
+
const untracked = execFileSync("git", [
|
|
217
|
+
"ls-files",
|
|
218
|
+
"--others",
|
|
219
|
+
"--exclude-standard"
|
|
220
|
+
], {
|
|
221
|
+
encoding: "utf-8",
|
|
222
|
+
maxBuffer: 100 * 1024 * 1024
|
|
223
|
+
}).trim();
|
|
224
|
+
const set = /* @__PURE__ */ new Set();
|
|
225
|
+
for (const list of [tracked, untracked]) {
|
|
226
|
+
if (!list) continue;
|
|
227
|
+
for (const line of list.split("\n")) if (line) set.add(line);
|
|
228
|
+
}
|
|
229
|
+
return [...set].sort();
|
|
230
|
+
} catch {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Reports whether the repo is currently in the middle of a merge and which
|
|
236
|
+
* files have unresolved conflicts. Used by the Phase C merge-conflict UI to
|
|
237
|
+
* decide when to render the @pierre/diffs UnresolvedFile component.
|
|
238
|
+
*/
|
|
239
|
+
function getMergeStatus() {
|
|
240
|
+
let root;
|
|
241
|
+
try {
|
|
242
|
+
root = getRepoRoot();
|
|
243
|
+
} catch {
|
|
244
|
+
return {
|
|
245
|
+
inMerge: false,
|
|
246
|
+
conflicts: []
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const mergeHead = join(root, ".git", "MERGE_HEAD");
|
|
250
|
+
let inMerge = false;
|
|
251
|
+
try {
|
|
252
|
+
readFileSync(mergeHead);
|
|
253
|
+
inMerge = true;
|
|
254
|
+
} catch {
|
|
255
|
+
inMerge = false;
|
|
256
|
+
}
|
|
257
|
+
let conflicts = [];
|
|
258
|
+
try {
|
|
259
|
+
const out = execFileSync("git", [
|
|
260
|
+
"diff",
|
|
261
|
+
"--name-only",
|
|
262
|
+
"--diff-filter=U"
|
|
263
|
+
], {
|
|
264
|
+
encoding: "utf-8",
|
|
265
|
+
maxBuffer: 50 * 1024 * 1024
|
|
266
|
+
}).trim();
|
|
267
|
+
conflicts = out ? out.split("\n") : [];
|
|
268
|
+
} catch {
|
|
269
|
+
conflicts = [];
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
inMerge: inMerge || conflicts.length > 0,
|
|
273
|
+
conflicts
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function gitAddFile(filePath) {
|
|
277
|
+
execFileSync("git", [
|
|
278
|
+
"add",
|
|
279
|
+
"--",
|
|
280
|
+
filePath
|
|
281
|
+
], { stdio: "pipe" });
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Returns a unified diff for a single working-tree file (covers unstaged
|
|
285
|
+
* and untracked changes). Used by the Phase E hunk-revert flow to derive
|
|
286
|
+
* the exact patch text we need to `git apply --reverse`.
|
|
287
|
+
*/
|
|
288
|
+
function getFilePatch(filePath) {
|
|
289
|
+
try {
|
|
290
|
+
const unstaged = execFileSync("git", [
|
|
291
|
+
"diff",
|
|
292
|
+
...DIFF_FLAGS,
|
|
293
|
+
"--",
|
|
294
|
+
filePath
|
|
295
|
+
], {
|
|
296
|
+
encoding: "utf-8",
|
|
297
|
+
maxBuffer: 50 * 1024 * 1024
|
|
298
|
+
});
|
|
299
|
+
if (unstaged) return unstaged;
|
|
300
|
+
} catch {}
|
|
301
|
+
try {
|
|
302
|
+
const absolutePath = join(getRepoRoot(), filePath);
|
|
303
|
+
if (isBinaryFile(absolutePath)) return "";
|
|
304
|
+
const lines = splitLines(readFileSync(absolutePath, "utf-8"));
|
|
305
|
+
return [
|
|
306
|
+
`diff --git a/${filePath} b/${filePath}`,
|
|
307
|
+
"new file mode 100644",
|
|
308
|
+
"index 0000000..0000001",
|
|
309
|
+
"--- /dev/null",
|
|
310
|
+
`+++ b/${filePath}`,
|
|
311
|
+
`@@ -0,0 +1,${lines.length} @@`,
|
|
312
|
+
...lines.map((l) => `+${l}`)
|
|
313
|
+
].join("\n");
|
|
314
|
+
} catch {
|
|
315
|
+
return "";
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Extracts the Nth hunk text from a single-file patch. Returns the lines
|
|
320
|
+
* from `@@ ... @@` through the line before the next `@@` (or EOF).
|
|
321
|
+
*/
|
|
322
|
+
function extractHunk(patch, hunkIndex) {
|
|
323
|
+
const lines = patch.split("\n");
|
|
324
|
+
const hunkStarts = [];
|
|
325
|
+
for (let i = 0; i < lines.length; i++) if (lines[i].startsWith("@@ ")) hunkStarts.push(i);
|
|
326
|
+
if (hunkIndex < 0 || hunkIndex >= hunkStarts.length) return null;
|
|
327
|
+
const start = hunkStarts[hunkIndex];
|
|
328
|
+
const end = hunkIndex + 1 < hunkStarts.length ? hunkStarts[hunkIndex + 1] : lines.length;
|
|
329
|
+
return lines.slice(start, end).join("\n");
|
|
330
|
+
}
|
|
331
|
+
/** Header lines that the per-file patch needs in order for `git apply` to
|
|
332
|
+
* recognize the target. Stops just before the first `@@` hunk header. */
|
|
333
|
+
function extractPatchHeader(patch) {
|
|
334
|
+
const lines = patch.split("\n");
|
|
335
|
+
const out = [];
|
|
336
|
+
for (const line of lines) {
|
|
337
|
+
if (line.startsWith("@@ ")) break;
|
|
338
|
+
out.push(line);
|
|
339
|
+
}
|
|
340
|
+
return out.join("\n");
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Reverts a single hunk from the working tree by piping a minimal patch to
|
|
344
|
+
* `git apply --reverse`. Throws if git rejects the apply (typically because
|
|
345
|
+
* the file has shifted since the diff was rendered).
|
|
346
|
+
*/
|
|
347
|
+
function revertHunk(filePath, hunkIndex) {
|
|
348
|
+
const patch = getFilePatch(filePath);
|
|
349
|
+
if (!patch) throw new Error("No diff available for this file");
|
|
350
|
+
const header = extractPatchHeader(patch);
|
|
351
|
+
const hunk = extractHunk(patch, hunkIndex);
|
|
352
|
+
if (!hunk) throw new Error(`Hunk ${hunkIndex} not found`);
|
|
353
|
+
execFileSync("git", [
|
|
354
|
+
"apply",
|
|
355
|
+
"--reverse",
|
|
356
|
+
"-"
|
|
357
|
+
], {
|
|
358
|
+
input: `${header}\n${hunk}\n`,
|
|
359
|
+
stdio: [
|
|
360
|
+
"pipe",
|
|
361
|
+
"pipe",
|
|
362
|
+
"pipe"
|
|
363
|
+
]
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function getProjectStorageDir(customRepoRoot) {
|
|
367
|
+
const root = customRepoRoot || getRepoRoot();
|
|
368
|
+
const hash = createHash("sha256").update(root).digest("hex").slice(0, 8);
|
|
369
|
+
const repoName = basename(root);
|
|
370
|
+
return join(homedir(), ".diffing", `${repoName}-${hash}`);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Retrieves git blame for deleted lines and recent log history for the file,
|
|
374
|
+
* providing context on what commit introduced the deleted code.
|
|
375
|
+
*/
|
|
376
|
+
function getHunkHistory(filePath, deletionStart, deletionCount, revision = "HEAD") {
|
|
377
|
+
if (!isSafePath(filePath, getRepoRoot())) throw new Error("Forbidden file path");
|
|
378
|
+
const blame = [];
|
|
379
|
+
if (deletionCount > 0) try {
|
|
380
|
+
const lines = execFileSync("git", [
|
|
381
|
+
"blame",
|
|
382
|
+
"--date=format:%Y-%m-%d",
|
|
383
|
+
"-L",
|
|
384
|
+
`${deletionStart},+${deletionCount}`,
|
|
385
|
+
revision,
|
|
386
|
+
"--",
|
|
387
|
+
filePath
|
|
388
|
+
], {
|
|
389
|
+
encoding: "utf-8",
|
|
390
|
+
maxBuffer: 10 * 1024 * 1024
|
|
391
|
+
}).split("\n");
|
|
392
|
+
const commitHashes = /* @__PURE__ */ new Set();
|
|
393
|
+
for (const line of lines) {
|
|
394
|
+
if (!line.trim()) continue;
|
|
395
|
+
const match = line.match(/^(\^?[0-9a-fA-F]+) \((.*?) (\d{4}-\d{2}-\d{2}) (\d+)\)(?: (.*))?$/);
|
|
396
|
+
if (match) {
|
|
397
|
+
const [_, commit, author, date, lineNum, content] = match;
|
|
398
|
+
const cleanCommit = commit.startsWith("^") ? commit.slice(1) : commit;
|
|
399
|
+
blame.push({
|
|
400
|
+
commit: cleanCommit,
|
|
401
|
+
author: author.trim(),
|
|
402
|
+
date,
|
|
403
|
+
line: parseInt(lineNum, 10),
|
|
404
|
+
content: content || "",
|
|
405
|
+
summary: ""
|
|
406
|
+
});
|
|
407
|
+
commitHashes.add(cleanCommit);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const commitSummaries = {};
|
|
411
|
+
for (const hash of commitHashes) try {
|
|
412
|
+
commitSummaries[hash] = execFileSync("git", [
|
|
413
|
+
"show",
|
|
414
|
+
"-s",
|
|
415
|
+
"--format=%s",
|
|
416
|
+
hash
|
|
417
|
+
], { encoding: "utf-8" }).trim();
|
|
418
|
+
} catch {
|
|
419
|
+
commitSummaries[hash] = "Unknown commit";
|
|
420
|
+
}
|
|
421
|
+
for (const entry of blame) entry.summary = commitSummaries[entry.commit] || "Unknown commit";
|
|
422
|
+
} catch (err) {
|
|
423
|
+
console.warn("Failed to get git blame for hunk history:", err.message);
|
|
424
|
+
}
|
|
425
|
+
const recentCommits = [];
|
|
426
|
+
try {
|
|
427
|
+
const logOut = execFileSync("git", [
|
|
428
|
+
"log",
|
|
429
|
+
"-n",
|
|
430
|
+
"5",
|
|
431
|
+
"--date=format:%Y-%m-%d",
|
|
432
|
+
"--format=%h|%an|%ad|%s",
|
|
433
|
+
"--",
|
|
434
|
+
filePath
|
|
435
|
+
], { encoding: "utf-8" });
|
|
436
|
+
for (const line of logOut.split("\n")) {
|
|
437
|
+
if (!line.trim()) continue;
|
|
438
|
+
const [hash, author, date, summary] = line.split("|");
|
|
439
|
+
if (hash && author && date && summary) recentCommits.push({
|
|
440
|
+
hash,
|
|
441
|
+
author: author.trim(),
|
|
442
|
+
date,
|
|
443
|
+
summary: summary.trim()
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
} catch (err) {
|
|
447
|
+
console.warn("Failed to get git log for hunk history:", err.message);
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
blame,
|
|
451
|
+
recentCommits
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Parse the output of `git log --pretty=raw -p` into `CommitInfo[]`.
|
|
456
|
+
*
|
|
457
|
+
* The `raw` format emits one record per commit:
|
|
458
|
+
*
|
|
459
|
+
* commit <sha>
|
|
460
|
+
* tree <sha>
|
|
461
|
+
* parent <sha> (zero or more; merges have ≥ 2)
|
|
462
|
+
* author <name> <email> <unix-time> <tz>
|
|
463
|
+
* committer <name> <email> <unix-time> <tz>
|
|
464
|
+
* gpgsig -----BEGIN ... (optional; continuation lines start with a single space)
|
|
465
|
+
* <indented body>
|
|
466
|
+
*
|
|
467
|
+
* <indented commit message — 4 spaces of indent>
|
|
468
|
+
*
|
|
469
|
+
* diff --git a/... b/... (the per-commit patch; may be empty)
|
|
470
|
+
* ...
|
|
471
|
+
*
|
|
472
|
+
* Records are separated by blank lines but the unambiguous boundary is the
|
|
473
|
+
* next line beginning with `commit <40-hex>` at column 0.
|
|
474
|
+
*/
|
|
475
|
+
function parseGitShowRaw(raw) {
|
|
476
|
+
if (!raw) return [];
|
|
477
|
+
const out = [];
|
|
478
|
+
const lines = raw.split("\n");
|
|
479
|
+
const starts = [];
|
|
480
|
+
for (let i = 0; i < lines.length; i++) if (/^commit [0-9a-f]{40}\b/.test(lines[i])) starts.push(i);
|
|
481
|
+
if (starts.length === 0) return [];
|
|
482
|
+
for (let s = 0; s < starts.length; s++) {
|
|
483
|
+
const begin = starts[s];
|
|
484
|
+
const end = s + 1 < starts.length ? starts[s + 1] : lines.length;
|
|
485
|
+
const info = parseSingleCommitRaw(lines.slice(begin, end));
|
|
486
|
+
if (info) out.push(info);
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
function parseSingleCommitRaw(lines) {
|
|
491
|
+
const shaMatch = (lines[0] ?? "").match(/^commit ([0-9a-f]{40})/);
|
|
492
|
+
if (!shaMatch) return null;
|
|
493
|
+
const sha = shaMatch[1];
|
|
494
|
+
let i = 1;
|
|
495
|
+
const parents = [];
|
|
496
|
+
let authorName = "";
|
|
497
|
+
let authorEmail = "";
|
|
498
|
+
let authorDate = "";
|
|
499
|
+
let committerName = "";
|
|
500
|
+
let committerEmail = "";
|
|
501
|
+
let committerDate = "";
|
|
502
|
+
while (i < lines.length) {
|
|
503
|
+
const line = lines[i];
|
|
504
|
+
if (line === "") break;
|
|
505
|
+
if (line.startsWith(" ")) {
|
|
506
|
+
i++;
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const idx = line.indexOf(" ");
|
|
510
|
+
const key = idx === -1 ? line : line.slice(0, idx);
|
|
511
|
+
const value = idx === -1 ? "" : line.slice(idx + 1);
|
|
512
|
+
switch (key) {
|
|
513
|
+
case "tree": break;
|
|
514
|
+
case "parent":
|
|
515
|
+
if (value) parents.push(value);
|
|
516
|
+
break;
|
|
517
|
+
case "author": {
|
|
518
|
+
const ident = parseIdent(value);
|
|
519
|
+
authorName = ident.name;
|
|
520
|
+
authorEmail = ident.email;
|
|
521
|
+
authorDate = ident.date;
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
case "committer": {
|
|
525
|
+
const ident = parseIdent(value);
|
|
526
|
+
committerName = ident.name;
|
|
527
|
+
committerEmail = ident.email;
|
|
528
|
+
committerDate = ident.date;
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
default: break;
|
|
532
|
+
}
|
|
533
|
+
i++;
|
|
534
|
+
}
|
|
535
|
+
if (i < lines.length && lines[i] === "") i++;
|
|
536
|
+
const msgLines = [];
|
|
537
|
+
while (i < lines.length) {
|
|
538
|
+
const line = lines[i];
|
|
539
|
+
if (line.startsWith(" ")) {
|
|
540
|
+
msgLines.push(line.slice(4));
|
|
541
|
+
i++;
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
if (line === "") {
|
|
545
|
+
msgLines.push("");
|
|
546
|
+
i++;
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
const { subject, body } = splitMessage(msgLines);
|
|
552
|
+
let patchStart = -1;
|
|
553
|
+
for (let j = i; j < lines.length; j++) {
|
|
554
|
+
const line = lines[j];
|
|
555
|
+
if (line.startsWith("diff --git ") || line.startsWith("Binary files ")) {
|
|
556
|
+
patchStart = j;
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
if (line === "") continue;
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
const patch = patchStart === -1 ? "" : lines.slice(patchStart).join("\n").replace(/\n+$/, "\n");
|
|
563
|
+
return {
|
|
564
|
+
sha,
|
|
565
|
+
shortSha: sha.slice(0, 7),
|
|
566
|
+
parents,
|
|
567
|
+
subject,
|
|
568
|
+
body,
|
|
569
|
+
authorName,
|
|
570
|
+
authorEmail,
|
|
571
|
+
authorDate,
|
|
572
|
+
committerName,
|
|
573
|
+
committerEmail,
|
|
574
|
+
committerDate,
|
|
575
|
+
patch
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Parse a `Name <email> <unix-seconds> <±HHMM>` ident line into structured
|
|
580
|
+
* fields. The email is bracketed; the timestamp is split out and converted to
|
|
581
|
+
* ISO 8601 for consumers.
|
|
582
|
+
*/
|
|
583
|
+
function parseIdent(value) {
|
|
584
|
+
const match = value.match(/^(.*?)\s+<([^>]*)>\s+(\d+)\s+([+-]\d{4})$/);
|
|
585
|
+
if (!match) return {
|
|
586
|
+
name: value,
|
|
587
|
+
email: "",
|
|
588
|
+
date: ""
|
|
589
|
+
};
|
|
590
|
+
const [, name, email, secs, tz] = match;
|
|
591
|
+
return {
|
|
592
|
+
name,
|
|
593
|
+
email,
|
|
594
|
+
date: unixToIso(Number(secs), tz)
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function unixToIso(secs, tz) {
|
|
598
|
+
if (!Number.isFinite(secs)) return "";
|
|
599
|
+
const sign = tz.startsWith("-") ? -1 : 1;
|
|
600
|
+
const tzHours = Number(tz.slice(1, 3));
|
|
601
|
+
const tzMins = Number(tz.slice(3, 5));
|
|
602
|
+
const offsetMs = sign * (tzHours * 60 + tzMins) * 6e4;
|
|
603
|
+
const d = new Date(secs * 1e3 + offsetMs);
|
|
604
|
+
const pad = (n, w = 2) => String(n).padStart(w, "0");
|
|
605
|
+
return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}T${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}:${pad(d.getUTCSeconds())}${tz.slice(0, 3)}:${tz.slice(3)}`;
|
|
606
|
+
}
|
|
607
|
+
function splitMessage(msgLines) {
|
|
608
|
+
if (msgLines.length === 0) return {
|
|
609
|
+
subject: "",
|
|
610
|
+
body: ""
|
|
611
|
+
};
|
|
612
|
+
let start = 0;
|
|
613
|
+
while (start < msgLines.length && msgLines[start] === "") start++;
|
|
614
|
+
let stop = msgLines.length;
|
|
615
|
+
while (stop > start && msgLines[stop - 1] === "") stop--;
|
|
616
|
+
if (start >= stop) return {
|
|
617
|
+
subject: "",
|
|
618
|
+
body: ""
|
|
619
|
+
};
|
|
620
|
+
const subject = msgLines[start];
|
|
621
|
+
let bodyStart = start + 1;
|
|
622
|
+
if (bodyStart < stop && msgLines[bodyStart] === "") bodyStart++;
|
|
623
|
+
return {
|
|
624
|
+
subject,
|
|
625
|
+
body: msgLines.slice(bodyStart, stop).join("\n")
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
async function getShowDiff(revspecs, pathspecs = []) {
|
|
629
|
+
if (revspecs.length === 0) return {
|
|
630
|
+
commits: [],
|
|
631
|
+
patch: "",
|
|
632
|
+
truncated: 0
|
|
633
|
+
};
|
|
634
|
+
let shaList;
|
|
635
|
+
try {
|
|
636
|
+
const { stdout } = await execFileAsync("git", [
|
|
637
|
+
"rev-list",
|
|
638
|
+
"--no-walk",
|
|
639
|
+
"--reverse",
|
|
640
|
+
...revspecs,
|
|
641
|
+
...pathspecs.length ? ["--", ...pathspecs] : []
|
|
642
|
+
], {
|
|
643
|
+
encoding: "utf-8",
|
|
644
|
+
maxBuffer: 50 * 1024 * 1024
|
|
645
|
+
});
|
|
646
|
+
shaList = stdout.split("\n").filter(Boolean);
|
|
647
|
+
} catch {
|
|
648
|
+
return {
|
|
649
|
+
commits: [],
|
|
650
|
+
patch: "",
|
|
651
|
+
truncated: 0
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
if (shaList.length === 0) return {
|
|
655
|
+
commits: [],
|
|
656
|
+
patch: "",
|
|
657
|
+
truncated: 0
|
|
658
|
+
};
|
|
659
|
+
const truncated = Math.max(0, shaList.length - 100);
|
|
660
|
+
const trimmed = truncated === 0 ? shaList : shaList.slice(0, 100);
|
|
661
|
+
let raw;
|
|
662
|
+
try {
|
|
663
|
+
const { stdout } = await execFileAsync("git", [
|
|
664
|
+
"log",
|
|
665
|
+
"--no-walk",
|
|
666
|
+
"--reverse",
|
|
667
|
+
"-p",
|
|
668
|
+
"--pretty=raw",
|
|
669
|
+
...DIFF_FLAGS,
|
|
670
|
+
...trimmed,
|
|
671
|
+
...pathspecs.length ? ["--", ...pathspecs] : []
|
|
672
|
+
], {
|
|
673
|
+
encoding: "utf-8",
|
|
674
|
+
maxBuffer: 200 * 1024 * 1024
|
|
675
|
+
});
|
|
676
|
+
raw = stdout;
|
|
677
|
+
} catch {
|
|
678
|
+
return {
|
|
679
|
+
commits: [],
|
|
680
|
+
patch: "",
|
|
681
|
+
truncated: 0
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
const commits = parseGitShowRaw(raw);
|
|
685
|
+
return {
|
|
686
|
+
commits,
|
|
687
|
+
patch: commits.map((c) => c.patch).filter(Boolean).join("\n"),
|
|
688
|
+
truncated
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region src/lib/comment-format.ts
|
|
693
|
+
/** Plain-language guidance the agent should act on, derived from the verdict. */
|
|
694
|
+
function reviewDecisionSummary(decision) {
|
|
695
|
+
switch (decision) {
|
|
696
|
+
case "approved": return "The reviewer APPROVED these changes. Address any open comments below, then proceed — the overall direction is good.";
|
|
697
|
+
case "changes-requested": return "The reviewer REQUESTED EDITS. Address every open comment below and apply the requested changes before considering this review done.";
|
|
698
|
+
case "rejected": return "The reviewer REJECTED these changes. Do NOT keep building on this approach; reconsider it in light of the comments below before continuing.";
|
|
699
|
+
case "comment-only": return "The reviewer chose COMMENT-ONLY mode. You MUST NOT edit any files. Only reply to the comments below — answer questions, provide clarification, or discuss. The general comment (if any) is your prompt for the chat.";
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Render review comments as the `<code-review-comments>` XML envelope used to
|
|
704
|
+
* hand a review to an AI agent. Shared by the UI clipboard button
|
|
705
|
+
* (`useComments.formatAllComments`), the server's `/api/review/send` handoff,
|
|
706
|
+
* and the `diffing` CLI/MCP so every channel emits byte-identical output.
|
|
707
|
+
*
|
|
708
|
+
* A review may carry a headline `decision` (approve / request edits / reject / comment-only)
|
|
709
|
+
* and/or an overall comment, so the envelope is emitted even with zero inline
|
|
710
|
+
* comments — letting a reviewer submit a verdict without annotating any line.
|
|
711
|
+
*/
|
|
712
|
+
function formatComments(comments, generalComment, decision, mode) {
|
|
713
|
+
const trimmedGeneral = generalComment?.trim();
|
|
714
|
+
if (comments.length === 0 && !decision && !trimmedGeneral) return "";
|
|
715
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
716
|
+
for (const comment of comments) {
|
|
717
|
+
const list = grouped.get(comment.filePath) ?? [];
|
|
718
|
+
list.push(comment);
|
|
719
|
+
grouped.set(comment.filePath, list);
|
|
720
|
+
}
|
|
721
|
+
const modeAttr = mode && mode !== "standard" ? ` mode="${mode}"` : "";
|
|
722
|
+
const lines = [];
|
|
723
|
+
lines.push(decision ? `<code-review-comments decision="${decision}"${modeAttr}>` : `<code-review-comments${modeAttr}>`);
|
|
724
|
+
lines.push(" <instructions>");
|
|
725
|
+
lines.push(" You are an AI coding assistant. You are receiving a structured list of code review comments to address in the repository.");
|
|
726
|
+
if (mode === "comment-only") lines.push(" ⚠️ COMMENT-ONLY MODE: You MUST NOT edit any files. Your only task is to reply to the comments below — answer questions, provide clarification, or discuss. The general comment (if present) is your prompt for this chat.");
|
|
727
|
+
else lines.push(" For each file, review the inline comments and apply the changes requested.");
|
|
728
|
+
if (decision) {
|
|
729
|
+
lines.push(" - The \"decision\" attribute on the root element is the reviewer's headline verdict: \"approved\", \"changes-requested\", \"rejected\", or \"comment-only\".");
|
|
730
|
+
lines.push(" - <decision-summary> tells you, in plain language, what to do next based on that verdict.");
|
|
731
|
+
}
|
|
732
|
+
if (mode) lines.push(` - The "mode" attribute on the root element controls your behavior: "standard" (apply edits) or "comment-only" (reply only, no edits).`);
|
|
733
|
+
lines.push(" - Target lines are specified by the \"line\" attribute (e.g. line=\"10\" or line=\"10-15\").");
|
|
734
|
+
lines.push(" - \"side\" indicates whether the comment is on \"additions\" (added/modified lines) or \"deletions\" (deleted/old lines).");
|
|
735
|
+
lines.push(" - \"status\" indicates whether the comment is \"open\" or \"resolved\". Only address comments with status=\"open\".");
|
|
736
|
+
lines.push(" - The <code> block contains the specific code context at the reviewed lines, prefixed with \"+\" or \"-\".");
|
|
737
|
+
lines.push(" - The <body> tag contains the review feedback or request.");
|
|
738
|
+
lines.push(" - If developers have replied to the comment, their discussion is captured under the <replies> element.");
|
|
739
|
+
lines.push(" - The comment \"id\" attribute can be used to reference or update the comment via API if available.");
|
|
740
|
+
lines.push("");
|
|
741
|
+
lines.push(" HOW TO REPLY OR ASK FOR CLARIFICATION:");
|
|
742
|
+
lines.push(" If you need to ask for clarification, explain what you did, or reply to any comment:");
|
|
743
|
+
lines.push("");
|
|
744
|
+
lines.push(" Option A: Via the diffing CLI or MCP (Preferred — port-agnostic, no copy-paste)");
|
|
745
|
+
lines.push(" diffing reply <comment-id> --body \"Your response\" --model \"<your-model-name>\"");
|
|
746
|
+
lines.push(" diffing resolve <comment-id>");
|
|
747
|
+
lines.push(" (Or the equivalent MCP tools: reply_to_comment, resolve_comment.)");
|
|
748
|
+
lines.push("");
|
|
749
|
+
lines.push(" Option B: Via the local HTTP API (if you know the running port)");
|
|
750
|
+
lines.push(" POST http://localhost:<port>/api/comments/<comment-id>/replies");
|
|
751
|
+
lines.push(" Payload: { \"body\": \"Your response or clarification request here\", \"model\": \"<your-model-name>\" }");
|
|
752
|
+
lines.push(" PUT http://localhost:<port>/api/comments/<comment-id> Payload: { \"status\": \"resolved\" }");
|
|
753
|
+
lines.push("");
|
|
754
|
+
lines.push(" Option C: Via Text Response (Offline / Chat Copy-Paste)");
|
|
755
|
+
lines.push(" If you do not have local API access, output your comments/replies inside a structured XML block at the end of your response:");
|
|
756
|
+
lines.push(" <comment-replies>");
|
|
757
|
+
lines.push(" <reply to=\"<comment-id>\" model=\"<your-model-name>\"><![CDATA[Your reply or clarification request here]]></reply>");
|
|
758
|
+
lines.push(" </comment-replies>");
|
|
759
|
+
lines.push(" </instructions>");
|
|
760
|
+
if (decision) lines.push(` <decision-summary><![CDATA[${reviewDecisionSummary(decision)}]]></decision-summary>`);
|
|
761
|
+
if (trimmedGeneral) {
|
|
762
|
+
lines.push(" <general-comment>");
|
|
763
|
+
lines.push(` <![CDATA[${trimmedGeneral}]]>`);
|
|
764
|
+
lines.push(" </general-comment>");
|
|
765
|
+
}
|
|
766
|
+
for (const [filePath, fileComments] of grouped) {
|
|
767
|
+
lines.push(` <file path="${filePath}">`);
|
|
768
|
+
for (const comment of fileComments) {
|
|
769
|
+
const lineAttr = comment.lineNumber === 0 ? "file" : comment.startLineNumber && comment.startLineNumber !== comment.lineNumber ? `${comment.startLineNumber}-${comment.lineNumber}` : `${comment.lineNumber}`;
|
|
770
|
+
const isoDate = new Date(comment.createdAt).toISOString();
|
|
771
|
+
lines.push(` <comment id="${comment.id}" line="${lineAttr}" side="${comment.side}" status="${comment.status}" created-at="${isoDate}">`);
|
|
772
|
+
if (comment.lineNumber !== 0) {
|
|
773
|
+
const prefix = comment.side === "additions" ? "+" : "-";
|
|
774
|
+
const isMultiLine = comment.lineContent && comment.lineContent.includes("\n");
|
|
775
|
+
let codeVal = "";
|
|
776
|
+
if (isMultiLine) codeVal = `\n${comment.lineContent.split("\n").map((l) => `${prefix} ${l}`).join("\n")}\n`;
|
|
777
|
+
else codeVal = `${prefix} ${comment.lineContent}`;
|
|
778
|
+
lines.push(` <code><![CDATA[${codeVal}]]></code>`);
|
|
779
|
+
}
|
|
780
|
+
lines.push(` <body><![CDATA[${comment.body}]]></body>`);
|
|
781
|
+
if (comment.replies && comment.replies.length > 0) {
|
|
782
|
+
lines.push(" <replies>");
|
|
783
|
+
for (const reply of comment.replies) {
|
|
784
|
+
const replyIsoDate = new Date(reply.createdAt).toISOString();
|
|
785
|
+
const roleAttr = reply.role ? ` role="${reply.role}"` : " role=\"agent\"";
|
|
786
|
+
const modelAttr = reply.model ? ` model="${reply.model}"` : "";
|
|
787
|
+
lines.push(` <reply id="${reply.id}" created-at="${replyIsoDate}"${roleAttr}${modelAttr}>`);
|
|
788
|
+
lines.push(` <![CDATA[${reply.body}]]>`);
|
|
789
|
+
lines.push(" </reply>");
|
|
790
|
+
}
|
|
791
|
+
lines.push(" </replies>");
|
|
792
|
+
}
|
|
793
|
+
lines.push(" </comment>");
|
|
794
|
+
}
|
|
795
|
+
lines.push(" </file>");
|
|
796
|
+
}
|
|
797
|
+
lines.push("</code-review-comments>");
|
|
798
|
+
return lines.join("\n");
|
|
799
|
+
}
|
|
800
|
+
//#endregion
|
|
801
|
+
//#region src/lib/server-lock.ts
|
|
802
|
+
const STARTUP_LEASE_STALE_MS = 3e4;
|
|
803
|
+
/**
|
|
804
|
+
* Produce a stable comparison key for the diff a server displays. Runtime-only
|
|
805
|
+
* web options are excluded so `--port`/`--no-open` do not create false scope
|
|
806
|
+
* mismatches between a user-started session and an MCP request.
|
|
807
|
+
*/
|
|
808
|
+
function diffScopeKey(options) {
|
|
809
|
+
const { port: _port, host: _host, noOpen: _noOpen, help: _help, version: _version, outputMode: _outputMode, tui: _tui, gpu: _gpu, noExtDiff: _noExtDiff, ...scope } = options;
|
|
810
|
+
return JSON.stringify(scope);
|
|
811
|
+
}
|
|
812
|
+
function lockPath(repoRoot) {
|
|
813
|
+
return join(getProjectStorageDir(repoRoot), "server.json");
|
|
814
|
+
}
|
|
815
|
+
function writeServerLock(lock) {
|
|
816
|
+
const path = lockPath(lock.repoRoot);
|
|
817
|
+
mkdirSync(join(path, ".."), { recursive: true });
|
|
818
|
+
writeFileSync(path, JSON.stringify(lock, null, 2), "utf-8");
|
|
819
|
+
}
|
|
820
|
+
function readServerLock(repoRoot) {
|
|
821
|
+
try {
|
|
822
|
+
const raw = readFileSync(lockPath(repoRoot), "utf-8");
|
|
823
|
+
const lock = JSON.parse(raw);
|
|
824
|
+
if (typeof lock.port !== "number" || typeof lock.pid !== "number") return null;
|
|
825
|
+
return lock;
|
|
826
|
+
} catch {
|
|
827
|
+
return null;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* True if the process named by the lock is still alive and the lock belongs to
|
|
832
|
+
* this repo. `process.kill(pid, 0)` sends no signal — it just probes existence.
|
|
833
|
+
*/
|
|
834
|
+
function isLockAlive(lock, expectedRepoRoot) {
|
|
835
|
+
try {
|
|
836
|
+
process.kill(lock.pid, 0);
|
|
837
|
+
} catch {
|
|
838
|
+
return false;
|
|
839
|
+
}
|
|
840
|
+
try {
|
|
841
|
+
return lock.repoRoot === (expectedRepoRoot ?? getRepoRoot());
|
|
842
|
+
} catch {
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
function removeServerLock(repoRoot) {
|
|
847
|
+
try {
|
|
848
|
+
rmSync(lockPath(repoRoot), { force: true });
|
|
849
|
+
} catch {}
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Atomically reserve server startup for one repository. The exclusive-create
|
|
853
|
+
* directory is the cross-process serialization point; callers must re-read
|
|
854
|
+
* server.json after acquiring it because another process may have completed
|
|
855
|
+
* startup between their first lock check and this lease acquisition.
|
|
856
|
+
*/
|
|
857
|
+
function acquireServerStartupLease(repoRoot, ownerId, now = Date.now()) {
|
|
858
|
+
const path = join(getProjectStorageDir(repoRoot), "server-startup.lock");
|
|
859
|
+
const recordPath = join(path, "lease.json");
|
|
860
|
+
const ownerMarkerPath = join(path, encodeURIComponent(ownerId));
|
|
861
|
+
mkdirSync(join(path, ".."), { recursive: true });
|
|
862
|
+
const tryCreate = () => {
|
|
863
|
+
try {
|
|
864
|
+
mkdirSync(path, {
|
|
865
|
+
recursive: false,
|
|
866
|
+
mode: 448
|
|
867
|
+
});
|
|
868
|
+
} catch (error) {
|
|
869
|
+
if (error?.code === "EEXIST") return false;
|
|
870
|
+
throw error;
|
|
871
|
+
}
|
|
872
|
+
writeFileSync(recordPath, JSON.stringify({
|
|
873
|
+
ownerId,
|
|
874
|
+
createdAt: now
|
|
875
|
+
}), "utf-8");
|
|
876
|
+
writeFileSync(ownerMarkerPath, "", "utf-8");
|
|
877
|
+
return true;
|
|
878
|
+
};
|
|
879
|
+
if (!tryCreate()) {
|
|
880
|
+
try {
|
|
881
|
+
const record = JSON.parse(readFileSync(recordPath, "utf-8"));
|
|
882
|
+
if (typeof record.createdAt !== "number" || now - record.createdAt <= STARTUP_LEASE_STALE_MS) return null;
|
|
883
|
+
const stalePath = `${path}.stale-${process.pid}-${now}`;
|
|
884
|
+
renameSync(path, stalePath);
|
|
885
|
+
rmSync(stalePath, {
|
|
886
|
+
recursive: true,
|
|
887
|
+
force: true
|
|
888
|
+
});
|
|
889
|
+
} catch (error) {
|
|
890
|
+
if (error?.code !== "ENOENT") return null;
|
|
891
|
+
}
|
|
892
|
+
if (!tryCreate()) return null;
|
|
893
|
+
}
|
|
894
|
+
let released = false;
|
|
895
|
+
return {
|
|
896
|
+
ownerId,
|
|
897
|
+
release() {
|
|
898
|
+
if (released) return;
|
|
899
|
+
released = true;
|
|
900
|
+
try {
|
|
901
|
+
unlinkSync(ownerMarkerPath);
|
|
902
|
+
unlinkSync(recordPath);
|
|
903
|
+
rmdirSync(path);
|
|
904
|
+
} catch {}
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
//#endregion
|
|
909
|
+
export { revertHunk as C, listRepoFiles as S, toSafeRelativePath as T, getShowDiff as _, removeServerLock as a, gitAddFile as b, getBranchName as c, getGitDiffAsync as d, getHunkHistory as f, getRepoRoot as g, getRepoName as h, readServerLock as i, getCustomGitDiffAsync as l, getProjectStorageDir as m, diffScopeKey as n, writeServerLock as o, getMergeStatus as p, isLockAlive as r, formatComments as s, acquireServerStartupLease as t, getFileContent as u, getTabSizeForFiles as v, isSafePath as w, isGitRepo as x, getUntrackedFilePathsAsync as y };
|