@becrafter/prompt-manager 0.1.18 → 0.1.21

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 (70) hide show
  1. package/env.example +4 -8
  2. package/package.json +19 -9
  3. package/packages/resources/tools/cognitive-thinking/README.md +284 -0
  4. package/packages/resources/tools/cognitive-thinking/cognitive-thinking.tool.js +837 -0
  5. package/packages/server/api/admin.routes.js +19 -0
  6. package/packages/server/mcp/mcp.server.js +6 -6
  7. package/packages/server/server.js +6 -4
  8. package/packages/server/services/TerminalService.js +247 -13
  9. package/packages/server/services/WebSocketService.js +15 -5
  10. package/packages/server/toolm/tool-sync.service.js +8 -0
  11. package/packages/server/utils/config.js +24 -6
  12. package/packages/server/utils/util.js +63 -18
  13. package/packages/web/css/{main.3b61356b384d2f11f47f.css → main.196f434e6a88cd448158.css} +10 -0
  14. package/packages/web/css/terminal-fix.css +571 -0
  15. package/packages/web/index.html +1 -1
  16. package/packages/web/{main.77c2c4b553ca3fac223b.js → main.dceff50c7307dda04873.js} +2 -2
  17. package/app/desktop/assets/app.1.png +0 -0
  18. package/app/desktop/assets/app.png +0 -0
  19. package/app/desktop/assets/icons/icon.icns +0 -0
  20. package/app/desktop/assets/icons/icon.ico +0 -0
  21. package/app/desktop/assets/icons/icon.png +0 -0
  22. package/app/desktop/assets/icons/tray.png +0 -0
  23. package/app/desktop/assets/templates/about.html +0 -147
  24. package/app/desktop/assets/tray.1.png +0 -0
  25. package/app/desktop/assets/tray.png +0 -0
  26. package/app/desktop/docs/ASSETS_PLANNING.md +0 -351
  27. package/app/desktop/docs/REFACTORING_SUMMARY.md +0 -205
  28. package/app/desktop/main.js +0 -340
  29. package/app/desktop/package-lock.json +0 -6912
  30. package/app/desktop/package.json +0 -119
  31. package/app/desktop/preload.js +0 -7
  32. package/app/desktop/src/core/error-handler.js +0 -108
  33. package/app/desktop/src/core/event-emitter.js +0 -84
  34. package/app/desktop/src/core/logger.js +0 -130
  35. package/app/desktop/src/core/state-manager.js +0 -125
  36. package/app/desktop/src/services/module-loader.js +0 -330
  37. package/app/desktop/src/services/runtime-manager.js +0 -398
  38. package/app/desktop/src/services/service-manager.js +0 -210
  39. package/app/desktop/src/services/update-manager.js +0 -267
  40. package/app/desktop/src/ui/about-dialog-manager.js +0 -208
  41. package/app/desktop/src/ui/admin-window-manager.js +0 -757
  42. package/app/desktop/src/ui/splash-manager.js +0 -253
  43. package/app/desktop/src/ui/tray-manager.js +0 -186
  44. package/app/desktop/src/utils/icon-manager.js +0 -133
  45. package/app/desktop/src/utils/path-utils.js +0 -58
  46. package/app/desktop/src/utils/resource-paths.js +0 -49
  47. package/app/desktop/src/utils/resource-sync.js +0 -260
  48. package/app/desktop/src/utils/runtime-sync.js +0 -241
  49. package/app/desktop/src/utils/self-check.js +0 -288
  50. package/app/desktop/src/utils/template-renderer.js +0 -284
  51. package/app/desktop/src/utils/version-utils.js +0 -59
  52. package/packages/server/.eslintrc.js +0 -70
  53. package/packages/server/.husky/pre-commit +0 -8
  54. package/packages/server/.husky/pre-push +0 -8
  55. package/packages/server/.prettierrc +0 -14
  56. package/packages/server/dev-server.js +0 -90
  57. package/packages/server/jsdoc.conf.json +0 -39
  58. package/packages/server/package.json +0 -85
  59. package/packages/server/playwright.config.js +0 -62
  60. package/packages/server/scripts/generate-docs.js +0 -300
  61. package/packages/server/tests/e2e/terminal-e2e.test.js +0 -315
  62. package/packages/server/tests/integration/terminal-websocket.test.js +0 -372
  63. package/packages/server/tests/integration/tools.test.js +0 -264
  64. package/packages/server/tests/setup.js +0 -45
  65. package/packages/server/tests/unit/TerminalService.test.js +0 -410
  66. package/packages/server/tests/unit/WebSocketService.test.js +0 -403
  67. package/packages/server/tests/unit/core.test.js +0 -94
  68. package/packages/server/typedoc.json +0 -52
  69. package/packages/server/vitest.config.js +0 -74
  70. /package/packages/web/{main.77c2c4b553ca3fac223b.js.LICENSE.txt → main.dceff50c7307dda04873.js.LICENSE.txt} +0 -0
@@ -1,260 +0,0 @@
1
- /**
2
- * 通用资源同步工具
3
- * 支持将代码中的内容同步到运行环境中
4
- * 支持目录同步、文件同步和基于内容的文件创建
5
- */
6
-
7
- const fs = require('fs').promises;
8
- const path = require('path');
9
- const os = require('os');
10
- const { app } = require('electron');
11
- const PathUtils = require('./path-utils');
12
-
13
- class ResourceSync {
14
- /**
15
- * 检查是否为打包应用
16
- */
17
- static _checkIfPackaged() {
18
- const appPath = app.getAppPath();
19
- const isDev = appPath.includes('node_modules/electron') ||
20
- process.env.NODE_ENV === 'development' ||
21
- process.defaultApp;
22
-
23
- return !isDev && app.isPackaged;
24
- }
25
-
26
- /**
27
- * 获取项目根目录(开发模式)
28
- */
29
- static _getProjectRoot() {
30
- // 从 app/desktop/src/utils -> 项目根目录
31
- return path.resolve(__dirname, '..', '..', '..', '..');
32
- }
33
-
34
- /**
35
- * 获取用户配置根目录
36
- */
37
- static _getUserConfigRoot() {
38
- return path.join(os.homedir(), '.prompt-manager');
39
- }
40
-
41
- /**
42
- * 查找实际存在的源路径
43
- * @param {Object} options - 查找选项
44
- * @param {string|Function} options.devPath - 开发模式下的路径(字符串或返回路径的函数)
45
- * @param {string[]|Function} options.packagedPaths - 打包模式下的可能路径数组(或返回路径数组的函数)
46
- * @returns {Promise<string|null>} 找到的源路径,如果不存在则返回 null
47
- */
48
- static async findSourcePath({ devPath, packagedPaths }) {
49
- const isPackaged = this._checkIfPackaged();
50
-
51
- if (isPackaged) {
52
- // 打包模式
53
- let paths;
54
- if (typeof packagedPaths === 'function') {
55
- paths = packagedPaths();
56
- } else {
57
- paths = packagedPaths || [];
58
- }
59
-
60
- // 尝试每个路径,返回第一个存在的
61
- for (const possiblePath of paths) {
62
- try {
63
- if (await PathUtils.pathExists(possiblePath)) {
64
- return possiblePath;
65
- }
66
- } catch (error) {
67
- // 继续尝试下一个路径
68
- continue;
69
- }
70
- }
71
-
72
- console.warn('在打包模式下未找到源路径,尝试的路径:', paths);
73
- return null;
74
- } else {
75
- // 开发模式
76
- let sourcePath;
77
- if (typeof devPath === 'function') {
78
- sourcePath = devPath();
79
- } else {
80
- sourcePath = devPath;
81
- }
82
-
83
- if (sourcePath && await PathUtils.pathExists(sourcePath)) {
84
- return sourcePath;
85
- }
86
-
87
- console.warn('在开发模式下未找到源路径:', sourcePath);
88
- return null;
89
- }
90
- }
91
-
92
- /**
93
- * 同步目录
94
- * @param {Object} config - 同步配置
95
- * @param {string} config.targetPath - 目标目录路径
96
- * @param {string|Function} config.devPath - 开发模式下的源路径
97
- * @param {string[]|Function} config.packagedPaths - 打包模式下的可能源路径
98
- * @param {boolean} config.skipIfExists - 如果目标已存在则跳过(默认: true)
99
- * @param {string} config.name - 资源名称(用于日志)
100
- * @returns {Promise<Object>} 同步结果
101
- */
102
- static async syncDirectory({
103
- targetPath,
104
- devPath,
105
- packagedPaths,
106
- skipIfExists = true,
107
- name = '目录'
108
- }) {
109
- try {
110
- // 检查目标目录是否已存在
111
- const targetExists = await PathUtils.pathExists(targetPath);
112
- if (targetExists && skipIfExists) {
113
- console.log(`${name}目录已存在,跳过同步: ${targetPath}`);
114
- return { success: true, skipped: true, targetPath };
115
- }
116
-
117
- // 查找源路径
118
- const sourcePath = await this.findSourcePath({ devPath, packagedPaths });
119
-
120
- if (!sourcePath) {
121
- console.warn(`未找到源${name}目录,跳过同步`);
122
- return { success: false, error: `Source ${name} directory not found` };
123
- }
124
-
125
- // 创建目标目录的父目录
126
- await PathUtils.ensureDir(path.dirname(targetPath));
127
-
128
- // 如果目标已存在但不跳过,先删除
129
- if (targetExists && !skipIfExists) {
130
- await PathUtils.safeRemoveDir(targetPath);
131
- }
132
-
133
- // 创建目标目录
134
- await PathUtils.ensureDir(targetPath);
135
- console.log(`已创建${name}目录: ${targetPath}`);
136
-
137
- // 复制目录内容
138
- await PathUtils.copyDir(sourcePath, targetPath);
139
- console.log(`已同步${name}: ${sourcePath} -> ${targetPath}`);
140
-
141
- return {
142
- success: true,
143
- skipped: false,
144
- targetPath,
145
- sourcePath
146
- };
147
- } catch (error) {
148
- console.error(`${name}同步失败:`, error);
149
- return { success: false, error: error.message };
150
- }
151
- }
152
-
153
- /**
154
- * 同步文件(从源文件复制)
155
- * @param {Object} config - 同步配置
156
- * @param {string} config.targetPath - 目标文件路径
157
- * @param {string|Function} config.devPath - 开发模式下的源文件路径
158
- * @param {string[]|Function} config.packagedPaths - 打包模式下的可能源文件路径
159
- * @param {boolean} config.skipIfExists - 如果目标已存在则跳过(默认: true)
160
- * @param {string} config.name - 资源名称(用于日志)
161
- * @returns {Promise<Object>} 同步结果
162
- */
163
- static async syncFile({
164
- targetPath,
165
- devPath,
166
- packagedPaths,
167
- skipIfExists = true,
168
- name = '文件'
169
- }) {
170
- try {
171
- // 检查目标文件是否已存在
172
- const targetExists = await PathUtils.pathExists(targetPath);
173
- if (targetExists && skipIfExists) {
174
- console.log(`${name}文件已存在,跳过同步: ${targetPath}`);
175
- return { success: true, skipped: true, targetPath };
176
- }
177
-
178
- // 查找源路径
179
- const sourcePath = await this.findSourcePath({ devPath, packagedPaths });
180
-
181
- if (!sourcePath) {
182
- console.warn(`未找到源${name}文件,跳过同步`);
183
- return { success: false, error: `Source ${name} file not found` };
184
- }
185
-
186
- // 创建目标文件的父目录
187
- await PathUtils.ensureDir(path.dirname(targetPath));
188
-
189
- // 复制文件
190
- await fs.copyFile(sourcePath, targetPath);
191
- console.log(`已同步${name}文件: ${sourcePath} -> ${targetPath}`);
192
-
193
- return {
194
- success: true,
195
- skipped: false,
196
- targetPath,
197
- sourcePath
198
- };
199
- } catch (error) {
200
- console.error(`${name}文件同步失败:`, error);
201
- return { success: false, error: error.message };
202
- }
203
- }
204
-
205
- /**
206
- * 基于内容创建文件
207
- * @param {Object} config - 同步配置
208
- * @param {string} config.targetPath - 目标文件路径
209
- * @param {string|Function} config.content - 文件内容(字符串或返回内容的函数)
210
- * @param {boolean} config.skipIfExists - 如果目标已存在则跳过(默认: true)
211
- * @param {string} config.name - 资源名称(用于日志)
212
- * @returns {Promise<Object>} 同步结果
213
- */
214
- static async syncContent({
215
- targetPath,
216
- content,
217
- skipIfExists = true,
218
- name = '文件'
219
- }) {
220
- try {
221
- // 检查目标文件是否已存在
222
- const targetExists = await PathUtils.pathExists(targetPath);
223
- if (targetExists && skipIfExists) {
224
- console.log(`${name}文件已存在,跳过创建: ${targetPath}`);
225
- return { success: true, skipped: true, targetPath };
226
- }
227
-
228
- // 获取文件内容
229
- let fileContent;
230
- if (typeof content === 'function') {
231
- fileContent = content();
232
- } else {
233
- fileContent = content;
234
- }
235
-
236
- if (!fileContent) {
237
- return { success: false, error: 'Content is required' };
238
- }
239
-
240
- // 创建目标文件的父目录
241
- await PathUtils.ensureDir(path.dirname(targetPath));
242
-
243
- // 写入文件
244
- await fs.writeFile(targetPath, fileContent, 'utf8');
245
- console.log(`已创建${name}文件: ${targetPath}`);
246
-
247
- return {
248
- success: true,
249
- skipped: false,
250
- targetPath
251
- };
252
- } catch (error) {
253
- console.error(`${name}文件创建失败:`, error);
254
- return { success: false, error: error.message };
255
- }
256
- }
257
- }
258
-
259
- module.exports = ResourceSync;
260
-
@@ -1,241 +0,0 @@
1
- /**
2
- * 运行时环境同步工具
3
- * 负责将打包的 runtime 目录同步到 ~/.prompt-manager 目录
4
- * runtime 目录包含所有运行时需要的资源(toolbox、.env 等)
5
- *
6
- * 优化方案:直接同步整个 runtime 目录内容,避免逐个文件处理
7
- */
8
-
9
- const path = require('path');
10
- const { app } = require('electron');
11
- const ResourceSync = require('./resource-sync');
12
- const PathUtils = require('./path-utils');
13
-
14
- class RuntimeSync {
15
- /**
16
- * 同步运行时环境
17
- * 将 runtime 目录下的所有内容同步到 ~/.prompt-manager 目录
18
- * 支持选择性同步(只同步不存在的文件/目录)
19
- */
20
- static async syncRuntime() {
21
- const configRoot = ResourceSync._getUserConfigRoot();
22
-
23
- // 确保配置目录存在
24
- await PathUtils.ensureDir(configRoot);
25
-
26
- const isPackaged = ResourceSync._checkIfPackaged();
27
-
28
- if (isPackaged) {
29
- // 打包模式:从 runtime 目录同步
30
- return await this._syncFromRuntime(configRoot);
31
- } else {
32
- // 开发模式:从源文件同步(构建 runtime 结构)
33
- return await this._syncFromDev(configRoot);
34
- }
35
- }
36
-
37
- /**
38
- * 从打包的 runtime 目录同步
39
- */
40
- static async _syncFromRuntime(configRoot) {
41
- const resourcesPath = process.resourcesPath;
42
- const possiblePaths = [
43
- path.join(resourcesPath, 'runtime'), // extraResources 中的 runtime(最常见)
44
- path.join(app.getAppPath(), 'runtime'), // 备用路径
45
- ];
46
-
47
- // 查找 runtime 目录
48
- const runtimePath = await ResourceSync.findSourcePath({
49
- devPath: null,
50
- packagedPaths: () => possiblePaths
51
- });
52
-
53
- if (!runtimePath) {
54
- console.warn('未找到 runtime 目录,跳过同步');
55
- return { success: false, error: 'Runtime directory not found' };
56
- }
57
-
58
- // 同步 runtime 目录下的所有内容到 configRoot
59
- // 逐个同步子目录和文件,避免覆盖已存在的文件
60
- const results = await this._syncContents(runtimePath, configRoot);
61
-
62
- return {
63
- success: true,
64
- configRoot,
65
- runtimePath,
66
- results
67
- };
68
- }
69
-
70
- /**
71
- * 从开发环境源文件同步(模拟 runtime 结构)
72
- */
73
- static async _syncFromDev(configRoot) {
74
- const projectRoot = ResourceSync._getProjectRoot();
75
- const results = {};
76
-
77
- // 同步 toolbox(对应 runtime/toolbox)
78
- // 使用递归同步,确保新增的工具能够被同步
79
- const toolboxSource = path.join(projectRoot, 'packages', 'resources', 'tools');
80
- const toolboxTarget = path.join(configRoot, 'toolbox');
81
- if (await PathUtils.pathExists(toolboxSource)) {
82
- const result = await this._syncDirectoryRecursive(toolboxSource, toolboxTarget, 'toolbox');
83
- results.toolbox = result;
84
- }
85
-
86
- // 同步 .env(对应 runtime/.env)
87
- const envSource = path.join(projectRoot, 'env.example');
88
- const envTarget = path.join(configRoot, '.env');
89
- if (await PathUtils.pathExists(envSource)) {
90
- const result = await ResourceSync.syncFile({
91
- targetPath: envTarget,
92
- devPath: () => envSource,
93
- packagedPaths: () => [],
94
- skipIfExists: true,
95
- name: '环境配置'
96
- });
97
- results['.env'] = result;
98
- }
99
-
100
- return {
101
- success: true,
102
- configRoot,
103
- results
104
- };
105
- }
106
-
107
- /**
108
- * 递归同步目录
109
- * 确保新增的子目录和文件能够被同步到运行环境
110
- * @param {string} sourceDir - 源目录路径
111
- * @param {string} targetDir - 目标目录路径
112
- * @param {string} dirName - 目录名称(用于日志)
113
- * @returns {Promise<Object>} 同步结果
114
- */
115
- static async _syncDirectoryRecursive(sourceDir, targetDir, dirName = '目录') {
116
- const fs = require('fs').promises;
117
- const results = {
118
- synced: [],
119
- skipped: [],
120
- errors: []
121
- };
122
-
123
- try {
124
- // 确保目标目录存在
125
- await PathUtils.ensureDir(targetDir);
126
-
127
- // 读取源目录下的所有条目
128
- const entries = await fs.readdir(sourceDir, { withFileTypes: true });
129
-
130
- for (const entry of entries) {
131
- const sourcePath = path.join(sourceDir, entry.name);
132
- const targetPath = path.join(targetDir, entry.name);
133
-
134
- try {
135
- if (entry.isDirectory()) {
136
- // 递归同步子目录
137
- const subResult = await this._syncDirectoryRecursive(sourcePath, targetPath, entry.name);
138
-
139
- // 合并结果
140
- results.synced.push(...subResult.details.synced);
141
- results.skipped.push(...subResult.details.skipped);
142
- results.errors.push(...subResult.details.errors);
143
- } else if (entry.isFile()) {
144
- // 同步文件
145
- const targetExists = await PathUtils.pathExists(targetPath);
146
- let needsSync = !targetExists;
147
-
148
- if (targetExists) {
149
- // 比较文件修改时间
150
- try {
151
- const sourceStat = await fs.stat(sourcePath);
152
- const targetStat = await fs.stat(targetPath);
153
- if (sourceStat.mtime > targetStat.mtime) {
154
- needsSync = true;
155
- }
156
- } catch (statError) {
157
- // 如果无法获取文件状态,默认需要同步
158
- needsSync = true;
159
- }
160
- }
161
-
162
- if (needsSync) {
163
- // 确保目标文件的父目录存在
164
- await PathUtils.ensureDir(path.dirname(targetPath));
165
-
166
- // 复制文件
167
- await fs.copyFile(sourcePath, targetPath);
168
- console.log(`已同步文件: ${entry.name} -> ${targetPath}`);
169
-
170
- results.synced.push(entry.name);
171
- } else {
172
- console.log(`文件已存在且无需更新,跳过: ${entry.name}`);
173
- results.skipped.push({ item: entry.name, reason: '已存在且无需更新' });
174
- }
175
- }
176
- } catch (error) {
177
- console.error(`同步失败: ${entry.name}`, error);
178
- results.errors.push({ item: entry.name, error: error.message });
179
- }
180
- }
181
-
182
- return {
183
- success: results.errors.length === 0,
184
- synced: results.synced.length,
185
- skipped: results.skipped.length,
186
- errors: results.errors.length,
187
- details: results
188
- };
189
- } catch (error) {
190
- console.error(`递归同步 ${dirName} 失败:`, error);
191
- return {
192
- success: false,
193
- error: error.message,
194
- details: results
195
- };
196
- }
197
- }
198
-
199
- /**
200
- * 同步 runtime 目录下的所有内容到目标目录
201
- * 逐个同步子目录和文件,避免覆盖已存在的文件
202
- */
203
- static async _syncContents(runtimePath, configRoot) {
204
- const fs = require('fs').promises;
205
- const results = {};
206
-
207
- try {
208
- // 读取 runtime 目录下的所有条目
209
- const entries = await fs.readdir(runtimePath, { withFileTypes: true });
210
-
211
- for (const entry of entries) {
212
- const sourcePath = path.join(runtimePath, entry.name);
213
- const targetPath = path.join(configRoot, entry.name);
214
-
215
- if (entry.isDirectory()) {
216
- // 所有目录都使用递归同步,确保新增的子目录和文件能够被同步
217
- const result = await this._syncDirectoryRecursive(sourcePath, targetPath, entry.name);
218
- results[entry.name] = result;
219
- } else if (entry.isFile()) {
220
- // 同步文件(如 .env)
221
- const result = await ResourceSync.syncFile({
222
- targetPath,
223
- devPath: () => sourcePath,
224
- packagedPaths: () => [sourcePath],
225
- skipIfExists: true,
226
- name: entry.name
227
- });
228
- results[entry.name] = result;
229
- }
230
- }
231
-
232
- return results;
233
- } catch (error) {
234
- console.error('同步 runtime 内容失败:', error);
235
- throw error;
236
- }
237
- }
238
- }
239
-
240
- module.exports = RuntimeSync;
241
-