Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(git-history): shared types + log parser (ported from REF)
enesa6e0478d2b04
diff --git a/package-lock.json b/package-lock.jsonindex c84ba2c90..6a95fe2bf 100644--- a/package-lock.json+++ b/package-lock.json@@ -8,7 +8,7 @@"name": "node-terminal","version": "0.2.0","hasInstallScript": true,- "license": "MIT",+ "license": "SEE LICENSE IN LICENSE","dependencies": {"dompurify": "^3.4.10","electron-updater": "^6.8.9",@@ -32,7 +32,8 @@"react-dom": "^18.3.1","sharp": "^0.33.5","typescript": "^5.5.4",- "vite": "^5.4.0"+ "vite": "^5.4.0",+ "vitest": "^2.1.0"}},"node_modules/@babel/code-frame": {@@ -2405,6 +2406,119 @@"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"}},+ "node_modules/@vitest/expect": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.9.tgz",+ "integrity": "sha512-UJCIkTBenHeKT1TTlKMJWy1laZewsRIzYighyYiJKZreqtdxSos/S1t+ktRMQWu2CKqaarrkeszJx1cgC5tGZw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/spy": "2.1.9",+ "@vitest/utils": "2.1.9",+ "chai": "^5.1.2",+ "tinyrainbow": "^1.2.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/mocker": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-2.1.9.tgz",+ "integrity": "sha512-tVL6uJgoUdi6icpxmdrn5YNo3g3Dxv+IHJBr0GXHaEdTcw3F+cPKnsXFhli6nO+f/6SDKPHEK1UN+k+TQv0Ehg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/spy": "2.1.9",+ "estree-walker": "^3.0.3",+ "magic-string": "^0.30.12"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ },+ "peerDependencies": {+ "msw": "^2.4.9",+ "vite": "^5.0.0"+ },+ "peerDependenciesMeta": {+ "msw": {+ "optional": true+ },+ "vite": {+ "optional": true+ }+ }+ },+ "node_modules/@vitest/pretty-format": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-2.1.9.tgz",+ "integrity": "sha512-KhRIdGV2U9HOUzxfiHmY8IFHTdqtOhIzCpd8WRdJiE7D/HUcZVD0EgQCVjm+Q9gkUXWgBvMmTtZgIG48wq7sOQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "tinyrainbow": "^1.2.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/runner": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-2.1.9.tgz",+ "integrity": "sha512-ZXSSqTFIrzduD63btIfEyOmNcBmQvgOVsPNPe0jYtESiXkhd8u2erDLnMxmGrDCwHCCHE7hxwRDCT3pt0esT4g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/utils": "2.1.9",+ "pathe": "^1.1.2"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/snapshot": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-2.1.9.tgz",+ "integrity": "sha512-oBO82rEjsxLNJincVhLhaxxZdEtV0EFHMK5Kmx5sJ6H9L183dHECjiefOAdnqpIgT5eZwT04PoggUnW88vOBNQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/pretty-format": "2.1.9",+ "magic-string": "^0.30.12",+ "pathe": "^1.1.2"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/spy": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-2.1.9.tgz",+ "integrity": "sha512-E1B35FwzXXTs9FHNK6bDszs7mtydNi5MIfUWpceJ8Xbfb1gBMscAnwLbEu+B44ed6W3XjL9/ehLPHR1fkf1KLQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "tinyspy": "^3.0.2"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/utils": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-2.1.9.tgz",+ "integrity": "sha512-v0psaMSkNJ3A2NMrUEHFRzJtDPFn+/VWZ5WxImB21T9fjucJRmS7xCS3ppEnARb9y11OAzaD+P2Ps+b+BGX5iQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/pretty-format": "2.1.9",+ "loupe": "^3.1.2",+ "tinyrainbow": "^1.2.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },"node_modules/@xmldom/xmldom": {"version": "0.9.10","resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.9.10.tgz",@@ -2778,6 +2892,16 @@"node": ">=0.8"}},+ "node_modules/assertion-error": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",+ "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/astral-regex": {"version": "2.0.0","resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz",@@ -3154,6 +3278,23 @@],"license": "CC-BY-4.0"},+ "node_modules/chai": {+ "version": "5.3.3",+ "resolved": "https://registry.npmjs.org/chai/-/chai-5.3.3.tgz",+ "integrity": "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "assertion-error": "^2.0.1",+ "check-error": "^2.1.1",+ "deep-eql": "^5.0.1",+ "loupe": "^3.1.0",+ "pathval": "^2.0.0"+ },+ "engines": {+ "node": ">=18"+ }+ },"node_modules/chalk": {"version": "4.1.2","resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",@@ -3171,6 +3312,16 @@"url": "https://github.com/chalk/chalk?sponsor=1"}},+ "node_modules/check-error": {+ "version": "2.1.3",+ "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.3.tgz",+ "integrity": "sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">= 16"+ }+ },"node_modules/chownr": {"version": "2.0.0","resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",@@ -3700,6 +3851,16 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "node_modules/deep-eql": {+ "version": "5.0.2",+ "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",+ "integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=6"+ }+ },"node_modules/defaults": {"version": "1.0.4","resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.4.tgz",@@ -4152,6 +4313,13 @@"node": ">= 0.4"}},+ "node_modules/es-module-lexer": {+ "version": "1.7.0",+ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz",+ "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==",+ "dev": true,+ "license": "MIT"+ },"node_modules/es-object-atoms": {"version": "1.1.2","resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",@@ -4252,6 +4420,26 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "node_modules/estree-walker": {+ "version": "3.0.3",+ "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",+ "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/estree": "^1.0.0"+ }+ },+ "node_modules/expect-type": {+ "version": "1.3.0",+ "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",+ "integrity": "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==",+ "dev": true,+ "license": "Apache-2.0",+ "engines": {+ "node": ">=12.0.0"+ }+ },"node_modules/exponential-backoff": {"version": "3.1.3","resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.3.tgz",@@ -5257,6 +5445,13 @@"loose-envify": "cli.js"}},+ "node_modules/loupe": {+ "version": "3.2.1",+ "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz",+ "integrity": "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==",+ "dev": true,+ "license": "MIT"+ },"node_modules/lowercase-keys": {"version": "2.0.0","resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",@@ -5842,6 +6037,23 @@"node": ">=16 || 14 >=14.17"}},+ "node_modules/pathe": {+ "version": "1.1.2",+ "resolved": "https://registry.npmjs.org/pathe/-/pathe-1.1.2.tgz",+ "integrity": "sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/pathval": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.1.tgz",+ "integrity": "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">= 14.16"+ }+ },"node_modules/pend": {"version": "1.2.0","resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",@@ -6415,6 +6627,13 @@"node": ">=8"}},+ "node_modules/siginfo": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",+ "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==",+ "dev": true,+ "license": "ISC"+ },"node_modules/signal-exit": {"version": "3.0.7","resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",@@ -6554,6 +6773,13 @@"node": "^12.13.0 || ^14.15.0 || >=16.0.0"}},+ "node_modules/stackback": {+ "version": "0.0.2",+ "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",+ "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==",+ "dev": true,+ "license": "MIT"+ },"node_modules/stat-mode": {"version": "1.0.0","resolved": "https://registry.npmjs.org/stat-mode/-/stat-mode-1.0.0.tgz",@@ -6564,6 +6790,13 @@"node": ">= 6"}},+ "node_modules/std-env": {+ "version": "3.10.0",+ "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz",+ "integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==",+ "dev": true,+ "license": "MIT"+ },"node_modules/string_decoder": {"version": "1.3.0","resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",@@ -6729,6 +6962,50 @@"integrity": "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==","license": "MIT"},+ "node_modules/tinybench": {+ "version": "2.9.0",+ "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",+ "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/tinyexec": {+ "version": "0.3.2",+ "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz",+ "integrity": "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/tinypool": {+ "version": "1.1.1",+ "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-1.1.1.tgz",+ "integrity": "sha512-Zba82s87IFq9A9XmjiX5uZA/ARWDrB03OHlq+Vw1fSdt0I+4/Kutwy8BP4Y/y/aORMo61FQ0vIb5j44vSo5Pkg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": "^18.0.0 || >=20.0.0"+ }+ },+ "node_modules/tinyrainbow": {+ "version": "1.2.0",+ "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-1.2.0.tgz",+ "integrity": "sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=14.0.0"+ }+ },+ "node_modules/tinyspy": {+ "version": "3.0.2",+ "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-3.0.2.tgz",+ "integrity": "sha512-n1cw8k1k0x4pgA2+9XrOkFydTerNcJ1zWCO5Nn9scWHTD+5tp8dghT2x1uduQePZTZgd3Tupf+x9BxJjeJi77Q==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=14.0.0"+ }+ },"node_modules/tmp": {"version": "0.2.7","resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.7.tgz",@@ -6977,6 +7254,95 @@}}},+ "node_modules/vite-node": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-2.1.9.tgz",+ "integrity": "sha512-AM9aQ/IPrW/6ENLQg3AGY4K1N2TGZdR5e4gu/MmmR2xR3Ll1+dib+nook92g4TV3PXVyeyxdWwtaCAiUL0hMxA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "cac": "^6.7.14",+ "debug": "^4.3.7",+ "es-module-lexer": "^1.5.4",+ "pathe": "^1.1.2",+ "vite": "^5.0.0"+ },+ "bin": {+ "vite-node": "vite-node.mjs"+ },+ "engines": {+ "node": "^18.0.0 || >=20.0.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/vitest": {+ "version": "2.1.9",+ "resolved": "https://registry.npmjs.org/vitest/-/vitest-2.1.9.tgz",+ "integrity": "sha512-MSmPM9REYqDGBI8439mA4mWhV5sKmDlBKWIYbA3lRb2PTHACE0mgKwA8yQ2xq9vxDTuk4iPrECBAEW2aoFXY0Q==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/expect": "2.1.9",+ "@vitest/mocker": "2.1.9",+ "@vitest/pretty-format": "^2.1.9",+ "@vitest/runner": "2.1.9",+ "@vitest/snapshot": "2.1.9",+ "@vitest/spy": "2.1.9",+ "@vitest/utils": "2.1.9",+ "chai": "^5.1.2",+ "debug": "^4.3.7",+ "expect-type": "^1.1.0",+ "magic-string": "^0.30.12",+ "pathe": "^1.1.2",+ "std-env": "^3.8.0",+ "tinybench": "^2.9.0",+ "tinyexec": "^0.3.1",+ "tinypool": "^1.0.1",+ "tinyrainbow": "^1.2.0",+ "vite": "^5.0.0",+ "vite-node": "2.1.9",+ "why-is-node-running": "^2.3.0"+ },+ "bin": {+ "vitest": "vitest.mjs"+ },+ "engines": {+ "node": "^18.0.0 || >=20.0.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ },+ "peerDependencies": {+ "@edge-runtime/vm": "*",+ "@types/node": "^18.0.0 || >=20.0.0",+ "@vitest/browser": "2.1.9",+ "@vitest/ui": "2.1.9",+ "happy-dom": "*",+ "jsdom": "*"+ },+ "peerDependenciesMeta": {+ "@edge-runtime/vm": {+ "optional": true+ },+ "@types/node": {+ "optional": true+ },+ "@vitest/browser": {+ "optional": true+ },+ "@vitest/ui": {+ "optional": true+ },+ "happy-dom": {+ "optional": true+ },+ "jsdom": {+ "optional": true+ }+ }+ },"node_modules/wcwidth": {"version": "1.0.1","resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz",@@ -7003,6 +7369,23 @@"node": ">= 8"}},+ "node_modules/why-is-node-running": {+ "version": "2.3.0",+ "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",+ "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "siginfo": "^2.0.0",+ "stackback": "0.0.2"+ },+ "bin": {+ "why-is-node-running": "cli.js"+ },+ "engines": {+ "node": ">=8"+ }+ },"node_modules/wrap-ansi": {"version": "7.0.0","resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",diff --git a/package.json b/package.jsonindex 25e128374..886a7e7ed 100644--- a/package.json+++ b/package.json@@ -12,6 +12,7 @@"preview": "electron-vite preview","start": "electron-vite preview","typecheck": "tsc --noEmit -p tsconfig.node.json && tsc --noEmit -p tsconfig.web.json",+ "test": "vitest run","rebuild": "electron-rebuild -f -w node-pty","make-icon": "node scripts/make-icon.mjs","make-social": "node scripts/make-social.mjs",@@ -86,6 +87,7 @@"react-dom": "^18.3.1","sharp": "^0.33.5","typescript": "^5.5.4",- "vite": "^5.4.0"+ "vite": "^5.4.0",+ "vitest": "^2.1.0"}}diff --git a/src/shared/git-history-log-parser.test.ts b/src/shared/git-history-log-parser.test.tsnew file mode 100644index 000000000..03b285e8a--- /dev/null+++ b/src/shared/git-history-log-parser.test.ts@@ -0,0 +1,32 @@+import { describe, expect, it } from 'vitest'+import { parseGitHistoryLog, shortGitHash } from './git-history-log-parser'++describe('parseGitHistoryLog', () => {+ it('parses one NUL-delimited record with refs', () => {+ const hash = 'a'.repeat(40)+ const record = [+ hash,+ 'Jane Dev',+ '[email protected]',+ '1700000000',+ '1700000005',+ 'b'.repeat(40),+ 'HEAD -> refs/heads/main\x1frefs/remotes/origin/main\x1ftag: refs/tags/v1',+ 'Subject line\n\nBody text'+ ].join('\n')+ const [item] = parseGitHistoryLog(record + '\0')+ expect(item.id).toBe(hash)+ expect(item.subject).toBe('Subject line')+ expect(item.parentIds).toEqual(['b'.repeat(40)])+ expect(item.author).toBe('Jane Dev')+ expect(item.references?.map((r) => r.name)).toEqual(['main', 'origin/main', 'v1'])+ })++ it('skips blank records and short hashes', () => {+ expect(parseGitHistoryLog('\0not-a-hash\n\0')).toEqual([])+ })++ it('shortens hashes to 7 chars', () => {+ expect(shortGitHash('abcdef1234567')).toBe('abcdef1')+ })+})diff --git a/src/shared/git-history-log-parser.ts b/src/shared/git-history-log-parser.tsnew file mode 100644index 000000000..8744a70f1--- /dev/null+++ b/src/shared/git-history-log-parser.ts@@ -0,0 +1,151 @@+import type { GitHistoryItem, GitHistoryItemRef } from './git-history-types'++const GIT_HISTORY_DECORATION_SEPARATOR = '\x1f'++export const GIT_HISTORY_COMMIT_FORMAT =+ '%H%n%aN%n%aE%n%at%n%ct%n%P%n%(decorate:prefix=,suffix=,separator=%x1f)%n%B'++export function shortGitHash(hash: string): string {+ return hash.slice(0, 7)+}++function commitSubject(message: string): string {+ const firstLine = message.split(/\r?\n/, 1)[0]?.trim()+ return firstLine || '(no commit message)'+}++function parseGitDecorationRefs(raw: string, revision: string): GitHistoryItemRef[] {+ if (!raw.trim()) {+ return []+ }++ const refs: GitHistoryItemRef[] = []+ // Why: Git permits commas in ref names, so REF's git log format uses a+ // control-character separator that Git ref names cannot contain.+ const parts = raw.includes(GIT_HISTORY_DECORATION_SEPARATOR)+ ? raw.split(GIT_HISTORY_DECORATION_SEPARATOR)+ : raw.split(',')++ for (const part of parts) {+ const ref = part.trim()+ if (!ref || ref === 'HEAD' || /^refs\/remotes\/[^/]+\/HEAD(?:\s|$)/.test(ref)) {+ continue+ }++ if (ref.startsWith('HEAD -> refs/heads/')) {+ refs.push({+ id: ref.slice('HEAD -> '.length),+ name: ref.slice('HEAD -> refs/heads/'.length),+ revision,+ category: 'branches'+ })+ continue+ }++ if (ref.startsWith('refs/heads/')) {+ refs.push({+ id: ref,+ name: ref.slice('refs/heads/'.length),+ revision,+ category: 'branches'+ })+ continue+ }++ if (ref.startsWith('refs/remotes/')) {+ refs.push({+ id: ref,+ name: ref.slice('refs/remotes/'.length),+ revision,+ category: 'remote branches'+ })+ continue+ }++ if (ref.startsWith('tag: refs/tags/')) {+ refs.push({+ id: ref.slice('tag: '.length),+ name: ref.slice('tag: refs/tags/'.length),+ revision,+ category: 'tags'+ })+ }+ }++ return refs.sort(compareGitHistoryItemRefsByCategory)+}++export function compareGitHistoryItemRefsByCategory(+ ref1: GitHistoryItemRef,+ ref2: GitHistoryItemRef+): number {+ const order = (ref: GitHistoryItemRef): number => {+ if (ref.id.startsWith('refs/heads/')) {+ return 1+ }+ if (ref.id.startsWith('refs/remotes/')) {+ return 2+ }+ if (ref.id.startsWith('refs/tags/')) {+ return 3+ }+ return 99+ }++ const categoryOrder = order(ref1) - order(ref2)+ return categoryOrder || ref1.name.localeCompare(ref2.name)+}++export function parseGitHistoryLog(stdout: string): GitHistoryItem[] {+ const items: GitHistoryItem[] = []+ for (const rawRecord of stdout.split('\0')) {+ const record = rawRecord.replace(/^\n+/, '')+ if (!record.trim()) {+ continue+ }++ const lines = record.split('\n')+ const hash = lines[0]?.trim() ?? ''+ if (!/^[0-9a-fA-F]{40,64}$/.test(hash)) {+ continue+ }++ const authorName = lines[1] ?? ''+ const authorEmail = lines[2] ?? ''+ const authorDateSeconds = Number.parseInt(lines[3] ?? '', 10)+ const parents = (lines[5] ?? '').trim()+ const decorations = lines[6] ?? ''+ const message = lines.slice(7).join('\n').replace(/\n$/, '')++ items.push({+ id: hash,+ parentIds: parents ? parents.split(' ') : [],+ subject: commitSubject(message),+ message,+ author: authorName || undefined,+ authorEmail: authorEmail || undefined,+ displayId: shortGitHash(hash),+ timestamp: Number.isFinite(authorDateSeconds) ? authorDateSeconds * 1000 : undefined,+ references: parseGitDecorationRefs(decorations, hash)+ })+ }+ return items+}++export function gitHistoryRefFromFullName(+ fullName: string | null,+ fallbackName: string,+ revision: string+): GitHistoryItemRef {+ const id = fullName || fallbackName+ if (id.startsWith('refs/heads/')) {+ return { id, name: id.slice('refs/heads/'.length), revision, category: 'branches' }+ }+ if (id.startsWith('refs/remotes/')) {+ return { id, name: id.slice('refs/remotes/'.length), revision, category: 'remote branches' }+ }+ if (id.startsWith('refs/tags/')) {+ return { id, name: id.slice('refs/tags/'.length), revision, category: 'tags' }+ }+ return { id, name: fallbackName || shortGitHash(revision), revision, category: 'commits' }+}diff --git a/src/shared/git-history-types.ts b/src/shared/git-history-types.tsnew file mode 100644index 000000000..4e99d4b2e--- /dev/null+++ b/src/shared/git-history-types.ts@@ -0,0 +1,76 @@+export type GitHistoryGraphColorId =+ | 'git-graph-ref'+ | 'git-graph-remote-ref'+ | 'git-graph-base-ref'+ | 'git-graph-lane-1'+ | 'git-graph-lane-2'+ | 'git-graph-lane-3'+ | 'git-graph-lane-4'+ | 'git-graph-lane-5'++export const GIT_HISTORY_REF_COLOR: GitHistoryGraphColorId = 'git-graph-ref'+export const GIT_HISTORY_REMOTE_REF_COLOR: GitHistoryGraphColorId = 'git-graph-remote-ref'+export const GIT_HISTORY_BASE_REF_COLOR: GitHistoryGraphColorId = 'git-graph-base-ref'++export const GIT_HISTORY_LANE_COLORS: readonly GitHistoryGraphColorId[] = [+ 'git-graph-lane-1',+ 'git-graph-lane-2',+ 'git-graph-lane-3',+ 'git-graph-lane-4',+ 'git-graph-lane-5'+]++export const GIT_HISTORY_DEFAULT_LIMIT = 50+export const GIT_HISTORY_MAX_LIMIT = 200++export type GitHistoryRefCategory = 'branches' | 'remote branches' | 'tags' | 'commits'++export type GitHistoryItemRef = {+ id: string+ name: string+ revision?: string+ category?: GitHistoryRefCategory+ description?: string+ color?: GitHistoryGraphColorId+}++export type GitHistoryItemStatistics = {+ files: number+ insertions: number+ deletions: number+}++export type GitHistoryItem = {+ id: string+ parentIds: string[]+ subject: string+ message: string+ displayId?: string+ author?: string+ authorEmail?: string+ timestamp?: number+ statistics?: GitHistoryItemStatistics+ references?: GitHistoryItemRef[]+}++export type GitHistoryOptions = {+ limit?: number+ baseRef?: string | null+}++export type GitHistoryResult = {+ items: GitHistoryItem[]+ currentRef?: GitHistoryItemRef+ remoteRef?: GitHistoryItemRef+ baseRef?: GitHistoryItemRef+ mergeBase?: string+ hasIncomingChanges: boolean+ hasOutgoingChanges: boolean+ hasMore: boolean+ limit: number+}++export type GitHistoryExecutor = (+ args: string[],+ cwd: string+) => Promise<{ stdout: string; stderr?: string }>diff --git a/vitest.config.ts b/vitest.config.tsnew file mode 100644index 000000000..543975127--- /dev/null+++ b/vitest.config.ts@@ -0,0 +1,7 @@+import { defineConfig } from 'vitest/config'+import { resolve } from 'path'++export default defineConfig({+ test: { include: ['src/shared/**/*.test.ts'], environment: 'node' },+ resolve: { alias: { '@shared': resolve(__dirname, 'src/shared') } }+})