@katlux/toolkit 0.1.1-alpha.145 → 0.1.1-alpha.146
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/bin/ai-init.mjs +517 -0
- package/bin/ai-tokens.mjs +212 -54
- package/bin/cli.mjs +76 -47
- package/bin/create-preset.mjs +1 -0
- package/bin/preset-contracts.json +2941 -0
- package/dist/compiled/composables/locales.mjs +204 -25
- package/dist/compiled/composables/useDataProvider.mjs +36 -25
- package/dist/compiled/composables/useFilterLogic.mjs +10 -2
- package/dist/compiled/composables/useKatluxForm.mjs +6 -4
- package/dist/compiled/composables/useVirtualDataset.mjs +689 -0
- package/dist/compiled/composables/useVirtualScroll.mjs +29 -9
- package/dist/module.cjs +63 -77
- package/dist/module.d.cts +5 -0
- package/dist/module.d.mts +4 -1
- package/dist/module.mjs +60 -78
- package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +7 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +4 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +7 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.d.ts +4 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +70 -37
- package/dist/runtime/components/KButton/KButton.global.d.vue.ts +2 -2
- package/dist/runtime/components/KButton/KButton.global.vue.d.ts +2 -2
- package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
- package/dist/runtime/components/KCalendar/KCalendar.global.d.vue.ts +19 -10
- package/dist/runtime/components/KCalendar/KCalendar.global.vue +7 -2
- package/dist/runtime/components/KCalendar/KCalendar.global.vue.d.ts +19 -10
- package/dist/runtime/components/KCalendar/KCalendar.logic.d.ts +14 -201
- package/dist/runtime/components/KCalendar/KCalendar.logic.js +60 -11
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.d.vue.ts +25 -5
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.vue +11 -1
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.vue.d.ts +25 -5
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.d.ts +19 -3
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.js +115 -1
- 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 +3 -3
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +3 -3
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +7 -1
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +1 -1
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +2 -2
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +2 -2
- package/dist/runtime/components/KContextMenu/KContextMenu.logic.js +5 -0
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +21 -17
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue +23 -16
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +21 -17
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +13 -10
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +25 -20
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +9 -13
- package/dist/runtime/components/KDatatable/KDatatable.global.vue +6 -5
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +9 -13
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +4 -6
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +26 -19
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +30 -14
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +38 -13
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +30 -14
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.d.ts +28 -6
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +197 -53
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +2 -2
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +2 -2
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +2 -0
- package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +55 -6
- package/dist/runtime/components/KGantt/KGantt.global.vue +12 -3
- package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +55 -6
- package/dist/runtime/components/KGantt/KGantt.logic.d.ts +33 -5
- package/dist/runtime/components/KGantt/KGantt.logic.js +39 -6
- 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/KLoader/KLoader.global.vue +2 -0
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.d.vue.ts +23 -0
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.vue +22 -0
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.vue.d.ts +23 -0
- package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +3 -1
- package/dist/runtime/components/KPagination/KPagination.global.vue +2 -1
- package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +3 -1
- package/dist/runtime/components/KPagination/KPagination.logic.d.ts +1 -0
- package/dist/runtime/components/KPagination/KPagination.logic.js +57 -5
- 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 +1 -1
- package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +1 -1
- 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/KTree/KTree.global.d.vue.ts +4 -4
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +4 -4
- package/dist/runtime/components/KTree/KTree.logic.d.ts +2 -2
- package/dist/runtime/components/KTree/KTree.logic.js +16 -12
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +5 -7
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +1 -5
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +5 -7
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +39 -5
- package/dist/runtime/components/KTreeView/KTreeView.global.vue +19 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +39 -5
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +23 -3
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +76 -6
- package/dist/runtime/composables/locales.js +204 -25
- package/dist/runtime/composables/useDataProvider.d.ts +5 -3
- package/dist/runtime/composables/useDataProvider.js +36 -25
- package/dist/runtime/composables/useFilterLogic.d.ts +16 -4
- package/dist/runtime/composables/useFilterLogic.js +10 -2
- package/dist/runtime/composables/useKatluxForm.d.ts +4 -4
- package/dist/runtime/composables/useKatluxForm.js +6 -4
- package/dist/runtime/composables/useSortLogic.d.ts +1 -1
- package/dist/runtime/composables/useVirtualDataset.d.ts +121 -0
- package/dist/runtime/composables/useVirtualDataset.js +689 -0
- package/dist/runtime/composables/useVirtualScroll.d.ts +8 -4
- package/dist/runtime/composables/useVirtualScroll.js +29 -9
- package/dist/runtime/plugins/nuxtCompatPlugin.js +9 -1
- package/dist/runtime/presets/default/assets/scss/css-variables.css +3 -0
- package/dist/runtime/presets/default/assets/scss/css-variables.scss +6 -1
- package/dist/runtime/presets/default/assets/scss/index.css +3 -0
- package/dist/runtime/presets/default/assets/svg/katlux-logo.svg +7 -0
- package/dist/runtime/presets/default/assets/svg/katlux.svg +6 -0
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.d.vue.ts +3 -2
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +31 -3
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue.d.ts +3 -2
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.d.vue.ts +3 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.vue +6 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.vue.d.ts +3 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.d.vue.ts +5 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue +33 -2
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue.d.ts +5 -0
- package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.vue +7 -1
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +30 -8
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +80 -164
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +30 -8
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +16 -9
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +99 -394
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +16 -9
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.d.vue.ts +6 -0
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue +71 -4
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue.d.ts +6 -0
- package/dist/runtime/presets/default/components/KGantt/KGantt.d.vue.ts +11 -12
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue +77 -14
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue.d.ts +11 -12
- package/dist/runtime/presets/default/components/KGantt/KGanttTimeline.vue +1 -0
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +3 -3
- package/dist/runtime/presets/default/components/KTree/KTree.vue +48 -14
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +3 -3
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +11 -2
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +14 -2
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +11 -2
- package/dist/skills/KATLUX_INDEX.md +9 -6
- package/dist/skills/katlux-components/SKILL.md +2 -0
- package/dist/skills/katlux-components/components/KBulkActions.md +25 -1
- package/dist/skills/katlux-components/components/KCombobox.md +2 -2
- package/dist/skills/katlux-components/components/KDataIterator.md +12 -4
- package/dist/skills/katlux-components/components/KDatatable.md +38 -0
- package/dist/skills/katlux-components/components/KDatePicker.md +3 -1
- package/dist/skills/katlux-components/components/KGantt.md +9 -0
- package/dist/skills/katlux-components/components/KIcon.md +1 -1
- package/dist/skills/katlux-components/components/KLineChart.md +3 -0
- package/dist/skills/katlux-components/components/KProductList.md +0 -1
- package/dist/skills/katlux-components/components/KScatterChart.md +3 -0
- package/dist/skills/katlux-components/components/KTreePicker.md +2 -1
- package/dist/skills/katlux-components/components/KTreeView.md +12 -0
- package/dist/skills/katlux-config/SKILL.md +19 -8
- package/dist/skills/katlux-presets/SKILL.md +121 -1
- package/dist/skills/katlux-presets/creating-a-preset.md +67 -0
- package/dist/skills/katlux-providers/SKILL.md +7 -5
- package/dist/skills/katlux-providers/providers/ADataProvider.md +16 -9
- package/dist/skills/katlux-providers/providers/CAPIFlatClientDataProvider.md +27 -3
- package/dist/skills/katlux-providers/providers/CAPIFlatServerDataProvider.md +11 -1
- package/dist/skills/katlux-providers/providers/CFlatClientDataProvider.md +19 -4
- package/dist/skills/katlux-providers/providers/CFlatServerDataProvider.md +4 -2
- package/dist/skills/katlux-providers/providers/CTreeClientDataProvider.md +2 -2
- package/dist/skills/katlux-providers/providers/RequestProvider.md +10 -0
- package/dist/skills/katlux-providers/providers/encryption-field-level.md +63 -19
- package/dist/skills/katlux-providers/providers/encryption-key-management.md +20 -2
- package/dist/skills/katlux-providers/providers/encryption-key-pinning.md +25 -11
- package/dist/skills/katlux-providers/providers/encryption-searchable.md +218 -0
- package/dist/skills/katlux-providers/providers/encryption-symmetric.md +25 -1
- package/dist/skills/katlux-providers/providers/encryption-threat-model.md +63 -0
- package/dist/skills/katlux-providers/providers/encryption.md +26 -1
- package/dist/skills/katlux-providers/providers/types.md +3 -1
- package/dist/skills/katlux-providers/providers/useDataProvider.md +2 -1
- package/dist/skills/katlux-providers/providers/useVirtualDataset.md +154 -0
- package/dist/skills/katlux-tokens/SKILL.md +2 -1
- package/dist/types.d.mts +1 -1
- package/package.json +7 -3
- package/bin/add-ai-reference.mjs +0 -259
package/bin/ai-init.mjs
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @katlux/toolkit katlux-ai-init
|
|
4
|
+
*
|
|
5
|
+
* Configures Katlux AI assistant skills, agent rules, and Model Context Protocol (MCP)
|
|
6
|
+
* servers for your development workspace.
|
|
7
|
+
*
|
|
8
|
+
* What it does:
|
|
9
|
+
* 1. Installs/updates Katlux AI skills in .agents/skills/katlux-* with content-hash protection
|
|
10
|
+
* 2. Scaffolds AGENTS.md and .agents/rules/rules.md (if missing)
|
|
11
|
+
* 3. Configures Katlux MCP server in .agents/mcp_config.json (always)
|
|
12
|
+
* 4. Optionally configures Cursor (.cursor/mcp.json) with --cursor or --all
|
|
13
|
+
* 5. Optionally configures VS Code (.vscode/mcp.json) with --vscode or --all
|
|
14
|
+
* 6. Optionally adds "ai:check" script to package.json with --scripts
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* npx @katlux/toolkit katlux-ai-init [options]
|
|
18
|
+
*
|
|
19
|
+
* Options:
|
|
20
|
+
* --cursor Configure Cursor MCP (.cursor/mcp.json)
|
|
21
|
+
* --vscode Configure VS Code Copilot MCP (.vscode/mcp.json)
|
|
22
|
+
* --all Configure all IDEs (.agents, .cursor, .vscode)
|
|
23
|
+
* --scripts Add token-efficient "ai:check" typechecker script to package.json
|
|
24
|
+
* --dry-run Display changes without modifying any files
|
|
25
|
+
* --force Overwrite local files even if locally modified
|
|
26
|
+
* --help, -h Show this help message
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync } from 'node:fs'
|
|
30
|
+
import { resolve, join, dirname } from 'node:path'
|
|
31
|
+
import { createHash } from 'node:crypto'
|
|
32
|
+
import { fileURLToPath } from 'node:url'
|
|
33
|
+
|
|
34
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
35
|
+
|
|
36
|
+
const RESET = '\x1b[0m'
|
|
37
|
+
const GREEN = '\x1b[32m'
|
|
38
|
+
const CYAN = '\x1b[36m'
|
|
39
|
+
const YELLOW = '\x1b[33m'
|
|
40
|
+
const RED = '\x1b[31m'
|
|
41
|
+
const BOLD = '\x1b[1m'
|
|
42
|
+
const DIM = '\x1b[2m'
|
|
43
|
+
|
|
44
|
+
export function log(color, prefix, message) {
|
|
45
|
+
console.log(`${color}${BOLD}${prefix}${RESET} ${message}`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function hashContent(content) {
|
|
49
|
+
return createHash('sha256').update(content, 'utf-8').digest('hex')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Strips single-line and multi-line comments from JSON string while preserving string literals.
|
|
54
|
+
* Also removes trailing commas before closing braces/brackets.
|
|
55
|
+
*/
|
|
56
|
+
export function stripJsonComments(jsonString) {
|
|
57
|
+
if (typeof jsonString !== 'string') return ''
|
|
58
|
+
return jsonString
|
|
59
|
+
.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (match, group) => group ? '' : match)
|
|
60
|
+
.replace(/,(\s*[}\]])/g, '$1')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Determines current Katlux package version and compatible MCP version.
|
|
65
|
+
*/
|
|
66
|
+
export function resolvePackageVersions(projectRoot) {
|
|
67
|
+
let toolkitVersion = '0.1.1-alpha.145'
|
|
68
|
+
let mcpVersion = '0.1.0-alpha.24'
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const pkgPath = resolve(__dirname, '../package.json')
|
|
72
|
+
if (existsSync(pkgPath)) {
|
|
73
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
|
|
74
|
+
if (pkg.version) toolkitVersion = pkg.version
|
|
75
|
+
if (pkg.katlux?.mcpVersion) mcpVersion = pkg.katlux.mcpVersion
|
|
76
|
+
}
|
|
77
|
+
} catch {}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const mcpPkgPath = resolve(__dirname, '../../katlux-mcp/package.json')
|
|
81
|
+
if (existsSync(mcpPkgPath)) {
|
|
82
|
+
const mcpPkg = JSON.parse(readFileSync(mcpPkgPath, 'utf-8'))
|
|
83
|
+
if (mcpPkg.version) mcpVersion = mcpPkg.version
|
|
84
|
+
}
|
|
85
|
+
} catch {}
|
|
86
|
+
|
|
87
|
+
if (projectRoot) {
|
|
88
|
+
try {
|
|
89
|
+
const consumerMcpPkg = resolve(projectRoot, 'node_modules/@katlux/mcp/package.json')
|
|
90
|
+
if (existsSync(consumerMcpPkg)) {
|
|
91
|
+
const mcpPkg = JSON.parse(readFileSync(consumerMcpPkg, 'utf-8'))
|
|
92
|
+
if (mcpPkg.version) mcpVersion = mcpPkg.version
|
|
93
|
+
}
|
|
94
|
+
} catch {}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return { toolkitVersion, mcpVersion }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Updates an MCP configuration file non-destructively, supporting JSONC (comments) and
|
|
102
|
+
* formatting correctly based on target type ('vscode' vs 'cursor' / 'agents').
|
|
103
|
+
*/
|
|
104
|
+
export function updateMcpConfig({
|
|
105
|
+
filePath,
|
|
106
|
+
targetType,
|
|
107
|
+
mcpVersion,
|
|
108
|
+
isMonorepo = false,
|
|
109
|
+
dryRun = false
|
|
110
|
+
}) {
|
|
111
|
+
const dir = dirname(filePath)
|
|
112
|
+
let rawContent = ''
|
|
113
|
+
let config = {}
|
|
114
|
+
|
|
115
|
+
if (existsSync(filePath)) {
|
|
116
|
+
try {
|
|
117
|
+
rawContent = readFileSync(filePath, 'utf-8')
|
|
118
|
+
const cleanJson = stripJsonComments(rawContent)
|
|
119
|
+
config = JSON.parse(cleanJson)
|
|
120
|
+
} catch (err) {
|
|
121
|
+
return {
|
|
122
|
+
status: 'parse_error',
|
|
123
|
+
error: err.message,
|
|
124
|
+
filePath
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (typeof config !== 'object' || config === null || Array.isArray(config)) {
|
|
130
|
+
config = {}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (targetType === 'vscode') {
|
|
134
|
+
// VS Code native format uses root "servers" and requires "type": "stdio"
|
|
135
|
+
if (!config.servers || typeof config.servers !== 'object' || Array.isArray(config.servers)) {
|
|
136
|
+
config.servers = {}
|
|
137
|
+
}
|
|
138
|
+
config.servers.katlux = {
|
|
139
|
+
type: 'stdio',
|
|
140
|
+
command: isMonorepo ? 'node' : 'npx',
|
|
141
|
+
args: isMonorepo
|
|
142
|
+
? ['packages/katlux-mcp/bin/katlux-mcp.mjs']
|
|
143
|
+
: ['-y', `@katlux/mcp@${mcpVersion}`]
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
// Cursor & Antigravity/Agents format uses root "mcpServers"
|
|
147
|
+
if (!config.mcpServers || typeof config.mcpServers !== 'object' || Array.isArray(config.mcpServers)) {
|
|
148
|
+
config.mcpServers = {}
|
|
149
|
+
}
|
|
150
|
+
config.mcpServers.katlux = {
|
|
151
|
+
command: isMonorepo ? 'node' : 'npx',
|
|
152
|
+
args: isMonorepo
|
|
153
|
+
? ['packages/katlux-mcp/bin/katlux-mcp.mjs']
|
|
154
|
+
: ['-y', `@katlux/mcp@${mcpVersion}`]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!dryRun) {
|
|
159
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
|
|
160
|
+
writeFileSync(filePath, JSON.stringify(config, null, 2) + '\n', 'utf-8')
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
status: 'success',
|
|
165
|
+
filePath,
|
|
166
|
+
config
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Scaffolds AGENTS.md and .agents/rules/rules.md only if missing.
|
|
172
|
+
*/
|
|
173
|
+
export function scaffoldAgentFiles({ projectRoot, dryRun = false }) {
|
|
174
|
+
const created = []
|
|
175
|
+
const skipped = []
|
|
176
|
+
|
|
177
|
+
const agentsMdPath = resolve(projectRoot, 'AGENTS.md')
|
|
178
|
+
if (!existsSync(agentsMdPath)) {
|
|
179
|
+
if (!dryRun) {
|
|
180
|
+
writeFileSync(agentsMdPath, `# Agent Context and Guidelines
|
|
181
|
+
|
|
182
|
+
This file serves as the main entry point for AI agents to understand the workspace structure and guidelines.
|
|
183
|
+
|
|
184
|
+
- [Project Rules](.agents/rules/rules.md)
|
|
185
|
+
- [Katlux Skills Index](.agents/skills/KATLUX_INDEX.md)
|
|
186
|
+
`, 'utf-8')
|
|
187
|
+
}
|
|
188
|
+
created.push('AGENTS.md')
|
|
189
|
+
} else {
|
|
190
|
+
skipped.push('AGENTS.md')
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const rulesDir = resolve(projectRoot, '.agents/rules')
|
|
194
|
+
const rulesMdPath = resolve(rulesDir, 'rules.md')
|
|
195
|
+
if (!existsSync(rulesMdPath)) {
|
|
196
|
+
if (!dryRun) {
|
|
197
|
+
if (!existsSync(rulesDir)) mkdirSync(rulesDir, { recursive: true })
|
|
198
|
+
writeFileSync(rulesMdPath, `# Agent Rules
|
|
199
|
+
|
|
200
|
+
## Project-Specific Rules
|
|
201
|
+
|
|
202
|
+
<!-- Add your own project rules here. -->
|
|
203
|
+
<!-- Example: always use the "users" Pinia store for auth state. -->
|
|
204
|
+
|
|
205
|
+
## Katlux Code Standards
|
|
206
|
+
|
|
207
|
+
1. **Zero-Import Standard**: All \`K*\` components (\`KDatatable\`, \`KModal\`, etc.), \`C*\` provider classes (\`CAPIFlatServerDataProvider\`, \`CFlatClientDataProvider\`, etc.), and \`E*\` enums (\`ECacheStrategy\`, \`EDataFilterOperator\`) are globally auto-imported by the Nuxt module. **DO NOT generate top-level import statements for Katlux components, providers, or enums in Vue SFC files.**
|
|
208
|
+
2. **Template**: Always use **Pug** (\`lang="pug"\`). Use **Tabs** for indentation.
|
|
209
|
+
3. **Styling**: Use CSS variables (e.g. \`var(--primary-500)\`, \`var(--border-radius-md)\`). Never hardcode colors or sizes.
|
|
210
|
+
4. **Preset Selectors**: Scope CSS rules under \`[data-preset~="preset-name"]\`. Avoid \`!important\`.
|
|
211
|
+
5. **Imports**: Use workspace aliases (e.g. \`#toolkit/composables/...\`). Avoid deep relative imports.
|
|
212
|
+
6. **i18n**: Use \`t('...')\` for all user-facing strings and ARIA labels.
|
|
213
|
+
|
|
214
|
+
## Katlux AI Pairing & Token Efficiency Standards
|
|
215
|
+
|
|
216
|
+
1. **MCP Tools First**: Always call Katlux MCP tools (\`katlux_get_component\`, \`katlux_get_provider\`, \`katlux_get_tokens\`) for exact component APIs, slots, props, and provider options (~200 tokens) instead of searching or reading deep package source files.
|
|
217
|
+
2. **Surgical File Reads**: When inspecting code, use targeted line ranges (30–50 lines maximum). Pinpoint lines with symbol searches or grep before reading.
|
|
218
|
+
3. **Compact Test Execution**: When running tests during AI pairing, use compact flags (e.g. \`--changed\`, \`--reporter=summary\`, or \`--reporter=agent\`) to prevent verbose logs from consuming context tokens.
|
|
219
|
+
4. **Focused Sessions**: Complete one feature or bug per conversation session. Start a fresh session when moving to an unrelated task to keep the AI context lean and token-efficient.
|
|
220
|
+
`, 'utf-8')
|
|
221
|
+
}
|
|
222
|
+
created.push('.agents/rules/rules.md')
|
|
223
|
+
} else {
|
|
224
|
+
skipped.push('.agents/rules/rules.md')
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return { created, skipped }
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Injects token-efficient typechecker into package.json preserving formatting.
|
|
232
|
+
*/
|
|
233
|
+
export function injectPackageScript({ projectRoot, dryRun = false }) {
|
|
234
|
+
const pkgPath = resolve(projectRoot, 'package.json')
|
|
235
|
+
if (!existsSync(pkgPath)) return { status: 'no_package_json' }
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
const raw = readFileSync(pkgPath, 'utf-8')
|
|
239
|
+
const indent = raw.includes('\t') ? '\t' : (raw.match(/^[ ]+/m)?.[0]?.length || 2)
|
|
240
|
+
const pkg = JSON.parse(raw)
|
|
241
|
+
|
|
242
|
+
if (!pkg.scripts) pkg.scripts = {}
|
|
243
|
+
if (pkg.scripts['ai:check']) {
|
|
244
|
+
return { status: 'already_exists', script: pkg.scripts['ai:check'] }
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Cross-platform command avoiding grep/head pipelines
|
|
248
|
+
pkg.scripts['ai:check'] = 'vue-tsc --noEmit --pretty false'
|
|
249
|
+
|
|
250
|
+
if (!dryRun) {
|
|
251
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, indent) + '\n', 'utf-8')
|
|
252
|
+
}
|
|
253
|
+
return { status: 'injected', script: pkg.scripts['ai:check'] }
|
|
254
|
+
} catch (err) {
|
|
255
|
+
return { status: 'error', error: err.message }
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Syncs Katlux skill files with hash-based modification protection.
|
|
261
|
+
*/
|
|
262
|
+
export async function syncSkills({
|
|
263
|
+
projectRoot,
|
|
264
|
+
skillsDir,
|
|
265
|
+
packagedSkillsDir,
|
|
266
|
+
force = false,
|
|
267
|
+
dryRun = false
|
|
268
|
+
}) {
|
|
269
|
+
const manifestFile = resolve(skillsDir, '.katlux-manifest.json')
|
|
270
|
+
const versionFile = resolve(skillsDir, '.katlux-version')
|
|
271
|
+
|
|
272
|
+
let manifest = {}
|
|
273
|
+
if (existsSync(manifestFile)) {
|
|
274
|
+
try {
|
|
275
|
+
manifest = JSON.parse(readFileSync(manifestFile, 'utf-8'))
|
|
276
|
+
} catch {}
|
|
277
|
+
}
|
|
278
|
+
if (!manifest.hashes) manifest.hashes = {}
|
|
279
|
+
|
|
280
|
+
let copied = 0
|
|
281
|
+
let skippedUserModified = 0
|
|
282
|
+
let preservedFiles = []
|
|
283
|
+
|
|
284
|
+
const hasPackaged = packagedSkillsDir && existsSync(join(packagedSkillsDir, 'KATLUX_INDEX.md'))
|
|
285
|
+
if (!hasPackaged) {
|
|
286
|
+
return {
|
|
287
|
+
status: 'no_packaged_skills',
|
|
288
|
+
error: `Packaged skills not found in ${packagedSkillsDir || 'default location'}`,
|
|
289
|
+
copied: 0,
|
|
290
|
+
skippedUserModified: 0,
|
|
291
|
+
preservedFiles: []
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Helper to copy directory files
|
|
296
|
+
function copyFilesRecursive(src, dest, relBase = '') {
|
|
297
|
+
if (!dryRun && !existsSync(dest)) mkdirSync(dest, { recursive: true })
|
|
298
|
+
const entries = readdirSync(src, { withFileTypes: true })
|
|
299
|
+
for (const entry of entries) {
|
|
300
|
+
const relPath = relBase ? `${relBase}/${entry.name}` : entry.name
|
|
301
|
+
if (!relBase && entry.name !== 'KATLUX_INDEX.md' && !entry.name.startsWith('katlux-')) {
|
|
302
|
+
continue
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const srcPath = join(src, entry.name)
|
|
306
|
+
const destPath = join(dest, entry.name)
|
|
307
|
+
|
|
308
|
+
if (entry.isDirectory()) {
|
|
309
|
+
copyFilesRecursive(srcPath, destPath, relPath)
|
|
310
|
+
} else if (entry.name.endsWith('.md')) {
|
|
311
|
+
const srcContent = readFileSync(srcPath, 'utf-8')
|
|
312
|
+
const newHash = hashContent(srcContent)
|
|
313
|
+
|
|
314
|
+
if (existsSync(destPath) && !force) {
|
|
315
|
+
const diskContent = readFileSync(destPath, 'utf-8')
|
|
316
|
+
const diskHash = hashContent(diskContent)
|
|
317
|
+
const prevHash = manifest.hashes?.[relPath]
|
|
318
|
+
|
|
319
|
+
if (prevHash && diskHash !== prevHash && diskHash !== newHash) {
|
|
320
|
+
skippedUserModified++
|
|
321
|
+
preservedFiles.push(relPath)
|
|
322
|
+
continue
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (!dryRun) {
|
|
327
|
+
const targetDir = dirname(destPath)
|
|
328
|
+
if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true })
|
|
329
|
+
writeFileSync(destPath, srcContent, 'utf-8')
|
|
330
|
+
manifest.hashes[relPath] = newHash
|
|
331
|
+
}
|
|
332
|
+
copied++
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
copyFilesRecursive(packagedSkillsDir, skillsDir)
|
|
338
|
+
|
|
339
|
+
if (!dryRun) {
|
|
340
|
+
const { toolkitVersion } = resolvePackageVersions(projectRoot)
|
|
341
|
+
manifest.version = toolkitVersion
|
|
342
|
+
if (!existsSync(skillsDir)) mkdirSync(skillsDir, { recursive: true })
|
|
343
|
+
writeFileSync(manifestFile, JSON.stringify(manifest, null, 2), 'utf-8')
|
|
344
|
+
writeFileSync(versionFile, toolkitVersion, 'utf-8')
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
status: 'success',
|
|
349
|
+
copied,
|
|
350
|
+
skippedUserModified,
|
|
351
|
+
preservedFiles
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Main dispatcher for katlux-ai-init CLI
|
|
357
|
+
*/
|
|
358
|
+
export async function runAiInit(options = {}) {
|
|
359
|
+
const projectRoot = options.projectRoot || process.cwd()
|
|
360
|
+
const args = options.args || process.argv.slice(2)
|
|
361
|
+
|
|
362
|
+
const isHelp = args.includes('--help') || args.includes('-h')
|
|
363
|
+
if (isHelp) {
|
|
364
|
+
console.log(`
|
|
365
|
+
${BOLD}Katlux AI Assistant & MCP Initializer${RESET}
|
|
366
|
+
|
|
367
|
+
${BOLD}Usage:${RESET}
|
|
368
|
+
npx @katlux/toolkit katlux-ai-init [options]
|
|
369
|
+
|
|
370
|
+
${BOLD}Options:${RESET}
|
|
371
|
+
${CYAN}--cursor${RESET} Configure Cursor MCP (.cursor/mcp.json)
|
|
372
|
+
${CYAN}--vscode${RESET} Configure VS Code Copilot MCP (.vscode/mcp.json)
|
|
373
|
+
${CYAN}--all${RESET} Configure all IDEs (.agents, .cursor, .vscode)
|
|
374
|
+
${CYAN}--scripts${RESET} Inject token-efficient "ai:check" script into package.json
|
|
375
|
+
${CYAN}--dry-run${RESET} Preview all changes without writing to disk
|
|
376
|
+
${CYAN}--force${RESET} Overwrite skill files even if locally modified
|
|
377
|
+
${CYAN}--help, -h${RESET} Show this help screen
|
|
378
|
+
`)
|
|
379
|
+
return 0
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const dryRun = args.includes('--dry-run') || options.dryRun || false
|
|
383
|
+
const force = args.includes('--force') || options.force || false
|
|
384
|
+
const withCursor = args.includes('--cursor') || args.includes('--all') || options.cursor || false
|
|
385
|
+
const withVsCode = args.includes('--vscode') || args.includes('--all') || options.vscode || false
|
|
386
|
+
const withScripts = args.includes('--scripts') || options.scripts || false
|
|
387
|
+
|
|
388
|
+
const localMcpPath = resolve(projectRoot, 'packages/katlux-mcp/bin/katlux-mcp.mjs')
|
|
389
|
+
const isMonorepo = existsSync(localMcpPath)
|
|
390
|
+
|
|
391
|
+
const { toolkitVersion, mcpVersion } = resolvePackageVersions(projectRoot)
|
|
392
|
+
|
|
393
|
+
console.log()
|
|
394
|
+
log(CYAN, '[katlux-ai-init]', `Initializing Katlux AI assistant context & tools...${dryRun ? ` ${YELLOW}(dry-run)${RESET}` : ''}`)
|
|
395
|
+
console.log()
|
|
396
|
+
|
|
397
|
+
const skillsDir = resolve(projectRoot, '.agents/skills')
|
|
398
|
+
const packagedSkillsDir = resolve(__dirname, '../dist/skills')
|
|
399
|
+
|
|
400
|
+
// 1. Sync skills
|
|
401
|
+
process.stdout.write(` ${DIM}Syncing Katlux AI skill files to .agents/skills/...${RESET}`)
|
|
402
|
+
const skillResult = await syncSkills({
|
|
403
|
+
projectRoot,
|
|
404
|
+
skillsDir,
|
|
405
|
+
packagedSkillsDir,
|
|
406
|
+
force,
|
|
407
|
+
dryRun
|
|
408
|
+
})
|
|
409
|
+
if (skillResult.status === 'no_packaged_skills') {
|
|
410
|
+
process.stdout.write(` ${YELLOW}⚠ (${skillResult.error})${RESET}\n`)
|
|
411
|
+
} else {
|
|
412
|
+
process.stdout.write(` ${GREEN}✔ (${skillResult.copied} files synced)${RESET}\n`)
|
|
413
|
+
}
|
|
414
|
+
if (skillResult.skippedUserModified > 0) {
|
|
415
|
+
log(YELLOW, ' preserved', `${skillResult.skippedUserModified} locally modified skill files were kept intact (use --force to overwrite)`)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// 2. Scaffold agent files
|
|
419
|
+
const agentScaffold = scaffoldAgentFiles({ projectRoot, dryRun })
|
|
420
|
+
if (agentScaffold.created.includes('AGENTS.md')) {
|
|
421
|
+
log(GREEN, ' created', `AGENTS.md ${DIM}(primary entry point for AI context)${RESET}`)
|
|
422
|
+
} else {
|
|
423
|
+
log(DIM, ' skipped', `AGENTS.md (already exists)`)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (agentScaffold.created.includes('.agents/rules/rules.md')) {
|
|
427
|
+
log(GREEN, ' created', `.agents/rules/rules.md ${DIM}(project-specific agent rules)${RESET}`)
|
|
428
|
+
} else {
|
|
429
|
+
log(DIM, ' skipped', `.agents/rules/rules.md (already exists)`)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// 3. Configure .agents/mcp_config.json (standard)
|
|
433
|
+
const agentsMcpPath = resolve(projectRoot, '.agents/mcp_config.json')
|
|
434
|
+
const agentsMcp = updateMcpConfig({
|
|
435
|
+
filePath: agentsMcpPath,
|
|
436
|
+
targetType: 'agents',
|
|
437
|
+
mcpVersion,
|
|
438
|
+
isMonorepo,
|
|
439
|
+
dryRun
|
|
440
|
+
})
|
|
441
|
+
if (agentsMcp.status === 'success') {
|
|
442
|
+
log(GREEN, ' configured', `.agents/mcp_config.json ${DIM}(@katlux/mcp@${mcpVersion})${RESET}`)
|
|
443
|
+
} else {
|
|
444
|
+
log(YELLOW, ' warning', `Failed to parse .agents/mcp_config.json: ${agentsMcp.error}. File was left untouched.`)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// 4. Configure Cursor if requested
|
|
448
|
+
if (withCursor) {
|
|
449
|
+
const cursorMcpPath = resolve(projectRoot, '.cursor/mcp.json')
|
|
450
|
+
const cursorMcp = updateMcpConfig({
|
|
451
|
+
filePath: cursorMcpPath,
|
|
452
|
+
targetType: 'cursor',
|
|
453
|
+
mcpVersion,
|
|
454
|
+
isMonorepo,
|
|
455
|
+
dryRun
|
|
456
|
+
})
|
|
457
|
+
if (cursorMcp.status === 'success') {
|
|
458
|
+
log(GREEN, ' configured', `.cursor/mcp.json ${DIM}(Cursor MCP server enabled)${RESET}`)
|
|
459
|
+
} else {
|
|
460
|
+
log(YELLOW, ' warning', `Failed to parse .cursor/mcp.json: ${cursorMcp.error}. File was left untouched.`)
|
|
461
|
+
}
|
|
462
|
+
} else {
|
|
463
|
+
log(DIM, ' info', `Run with --cursor to configure Cursor (.cursor/mcp.json)`)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// 5. Configure VS Code if requested
|
|
467
|
+
if (withVsCode) {
|
|
468
|
+
const vscodeMcpPath = resolve(projectRoot, '.vscode/mcp.json')
|
|
469
|
+
const vscodeMcp = updateMcpConfig({
|
|
470
|
+
filePath: vscodeMcpPath,
|
|
471
|
+
targetType: 'vscode',
|
|
472
|
+
mcpVersion,
|
|
473
|
+
isMonorepo,
|
|
474
|
+
dryRun
|
|
475
|
+
})
|
|
476
|
+
if (vscodeMcp.status === 'success') {
|
|
477
|
+
log(GREEN, ' configured', `.vscode/mcp.json ${DIM}(VS Code Copilot "servers" with type: stdio)${RESET}`)
|
|
478
|
+
} else {
|
|
479
|
+
log(YELLOW, ' warning', `Failed to parse .vscode/mcp.json: ${vscodeMcp.error}. File was left untouched.`)
|
|
480
|
+
}
|
|
481
|
+
} else {
|
|
482
|
+
log(DIM, ' info', `Run with --vscode to configure VS Code (.vscode/mcp.json)`)
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// 6. Scripts injection if requested
|
|
486
|
+
if (withScripts) {
|
|
487
|
+
const scriptResult = injectPackageScript({ projectRoot, dryRun })
|
|
488
|
+
if (scriptResult.status === 'injected') {
|
|
489
|
+
log(GREEN, ' injected', `package.json "ai:check" script: ${scriptResult.script}`)
|
|
490
|
+
} else if (scriptResult.status === 'already_exists') {
|
|
491
|
+
log(DIM, ' skipped', `package.json "ai:check" already exists`)
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
console.log()
|
|
496
|
+
log(GREEN, '[katlux-ai-init] ✔', `Katlux AI assistant integration successfully initialized!`)
|
|
497
|
+
console.log()
|
|
498
|
+
console.log(` ${CYAN}Skills:${RESET} .agents/skills/katlux-*/SKILL.md`)
|
|
499
|
+
console.log(` ${CYAN}Index:${RESET} .agents/skills/KATLUX_INDEX.md`)
|
|
500
|
+
console.log(` ${CYAN}Context:${RESET} AGENTS.md`)
|
|
501
|
+
console.log(` ${CYAN}Rules:${RESET} .agents/rules/rules.md`)
|
|
502
|
+
console.log(` ${CYAN}MCP Server:${RESET} @katlux/mcp@${mcpVersion}`)
|
|
503
|
+
console.log()
|
|
504
|
+
return 0
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Execute directly if run as CLI script
|
|
508
|
+
const isMain = process.argv[1] && (
|
|
509
|
+
process.argv[1].endsWith('ai-init.mjs') ||
|
|
510
|
+
process.argv[1].endsWith('katlux-ai-init')
|
|
511
|
+
)
|
|
512
|
+
if (isMain) {
|
|
513
|
+
runAiInit().catch(err => {
|
|
514
|
+
console.error(`${RED}[katlux-ai-init] ✖${RESET} ${err.message}`)
|
|
515
|
+
process.exit(1)
|
|
516
|
+
})
|
|
517
|
+
}
|