@dxtmisha/scripts 0.10.15 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/bin/design-types-save.ts +9 -0
- package/package.json +2 -1
- package/src/classes/Design/DesignTypes.ts +41 -520
- package/src/classes/Design/DesignTypesAi.ts +135 -0
- package/src/classes/Design/DesignTypesDescription.ts +109 -0
- package/src/classes/Design/DesignTypesMake.ts +460 -0
- package/src/classes/Design/DesignTypesMcp.ts +90 -0
- package/src/classes/Design/DesignTypesPrompts.ts +289 -0
- package/src/config.ts +2 -0
- package/src/library.ts +73 -68
- package/src/media/templates/packages/library/_.gitignore.txt +2 -0
- package/src/media/templates/packages/library/package.json +2 -2
- package/src/media/templates/prompts/aiCodeGlobalPrompt.en.md +1 -1
- package/src/media/templates/prompts/aiCodeGlobalPrompt.ru.md +1 -1
- package/src/media/templates/prompts/aiCodeVuePrompt.en.md +1 -1
- package/src/media/templates/prompts/aiCodeVuePrompt.ru.md +1 -1
- package/src/types/designTypes.ts +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.11.1] - 2026-08-14
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- **AI Prompt Templates**:
|
|
9
|
+
- Refined AI initialization step in `aiCodeGlobalPrompt.en.md` and `aiCodeGlobalPrompt.ru.md` to load `ai-types.md` and `ai-developer.md` conditionally only when relevant to the task.
|
|
10
|
+
- Added directive to search `ai-prompt.md` and `ai-types.md` for existing utilities and keywords before writing custom code logic.
|
|
11
|
+
|
|
12
|
+
## [0.11.0] - 2026-08-13
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- **CLI `dxt-types-save` & Fast Save Mode**: Added `dxt-types-save` CLI executable script (`bin/design-types-save.ts`) and `makeSave()` method in `DesignTypes` to generate `ai-types.md` from cached `ai-types-list` files without invoking AI APIs.
|
|
16
|
+
- **MD5 Hash Calculation & `ai-types-list` Sync**:
|
|
17
|
+
- Added `md5` hash property to `DesignTypesItem` (`DesignTypesList`) and `getMd5` calculation utility in `DesignTypes`.
|
|
18
|
+
- Added `UI_DIR_AI_TYPES_LIST` constant (`ai-types-list`) to `src/config.ts`.
|
|
19
|
+
- Added `saveList` method to save copies of type definition files with MD5 headers (`// md5:...`) to `ai-types-list`, skipping redundant writes for unchanged content.
|
|
20
|
+
- **Modular Class Structure for AI Types Generation**:
|
|
21
|
+
- Extracted core `DesignTypes` logic into specialized sub-classes: `DesignTypesAi`, `DesignTypesMake`, `DesignTypesPrompts`, `DesignTypesDescription`, and `DesignTypesMcp`.
|
|
22
|
+
- Registered and exported new classes in `@dxtmisha/scripts` entrypoint (`src/library.ts`).
|
|
23
|
+
- **Prompt Metadata & Cache System**:
|
|
24
|
+
- Structured AI prompt generation output using JSON metadata (title, description) via `toAiJson`.
|
|
25
|
+
- Implemented prompt item caching with MD5 hash validation (`DesignTypesPromptCacheItem` and `DesignTypesPrompts` cache persistence).
|
|
26
|
+
- **Dedicated MCP & Description Generators**:
|
|
27
|
+
- Added `DesignTypesDescription` for generating high-density project overview descriptions with capability lists and study triggers.
|
|
28
|
+
- Added `DesignTypesMcp` for populating MCP server resource descriptors (`ai-mcp.json`) using cached prompt metadata.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
- **AI Types & Prompt Optimization**:
|
|
32
|
+
- Optimized JSDoc extraction in `DesignTypesMake` (`hasJSDoc` check): skips passing full JS source implementation (`fullJsContent`) when TypeScript declarations already contain complete JSDoc annotations, significantly reducing token usage.
|
|
33
|
+
- Restructured AI prompt context in `DesignTypesAi` to separate target declaration file content from supplementary JS implementation context.
|
|
34
|
+
- Updated prompt guidelines for `dxt-types` generation to require concise JSDocs, keyword search tags, and stripped `@returns` tags.
|
|
35
|
+
- **Scaffolding Template**: Added `ai-types.md` to package template `.gitignore` (`_.gitignore.txt`).
|
|
36
|
+
|
|
37
|
+
## [0.10.16] - 2026-08-11
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
- **AI Prompts**: Refined Vue component logic rules in `aiCodeVuePrompt.en.md` and `aiCodeVuePrompt.ru.md` — restricted mandatory composable extraction to complex logic, clarifying that simple logic or calling existing hooks does not require a separate composable.
|
|
41
|
+
|
|
5
42
|
## [0.10.15] - 2026-08-10
|
|
6
43
|
|
|
7
44
|
### Added
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxtmisha/scripts",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "CLI tools, AI integration scripts, and automation utilities for DXT UI — automated component scaffolding, Figma layout generation, library packaging, documentation building, screenshot captures, and AI prompt processing.",
|
|
7
7
|
"keywords": [
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"dxt-prompt": "bin/design-prompt.ts",
|
|
63
63
|
"dxt-screenshot": "bin/design-screenshot.ts",
|
|
64
64
|
"dxt-types": "bin/design-types.ts",
|
|
65
|
+
"dxt-types-save": "bin/design-types-save.ts",
|
|
65
66
|
"dxt-ui": "bin/design-ui.ts",
|
|
66
67
|
"dxt-wiki-storm": "bin/design-wiki-storm.ts"
|
|
67
68
|
},
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getPackageJson } from '../../functions/getPackageJson'
|
|
3
|
-
import { useAi } from '../../composables/useAi'
|
|
1
|
+
import { ServerStorage } from '@dxtmisha/functional-basic'
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import {
|
|
3
|
+
import { DesignTypesAi } from './DesignTypesAi'
|
|
4
|
+
import { DesignTypesDescription } from './DesignTypesDescription'
|
|
5
|
+
import { DesignTypesMake } from './DesignTypesMake'
|
|
6
|
+
import { DesignTypesMcp } from './DesignTypesMcp'
|
|
7
|
+
import { DesignTypesPrompts } from './DesignTypesPrompts'
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* Engine for generating compressed and AI-optimized TypeScript type definitions.
|
|
@@ -16,12 +14,20 @@ import { UI_DIR_CONSTRUCTOR, UI_FILE_AI_DESCRIPTION, UI_FILE_AI_MCP, UI_FILE_AI_
|
|
|
16
14
|
* Сканирует выходные данные сборки на наличие файлов деклараций, очищает их и использует ИИ для создания минимальной, насыщенной контекстом библиотеки типов для использования в автоматизированных помощниках по кодированию.
|
|
17
15
|
*/
|
|
18
16
|
export class DesignTypes {
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
/** Instance of DesignTypesAi for AI interactions / Экземпляр DesignTypesAi для ИИ взаимодействия */
|
|
18
|
+
protected readonly ai: DesignTypesAi
|
|
19
|
+
|
|
20
|
+
/** Instance of DesignTypesDescription for description generation / Экземпляр DesignTypesDescription для генерации описания */
|
|
21
|
+
protected readonly description: DesignTypesDescription
|
|
22
|
+
|
|
23
|
+
/** Instance of DesignTypesMake for declaration file processing / Экземпляр DesignTypesMake для обработки файлов деклараций */
|
|
24
|
+
protected readonly makeTypes: DesignTypesMake
|
|
25
|
+
|
|
26
|
+
/** Instance of DesignTypesMcp for MCP server resources processing / Экземпляр DesignTypesMcp для обработки ресурсов MCP-сервера */
|
|
27
|
+
protected readonly mcp: DesignTypesMcp
|
|
28
|
+
|
|
29
|
+
/** Instance of DesignTypesPrompts for prompt file processing / Экземпляр DesignTypesPrompts для обработки файлов промптов */
|
|
30
|
+
protected readonly prompts: DesignTypesPrompts
|
|
25
31
|
|
|
26
32
|
/**
|
|
27
33
|
* Constructor for DesignTypes.
|
|
@@ -37,531 +43,46 @@ export class DesignTypes {
|
|
|
37
43
|
protected readonly isRaw: boolean = false
|
|
38
44
|
) {
|
|
39
45
|
ServerStorage.setErrorStatus(true)
|
|
40
|
-
|
|
46
|
+
|
|
47
|
+
this.ai = new DesignTypesAi(this.dir, this.isRaw)
|
|
48
|
+
this.makeTypes = new DesignTypesMake(this.ai)
|
|
49
|
+
this.prompts = new DesignTypesPrompts(this.promptsDir, this.ai)
|
|
50
|
+
this.description = new DesignTypesDescription(this.ai, this.makeTypes, this.prompts, this.isRaw)
|
|
51
|
+
this.mcp = new DesignTypesMcp(this.ai, this.prompts, this.isRaw)
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
/**
|
|
44
55
|
* Main method to execute the type generation process.
|
|
45
56
|
*
|
|
46
57
|
* Основной метод для выполнения процесса генерации типов.
|
|
58
|
+
* @returns current instance / текущий экземпляр
|
|
47
59
|
*/
|
|
48
|
-
async make() {
|
|
60
|
+
async make(): Promise<this> {
|
|
49
61
|
console.log('DesignTypes: making AI types...')
|
|
50
62
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const fullJsContent = this.toOneFile(jsFiles)
|
|
56
|
-
|
|
57
|
-
const aiContent = this.isRaw
|
|
58
|
-
? fullContent
|
|
59
|
-
: await this.toAiEdit(fullContent, fullJsContent)
|
|
60
|
-
let fullDescription = ''
|
|
61
|
-
let mcpPrompts: DesignMcpResources | undefined
|
|
62
|
-
|
|
63
|
-
this.save(aiContent)
|
|
64
|
-
|
|
65
|
-
if (!this.isRaw) {
|
|
66
|
-
const aiDescription = await this.toAiDescription(fullContent, fullJsContent)
|
|
67
|
-
|
|
68
|
-
const promptList = this.getListPrompts()
|
|
69
|
-
const prompts = await this.toAiPrompts(promptList)
|
|
70
|
-
|
|
71
|
-
fullDescription = `${aiDescription}\n${prompts}`
|
|
72
|
-
|
|
73
|
-
const mcpList: DesignTypesList = [
|
|
74
|
-
{
|
|
75
|
-
path: UI_FILE_AI_TYPES,
|
|
76
|
-
content: aiContent
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
path: UI_FILE_AI_DESCRIPTION,
|
|
80
|
-
content: fullDescription
|
|
81
|
-
},
|
|
82
|
-
...promptList
|
|
83
|
-
]
|
|
84
|
-
|
|
85
|
-
mcpPrompts = await this.toAiMcpPrompts(mcpList)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.saveDescription(fullDescription)
|
|
89
|
-
this.saveMcp(mcpPrompts ?? [])
|
|
63
|
+
await this.makeTypes.make()
|
|
64
|
+
await this.prompts.make()
|
|
65
|
+
await this.description.make()
|
|
66
|
+
await this.mcp.make()
|
|
90
67
|
|
|
91
68
|
console.log('DesignTypes: AI types saved.')
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Checks if the file is a valid declaration file.
|
|
96
|
-
*
|
|
97
|
-
* Проверяет, является ли файл валидным файлом декларации.
|
|
98
|
-
* @param file file name / имя файла
|
|
99
|
-
*/
|
|
100
|
-
protected isFile(file: string): boolean {
|
|
101
|
-
return file.endsWith('.d.ts')
|
|
102
|
-
&& !file.endsWith('.vue.d.ts')
|
|
103
|
-
&& !file.endsWith('wiki.d.ts')
|
|
104
|
-
&& !file.endsWith('wikiData.d.ts')
|
|
105
|
-
&& (
|
|
106
|
-
!file.includes(`${UI_DIR_CONSTRUCTOR}/`)
|
|
107
|
-
|| file.endsWith('/basicTypes.d.ts')
|
|
108
|
-
|| file.endsWith('/types.d.ts')
|
|
109
|
-
|| file.endsWith('/props.d.ts')
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Checks if the file is a valid JavaScript or TypeScript file.
|
|
115
|
-
*
|
|
116
|
-
* Проверяет, является ли файл валидным JavaScript или TypeScript файлом.
|
|
117
|
-
* @param file file name / имя файла
|
|
118
|
-
*/
|
|
119
|
-
protected isFileJs(file: string): boolean {
|
|
120
|
-
return file.endsWith('.js')
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Checks if the content contains type definitions.
|
|
125
|
-
*
|
|
126
|
-
* Проверяет, содержит ли контент определения типов.
|
|
127
|
-
* @param content file content / содержимое файла
|
|
128
|
-
*/
|
|
129
|
-
protected isContent(content?: string): content is string {
|
|
130
|
-
return Boolean(
|
|
131
|
-
content
|
|
132
|
-
&& content.includes('export')
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Returns the full path segments for a file.
|
|
138
|
-
*
|
|
139
|
-
* Возвращает сегменты полного пути для файла.
|
|
140
|
-
* @param file file name / имя файла
|
|
141
|
-
*/
|
|
142
|
-
protected getPath(file: string): string[] {
|
|
143
|
-
return [...this.dirArray, file]
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Returns the project name from package.json.
|
|
148
|
-
*
|
|
149
|
-
* Возвращает название проекта из package.json.
|
|
150
|
-
* @returns project name or 'none' / название проекта или 'none'
|
|
151
|
-
*/
|
|
152
|
-
protected getProjectName(): string {
|
|
153
|
-
return getPackageJson()?.name ?? 'none'
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Reads the directory recursively.
|
|
158
|
-
*
|
|
159
|
-
* Читает директорию рекурсивно.
|
|
160
|
-
*/
|
|
161
|
-
protected getList() {
|
|
162
|
-
return PropertiesFile.readDirRecursive(this.dirArray)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Gets a list of files filtered by a provided checker function.
|
|
167
|
-
*
|
|
168
|
-
* Получает список файлов, отфильтрованный переданной функцией проверки.
|
|
169
|
-
* @param checkFile function to check if the file matches criteria / функция проверки соответствия файла критериям
|
|
170
|
-
*/
|
|
171
|
-
protected getListBy(checkFile: (file: string) => boolean): DesignTypesList {
|
|
172
|
-
return forEach(
|
|
173
|
-
this.getList(),
|
|
174
|
-
(file) => {
|
|
175
|
-
if (checkFile(file)) {
|
|
176
|
-
const content = this.readFile(file)
|
|
177
|
-
|
|
178
|
-
if (this.isContent(content)) {
|
|
179
|
-
return {
|
|
180
|
-
path: file,
|
|
181
|
-
content
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return undefined
|
|
187
|
-
}
|
|
188
|
-
) as DesignTypesList
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Gets a list of files filtered by criteria.
|
|
193
|
-
*
|
|
194
|
-
* Получает список файлов, отфильтрованный по критериям.
|
|
195
|
-
*/
|
|
196
|
-
protected getListByFilter(): DesignTypesList {
|
|
197
|
-
return this.getListBy(file => this.isFile(file))
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Gets a list of JS files filtered by criteria.
|
|
202
|
-
*
|
|
203
|
-
* Получает список JS файлов, отфильтрованный по критериям.
|
|
204
|
-
*/
|
|
205
|
-
protected getListByFilterJs(): DesignTypesList {
|
|
206
|
-
return this.getListBy(file => this.isFileJs(file))
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Gets a list of prompt files.
|
|
211
|
-
*
|
|
212
|
-
* Получает список файлов с промптами.
|
|
213
|
-
*/
|
|
214
|
-
protected getListPrompts(): DesignTypesList {
|
|
215
|
-
const files = PropertiesFile.readDirRecursive(this.promptsDir)
|
|
216
|
-
|
|
217
|
-
return forEach(
|
|
218
|
-
files,
|
|
219
|
-
(file) => {
|
|
220
|
-
const path = `${this.promptsDir}/${file}`
|
|
221
|
-
const content = PropertiesFile.readFileOnly(path)
|
|
222
|
-
|
|
223
|
-
if (content) {
|
|
224
|
-
return {
|
|
225
|
-
path,
|
|
226
|
-
content
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
) as DesignTypesList
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Reads the content of a file.
|
|
235
|
-
*
|
|
236
|
-
* Читает содержимое файла.
|
|
237
|
-
* @param path file path / путь к файлу
|
|
238
|
-
*/
|
|
239
|
-
protected readFile(path: string): string | undefined {
|
|
240
|
-
return PropertiesFile.readFileOnly(this.getPath(path))
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Saves the generated content to a file.
|
|
245
|
-
*
|
|
246
|
-
* Сохраняет сгенерированный контент в файл.
|
|
247
|
-
* @param content content to save / контент для сохранения
|
|
248
|
-
*/
|
|
249
|
-
protected save(content: string) {
|
|
250
|
-
const packageJson = getPackageJson()
|
|
251
|
-
|
|
252
|
-
if (packageJson) {
|
|
253
|
-
const versionStr = packageJson.version ? ` (v${packageJson.version})` : ''
|
|
254
|
-
PropertiesFile.writeByPath(
|
|
255
|
-
UI_FILE_AI_TYPES,
|
|
256
|
-
[
|
|
257
|
-
`All these methods are in the ${packageJson.name}${versionStr} library.`,
|
|
258
|
-
'',
|
|
259
|
-
content
|
|
260
|
-
].join('\n')
|
|
261
|
-
)
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Saves the AI-generated project description to a file.
|
|
267
|
-
*
|
|
268
|
-
* Сохраняет сгенерированное ИИ описание проекта в файл.
|
|
269
|
-
* @param content content to save / контент для сохранения
|
|
270
|
-
*/
|
|
271
|
-
protected saveDescription(content: string) {
|
|
272
|
-
PropertiesFile.writeByPath(
|
|
273
|
-
UI_FILE_AI_DESCRIPTION,
|
|
274
|
-
content
|
|
275
|
-
)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Saves the AI-generated MCP server resources to a file.
|
|
280
|
-
*
|
|
281
|
-
* Сохраняет сгенерированные ИИ ресурсы MCP-сервера в файл.
|
|
282
|
-
* @param data data to save / данные для сохранения
|
|
283
|
-
*/
|
|
284
|
-
protected saveMcp(data: object) {
|
|
285
|
-
PropertiesFile.writeByPath(
|
|
286
|
-
UI_FILE_AI_MCP,
|
|
287
|
-
JSON.stringify(data, null, 2)
|
|
288
|
-
)
|
|
289
|
-
}
|
|
290
69
|
|
|
291
|
-
|
|
292
|
-
* Combines a list of files into a single string.
|
|
293
|
-
*
|
|
294
|
-
* Объединяет список файлов в одну строку.
|
|
295
|
-
* @param list list of files / список файлов
|
|
296
|
-
*/
|
|
297
|
-
protected toOneFile(list: DesignTypesList): string {
|
|
298
|
-
return forEach(
|
|
299
|
-
list,
|
|
300
|
-
item => `// File: ${item.path}\n${item.content}`
|
|
301
|
-
)
|
|
302
|
-
.join('\n\n')
|
|
70
|
+
return this
|
|
303
71
|
}
|
|
304
72
|
|
|
305
73
|
/**
|
|
306
|
-
*
|
|
74
|
+
* Generates type definitions by combining processed files from ai-types-list directory without running AI.
|
|
307
75
|
*
|
|
308
|
-
*
|
|
309
|
-
* @
|
|
310
|
-
* @param prompt instructions for the AI / инструкции для ИИ
|
|
311
|
-
* @param code code to optimize / код для оптимизации
|
|
76
|
+
* Генерирует определения типов путем объединения обработанных файлов из директории ai-types-list без запуска ИИ.
|
|
77
|
+
* @returns current instance / текущий экземпляр
|
|
312
78
|
*/
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
prompt: string,
|
|
316
|
-
code?: string
|
|
317
|
-
): Promise<string | undefined> {
|
|
318
|
-
if (this.isRaw) {
|
|
319
|
-
return undefined
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const ai = useAi()
|
|
79
|
+
makeSave(): this {
|
|
80
|
+
console.log('DesignTypes: saving AI types from list...')
|
|
323
81
|
|
|
324
|
-
|
|
325
|
-
ai.addPrompt('You are a world-class senior developer and an exceptional technical writer.')
|
|
326
|
-
ai.addPrompt('CRITICAL DIRECTIVE: No data stored in history, previous chat messages, or prior conversation context must influence the result. Process strictly and exclusively the data provided in the text below.')
|
|
327
|
-
ai.addPrompt(prompt)
|
|
328
|
-
ai.addPrompt(`File Content: ${content}`)
|
|
329
|
-
|
|
330
|
-
if (code) {
|
|
331
|
-
ai.addPrompt(`File JS Code: ${code}`)
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const generate = await ai.generate('go!')
|
|
335
|
-
|
|
336
|
-
if (generate) {
|
|
337
|
-
return generate
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return undefined
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Cleans up the content by removing imports, local exports, and empty lines.
|
|
346
|
-
*
|
|
347
|
-
* Очищает контент, удаляя импорты, локальные экспорты и пустые строки.
|
|
348
|
-
* @param content content to clean / контент для очистки
|
|
349
|
-
*/
|
|
350
|
-
protected cleanContent(content: string): string {
|
|
351
|
-
return content
|
|
352
|
-
// Remove multi-line and single-line imports (only local files)
|
|
353
|
-
.replace(/^import\s+(?:{[^}]+}|[^{]+)\s+from\s+['"]\.[^'"]+['"];?/gm, '')
|
|
354
|
-
.replace(/^import\s+['"]\.[^'"]+['"];?/gm, '')
|
|
355
|
-
// Remove local internal re-exports (e.g., export * from "./...")
|
|
356
|
-
.replace(/^export\s+(?:\*|{[^}]+})\s+from\s+['"]\.[^'"]+['"];?/gm, '')
|
|
357
|
-
// Remove single-line private and protected properties
|
|
358
|
-
.replace(/^\s*(?:private|protected)\s+[^({]+;/gm, '')
|
|
359
|
-
// Remove lines that only contain inline comments
|
|
360
|
-
.replace(/^\s*\/\/.*$/gm, '')
|
|
361
|
-
// Remove empty lines
|
|
362
|
-
.replace(/^\s*[\r\n]/gm, '')
|
|
363
|
-
.trim()
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Sends content to AI for optimization.
|
|
368
|
-
*
|
|
369
|
-
* Отправляет контент ИИ для оптимизации.
|
|
370
|
-
* @param content content to optimize / контент для оптимизации
|
|
371
|
-
* @param code code to optimize / код для оптимизации
|
|
372
|
-
*/
|
|
373
|
-
protected async toAiEdit(content: string, code: string): Promise<string> {
|
|
374
|
-
const generate = await this.toAi(
|
|
375
|
-
content,
|
|
376
|
-
'Goal: Optimize and generate clean, highly informative TypeScript type definitions based ONLY on the provided code and types.\n\n'
|
|
377
|
-
+ 'CRITICAL CONTEXT & SCOPE RESTRICTIONS:\n'
|
|
378
|
-
+ '- IMPORTANT: The AI coding agent that will write code for developers using this library will NEVER see or have access to the underlying JS implementation code or external files. It will rely EXCLUSIVELY on the output document generated by you in this session. You MUST ensure that your output provides complete, flawless context, clear JSDoc explanations, and precise type contracts so that the reading AI agent can write accurate code without making assumptions.\n'
|
|
379
|
-
+ '- Analyze ONLY the code, type definitions, and text explicitly provided in this prompt. Do NOT attempt to read, search, infer, or assume any external files, imports, project structure, or unprovided environment data.\n'
|
|
380
|
-
+ '- Do NOT include any references, links, file paths, or pointers to external files or local directories in the final output, as AI agents will have no environment file access.\n'
|
|
381
|
-
+ '- Do NOT return the provided JS code in your response.\n\n'
|
|
382
|
-
+ 'JSDOC & COMMENT RULES:\n'
|
|
383
|
-
+ '- STUDY THE PROVIDED JS CODE: You are explicitly provided with the JS implementation code (`File JS Code`). You MUST study the JS code for every function/method/property to understand its exact logic, behavior, and purpose.\n'
|
|
384
|
-
+ '- IF AN EXISTING JSDOC / COMMENT IS PRESENT:\n'
|
|
385
|
-
+ ' * Obvious entities (e.g., `isString`, `capitalize`, `copyObject`): DELETE the JSDoc / comment entirely.\n'
|
|
386
|
-
+ ' * Non-obvious entities: OPTIMIZE the existing JSDoc — remove fluff, translate to clear English, and PRESERVE ONLY `@example`, `@remarks`, `@note`, and `@warning` tags (remove all other JSDoc tags).\n'
|
|
387
|
-
+ '- IF NO JSDOC / COMMENT IS PRESENT:\n'
|
|
388
|
-
+ ' * Obvious entities: DO NOTHING (do NOT add any JSDoc).\n'
|
|
389
|
-
+ ' * Moderately non-obvious entities (obscure, custom, abbreviated, or ambiguous naming): Generate and add a SHORT, concise, 1-line English JSDoc description derived from inspecting its JS implementation code.\n'
|
|
390
|
-
+ ' * Very unclear or highly complex entities (intricate operational logic, complex parameters, or subtle side effects): Generate and add a DETAILED, comprehensive English JSDoc description derived from inspecting its JS implementation code.\n'
|
|
391
|
-
+ '- Place all JSDoc comments STRICTLY directly above the target declaration.\n'
|
|
392
|
-
+ '- Translate all non-English comments and JSDocs to English.\n'
|
|
393
|
-
+ '- Remove regular inline comments (`//` or `/* ... */`).\n'
|
|
394
|
-
+ 'CLEANING & OPTIMIZATION:\n'
|
|
395
|
-
+ '- Remove all `import` statements and local internal re-exports (e.g., `export * from "./..."`). Strictly KEEP exports from external packages.\n'
|
|
396
|
-
+ '- Delete all non-public content (private/protected class members, unexported elements). Keep all public API surfaces.\n'
|
|
397
|
-
+ '- Do NOT delete any `type` definitions; they are strictly required.\n'
|
|
398
|
-
+ '- Remove large Enums or structures that add length without critical context.\n'
|
|
399
|
-
+ '- Exercise extreme caution when removing abstract classes: if there is even a 5% chance it helps understand the API or generate code, keep it.\n'
|
|
400
|
-
+ '- Format output tightly with no blank lines.\n\n'
|
|
401
|
-
+ 'OUTPUT REQUIREMENTS:\n'
|
|
402
|
-
+ 'Return ONLY the resulting optimized TypeScript type definitions code. No markdown formatting, no code blocks (```), no explanations, and no additional AI text. NOTHING but pure code.',
|
|
403
|
-
code
|
|
404
|
-
)
|
|
82
|
+
this.makeTypes.makeSave()
|
|
405
83
|
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Generates a project description and usage guidelines using AI.
|
|
411
|
-
*
|
|
412
|
-
* Генерирует описание проекта и рекомендации по использованию с помощью ИИ.
|
|
413
|
-
* @param content cleaned type definitions / очищенные определения типов
|
|
414
|
-
* @param code JS code for analysis / JS код для анализа
|
|
415
|
-
*/
|
|
416
|
-
protected async toAiDescription(content: string, code?: string): Promise<string> {
|
|
417
|
-
const generate = await this.toAi(
|
|
418
|
-
content,
|
|
419
|
-
'Goal: Generate a CONCISE, high-density project overview for an AI coding assistant to evaluate this library\'s core purpose, key module groupings, and triggers for studying type definitions.\n\n'
|
|
420
|
-
+ 'CRITICAL RESTRICTIONS:\n'
|
|
421
|
-
+ '- Keep the output dense, focused, and fluff-free. Avoid bloated descriptions, exhaustive lists of individual methods, classes, or components by name, or repetitive explanations.\n'
|
|
422
|
-
+ '- Always group components, classes, or methods by functional category (e.g. "form components", "navigation controls", "storage utilities") instead of enumerating every individual name.\n'
|
|
423
|
-
+ '- Analyze ONLY the code, type definitions, and text explicitly provided in this prompt. Do NOT assume external unprovided data.\n'
|
|
424
|
-
+ '- Do NOT include file paths, relative links, URLs, or markdown formatting.\n\n'
|
|
425
|
-
+ 'STRUCTURE REQUIREMENTS (Provide a single cohesive text block):\n'
|
|
426
|
-
+ '1. Core Purpose: 1-2 sentences summarizing the library\'s primary technical function and responsibility.\n'
|
|
427
|
-
+ '2. Key Capabilities & Groupings: Group main classes, composables, or components into high-level functional modules (e.g. API/Network, Storage, Localization, Form Components, Layout Controls, Utilities) and summarize their capabilities in tight sentences. Avoid listing individual component or method names—group them by function instead.\n'
|
|
428
|
-
+ '3. Triggers for Studying ai-types.md: Under what specific coding requirements, keywords, tasks, or architectural needs is it mandatory for the AI to study "ai-types.md"?\n'
|
|
429
|
-
+ '4. Integration Context: 1 sentence explaining how this library connects with other stack frameworks or packages.\n\n'
|
|
430
|
-
+ 'OUTPUT REQUIREMENTS:\n'
|
|
431
|
-
+ 'Return ONLY the resulting concise description text. No markdown code blocks (```), no section headers, no labels (like "Description:"), and no conversational fluff.',
|
|
432
|
-
code
|
|
433
|
-
)
|
|
434
|
-
|
|
435
|
-
return generate ?? ''
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Generates project rules and prompt triggers description.
|
|
440
|
-
*
|
|
441
|
-
* Генерирует описание правил проекта и триггеров промптов.
|
|
442
|
-
* @param list list of prompt files / список файлов промптов
|
|
443
|
-
*/
|
|
444
|
-
protected async toAiPrompts(list: DesignTypesList): Promise<string> {
|
|
445
|
-
const projectName = this.getProjectName()
|
|
446
|
-
const prompts: string[] = []
|
|
447
|
-
|
|
448
|
-
for (const item of list) {
|
|
449
|
-
const content = await this.toAiPromptName(item.content)
|
|
450
|
-
|
|
451
|
-
if (isFilled(content)) {
|
|
452
|
-
prompts.push(`- '${UI_MODULES}/${projectName}/${item.path}': ${content}`)
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
if (prompts.length > 0) {
|
|
457
|
-
return '## Mandatory Rules\n'
|
|
458
|
-
+ 'Read the corresponding file ONLY when working on a task related to (even if not working directly with this package):\n'
|
|
459
|
-
+ `${prompts.join('\n')}`
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
return ''
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Generates a trigger description for studying a prompt file using AI.
|
|
467
|
-
*
|
|
468
|
-
* Генерирует описание-триггер для изучения файла промпта с помощью ИИ.
|
|
469
|
-
* @param content prompt file content / содержимое файла промпта
|
|
470
|
-
*/
|
|
471
|
-
protected async toAiPromptName(content: string): Promise<string> {
|
|
472
|
-
const generate = await this.toAi(
|
|
473
|
-
content,
|
|
474
|
-
'Goal: Generate an EXTREMELY SHORT, high-density trigger and topic summary for an AI coding assistant describing what rules/topics are covered AND under what specific tasks, conditions, or use cases this document must be studied.\n\n'
|
|
475
|
-
+ 'CRITICAL RESTRICTIONS:\n'
|
|
476
|
-
+ '- The output MUST be EXTREMELY CONCISE: 1-2 short sentence or clause (maximum 30-35 words).\n'
|
|
477
|
-
+ '- Clearly specify BOTH the key topics/rules AND the specific scenarios, tasks, or triggers when this document must be read.\n'
|
|
478
|
-
+ '- Do NOT include repetitive filler like "you MUST study this document", "in order to follow...", or "when working with...".\n'
|
|
479
|
-
+ '- Analyze ONLY the text explicitly provided in this prompt.\n'
|
|
480
|
-
+ '- Do NOT include file paths, URLs, quotes, or markdown syntax.\n\n'
|
|
481
|
-
+ 'EXAMPLES OF GOOD OUTPUT:\n'
|
|
482
|
-
+ '- "Class structure, typing standards, SSR safety, and primitive utility functions"\n'
|
|
483
|
-
+ '- "HTTP client, storage management, localization formatting, and DOM event helpers"\n'
|
|
484
|
-
+ '- "Implementing or wrapping D1 components, slot/event types, or customizing theme variables"\n\n'
|
|
485
|
-
+ 'OUTPUT REQUIREMENTS:\n'
|
|
486
|
-
+ 'Return ONLY the resulting short trigger and topic summary. No markdown code blocks (```), no labels, no quotes, and no conversational text.'
|
|
487
|
-
)
|
|
488
|
-
|
|
489
|
-
return generate ?? ''
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Generates MCP server resources structure for prompt, type definition, and description files using AI.
|
|
494
|
-
*
|
|
495
|
-
* Генерирует структуру ресурсов MCP-сервера для файлов промптов, определений типов и описаний с помощью ИИ.
|
|
496
|
-
* @param list list of documentation files / список файлов документации
|
|
497
|
-
* @returns object with resources array or undefined / объект со массивом ресурсов или undefined
|
|
498
|
-
*/
|
|
499
|
-
protected async toAiMcpPrompts(list: DesignTypesList): Promise<DesignMcpResources | undefined> {
|
|
500
|
-
const projectName = this.getProjectName()
|
|
501
|
-
const resources: DesignMcpResourceItem[] = []
|
|
502
|
-
|
|
503
|
-
for (const item of list) {
|
|
504
|
-
const data = await this.toAiMcpResources(item.content, item.path)
|
|
505
|
-
|
|
506
|
-
if (
|
|
507
|
-
data?.name
|
|
508
|
-
&& data?.description
|
|
509
|
-
) {
|
|
510
|
-
resources.push({
|
|
511
|
-
uri: `${projectName}/${item.path}`,
|
|
512
|
-
name: `${data.name} (${projectName})`,
|
|
513
|
-
mimeType: data.mimeType ?? 'text/markdown',
|
|
514
|
-
description: data.description
|
|
515
|
-
})
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
if (resources.length > 0) {
|
|
520
|
-
return resources
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
return undefined
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Generates MCP server resource metadata for a prompt document using AI.
|
|
528
|
-
*
|
|
529
|
-
* Генерирует метаданные ресурса MCP-сервера для документа промпта с помощью ИИ.
|
|
530
|
-
* @param content prompt file content / содержимое файла промпта
|
|
531
|
-
* @param file prompt file path or name / путь или имя файла промпта
|
|
532
|
-
* @returns resource metadata object or undefined / объект метаданных ресурса или undefined
|
|
533
|
-
*/
|
|
534
|
-
protected async toAiMcpResources(content: string, file?: string): Promise<Partial<DesignMcpResourceItem> | undefined> {
|
|
535
|
-
const generate = await this.toAi(
|
|
536
|
-
content,
|
|
537
|
-
(file ? `File Name: ${file}\n\n` : '')
|
|
538
|
-
+ 'Goal: Generate an MCP (Model Context Protocol) server resource metadata object in valid JSON format for this prompt document.\n\n'
|
|
539
|
-
+ 'CRITICAL RESTRICTIONS:\n'
|
|
540
|
-
+ '- The output MUST be a valid JSON object with keys: "name", "mimeType", and "description".\n'
|
|
541
|
-
+ '- All text values MUST be strictly in English. Non-English languages are strictly forbidden.\n'
|
|
542
|
-
+ '- "name": A concise, clear English title (2-4 words, e.g. "Coding Standards", "API Reference").\n'
|
|
543
|
-
+ '- "mimeType": Must be strictly "text/markdown".\n'
|
|
544
|
-
+ '- "description": A high-density, professional description strictly in English (1-2 sentences) summarizing what rules, APIs, or architectural conventions are covered in this document.\n'
|
|
545
|
-
+ '- Do NOT include markdown code block wrappers (```json). Return ONLY the raw JSON string.\n\n'
|
|
546
|
-
+ 'EXAMPLES OF GOOD OUTPUT:\n'
|
|
547
|
-
+ '{\n'
|
|
548
|
-
+ ' "name": "Coding Standards",\n'
|
|
549
|
-
+ ' "mimeType": "text/markdown",\n'
|
|
550
|
-
+ ' "description": "Strict architectural conventions and code implementation standards for the product."\n'
|
|
551
|
-
+ '}\n\n'
|
|
552
|
-
+ 'OUTPUT REQUIREMENTS:\n'
|
|
553
|
-
+ 'Return ONLY the JSON object. No explanations, no markdown formatting, no conversational text.'
|
|
554
|
-
)
|
|
555
|
-
|
|
556
|
-
if (generate) {
|
|
557
|
-
try {
|
|
558
|
-
const cleaned = generate.replace(/```json|```/g, '').trim()
|
|
559
|
-
return JSON.parse(cleaned)
|
|
560
|
-
} catch {
|
|
561
|
-
return undefined
|
|
562
|
-
}
|
|
563
|
-
}
|
|
84
|
+
console.log('DesignTypes: AI types saved.')
|
|
564
85
|
|
|
565
|
-
return
|
|
86
|
+
return this
|
|
566
87
|
}
|
|
567
88
|
}
|