merge: resolve conflict in TabBar.tsx — keep both Activity icon and formatShortcut import

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
matt 2026-02-23 22:14:01 +08:00
commit 02940ce216
56 changed files with 6894 additions and 249 deletions

32
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View file

@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: bug
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

View file

@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[FEAT]"
labels: feature request
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

View file

@ -7,6 +7,9 @@ The format is based on Keep a Changelog and this project follows Semantic Versio
## [Unreleased]
### Added
- `general.autoExpandAIGroups` setting: automatically expands all AI response groups when opening a transcript or when new AI responses arrive in a live session. Defaults to off. Stored in the on-disk config so it persists across restarts.
- Strict IPC input validation guards for project/session/subagent/search limits.
- `get-waterfall-data` IPC endpoint implementation.
- Cross-platform path normalization in renderer path resolvers.

View file

@ -19,6 +19,7 @@
"main": "dist-electron/main/index.cjs",
"scripts": {
"dev": "electron-vite dev",
"prebuild": "tsx scripts/fetch-pricing-data.ts",
"build": "electron-vite build",
"dist": "electron-builder --mac --win --linux",
"dist:mac": "electron-builder --mac --publish always",
@ -100,7 +101,7 @@
"eslint-plugin-sonarjs": "^3.0.6",
"eslint-plugin-tailwindcss": "^3.18.2",
"globals": "^17.2.0",
"happy-dom": "^17.4.6",
"happy-dom": "^20.0.2",
"knip": "^5.82.1",
"postcss": "^8.4.35",
"prettier": "^3.8.1",
@ -127,6 +128,12 @@
"asarUnpack": [
"out/renderer/**"
],
"extraResources": [
{
"from": "resources/pricing.json",
"to": "pricing.json"
}
],
"npmRebuild": false,
"extraMetadata": {
"main": "dist-electron/main/index.cjs"

View file

@ -104,7 +104,7 @@ importers:
version: 4.7.0(vite@5.4.21(@types/node@25.0.7)(terser@5.46.0))
'@vitest/coverage-v8':
specifier: ^3.1.4
version: 3.2.4(vitest@3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@17.6.3)(terser@5.46.0))
version: 3.2.4(vitest@3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@20.0.2)(terser@5.46.0))
autoprefixer:
specifier: ^10.4.17
version: 10.4.23(postcss@8.5.6)
@ -160,8 +160,8 @@ importers:
specifier: ^17.2.0
version: 17.2.0
happy-dom:
specifier: ^17.4.6
version: 17.6.3
specifier: ^20.0.2
version: 20.0.2
knip:
specifier: ^5.82.1
version: 5.82.1(@types/node@25.0.7)(typescript@5.9.3)
@ -191,7 +191,7 @@ importers:
version: 5.4.21(@types/node@25.0.7)(terser@5.46.0)
vitest:
specifier: ^3.1.4
version: 3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@17.6.3)(terser@5.46.0)
version: 3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@20.0.2)(terser@5.46.0)
packages:
@ -769,10 +769,6 @@ packages:
resolution: {integrity: sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==}
engines: {node: 20 || >=22}
'@isaacs/brace-expansion@5.0.0':
resolution: {integrity: sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA==}
engines: {node: 20 || >=22}
'@isaacs/brace-expansion@5.0.1':
resolution: {integrity: sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==}
engines: {node: 20 || >=22}
@ -1171,6 +1167,9 @@ packages:
'@types/node@18.19.130':
resolution: {integrity: sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg==}
'@types/node@20.19.33':
resolution: {integrity: sha512-Rs1bVAIdBs5gbTIKza/tgpMuG1k3U/UMJLWecIMxNdJFDMzcM5LOiLVRYh3PilWEYDIeUDv7bpiHPLPsbydGcw==}
'@types/node@24.10.12':
resolution: {integrity: sha512-68e+T28EbdmLSTkPgs3+UacC6rzmqrcWFPQs1C8mwJhI/r5Uxr0yEuQotczNRROd1gq30NGxee+fo0rSIxpyAw==}
@ -1206,6 +1205,9 @@ packages:
'@types/verror@1.10.11':
resolution: {integrity: sha512-RlDm9K7+o5stv0Co8i8ZRGxDbrTxhJtgjqjFyVh/tXQyl/rYtTKlnTvZ88oSTeYREWurwx20Js4kTuKCsFkUtg==}
'@types/whatwg-mimetype@3.0.2':
resolution: {integrity: sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==}
'@types/yauzl@2.10.3':
resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==}
@ -1430,6 +1432,11 @@ packages:
engines: {node: '>=0.4.0'}
hasBin: true
acorn@8.16.0:
resolution: {integrity: sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==}
engines: {node: '>=0.4.0'}
hasBin: true
agent-base@6.0.2:
resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==}
engines: {node: '>= 6.0.0'}
@ -1459,11 +1466,11 @@ packages:
peerDependencies:
ajv: ^6.9.1
ajv@6.12.6:
resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==}
ajv@6.14.0:
resolution: {integrity: sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==}
ajv@8.17.1:
resolution: {integrity: sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==}
ajv@8.18.0:
resolution: {integrity: sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==}
ansi-regex@5.0.1:
resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
@ -1641,6 +1648,10 @@ packages:
balanced-match@1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
balanced-match@4.0.3:
resolution: {integrity: sha512-1pHv8LX9CpKut1Zp4EXey7Z8OfH11ONNH6Dhi2WDUt31VVZFXZzKwXcysBgqSumFCmR+0dqjMK5v5JiFHzi0+g==}
engines: {node: 20 || >=22}
base64-js@1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
@ -1674,6 +1685,10 @@ packages:
brace-expansion@2.0.2:
resolution: {integrity: sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==}
brace-expansion@5.0.2:
resolution: {integrity: sha512-Pdk8c9poy+YhOgVWw1JNN22/HcivgKWwpxKq04M/jTmHyCZn12WPJebZxdjSa5TmBqISrUSgNYU3eRORljfCCw==}
engines: {node: 20 || >=22}
braces@3.0.3:
resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==}
engines: {node: '>=8'}
@ -2550,6 +2565,7 @@ packages:
glob@10.5.0:
resolution: {integrity: sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==}
deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me
hasBin: true
glob@13.0.2:
@ -2597,8 +2613,8 @@ packages:
engines: {node: '>=0.4.7'}
hasBin: true
happy-dom@17.6.3:
resolution: {integrity: sha512-UVIHeVhxmxedbWPCfgS55Jg2rDfwf2BCKeylcPSqazLz5w3Kri7Q4xdBJubsr/+VUzFLh0VjIvh13RaDA2/Xug==}
happy-dom@20.0.2:
resolution: {integrity: sha512-pYOyu624+6HDbY+qkjILpQGnpvZOusItCk+rvF5/V+6NkcgTKnbOldpIy22tBnxoaLtlM9nXgoqAcW29/B7CIw==}
engines: {node: '>=20.0.0'}
has-bigints@1.1.0:
@ -3302,19 +3318,19 @@ packages:
resolution: {integrity: sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==}
engines: {node: 20 || >=22}
minimatch@10.1.2:
resolution: {integrity: sha512-fu656aJ0n2kcXwsnwnv9g24tkU5uSmOlTjd6WyyaKm2Z+h1qmY6bAjrcaIxF/BslFqbZ8UBtbJi7KgQOZD2PTw==}
engines: {node: 20 || >=22}
minimatch@10.2.2:
resolution: {integrity: sha512-+G4CpNBxa5MprY+04MbgOw1v7So6n5JY166pFi9KfYwT78fxScCeSNQSNzp6dpPSW2rONOps6Ocam1wFhCgoVw==}
engines: {node: 18 || 20 || >=22}
minimatch@3.1.2:
resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
minimatch@3.1.3:
resolution: {integrity: sha512-M2GCs7Vk83NxkUyQV1bkABc4yxgz9kILhHImZiBPAZ9ybuvCb0/H7lEl5XvIg3g+9d4eNotkZA5IWwYl0tibaA==}
minimatch@5.1.6:
resolution: {integrity: sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==}
minimatch@5.1.7:
resolution: {integrity: sha512-FjiwU9HaHW6YB3H4a1sFudnv93lvydNjz2lmyUXR6IwKhGI+bgL3SOZrBGn6kvvX2pJvhEkGSGjyTHN47O4rqA==}
engines: {node: '>=10'}
minimatch@9.0.5:
resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==}
minimatch@9.0.6:
resolution: {integrity: sha512-kQAVowdR33euIqeA0+VZTDqU+qo1IeVY+hrKYtZMio3Pg0P0vuh/kwRylLUddJhB6pf3q/botcOvRtx4IN1wqQ==}
engines: {node: '>=16 || 14 >=14.17'}
minimist@1.2.8:
@ -3964,6 +3980,11 @@ packages:
engines: {node: '>=10'}
hasBin: true
semver@7.7.4:
resolution: {integrity: sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==}
engines: {node: '>=10'}
hasBin: true
serialize-error@7.0.1:
resolution: {integrity: sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==}
engines: {node: '>=10'}
@ -4351,6 +4372,9 @@ packages:
undici-types@5.26.5:
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
undici-types@6.21.0:
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
undici-types@7.16.0:
resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==}
@ -4492,10 +4516,6 @@ packages:
wcwidth@1.0.1:
resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==}
webidl-conversions@7.0.0:
resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==}
engines: {node: '>=12'}
whatwg-mimetype@3.0.0:
resolution: {integrity: sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==}
engines: {node: '>=12'}
@ -4758,8 +4778,8 @@ snapshots:
'@develar/schema-utils@2.6.5':
dependencies:
ajv: 6.12.6
ajv-keywords: 3.5.2(ajv@6.12.6)
ajv: 6.14.0
ajv-keywords: 3.5.2(ajv@6.14.0)
'@dnd-kit/accessibility@3.1.1(react@18.3.1)':
dependencies:
@ -4790,7 +4810,7 @@ snapshots:
dependencies:
commander: 5.1.0
glob: 7.2.3
minimatch: 3.1.2
minimatch: 3.1.3
'@electron/get@2.0.3':
dependencies:
@ -4871,7 +4891,7 @@ snapshots:
debug: 4.4.3
dir-compare: 3.3.0
fs-extra: 9.1.0
minimatch: 3.1.2
minimatch: 3.1.3
plist: 3.1.0
transitivePeerDependencies:
- supports-color
@ -4883,7 +4903,7 @@ snapshots:
debug: 4.4.3
dir-compare: 4.2.0
fs-extra: 11.3.3
minimatch: 9.0.5
minimatch: 9.0.6
plist: 3.1.0
transitivePeerDependencies:
- supports-color
@ -5068,7 +5088,7 @@ snapshots:
dependencies:
'@eslint/object-schema': 2.1.7
debug: 4.4.3
minimatch: 3.1.2
minimatch: 3.1.3
transitivePeerDependencies:
- supports-color
@ -5082,14 +5102,14 @@ snapshots:
'@eslint/eslintrc@3.3.3':
dependencies:
ajv: 6.12.6
ajv: 6.14.0
debug: 4.4.3
espree: 10.4.0
globals: 14.0.0
ignore: 5.3.2
import-fresh: 3.3.1
js-yaml: 4.1.1
minimatch: 3.1.2
minimatch: 3.1.3
strip-json-comments: 3.1.1
transitivePeerDependencies:
- supports-color
@ -5107,8 +5127,8 @@ snapshots:
'@fastify/ajv-compiler@4.0.5':
dependencies:
ajv: 8.17.1
ajv-formats: 3.0.1(ajv@8.17.1)
ajv: 8.18.0
ajv-formats: 3.0.1(ajv@8.18.0)
fast-uri: 3.1.0
'@fastify/cors@11.2.0':
@ -5165,10 +5185,6 @@ snapshots:
'@isaacs/balanced-match@4.0.1': {}
'@isaacs/brace-expansion@5.0.0':
dependencies:
'@isaacs/balanced-match': 4.0.1
'@isaacs/brace-expansion@5.0.1':
dependencies:
'@isaacs/balanced-match': 4.0.1
@ -5509,6 +5525,10 @@ snapshots:
dependencies:
undici-types: 5.26.5
'@types/node@20.19.33':
dependencies:
undici-types: 6.21.0
'@types/node@24.10.12':
dependencies:
undici-types: 7.16.0
@ -5549,6 +5569,8 @@ snapshots:
'@types/verror@1.10.11':
optional: true
'@types/whatwg-mimetype@3.0.2': {}
'@types/yauzl@2.10.3':
dependencies:
'@types/node': 25.0.7
@ -5621,7 +5643,7 @@ snapshots:
'@typescript-eslint/types': 8.54.0
'@typescript-eslint/visitor-keys': 8.54.0
debug: 4.4.3
minimatch: 9.0.5
minimatch: 9.0.6
semver: 7.7.3
tinyglobby: 0.2.15
ts-api-utils: 2.4.0(typescript@5.9.3)
@ -5718,7 +5740,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
'@vitest/coverage-v8@3.2.4(vitest@3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@17.6.3)(terser@5.46.0))':
'@vitest/coverage-v8@3.2.4(vitest@3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@20.0.2)(terser@5.46.0))':
dependencies:
'@ampproject/remapping': 2.3.0
'@bcoe/v8-coverage': 1.0.2
@ -5733,7 +5755,7 @@ snapshots:
std-env: 3.10.0
test-exclude: 7.0.1
tinyrainbow: 2.0.0
vitest: 3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@17.6.3)(terser@5.46.0)
vitest: 3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@20.0.2)(terser@5.46.0)
transitivePeerDependencies:
- supports-color
@ -5791,6 +5813,9 @@ snapshots:
acorn@8.15.0: {}
acorn@8.16.0:
optional: true
agent-base@6.0.2:
dependencies:
debug: 4.4.3
@ -5808,22 +5833,22 @@ snapshots:
clean-stack: 2.2.0
indent-string: 4.0.0
ajv-formats@3.0.1(ajv@8.17.1):
ajv-formats@3.0.1(ajv@8.18.0):
optionalDependencies:
ajv: 8.17.1
ajv: 8.18.0
ajv-keywords@3.5.2(ajv@6.12.6):
ajv-keywords@3.5.2(ajv@6.14.0):
dependencies:
ajv: 6.12.6
ajv: 6.14.0
ajv@6.12.6:
ajv@6.14.0:
dependencies:
fast-deep-equal: 3.1.3
fast-json-stable-stringify: 2.1.0
json-schema-traverse: 0.4.1
uri-js: 4.4.1
ajv@8.17.1:
ajv@8.18.0:
dependencies:
fast-deep-equal: 3.1.3
fast-uri: 3.1.0
@ -5876,10 +5901,10 @@ snapshots:
isbinaryfile: 5.0.7
js-yaml: 4.1.1
lazy-val: 1.0.5
minimatch: 5.1.6
minimatch: 5.1.7
read-config-file: 6.3.2
sanitize-filename: 1.6.3
semver: 7.7.3
semver: 7.7.4
tar: 6.2.1
temp-file: 3.4.0
transitivePeerDependencies:
@ -5915,7 +5940,7 @@ snapshots:
js-yaml: 4.1.1
json5: 2.2.3
lazy-val: 1.0.5
minimatch: 10.1.2
minimatch: 10.2.2
resedit: 1.7.2
sanitize-filename: 1.6.3
semver: 7.7.3
@ -6099,6 +6124,8 @@ snapshots:
balanced-match@1.0.2: {}
balanced-match@4.0.3: {}
base64-js@1.5.1: {}
baseline-browser-mapping@2.9.14: {}
@ -6133,6 +6160,10 @@ snapshots:
dependencies:
balanced-match: 1.0.2
brace-expansion@5.0.2:
dependencies:
balanced-match: 4.0.3
braces@3.0.3:
dependencies:
fill-range: 7.1.1
@ -6520,11 +6551,11 @@ snapshots:
dir-compare@3.3.0:
dependencies:
buffer-equal: 1.0.1
minimatch: 3.1.2
minimatch: 3.1.3
dir-compare@4.2.0:
dependencies:
minimatch: 3.1.2
minimatch: 3.1.3
p-limit: 3.1.0
dlv@1.1.3: {}
@ -6548,7 +6579,7 @@ snapshots:
dependencies:
'@types/plist': 3.0.5
'@types/verror': 1.10.11
ajv: 6.12.6
ajv: 6.14.0
crc: 3.8.0
iconv-corefoundation: 1.1.7
plist: 3.1.0
@ -6928,7 +6959,7 @@ snapshots:
hasown: 2.0.2
is-core-module: 2.16.1
is-glob: 4.0.3
minimatch: 3.1.2
minimatch: 3.1.3
object.fromentries: 2.0.8
object.groupby: 1.0.3
object.values: 1.2.1
@ -6956,7 +6987,7 @@ snapshots:
hasown: 2.0.2
jsx-ast-utils: 3.3.5
language-tags: 1.0.9
minimatch: 3.1.2
minimatch: 3.1.3
object.fromentries: 2.0.8
safe-regex-test: 1.1.0
string.prototype.includes: 2.0.1
@ -6988,7 +7019,7 @@ snapshots:
estraverse: 5.3.0
hasown: 2.0.2
jsx-ast-utils: 3.3.5
minimatch: 3.1.2
minimatch: 3.1.3
object.entries: 1.1.9
object.fromentries: 2.0.8
object.values: 1.2.1
@ -7049,7 +7080,7 @@ snapshots:
'@humanwhocodes/module-importer': 1.0.1
'@humanwhocodes/retry': 0.4.3
'@types/estree': 1.0.8
ajv: 6.12.6
ajv: 6.14.0
chalk: 4.1.2
cross-spawn: 7.0.6
debug: 4.4.3
@ -7068,7 +7099,7 @@ snapshots:
is-glob: 4.0.3
json-stable-stringify-without-jsonify: 1.0.1
lodash.merge: 4.6.2
minimatch: 3.1.2
minimatch: 3.1.3
natural-compare: 1.4.0
optionator: 0.9.4
optionalDependencies:
@ -7136,8 +7167,8 @@ snapshots:
fast-json-stringify@6.3.0:
dependencies:
'@fastify/merge-json-schemas': 0.2.1
ajv: 8.17.1
ajv-formats: 3.0.1(ajv@8.17.1)
ajv: 8.18.0
ajv-formats: 3.0.1(ajv@8.18.0)
fast-uri: 3.1.0
json-schema-ref-resolver: 3.0.0
rfdc: 1.4.1
@ -7192,7 +7223,7 @@ snapshots:
filelist@1.0.4:
dependencies:
minimatch: 5.1.6
minimatch: 5.1.7
fill-range@7.1.1:
dependencies:
@ -7351,14 +7382,14 @@ snapshots:
dependencies:
foreground-child: 3.3.1
jackspeak: 3.4.3
minimatch: 9.0.5
minimatch: 9.0.6
minipass: 7.1.2
package-json-from-dist: 1.0.1
path-scurry: 1.11.1
glob@13.0.2:
dependencies:
minimatch: 10.1.2
minimatch: 10.2.2
minipass: 7.1.2
path-scurry: 2.0.1
@ -7367,7 +7398,7 @@ snapshots:
fs.realpath: 1.0.0
inflight: 1.0.6
inherits: 2.0.4
minimatch: 3.1.2
minimatch: 3.1.3
once: 1.4.0
path-is-absolute: 1.0.1
@ -7376,7 +7407,7 @@ snapshots:
fs.realpath: 1.0.0
inflight: 1.0.6
inherits: 2.0.4
minimatch: 5.1.6
minimatch: 5.1.7
once: 1.4.0
global-agent@3.0.0:
@ -7425,9 +7456,10 @@ snapshots:
optionalDependencies:
uglify-js: 3.19.3
happy-dom@17.6.3:
happy-dom@20.0.2:
dependencies:
webidl-conversions: 7.0.0
'@types/node': 20.19.33
'@types/whatwg-mimetype': 3.0.2
whatwg-mimetype: 3.0.0
has-bigints@1.1.0: {}
@ -8351,24 +8383,24 @@ snapshots:
mimic-response@3.1.0: {}
minimatch@10.1.1:
dependencies:
'@isaacs/brace-expansion': 5.0.0
minimatch@10.1.2:
dependencies:
'@isaacs/brace-expansion': 5.0.1
minimatch@3.1.2:
minimatch@10.2.2:
dependencies:
brace-expansion: 5.0.2
minimatch@3.1.3:
dependencies:
brace-expansion: 1.1.12
minimatch@5.1.6:
minimatch@5.1.7:
dependencies:
brace-expansion: 2.0.2
minimatch@9.0.5:
minimatch@9.0.6:
dependencies:
brace-expansion: 2.0.2
brace-expansion: 5.0.2
minimist@1.2.8: {}
@ -8832,7 +8864,7 @@ snapshots:
readdir-glob@1.1.3:
dependencies:
minimatch: 5.1.6
minimatch: 5.1.7
readdirp@3.6.0:
dependencies:
@ -9057,6 +9089,8 @@ snapshots:
semver@7.7.3: {}
semver@7.7.4: {}
serialize-error@7.0.1:
dependencies:
type-fest: 0.13.1
@ -9383,7 +9417,7 @@ snapshots:
terser@5.46.0:
dependencies:
'@jridgewell/source-map': 0.3.11
acorn: 8.15.0
acorn: 8.16.0
commander: 2.20.3
source-map-support: 0.5.21
optional: true
@ -9392,7 +9426,7 @@ snapshots:
dependencies:
'@istanbuljs/schema': 0.1.3
glob: 10.5.0
minimatch: 9.0.5
minimatch: 9.0.6
thenify-all@1.6.0:
dependencies:
@ -9534,6 +9568,8 @@ snapshots:
undici-types@5.26.5: {}
undici-types@6.21.0: {}
undici-types@7.16.0: {}
unified@11.0.5:
@ -9668,7 +9704,7 @@ snapshots:
fsevents: 2.3.3
terser: 5.46.0
vitest@3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@17.6.3)(terser@5.46.0):
vitest@3.2.4(@types/debug@4.1.12)(@types/node@25.0.7)(happy-dom@20.0.2)(terser@5.46.0):
dependencies:
'@types/chai': 5.2.3
'@vitest/expect': 3.2.4
@ -9696,7 +9732,7 @@ snapshots:
optionalDependencies:
'@types/debug': 4.1.12
'@types/node': 25.0.7
happy-dom: 17.6.3
happy-dom: 20.0.2
transitivePeerDependencies:
- less
- lightningcss
@ -9714,8 +9750,6 @@ snapshots:
dependencies:
defaults: 1.0.4
webidl-conversions@7.0.0: {}
whatwg-mimetype@3.0.0: {}
which-boxed-primitive@1.1.1:

4195
resources/pricing.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,113 @@
#!/usr/bin/env tsx
/**
* Fetch latest model pricing from LiteLLM and save to renderer assets.
* Filters to Claude models only to reduce bundle size.
* Runs automatically during prebuild.
*/
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const LITELLM_PRICING_URL =
'https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json';
const OUTPUT_PATH = path.join(__dirname, '..', 'resources', 'pricing.json');
const FETCH_TIMEOUT = 10000; // 10 seconds
interface ModelPricing {
input_cost_per_token: number;
output_cost_per_token: number;
cache_creation_input_token_cost?: number;
cache_read_input_token_cost?: number;
input_cost_per_token_above_200k_tokens?: number;
output_cost_per_token_above_200k_tokens?: number;
cache_creation_input_token_cost_above_200k_tokens?: number;
cache_read_input_token_cost_above_200k_tokens?: number;
[key: string]: unknown;
}
function isValidModelPricing(entry: unknown): entry is ModelPricing {
return (
typeof entry === 'object' &&
entry !== null &&
'input_cost_per_token' in entry &&
'output_cost_per_token' in entry &&
typeof (entry as ModelPricing).input_cost_per_token === 'number' &&
typeof (entry as ModelPricing).output_cost_per_token === 'number'
);
}
function isClaudeModel(modelName: string): boolean {
const lower = modelName.toLowerCase();
return lower.includes('claude');
}
async function fetchPricingData(): Promise<Record<string, ModelPricing>> {
console.log('Fetching pricing data from LiteLLM...');
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT);
try {
const response = await fetch(LITELLM_PRICING_URL, { signal: controller.signal });
clearTimeout(timeout);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = (await response.json()) as Record<string, unknown>;
console.log(`Fetched pricing for ${Object.keys(data).length} models`);
// Filter to Claude models only and validate entries
const claudeModels: Record<string, ModelPricing> = {};
for (const [modelName, entry] of Object.entries(data)) {
if (isClaudeModel(modelName) && isValidModelPricing(entry)) {
claudeModels[modelName] = entry;
}
}
console.log(`Filtered to ${Object.keys(claudeModels).length} Claude models`);
return claudeModels;
} catch (error) {
clearTimeout(timeout);
if (error instanceof Error && error.name === 'AbortError') {
throw new Error('Fetch timeout after 10 seconds');
}
throw error;
}
}
async function main(): Promise<void> {
try {
console.log('Fetching pricing data for models...');
const pricing = await fetchPricingData();
// Ensure output directory exists
const outputDir = path.dirname(OUTPUT_PATH);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Write formatted JSON
fs.writeFileSync(OUTPUT_PATH, JSON.stringify(pricing, null, 2), 'utf-8');
// Calculate file size
const stats = fs.statSync(OUTPUT_PATH);
const sizeKB = (stats.size / 1024).toFixed(2);
console.log(`✓ Wrote pricing data to ${OUTPUT_PATH}`);
console.log(` Bundle size: ${sizeKB} KB`);
} catch (error) {
console.error('Failed to fetch pricing data:', error);
console.error('Build will continue with existing pricing.json if available');
// Don't fail the build - allow using existing pricing.json
process.exit(0);
}
}
main();

View file

@ -14,7 +14,7 @@ import { createLogger } from '@shared/utils/logger';
import * as fs from 'fs';
import * as path from 'path';
import { type ClaudeMdFileInfo, readAllClaudeMdFiles, readDirectoryClaudeMd } from '../services';
import { type ClaudeMdFileInfo, readAgentConfigs, readAllClaudeMdFiles, readDirectoryClaudeMd } from '../services';
import { validateFilePath } from '../utils/pathValidation';
import { countTokens } from '../utils/tokenizer';
@ -123,4 +123,15 @@ export function registerUtilityRoutes(app: FastifyInstance): void {
app.post<{ Body: { url: string } }>('/api/open-external', async () => {
return { success: false, error: 'Not available in browser mode' };
});
// Read agent configs
app.post<{ Body: { projectRoot: string } }>('/api/read-agent-configs', async (request) => {
try {
const { projectRoot } = request.body;
return await readAgentConfigs(projectRoot);
} catch (error) {
logger.error('Error in POST /api/read-agent-configs:', error);
return {};
}
});
}

View file

@ -310,7 +310,7 @@ function initializeServices(): void {
});
ipcMain.handle(HTTP_SERVER_GET_STATUS, () => {
return { running: httpServer.isRunning(), port: httpServer.getPort() };
return { success: true, data: { running: httpServer.isRunning(), port: httpServer.getPort() } };
});
// Forward SSH state changes to renderer and HTTP SSE clients
@ -481,7 +481,16 @@ function createWindow(): void {
const ZOOM_OUT_KEYS = new Set(['-', '_']);
mainWindow.webContents.on('before-input-event', (event, input) => {
if (!mainWindow || mainWindow.isDestroyed()) return;
if (!input.meta || input.type !== 'keyDown') return;
if (input.type !== 'keyDown') return;
// Prevent Electron's default Ctrl+R / Cmd+R page reload so the renderer
// keyboard handler can use it as "Refresh Session" (fixes #58).
if ((input.control || input.meta) && input.key.toLowerCase() === 'r') {
event.preventDefault();
return;
}
if (!input.meta) return;
const currentLevel = mainWindow.webContents.getZoomLevel();

View file

@ -203,6 +203,7 @@ function validateGeneralSection(data: unknown): ValidationSuccess<'general'> | V
'theme',
'defaultTab',
'claudeRootPath',
'autoExpandAIGroups',
];
const result: Partial<GeneralConfig> = {};
@ -267,6 +268,12 @@ function validateGeneralSection(data: unknown): ValidationSuccess<'general'> | V
result.claudeRootPath = path.resolve(normalized);
}
break;
case 'autoExpandAIGroups':
if (typeof value !== 'boolean') {
return { valid: false, error: `general.${key} must be a boolean` };
}
result.autoExpandAIGroups = value;
break;
default:
return { valid: false, error: `Unsupported general key: ${key}` };
}

View file

@ -12,7 +12,9 @@ import { createLogger } from '@shared/utils/logger';
import { app, type IpcMain, type IpcMainInvokeEvent, shell } from 'electron';
import * as fs from 'fs';
import { type ClaudeMdFileInfo, readAllClaudeMdFiles, readDirectoryClaudeMd } from '../services';
import { type ClaudeMdFileInfo, readAgentConfigs, readAllClaudeMdFiles, readDirectoryClaudeMd } from '../services';
import type { AgentConfig } from '@shared/types/api';
const logger = createLogger('IPC:utility');
import { validateFilePath, validateOpenPath } from '../utils/pathValidation';
@ -28,6 +30,7 @@ export function registerUtilityHandlers(ipcMain: IpcMain): void {
ipcMain.handle('read-claude-md-files', handleReadClaudeMdFiles);
ipcMain.handle('read-directory-claude-md', handleReadDirectoryClaudeMd);
ipcMain.handle('read-mentioned-file', handleReadMentionedFile);
ipcMain.handle('read-agent-configs', handleReadAgentConfigs);
logger.info('Utility handlers registered');
}
@ -42,6 +45,7 @@ export function removeUtilityHandlers(ipcMain: IpcMain): void {
ipcMain.removeHandler('read-claude-md-files');
ipcMain.removeHandler('read-directory-claude-md');
ipcMain.removeHandler('read-mentioned-file');
ipcMain.removeHandler('read-agent-configs');
logger.info('Utility handlers removed');
}
@ -228,3 +232,19 @@ async function handleReadMentionedFile(
return null;
}
}
/**
* Handler for 'read-agent-configs' IPC call.
* Reads agent definitions from project's .claude/agents/ directory.
*/
async function handleReadAgentConfigs(
_event: IpcMainInvokeEvent,
projectRoot: string
): Promise<Record<string, AgentConfig>> {
try {
return await readAgentConfigs(projectRoot);
} catch (error) {
logger.error('Error in read-agent-configs:', error);
return {};
}
}

View file

@ -0,0 +1,95 @@
/**
* SearchTextCache - LRU cache for extracted search text with mtime invalidation.
*
* Caches SearchTextResult per session file path. Entries are small (~1KB each,
* just text + metadata), so 200 entries is a reasonable default.
*
* Invalidation: mtime comparison on get(). If the file's mtime has changed
* since caching, the entry is considered stale and undefined is returned.
* No TTL needed mtime check is sufficient.
*/
import type { SearchableEntry } from './SearchTextExtractor';
interface CacheEntry {
entries: SearchableEntry[];
sessionTitle: string | undefined;
mtimeMs: number;
}
export class SearchTextCache {
private readonly cache = new Map<string, CacheEntry>();
private readonly maxSize: number;
constructor(maxSize: number = 200) {
this.maxSize = maxSize;
}
/**
* Get cached entries for a file path if the mtime matches.
* Returns undefined if not cached or stale.
*/
get(
filePath: string,
mtimeMs: number
): { entries: SearchableEntry[]; sessionTitle: string | undefined } | undefined {
const entry = this.cache.get(filePath);
if (!entry) return undefined;
// Stale — file was modified since we cached it
if (entry.mtimeMs !== mtimeMs) {
this.cache.delete(filePath);
return undefined;
}
// LRU: delete and re-insert to move to end (most recent)
this.cache.delete(filePath);
this.cache.set(filePath, entry);
return { entries: entry.entries, sessionTitle: entry.sessionTitle };
}
/**
* Cache extracted entries for a file path.
*/
set(
filePath: string,
mtimeMs: number,
entries: SearchableEntry[],
sessionTitle: string | undefined
): void {
// If already exists, delete first to update position
this.cache.delete(filePath);
// Evict oldest if at capacity
if (this.cache.size >= this.maxSize) {
const oldest = this.cache.keys().next().value;
if (oldest !== undefined) {
this.cache.delete(oldest);
}
}
this.cache.set(filePath, { entries, sessionTitle, mtimeMs });
}
/**
* Remove a specific entry from the cache.
*/
invalidate(filePath: string): void {
this.cache.delete(filePath);
}
/**
* Clear all cached entries.
*/
clear(): void {
this.cache.clear();
}
/**
* Current number of cached entries.
*/
get size(): number {
return this.cache.size;
}
}

View file

@ -0,0 +1,159 @@
/**
* SearchTextExtractor - Lightweight text extraction for search.
*
* Mirrors ChunkBuilder's classification loop (classifyMessages buffer flush)
* but only extracts searchable text + metadata, skipping all expensive operations:
* - No tool execution building
* - No semantic step extraction
* - No subagent linking
* - No timeline gap filling
* - No metrics calculation
*/
import { classifyMessages } from '@main/services/parsing/MessageClassifier';
import { sanitizeDisplayContent } from '@shared/utils/contentSanitizer';
import type { ParsedMessage } from '@main/types';
/**
* A lightweight entry containing only the data needed for search matching.
*/
export interface SearchableEntry {
text: string;
groupId: string;
messageType: 'user' | 'assistant';
itemType: 'user' | 'ai';
timestamp: number;
messageUuid: string;
}
/**
* Result of extracting searchable text from a session's messages.
*/
export interface SearchTextResult {
entries: SearchableEntry[];
sessionTitle: string | undefined;
}
/**
* Extract searchable text entries from parsed messages.
*
* Algorithm mirrors ChunkBuilder.buildChunks() lines 78-151:
* - Filter to main thread (!m.isSidechain)
* - classifyMessages() cheap type guard checks
* - Walk classified messages with an aiBuffer:
* - hardNoise skip
* - compact / system / user flush AI buffer, then handle
* - ai push to buffer
* - Flush remaining buffer at end
*/
export function extractSearchableEntries(messages: ParsedMessage[]): SearchTextResult {
const entries: SearchableEntry[] = [];
let sessionTitle: string | undefined;
// Filter to main thread messages (non-sidechain) — same as ChunkBuilder line 82
const mainMessages = messages.filter((m) => !m.isSidechain);
const classified = classifyMessages(mainMessages);
let aiBuffer: ParsedMessage[] = [];
for (const { message, category } of classified) {
switch (category) {
case 'hardNoise':
// Skip — filtered out
break;
case 'compact':
case 'system':
// Flush AI buffer, but compact/system messages have no searchable text
if (aiBuffer.length > 0) {
const aiEntry = extractAIEntry(aiBuffer);
if (aiEntry) entries.push(aiEntry);
aiBuffer = [];
}
break;
case 'user': {
// Flush AI buffer
if (aiBuffer.length > 0) {
const aiEntry = extractAIEntry(aiBuffer);
if (aiEntry) entries.push(aiEntry);
aiBuffer = [];
}
// Extract user text
const userText = extractUserText(message);
if (userText) {
if (!sessionTitle) {
sessionTitle = userText.slice(0, 100);
}
entries.push({
text: userText,
groupId: `user-${message.uuid}`,
messageType: 'user',
itemType: 'user',
timestamp: message.timestamp.getTime(),
messageUuid: message.uuid,
});
}
break;
}
case 'ai':
aiBuffer.push(message);
break;
}
}
// Flush remaining AI buffer
if (aiBuffer.length > 0) {
const aiEntry = extractAIEntry(aiBuffer);
if (aiEntry) entries.push(aiEntry);
}
return { entries, sessionTitle };
}
/**
* Extract the last text output from an AI message buffer.
* Scans backward for the last assistant message with a text content block.
*/
function extractAIEntry(buffer: ParsedMessage[]): SearchableEntry | null {
// Scan backward for last assistant message with text content
for (let i = buffer.length - 1; i >= 0; i--) {
const msg = buffer[i];
if (msg.role !== 'assistant' || !Array.isArray(msg.content)) continue;
// Find the last text block in this message
for (let j = msg.content.length - 1; j >= 0; j--) {
const block = msg.content[j];
if (block.type === 'text' && block.text) {
return {
text: block.text,
groupId: `ai-${buffer[0].uuid}`,
messageType: 'assistant',
itemType: 'ai',
timestamp: msg.timestamp.getTime(),
messageUuid: msg.uuid,
};
}
}
}
return null;
}
/**
* Extract searchable text from a user message.
* Shared logic previously in SessionSearcher.extractUserSearchableText().
*/
export function extractUserText(message: ParsedMessage): string {
let rawText = '';
if (typeof message.content === 'string') {
rawText = message.content;
} else if (Array.isArray(message.content)) {
rawText = message.content
.filter((block) => block.type === 'text')
.map((block) => block.text)
.join('');
}
return sanitizeDisplayContent(rawText);
}

View file

@ -6,21 +6,14 @@
* - Search within a single session file
* - Restrict matching scope to User text + AI last text output
* - Extract context around each match occurrence
*
* Uses SearchTextExtractor for lightweight text extraction (skips ChunkBuilder)
* and SearchTextCache for mtime-based caching of extracted entries.
*/
import { ChunkBuilder } from '@main/services/analysis/ChunkBuilder';
import { LocalFileSystemProvider } from '@main/services/infrastructure/LocalFileSystemProvider';
import {
isEnhancedAIChunk,
isUserChunk,
type ParsedMessage,
type SearchResult,
type SearchSessionsResult,
type SemanticStep,
} from '@main/types';
import { parseJsonlFile } from '@main/utils/jsonl';
import { extractBaseDir, extractSessionId } from '@main/utils/pathDecoder';
import { sanitizeDisplayContent } from '@shared/utils/contentSanitizer';
import { createLogger } from '@shared/utils/logger';
import {
extractMarkdownPlainText,
@ -28,36 +21,31 @@ import {
} from '@shared/utils/markdownTextSearch';
import * as path from 'path';
import { SearchTextCache } from './SearchTextCache';
import { extractSearchableEntries } from './SearchTextExtractor';
import { subprojectRegistry } from './SubprojectRegistry';
import type { SearchableEntry } from './SearchTextExtractor';
import type { FileSystemProvider } from '@main/services/infrastructure/FileSystemProvider';
import type { SearchResult, SearchSessionsResult } from '@main/types';
const logger = createLogger('Discovery:SessionSearcher');
const SSH_FAST_SEARCH_STAGE_LIMITS = [40, 140, 320] as const;
const SSH_FAST_SEARCH_MIN_RESULTS = 8;
const SSH_FAST_SEARCH_TIME_BUDGET_MS = 4500;
interface SearchableEntry {
text: string;
groupId: string;
messageType: 'user' | 'assistant';
itemType: 'user' | 'ai';
timestamp: number;
messageUuid: string;
}
/**
* SessionSearcher provides methods for searching sessions.
*/
export class SessionSearcher {
private readonly projectsDir: string;
private readonly chunkBuilder: ChunkBuilder;
private readonly fsProvider: FileSystemProvider;
private readonly searchCache: SearchTextCache;
constructor(projectsDir: string, fsProvider?: FileSystemProvider) {
this.projectsDir = projectsDir;
this.chunkBuilder = new ChunkBuilder();
this.fsProvider = fsProvider ?? new LocalFileSystemProvider();
this.searchCache = new SearchTextCache();
}
/**
@ -151,7 +139,8 @@ export class SessionSearcher {
sessionId,
file.filePath,
normalizedQuery,
maxResults
maxResults,
file.mtimeMs
);
})
);
@ -207,11 +196,15 @@ export class SessionSearcher {
/**
* Searches a single session file for a query string.
*
* Uses SearchTextExtractor for lightweight text extraction (no ChunkBuilder)
* and SearchTextCache for mtime-based caching.
*
* @param projectId - The project ID
* @param sessionId - The session ID
* @param filePath - Path to the session file
* @param query - Normalized search query (lowercase)
* @param maxResults - Maximum number of results to return
* @param mtimeMs - File modification time for cache invalidation
* @returns Array of search results
*/
async searchSessionFile(
@ -219,71 +212,35 @@ export class SessionSearcher {
sessionId: string,
filePath: string,
query: string,
maxResults: number
maxResults: number,
mtimeMs: number
): Promise<SearchResult[]> {
const results: SearchResult[] = [];
let sessionTitle: string | undefined;
const messages = await parseJsonlFile(filePath, this.fsProvider);
const chunks = this.chunkBuilder.buildChunks(messages, []);
for (const chunk of chunks) {
if (results.length >= maxResults) {
break;
}
// Check cache first
let cached = this.searchCache.get(filePath, mtimeMs);
if (!cached) {
// Cache miss — parse and extract
const messages = await parseJsonlFile(filePath, this.fsProvider);
const extracted = extractSearchableEntries(messages);
this.searchCache.set(filePath, mtimeMs, extracted.entries, extracted.sessionTitle);
cached = extracted;
}
if (isUserChunk(chunk)) {
const userText = this.extractUserSearchableText(chunk.userMessage);
if (!sessionTitle && userText) {
sessionTitle = userText.slice(0, 100);
}
if (!userText) {
continue;
}
const searchableEntry: SearchableEntry = {
text: userText,
groupId: chunk.id,
messageType: 'user',
itemType: 'user',
timestamp: chunk.userMessage.timestamp.getTime(),
messageUuid: chunk.userMessage.uuid,
};
this.collectMatchesForEntry(
searchableEntry,
query,
results,
maxResults,
projectId,
sessionId,
sessionTitle
);
continue;
}
const { entries, sessionTitle } = cached;
if (isEnhancedAIChunk(chunk)) {
const lastOutputStep = this.findLastOutputTextStep(chunk.semanticSteps);
const outputText = lastOutputStep?.content.outputText;
if (!lastOutputStep || !outputText) {
continue;
}
for (const entry of entries) {
if (results.length >= maxResults) break;
const searchableEntry: SearchableEntry = {
text: outputText,
groupId: chunk.id,
messageType: 'assistant',
itemType: 'ai',
timestamp: lastOutputStep.startTime.getTime(),
messageUuid: lastOutputStep.sourceMessageId ?? chunk.responses[0]?.uuid ?? '',
};
this.collectMatchesForEntry(
searchableEntry,
query,
results,
maxResults,
projectId,
sessionId,
sessionTitle
);
}
this.collectMatchesForEntry(
entry,
query,
results,
maxResults,
projectId,
sessionId,
sessionTitle
);
}
return results;
@ -342,29 +299,6 @@ export class SessionSearcher {
}
}
private extractUserSearchableText(message: ParsedMessage): string {
let rawText = '';
if (typeof message.content === 'string') {
rawText = message.content;
} else if (Array.isArray(message.content)) {
rawText = message.content
.filter((block) => block.type === 'text')
.map((block) => block.text)
.join('');
}
return sanitizeDisplayContent(rawText);
}
private findLastOutputTextStep(steps: SemanticStep[]): SemanticStep | null {
for (let i = steps.length - 1; i >= 0; i--) {
const step = steps[i];
if (step.type === 'output' && step.content.outputText) {
return step;
}
}
return null;
}
private async collectFulfilledInBatches<T, R>(
items: T[],
batchSize: number,

View file

@ -12,6 +12,8 @@
export * from './ProjectPathResolver';
export * from './ProjectScanner';
export * from './SearchTextCache';
export * from './SearchTextExtractor';
export * from './SessionContentFilter';
export * from './SessionSearcher';
export * from './SubagentLocator';

View file

@ -181,6 +181,7 @@ export interface GeneralConfig {
theme: 'dark' | 'light' | 'system';
defaultTab: 'dashboard' | 'last-session';
claudeRootPath: string | null;
autoExpandAIGroups: boolean;
}
export interface DisplayConfig {
@ -248,6 +249,7 @@ const DEFAULT_CONFIG: AppConfig = {
theme: 'dark',
defaultTab: 'dashboard',
claudeRootPath: null,
autoExpandAIGroups: false,
},
display: {
showTimestamps: true,

View file

@ -43,11 +43,25 @@ export class LocalFileSystemProvider implements FileSystemProvider {
async readdir(dirPath: string): Promise<FsDirent[]> {
const entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
return entries.map((entry) => ({
name: entry.name,
isFile: () => entry.isFile(),
isDirectory: () => entry.isDirectory(),
}));
// Stat all entries concurrently to populate mtimeMs, used by SessionSearcher's
// mtime-based cache invalidation. Failures are silently ignored (mtimeMs stays undefined).
return Promise.all(
entries.map(async (entry) => {
let mtimeMs: number | undefined;
try {
const stat = await fs.promises.stat(`${dirPath}/${entry.name}`);
mtimeMs = stat.mtimeMs;
} catch {
// ignore
}
return {
name: entry.name,
mtimeMs,
isFile: () => entry.isFile(),
isDirectory: () => entry.isDirectory(),
};
})
);
}
createReadStream(filePath: string, opts?: ReadStreamOptions): fs.ReadStream {

View file

@ -373,8 +373,12 @@ export class NotificationManager extends EventEmitter {
* Shows a native macOS notification for an error.
*/
private showNativeNotification(error: DetectedError): void {
// Check if Notification is supported
if (!Notification.isSupported()) {
// Guard against standalone/Docker mode where Electron's Notification API is unavailable
if (
typeof Notification === 'undefined' ||
typeof Notification.isSupported !== 'function' ||
!Notification.isSupported()
) {
logger.warn('Native notifications not supported');
return;
}

View file

@ -0,0 +1,75 @@
/**
* Agent Config Reader
*
* Reads `.claude/agents/*.md` files from a project directory and extracts
* frontmatter metadata (name, color) for use in subagent visualization.
*/
import { createLogger } from '@shared/utils/logger';
import * as fs from 'fs';
import * as path from 'path';
import type { AgentConfig } from '@shared/types/api';
const logger = createLogger('AgentConfigReader');
/**
* Parse simple YAML frontmatter from markdown content.
* Only extracts top-level scalar key: value pairs between --- delimiters.
*/
function parseFrontmatter(content: string): Record<string, string> {
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(content);
if (!match) return {};
const result: Record<string, string> = {};
for (const line of match[1].split('\n')) {
const colonIdx = line.indexOf(':');
if (colonIdx === -1) continue;
const key = line.slice(0, colonIdx).trim();
let value = line.slice(colonIdx + 1).trim();
// Strip surrounding quotes
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
value = value.slice(1, -1);
}
if (key) result[key] = value;
}
return result;
}
/**
* Read agent config files from a project's `.claude/agents/` directory.
* Returns a map of agent name config (with optional color).
*/
export async function readAgentConfigs(
projectRoot: string
): Promise<Record<string, AgentConfig>> {
const agentsDir = path.join(projectRoot, '.claude', 'agents');
const result: Record<string, AgentConfig> = {};
try {
const entries = await fs.promises.readdir(agentsDir);
const mdFiles = entries.filter((f) => f.endsWith('.md'));
await Promise.all(
mdFiles.map(async (filename) => {
try {
const content = await fs.promises.readFile(path.join(agentsDir, filename), 'utf8');
const frontmatter = parseFrontmatter(content);
const name = frontmatter.name || filename.replace(/\.md$/, '');
const config: AgentConfig = { name };
if (frontmatter.color) {
config.color = frontmatter.color;
}
result[name] = config;
} catch {
// Skip unreadable files
}
})
);
} catch {
// Directory doesn't exist or unreadable — normal for projects without custom agents
logger.debug(`No agents directory at ${agentsDir}`);
}
return result;
}

View file

@ -8,6 +8,7 @@
* - GitIdentityResolver: Resolves git identities from sessions
*/
export * from './AgentConfigReader';
export * from './ClaudeMdReader';
export * from './GitIdentityResolver';
export * from './MessageClassifier';

View file

@ -461,6 +461,7 @@ export const EMPTY_METRICS: SessionMetrics = {
cacheReadTokens: 0,
cacheCreationTokens: 0,
messageCount: 0,
costUsd: 0,
};
// =============================================================================

View file

@ -212,6 +212,113 @@ function parseMessageType(type?: string): MessageType | null {
}
}
// =============================================================================
// Cost Calculation
// =============================================================================
import * as fs from 'fs';
import * as path from 'path';
interface ModelPricing {
input_cost_per_token: number;
output_cost_per_token: number;
cache_creation_input_token_cost?: number;
cache_read_input_token_cost?: number;
input_cost_per_token_above_200k_tokens?: number;
output_cost_per_token_above_200k_tokens?: number;
cache_creation_input_token_cost_above_200k_tokens?: number;
cache_read_input_token_cost_above_200k_tokens?: number;
[key: string]: unknown;
}
const TIER_THRESHOLD = 200_000;
// Cache pricing data in memory (loaded once on first use)
let pricingCache: Record<string, unknown> | null = null;
/**
* Load pricing data from resources directory.
* Uses electron-vite resource directory pattern:
* - Development: resources/pricing.json (project root)
* - Production: process.resourcesPath/pricing.json
*/
function loadPricingData(): Record<string, unknown> {
if (pricingCache !== null) {
return pricingCache;
}
try {
// Determine if we're in development or production
const isDev = process.env.NODE_ENV === 'development' || !process.resourcesPath;
let pricingPath: string;
if (isDev) {
// Development: Compiled code is in dist-electron/main/
// __dirname = /path/to/project/dist-electron/main
// Need to go up 2 levels to reach project root, then into resources/
pricingPath = path.join(__dirname, '..', '..', 'resources', 'pricing.json');
} else {
// Production: pricing.json in app's resources directory
pricingPath = path.join(process.resourcesPath, 'pricing.json');
}
const data = fs.readFileSync(pricingPath, 'utf-8');
pricingCache = JSON.parse(data) as Record<string, unknown>;
return pricingCache;
} catch (error) {
console.error('Failed to load pricing data:', error);
// Return empty object if pricing data can't be loaded
pricingCache = {};
return pricingCache;
}
}
function calculateTieredCost(tokens: number, baseRate: number, tieredRate?: number): number {
if (tokens <= 0) return 0;
if (!tieredRate || tokens <= TIER_THRESHOLD) {
return tokens * baseRate;
}
const costBelow = TIER_THRESHOLD * baseRate;
const costAbove = (tokens - TIER_THRESHOLD) * tieredRate;
return costBelow + costAbove;
}
function getPricing(modelName: string): ModelPricing | null {
const pricing = loadPricingData();
const tryGet = (key: string): ModelPricing | null => {
const entry = pricing[key];
if (
entry &&
typeof entry === 'object' &&
'input_cost_per_token' in entry &&
'output_cost_per_token' in entry
) {
return entry as ModelPricing;
}
return null;
};
// Try exact match
const exact = tryGet(modelName);
if (exact) return exact;
// Try lowercase
const lowerName = modelName.toLowerCase();
const lower = tryGet(lowerName);
if (lower) return lower;
// Try case-insensitive search
for (const key of Object.keys(pricing)) {
if (key.toLowerCase() === lowerName) {
const match = tryGet(key);
if (match) return match;
}
}
return null;
}
// =============================================================================
// Metrics Calculation
// =============================================================================
@ -228,7 +335,7 @@ export function calculateMetrics(messages: ParsedMessage[]): SessionMetrics {
let outputTokens = 0;
let cacheReadTokens = 0;
let cacheCreationTokens = 0;
const costUsd = 0;
let modelName: string | undefined;
// Get timestamps for duration (loop instead of Math.min/max spread to avoid stack overflow on large sessions)
const timestamps = messages.map((m) => m.timestamp.getTime()).filter((t) => !isNaN(t));
@ -244,12 +351,52 @@ export function calculateMetrics(messages: ParsedMessage[]): SessionMetrics {
}
}
// Calculate cost per-message, then sum (tiered pricing applies per-API-call, not to aggregated totals)
let costUsd = 0;
for (const msg of messages) {
if (msg.usage) {
inputTokens += msg.usage.input_tokens ?? 0;
outputTokens += msg.usage.output_tokens ?? 0;
cacheReadTokens += msg.usage.cache_read_input_tokens ?? 0;
cacheCreationTokens += msg.usage.cache_creation_input_tokens ?? 0;
const msgInputTokens = msg.usage.input_tokens ?? 0;
const msgOutputTokens = msg.usage.output_tokens ?? 0;
const msgCacheReadTokens = msg.usage.cache_read_input_tokens ?? 0;
const msgCacheCreationTokens = msg.usage.cache_creation_input_tokens ?? 0;
inputTokens += msgInputTokens;
outputTokens += msgOutputTokens;
cacheReadTokens += msgCacheReadTokens;
cacheCreationTokens += msgCacheCreationTokens;
// Calculate cost for this message if we have pricing data
if (msg.model && !modelName) {
modelName = msg.model;
}
if (msg.model) {
const pricing = getPricing(msg.model);
if (pricing) {
const inputCost = calculateTieredCost(
msgInputTokens,
pricing.input_cost_per_token,
pricing.input_cost_per_token_above_200k_tokens
);
const outputCost = calculateTieredCost(
msgOutputTokens,
pricing.output_cost_per_token,
pricing.output_cost_per_token_above_200k_tokens
);
const cacheCreationCost = calculateTieredCost(
msgCacheCreationTokens,
pricing.cache_creation_input_token_cost ?? 0,
pricing.cache_creation_input_token_cost_above_200k_tokens
);
const cacheReadCost = calculateTieredCost(
msgCacheReadTokens,
pricing.cache_read_input_token_cost ?? 0,
pricing.cache_read_input_token_cost_above_200k_tokens
);
costUsd += inputCost + outputCost + cacheCreationCost + cacheReadCost;
}
}
}
}
@ -261,7 +408,7 @@ export function calculateMetrics(messages: ParsedMessage[]): SessionMetrics {
cacheReadTokens,
cacheCreationTokens,
messageCount: messages.length,
costUsd: costUsd > 0 ? costUsd : undefined,
costUsd,
};
}

View file

@ -169,6 +169,10 @@ const electronAPI: ElectronAPI = {
readMentionedFile: (absolutePath: string, projectRoot: string, maxTokens?: number) =>
ipcRenderer.invoke('read-mentioned-file', absolutePath, projectRoot, maxTokens),
// Agent config reading
readAgentConfigs: (projectRoot: string) =>
ipcRenderer.invoke('read-agent-configs', projectRoot),
// Notifications API
notifications: {
get: (options?: { limit?: number; offset?: number }) =>

View file

@ -41,6 +41,7 @@ import type {
WaterfallData,
WslClaudeRootCandidate,
} from '@shared/types';
import type { AgentConfig } from '@shared/types/api';
export class HttpAPIClient implements ElectronAPI {
private baseUrl: string;
@ -309,6 +310,13 @@ export class HttpAPIClient implements ElectronAPI {
maxTokens,
});
// ---------------------------------------------------------------------------
// Agent config reading
// ---------------------------------------------------------------------------
readAgentConfigs = (projectRoot: string): Promise<Record<string, AgentConfig>> =>
this.post<Record<string, AgentConfig>>('/api/read-agent-configs', { projectRoot });
// ---------------------------------------------------------------------------
// Notifications (nested API)
// ---------------------------------------------------------------------------

View file

@ -245,6 +245,9 @@ const AIChatGroupInner = ({
return null;
}, [aiGroup.responses]);
// Get the total cost
const costUSD = aiGroup.metrics.costUsd;
// Calculate thinking and text output tokens from assistant message content blocks
// These are estimated from the actual content, providing breakdown of output token usage
const { thinkingTokens, textOutputTokens } = useMemo(() => {
@ -470,6 +473,7 @@ const AIChatGroupInner = ({
contextStats={contextStats}
phaseNumber={phaseNumber}
totalPhases={totalPhases}
costUsd={costUSD}
/>
)}

View file

@ -1,14 +1,21 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useAutoScrollBottom } from '@renderer/hooks/useAutoScrollBottom';
import { isNearBottom, useAutoScrollBottom } from '@renderer/hooks/useAutoScrollBottom';
import { useTabNavigationController } from '@renderer/hooks/useTabNavigationController';
import { useTabUI } from '@renderer/hooks/useTabUI';
import { useVisibleAIGroup } from '@renderer/hooks/useVisibleAIGroup';
import { useStore } from '@renderer/store';
import { useVirtualizer } from '@tanstack/react-virtual';
import { ChevronsDown } from 'lucide-react';
import { useShallow } from 'zustand/react/shallow';
import { SessionContextPanel } from './SessionContextPanel/index';
/** Pixels from bottom considered "near bottom" for scroll-button visibility and auto-scroll. */
const SCROLL_THRESHOLD = 300;
/** Must match the `w-80` (320px) context panel width used in the layout below. */
const CONTEXT_PANEL_WIDTH_PX = 320;
import { ChatHistoryEmptyState } from './ChatHistoryEmptyState';
import { ChatHistoryItem } from './ChatHistoryItem';
import { ChatHistoryLoadingState } from './ChatHistoryLoadingState';
@ -343,11 +350,21 @@ export const ChatHistory = ({ tabId }: ChatHistoryProps): JSX.Element => {
rootRef: scrollContainerRef,
});
// Scroll-to-bottom button visibility
const [showScrollButton, setShowScrollButton] = useState(false);
const checkScrollButton = useCallback(() => {
const container = scrollContainerRef.current;
if (!container) return;
const { scrollTop, scrollHeight, clientHeight } = container;
setShowScrollButton(!isNearBottom(scrollTop, scrollHeight, clientHeight, SCROLL_THRESHOLD));
}, []);
// Auto-follow when conversation updates, but only if the user was already near bottom.
// This preserves manual reading position when the user scrolls up.
// Disabled during navigation to prevent conflicts with deep-link/search scrolling.
useAutoScrollBottom([conversation], {
threshold: 150,
const { scrollToBottom } = useAutoScrollBottom([conversation], {
threshold: SCROLL_THRESHOLD,
smoothDuration: 300,
autoBehavior: 'auto',
disabled: shouldDisableAutoScroll,
@ -355,6 +372,11 @@ export const ChatHistory = ({ tabId }: ChatHistoryProps): JSX.Element => {
resetKey: effectiveTabId,
});
// Re-check button visibility whenever conversation updates
useEffect(() => {
checkScrollButton();
}, [conversation, checkScrollButton]);
// Callback to register AI group refs (combines with visibility hook)
const registerAIGroupRefCombined = useCallback(
(groupId: string) => {
@ -718,12 +740,13 @@ export const ChatHistory = ({ tabId }: ChatHistoryProps): JSX.Element => {
className="flex flex-1 flex-col overflow-hidden"
style={{ backgroundColor: 'var(--color-surface)' }}
>
<div className="flex flex-1 overflow-hidden">
<div className="relative flex flex-1 overflow-hidden">
{/* Chat content */}
<div
ref={scrollContainerRef}
className="flex-1 overflow-y-auto"
style={{ backgroundColor: 'var(--color-surface)' }}
onScroll={checkScrollButton}
>
{/* Sticky Context button */}
{allContextInjections.length > 0 && (
@ -813,6 +836,30 @@ export const ChatHistory = ({ tabId }: ChatHistoryProps): JSX.Element => {
</div>
</div>
{/* Scroll to bottom button */}
{showScrollButton && (
<button
onClick={() => {
scrollToBottom('smooth');
setShowScrollButton(false);
}}
className="absolute bottom-5 z-20 flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs shadow-lg backdrop-blur-md transition-all"
style={{
right:
isContextPanelVisible && allContextInjections.length > 0
? `calc(${CONTEXT_PANEL_WIDTH_PX}px + 1rem)`
: '1rem',
backgroundColor: 'var(--context-btn-bg)',
color: 'var(--color-text-secondary)',
border: '1px solid var(--color-border-emphasis)',
}}
title="Scroll to bottom"
>
<ChevronsDown className="size-3.5" />
<span>Bottom</span>
</button>
)}
{/* Context panel sidebar */}
{isContextPanelVisible && allContextInjections.length > 0 && (
<div className="w-80 shrink-0">
@ -824,6 +871,7 @@ export const ChatHistory = ({ tabId }: ChatHistoryProps): JSX.Element => {
onNavigateToTool={handleNavigateToTool}
onNavigateToUserGroup={handleNavigateToUserGroup}
totalSessionTokens={lastAiGroupTotalTokens}
sessionMetrics={sessionDetail?.metrics}
phaseInfo={sessionPhaseInfo ?? undefined}
selectedPhase={selectedContextPhase}
onPhaseChange={setSelectedContextPhase}

View file

@ -12,6 +12,7 @@ import {
COLOR_TEXT_MUTED,
COLOR_TEXT_SECONDARY,
} from '@renderer/constants/cssVariables';
import { formatCostUsd } from '@shared/utils/costFormatting';
import { ArrowDownWideNarrow, FileText, LayoutList, X } from 'lucide-react';
import { formatTokens } from '../utils/formatting';
@ -20,11 +21,13 @@ import { SessionContextHelpTooltip } from './SessionContextHelpTooltip';
import type { ContextViewMode } from '../types';
import type { ContextPhaseInfo } from '@renderer/types/contextInjection';
import type { SessionMetrics } from '@shared/types';
interface SessionContextHeaderProps {
injectionCount: number;
totalTokens: number;
totalSessionTokens?: number;
sessionMetrics?: SessionMetrics;
onClose?: () => void;
phaseInfo?: ContextPhaseInfo;
selectedPhase: number | null;
@ -37,6 +40,7 @@ export const SessionContextHeader = ({
injectionCount,
totalTokens,
totalSessionTokens,
sessionMetrics,
onClose,
phaseInfo,
selectedPhase,
@ -115,6 +119,24 @@ export const SessionContextHeader = ({
)}
</div>
{/* Session Metrics Breakdown */}
{sessionMetrics && (
<div
className="mt-2 grid grid-cols-2 gap-x-4 gap-y-1 pt-2 text-[10px]"
style={{ borderTop: `1px solid ${COLOR_BORDER_SUBTLE}` }}
>
{/* Cost */}
{sessionMetrics.costUsd !== undefined && sessionMetrics.costUsd > 0 && (
<div className="col-span-2">
<span style={{ color: COLOR_TEXT_MUTED }}>Session Cost: </span>
<span className="font-medium tabular-nums" style={{ color: COLOR_TEXT_SECONDARY }}>
{formatCostUsd(sessionMetrics.costUsd)}
</span>
</div>
)}
</div>
)}
{/* Phase selector - only shown when compactions exist */}
{phaseInfo && phaseInfo.phases.length > 1 && (
<div

View file

@ -48,6 +48,7 @@ export const SessionContextPanel = ({
onNavigateToTool,
onNavigateToUserGroup,
totalSessionTokens,
sessionMetrics,
phaseInfo,
selectedPhase,
onPhaseChange,
@ -190,6 +191,7 @@ export const SessionContextPanel = ({
injectionCount={injections.length}
totalTokens={totalTokens}
totalSessionTokens={totalSessionTokens}
sessionMetrics={sessionMetrics}
onClose={onClose}
phaseInfo={phaseInfo}
selectedPhase={selectedPhase}

View file

@ -4,6 +4,7 @@
import type { ClaudeMdSource } from '@renderer/types/claudeMd';
import type { ContextInjection, ContextPhaseInfo } from '@renderer/types/contextInjection';
import type { SessionMetrics } from '@shared/types';
// =============================================================================
// Props Interface
@ -24,6 +25,8 @@ export interface SessionContextPanelProps {
onNavigateToUserGroup?: (turnIndex: number) => void;
/** Total session tokens (input + output + cache) for comparison */
totalSessionTokens?: number;
/** Full session metrics (input, output, cache tokens, cost) */
sessionMetrics?: SessionMetrics;
/** Phase information for phase selector */
phaseInfo?: ContextPhaseInfo;
/** Currently selected phase (null = current/latest) */

View file

@ -11,11 +11,8 @@ import {
CARD_TEXT_LIGHTER,
COLOR_TEXT_MUTED,
COLOR_TEXT_SECONDARY,
TAG_BG,
TAG_BORDER,
TAG_TEXT,
} from '@renderer/constants/cssVariables';
import { getTeamColorSet } from '@renderer/constants/teamColors';
import { getSubagentTypeColorSet, getTeamColorSet } from '@renderer/constants/teamColors';
import { useTabUI } from '@renderer/hooks/useTabUI';
import { useStore } from '@renderer/store';
import { buildDisplayItemsFromMessages, buildSummary } from '@renderer/utils/aiGroupEnhancer';
@ -78,8 +75,13 @@ export const SubagentItem: React.FC<SubagentItemProps> = ({
const subagentType = subagent.subagentType ?? 'Task';
const truncatedDesc = description.length > 60 ? description.slice(0, 60) + '...' : description;
// Agent configs from .claude/agents/ for color lookup
const agentConfigs = useStore((s) => s.agentConfigs);
// Team member colors (when this subagent is a team member)
const teamColors = subagent.team ? getTeamColorSet(subagent.team.memberColor) : null;
// Type-based colors for non-team subagents (from agent config or deterministic hash)
const typeColors = !teamColors ? getSubagentTypeColorSet(subagentType, agentConfigs) : null;
// Detect shutdown-only team activations (trivial: just a shutdown_response)
const isShutdownOnly = useMemo(() => {
@ -285,11 +287,11 @@ export const SubagentItem: React.FC<SubagentItemProps> = ({
style={{ color: CARD_ICON_MUTED }}
/>
{/* Icon - colored dot for team members, Bot icon for regular subagents */}
{teamColors ? (
{/* Icon - colored dot for team members/typed subagents, Bot icon for generic */}
{teamColors || typeColors ? (
<span
className="size-3.5 shrink-0 rounded-full"
style={{ backgroundColor: teamColors.border }}
style={{ backgroundColor: (teamColors ?? typeColors)!.border }}
/>
) : (
<Bot
@ -298,7 +300,7 @@ export const SubagentItem: React.FC<SubagentItemProps> = ({
/>
)}
{/* Type badge - team member name or generic type */}
{/* Type badge - team member name or typed subagent */}
{teamColors && subagent.team ? (
<span
className="rounded px-1.5 py-0.5 text-[10px] font-medium tracking-wide"
@ -314,9 +316,9 @@ export const SubagentItem: React.FC<SubagentItemProps> = ({
<span
className="rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide"
style={{
backgroundColor: TAG_BG,
color: TAG_TEXT,
border: `1px solid ${TAG_BORDER}`,
backgroundColor: typeColors!.badge,
color: typeColors!.text,
border: `1px solid ${typeColors!.border}40`,
}}
>
{subagentType}

View file

@ -11,6 +11,7 @@ import React, { useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { COLOR_TEXT_MUTED, COLOR_TEXT_SECONDARY } from '@renderer/constants/cssVariables';
import { formatCostUsd } from '@shared/utils/costFormatting';
import { getModelColorClass } from '@shared/utils/modelParser';
import {
formatTokensCompact as formatTokens,
@ -49,6 +50,8 @@ interface TokenUsageDisplayProps {
phaseNumber?: number;
/** Total number of phases in the session */
totalPhases?: number;
/** Optional USD cost for this usage */
costUsd?: number;
}
/**
@ -255,6 +258,7 @@ export const TokenUsageDisplay = ({
contextStats,
phaseNumber,
totalPhases,
costUsd,
}: Readonly<TokenUsageDisplayProps>): React.JSX.Element => {
const totalTokens = inputTokens + cacheReadTokens + cacheCreationTokens + outputTokens;
const formattedTotal = formatTokens(totalTokens);
@ -513,6 +517,19 @@ export const TokenUsageDisplay = ({
</span>
</div>
{/* Cost (USD) - if available */}
{costUsd !== undefined && costUsd > 0 && (
<div className="mt-1 flex items-center justify-between text-[10px]">
<span style={{ color: COLOR_TEXT_SECONDARY }}>Cost (USD)</span>
<span
className="tabular-nums"
style={{ color: 'var(--color-text-primary, var(--color-text))' }}
>
{formatCostUsd(costUsd)}
</span>
</div>
)}
{/* Visible Context Breakdown - expandable section */}
{contextStats &&
(contextStats.totalEstimatedTokens > 0 ||

View file

@ -11,6 +11,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { api } from '@renderer/api';
import { useStore } from '@renderer/store';
import { formatShortcut } from '@renderer/utils/stringUtils';
import { createLogger } from '@shared/utils/logger';
import { useShallow } from 'zustand/react/shallow';
@ -75,7 +76,7 @@ const CommandSearch = ({ value, onChange }: Readonly<CommandSearchProps>): React
<button
onClick={() => openCommandPalette()}
className="flex shrink-0 items-center gap-1 transition-opacity hover:opacity-80"
title={selectedProjectId ? 'Search in sessions (⌘K)' : 'Search projects (⌘K)'}
title={selectedProjectId ? `Search in sessions (${formatShortcut('K')})` : `Search projects (${formatShortcut('K')})`}
>
<kbd className="flex h-5 items-center justify-center rounded border border-border bg-surface-overlay px-1.5 text-[10px] font-medium text-text-muted">
<Command className="size-2.5" />

View file

@ -16,7 +16,7 @@ import { useEffect, useRef, useState } from 'react';
import { isElectronMode } from '@renderer/api';
import { HEADER_ROW1_HEIGHT, HEADER_ROW2_HEIGHT } from '@renderer/constants/layout';
import { useStore } from '@renderer/store';
import { truncateMiddle } from '@renderer/utils/stringUtils';
import { formatShortcut, truncateMiddle } from '@renderer/utils/stringUtils';
import { Check, ChevronDown, GitBranch, PanelLeft } from 'lucide-react';
import { useShallow } from 'zustand/react/shallow';
@ -369,7 +369,7 @@ export const SidebarHeader = (): React.JSX.Element => {
backgroundColor: isCollapseHovered ? 'var(--color-surface-raised)' : 'transparent',
} as React.CSSProperties
}
title="Collapse sidebar (⌘B)"
title={`Collapse sidebar (${formatShortcut('B')})`}
>
<PanelLeft className="size-4" />
</button>

View file

@ -61,7 +61,8 @@ export const SortableTab = ({
},
});
const style: React.CSSProperties = {
const style = {
WebkitAppRegion: 'no-drag',
transform: CSS.Transform.toString(transform),
transition: isDragging ? 'none' : transition,
opacity: isDragging ? 0.3 : 1,

View file

@ -14,6 +14,7 @@ import { horizontalListSortingStrategy, SortableContext } from '@dnd-kit/sortabl
import { isElectronMode } from '@renderer/api';
import { HEADER_ROW1_HEIGHT } from '@renderer/constants/layout';
import { useStore } from '@renderer/store';
import { formatShortcut } from '@renderer/utils/stringUtils';
import { Activity, Bell, PanelLeft, Plus, RefreshCw, Search, Settings } from 'lucide-react';
import { useShallow } from 'zustand/react/shallow';
@ -271,8 +272,7 @@ export const TabBar = ({ paneId }: TabBarProps): React.JSX.Element => {
sidebarCollapsed && isLeftmostPane
? 'var(--macos-traffic-light-padding-left, 72px)'
: '8px',
WebkitAppRegion:
isElectronMode() && sidebarCollapsed && isLeftmostPane ? 'drag' : undefined,
WebkitAppRegion: isElectronMode() && isLeftmostPane ? 'drag' : undefined,
backgroundColor: 'var(--color-surface)',
borderBottom: '1px solid var(--color-border)',
opacity: isFocused || paneCount === 1 ? 1 : 0.7,
@ -299,15 +299,17 @@ export const TabBar = ({ paneId }: TabBarProps): React.JSX.Element => {
</button>
)}
{/* Tab list with horizontal scroll, sortable DnD, and droppable area */}
{/* Tab list with horizontal scroll, sortable DnD, and droppable area.
Capped at 75% so the drag spacer always has room to the right. */}
<div
ref={(el) => {
scrollContainerRef.current = el;
setDroppableRef(el);
}}
className="scrollbar-none flex min-w-0 flex-1 items-center gap-1 overflow-x-auto"
className="scrollbar-none flex min-w-0 shrink items-center gap-1 overflow-x-auto"
style={
{
maxWidth: '75%',
WebkitAppRegion: 'no-drag',
outline: isDroppableOver ? '1px dashed var(--color-accent, #6366f1)' : 'none',
outlineOffset: '-1px',
@ -342,13 +344,25 @@ export const TabBar = ({ paneId }: TabBarProps): React.JSX.Element => {
onMouseEnter={() => setRefreshHover(true)}
onMouseLeave={() => setRefreshHover(false)}
onClick={handleRefresh}
title="Refresh Session (Cmd+R)"
title={`Refresh Session (${formatShortcut('R')})`}
>
<RefreshCw className="size-4" />
</button>
)}
</div>
{/* Drag spacer fills empty space between tab list and action buttons.
Gives users a reliable window-drag target regardless of how many tabs are open.
Only applied on the leftmost pane in Electron to match the TabBar drag region logic. */}
<div
className="flex-1 self-stretch"
style={
{
WebkitAppRegion: isElectronMode() && isLeftmostPane ? 'drag' : undefined,
} as React.CSSProperties
}
/>
{/* Right side actions */}
<div
className="ml-2 flex shrink-0 items-center gap-1"
@ -379,7 +393,7 @@ export const TabBar = ({ paneId }: TabBarProps): React.JSX.Element => {
color: searchHover ? 'var(--color-text)' : 'var(--color-text-muted)',
backgroundColor: searchHover ? 'var(--color-surface-raised)' : 'transparent',
}}
title="Search (Cmd+K)"
title={`Search (${formatShortcut('K')})`}
>
<Search className="size-4" />
</button>

View file

@ -7,6 +7,8 @@
import { useEffect, useRef } from 'react';
import { formatShortcut } from '@renderer/utils/stringUtils';
interface TabContextMenuProps {
x: number;
y: number;
@ -100,13 +102,13 @@ export const TabContextMenu = ({
onClick={handleClick(onCloseSelectedTabs)}
/>
) : (
<MenuItem label="Close Tab" shortcut="⌘W" onClick={handleClick(onCloseTab)} />
<MenuItem label="Close Tab" shortcut={formatShortcut('W')} onClick={handleClick(onCloseTab)} />
)}
<MenuItem label="Close Other Tabs" onClick={handleClick(onCloseOtherTabs)} />
<div className="mx-2 my-1 border-t" style={{ borderColor: 'var(--color-border)' }} />
<MenuItem
label="Split Right"
shortcut="⌘\"
shortcut={formatShortcut('\\')}
onClick={handleClick(onSplitRight)}
disabled={disableSplit}
/>
@ -127,7 +129,7 @@ export const TabContextMenu = ({
/>
)}
<div className="mx-2 my-1 border-t" style={{ borderColor: 'var(--color-border)' }} />
<MenuItem label="Close All Tabs" shortcut="⇧⌘W" onClick={handleClick(onCloseAllTabs)} />
<MenuItem label="Close All Tabs" shortcut={formatShortcut('W', { shift: true })} onClick={handleClick(onCloseAllTabs)} />
</div>
);
};

View file

@ -30,6 +30,7 @@ export interface SafeConfig {
theme: 'dark' | 'light' | 'system';
defaultTab: 'dashboard' | 'last-session';
claudeRootPath: string | null;
autoExpandAIGroups: boolean;
};
notifications: {
enabled: boolean;
@ -154,6 +155,7 @@ export function useSettingsConfig(): UseSettingsConfigReturn {
theme: displayConfig?.general?.theme ?? 'dark',
defaultTab: displayConfig?.general?.defaultTab ?? 'dashboard',
claudeRootPath: displayConfig?.general?.claudeRootPath ?? null,
autoExpandAIGroups: displayConfig?.general?.autoExpandAIGroups ?? false,
},
notifications: {
enabled: displayConfig?.notifications?.enabled ?? true,

View file

@ -287,6 +287,7 @@ export function useSettingsHandlers({
theme: 'dark',
defaultTab: 'dashboard',
claudeRootPath: null,
autoExpandAIGroups: false,
},
display: {
showTimestamps: true,

View file

@ -15,6 +15,7 @@ import { SettingRow, SettingsSectionHeader, SettingsSelect, SettingsToggle } fro
import type { SafeConfig } from '../hooks/useSettingsConfig';
import type { ClaudeRootInfo, WslClaudeRootCandidate } from '@shared/types';
import type { HttpServerStatus } from '@shared/types/api';
import type { AppConfig } from '@shared/types/notifications';
// Theme options
const THEME_OPTIONS = [
@ -26,7 +27,7 @@ const THEME_OPTIONS = [
interface GeneralSectionProps {
readonly safeConfig: SafeConfig;
readonly saving: boolean;
readonly onGeneralToggle: (key: 'launchAtLogin' | 'showDockIcon', value: boolean) => void;
readonly onGeneralToggle: (key: keyof AppConfig['general'], value: boolean) => void;
readonly onThemeChange: (value: 'dark' | 'light' | 'system') => void;
}
@ -286,6 +287,16 @@ export const GeneralSection = ({
disabled={saving}
/>
</SettingRow>
<SettingRow
label="Expand AI responses by default"
description="Automatically expand each response turn when opening a transcript or receiving a new message"
>
<SettingsToggle
enabled={safeConfig.general.autoExpandAIGroups ?? false}
onChange={(v) => onGeneralToggle('autoExpandAIGroups', v)}
disabled={saving}
/>
</SettingRow>
{isElectron && (
<>

View file

@ -7,6 +7,7 @@
import { useEffect, useRef, useState } from 'react';
import { MAX_PANES } from '@renderer/types/panes';
import { formatShortcut } from '@renderer/utils/stringUtils';
import { Check, ClipboardCopy, Eye, EyeOff, Pin, PinOff, Terminal } from 'lucide-react';
interface SessionContextMenuProps {
@ -98,7 +99,7 @@ export const SessionContextMenu = ({
}}
>
<MenuItem label="Open in Current Pane" onClick={handleClick(onOpenInCurrentPane)} />
<MenuItem label="Open in New Tab" shortcut="⌘ Click" onClick={handleClick(onOpenInNewTab)} />
<MenuItem label="Open in New Tab" shortcut={`${formatShortcut('')}Click`} onClick={handleClick(onOpenInNewTab)} />
<div className="mx-2 my-1 border-t" style={{ borderColor: 'var(--color-border)' }} />
<MenuItem
label="Split Right and Open"

View file

@ -31,6 +31,30 @@ const DEFAULT_COLOR: TeamColorSet = TEAMMATE_COLORS.blue;
* Get a TeamColorSet from a color name or hex string.
* Falls back to blue if unrecognized.
*/
const COLOR_NAMES = Object.keys(TEAMMATE_COLORS);
function hashString(str: string): number {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash * 31 + str.charCodeAt(i)) | 0;
}
return Math.abs(hash);
}
export function getSubagentTypeColorSet(
subagentType: string,
agentConfigs?: Record<string, { color?: string }>
): TeamColorSet {
// Use color from agent config if available
const configColor = agentConfigs?.[subagentType]?.color;
if (configColor) {
return getTeamColorSet(configColor);
}
// Fallback: deterministic hash-based color
const index = hashString(subagentType) % COLOR_NAMES.length;
return TEAMMATE_COLORS[COLOR_NAMES[index]];
}
export function getTeamColorSet(colorName: string): TeamColorSet {
if (!colorName) return DEFAULT_COLOR;

View file

@ -138,6 +138,8 @@ export function useAutoScrollBottom(
const disabledRef = useRef(disabled);
// Track resetKey to detect changes
const prevResetKeyRef = useRef(resetKey);
// Set true when resetKey changes; consumed by the content effect to force scroll on first load
const needsInitialScrollRef = useRef(false);
/**
* Check if the scroll container is at the bottom.
@ -223,34 +225,47 @@ export function useAutoScrollBottom(
disabledRef.current = disabled;
}, [disabled]);
// Reset isAtBottom state when resetKey changes (e.g., tab/session switch)
// This ensures new content will auto-scroll to bottom
// Reset isAtBottom state when resetKey changes (e.g., tab/session switch).
// Sets needsInitialScrollRef so the content effect scrolls to bottom on first load.
useEffect(() => {
if (resetKey !== prevResetKeyRef.current) {
isAtBottomRef.current = true;
wasAtBottomBeforeUpdateRef.current = true;
prevResetKeyRef.current = resetKey;
needsInitialScrollRef.current = true;
}
}, [resetKey]);
/**
* After content updates (dependencies change), scroll to bottom if we were at bottom.
* After content updates (dependencies change), scroll to bottom if:
* - User was already near the bottom before the update, OR
* - This is the first load after a tab/session switch (needsInitialScrollRef)
* Uses double-RAF + cleanup so React StrictMode's double-invoke doesn't fire twice.
*/
useEffect(() => {
// Skip if disabled (e.g., during navigation) or not enabled
if (!enabled || disabled) return;
// Use requestAnimationFrame to ensure DOM has updated
requestAnimationFrame(() => {
// Re-check disabled state inside RAF - it might have changed between effect and callback
// This prevents auto-scroll from firing if navigation started after the effect ran
if (disabledRef.current) return;
let id1 = 0;
let id2 = 0;
// Only auto-scroll if user was at bottom before the update
if (wasAtBottomBeforeUpdateRef.current) {
scrollToBottom(autoBehavior);
}
id1 = requestAnimationFrame(() => {
id2 = requestAnimationFrame(() => {
// Re-check disabled state — navigation may have started between effect and RAF
if (disabledRef.current) return;
const shouldScroll = needsInitialScrollRef.current || wasAtBottomBeforeUpdateRef.current;
if (shouldScroll) {
needsInitialScrollRef.current = false;
scrollToBottom(autoBehavior);
}
});
});
return () => {
cancelAnimationFrame(id1);
cancelAnimationFrame(id2);
};
// eslint-disable-next-line react-hooks/exhaustive-deps -- Dynamic dependencies array is intentional design
}, [...dependencies, enabled, disabled, autoBehavior, scrollToBottom]);

View file

@ -59,6 +59,7 @@ export const createProjectSlice: StateCreator<AppState, [], [], ProjectSlice> =
selectProject: (id: string) => {
set({
selectedProjectId: id,
sidebarCollapsed: false, // Ensure session list is visible when a project is selected
...getSessionResetState(),
});

View file

@ -87,6 +87,7 @@ export const createRepositorySlice: StateCreator<AppState, [], [], RepositorySli
selectedWorktreeId: worktreeToSelect.id,
selectedProjectId: worktreeToSelect.id,
activeProjectId: worktreeToSelect.id,
sidebarCollapsed: false, // Ensure session list is visible when a project is selected
...getSessionResetState(),
});
// Fetch sessions for this worktree

View file

@ -25,6 +25,7 @@ const sessionRefreshGeneration = new Map<string, number>();
const sessionRefreshInFlight = new Set<string>();
const sessionRefreshQueued = new Set<string>();
let sessionDetailFetchGeneration = 0;
let agentConfigsCachedForProject = '';
import { getAllTabs } from '../utils/paneHelpers';
@ -37,6 +38,7 @@ import type {
} from '@renderer/types/contextInjection';
import type { ClaudeMdFileInfo, SessionDetail } from '@renderer/types/data';
import type { AIGroup, SessionConversation } from '@renderer/types/groups';
import type { AgentConfig } from '@shared/types/api';
import type { StateCreator } from 'zustand';
// =============================================================================
@ -92,6 +94,9 @@ export interface SessionDetailSlice {
// Context phase info (compaction boundaries)
sessionPhaseInfo: ContextPhaseInfo | null;
// Agent configs from .claude/agents/ (keyed by agent name)
agentConfigs: Record<string, AgentConfig>;
// Visible AI Group
visibleAIGroupId: string | null;
selectedAIGroup: AIGroup | null;
@ -133,6 +138,8 @@ export const createSessionDetailSlice: StateCreator<AppState, [], [], SessionDet
// Context phase info (compaction boundaries)
sessionPhaseInfo: null,
agentConfigs: {},
visibleAIGroupId: null,
selectedAIGroup: null,
@ -190,6 +197,21 @@ export const createSessionDetailSlice: StateCreator<AppState, [], [], SessionDet
let claudeMdStats: Map<string, ClaudeMdStats> | null = null;
let contextStats: Map<string, ContextStats> | null = null;
let phaseInfo: ContextPhaseInfo | null = null;
// Fetch agent configs from .claude/agents/ (only when project changes).
// Fire-and-forget: don't block transcript rendering — color badges update async.
if (connectionMode !== 'ssh' && projectRoot && projectRoot !== agentConfigsCachedForProject) {
agentConfigsCachedForProject = projectRoot; // Optimistic set to prevent duplicate fetches
api
.readAgentConfigs(projectRoot)
.then((configs) => {
set({ agentConfigs: configs });
})
.catch((err) => {
logger.error('Failed to read agent configs:', err);
agentConfigsCachedForProject = ''; // Reset so it retries next time
});
}
if (connectionMode !== 'ssh' && conversation?.items) {
// Fetch real CLAUDE.md token data
let claudeMdTokenData: Record<string, ClaudeMdFileInfo> = {};
@ -394,6 +416,15 @@ export const createSessionDetailSlice: StateCreator<AppState, [], [], SessionDet
sessionPhaseInfo: phaseInfo,
});
// Auto-expand all AI groups if the setting is enabled
if (tabId && conversation?.items && get().appConfig?.general?.autoExpandAIGroups) {
for (const item of conversation.items) {
if (item.type === 'ai') {
get().expandAIGroupForTab(tabId, item.group.id);
}
}
}
// Store per-tab session data
if (tabId) {
const prev = get().tabSessionData;
@ -532,6 +563,14 @@ export const createSessionDetailSlice: StateCreator<AppState, [], [], SessionDet
}
}
// Snapshot existing AI group IDs before overwriting state, so the
// auto-expand diff below can correctly identify which groups are new.
const prevGroupIds = new Set(
(latestState.conversation?.items ?? [])
.filter((item) => item.type === 'ai')
.map((item) => (item as { type: 'ai'; group: { id: string } }).group.id)
);
// Update only the data, preserve UI states
set((state) => ({
sessionDetail: detail,
@ -550,6 +589,29 @@ export const createSessionDetailSlice: StateCreator<AppState, [], [], SessionDet
// so expansion states are preserved
}));
// Auto-expand newly arrived AI groups if the setting is enabled.
// Uses prevGroupIds snapshotted before set() so the diff is accurate.
if (get().appConfig?.general?.autoExpandAIGroups) {
const oldGroupIds = prevGroupIds;
const newGroupIds = newConversation.items
.filter(
(item) =>
item.type === 'ai' &&
!oldGroupIds.has((item as { type: 'ai'; group: { id: string } }).group.id)
)
.map((item) => (item as { type: 'ai'; group: { id: string } }).group.id);
if (newGroupIds.length > 0) {
for (const tab of latestAllTabs) {
if (tab.type === 'session' && tab.sessionId === sessionId) {
for (const groupId of newGroupIds) {
get().expandAIGroupForTab(tab.id, groupId);
}
}
}
}
}
// Also update per-tab session data for all tabs viewing this session
const latestTabSessionData = { ...get().tabSessionData };
for (const tab of latestAllTabs) {

View file

@ -2,6 +2,27 @@
* String utilities for display formatting.
*/
const isMacPlatform =
typeof window !== 'undefined' && window.navigator.userAgent.includes('Macintosh');
/** Returns '⌘' on macOS, 'Ctrl' on Windows/Linux. */
export const modKey = isMacPlatform ? '⌘' : 'Ctrl+';
/** Returns '⇧' on macOS, 'Shift+' on Windows/Linux. */
export const shiftKey = isMacPlatform ? '⇧' : 'Shift+';
/**
* Formats a keyboard shortcut for the current platform.
* @example formatShortcut('R') '⌘R' on Mac, 'Ctrl+R' on Windows/Linux
* @example formatShortcut('W', { shift: true }) '⇧⌘W' on Mac, 'Ctrl+Shift+W' on Windows/Linux
*/
export function formatShortcut(key: string, opts?: { shift?: boolean }): string {
if (opts?.shift) {
return isMacPlatform ? `${shiftKey}${modKey}${key}` : `${modKey}${shiftKey}${key}`;
}
return `${modKey}${key}`;
}
/**
* Truncates a string in the middle to preserve both the beginning and end.
* Useful for branch names where the unique identifier is often at the end.

View file

@ -29,6 +29,39 @@ import type {
SubagentDetail,
} from '@main/types';
// =============================================================================
// Cost Calculation Types
// =============================================================================
/**
* Detailed cost breakdown by token type for a session or chunk
*/
export interface CostBreakdown {
/** Cost for input tokens */
inputCost: number;
/** Cost for output tokens */
outputCost: number;
/** Cost for cache creation tokens */
cacheCreationCost: number;
/** Cost for cache read tokens */
cacheReadCost: number;
/** Total cost (sum of all components) */
totalCost: number;
/** Model name used for calculation */
model: string;
/** Source of the cost data */
source: 'calculated' | 'precalculated' | 'unavailable';
}
// =============================================================================
// Agent Config
// =============================================================================
export interface AgentConfig {
name: string;
color?: string;
}
// =============================================================================
// Notifications API
// =============================================================================
@ -366,6 +399,9 @@ export interface ElectronAPI {
maxTokens?: number
) => Promise<ClaudeMdFileInfo | null>;
// Agent config reading
readAgentConfigs: (projectRoot: string) => Promise<Record<string, AgentConfig>>;
// Notifications API
notifications: NotificationsAPI;

View file

@ -262,6 +262,8 @@ export interface AppConfig {
defaultTab: 'dashboard' | 'last-session';
/** Optional custom Claude root folder (auto-detected when null) */
claudeRootPath: string | null;
/** Whether to auto-expand AI response groups when opening a transcript or receiving new messages */
autoExpandAIGroups: boolean;
};
/** Display and UI settings */
display: {

View file

@ -0,0 +1,45 @@
/**
* Cost formatting utilities
*/
/**
* Format USD cost with appropriate precision
* - $0.001 or more: 2 decimal places ($1.23)
* - Less than $0.001: 3-4 decimal places for precision ($0.0012)
* - Zero: $0.00
*/
export function formatCostUsd(cost: number): string {
if (cost === 0) {
return '$0.00';
}
if (cost >= 0.01) {
// Standard currency format for amounts >= 1 cent
return `$${cost.toFixed(2)}`;
} else if (cost >= 0.001) {
// 3 decimal places for sub-cent amounts
return `$${cost.toFixed(3)}`;
} else {
// 4 decimal places for very small amounts
return `$${cost.toFixed(4)}`;
}
}
/**
* Format cost compactly for display in badges
* - Rounds to 2 decimal places
* - Omits $ prefix for brevity
*/
export function formatCostCompact(cost: number): string {
if (cost === 0) {
return '0.00';
}
if (cost >= 0.01) {
return cost.toFixed(2);
} else if (cost >= 0.001) {
return cost.toFixed(3);
} else {
return cost.toFixed(4);
}
}

View file

@ -20,6 +20,28 @@ describe('configValidation', () => {
}
});
it('accepts general.autoExpandAIGroups boolean toggle', () => {
const resultOn = validateConfigUpdatePayload('general', { autoExpandAIGroups: true });
expect(resultOn.valid).toBe(true);
if (resultOn.valid) {
expect(resultOn.data).toEqual({ autoExpandAIGroups: true });
}
const resultOff = validateConfigUpdatePayload('general', { autoExpandAIGroups: false });
expect(resultOff.valid).toBe(true);
if (resultOff.valid) {
expect(resultOff.data).toEqual({ autoExpandAIGroups: false });
}
});
it('rejects non-boolean general.autoExpandAIGroups', () => {
const result = validateConfigUpdatePayload('general', { autoExpandAIGroups: 'yes' });
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('boolean');
}
});
it('accepts absolute general.claudeRootPath updates', () => {
const result = validateConfigUpdatePayload('general', {
claudeRootPath: '/Users/test/.claude',

View file

@ -0,0 +1,119 @@
import { describe, expect, it } from 'vitest';
import { SearchTextCache } from '../../../../src/main/services/discovery/SearchTextCache';
import type { SearchableEntry } from '../../../../src/main/services/discovery/SearchTextExtractor';
function makeEntry(text: string, groupId: string): SearchableEntry {
return {
text,
groupId,
messageType: 'user',
itemType: 'user',
timestamp: Date.now(),
messageUuid: groupId,
};
}
describe('SearchTextCache', () => {
it('returns cached entry on mtime match', () => {
const cache = new SearchTextCache();
const entries = [makeEntry('hello', 'user-1')];
cache.set('/path/a.jsonl', 1000, entries, 'Title A');
const result = cache.get('/path/a.jsonl', 1000);
expect(result).toBeDefined();
expect(result!.entries).toEqual(entries);
expect(result!.sessionTitle).toBe('Title A');
});
it('returns undefined on mtime mismatch (stale)', () => {
const cache = new SearchTextCache();
const entries = [makeEntry('hello', 'user-1')];
cache.set('/path/a.jsonl', 1000, entries, 'Title A');
const result = cache.get('/path/a.jsonl', 2000);
expect(result).toBeUndefined();
});
it('returns undefined for uncached paths', () => {
const cache = new SearchTextCache();
const result = cache.get('/path/missing.jsonl', 1000);
expect(result).toBeUndefined();
});
it('evicts oldest entry when at max capacity', () => {
const cache = new SearchTextCache(3);
cache.set('/path/1.jsonl', 100, [makeEntry('one', 'u1')], 'One');
cache.set('/path/2.jsonl', 200, [makeEntry('two', 'u2')], 'Two');
cache.set('/path/3.jsonl', 300, [makeEntry('three', 'u3')], 'Three');
expect(cache.size).toBe(3);
// Adding a 4th entry should evict the oldest (1.jsonl)
cache.set('/path/4.jsonl', 400, [makeEntry('four', 'u4')], 'Four');
expect(cache.size).toBe(3);
expect(cache.get('/path/1.jsonl', 100)).toBeUndefined();
expect(cache.get('/path/4.jsonl', 400)).toBeDefined();
});
it('LRU access moves entry to end, preserving it from eviction', () => {
const cache = new SearchTextCache(3);
cache.set('/path/1.jsonl', 100, [makeEntry('one', 'u1')], 'One');
cache.set('/path/2.jsonl', 200, [makeEntry('two', 'u2')], 'Two');
cache.set('/path/3.jsonl', 300, [makeEntry('three', 'u3')], 'Three');
// Access entry 1, moving it to end
cache.get('/path/1.jsonl', 100);
// Adding a 4th should now evict entry 2 (oldest after LRU access)
cache.set('/path/4.jsonl', 400, [makeEntry('four', 'u4')], 'Four');
expect(cache.get('/path/1.jsonl', 100)).toBeDefined();
expect(cache.get('/path/2.jsonl', 200)).toBeUndefined();
});
it('invalidate() removes a specific entry', () => {
const cache = new SearchTextCache();
cache.set('/path/a.jsonl', 1000, [makeEntry('hello', 'u1')], 'Title');
cache.invalidate('/path/a.jsonl');
expect(cache.get('/path/a.jsonl', 1000)).toBeUndefined();
expect(cache.size).toBe(0);
});
it('clear() empties the cache', () => {
const cache = new SearchTextCache();
cache.set('/path/1.jsonl', 100, [makeEntry('one', 'u1')], 'One');
cache.set('/path/2.jsonl', 200, [makeEntry('two', 'u2')], 'Two');
expect(cache.size).toBe(2);
cache.clear();
expect(cache.size).toBe(0);
});
it('handles undefined sessionTitle', () => {
const cache = new SearchTextCache();
cache.set('/path/a.jsonl', 1000, [], undefined);
const result = cache.get('/path/a.jsonl', 1000);
expect(result).toBeDefined();
expect(result!.sessionTitle).toBeUndefined();
expect(result!.entries).toEqual([]);
});
it('updates existing entry on re-set', () => {
const cache = new SearchTextCache();
cache.set('/path/a.jsonl', 1000, [makeEntry('old', 'u1')], 'Old');
cache.set('/path/a.jsonl', 2000, [makeEntry('new', 'u2')], 'New');
const result = cache.get('/path/a.jsonl', 2000);
expect(result).toBeDefined();
expect(result!.entries[0].text).toBe('new');
expect(result!.sessionTitle).toBe('New');
expect(cache.size).toBe(1);
});
});

View file

@ -0,0 +1,230 @@
import { describe, expect, it } from 'vitest';
import {
extractSearchableEntries,
extractUserText,
} from '../../../../src/main/services/discovery/SearchTextExtractor';
import type { ParsedMessage } from '../../../../src/main/types';
function makeUserMessage(
uuid: string,
content: string,
timestamp = '2026-01-01T00:00:00.000Z'
): ParsedMessage {
return {
uuid,
type: 'user',
role: 'user',
content,
timestamp: new Date(timestamp),
isMeta: false,
isSidechain: false,
} as ParsedMessage;
}
function makeAssistantMessage(
uuid: string,
textContent: string,
timestamp = '2026-01-01T00:00:01.000Z'
): ParsedMessage {
return {
uuid,
type: 'assistant',
role: 'assistant',
content: [{ type: 'text', text: textContent }],
timestamp: new Date(timestamp),
isMeta: false,
isSidechain: false,
} as ParsedMessage;
}
function makeAssistantWithThinking(
uuid: string,
thinking: string,
textContent: string,
timestamp = '2026-01-01T00:00:01.000Z'
): ParsedMessage {
return {
uuid,
type: 'assistant',
role: 'assistant',
content: [
{ type: 'thinking', thinking },
{ type: 'text', text: textContent },
],
timestamp: new Date(timestamp),
isMeta: false,
isSidechain: false,
} as ParsedMessage;
}
function makeToolResultMessage(
uuid: string,
timestamp = '2026-01-01T00:00:01.500Z'
): ParsedMessage {
return {
uuid,
type: 'user',
role: 'user',
content: [{ type: 'tool_result', tool_use_id: 'tool-1', content: 'result text' }],
timestamp: new Date(timestamp),
isMeta: true,
isSidechain: false,
} as ParsedMessage;
}
describe('SearchTextExtractor', () => {
describe('extractSearchableEntries', () => {
it('produces user-{uuid} groupIds for user messages', () => {
const messages = [makeUserMessage('u1', 'hello world')];
const result = extractSearchableEntries(messages);
expect(result.entries).toHaveLength(1);
expect(result.entries[0].groupId).toBe('user-u1');
expect(result.entries[0].itemType).toBe('user');
expect(result.entries[0].messageType).toBe('user');
expect(result.entries[0].text).toBe('hello world');
});
it('produces ai-{uuid} groupIds for AI groups (using first buffer message uuid)', () => {
const messages = [
makeUserMessage('u1', 'question'),
makeToolResultMessage('tr1', '2026-01-01T00:00:01.000Z'),
makeAssistantMessage('a1', 'thinking...', '2026-01-01T00:00:02.000Z'),
makeAssistantMessage('a2', 'final answer', '2026-01-01T00:00:03.000Z'),
];
const result = extractSearchableEntries(messages);
const aiEntries = result.entries.filter((e) => e.itemType === 'ai');
expect(aiEntries).toHaveLength(1);
// groupId uses the first message in the AI buffer
expect(aiEntries[0].groupId).toMatch(/^ai-/);
// Text is from the last assistant message with text
expect(aiEntries[0].text).toBe('final answer');
});
it('extracts last AI text output correctly (backward scan)', () => {
const messages = [
makeUserMessage('u1', 'question'),
makeAssistantMessage('a1', 'older output', '2026-01-01T00:00:01.000Z'),
makeAssistantMessage('a2', 'latest output', '2026-01-01T00:00:02.000Z'),
];
const result = extractSearchableEntries(messages);
const aiEntries = result.entries.filter((e) => e.itemType === 'ai');
expect(aiEntries).toHaveLength(1);
expect(aiEntries[0].text).toBe('latest output');
});
it('handles assistant messages with thinking + text blocks', () => {
const messages = [
makeUserMessage('u1', 'question'),
makeAssistantWithThinking('a1', 'internal reasoning', 'visible answer'),
];
const result = extractSearchableEntries(messages);
const aiEntries = result.entries.filter((e) => e.itemType === 'ai');
expect(aiEntries).toHaveLength(1);
expect(aiEntries[0].text).toBe('visible answer');
});
it('skips sidechain messages', () => {
const sidechain: ParsedMessage = {
...makeUserMessage('u-side', 'sidechain text'),
isSidechain: true,
} as ParsedMessage;
const messages = [sidechain, makeUserMessage('u1', 'main thread')];
const result = extractSearchableEntries(messages);
expect(result.entries).toHaveLength(1);
expect(result.entries[0].text).toBe('main thread');
});
it('extracts sessionTitle from first user message (truncated to 100 chars)', () => {
const longText = 'a'.repeat(200);
const messages = [
makeUserMessage('u1', longText),
makeUserMessage('u2', 'second message'),
];
const result = extractSearchableEntries(messages);
expect(result.sessionTitle).toBe('a'.repeat(100));
});
it('handles empty messages array', () => {
const result = extractSearchableEntries([]);
expect(result.entries).toHaveLength(0);
expect(result.sessionTitle).toBeUndefined();
});
it('handles messages with no user messages', () => {
const messages = [
makeAssistantMessage('a1', 'just AI talking'),
];
const result = extractSearchableEntries(messages);
expect(result.sessionTitle).toBeUndefined();
const aiEntries = result.entries.filter((e) => e.itemType === 'ai');
expect(aiEntries).toHaveLength(1);
});
it('handles AI buffer with no text content', () => {
const noTextAssistant: ParsedMessage = {
uuid: 'a1',
type: 'assistant',
role: 'assistant',
content: [{ type: 'thinking', thinking: 'just thinking' }],
timestamp: new Date('2026-01-01T00:00:01.000Z'),
isMeta: false,
isSidechain: false,
} as ParsedMessage;
const messages = [makeUserMessage('u1', 'question'), noTextAssistant];
const result = extractSearchableEntries(messages);
const aiEntries = result.entries.filter((e) => e.itemType === 'ai');
expect(aiEntries).toHaveLength(0);
});
it('flushes AI buffer on user messages', () => {
const messages = [
makeUserMessage('u1', 'first question'),
makeAssistantMessage('a1', 'first answer', '2026-01-01T00:00:01.000Z'),
makeUserMessage('u2', 'second question', '2026-01-01T00:00:02.000Z'),
makeAssistantMessage('a2', 'second answer', '2026-01-01T00:00:03.000Z'),
];
const result = extractSearchableEntries(messages);
expect(result.entries).toHaveLength(4);
const userEntries = result.entries.filter((e) => e.itemType === 'user');
const aiEntries = result.entries.filter((e) => e.itemType === 'ai');
expect(userEntries).toHaveLength(2);
expect(aiEntries).toHaveLength(2);
expect(aiEntries[0].text).toBe('first answer');
expect(aiEntries[1].text).toBe('second answer');
});
});
describe('extractUserText', () => {
it('extracts string content', () => {
const msg = makeUserMessage('u1', 'hello world');
expect(extractUserText(msg)).toBe('hello world');
});
it('extracts array content with text blocks', () => {
const msg: ParsedMessage = {
uuid: 'u1',
type: 'user',
role: 'user',
content: [
{ type: 'text', text: 'part one' },
{ type: 'text', text: ' part two' },
],
timestamp: new Date(),
isMeta: false,
isSidechain: false,
} as ParsedMessage;
expect(extractUserText(msg)).toBe('part one part two');
});
});
});

View file

@ -0,0 +1,95 @@
import { describe, expect, it, beforeEach, afterEach } from 'vitest';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { readAgentConfigs } from '@main/services/parsing/AgentConfigReader';
describe('readAgentConfigs', () => {
let tmpDir: string;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-config-test-'));
});
afterEach(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});
function writeAgent(filename: string, content: string): void {
const agentsDir = path.join(tmpDir, '.claude', 'agents');
fs.mkdirSync(agentsDir, { recursive: true });
fs.writeFileSync(path.join(agentsDir, filename), content);
}
it('returns empty object when .claude/agents/ does not exist', async () => {
const result = await readAgentConfigs(tmpDir);
expect(result).toEqual({});
});
it('parses agent with name and color from frontmatter', async () => {
writeAgent('test-agent.md', `---
name: test-agent
color: red
---
# Test agent
`);
const result = await readAgentConfigs(tmpDir);
expect(result).toEqual({
'test-agent': { name: 'test-agent', color: 'red' },
});
});
it('uses filename as name when frontmatter has no name field', async () => {
writeAgent('my-agent.md', `---
color: blue
---
# My Agent
`);
const result = await readAgentConfigs(tmpDir);
expect(result['my-agent']).toBeDefined();
expect(result['my-agent'].color).toBe('blue');
});
it('handles agents without color field', async () => {
writeAgent('plain.md', `---
name: plain
description: "A plain agent"
---
Content
`);
const result = await readAgentConfigs(tmpDir);
expect(result.plain).toEqual({ name: 'plain' });
expect(result.plain.color).toBeUndefined();
});
it('handles agents without frontmatter', async () => {
writeAgent('no-front.md', '# Just markdown\nNo frontmatter here.');
const result = await readAgentConfigs(tmpDir);
expect(result['no-front']).toEqual({ name: 'no-front' });
});
it('reads multiple agents', async () => {
writeAgent('a.md', `---\nname: a\ncolor: green\n---\n`);
writeAgent('b.md', `---\nname: b\ncolor: purple\n---\n`);
const result = await readAgentConfigs(tmpDir);
expect(Object.keys(result)).toHaveLength(2);
expect(result.a.color).toBe('green');
expect(result.b.color).toBe('purple');
});
it('strips quotes from frontmatter values', async () => {
writeAgent('quoted.md', `---\nname: "quoted-agent"\ncolor: 'cyan'\n---\n`);
const result = await readAgentConfigs(tmpDir);
expect(result['quoted-agent']).toEqual({ name: 'quoted-agent', color: 'cyan' });
});
it('ignores non-md files', async () => {
const agentsDir = path.join(tmpDir, '.claude', 'agents');
fs.mkdirSync(agentsDir, { recursive: true });
fs.writeFileSync(path.join(agentsDir, 'readme.txt'), 'not an agent');
writeAgent('real.md', `---\nname: real\ncolor: red\n---\n`);
const result = await readAgentConfigs(tmpDir);
expect(Object.keys(result)).toEqual(['real']);
});
});

View file

@ -0,0 +1,600 @@
/**
* Tests for cost calculation in jsonl.ts
*/
import { describe, it, expect, beforeEach, vi } from 'vitest';
import * as fs from 'fs';
import { calculateMetrics } from '@main/utils/jsonl';
import type { ParsedMessage } from '@main/types';
// Mock fs module
vi.mock('fs');
describe('Cost Calculation', () => {
// Sample pricing data matching Claude models
const mockPricingData = {
'claude-3-5-sonnet-20241022': {
input_cost_per_token: 0.000003,
output_cost_per_token: 0.000015,
cache_creation_input_token_cost: 0.00000375,
cache_read_input_token_cost: 0.0000003,
input_cost_per_token_above_200k_tokens: 0.000006,
output_cost_per_token_above_200k_tokens: 0.00003,
cache_creation_input_token_cost_above_200k_tokens: 0.0000075,
cache_read_input_token_cost_above_200k_tokens: 0.0000006,
},
'claude-3-opus-20240229': {
input_cost_per_token: 0.000015,
output_cost_per_token: 0.000075,
cache_creation_input_token_cost: 0.00001875,
cache_read_input_token_cost: 0.0000015,
},
};
beforeEach(() => {
// Reset modules to clear pricing cache
vi.resetModules();
// Mock fs.readFileSync to return our test pricing data
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockPricingData));
vi.mocked(fs.existsSync).mockReturnValue(true);
});
describe('Basic Cost Calculation', () => {
it('should calculate cost for simple token usage', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Expected: (1000 * 0.000003) + (500 * 0.000015) = 0.003 + 0.0075 = 0.0105
expect(metrics.costUsd).toBeCloseTo(0.0105, 6);
});
it('should calculate cost with cache tokens', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1000,
output_tokens: 500,
cache_creation_input_tokens: 200,
cache_read_input_tokens: 300,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Input: 1000 * 0.000003 = 0.003
// Output: 500 * 0.000015 = 0.0075
// Cache creation: 200 * 0.00000375 = 0.00075
// Cache read: 300 * 0.0000003 = 0.00009
// Total: 0.01134
expect(metrics.costUsd).toBeCloseTo(0.01134, 6);
});
it('should return 0 cost when no model is specified', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
expect(metrics.costUsd).toBe(0);
});
it('should return 0 cost when model pricing not found', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'unknown-model',
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
expect(metrics.costUsd).toBe(0);
});
});
describe('Tiered Pricing', () => {
it('should use base rates for tokens below 200k threshold', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 100_000,
output_tokens: 50_000,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Input: 100000 * 0.000003 = 0.3
// Output: 50000 * 0.000015 = 0.75
// Total: 1.05
expect(metrics.costUsd).toBeCloseTo(1.05, 6);
});
it('should use tiered rates for input tokens above 200k threshold', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 250_000,
output_tokens: 1_000,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Input: (200000 * 0.000003) + (50000 * 0.000006) = 0.6 + 0.3 = 0.9
// Output: 1000 * 0.000015 = 0.015
// Total: 0.915
expect(metrics.costUsd).toBeCloseTo(0.915, 6);
});
it('should use tiered rates for output tokens above 200k threshold', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1_000,
output_tokens: 250_000,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Input: 1000 * 0.000003 = 0.003
// Output: (200000 * 0.000015) + (50000 * 0.00003) = 3.0 + 1.5 = 4.5
// Total: 4.503
expect(metrics.costUsd).toBeCloseTo(4.503, 6);
});
it('should use tiered rates for cache tokens above 200k threshold', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1_000,
output_tokens: 1_000,
cache_creation_input_tokens: 250_000,
cache_read_input_tokens: 250_000,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Input: 1000 * 0.000003 = 0.003
// Output: 1000 * 0.000015 = 0.015
// Cache creation: (200000 * 0.00000375) + (50000 * 0.0000075) = 0.75 + 0.375 = 1.125
// Cache read: (200000 * 0.0000003) + (50000 * 0.0000006) = 0.06 + 0.03 = 0.09
// Total: 1.233
expect(metrics.costUsd).toBeCloseTo(1.233, 6);
});
it('should handle model without tiered pricing', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-opus-20240229',
usage: {
input_tokens: 250_000,
output_tokens: 250_000,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// No tiered rates, so use base rates even above 200k
// Input: 250000 * 0.000015 = 3.75
// Output: 250000 * 0.000075 = 18.75
// Total: 22.5
expect(metrics.costUsd).toBeCloseTo(22.5, 6);
});
});
describe('Multiple Messages', () => {
it('should aggregate costs across multiple messages', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
{
type: 'assistant',
uuid: 'msg-2',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 2000,
output_tokens: 1000,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Message 1: (1000 * 0.000003) + (500 * 0.000015) = 0.0105
// Message 2: (2000 * 0.000003) + (1000 * 0.000015) = 0.021
// Total: 0.0315
expect(metrics.costUsd).toBeCloseTo(0.0315, 6);
});
it("should calculate cost per-message using each message's model", () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
{
type: 'assistant',
uuid: 'msg-2',
timestamp: new Date(),
content: [],
model: 'claude-3-opus-20240229', // Different model
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Each message uses its own model's pricing
// Message 1 (sonnet): (1000 * 0.000003) + (500 * 0.000015) = 0.003 + 0.0075 = 0.0105
// Message 2 (opus): (1000 * 0.000015) + (500 * 0.000075) = 0.015 + 0.0375 = 0.0525
// Total cost: 0.0105 + 0.0525 = 0.063
expect(metrics.costUsd).toBeCloseTo(0.063, 6);
});
});
describe('Edge Cases', () => {
it('should handle zero tokens', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 0,
output_tokens: 0,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
expect(metrics.costUsd).toBe(0);
});
it('should handle messages without usage data', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
expect(metrics.costUsd).toBe(0);
});
it('should handle empty messages array', () => {
const messages: ParsedMessage[] = [];
const metrics = calculateMetrics(messages);
expect(metrics.costUsd).toBe(0);
});
it('should handle pricing data load failure gracefully', async () => {
// Suppress expected console.error for this test
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
// Reset modules to clear the pricing cache
vi.resetModules();
// Mock fs to throw error BEFORE importing calculateMetrics
vi.mocked(fs.readFileSync).mockImplementation(() => {
throw new Error('File not found');
});
// Re-import calculateMetrics to get fresh instance with cleared cache
const { calculateMetrics: freshCalculateMetrics } = await import('@main/utils/jsonl');
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = freshCalculateMetrics(messages);
expect(metrics.costUsd).toBe(0);
// Verify that console.error was called (error was logged)
expect(consoleErrorSpy).toHaveBeenCalled();
// Restore console.error
consoleErrorSpy.mockRestore();
});
});
describe('Model Name Lookup', () => {
it('should find model with exact match', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
expect(metrics.costUsd).toBeGreaterThan(0);
});
it('should find model with case-insensitive match', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'CLAUDE-3-5-SONNET-20241022',
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
expect(metrics.costUsd).toBeGreaterThan(0);
});
});
describe('Per-Message Tiering', () => {
it('should apply tiered pricing per-message, not to aggregated totals', () => {
// Scenario: Many messages each with cache_read tokens < 200k,
// but aggregated total > 200k
// Each message should use base rates, not tiered rates
const messages: ParsedMessage[] = [];
// Create 10 messages, each with 50k cache_read tokens (500k total)
for (let i = 0; i < 10; i++) {
messages.push({
type: 'assistant',
uuid: `msg-${i}`,
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 0,
output_tokens: 0,
cache_read_input_tokens: 50000,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
});
}
const metrics = calculateMetrics(messages);
// Per-message tiering: Each message uses base rate (< 200k threshold)
// Each message: 50,000 * 0.0000003 = $0.015
// Total: 10 * $0.015 = $0.15
const expectedCost = 10 * 50000 * 0.0000003;
expect(metrics.costUsd).toBeCloseTo(expectedCost, 6);
// Verify this is NOT using tiered rate on aggregated total
// If incorrectly aggregated: (200k * 0.0000003) + (300k * 0.0000006) = $0.24
const incorrectAggregatedCost = 0.24;
expect(metrics.costUsd).not.toBeCloseTo(incorrectAggregatedCost, 2);
});
it('should apply tiered rates when individual messages exceed 200k', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 0,
output_tokens: 0,
cache_read_input_tokens: 300000, // Exceeds 200k threshold
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Single message with 300k cache_read tokens
// First 200k: 200,000 * 0.0000003 = $0.06
// Remaining 100k: 100,000 * 0.0000006 = $0.06
// Total: $0.12
const expectedCost = 200000 * 0.0000003 + 100000 * 0.0000006;
expect(metrics.costUsd).toBeCloseTo(expectedCost, 6);
});
});
describe('Integration with Other Metrics', () => {
it('should include cost alongside other session metrics', () => {
const messages: ParsedMessage[] = [
{
type: 'assistant',
uuid: 'msg-1',
timestamp: new Date(),
content: [],
model: 'claude-3-5-sonnet-20241022',
usage: {
input_tokens: 1000,
output_tokens: 500,
},
toolCalls: [],
toolResults: [],
isSidechain: false,
},
];
const metrics = calculateMetrics(messages);
// Check that all expected metrics are present
expect(metrics).toHaveProperty('totalTokens');
expect(metrics).toHaveProperty('inputTokens');
expect(metrics).toHaveProperty('outputTokens');
expect(metrics).toHaveProperty('costUsd');
expect(metrics.totalTokens).toBe(1500);
expect(metrics.inputTokens).toBe(1000);
expect(metrics.outputTokens).toBe(500);
expect(metrics.costUsd).toBeCloseTo(0.0105, 6);
});
});
});

View file

@ -0,0 +1,116 @@
import { describe, expect, it } from 'vitest';
import { getSubagentTypeColorSet, getTeamColorSet, TeamColorSet } from '@renderer/constants/teamColors';
function isValidColorSet(cs: TeamColorSet): boolean {
return typeof cs.border === 'string' && typeof cs.badge === 'string' && typeof cs.text === 'string';
}
// =============================================================================
// getTeamColorSet
// =============================================================================
describe('getTeamColorSet', () => {
it('returns blue (default) for empty string', () => {
const result = getTeamColorSet('');
expect(result.border).toBe('#3b82f6');
});
it('resolves named colors', () => {
expect(getTeamColorSet('green').border).toBe('#22c55e');
expect(getTeamColorSet('red').border).toBe('#ef4444');
expect(getTeamColorSet('purple').border).toBe('#a855f7');
});
it('is case-insensitive for named colors', () => {
expect(getTeamColorSet('Green')).toEqual(getTeamColorSet('green'));
expect(getTeamColorSet('BLUE')).toEqual(getTeamColorSet('blue'));
});
it('generates a color set from hex strings', () => {
const result = getTeamColorSet('#ff5500');
expect(result.border).toBe('#ff5500');
expect(result.badge).toBe('#ff550026');
expect(result.text).toBe('#ff5500');
});
it('falls back to blue for unknown non-hex strings', () => {
const result = getTeamColorSet('nonexistent');
expect(result.border).toBe('#3b82f6');
});
});
// =============================================================================
// getSubagentTypeColorSet
// =============================================================================
describe('getSubagentTypeColorSet', () => {
it('always returns a valid TeamColorSet without agent configs', () => {
const types = ['test-agent', 'quality-fixer', 'Explore', 'Plan', 'my-custom-agent', 'anything'];
for (const t of types) {
const result = getSubagentTypeColorSet(t);
expect(isValidColorSet(result)).toBe(true);
}
});
it('is deterministic — same input always returns same color', () => {
const a = getSubagentTypeColorSet('my-custom-agent');
const b = getSubagentTypeColorSet('my-custom-agent');
expect(a).toEqual(b);
});
it('different types can produce different colors', () => {
const results = new Set(
['Explore', 'Plan', 'test-agent', 'quality-fixer', 'claude-md-auditor', 'Bash', 'general-purpose', 'statusline-setup']
.map((t) => getSubagentTypeColorSet(t).border)
);
expect(results.size).toBeGreaterThan(1);
});
it('uses color from agent config when available', () => {
const configs = {
'test-agent': { name: 'test-agent', color: 'red' },
};
const result = getSubagentTypeColorSet('test-agent', configs);
// Should use the named "red" color from getTeamColorSet
expect(result.border).toBe('#ef4444');
expect(result.text).toBe('#f87171');
});
it('uses hex color from agent config', () => {
const configs = {
'my-agent': { name: 'my-agent', color: '#ff00ff' },
};
const result = getSubagentTypeColorSet('my-agent', configs);
expect(result.border).toBe('#ff00ff');
});
it('falls back to hash when agent config has no color', () => {
const configs = {
'my-agent': { name: 'my-agent' },
};
const withConfig = getSubagentTypeColorSet('my-agent', configs);
const withoutConfig = getSubagentTypeColorSet('my-agent');
// Should be the same — both use hash fallback
expect(withConfig).toEqual(withoutConfig);
});
it('falls back to hash when agent type not in configs', () => {
const configs = {
'other-agent': { name: 'other-agent', color: 'green' },
};
const withConfig = getSubagentTypeColorSet('unknown-agent', configs);
const withoutConfig = getSubagentTypeColorSet('unknown-agent');
expect(withConfig).toEqual(withoutConfig);
});
it('does not interfere with getTeamColorSet', () => {
const teamGreen = getTeamColorSet('green');
expect(teamGreen.border).toBe('#22c55e');
const configs = { green: { name: 'green', color: 'purple' } };
getSubagentTypeColorSet('green', configs);
// Team API remains unaffected
expect(getTeamColorSet('green').border).toBe('#22c55e');
});
});

View file

@ -0,0 +1,228 @@
/**
* Tests for cost formatting utilities
*/
import { describe, it, expect } from 'vitest';
import { formatCostUsd, formatCostCompact } from '@shared/utils/costFormatting';
describe('Cost Formatting', () => {
describe('formatCostUsd', () => {
describe('Zero values', () => {
it('should format zero as $0.00', () => {
expect(formatCostUsd(0)).toBe('$0.00');
});
it('should format negative zero as $0.00', () => {
expect(formatCostUsd(-0)).toBe('$0.00');
});
});
describe('Standard amounts (>= $0.01)', () => {
it('should format 1 cent with 2 decimal places', () => {
expect(formatCostUsd(0.01)).toBe('$0.01');
});
it('should format 1 dollar with 2 decimal places', () => {
expect(formatCostUsd(1.0)).toBe('$1.00');
});
it('should format dollars and cents', () => {
expect(formatCostUsd(1.23)).toBe('$1.23');
});
it('should format large amounts', () => {
expect(formatCostUsd(999.99)).toBe('$999.99');
expect(formatCostUsd(1234.56)).toBe('$1234.56');
});
it('should round to 2 decimal places for amounts >= 1 cent', () => {
expect(formatCostUsd(1.234)).toBe('$1.23');
expect(formatCostUsd(1.235)).toBe('$1.24'); // Rounds up
expect(formatCostUsd(1.999)).toBe('$2.00');
});
});
describe('Sub-cent amounts ($0.001 - $0.01)', () => {
it('should format 1 tenth of a cent with 3 decimal places', () => {
expect(formatCostUsd(0.001)).toBe('$0.001');
});
it('should format sub-cent amounts with 3 decimal places', () => {
expect(formatCostUsd(0.005)).toBe('$0.005');
expect(formatCostUsd(0.009)).toBe('$0.009');
});
it('should round to 3 decimal places for sub-cent amounts', () => {
expect(formatCostUsd(0.0012)).toBe('$0.001');
expect(formatCostUsd(0.0015)).toBe('$0.002'); // Rounds up
expect(formatCostUsd(0.0099)).toBe('$0.010');
});
});
describe('Very small amounts (< $0.001)', () => {
it('should format tiny amounts with 4 decimal places', () => {
expect(formatCostUsd(0.0001)).toBe('$0.0001');
expect(formatCostUsd(0.0005)).toBe('$0.0005');
expect(formatCostUsd(0.0009)).toBe('$0.0009');
});
it('should round to 4 decimal places for tiny amounts', () => {
expect(formatCostUsd(0.00012)).toBe('$0.0001');
expect(formatCostUsd(0.00016)).toBe('$0.0002'); // Rounds up
expect(formatCostUsd(0.00099)).toBe('$0.0010');
});
it('should handle very tiny amounts', () => {
expect(formatCostUsd(0.000001)).toBe('$0.0000');
});
});
describe('Edge cases', () => {
it('should handle negative amounts with 4 decimal places', () => {
// Negative numbers don't match >= comparisons, so they use 4 decimals
expect(formatCostUsd(-1.23)).toBe('$-1.2300');
expect(formatCostUsd(-0.001)).toBe('$-0.0010');
expect(formatCostUsd(-0.0001)).toBe('$-0.0001');
});
it('should handle very large amounts', () => {
expect(formatCostUsd(1000000)).toBe('$1000000.00');
});
it('should handle precision boundaries', () => {
// Boundary between 2 and 3 decimal places
expect(formatCostUsd(0.01)).toBe('$0.01');
expect(formatCostUsd(0.00999)).toBe('$0.010'); // Just below threshold, uses 3 decimals
// Boundary between 3 and 4 decimal places
expect(formatCostUsd(0.001)).toBe('$0.001');
expect(formatCostUsd(0.00099)).toBe('$0.0010'); // Just below threshold, uses 4 decimals
});
});
describe('Real-world API cost examples', () => {
it('should format typical Claude API costs', () => {
// 1M input tokens at $3.00/M
expect(formatCostUsd(3.0)).toBe('$3.00');
// 100k input tokens at $3.00/M
expect(formatCostUsd(0.3)).toBe('$0.30');
// 10k cache read tokens at $0.30/M
expect(formatCostUsd(0.003)).toBe('$0.003');
// 1k cache read tokens at $0.30/M
expect(formatCostUsd(0.0003)).toBe('$0.0003');
});
it('should format session totals', () => {
// Small session
expect(formatCostUsd(0.15)).toBe('$0.15');
// Medium session
expect(formatCostUsd(5.67)).toBe('$5.67');
// Large session
expect(formatCostUsd(29.57)).toBe('$29.57');
});
});
});
describe('formatCostCompact', () => {
describe('Zero values', () => {
it('should format zero as 0.00', () => {
expect(formatCostCompact(0)).toBe('0.00');
});
it('should format negative zero as 0.00', () => {
expect(formatCostCompact(-0)).toBe('0.00');
});
});
describe('Standard amounts (>= $0.01)', () => {
it('should format amounts without $ prefix', () => {
expect(formatCostCompact(0.01)).toBe('0.01');
expect(formatCostCompact(1.0)).toBe('1.00');
expect(formatCostCompact(1.23)).toBe('1.23');
});
it('should format large amounts', () => {
expect(formatCostCompact(999.99)).toBe('999.99');
expect(formatCostCompact(1234.56)).toBe('1234.56');
});
it('should round to 2 decimal places', () => {
expect(formatCostCompact(1.234)).toBe('1.23');
expect(formatCostCompact(1.235)).toBe('1.24'); // Rounds up
expect(formatCostCompact(1.999)).toBe('2.00');
});
});
describe('Sub-cent amounts ($0.001 - $0.01)', () => {
it('should format sub-cent amounts with 3 decimal places', () => {
expect(formatCostCompact(0.001)).toBe('0.001');
expect(formatCostCompact(0.005)).toBe('0.005');
expect(formatCostCompact(0.009)).toBe('0.009');
});
it('should round to 3 decimal places', () => {
expect(formatCostCompact(0.0012)).toBe('0.001');
expect(formatCostCompact(0.0015)).toBe('0.002'); // Rounds up
expect(formatCostCompact(0.0099)).toBe('0.010');
});
});
describe('Very small amounts (< $0.001)', () => {
it('should format tiny amounts with 4 decimal places', () => {
expect(formatCostCompact(0.0001)).toBe('0.0001');
expect(formatCostCompact(0.0005)).toBe('0.0005');
expect(formatCostCompact(0.0009)).toBe('0.0009');
});
it('should round to 4 decimal places', () => {
expect(formatCostCompact(0.00012)).toBe('0.0001');
expect(formatCostCompact(0.00016)).toBe('0.0002'); // Rounds up
expect(formatCostCompact(0.00099)).toBe('0.0010');
});
});
describe('Edge cases', () => {
it('should handle negative amounts with 4 decimal places', () => {
// Negative numbers don't match >= comparisons, so they use 4 decimals
expect(formatCostCompact(-1.23)).toBe('-1.2300');
expect(formatCostCompact(-0.001)).toBe('-0.0010');
expect(formatCostCompact(-0.0001)).toBe('-0.0001');
});
it('should handle very large amounts', () => {
expect(formatCostCompact(1000000)).toBe('1000000.00');
});
});
describe('Comparison with formatCostUsd', () => {
it('should match formatCostUsd except for $ prefix', () => {
const testCases = [0, 0.0001, 0.001, 0.01, 1.23, 999.99];
testCases.forEach((cost) => {
const withPrefix = formatCostUsd(cost);
const compact = formatCostCompact(cost);
// Compact should equal the USD format without the $
expect(compact).toBe(withPrefix.substring(1));
});
});
});
describe('Badge display use cases', () => {
it('should format for badge display', () => {
// Small per-message costs
expect(formatCostCompact(0.0015)).toBe('0.002');
expect(formatCostCompact(0.01)).toBe('0.01');
// Session totals in badges
expect(formatCostCompact(2.5)).toBe('2.50');
expect(formatCostCompact(15.0)).toBe('15.00');
});
});
});
});