@katlux/toolkit 0.1.1-alpha.146 → 0.1.1-alpha.148
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -22
- package/bin/ai-init.mjs +71 -13
- package/bin/ai-tokens/adapters/antigravityAdapter.mjs +22 -0
- package/bin/ai-tokens/adapters/claudeCodeAdapter.mjs +192 -0
- package/bin/ai-tokens/adapters/codexAdapter.mjs +176 -0
- package/bin/ai-tokens/adapters/cursorAdapter.mjs +202 -0
- package/bin/ai-tokens/adapters/index.mjs +30 -0
- package/bin/ai-tokens/cliViews.mjs +301 -0
- package/bin/ai-tokens/formatAndDates.mjs +89 -0
- package/bin/ai-tokens/reportGenerator.mjs +232 -0
- package/bin/ai-tokens/transcriptParser.mjs +299 -0
- package/bin/ai-tokens.mjs +38 -1030
- package/bin/cli.mjs +14 -10
- package/bin/preset-contracts.json +66 -10
- package/dist/compiled/composables/locales/asianAndPacific.mjs +296 -0
- package/dist/compiled/composables/locales/northernAndEasternEuropean.mjs +342 -0
- package/dist/compiled/composables/locales/westernEuropean.mjs +268 -0
- package/dist/compiled/composables/locales.mjs +28 -895
- package/dist/compiled/composables/useDataProvider.mjs +3 -1
- package/dist/compiled/composables/useKatluxForm.mjs +7 -7
- package/dist/compiled/composables/usePresetComponent.mjs +2 -0
- package/dist/compiled/composables/useRequestQueue.mjs +3 -1
- package/dist/compiled/composables/useVirtualDataset.mjs +322 -354
- package/dist/compiled/composables/useVirtualScroll.mjs +69 -62
- package/dist/compiled/composables/virtualDataset/cacheStateHelpers.mjs +76 -0
- package/dist/compiled/composables/virtualDataset/keyboardNavHelpers.mjs +60 -0
- package/dist/compiled/composables/virtualDataset/treeSelectionHelpers.mjs +103 -0
- package/dist/compiled/composables/virtualDataset/types.mjs +0 -0
- package/dist/compiled/utils/deprecation.mjs +44 -0
- package/dist/compiled/utils/dom.mjs +124 -0
- package/dist/module.cjs +0 -5
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -6
- package/dist/runtime/app.config.d.ts +3 -0
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.d.ts +8 -0
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +21 -55
- package/dist/runtime/components/KButton/KButton.global.d.vue.ts +1 -1
- package/dist/runtime/components/KButton/KButton.global.vue.d.ts +1 -1
- package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
- package/dist/runtime/components/KCalendar/KCalendar.global.d.vue.ts +4 -4
- package/dist/runtime/components/KCalendar/KCalendar.global.vue.d.ts +4 -4
- package/dist/runtime/components/KCalendar/KCalendar.logic.js +8 -4
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.vue +4 -0
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.d.ts +2 -0
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.js +41 -26
- package/dist/runtime/components/KCalendar/recurringUtils.js +6 -5
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +17 -2
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +9 -4
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +17 -2
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +10 -2
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +32 -13
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +1 -1
- package/dist/runtime/components/KContextMenu/KContextMenu.global.d.vue.ts +3 -3
- package/dist/runtime/components/KContextMenu/KContextMenu.global.vue +4 -1
- package/dist/runtime/components/KContextMenu/KContextMenu.global.vue.d.ts +3 -3
- package/dist/runtime/components/KContextMenu/KContextMenu.logic.d.ts +24 -4
- package/dist/runtime/components/KContextMenu/KContextMenu.logic.js +43 -27
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +24 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue +19 -7
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +24 -1
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +20 -0
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +54 -14
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +6 -5
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +6 -4
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +45 -26
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +6 -4
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.d.ts +2 -0
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +66 -20
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +3 -3
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +3 -3
- package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +4 -4
- package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +4 -4
- package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +3 -2
- package/dist/runtime/components/KDropdown/KDropdown.logic.js +14 -13
- package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +3 -1
- package/dist/runtime/components/KGantt/KGantt.global.vue +7 -1
- package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +3 -1
- package/dist/runtime/components/KGrid/KGrid.global.d.vue.ts +1 -1
- package/dist/runtime/components/KGrid/KGrid.global.vue.d.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KIcon/KIcon.global.d.vue.ts +1 -1
- package/dist/runtime/components/KIcon/KIcon.global.vue.d.ts +1 -1
- package/dist/runtime/components/KLayout/KLayout.global.d.vue.ts +4 -1
- package/dist/runtime/components/KLayout/KLayout.global.vue +4 -1
- package/dist/runtime/components/KLayout/KLayout.global.vue.d.ts +4 -1
- package/dist/runtime/components/KLoader/KLoader.global.d.vue.ts +9 -0
- package/dist/runtime/components/KLoader/KLoader.global.vue +1 -0
- package/dist/runtime/components/KLoader/KLoader.global.vue.d.ts +9 -0
- package/dist/runtime/components/KLoader/KLoader.logic.d.ts +5 -0
- package/dist/runtime/components/KLoader/KLoader.logic.js +4 -0
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.logic.js +30 -7
- package/dist/runtime/components/KMultiTabs/KMultiTabs.logic.d.ts +1 -0
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.vue +6 -4
- package/dist/runtime/components/KPagination/KPagination.logic.d.ts +1 -1
- package/dist/runtime/components/KPagination/KPagination.logic.js +17 -9
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTabs/KTabs.logic.js +33 -11
- package/dist/runtime/components/KTextarea/KTextarea.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTextarea/KTextarea.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTextbox/KTextbox.global.d.vue.ts +12 -1
- package/dist/runtime/components/KTextbox/KTextbox.global.vue +8 -2
- package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +12 -1
- package/dist/runtime/components/KTextbox/KTextbox.logic.d.ts +5 -0
- package/dist/runtime/components/KTextbox/KTextbox.logic.js +4 -0
- package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTooltip/KTooltip.logic.d.ts +11 -2
- package/dist/runtime/components/KTooltip/KTooltip.logic.js +7 -5
- package/dist/runtime/components/KTree/KTree.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.logic.js +21 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +8 -4
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +4 -2
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +8 -4
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +3 -2
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +10 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +3 -3
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +3 -3
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +1 -1
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +36 -12
- package/dist/runtime/composables/locales/asianAndPacific.d.ts +11 -0
- package/dist/runtime/composables/locales/asianAndPacific.js +296 -0
- package/dist/runtime/composables/locales/northernAndEasternEuropean.d.ts +12 -0
- package/dist/runtime/composables/locales/northernAndEasternEuropean.js +342 -0
- package/dist/runtime/composables/locales/westernEuropean.d.ts +10 -0
- package/dist/runtime/composables/locales/westernEuropean.js +268 -0
- package/dist/runtime/composables/locales.d.ts +4 -24
- package/dist/runtime/composables/locales.js +28 -895
- package/dist/runtime/composables/useDataProvider.js +3 -1
- package/dist/runtime/composables/useKatluxForm.js +7 -7
- package/dist/runtime/composables/usePresetComponent.js +2 -0
- package/dist/runtime/composables/useRequestQueue.d.ts +2 -0
- package/dist/runtime/composables/useRequestQueue.js +3 -1
- package/dist/runtime/composables/useVirtualDataset.d.ts +6 -118
- package/dist/runtime/composables/useVirtualDataset.js +322 -354
- package/dist/runtime/composables/useVirtualScroll.d.ts +9 -9
- package/dist/runtime/composables/useVirtualScroll.js +69 -62
- package/dist/runtime/composables/virtualDataset/cacheStateHelpers.d.ts +49 -0
- package/dist/runtime/composables/virtualDataset/cacheStateHelpers.js +76 -0
- package/dist/runtime/composables/virtualDataset/keyboardNavHelpers.d.ts +26 -0
- package/dist/runtime/composables/virtualDataset/keyboardNavHelpers.js +60 -0
- package/dist/runtime/composables/virtualDataset/treeSelectionHelpers.d.ts +24 -0
- package/dist/runtime/composables/virtualDataset/treeSelectionHelpers.js +103 -0
- package/dist/runtime/composables/virtualDataset/types.d.ts +113 -0
- package/dist/runtime/composables/virtualDataset/types.js +0 -0
- package/dist/runtime/directives/clickOutside.d.ts +1 -1
- package/dist/runtime/directives/clickOutside.js +41 -13
- package/dist/runtime/plugins/nuxtCompatPlugin.d.ts +2 -1
- package/dist/runtime/plugins/nuxtCompatPlugin.js +7 -0
- package/dist/runtime/plugins/toastPlugin.client.js +2 -2
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.d.vue.ts +2 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue +24 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue.d.ts +2 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarWeek.vue +6 -5
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +4 -1
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +27 -17
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +4 -1
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -1
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +10 -10
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -1
- package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.d.vue.ts +2 -0
- package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.vue +60 -21
- package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.vue.d.ts +2 -0
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +12 -1
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +109 -15
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +12 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +1 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +14 -0
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +1 -1
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +5 -2
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +15 -12
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +5 -2
- package/dist/runtime/presets/default/components/KGantt/KGantt.d.vue.ts +10 -0
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue +23 -69
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue.d.ts +10 -0
- package/dist/runtime/presets/default/components/KGantt/KGanttTimeline.d.vue.ts +6 -2
- package/dist/runtime/presets/default/components/KGantt/KGanttTimeline.vue +22 -8
- package/dist/runtime/presets/default/components/KGantt/KGanttTimeline.vue.d.ts +6 -2
- package/dist/runtime/presets/default/components/KLayout/KLayout.vue +2 -2
- package/dist/runtime/presets/default/components/KLoader/KLoader.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KLoader/KLoader.vue +13 -2
- package/dist/runtime/presets/default/components/KLoader/KLoader.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KMaskTextbox/KMaskTextbox.vue +1 -94
- package/dist/runtime/presets/default/components/KMultiTabs/KMultiTabs.vue +69 -4
- package/dist/runtime/presets/default/components/KRangeSlider/KRangeSlider.vue +18 -46
- package/dist/runtime/presets/default/components/KSlider/KSlider.vue +11 -23
- package/dist/runtime/presets/default/components/KTextbox/KTextbox.d.vue.ts +4 -1
- package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +24 -8
- package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue.d.ts +4 -1
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +1 -1
- package/dist/runtime/presets/default/components/KTree/KTree.vue +51 -80
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +1 -1
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.vue +12 -2
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.vue.d.ts +1 -0
- package/dist/runtime/server/middleware/session.js +7 -0
- package/dist/runtime/utils/deprecation.d.ts +14 -0
- package/dist/runtime/utils/deprecation.js +44 -0
- package/dist/runtime/utils/dom.d.ts +31 -0
- package/dist/runtime/utils/dom.js +124 -0
- package/dist/skills/KATLUX_INDEX.md +15 -19
- package/dist/skills/katlux-components/components/KBulkActions.md +1 -1
- package/dist/skills/katlux-components/components/KDataIterator.md +5 -0
- package/dist/skills/katlux-components/components/KLayout.md +4 -0
- package/dist/skills/katlux-components/components/KLoader.md +3 -0
- package/dist/skills/katlux-components/components/KTextbox.md +1 -0
- package/dist/skills/katlux-config/SKILL.md +15 -7
- package/dist/skills/katlux-presets/SKILL.md +42 -2
- package/dist/skills/katlux-providers/SKILL.md +12 -0
- package/dist/skills/katlux-providers/providers/ADataProvider.md +1 -0
- package/dist/skills/katlux-providers/providers/CAPITreeServerDataProvider.md +13 -0
- package/dist/skills/katlux-providers/providers/RequestProvider.md +2 -2
- package/dist/skills/katlux-providers/providers/encryption-field-level.md +5 -2
- package/dist/skills/katlux-providers/providers/encryption-key-management.md +5 -2
- package/dist/skills/katlux-providers/providers/encryption-searchable.md +150 -27
- package/dist/skills/katlux-providers/providers/encryption-symmetric.md +4 -1
- package/dist/skills/katlux-providers/providers/encryption-threat-model.md +12 -6
- package/dist/skills/katlux-providers/providers/encryption.md +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import { basename, dirname, join } from 'node:path'
|
|
4
|
+
import { estimateTokens, getWeekKey } from '../formatAndDates.mjs'
|
|
5
|
+
import { analyzeSession } from '../transcriptParser.mjs'
|
|
6
|
+
|
|
7
|
+
export const getCursorProjectsDir = () =>
|
|
8
|
+
process.env.CURSOR_PROJECTS_DIR || join(homedir(), '.cursor', 'projects')
|
|
9
|
+
|
|
10
|
+
function projectFromSlug(slug) {
|
|
11
|
+
if (!slug) return 'Unknown'
|
|
12
|
+
const parts = slug.split('-').filter(Boolean)
|
|
13
|
+
return parts[parts.length - 1] || slug
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function extractText(content) {
|
|
17
|
+
if (typeof content === 'string') return content
|
|
18
|
+
if (!Array.isArray(content)) return ''
|
|
19
|
+
return content
|
|
20
|
+
.filter(b => b && (b.type === 'text' || typeof b.text === 'string'))
|
|
21
|
+
.map(b => b.text || '')
|
|
22
|
+
.join('\n')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function extractToolCalls(content) {
|
|
26
|
+
if (!Array.isArray(content)) return undefined
|
|
27
|
+
const calls = content
|
|
28
|
+
.filter(b => b && (b.type === 'tool_use' || b.type === 'tool_call'))
|
|
29
|
+
.map(b => ({
|
|
30
|
+
name: b.name || 'unknown_tool',
|
|
31
|
+
arguments: b.input ? JSON.stringify(b.input) : (b.arguments || '')
|
|
32
|
+
}))
|
|
33
|
+
return calls.length > 0 ? calls : undefined
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function collectJsonlFiles(dir) {
|
|
37
|
+
const files = []
|
|
38
|
+
if (!existsSync(dir)) return files
|
|
39
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
40
|
+
const full = join(dir, entry.name)
|
|
41
|
+
if (entry.isDirectory() && !entry.name.startsWith('.')) {
|
|
42
|
+
files.push(...collectJsonlFiles(full))
|
|
43
|
+
} else if (entry.isFile() && entry.name.endsWith('.jsonl')) {
|
|
44
|
+
files.push(full)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return files
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Discovers Cursor agent transcript `.jsonl` files under `CURSOR_PROJECTS_DIR`.
|
|
52
|
+
*/
|
|
53
|
+
export function getConversations(projectsDir = getCursorProjectsDir()) {
|
|
54
|
+
if (!existsSync(projectsDir)) return []
|
|
55
|
+
|
|
56
|
+
const results = []
|
|
57
|
+
for (const pDir of readdirSync(projectsDir, { withFileTypes: true })) {
|
|
58
|
+
if (!pDir.isDirectory() || pDir.name.startsWith('.')) continue
|
|
59
|
+
const fullProjectDir = join(projectsDir, pDir.name)
|
|
60
|
+
const transcriptDir = existsSync(join(fullProjectDir, 'agent-transcripts'))
|
|
61
|
+
? join(fullProjectDir, 'agent-transcripts')
|
|
62
|
+
: fullProjectDir
|
|
63
|
+
|
|
64
|
+
for (const filePath of collectJsonlFiles(transcriptDir)) {
|
|
65
|
+
const stat = statSync(filePath)
|
|
66
|
+
results.push({
|
|
67
|
+
id: basename(filePath, '.jsonl'),
|
|
68
|
+
path: filePath,
|
|
69
|
+
createdAt: stat.birthtimeMs ? new Date(stat.birthtimeMs) : stat.mtime,
|
|
70
|
+
lastActive: stat.mtime,
|
|
71
|
+
mtime: stat.mtime,
|
|
72
|
+
weekKey: getWeekKey(stat.mtime),
|
|
73
|
+
project: projectFromSlug(pDir.name)
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return results.sort((a, b) => b.lastActive.getTime() - a.lastActive.getTime())
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Fast preview metadata extractor for a Cursor `.jsonl` transcript file.
|
|
83
|
+
*/
|
|
84
|
+
export function getConversationPreviewFast(filePath, searchQuery = '') {
|
|
85
|
+
if (!existsSync(filePath)) {
|
|
86
|
+
return {
|
|
87
|
+
title: '(Empty)',
|
|
88
|
+
fullTitle: '',
|
|
89
|
+
project: 'Unknown',
|
|
90
|
+
estimatedTokens: 0,
|
|
91
|
+
rawSize: 0,
|
|
92
|
+
matchesSearch: false
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const raw = readFileSync(filePath, 'utf8')
|
|
97
|
+
const rawSize = Buffer.byteLength(raw, 'utf8')
|
|
98
|
+
const estimatedTokens = estimateTokens(rawSize)
|
|
99
|
+
const matchesSearch = searchQuery ? raw.toLowerCase().includes(searchQuery.toLowerCase()) : false
|
|
100
|
+
|
|
101
|
+
const parentName = basename(dirname(filePath))
|
|
102
|
+
const projectSlug = parentName === 'agent-transcripts'
|
|
103
|
+
? basename(dirname(dirname(filePath)))
|
|
104
|
+
: parentName
|
|
105
|
+
let project = projectFromSlug(projectSlug)
|
|
106
|
+
let fullTitle = ''
|
|
107
|
+
|
|
108
|
+
for (const line of raw.split('\n')) {
|
|
109
|
+
if (!line.trim()) continue
|
|
110
|
+
try {
|
|
111
|
+
const entry = JSON.parse(line)
|
|
112
|
+
if (entry.cwd && project === 'Unknown') project = basename(entry.cwd)
|
|
113
|
+
const role = entry.role || entry.message?.role || entry.type
|
|
114
|
+
if (role === 'user') {
|
|
115
|
+
const text = extractText(entry.message?.content ?? entry.content ?? entry.text)
|
|
116
|
+
.replace(/[\r\n\t]+/g, ' ')
|
|
117
|
+
.trim()
|
|
118
|
+
if (text) {
|
|
119
|
+
fullTitle = text
|
|
120
|
+
break
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} catch {
|
|
124
|
+
// Skip malformed lines
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const title = fullTitle
|
|
129
|
+
? (fullTitle.length > 32 ? fullTitle.slice(0, 31) + '…' : fullTitle)
|
|
130
|
+
: '(No user prompt)'
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
title,
|
|
134
|
+
fullTitle,
|
|
135
|
+
project,
|
|
136
|
+
estimatedTokens,
|
|
137
|
+
rawSize,
|
|
138
|
+
matchesSearch
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Parses a Cursor `.jsonl` transcript into the shared step format
|
|
144
|
+
* consumed by `analyzeSession`.
|
|
145
|
+
*/
|
|
146
|
+
export function parseTranscript(filePath) {
|
|
147
|
+
if (!existsSync(filePath)) return null
|
|
148
|
+
const raw = readFileSync(filePath, 'utf8')
|
|
149
|
+
const lines = raw.split('\n').filter(l => l.trim())
|
|
150
|
+
const steps = []
|
|
151
|
+
|
|
152
|
+
lines.forEach((line, idx) => {
|
|
153
|
+
try {
|
|
154
|
+
const entry = JSON.parse(line)
|
|
155
|
+
const msg = entry.message || {}
|
|
156
|
+
const role = entry.role || msg.role || entry.type
|
|
157
|
+
const content = msg.content ?? entry.content ?? entry.text ?? ''
|
|
158
|
+
const createdAt = entry.timestamp || entry.createdAt || undefined
|
|
159
|
+
|
|
160
|
+
if (role === 'user') {
|
|
161
|
+
steps.push({
|
|
162
|
+
step_index: idx + 1,
|
|
163
|
+
type: 'USER_INPUT',
|
|
164
|
+
content: extractText(content),
|
|
165
|
+
created_at: createdAt
|
|
166
|
+
})
|
|
167
|
+
} else if (role === 'assistant') {
|
|
168
|
+
steps.push({
|
|
169
|
+
step_index: idx + 1,
|
|
170
|
+
type: 'PLANNER_RESPONSE',
|
|
171
|
+
content: extractText(content),
|
|
172
|
+
tool_calls: extractToolCalls(content),
|
|
173
|
+
created_at: createdAt
|
|
174
|
+
})
|
|
175
|
+
} else if (role === 'tool' || role === 'tool_result') {
|
|
176
|
+
steps.push({
|
|
177
|
+
step_index: idx + 1,
|
|
178
|
+
type: 'TOOL_RESULT',
|
|
179
|
+
content: typeof content === 'string' ? content : JSON.stringify(content),
|
|
180
|
+
created_at: createdAt
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
} catch {
|
|
184
|
+
// Skip malformed lines
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
return steps
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const cursorAdapter = {
|
|
192
|
+
name: 'cursor',
|
|
193
|
+
displayName: 'Cursor',
|
|
194
|
+
get emptyMessage() {
|
|
195
|
+
return `No conversations found in ${getCursorProjectsDir()}`
|
|
196
|
+
},
|
|
197
|
+
getConversations: () => getConversations(),
|
|
198
|
+
getConversationPreviewFast,
|
|
199
|
+
parseTranscript,
|
|
200
|
+
analyzeSession
|
|
201
|
+
}
|
|
202
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { antigravityAdapter } from './antigravityAdapter.mjs'
|
|
2
|
+
import { claudeCodeAdapter } from './claudeCodeAdapter.mjs'
|
|
3
|
+
import { codexAdapter } from './codexAdapter.mjs'
|
|
4
|
+
import { cursorAdapter } from './cursorAdapter.mjs'
|
|
5
|
+
|
|
6
|
+
const ADAPTERS = {
|
|
7
|
+
antigravity: antigravityAdapter,
|
|
8
|
+
'claude-code': claudeCodeAdapter,
|
|
9
|
+
claude: claudeCodeAdapter,
|
|
10
|
+
cursor: cursorAdapter,
|
|
11
|
+
codex: codexAdapter
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const SUPPORTED_IDES = ['antigravity', 'claude-code', 'cursor', 'codex']
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resolves an IDE transcript adapter by name (defaults to `antigravity`).
|
|
18
|
+
* Throws an Error if the requested IDE is not supported.
|
|
19
|
+
*/
|
|
20
|
+
export function getIdeAdapter(ideName = 'antigravity') {
|
|
21
|
+
const key = String(ideName || 'antigravity').trim().toLowerCase()
|
|
22
|
+
const adapter = ADAPTERS[key]
|
|
23
|
+
if (!adapter) {
|
|
24
|
+
throw new Error(`Unsupported IDE "${ideName}". Supported IDEs: ${SUPPORTED_IDES.join(', ')}`)
|
|
25
|
+
}
|
|
26
|
+
return adapter
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { antigravityAdapter, claudeCodeAdapter, cursorAdapter, codexAdapter }
|
|
30
|
+
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { basename } from 'node:path'
|
|
2
|
+
import {
|
|
3
|
+
ANSI,
|
|
4
|
+
estimateTokens,
|
|
5
|
+
formatBytes,
|
|
6
|
+
formatDateTime,
|
|
7
|
+
formatTokens
|
|
8
|
+
} from './formatAndDates.mjs'
|
|
9
|
+
import { getIdeAdapter, SUPPORTED_IDES } from './adapters/index.mjs'
|
|
10
|
+
import { generateWeekReport, listDetectedProjects } from './reportGenerator.mjs'
|
|
11
|
+
|
|
12
|
+
const { RESET, BOLD, DIM, CYAN, GREEN, YELLOW, RED, MAGENTA, BLUE } = ANSI
|
|
13
|
+
|
|
14
|
+
/** Renders the paginated conversation browser list view. */
|
|
15
|
+
export function renderConversationListView({ filteredConversations, projectFilter, searchQuery, page, limit }) {
|
|
16
|
+
const total = filteredConversations.length
|
|
17
|
+
const totalPages = Math.max(1, Math.ceil(total / limit))
|
|
18
|
+
const safePage = Math.min(page, totalPages)
|
|
19
|
+
const startIndex = (safePage - 1) * limit
|
|
20
|
+
const pageItems = filteredConversations.slice(startIndex, startIndex + limit)
|
|
21
|
+
|
|
22
|
+
console.log(`\n${BOLD}╭──────────────────────────────────────────────────────────────────────────────╮${RESET}`)
|
|
23
|
+
console.log(`${BOLD}│ ANTIGRAVITY CONVERSATIONS BROWSER │${RESET}`)
|
|
24
|
+
console.log(`${BOLD}╰──────────────────────────────────────────────────────────────────────────────╯${RESET}`)
|
|
25
|
+
if (projectFilter) console.log(` Project Filter: ${GREEN}${projectFilter}${RESET}`)
|
|
26
|
+
if (searchQuery) console.log(` Filtered by: ${YELLOW}"${searchQuery}"${RESET} (${total} matching)`)
|
|
27
|
+
console.log(` Showing Page ${BOLD}${safePage}${RESET} of ${BOLD}${totalPages}${RESET} (${total === 0 ? 0 : startIndex + 1}–${Math.min(startIndex + limit, total)} of ${total} conversations)\n`)
|
|
28
|
+
|
|
29
|
+
if (total === 0) {
|
|
30
|
+
console.log(` ${RED}No conversations found matching criteria.${RESET}\n`)
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
console.log(` ${'#'.padStart(4)} ${'ID'.padEnd(9)} ${'PROJECT'.padEnd(16)} ${'WEEK'.padEnd(6)} ${'TOPIC / PROMPT'.padEnd(34)} ${'TOKENS'.padStart(8)} ${'LAST ACTIVE'.padEnd(19)} STARTED`)
|
|
35
|
+
console.log(` ${'─'.repeat(4)} ${'─'.repeat(9)} ${'─'.repeat(16)} ${'─'.repeat(6)} ${'─'.repeat(34)} ${'─'.repeat(8)} ${'─'.repeat(19)} ${'─'.repeat(19)}`)
|
|
36
|
+
|
|
37
|
+
pageItems.forEach(conv => {
|
|
38
|
+
const preview = conv.preview
|
|
39
|
+
const indexColor = conv.originalIndex === 1 ? GREEN : CYAN
|
|
40
|
+
console.log(
|
|
41
|
+
` ${indexColor}${String(conv.originalIndex).padStart(4)}${RESET} ` +
|
|
42
|
+
`${conv.id.slice(0, 8).padEnd(9)} ` +
|
|
43
|
+
`${YELLOW}${(preview.project || 'Unknown').slice(0, 15).padEnd(16)}${RESET} ` +
|
|
44
|
+
`${DIM}${conv.weekKey.replace('2026-', '').padEnd(6)}${RESET} ` +
|
|
45
|
+
`${preview.title.padEnd(34)} ` +
|
|
46
|
+
`${BOLD}${formatTokens(preview.estimatedTokens).padStart(8)}${RESET} ` +
|
|
47
|
+
`${GREEN}${formatDateTime(conv.lastActive).padEnd(19)}${RESET} ` +
|
|
48
|
+
`${DIM}${formatDateTime(conv.createdAt)}${RESET}`
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
console.log(`\n${BOLD}Navigation & Actions:${RESET}`)
|
|
53
|
+
if (safePage < totalPages) console.log(` • Next page: ${CYAN}npm run ai:tokens -- -p ${safePage + 1}${projectFilter ? ` -P ${projectFilter}` : ''}${RESET}`)
|
|
54
|
+
if (safePage > 1) console.log(` • Previous page: ${CYAN}npm run ai:tokens -- -p ${safePage - 1}${projectFilter ? ` -P ${projectFilter}` : ''}${RESET}`)
|
|
55
|
+
console.log(` • Filter project: ${CYAN}npm run ai:tokens -- -P <projectName>${RESET}`)
|
|
56
|
+
console.log(` • Weekly report: ${CYAN}${projectFilter ? `npm run ai:tokens -- --report -P ${projectFilter}` : 'npm run ai:tokens:report'}${RESET}`)
|
|
57
|
+
console.log(` • Inspect one: ${CYAN}npm run ai:tokens -- <#>${RESET} (e.g. ${CYAN}npm run ai:tokens -- ${pageItems[0]?.originalIndex}${RESET} or ${CYAN}npm run ai:tokens -- ${pageItems[0]?.id.slice(0, 8)}${RESET})`)
|
|
58
|
+
console.log(` • Detailed steps: ${CYAN}npm run ai:tokens -- <#> -d${RESET}\n`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Renders the detailed token breakdown and optional chronology for a single session. */
|
|
62
|
+
export function renderSingleConversationDetailView(selectedConv, allConversations, showDetail, adapter = getIdeAdapter('antigravity')) {
|
|
63
|
+
const steps = adapter.parseTranscript(selectedConv.path)
|
|
64
|
+
if (!steps) {
|
|
65
|
+
console.log(`${RED}No transcript found for conversation ${selectedConv.id}${RESET}`)
|
|
66
|
+
process.exit(1)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const previewMeta = adapter.getConversationPreviewFast(selectedConv.path)
|
|
70
|
+
const data = adapter.analyzeSession(steps, selectedConv.id, selectedConv.mtime, previewMeta.project)
|
|
71
|
+
const convIndex = allConversations.findIndex(c => c.id === selectedConv.id) + 1
|
|
72
|
+
|
|
73
|
+
console.log(`\n${BOLD}╭──────────────────────────────────────────────────────────────────────────╮${RESET}`)
|
|
74
|
+
console.log(`${BOLD}│ AI CONVERSATION TOKEN LOG │${RESET}`)
|
|
75
|
+
console.log(`${BOLD}╰──────────────────────────────────────────────────────────────────────────╯${RESET}`)
|
|
76
|
+
console.log(` ${BOLD}Conversation Index:${RESET} ${GREEN}#${convIndex}${RESET} of ${allConversations.length}`)
|
|
77
|
+
console.log(` ${BOLD}Project:${RESET} ${YELLOW}${data.project}${RESET} (${CYAN}${data.weekKey}${RESET})`)
|
|
78
|
+
console.log(` ${BOLD}Conversation ID:${RESET} ${CYAN}${data.conversationId}${RESET}`)
|
|
79
|
+
console.log(` ${BOLD}Topic / Prompt:${RESET} ${YELLOW}"${data.sessionTitle}"${RESET}`)
|
|
80
|
+
console.log(` ${BOLD}Started:${RESET} ${formatDateTime(selectedConv.createdAt)}`)
|
|
81
|
+
console.log(` ${BOLD}Last Active:${RESET} ${GREEN}${formatDateTime(selectedConv.lastActive)}${RESET}`)
|
|
82
|
+
console.log(` ${BOLD}Total Steps:${RESET} ${data.totalSteps} recorded steps`)
|
|
83
|
+
console.log(` ${BOLD}Transcript Size:${RESET} ${formatBytes(data.totalChars)} total characters\n`)
|
|
84
|
+
|
|
85
|
+
console.log(`${BOLD}Token Summary (Estimated BPE):${RESET}`)
|
|
86
|
+
console.log(` ${GREEN}● Total Tokens:${RESET} ${BOLD}${formatTokens(data.totalTokens)}${RESET} tokens (~${data.totalTokens.toLocaleString()})`)
|
|
87
|
+
console.log(` ${BLUE}↳ Input Tokens:${RESET} ${formatTokens(data.inputTokens)} tokens (${Math.round((data.inputTokens / data.totalTokens) * 100 || 0)}%)`)
|
|
88
|
+
console.log(` ${MAGENTA}↳ Output Tokens:${RESET} ${formatTokens(data.outputTokens)} tokens (${Math.round((data.outputTokens / data.totalTokens) * 100 || 0)}%)\n`)
|
|
89
|
+
|
|
90
|
+
console.log(`${BOLD}Approximate Model Cost (if fresh API query):${RESET}`)
|
|
91
|
+
const geminiCost = ((data.inputTokens / 1_000_000) * 0.35 + (data.outputTokens / 1_000_000) * 1.05).toFixed(4)
|
|
92
|
+
const claudeCost = ((data.inputTokens / 1_000_000) * 3.00 + (data.outputTokens / 1_000_000) * 15.00).toFixed(4)
|
|
93
|
+
const gptCost = ((data.inputTokens / 1_000_000) * 2.50 + (data.outputTokens / 1_000_000) * 10.00).toFixed(4)
|
|
94
|
+
console.log(` Gemini 1.5/2.0 Flash : ${GREEN}$${geminiCost}${RESET}`)
|
|
95
|
+
console.log(` Claude 3.5 Sonnet : ${YELLOW}$${claudeCost}${RESET}`)
|
|
96
|
+
console.log(` GPT-4o : ${CYAN}$${gptCost}${RESET}\n`)
|
|
97
|
+
|
|
98
|
+
if (data.userPrompts.length > 0) {
|
|
99
|
+
console.log(`${BOLD}Conversation Turns (${data.userPrompts.length} User Requests):${RESET}`)
|
|
100
|
+
const formatTurn = (p, idx, timeColor = DIM) => {
|
|
101
|
+
const timeLabel = p.time ? `${timeColor}(${p.time})${RESET} ` : ''
|
|
102
|
+
console.log(` ${CYAN}Turn ${idx + 1}${RESET} [Step #${p.step}] ${timeLabel}${p.text.slice(0, 85)}${p.text.length > 85 ? '...' : ''}`)
|
|
103
|
+
}
|
|
104
|
+
if (data.userPrompts.length <= 8) {
|
|
105
|
+
data.userPrompts.forEach((p, idx) => formatTurn(p, idx))
|
|
106
|
+
} else {
|
|
107
|
+
data.userPrompts.slice(0, 2).forEach((p, idx) => formatTurn(p, idx))
|
|
108
|
+
console.log(` ${DIM}... and ${data.userPrompts.length - 8} earlier turns ...${RESET}`)
|
|
109
|
+
const startIdx = data.userPrompts.length - 6
|
|
110
|
+
data.userPrompts.slice(-6).forEach((p, i) => formatTurn(p, startIdx + i, GREEN))
|
|
111
|
+
}
|
|
112
|
+
console.log(` ${DIM}Tip: Run with -d to see full chronology of every turn and tool call.${RESET}\n`)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
console.log(`${BOLD}Token Breakdown by Event Category:${RESET}`)
|
|
116
|
+
console.log(` ${'CATEGORY'.padEnd(25)} ${'CALLS'.padStart(6)} ${'TOKENS'.padStart(10)} ${'PERCENT'.padStart(8)}`)
|
|
117
|
+
console.log(` ${'─'.repeat(25)} ${'─'.repeat(6)} ${'─'.repeat(10)} ${'─'.repeat(8)}`)
|
|
118
|
+
Object.entries(data.categories)
|
|
119
|
+
.filter(([_, cat]) => cat.count > 0)
|
|
120
|
+
.sort((a, b) => b[1].tokens - a[1].tokens)
|
|
121
|
+
.forEach(([_, cat]) => {
|
|
122
|
+
const pct = Math.round((cat.tokens / data.totalTokens) * 100) || 0
|
|
123
|
+
const color = pct > 40 ? RED : pct > 20 ? YELLOW : CYAN
|
|
124
|
+
console.log(` ${cat.label.padEnd(25)} ${String(cat.count).padStart(6)} ${BOLD}${formatTokens(cat.tokens).padStart(10)}${RESET} ${color}${String(pct + '%').padStart(8)}${RESET}`)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
if (data.topViewedFiles.length > 0 || data.topModifiedFiles.length > 0) {
|
|
128
|
+
console.log(`\n${BOLD}Key Files Touched in this Session:${RESET}`)
|
|
129
|
+
if (data.topModifiedFiles.length > 0) console.log(` ${YELLOW}Modified:${RESET} ${data.topModifiedFiles.map(([f, n]) => `${f} (${n}x)`).join(', ')}`)
|
|
130
|
+
if (data.topViewedFiles.length > 0) console.log(` ${CYAN}Viewed:${RESET} ${data.topViewedFiles.map(([f, n]) => `${f} (${n}x)`).join(', ')}`)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (data.mcpCalls && data.mcpCalls.total > 0) {
|
|
134
|
+
console.log(`\n${BOLD}MCP Introspection Invocations:${RESET}`)
|
|
135
|
+
console.log(` katlux_inspect_project : ${data.mcpCalls.inspectProject} call(s)`)
|
|
136
|
+
console.log(` katlux_validate_code : ${data.mcpCalls.validateCode} call(s)`)
|
|
137
|
+
if (data.mcpCalls.otherMcp > 0) console.log(` other MCP tools : ${data.mcpCalls.otherMcp} call(s)`)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.log(`\n${BOLD}Top 5 Largest Token Spikes in this Session:${RESET}`)
|
|
141
|
+
data.spikes.forEach((spike, idx) => {
|
|
142
|
+
console.log(` ${idx + 1}. [Step #${spike.step_index}] ${YELLOW}${formatTokens(spike.tokens)} tokens${RESET} (${spike.type})`)
|
|
143
|
+
console.log(` ${DIM}"${spike.preview}..."${RESET}`)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
if (showDetail) {
|
|
147
|
+
console.log(`\n${BOLD}Full Step Chronology:${RESET}`)
|
|
148
|
+
steps.forEach(s => {
|
|
149
|
+
let c = ''
|
|
150
|
+
if (typeof s.content === 'string') c = s.content
|
|
151
|
+
else if (s.tool_calls) c = JSON.stringify(s.tool_calls)
|
|
152
|
+
else if (s.content) c = JSON.stringify(s.content)
|
|
153
|
+
const tok = estimateTokens(c)
|
|
154
|
+
const preview = c.replace(/[\r\n\t]+/g, ' ').slice(0, 60).trim()
|
|
155
|
+
console.log(` [#${String(s.step_index).padStart(3)}] ${s.type.padEnd(20)} ${formatTokens(tok).padStart(8)} tokens ${DIM}${preview}${RESET}`)
|
|
156
|
+
})
|
|
157
|
+
} else {
|
|
158
|
+
console.log(`\n${DIM}Commands:${RESET}`)
|
|
159
|
+
console.log(` • Weekly Report: ${CYAN}npm run ai:tokens:report${RESET}`)
|
|
160
|
+
console.log(` • Browse list: ${CYAN}npm run ai:tokens -- -p 1${RESET}`)
|
|
161
|
+
console.log(` • Search topic: ${CYAN}npm run ai:tokens -- -s "<keyword>"${RESET}`)
|
|
162
|
+
console.log(` • View step log: ${CYAN}npm run ai:tokens -- ${convIndex} -d${RESET}\n`)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Parses `--ide <name>` or `--ide=<name>` from CLI args (defaults to `antigravity`). */
|
|
167
|
+
export function parseIdeArg(args = []) {
|
|
168
|
+
for (let i = 0; i < args.length; i++) {
|
|
169
|
+
const arg = args[i]
|
|
170
|
+
if (arg.startsWith('--ide=')) {
|
|
171
|
+
return arg.slice('--ide='.length).trim() || 'antigravity'
|
|
172
|
+
}
|
|
173
|
+
if (arg === '--ide' && args[i + 1] && !args[i + 1].startsWith('-')) {
|
|
174
|
+
return args[i + 1].trim()
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return 'antigravity'
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** CLI argument parser and dispatcher for `katlux-tokens`. */
|
|
181
|
+
export function runAiTokensCli(args = process.argv.slice(2)) {
|
|
182
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
183
|
+
console.log(`Usage: ai-tokens [options] [index|id]`)
|
|
184
|
+
console.log(` --ide <name> IDE transcript adapter (${SUPPORTED_IDES.join(' | ')}, default: antigravity)`)
|
|
185
|
+
console.log(` -P, --project <name> Filter by project name (or 'current' / '.')`)
|
|
186
|
+
console.log(` --projects List all detected projects`)
|
|
187
|
+
console.log(` -r, --report Generate weekly token report`)
|
|
188
|
+
console.log(` -w, --week <YYYY-Www> Filter weekly report`)
|
|
189
|
+
console.log(` --md, --save Output Markdown / save report`)
|
|
190
|
+
console.log(` -s, --search <q> Search conversations`)
|
|
191
|
+
console.log(` -p, --page <n> Paginated list view`)
|
|
192
|
+
console.log(` -l, --limit <n> Items per page (default: 100)`)
|
|
193
|
+
console.log(` -d, --detail Show full step chronology`)
|
|
194
|
+
process.exit(0)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const ideName = parseIdeArg(args)
|
|
198
|
+
let adapter
|
|
199
|
+
try {
|
|
200
|
+
adapter = getIdeAdapter(ideName)
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.log(`${RED}${err.message}${RESET}`)
|
|
203
|
+
process.exit(1)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const showDetail = args.includes('-d') || args.includes('--detail')
|
|
207
|
+
|
|
208
|
+
let projectFilter = ''
|
|
209
|
+
const prjArgIdx = args.findIndex(a => a === '-P' || a === '--project')
|
|
210
|
+
if (prjArgIdx !== -1 && args[prjArgIdx + 1] && !args[prjArgIdx + 1].startsWith('-')) {
|
|
211
|
+
projectFilter = args[prjArgIdx + 1]
|
|
212
|
+
if (projectFilter === 'current' || projectFilter === '.') projectFilter = basename(process.cwd())
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (args.includes('--projects') || (args.includes('-P') && !projectFilter)) {
|
|
216
|
+
const all = adapter.getConversations().map(c => ({ ...c, preview: adapter.getConversationPreviewFast(c.path) }))
|
|
217
|
+
listDetectedProjects(all, adapter)
|
|
218
|
+
process.exit(0)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const isReport = args.includes('--report') || args.includes('-r') || args.includes('--weekly')
|
|
222
|
+
const asMarkdown = args.includes('--md') || args.includes('--markdown')
|
|
223
|
+
const saveFile = args.includes('--save')
|
|
224
|
+
|
|
225
|
+
let weekFilter = ''
|
|
226
|
+
const weekArgIdx = args.findIndex(a => a === '-w' || a === '--week')
|
|
227
|
+
if (weekArgIdx !== -1 && args[weekArgIdx + 1]) weekFilter = args[weekArgIdx + 1]
|
|
228
|
+
|
|
229
|
+
if (isReport || weekFilter) {
|
|
230
|
+
generateWeekReport({ weekFilter, projectFilter, asMarkdown, saveFile, adapter })
|
|
231
|
+
process.exit(0)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
let searchQuery = ''
|
|
235
|
+
const searchArgIdx = args.findIndex(a => a === '-s' || a === '--search' || a === '-q')
|
|
236
|
+
if (searchArgIdx !== -1 && args[searchArgIdx + 1]) searchQuery = args[searchArgIdx + 1].toLowerCase()
|
|
237
|
+
|
|
238
|
+
let page = 1
|
|
239
|
+
const pageArgIdx = args.findIndex(a => a === '-p' || a === '--page')
|
|
240
|
+
if (pageArgIdx !== -1 && args[pageArgIdx + 1]) page = Math.max(1, parseInt(args[pageArgIdx + 1], 10) || 1)
|
|
241
|
+
|
|
242
|
+
let limit = 100
|
|
243
|
+
const limitArgIdx = args.findIndex(a => a === '-l' || a === '--limit')
|
|
244
|
+
if (limitArgIdx !== -1 && args[limitArgIdx + 1]) limit = Math.max(1, parseInt(args[limitArgIdx + 1], 10) || 100)
|
|
245
|
+
|
|
246
|
+
const allConversations = adapter.getConversations()
|
|
247
|
+
if (allConversations.length === 0) {
|
|
248
|
+
console.log(`${RED}${adapter.emptyMessage}${RESET}`)
|
|
249
|
+
process.exit(1)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const mappedConversations = allConversations.map((c, i) => ({
|
|
253
|
+
...c,
|
|
254
|
+
originalIndex: i + 1,
|
|
255
|
+
preview: adapter.getConversationPreviewFast(c.path, searchQuery)
|
|
256
|
+
}))
|
|
257
|
+
|
|
258
|
+
const projectFiltered = projectFilter
|
|
259
|
+
? mappedConversations.filter(c => c.preview.project.toLowerCase().includes(projectFilter.toLowerCase()))
|
|
260
|
+
: mappedConversations
|
|
261
|
+
|
|
262
|
+
const filteredConversations = searchQuery
|
|
263
|
+
? projectFiltered.filter(c =>
|
|
264
|
+
c.id.toLowerCase().includes(searchQuery) ||
|
|
265
|
+
(c.preview.fullTitle && c.preview.fullTitle.toLowerCase().includes(searchQuery)) ||
|
|
266
|
+
c.preview.matchesSearch
|
|
267
|
+
)
|
|
268
|
+
: projectFiltered
|
|
269
|
+
|
|
270
|
+
const positionalArgs = args.filter(a =>
|
|
271
|
+
!a.startsWith('-') && a !== String(page) && a !== String(limit) && a !== searchQuery && a !== weekFilter && a !== projectFilter && a !== ideName
|
|
272
|
+
)
|
|
273
|
+
const targetArg = positionalArgs[0]
|
|
274
|
+
const targetIndex = targetArg && /^\d+$/.test(targetArg) ? parseInt(targetArg, 10) : null
|
|
275
|
+
const isExplicitList = args.includes('--list') || pageArgIdx !== -1 || searchArgIdx !== -1 || projectFilter !== ''
|
|
276
|
+
|
|
277
|
+
if ((isExplicitList && !targetIndex) || (searchQuery && !targetIndex)) {
|
|
278
|
+
renderConversationListView({ filteredConversations, projectFilter, searchQuery, page, limit })
|
|
279
|
+
process.exit(0)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
let selectedConv = allConversations[0]
|
|
283
|
+
if (targetIndex !== null) {
|
|
284
|
+
if (targetIndex < 1 || targetIndex > allConversations.length) {
|
|
285
|
+
console.log(`${RED}Invalid index #${targetIndex}. Available: 1 to ${allConversations.length}.${RESET}`)
|
|
286
|
+
process.exit(1)
|
|
287
|
+
}
|
|
288
|
+
selectedConv = allConversations[targetIndex - 1]
|
|
289
|
+
} else if (targetArg) {
|
|
290
|
+
const found = allConversations.find(c => c.id.toLowerCase().startsWith(targetArg.toLowerCase()))
|
|
291
|
+
if (!found) {
|
|
292
|
+
console.log(`${RED}Conversation matching "${targetArg}" not found.${RESET}`)
|
|
293
|
+
console.log(`Run ${CYAN}npm run ai:tokens -- -p 1${RESET} to view all conversations.`)
|
|
294
|
+
process.exit(1)
|
|
295
|
+
}
|
|
296
|
+
selectedConv = found
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
renderSingleConversationDetailView(selectedConv, allConversations, showDetail, adapter)
|
|
300
|
+
}
|
|
301
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { homedir } from 'node:os'
|
|
4
|
+
|
|
5
|
+
export const ANSI = {
|
|
6
|
+
RESET: '\x1b[0m',
|
|
7
|
+
BOLD: '\x1b[1m',
|
|
8
|
+
DIM: '\x1b[2m',
|
|
9
|
+
CYAN: '\x1b[36m',
|
|
10
|
+
GREEN: '\x1b[32m',
|
|
11
|
+
YELLOW: '\x1b[33m',
|
|
12
|
+
RED: '\x1b[31m',
|
|
13
|
+
MAGENTA: '\x1b[35m',
|
|
14
|
+
BLUE: '\x1b[34m'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const BRAIN_DIRS = [
|
|
18
|
+
resolve(homedir(), '.gemini/antigravity/brain'),
|
|
19
|
+
resolve(homedir(), '.gemini/antigravity-ide/brain')
|
|
20
|
+
]
|
|
21
|
+
export const BRAIN_DIR = BRAIN_DIRS.find(d => existsSync(d)) || BRAIN_DIRS[0]
|
|
22
|
+
|
|
23
|
+
/** Estimates BPE token count for code and conversation JSON (~3.75 chars per token). */
|
|
24
|
+
export function estimateTokens(input = 0) {
|
|
25
|
+
if (!input) return 0
|
|
26
|
+
const chars = typeof input === 'number' ? input : (input.length || 0)
|
|
27
|
+
return Math.ceil(chars / 3.75)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Formats integer token counts compactly (e.g. `12.4k`, `1.25M`). */
|
|
31
|
+
export function formatTokens(count) {
|
|
32
|
+
if (count >= 1_000_000) return (count / 1_000_000).toFixed(2) + 'M'
|
|
33
|
+
if (count >= 1_000) return (count / 1_000).toFixed(1) + 'k'
|
|
34
|
+
return (count || 0).toLocaleString()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Formats byte lengths into human-readable units. */
|
|
38
|
+
export function formatBytes(bytes) {
|
|
39
|
+
if (bytes >= 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(2) + ' MB'
|
|
40
|
+
if (bytes >= 1024) return (bytes / 1024).toFixed(1) + ' KB'
|
|
41
|
+
return (bytes || 0) + ' B'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Formats a Date instance into compact local date and time display. */
|
|
45
|
+
export function formatDateTime(d) {
|
|
46
|
+
if (!d) return '-'
|
|
47
|
+
const dateStr = d.toLocaleDateString('en-US', { month: '2-digit', day: '2-digit', year: 'numeric' })
|
|
48
|
+
const timeStr = d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
49
|
+
return `${dateStr} ${timeStr}`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function cleanString(val) {
|
|
53
|
+
if (!val) return ''
|
|
54
|
+
return String(val).replace(/^["']|["']$/g, '').trim()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function makeBar(percent, maxLen = 16) {
|
|
58
|
+
const filled = Math.min(maxLen, Math.round((percent / 100) * maxLen))
|
|
59
|
+
return '█'.repeat(filled) + '░'.repeat(maxLen - filled)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Calculates standard ISO Calendar Week key (e.g. `"2026-W43"`). */
|
|
63
|
+
export function getWeekKey(date) {
|
|
64
|
+
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()))
|
|
65
|
+
const dayNum = d.getUTCDay() || 7
|
|
66
|
+
d.setUTCDate(d.getUTCDate() + 4 - dayNum)
|
|
67
|
+
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1))
|
|
68
|
+
const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7)
|
|
69
|
+
return `${d.getUTCFullYear()}-W${String(weekNo).padStart(2, '0')}`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Formats a calendar week key into a human-readable `Mon – Sun` range. */
|
|
73
|
+
export function getWeekDateRange(weekKey) {
|
|
74
|
+
const match = weekKey.match(/^(\d{4})-W(\d{2})$/)
|
|
75
|
+
if (!match) return weekKey
|
|
76
|
+
const year = parseInt(match[1], 10)
|
|
77
|
+
const week = parseInt(match[2], 10)
|
|
78
|
+
|
|
79
|
+
const jan4 = new Date(Date.UTC(year, 0, 4))
|
|
80
|
+
const jan4Day = jan4.getUTCDay() || 7
|
|
81
|
+
const mondayWeek1 = new Date(jan4.getTime() - (jan4Day - 1) * 86400000)
|
|
82
|
+
const monday = new Date(mondayWeek1.getTime() + (week - 1) * 7 * 86400000)
|
|
83
|
+
const sunday = new Date(monday.getTime() + 6 * 86400000)
|
|
84
|
+
|
|
85
|
+
const monStr = monday.toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' })
|
|
86
|
+
const sunStr = sunday.toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' })
|
|
87
|
+
return `${monStr} – ${sunStr}`
|
|
88
|
+
}
|
|
89
|
+
|