@becrafter/prompt-manager 0.1.12 → 0.1.15

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.
Files changed (139) hide show
  1. package/app/desktop/assets/app.1.png +0 -0
  2. package/app/desktop/assets/app.png +0 -0
  3. package/app/desktop/assets/icons/icon.icns +0 -0
  4. package/app/desktop/assets/icons/icon.ico +0 -0
  5. package/app/desktop/assets/icons/icon.png +0 -0
  6. package/app/desktop/assets/icons/tray.png +0 -0
  7. package/app/desktop/assets/templates/about.html +147 -0
  8. package/app/desktop/assets/tray.1.png +0 -0
  9. package/app/desktop/assets/tray.png +0 -0
  10. package/app/desktop/docs/ASSETS_PLANNING.md +351 -0
  11. package/app/desktop/docs/REFACTORING_SUMMARY.md +205 -0
  12. package/app/desktop/main.js +340 -0
  13. package/app/desktop/package-lock.json +6912 -0
  14. package/app/desktop/package.json +119 -0
  15. package/app/desktop/preload.js +7 -0
  16. package/app/desktop/src/core/error-handler.js +108 -0
  17. package/app/desktop/src/core/event-emitter.js +84 -0
  18. package/app/desktop/src/core/logger.js +130 -0
  19. package/app/desktop/src/core/state-manager.js +125 -0
  20. package/app/desktop/src/services/module-loader.js +330 -0
  21. package/app/desktop/src/services/runtime-manager.js +398 -0
  22. package/app/desktop/src/services/service-manager.js +210 -0
  23. package/app/desktop/src/services/update-manager.js +267 -0
  24. package/app/desktop/src/ui/about-dialog-manager.js +208 -0
  25. package/app/desktop/src/ui/admin-window-manager.js +757 -0
  26. package/app/desktop/src/ui/splash-manager.js +253 -0
  27. package/app/desktop/src/ui/tray-manager.js +186 -0
  28. package/app/desktop/src/utils/icon-manager.js +133 -0
  29. package/app/desktop/src/utils/path-utils.js +58 -0
  30. package/app/desktop/src/utils/resource-paths.js +49 -0
  31. package/app/desktop/src/utils/resource-sync.js +260 -0
  32. package/app/desktop/src/utils/runtime-sync.js +241 -0
  33. package/app/desktop/src/utils/self-check.js +288 -0
  34. package/app/desktop/src/utils/template-renderer.js +284 -0
  35. package/app/desktop/src/utils/version-utils.js +59 -0
  36. package/env.example +1 -1
  37. package/examples/prompts/developer/code-review.yaml +32 -0
  38. package/examples/prompts/developer/code_refactoring.yaml +31 -0
  39. package/examples/prompts/developer/doc-generator.yaml +36 -0
  40. package/examples/prompts/developer/error-code-fixer.yaml +35 -0
  41. package/examples/prompts/engineer/engineer-professional.yaml +92 -0
  42. package/examples/prompts/engineer/laowang-engineer.yaml +132 -0
  43. package/examples/prompts/engineer/nekomata-engineer.yaml +123 -0
  44. package/examples/prompts/engineer/ojousama-engineer.yaml +124 -0
  45. package/examples/prompts/generator/gen_3d_edu_webpage_html.yaml +117 -0
  46. package/examples/prompts/generator/gen_3d_webpage_html.yaml +75 -0
  47. package/examples/prompts/generator/gen_bento_grid_html.yaml +112 -0
  48. package/examples/prompts/generator/gen_html_web_page.yaml +88 -0
  49. package/examples/prompts/generator/gen_knowledge_card_html.yaml +83 -0
  50. package/examples/prompts/generator/gen_magazine_card_html.yaml +82 -0
  51. package/examples/prompts/generator/gen_mimeng_headline_title.yaml +71 -0
  52. package/examples/prompts/generator/gen_podcast_script.yaml +69 -0
  53. package/examples/prompts/generator/gen_prd_prototype_html.yaml +175 -0
  54. package/examples/prompts/generator/gen_summarize.yaml +157 -0
  55. package/examples/prompts/generator/gen_title.yaml +119 -0
  56. package/examples/prompts/generator/others/api_documentation.yaml +32 -0
  57. package/examples/prompts/generator/others/build_mcp_server.yaml +26 -0
  58. package/examples/prompts/generator/others/project_architecture.yaml +31 -0
  59. package/examples/prompts/generator/others/test_case_generator.yaml +30 -0
  60. package/examples/prompts/generator/others/writing_assistant.yaml +72 -0
  61. package/examples/prompts/recommend/human_3-0_growth_diagnostic_coach_prompt.yaml +105 -0
  62. package/examples/prompts/workflow/sixstep-workflow.yaml +192 -0
  63. package/package.json +13 -1
  64. package/packages/server/.eslintrc.js +70 -0
  65. package/packages/server/.husky/pre-commit +8 -0
  66. package/packages/server/.husky/pre-push +8 -0
  67. package/packages/server/.prettierrc +14 -0
  68. package/packages/server/dev-server.js +90 -0
  69. package/packages/server/jsdoc.conf.json +39 -0
  70. package/packages/server/playwright.config.js +62 -0
  71. package/packages/server/scripts/generate-docs.js +300 -0
  72. package/packages/server/server.js +1 -0
  73. package/packages/server/services/TerminalService.js +84 -11
  74. package/packages/server/tests/e2e/terminal-e2e.test.js +315 -0
  75. package/packages/server/tests/integration/terminal-websocket.test.js +372 -0
  76. package/packages/server/tests/integration/tools.test.js +264 -0
  77. package/packages/server/tests/setup.js +45 -0
  78. package/packages/server/tests/unit/TerminalService.test.js +410 -0
  79. package/packages/server/tests/unit/WebSocketService.test.js +403 -0
  80. package/packages/server/tests/unit/core.test.js +94 -0
  81. package/packages/server/typedoc.json +52 -0
  82. package/packages/server/utils/config.js +1 -1
  83. package/packages/server/utils/util.js +59 -5
  84. package/packages/server/vitest.config.js +74 -0
  85. package/packages/web/0.d1c5a72339dfc32ad86a.js +1 -0
  86. package/packages/web/112.8807b976372b2b0541a8.js +1 -0
  87. package/packages/web/130.584c7e365da413f5d9be.js +1 -0
  88. package/packages/web/142.72c985bc29720f975cca.js +1 -0
  89. package/packages/web/165.a05fc53bf84d18db36b8.js +2 -0
  90. package/packages/web/165.a05fc53bf84d18db36b8.js.LICENSE.txt +9 -0
  91. package/packages/web/203.724ab9f717b80554c397.js +1 -0
  92. package/packages/web/241.bf941d4f02866795f64a.js +1 -0
  93. package/packages/web/249.54cfb224af63f5f5ec55.js +1 -0
  94. package/packages/web/291.6df35042f8f296fca7cd.js +1 -0
  95. package/packages/web/319.2fab900a31b29873f666.js +1 -0
  96. package/packages/web/32.c78d866281995ec33a7b.js +1 -0
  97. package/packages/web/325.9ca297d0f73f38468ce9.js +1 -0
  98. package/packages/web/366.2f9b48fdbf8eee039e57.js +1 -0
  99. package/packages/web/378.6be08c612cd5a3ef97dc.js +1 -0
  100. package/packages/web/393.7a2f817515c5e90623d7.js +1 -0
  101. package/packages/web/412.062df5f732d5ba203415.js +1 -0
  102. package/packages/web/426.08656fef4918b3fb19ad.js +1 -0
  103. package/packages/web/465.2be8018327130a3bd798.js +1 -0
  104. package/packages/web/48.8ca96fc93667a715e67a.js +1 -0
  105. package/packages/web/480.44c1f1a2927486ac3d4f.js +1 -0
  106. package/packages/web/489.e041a8d0db15dc96d607.js +1 -0
  107. package/packages/web/490.9ffb26c907de020d671b.js +1 -0
  108. package/packages/web/492.58781369e348d91fc06a.js +1 -0
  109. package/packages/web/495.ed63e99791a87167c6b3.js +1 -0
  110. package/packages/web/510.4cc07ab7d30d5c1cd17f.js +1 -0
  111. package/packages/web/543.3af155ed4fa237664308.js +1 -0
  112. package/packages/web/567.f04ab60f8e2c2fb0745a.js +1 -0
  113. package/packages/web/592.f3ad085fa9c1849daa06.js +1 -0
  114. package/packages/web/616.b03fb801b3433b17750f.js +1 -0
  115. package/packages/web/617.d88def54921d2c4dc44c.js +1 -0
  116. package/packages/web/641.d30787d674f548928261.js +1 -0
  117. package/packages/web/672.5269c8399fa42a5af95d.js +1 -0
  118. package/packages/web/731.97cab92b71811c502bda.js +1 -0
  119. package/packages/web/746.3947c6f0235407e420fb.js +1 -0
  120. package/packages/web/756.a53233b3f3913900d5ac.js +1 -0
  121. package/packages/web/77.68801af593a28a631fbf.js +1 -0
  122. package/packages/web/802.53b2bff3cf2a69f7b80c.js +1 -0
  123. package/packages/web/815.b6dfab82265f56c7e046.js +1 -0
  124. package/packages/web/821.f5a13e5c735aac244eb9.js +1 -0
  125. package/packages/web/846.b9bf97d5f559270675ce.js +1 -0
  126. package/packages/web/869.7c10403f500e6201407f.js +1 -0
  127. package/packages/web/885.135050364f99e6924fb5.js +1 -0
  128. package/packages/web/901.fd5aeb9df630609a2b43.js +1 -0
  129. package/packages/web/928.f67e590de3caa4daa3ae.js +1 -0
  130. package/packages/web/955.d833403521ba4dd567ee.js +1 -0
  131. package/packages/web/981.a45cb745cf424044c8c8.js +1 -0
  132. package/packages/web/992.645320b60c74c8787482.js +1 -0
  133. package/packages/web/996.ed9a963dc9e7439eca9a.js +1 -0
  134. package/packages/web/css/codemirror-theme_xq-light.css +43 -0
  135. package/packages/web/css/codemirror.css +344 -0
  136. package/packages/web/css/main.3b61356b384d2f11f47f.css +7268 -0
  137. package/packages/web/index.html +3 -0
  138. package/packages/web/main.77c2c4b553ca3fac223b.js +2 -0
  139. package/packages/web/main.77c2c4b553ca3fac223b.js.LICENSE.txt +3 -0
@@ -0,0 +1,288 @@
1
+ const fs = require('fs/promises');
2
+ const path = require('path');
3
+ const { app } = require('electron');
4
+
5
+ /**
6
+ * 应用启动自检功能
7
+ * 在应用启动时检查关键资源和环境配置
8
+ */
9
+ class SelfCheck {
10
+ constructor(logger) {
11
+ this.logger = logger;
12
+ this.checkResults = [];
13
+ }
14
+
15
+ /**
16
+ * 运行所有自检项目
17
+ * @returns {Promise<boolean>} - 是否所有检查都通过
18
+ */
19
+ async run() {
20
+ this.logger.info('Running application self-check...');
21
+
22
+ const checks = [
23
+ this.checkAppResources(),
24
+ this.checkRuntimeDirectory(),
25
+ this.checkPortAvailability(),
26
+ this.checkDependencies(),
27
+ this.checkSystemTools()
28
+ ];
29
+
30
+ const results = await Promise.allSettled(checks);
31
+
32
+ // 记录检查结果
33
+ results.forEach((result, index) => {
34
+ if (result.status === 'fulfilled') {
35
+ this.checkResults.push({
36
+ name: this.getCheckName(index),
37
+ status: 'passed',
38
+ message: result.value
39
+ });
40
+ this.logger.debug(`Self-check passed: ${this.getCheckName(index)}`);
41
+ } else {
42
+ this.checkResults.push({
43
+ name: this.getCheckName(index),
44
+ status: 'failed',
45
+ message: result.reason?.message || 'Unknown error',
46
+ error: result.reason
47
+ });
48
+ this.logger.warn(`Self-check failed: ${this.getCheckName(index)}`, {
49
+ error: result.reason?.message
50
+ });
51
+ }
52
+ });
53
+
54
+ const passedCount = this.checkResults.filter(r => r.status === 'passed').length;
55
+ const totalCount = this.checkResults.length;
56
+
57
+ this.logger.info(`Self-check completed: ${passedCount}/${totalCount} checks passed`);
58
+
59
+ // 输出详细结果
60
+ if (this.checkResults.some(r => r.status === 'failed')) {
61
+ this.logger.warn('Self-check found potential issues:', {
62
+ results: this.checkResults
63
+ });
64
+ }
65
+
66
+ return passedCount === totalCount;
67
+ }
68
+
69
+ /**
70
+ * 获取检查项目名称
71
+ */
72
+ getCheckName(index) {
73
+ const names = [
74
+ 'App Resources',
75
+ 'Runtime Directory',
76
+ 'Port Availability',
77
+ 'Dependencies',
78
+ 'System Tools'
79
+ ];
80
+ return names[index] || `Check ${index + 1}`;
81
+ }
82
+
83
+ /**
84
+ * 检查应用资源文件
85
+ */
86
+ async checkAppResources() {
87
+ const resourcesPath = process.resourcesPath;
88
+ const appAsarPath = path.join(resourcesPath, 'app.asar');
89
+
90
+ try {
91
+ await fs.access(appAsarPath);
92
+ return 'ASAR file found and accessible';
93
+ } catch (error) {
94
+ throw new Error(`ASAR file not found or inaccessible at ${appAsarPath}: ${error.message}`);
95
+ }
96
+ }
97
+
98
+ /**
99
+ * 检查运行时目录
100
+ */
101
+ async checkRuntimeDirectory() {
102
+ const runtimeRoot = path.join(app.getPath('userData'), 'prompt-manager');
103
+
104
+ try {
105
+ await fs.mkdir(runtimeRoot, { recursive: true });
106
+
107
+ // 检查目录权限
108
+ const testFile = path.join(runtimeRoot, '.test-write');
109
+ await fs.writeFile(testFile, 'test');
110
+ await fs.unlink(testFile);
111
+
112
+ return `Runtime directory created and writable: ${runtimeRoot}`;
113
+ } catch (error) {
114
+ throw new Error(`Failed to create or write to runtime directory: ${error.message}`);
115
+ }
116
+ }
117
+
118
+ /**
119
+ * 检查端口可用性
120
+ */
121
+ async checkPortAvailability() {
122
+ return new Promise((resolve, reject) => {
123
+ const net = require('net');
124
+ const server = net.createServer();
125
+
126
+ // 设置超时
127
+ const timeout = setTimeout(() => {
128
+ server.close();
129
+ reject(new Error('Port check timeout'));
130
+ }, 3000);
131
+
132
+ server.listen(5621, () => {
133
+ clearTimeout(timeout);
134
+ server.close();
135
+ resolve('Port 5621 is available');
136
+ });
137
+
138
+ server.on('error', (error) => {
139
+ clearTimeout(timeout);
140
+ if (error.code === 'EADDRINUSE') {
141
+ reject(new Error('Port 5621 is already in use'));
142
+ } else {
143
+ reject(new Error(`Port check failed: ${error.message}`));
144
+ }
145
+ });
146
+ });
147
+ }
148
+
149
+ /**
150
+ * 检查依赖项
151
+ */
152
+ async checkDependencies() {
153
+ // 检查关键依赖是否存在
154
+ const criticalDeps = [
155
+ '@becrafter/prompt-manager-core',
156
+ '@modelcontextprotocol/sdk',
157
+ 'express',
158
+ 'cors',
159
+ 'ws'
160
+ ];
161
+
162
+ const missingDeps = [];
163
+
164
+ for (const dep of criticalDeps) {
165
+ try {
166
+ // 尝试动态导入依赖
167
+ if (dep === '@becrafter/prompt-manager-core') {
168
+ // 特殊处理核心包
169
+ const corePath = path.join(process.resourcesPath, 'app.asar', 'node_modules', dep, 'index.js');
170
+ if (await this._pathExists(corePath)) {
171
+ continue;
172
+ }
173
+ }
174
+
175
+ // 尝试使用 require(CommonJS)或 import(ESM)
176
+ try {
177
+ require(dep);
178
+ } catch (requireError) {
179
+ if (requireError.code === 'MODULE_NOT_FOUND') {
180
+ // 尝试其他方式
181
+ try {
182
+ await import(dep);
183
+ } catch (importError) {
184
+ if (importError.code === 'ERR_MODULE_NOT_FOUND') {
185
+ missingDeps.push(dep);
186
+ }
187
+ }
188
+ }
189
+ }
190
+ } catch (error) {
191
+ // 忽略检查错误,依赖可能在运行时才加载
192
+ this.logger.debug(`Dependency check for ${dep} failed:`, { error: error.message });
193
+ }
194
+ }
195
+
196
+ if (missingDeps.length > 0) {
197
+ this.logger.warn(`Missing critical dependencies: ${missingDeps.join(', ')}`);
198
+ return `Some dependencies may be missing: ${missingDeps.join(', ')}`;
199
+ }
200
+
201
+ return 'All critical dependencies appear to be available';
202
+ }
203
+
204
+ /**
205
+ * 检查文件或目录是否存在
206
+ */
207
+ async _pathExists(targetPath) {
208
+ try {
209
+ await fs.access(targetPath);
210
+ return true;
211
+ } catch (error) {
212
+ return false;
213
+ }
214
+ }
215
+
216
+ /**
217
+ * 检查系统工具
218
+ */
219
+ async checkSystemTools() {
220
+ const runtimeRoot = path.join(app.getPath('userData'), 'prompt-manager');
221
+ const toolsDir = path.join(runtimeRoot, 'tools');
222
+
223
+ try {
224
+ await fs.mkdir(toolsDir, { recursive: true });
225
+
226
+ // 检查工具目录结构
227
+ const expectedDirs = ['chrome-devtools', 'file-reader', 'filesystem', 'ollama-remote', 'pdf-reader', 'playwright', 'todolist'];
228
+ const missingDirs = [];
229
+
230
+ for (const dir of expectedDirs) {
231
+ const dirPath = path.join(toolsDir, dir);
232
+ try {
233
+ await fs.access(dirPath);
234
+ } catch {
235
+ missingDirs.push(dir);
236
+ }
237
+ }
238
+
239
+ if (missingDirs.length > 0) {
240
+ return `System tools directory created, but some subdirectories are missing: ${missingDirs.join(', ')}`;
241
+ }
242
+
243
+ return 'System tools directory structure is complete';
244
+ } catch (error) {
245
+ throw new Error(`Failed to check system tools: ${error.message}`);
246
+ }
247
+ }
248
+
249
+ /**
250
+ * 获取检查结果摘要
251
+ */
252
+ getSummary() {
253
+ const passed = this.checkResults.filter(r => r.status === 'passed').length;
254
+ const failed = this.checkResults.filter(r => r.status === 'failed').length;
255
+ const total = this.checkResults.length;
256
+
257
+ return {
258
+ passed,
259
+ failed,
260
+ total,
261
+ percentage: total > 0 ? Math.round((passed / total) * 100) : 0,
262
+ results: this.checkResults
263
+ };
264
+ }
265
+
266
+ /**
267
+ * 获取详细的检查报告
268
+ */
269
+ getReport() {
270
+ const summary = this.getSummary();
271
+
272
+ let report = `=== Application Self-Check Report ===\n`;
273
+ report += `Overall: ${summary.passed}/${summary.total} passed (${summary.percentage}%)\n\n`;
274
+
275
+ this.checkResults.forEach((result, index) => {
276
+ report += `${index + 1}. ${result.name}: ${result.status.toUpperCase()}\n`;
277
+ report += ` Message: ${result.message}\n`;
278
+ if (result.status === 'failed' && result.error) {
279
+ report += ` Error: ${result.error}\n`;
280
+ }
281
+ report += '\n';
282
+ });
283
+
284
+ return report;
285
+ }
286
+ }
287
+
288
+ module.exports = SelfCheck;
@@ -0,0 +1,284 @@
1
+ /**
2
+ * 模板渲染器
3
+ * 提供HTML模板渲染功能
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+
9
+ class TemplateRenderer {
10
+ constructor(templatesDir = null) {
11
+ this.templatesDir = templatesDir || path.join(__dirname, '..', '..', 'assets', 'templates');
12
+ this.templates = new Map();
13
+ this.loadTemplates();
14
+ }
15
+
16
+ /**
17
+ * 加载所有模板文件
18
+ */
19
+ loadTemplates() {
20
+ try {
21
+ if (!fs.existsSync(this.templatesDir)) {
22
+ this.logger?.warn('Templates directory not found', { dir: this.templatesDir });
23
+ return;
24
+ }
25
+
26
+ const templateFiles = fs.readdirSync(this.templatesDir);
27
+
28
+ templateFiles.forEach(file => {
29
+ if (file.endsWith('.html')) {
30
+ const templateName = path.basename(file, '.html');
31
+ const templatePath = path.join(this.templatesDir, file);
32
+
33
+ try {
34
+ const content = fs.readFileSync(templatePath, 'utf8');
35
+ this.templates.set(templateName, content);
36
+ } catch (error) {
37
+ console.error(`Failed to load template ${templateName}:`, error);
38
+ }
39
+ }
40
+ });
41
+ } catch (error) {
42
+ console.error('Failed to load templates:', error);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * 渲染模板
48
+ * @param {string} templateName - 模板名称
49
+ * @param {object} data - 渲染数据
50
+ * @returns {string} - 渲染后的HTML
51
+ */
52
+ render(templateName, data = {}) {
53
+ let template = this.templates.get(templateName);
54
+
55
+ if (!template) {
56
+ // 如果没有找到模板,返回基本HTML
57
+ return this.renderBasicHTML(templateName, data);
58
+ }
59
+
60
+ try {
61
+ // 处理条件语句
62
+ template = this.processConditionals(template, data);
63
+
64
+ // 处理变量替换
65
+ template = this.processVariables(template, data);
66
+
67
+ // 处理logo数据
68
+ template = this.processLogoData(template, data);
69
+
70
+ return template;
71
+ } catch (error) {
72
+ console.error(`Template rendering failed for ${templateName}:`, error);
73
+ return this.renderBasicHTML(templateName, data);
74
+ }
75
+ }
76
+
77
+ /**
78
+ * 处理条件语句 {{#if condition}}...{{/if}}
79
+ */
80
+ processConditionals(template, data) {
81
+ const ifRegex = /\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g;
82
+
83
+ return template.replace(ifRegex, (match, condition, content) => {
84
+ return data[condition] ? content : '';
85
+ });
86
+ }
87
+
88
+ /**
89
+ * 处理变量替换 {{variable}}
90
+ */
91
+ processVariables(template, data) {
92
+ const varRegex = /\{\{(\w+)\}\}/g;
93
+
94
+ return template.replace(varRegex, (match, variable) => {
95
+ return data[variable] !== undefined ? String(data[variable]) : '';
96
+ });
97
+ }
98
+
99
+ /**
100
+ * 处理logo数据
101
+ */
102
+ processLogoData(template, data) {
103
+ if (data.logoData) {
104
+ template = template.replace(/\{\{logoData\}\}/g, data.logoData);
105
+ }
106
+ return template;
107
+ }
108
+
109
+ /**
110
+ * 渲染基本HTML(备用方案)
111
+ */
112
+ renderBasicHTML(templateName, data) {
113
+ const basicTemplates = {
114
+ about: this.getBasicAboutHTML(data),
115
+ error: this.getBasicErrorHTML(data)
116
+ };
117
+
118
+ return basicTemplates[templateName] || this.getBasicFallbackHTML(data);
119
+ }
120
+
121
+ /**
122
+ * 基本关于页面HTML
123
+ */
124
+ getBasicAboutHTML(data) {
125
+ return `<!DOCTYPE html>
126
+ <html>
127
+ <head>
128
+ <meta charset="UTF-8">
129
+ <title>关于 Prompt Manager</title>
130
+ <style>
131
+ body {
132
+ margin: 0;
133
+ padding: 20px;
134
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
135
+ background: #f5f5f5;
136
+ color: #333;
137
+ }
138
+ .container {
139
+ background: white;
140
+ border-radius: 8px;
141
+ padding: 20px;
142
+ max-width: 300px;
143
+ margin: 0 auto;
144
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
145
+ }
146
+ .title {
147
+ text-align: center;
148
+ font-size: 18px;
149
+ font-weight: bold;
150
+ margin-bottom: 15px;
151
+ }
152
+ .info-item {
153
+ display: flex;
154
+ justify-content: space-between;
155
+ margin-bottom: 8px;
156
+ font-size: 14px;
157
+ }
158
+ .label {
159
+ color: #666;
160
+ }
161
+ .value {
162
+ color: #333;
163
+ font-weight: 500;
164
+ }
165
+ .hint {
166
+ text-align: center;
167
+ font-size: 12px;
168
+ color: #999;
169
+ margin-top: 15px;
170
+ font-style: italic;
171
+ }
172
+ </style>
173
+ </head>
174
+ <body>
175
+ <div class="container">
176
+ <div class="title">Prompt Manager</div>
177
+ <div class="info-item">
178
+ <span class="label">服务版本:</span>
179
+ <span class="value">${data.version || 'unknown'}</span>
180
+ </div>
181
+ <div class="info-item">
182
+ <span class="label">Electron:</span>
183
+ <span class="value">${data.electronVersion || 'unknown'}</span>
184
+ </div>
185
+ <div class="info-item">
186
+ <span class="label">Node.js:</span>
187
+ <span class="value">${data.nodeVersion || 'unknown'}</span>
188
+ </div>
189
+ ${data.debugLogEnabled ? '<div class="hint">调试日志已开启</div>' : ''}
190
+ <div class="hint">连续点击此窗口 ${data.clickCount || 3} 次可${data.debugLogEnabled ? '关闭' : '开启'}调试日志</div>
191
+ </div>
192
+ </body>
193
+ </html>`;
194
+ }
195
+
196
+ /**
197
+ * 基本错误页面HTML
198
+ */
199
+ getBasicErrorHTML(data) {
200
+ return `<!DOCTYPE html>
201
+ <html>
202
+ <head>
203
+ <meta charset="UTF-8">
204
+ <title>错误 - Prompt Manager</title>
205
+ <style>
206
+ body {
207
+ margin: 0;
208
+ padding: 20px;
209
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
210
+ background: #fff5f5;
211
+ color: #c53030;
212
+ }
213
+ .container {
214
+ background: white;
215
+ border-radius: 8px;
216
+ padding: 20px;
217
+ max-width: 400px;
218
+ margin: 0 auto;
219
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
220
+ text-align: center;
221
+ }
222
+ .error-title {
223
+ font-size: 18px;
224
+ font-weight: bold;
225
+ margin-bottom: 10px;
226
+ }
227
+ .error-message {
228
+ font-size: 14px;
229
+ color: #666;
230
+ }
231
+ </style>
232
+ </head>
233
+ <body>
234
+ <div class="container">
235
+ <div class="error-title">发生错误</div>
236
+ <div class="error-message">${data.message || '未知错误'}</div>
237
+ </div>
238
+ </body>
239
+ </html>`;
240
+ }
241
+
242
+ /**
243
+ * 基本备用HTML
244
+ */
245
+ getBasicFallbackHTML(data) {
246
+ return `<!DOCTYPE html>
247
+ <html>
248
+ <head>
249
+ <meta charset="UTF-8">
250
+ <title>Prompt Manager</title>
251
+ </head>
252
+ <body>
253
+ <h1>Prompt Manager</h1>
254
+ <p>版本: ${data.version || 'unknown'}</p>
255
+ <p>Electron: ${data.electronVersion || 'unknown'}</p>
256
+ <p>Node.js: ${data.nodeVersion || 'unknown'}</p>
257
+ </body>
258
+ </html>`;
259
+ }
260
+
261
+ /**
262
+ * 获取可用模板列表
263
+ */
264
+ getAvailableTemplates() {
265
+ return Array.from(this.templates.keys());
266
+ }
267
+
268
+ /**
269
+ * 检查模板是否存在
270
+ */
271
+ hasTemplate(templateName) {
272
+ return this.templates.has(templateName);
273
+ }
274
+
275
+ /**
276
+ * 重新加载模板
277
+ */
278
+ reloadTemplates() {
279
+ this.templates.clear();
280
+ this.loadTemplates();
281
+ }
282
+ }
283
+
284
+ module.exports = TemplateRenderer;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * 版本比较工具
3
+ * 提供版本号比较功能
4
+ */
5
+
6
+ class VersionUtils {
7
+ /**
8
+ * 比较两个版本号
9
+ * @param {string} versionA - 版本A
10
+ * @param {string} versionB - 版本B
11
+ * @returns {number} - 如果A>B返回正数,A<B返回负数,相等返回0
12
+ */
13
+ static compareVersions(a, b) {
14
+ const toNumbers = (value = '') => value.split('.').map((part) => parseInt(part, 10) || 0);
15
+ const [a1, a2, a3] = toNumbers(a);
16
+ const [b1, b2, b3] = toNumbers(b);
17
+
18
+ if (a1 !== b1) return a1 - b1;
19
+ if (a2 !== b2) return a2 - b2;
20
+ return a3 - b3;
21
+ }
22
+
23
+ /**
24
+ * 检查版本是否为有效格式
25
+ * @param {string} version - 版本号
26
+ * @returns {boolean} - 是否有效
27
+ */
28
+ static isValidVersion(version) {
29
+ if (!version || typeof version !== 'string') return false;
30
+ return /^\d+\.\d+\.\d+$/.test(version);
31
+ }
32
+
33
+ /**
34
+ * 解析版本号
35
+ * @param {string} version - 版本号
36
+ * @returns {object} - 解析后的版本对象
37
+ */
38
+ static parseVersion(version) {
39
+ if (!this.isValidVersion(version)) {
40
+ throw new Error(`Invalid version format: ${version}`);
41
+ }
42
+
43
+ const [major, minor, patch] = version.split('.').map(Number);
44
+ return { major, minor, patch };
45
+ }
46
+
47
+ /**
48
+ * 格式化版本号
49
+ * @param {number} major - 主版本号
50
+ * @param {number} minor - 次版本号
51
+ * @param {number} patch - 修订版本号
52
+ * @returns {string} - 格式化后的版本号
53
+ */
54
+ static formatVersion(major, minor, patch) {
55
+ return `${major}.${minor}.${patch}`;
56
+ }
57
+ }
58
+
59
+ module.exports = VersionUtils;
package/env.example CHANGED
@@ -7,7 +7,7 @@ PROMPTS_DIR=$HOME/.prompt-manager/prompts
7
7
 
8
8
  # MCP服务器配置
9
9
  MCP_SERVER_NAME=prompt-manager
10
- MCP_SERVER_VERSION=0.1.12
10
+ MCP_SERVER_VERSION=0.1.15
11
11
 
12
12
  # 日志级别 (error, warn, info, debug)
13
13
  LOG_LEVEL=info
@@ -0,0 +1,32 @@
1
+ name: code-review
2
+ description: 帮助进行代码审查的AI助手
3
+ messages:
4
+ - role: user
5
+ content:
6
+ text: |
7
+ 你是一个专业的代码审查助手。请审查以下代码:
8
+
9
+ 代码语言: {{language}}
10
+ 代码内容:
11
+ ```
12
+ {{code}}
13
+ ```
14
+
15
+ 请从以下几个方面进行审查:
16
+ 1. 代码质量和可读性
17
+ 2. 潜在的安全问题
18
+ 3. 性能优化建议
19
+ 4. 最佳实践建议
20
+ 5. 潜在的bug
21
+
22
+ 请提供具体的改进建议和示例代码。
23
+ arguments:
24
+ - name: language
25
+ description: 编程语言
26
+ type: string
27
+ required: true
28
+ - name: code
29
+ description: 要审查的代码
30
+ type: string
31
+ required: true
32
+ enabled: false
@@ -0,0 +1,31 @@
1
+ name: code_refactoring
2
+ description: 当用户想要重构代码时,可以使用这个提示词,来帮助用户提高代码质量和可维护性
3
+ arguments:
4
+ - name: language
5
+ description: 编程语言
6
+ required: true
7
+ - name: code
8
+ description: 要重构的代码
9
+ required: true
10
+ - name: focus_areas
11
+ description: 重点关注的重构领域(如性能、可读性、模块化等)
12
+ required: false
13
+ messages:
14
+ - role: user
15
+ content:
16
+ type: text
17
+ text: |
18
+ 请对以下{{language}}代码进行重构,以提高其质量和可维护性:
19
+
20
+ ```{{language}}
21
+ {{code}}
22
+ ```
23
+
24
+ {{#focus_areas}}
25
+ 重点关注以下方面:{{focus_areas}}
26
+ {{/focus_areas}}
27
+
28
+ 请提供:
29
+ 1. 重构后的完整代码
30
+ 2. 详细说明您所做的每项更改及其理由
31
+ 3. 重构如何改进了代码的质量和可维护性