codexmate 0.0.29 → 0.0.30

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 (143) hide show
  1. package/README.md +421 -421
  2. package/README.zh.md +354 -354
  3. package/cli/agents-files.js +224 -224
  4. package/cli/archive-helpers.js +446 -446
  5. package/cli/auth-profiles.js +375 -375
  6. package/cli/builtin-proxy.js +1725 -1725
  7. package/cli/claude-proxy.js +1022 -1022
  8. package/cli/config-bootstrap.js +402 -384
  9. package/cli/config-health.js +454 -338
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/local-bridge.js +324 -0
  13. package/cli/openai-bridge.js +1653 -1576
  14. package/cli/openclaw-config.js +629 -629
  15. package/cli/session-convert-args.js +65 -65
  16. package/cli/session-convert-io.js +82 -82
  17. package/cli/session-convert.js +43 -43
  18. package/cli/session-usage.concurrent.js +28 -28
  19. package/cli/session-usage.js +118 -118
  20. package/cli/session-usage.models.js +176 -176
  21. package/cli/skills.js +1141 -1141
  22. package/cli/zip-commands.js +510 -510
  23. package/cli.js +15481 -15340
  24. package/lib/automation.js +404 -404
  25. package/lib/cli-file-utils.js +151 -151
  26. package/lib/cli-models-utils.js +440 -440
  27. package/lib/cli-network-utils.js +190 -190
  28. package/lib/cli-path-utils.js +85 -85
  29. package/lib/cli-session-utils.js +121 -121
  30. package/lib/cli-sessions.js +417 -417
  31. package/lib/cli-utils.js +155 -155
  32. package/lib/cli-webhook.js +126 -126
  33. package/lib/download-artifacts.js +92 -92
  34. package/lib/mcp-stdio.js +453 -453
  35. package/lib/task-orchestrator.js +869 -869
  36. package/lib/text-diff.js +303 -303
  37. package/lib/workflow-engine.js +340 -340
  38. package/package.json +76 -76
  39. package/plugins/README.md +20 -20
  40. package/plugins/README.zh-CN.md +20 -20
  41. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  42. package/plugins/prompt-templates/computed.mjs +253 -253
  43. package/plugins/prompt-templates/index.mjs +8 -8
  44. package/plugins/prompt-templates/manifest.mjs +15 -15
  45. package/plugins/prompt-templates/methods.mjs +553 -553
  46. package/plugins/prompt-templates/overview.mjs +91 -91
  47. package/plugins/prompt-templates/ownership.mjs +19 -19
  48. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  49. package/plugins/prompt-templates/storage.mjs +64 -64
  50. package/plugins/registry.mjs +16 -16
  51. package/web-ui/app.js +645 -639
  52. package/web-ui/index.html +36 -36
  53. package/web-ui/logic.agents-diff.mjs +386 -386
  54. package/web-ui/logic.claude.mjs +168 -168
  55. package/web-ui/logic.codex.mjs +69 -69
  56. package/web-ui/logic.mjs +5 -5
  57. package/web-ui/logic.runtime.mjs +128 -128
  58. package/web-ui/logic.session-convert.mjs +70 -70
  59. package/web-ui/logic.sessions.mjs +765 -765
  60. package/web-ui/modules/api.mjs +90 -90
  61. package/web-ui/modules/app.computed.dashboard.mjs +248 -225
  62. package/web-ui/modules/app.computed.index.mjs +17 -17
  63. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  64. package/web-ui/modules/app.computed.session.mjs +999 -999
  65. package/web-ui/modules/app.constants.mjs +15 -15
  66. package/web-ui/modules/app.methods.agents.mjs +632 -632
  67. package/web-ui/modules/app.methods.claude-config.mjs +200 -200
  68. package/web-ui/modules/app.methods.codex-config.mjs +917 -892
  69. package/web-ui/modules/app.methods.index.mjs +94 -94
  70. package/web-ui/modules/app.methods.install.mjs +205 -205
  71. package/web-ui/modules/app.methods.navigation.mjs +774 -761
  72. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  73. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  74. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  75. package/web-ui/modules/app.methods.providers.mjs +529 -493
  76. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  77. package/web-ui/modules/app.methods.session-actions.mjs +593 -593
  78. package/web-ui/modules/app.methods.session-browser.mjs +984 -984
  79. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  80. package/web-ui/modules/app.methods.session-trash.mjs +438 -438
  81. package/web-ui/modules/app.methods.startup-claude.mjs +534 -533
  82. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  83. package/web-ui/modules/app.methods.webhook.mjs +79 -79
  84. package/web-ui/modules/config-mode.computed.mjs +124 -124
  85. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  86. package/web-ui/modules/i18n.dict.mjs +3146 -3131
  87. package/web-ui/modules/i18n.mjs +62 -62
  88. package/web-ui/modules/plugins.computed.mjs +3 -3
  89. package/web-ui/modules/plugins.methods.mjs +3 -3
  90. package/web-ui/modules/plugins.storage.mjs +11 -11
  91. package/web-ui/modules/provider-url-display.mjs +17 -17
  92. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  93. package/web-ui/modules/skills.computed.mjs +107 -107
  94. package/web-ui/modules/skills.methods.mjs +482 -481
  95. package/web-ui/partials/index/layout-footer.html +13 -13
  96. package/web-ui/partials/index/layout-header.html +500 -500
  97. package/web-ui/partials/index/modal-config-template-agents.html +174 -174
  98. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  99. package/web-ui/partials/index/modal-health-check.html +45 -45
  100. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  101. package/web-ui/partials/index/modal-skills.html +200 -200
  102. package/web-ui/partials/index/modals-basic.html +162 -162
  103. package/web-ui/partials/index/panel-config-claude.html +194 -194
  104. package/web-ui/partials/index/panel-config-codex.html +337 -323
  105. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  106. package/web-ui/partials/index/panel-dashboard.html +219 -186
  107. package/web-ui/partials/index/panel-docs.html +147 -147
  108. package/web-ui/partials/index/panel-market.html +177 -177
  109. package/web-ui/partials/index/panel-orchestration.html +391 -391
  110. package/web-ui/partials/index/panel-plugins.html +253 -253
  111. package/web-ui/partials/index/panel-sessions.html +308 -316
  112. package/web-ui/partials/index/panel-settings.html +190 -190
  113. package/web-ui/partials/index/panel-trash.html +88 -88
  114. package/web-ui/partials/index/panel-usage.html +371 -371
  115. package/web-ui/res/json5.min.js +1 -1
  116. package/web-ui/res/vue.global.prod.js +13 -13
  117. package/web-ui/session-helpers.mjs +594 -576
  118. package/web-ui/source-bundle.cjs +233 -233
  119. package/web-ui/styles/base-theme.css +281 -281
  120. package/web-ui/styles/controls-forms.css +422 -422
  121. package/web-ui/styles/dashboard.css +406 -274
  122. package/web-ui/styles/docs-panel.css +271 -271
  123. package/web-ui/styles/feedback.css +108 -108
  124. package/web-ui/styles/health-check-dialog.css +144 -144
  125. package/web-ui/styles/layout-shell.css +626 -626
  126. package/web-ui/styles/modals-core.css +466 -466
  127. package/web-ui/styles/navigation-panels.css +391 -391
  128. package/web-ui/styles/openclaw-structured.css +266 -266
  129. package/web-ui/styles/plugins-panel.css +564 -523
  130. package/web-ui/styles/responsive.css +454 -454
  131. package/web-ui/styles/sessions-list.css +417 -419
  132. package/web-ui/styles/sessions-preview.css +407 -411
  133. package/web-ui/styles/sessions-toolbar-trash.css +334 -330
  134. package/web-ui/styles/sessions-usage.css +1040 -1040
  135. package/web-ui/styles/settings-panel.css +349 -349
  136. package/web-ui/styles/skills-list.css +305 -303
  137. package/web-ui/styles/skills-market.css +429 -406
  138. package/web-ui/styles/task-orchestration.css +822 -822
  139. package/web-ui/styles/titles-cards.css +472 -472
  140. package/web-ui/styles/trash-panel.css +90 -90
  141. package/web-ui/styles/webhook.css +81 -81
  142. package/web-ui/styles.css +23 -23
  143. package/web-ui.html +17 -17
@@ -1,481 +1,482 @@
1
- function createUnsupportedSkillsTargetAppError(app) {
2
- return new Error(`Unsupported skills target app: ${String(app)}`);
3
- }
4
-
5
- function showUnsupportedSkillsTargetMessage(vm, app) {
6
- vm.showMessage(`不支持的 Skills 安装目标:${String(app)}`, 'error');
7
- }
8
-
9
- export function createSkillsMethods({ api }) {
10
- return {
11
- normalizeSkillsTargetApp(app) {
12
- if (app == null) {
13
- return 'codex';
14
- }
15
- if (app === 'codex' || app === 'claude') {
16
- return app;
17
- }
18
- throw createUnsupportedSkillsTargetAppError(app);
19
- },
20
-
21
- resetSkillsTargetState() {
22
- this.skillsSelectedNames = [];
23
- this.skillsKeyword = '';
24
- this.skillsStatusFilter = 'all';
25
- this.skillsRootPath = '';
26
- this.skillsList = [];
27
- this.skillsImportList = [];
28
- this.skillsImportSelectedKeys = [];
29
- this.skillsMarketLocalLoadedOnce = false;
30
- this.skillsMarketImportLoadedOnce = false;
31
- },
32
-
33
- async setSkillsTargetApp(app, options = {}) {
34
- if (
35
- this.skillsLoading
36
- || this.skillsDeleting
37
- || this.skillsScanningImports
38
- || this.skillsImporting
39
- || this.skillsZipImporting
40
- || this.skillsExporting
41
- || this.skillsMarketLoading
42
- ) {
43
- return false;
44
- }
45
- let nextTarget;
46
- try {
47
- nextTarget = this.normalizeSkillsTargetApp(app);
48
- } catch (error) {
49
- showUnsupportedSkillsTargetMessage(this, app);
50
- return false;
51
- }
52
- const refresh = !(options && options.refresh === false);
53
- const silent = !!(options && options.silent);
54
- if (nextTarget !== this.skillsTargetApp) {
55
- this.skillsTargetApp = nextTarget;
56
- this.resetSkillsTargetState();
57
- }
58
- if (!refresh) {
59
- return true;
60
- }
61
- return await this.loadSkillsMarketOverview({
62
- forceRefresh: true,
63
- silent
64
- });
65
- },
66
-
67
- async openSkillsManager(options = {}) {
68
- if (
69
- this.skillsLoading
70
- || this.skillsDeleting
71
- || this.skillsScanningImports
72
- || this.skillsImporting
73
- || this.skillsZipImporting
74
- || this.skillsExporting
75
- || this.skillsMarketLoading
76
- ) {
77
- return false;
78
- }
79
- let targetApp;
80
- try {
81
- targetApp = this.normalizeSkillsTargetApp(options && options.targetApp ? options.targetApp : this.skillsTargetApp);
82
- } catch (error) {
83
- showUnsupportedSkillsTargetMessage(this, options && options.targetApp);
84
- return false;
85
- }
86
- const targetChanged = targetApp !== this.skillsTargetApp;
87
- if (targetChanged) {
88
- this.skillsTargetApp = targetApp;
89
- this.resetSkillsTargetState();
90
- } else {
91
- this.skillsSelectedNames = [];
92
- this.skillsKeyword = '';
93
- this.skillsStatusFilter = 'all';
94
- this.skillsImportSelectedKeys = [];
95
- }
96
- this.showSkillsModal = true;
97
- await this.refreshSkillsList({ silent: false });
98
- },
99
-
100
- closeSkillsModal() {
101
- const busy = !!(
102
- this.skillsLoading
103
- || this.skillsDeleting
104
- || this.skillsScanningImports
105
- || this.skillsImporting
106
- || this.skillsZipImporting
107
- || this.skillsExporting
108
- );
109
- if (busy) return;
110
- this.showSkillsModal = false;
111
- this.skillsSelectedNames = [];
112
- this.skillsImportSelectedKeys = [];
113
- },
114
-
115
- async refreshSkillsList(options = {}) {
116
- this.skillsLoading = true;
117
- try {
118
- const res = await api('list-skills', {
119
- targetApp: this.skillsTargetApp
120
- });
121
- if (res.error) {
122
- this.skillsRootPath = '';
123
- this.skillsList = [];
124
- this.skillsSelectedNames = [];
125
- this.showMessage(res.error, 'error');
126
- return false;
127
- }
128
- const exists = res.exists !== false;
129
- if (!exists) {
130
- this.skillsRootPath = res.root || '';
131
- this.skillsList = [];
132
- this.skillsSelectedNames = [];
133
- if (!options.silent) {
134
- this.showMessage(`${this.skillsTargetLabel} skills 目录不存在,已按空列表显示`, 'info');
135
- }
136
- return true;
137
- }
138
- this.skillsRootPath = res.root || '';
139
- this.skillsList = Array.isArray(res.items) ? res.items : [];
140
- const currentNames = new Set((Array.isArray(this.skillsList) ? this.skillsList : [])
141
- .map((item) => (item && typeof item.name === 'string' ? item.name.trim() : ''))
142
- .filter(Boolean));
143
- this.skillsSelectedNames = (Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : [])
144
- .filter((name) => currentNames.has(name));
145
- return true;
146
- } catch (e) {
147
- this.skillsRootPath = '';
148
- this.skillsList = [];
149
- this.skillsSelectedNames = [];
150
- this.showMessage('加载 skills 失败', 'error');
151
- return false;
152
- } finally {
153
- this.skillsLoading = false;
154
- }
155
- },
156
-
157
- async loadSkillsMarketOverview(options = {}) {
158
- if (this.skillsMarketLoading) return false;
159
- const silent = !!(options && options.silent);
160
- const forceRefresh = !!(options && options.forceRefresh);
161
- this.skillsMarketLoading = true;
162
- let localLoaded = this.skillsMarketLocalLoadedOnce === true;
163
- let importLoaded = this.skillsMarketImportLoadedOnce === true;
164
- try {
165
- if (forceRefresh || !localLoaded) {
166
- localLoaded = await this.refreshSkillsList({ silent });
167
- this.skillsMarketLocalLoadedOnce = localLoaded;
168
- }
169
- if (forceRefresh || !importLoaded) {
170
- importLoaded = await this.scanImportableSkills({ silent });
171
- this.skillsMarketImportLoadedOnce = importLoaded;
172
- }
173
- return !!(localLoaded && importLoaded);
174
- } finally {
175
- this.skillsMarketLoading = false;
176
- }
177
- },
178
-
179
- resetSkillsFilters() {
180
- this.skillsKeyword = '';
181
- this.skillsStatusFilter = 'all';
182
- },
183
-
184
- toggleAllSkillsSelection() {
185
- const selectable = this.skillsSelectableNames;
186
- if (this.skillsAllSelected) {
187
- const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
188
- selectable.forEach((name) => selectedSet.delete(name));
189
- this.skillsSelectedNames = Array.from(selectedSet);
190
- return;
191
- }
192
- const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
193
- selectable.forEach((name) => selectedSet.add(name));
194
- this.skillsSelectedNames = Array.from(selectedSet);
195
- },
196
-
197
- buildSkillImportKey(item) {
198
- const safe = item && typeof item === 'object' ? item : {};
199
- const sourceApp = typeof safe.sourceApp === 'string' ? safe.sourceApp.trim().toLowerCase() : '';
200
- const name = typeof safe.name === 'string' ? safe.name.trim() : '';
201
- if (!sourceApp || !name) return '';
202
- return `${sourceApp}:${name}`;
203
- },
204
-
205
- toggleAllSkillsImportSelection() {
206
- const selectable = this.skillsImportSelectableKeys;
207
- if (this.skillsImportAllSelected) {
208
- this.skillsImportSelectedKeys = [];
209
- return;
210
- }
211
- this.skillsImportSelectedKeys = [...selectable];
212
- },
213
-
214
- async scanImportableSkills(options = {}) {
215
- if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return false;
216
- const silent = !!(options && options.silent);
217
- this.skillsScanningImports = true;
218
- try {
219
- const res = await api('scan-unmanaged-skills', {
220
- targetApp: this.skillsTargetApp
221
- });
222
- if (res.error) {
223
- this.skillsImportList = [];
224
- this.skillsImportSelectedKeys = [];
225
- if (!silent) {
226
- this.showMessage(res.error, 'error');
227
- }
228
- return false;
229
- }
230
- this.skillsImportList = Array.isArray(res.items) ? res.items : [];
231
- const availableKeys = new Set(this.skillsImportSelectableKeys);
232
- this.skillsImportSelectedKeys = (Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : [])
233
- .filter((key) => availableKeys.has(key));
234
- if (!silent && this.skillsImportList.length === 0) {
235
- this.showMessage('未扫描到可导入 skill', 'info');
236
- } else if (!silent) {
237
- this.showMessage(`扫描到 ${this.skillsImportList.length} 个可导入 skill`, 'success');
238
- }
239
- return true;
240
- } catch (e) {
241
- this.skillsImportList = [];
242
- this.skillsImportSelectedKeys = [];
243
- if (!silent) {
244
- this.showMessage('扫描可导入 skill 失败', 'error');
245
- }
246
- return false;
247
- } finally {
248
- this.skillsScanningImports = false;
249
- }
250
- },
251
-
252
- async importSelectedSkills() {
253
- if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return;
254
- const selectedSet = new Set(Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : []);
255
- const selectedItems = (Array.isArray(this.skillsImportList) ? this.skillsImportList : [])
256
- .filter((item) => selectedSet.has(this.buildSkillImportKey(item)))
257
- .map((item) => ({
258
- name: item.name,
259
- sourceApp: item.sourceApp
260
- }));
261
- if (!selectedItems.length) {
262
- this.showMessage('请先选择要导入的 skill', 'error');
263
- return;
264
- }
265
-
266
- this.skillsImporting = true;
267
- try {
268
- const res = await api('import-skills', {
269
- targetApp: this.skillsTargetApp,
270
- items: selectedItems
271
- });
272
- if (res.error) {
273
- this.showMessage(res.error, 'error');
274
- return;
275
- }
276
- const importedCount = Array.isArray(res.imported) ? res.imported.length : 0;
277
- const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
278
- if (failedCount > 0 && importedCount > 0) {
279
- this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
280
- } else if (failedCount > 0) {
281
- const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
282
- this.showMessage(first, 'error');
283
- } else {
284
- this.showMessage(`已导入 ${importedCount} skill 到 ${this.skillsTargetLabel}`, 'success');
285
- }
286
- await this.refreshSkillsList({ silent: true });
287
- } catch (e) {
288
- this.showMessage('导入 skill 失败', 'error');
289
- } finally {
290
- this.skillsImporting = false;
291
- await this.scanImportableSkills({ silent: true });
292
- }
293
- },
294
-
295
- triggerSkillsZipImport() {
296
- const input = this.$refs.skillsZipImportInput;
297
- if (input) {
298
- input.value = '';
299
- input.click();
300
- }
301
- },
302
-
303
- handleSkillsZipImportChange(event) {
304
- const file = event && event.target && event.target.files ? event.target.files[0] : null;
305
- if (file) {
306
- void this.importSkillsFromZipFile(file);
307
- }
308
- },
309
-
310
- resetSkillsZipImportInput() {
311
- const el = this.$refs.skillsZipImportInput;
312
- if (el) {
313
- el.value = '';
314
- }
315
- },
316
-
317
- async uploadSkillsZipStream(file) {
318
- const fileName = (file && typeof file.name === 'string' && file.name.trim())
319
- ? file.name.trim()
320
- : `${this.skillsTargetApp}-skills.zip`;
321
- const response = await fetch(`/api/import-skills-zip?targetApp=${encodeURIComponent(this.skillsTargetApp)}`, {
322
- method: 'POST',
323
- headers: {
324
- 'x-codexmate-file-name': encodeURIComponent(fileName)
325
- },
326
- body: file
327
- });
328
- let payload = {};
329
- try {
330
- payload = await response.json();
331
- } catch (_) {
332
- payload = {
333
- error: response.ok
334
- ? 'ZIP 导入响应无效'
335
- : `上传失败(HTTP ${response.status})`
336
- };
337
- }
338
- if (!response.ok && !payload.error) {
339
- payload.error = `上传失败(HTTP ${response.status})`;
340
- }
341
- return payload;
342
- },
343
-
344
- async importSkillsFromZipFile(file) {
345
- if (this.skillsDeleting || this.skillsScanningImports || this.skillsZipImporting || this.skillsImporting || this.skillsExporting) return;
346
- const maxSize = 20 * 1024 * 1024;
347
- if (file.size > maxSize) {
348
- this.showMessage('ZIP 文件过大,限制 20MB', 'error');
349
- this.resetSkillsZipImportInput();
350
- return;
351
- }
352
- this.skillsZipImporting = true;
353
- try {
354
- const res = await this.uploadSkillsZipStream(file);
355
- if (res && res.error) {
356
- this.showMessage(res.error, 'error');
357
- return;
358
- }
359
- const importedCount = Array.isArray(res && res.imported) ? res.imported.length : 0;
360
- const failedCount = Array.isArray(res && res.failed) ? res.failed.length : 0;
361
- if (failedCount > 0 && importedCount > 0) {
362
- this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
363
- } else if (failedCount > 0) {
364
- const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
365
- this.showMessage(first, 'error');
366
- } else {
367
- this.showMessage(`已导入 ${importedCount} skill 到 ${this.skillsTargetLabel}`, 'success');
368
- }
369
- await this.refreshSkillsList({ silent: true });
370
- } catch (e) {
371
- this.showMessage('ZIP 导入失败', 'error');
372
- } finally {
373
- this.skillsZipImporting = false;
374
- this.resetSkillsZipImportInput();
375
- await this.scanImportableSkills({ silent: true });
376
- }
377
- },
378
-
379
- async exportSelectedSkills() {
380
- if (this.skillsDeleting || this.skillsExporting || this.skillsZipImporting || this.skillsImporting) return;
381
- const selected = Array.isArray(this.skillsSelectedNames)
382
- ? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
383
- : [];
384
- if (!selected.length) {
385
- this.showMessage('请先选择要导出的 skill', 'error');
386
- return;
387
- }
388
- this.skillsExporting = true;
389
- try {
390
- const res = await api('export-skills', {
391
- targetApp: this.skillsTargetApp,
392
- names: selected
393
- });
394
- if (res && res.error) {
395
- this.showMessage(res.error, 'error');
396
- return;
397
- }
398
- if (!res || !res.fileName) {
399
- this.showMessage('导出失败:未生成压缩包', 'error');
400
- return;
401
- }
402
- const exportedCount = Array.isArray(res.exported) ? res.exported.length : 0;
403
- const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
404
- const downloadUrl = typeof res.downloadPath === 'string' && res.downloadPath.trim()
405
- ? res.downloadPath.trim()
406
- : `/download/${encodeURIComponent(res.fileName)}`;
407
- const link = document.createElement('a');
408
- link.href = downloadUrl;
409
- link.download = res.fileName;
410
- document.body.appendChild(link);
411
- link.click();
412
- document.body.removeChild(link);
413
- if (failedCount > 0) {
414
- this.showMessage(`已导出 ${exportedCount} 个,失败 ${failedCount} 个`, 'error');
415
- } else {
416
- this.showMessage(`已从 ${this.skillsTargetLabel} 导出 ${exportedCount} 个 skill`, 'success');
417
- }
418
- } catch (e) {
419
- this.showMessage('导出 skill 失败', 'error');
420
- } finally {
421
- this.skillsExporting = false;
422
- }
423
- },
424
-
425
- async deleteSelectedSkills() {
426
- if (this.skillsDeleting || this.skillsZipImporting || this.skillsExporting || this.skillsImporting) return;
427
- if (this.skillsScanningImports) {
428
- this.showMessage('正在扫描导入源,请稍后再试', 'error');
429
- return;
430
- }
431
- const selected = Array.isArray(this.skillsSelectedNames)
432
- ? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
433
- : [];
434
- if (!selected.length) {
435
- this.showMessage('请先选择要删除的 skill', 'error');
436
- return;
437
- }
438
- const confirmed = await this.requestConfirmDialog({
439
- title: '删除 Skills',
440
- message: `确认从 ${this.skillsTargetLabel} 删除 ${selected.length} 个 skill 吗?此操作不可撤销。`,
441
- confirmText: '删除',
442
- cancelText: '取消',
443
- confirmDisabled: () => this.skillsDeleting || this.skillsScanningImports,
444
- danger: true
445
- });
446
- if (!confirmed) {
447
- return;
448
- }
449
-
450
- this.skillsDeleting = true;
451
- try {
452
- const res = await api('delete-skills', {
453
- targetApp: this.skillsTargetApp,
454
- names: selected
455
- });
456
- if (res.error) {
457
- this.showMessage(res.error, 'error');
458
- return;
459
- }
460
-
461
- const deletedCount = Array.isArray(res.deleted) ? res.deleted.length : 0;
462
- const failedList = Array.isArray(res.failed) ? res.failed : [];
463
- const failedCount = failedList.length;
464
- if (failedCount > 0 && deletedCount > 0) {
465
- this.showMessage(`已删除 ${deletedCount} 个,失败 ${failedCount} 个`, 'error');
466
- } else if (failedCount > 0) {
467
- const first = failedList[0] && failedList[0].error ? failedList[0].error : '删除失败';
468
- this.showMessage(first, 'error');
469
- } else {
470
- this.showMessage(`已从 ${this.skillsTargetLabel} 删除 ${deletedCount} 个 skill`, 'success');
471
- }
472
- await this.refreshSkillsList({ silent: true });
473
- } catch (e) {
474
- this.showMessage('删除 skill 失败', 'error');
475
- } finally {
476
- this.skillsDeleting = false;
477
- await this.scanImportableSkills({ silent: true });
478
- }
479
- }
480
- };
481
- }
1
+ function createUnsupportedSkillsTargetAppError(app) {
2
+ return new Error(`Unsupported skills target app: ${String(app)}`);
3
+ }
4
+
5
+ function showUnsupportedSkillsTargetMessage(vm, app) {
6
+ vm.showMessage(`不支持的 Skills 安装目标:${String(app)}`, 'error');
7
+ }
8
+
9
+ export function createSkillsMethods({ api }) {
10
+ return {
11
+ normalizeSkillsTargetApp(app) {
12
+ if (app == null) {
13
+ return 'codex';
14
+ }
15
+ if (app === 'codex' || app === 'claude') {
16
+ return app;
17
+ }
18
+ throw createUnsupportedSkillsTargetAppError(app);
19
+ },
20
+
21
+ resetSkillsTargetState() {
22
+ this.skillsSelectedNames = [];
23
+ this.skillsKeyword = '';
24
+ this.skillsStatusFilter = 'all';
25
+ this.skillsRootPath = '';
26
+ this.skillsList = [];
27
+ this.skillsImportList = [];
28
+ this.skillsImportSelectedKeys = [];
29
+ this.skillsMarketLocalLoadedOnce = false;
30
+ this.skillsMarketImportLoadedOnce = false;
31
+ },
32
+
33
+ async setSkillsTargetApp(app, options = {}) {
34
+ if (
35
+ this.skillsLoading
36
+ || this.skillsDeleting
37
+ || this.skillsScanningImports
38
+ || this.skillsImporting
39
+ || this.skillsZipImporting
40
+ || this.skillsExporting
41
+ || this.skillsMarketLoading
42
+ ) {
43
+ return false;
44
+ }
45
+ let nextTarget;
46
+ try {
47
+ nextTarget = this.normalizeSkillsTargetApp(app);
48
+ } catch (error) {
49
+ showUnsupportedSkillsTargetMessage(this, app);
50
+ return false;
51
+ }
52
+ const refresh = !(options && options.refresh === false);
53
+ const silent = !!(options && options.silent);
54
+ if (nextTarget !== this.skillsTargetApp) {
55
+ this.skillsTargetApp = nextTarget;
56
+ this.resetSkillsTargetState();
57
+ if (typeof this.saveNavState === 'function') this.saveNavState();
58
+ }
59
+ if (!refresh) {
60
+ return true;
61
+ }
62
+ return await this.loadSkillsMarketOverview({
63
+ forceRefresh: true,
64
+ silent
65
+ });
66
+ },
67
+
68
+ async openSkillsManager(options = {}) {
69
+ if (
70
+ this.skillsLoading
71
+ || this.skillsDeleting
72
+ || this.skillsScanningImports
73
+ || this.skillsImporting
74
+ || this.skillsZipImporting
75
+ || this.skillsExporting
76
+ || this.skillsMarketLoading
77
+ ) {
78
+ return false;
79
+ }
80
+ let targetApp;
81
+ try {
82
+ targetApp = this.normalizeSkillsTargetApp(options && options.targetApp ? options.targetApp : this.skillsTargetApp);
83
+ } catch (error) {
84
+ showUnsupportedSkillsTargetMessage(this, options && options.targetApp);
85
+ return false;
86
+ }
87
+ const targetChanged = targetApp !== this.skillsTargetApp;
88
+ if (targetChanged) {
89
+ this.skillsTargetApp = targetApp;
90
+ this.resetSkillsTargetState();
91
+ } else {
92
+ this.skillsSelectedNames = [];
93
+ this.skillsKeyword = '';
94
+ this.skillsStatusFilter = 'all';
95
+ this.skillsImportSelectedKeys = [];
96
+ }
97
+ this.showSkillsModal = true;
98
+ await this.refreshSkillsList({ silent: false });
99
+ },
100
+
101
+ closeSkillsModal() {
102
+ const busy = !!(
103
+ this.skillsLoading
104
+ || this.skillsDeleting
105
+ || this.skillsScanningImports
106
+ || this.skillsImporting
107
+ || this.skillsZipImporting
108
+ || this.skillsExporting
109
+ );
110
+ if (busy) return;
111
+ this.showSkillsModal = false;
112
+ this.skillsSelectedNames = [];
113
+ this.skillsImportSelectedKeys = [];
114
+ },
115
+
116
+ async refreshSkillsList(options = {}) {
117
+ this.skillsLoading = true;
118
+ try {
119
+ const res = await api('list-skills', {
120
+ targetApp: this.skillsTargetApp
121
+ });
122
+ if (res.error) {
123
+ this.skillsRootPath = '';
124
+ this.skillsList = [];
125
+ this.skillsSelectedNames = [];
126
+ this.showMessage(res.error, 'error');
127
+ return false;
128
+ }
129
+ const exists = res.exists !== false;
130
+ if (!exists) {
131
+ this.skillsRootPath = res.root || '';
132
+ this.skillsList = [];
133
+ this.skillsSelectedNames = [];
134
+ if (!options.silent) {
135
+ this.showMessage(`${this.skillsTargetLabel} skills 目录不存在,已按空列表显示`, 'info');
136
+ }
137
+ return true;
138
+ }
139
+ this.skillsRootPath = res.root || '';
140
+ this.skillsList = Array.isArray(res.items) ? res.items : [];
141
+ const currentNames = new Set((Array.isArray(this.skillsList) ? this.skillsList : [])
142
+ .map((item) => (item && typeof item.name === 'string' ? item.name.trim() : ''))
143
+ .filter(Boolean));
144
+ this.skillsSelectedNames = (Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : [])
145
+ .filter((name) => currentNames.has(name));
146
+ return true;
147
+ } catch (e) {
148
+ this.skillsRootPath = '';
149
+ this.skillsList = [];
150
+ this.skillsSelectedNames = [];
151
+ this.showMessage('加载 skills 失败', 'error');
152
+ return false;
153
+ } finally {
154
+ this.skillsLoading = false;
155
+ }
156
+ },
157
+
158
+ async loadSkillsMarketOverview(options = {}) {
159
+ if (this.skillsMarketLoading) return false;
160
+ const silent = !!(options && options.silent);
161
+ const forceRefresh = !!(options && options.forceRefresh);
162
+ this.skillsMarketLoading = true;
163
+ let localLoaded = this.skillsMarketLocalLoadedOnce === true;
164
+ let importLoaded = this.skillsMarketImportLoadedOnce === true;
165
+ try {
166
+ if (forceRefresh || !localLoaded) {
167
+ localLoaded = await this.refreshSkillsList({ silent });
168
+ this.skillsMarketLocalLoadedOnce = localLoaded;
169
+ }
170
+ if (forceRefresh || !importLoaded) {
171
+ importLoaded = await this.scanImportableSkills({ silent });
172
+ this.skillsMarketImportLoadedOnce = importLoaded;
173
+ }
174
+ return !!(localLoaded && importLoaded);
175
+ } finally {
176
+ this.skillsMarketLoading = false;
177
+ }
178
+ },
179
+
180
+ resetSkillsFilters() {
181
+ this.skillsKeyword = '';
182
+ this.skillsStatusFilter = 'all';
183
+ },
184
+
185
+ toggleAllSkillsSelection() {
186
+ const selectable = this.skillsSelectableNames;
187
+ if (this.skillsAllSelected) {
188
+ const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
189
+ selectable.forEach((name) => selectedSet.delete(name));
190
+ this.skillsSelectedNames = Array.from(selectedSet);
191
+ return;
192
+ }
193
+ const selectedSet = new Set(Array.isArray(this.skillsSelectedNames) ? this.skillsSelectedNames : []);
194
+ selectable.forEach((name) => selectedSet.add(name));
195
+ this.skillsSelectedNames = Array.from(selectedSet);
196
+ },
197
+
198
+ buildSkillImportKey(item) {
199
+ const safe = item && typeof item === 'object' ? item : {};
200
+ const sourceApp = typeof safe.sourceApp === 'string' ? safe.sourceApp.trim().toLowerCase() : '';
201
+ const name = typeof safe.name === 'string' ? safe.name.trim() : '';
202
+ if (!sourceApp || !name) return '';
203
+ return `${sourceApp}:${name}`;
204
+ },
205
+
206
+ toggleAllSkillsImportSelection() {
207
+ const selectable = this.skillsImportSelectableKeys;
208
+ if (this.skillsImportAllSelected) {
209
+ this.skillsImportSelectedKeys = [];
210
+ return;
211
+ }
212
+ this.skillsImportSelectedKeys = [...selectable];
213
+ },
214
+
215
+ async scanImportableSkills(options = {}) {
216
+ if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return false;
217
+ const silent = !!(options && options.silent);
218
+ this.skillsScanningImports = true;
219
+ try {
220
+ const res = await api('scan-unmanaged-skills', {
221
+ targetApp: this.skillsTargetApp
222
+ });
223
+ if (res.error) {
224
+ this.skillsImportList = [];
225
+ this.skillsImportSelectedKeys = [];
226
+ if (!silent) {
227
+ this.showMessage(res.error, 'error');
228
+ }
229
+ return false;
230
+ }
231
+ this.skillsImportList = Array.isArray(res.items) ? res.items : [];
232
+ const availableKeys = new Set(this.skillsImportSelectableKeys);
233
+ this.skillsImportSelectedKeys = (Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : [])
234
+ .filter((key) => availableKeys.has(key));
235
+ if (!silent && this.skillsImportList.length === 0) {
236
+ this.showMessage('未扫描到可导入 skill', 'info');
237
+ } else if (!silent) {
238
+ this.showMessage(`扫描到 ${this.skillsImportList.length} 个可导入 skill`, 'success');
239
+ }
240
+ return true;
241
+ } catch (e) {
242
+ this.skillsImportList = [];
243
+ this.skillsImportSelectedKeys = [];
244
+ if (!silent) {
245
+ this.showMessage('扫描可导入 skill 失败', 'error');
246
+ }
247
+ return false;
248
+ } finally {
249
+ this.skillsScanningImports = false;
250
+ }
251
+ },
252
+
253
+ async importSelectedSkills() {
254
+ if (this.skillsDeleting || this.skillsScanningImports || this.skillsImporting || this.skillsZipImporting || this.skillsExporting) return;
255
+ const selectedSet = new Set(Array.isArray(this.skillsImportSelectedKeys) ? this.skillsImportSelectedKeys : []);
256
+ const selectedItems = (Array.isArray(this.skillsImportList) ? this.skillsImportList : [])
257
+ .filter((item) => selectedSet.has(this.buildSkillImportKey(item)))
258
+ .map((item) => ({
259
+ name: item.name,
260
+ sourceApp: item.sourceApp
261
+ }));
262
+ if (!selectedItems.length) {
263
+ this.showMessage('请先选择要导入的 skill', 'error');
264
+ return;
265
+ }
266
+
267
+ this.skillsImporting = true;
268
+ try {
269
+ const res = await api('import-skills', {
270
+ targetApp: this.skillsTargetApp,
271
+ items: selectedItems
272
+ });
273
+ if (res.error) {
274
+ this.showMessage(res.error, 'error');
275
+ return;
276
+ }
277
+ const importedCount = Array.isArray(res.imported) ? res.imported.length : 0;
278
+ const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
279
+ if (failedCount > 0 && importedCount > 0) {
280
+ this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
281
+ } else if (failedCount > 0) {
282
+ const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
283
+ this.showMessage(first, 'error');
284
+ } else {
285
+ this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
286
+ }
287
+ await this.refreshSkillsList({ silent: true });
288
+ } catch (e) {
289
+ this.showMessage('导入 skill 失败', 'error');
290
+ } finally {
291
+ this.skillsImporting = false;
292
+ await this.scanImportableSkills({ silent: true });
293
+ }
294
+ },
295
+
296
+ triggerSkillsZipImport() {
297
+ const input = this.$refs.skillsZipImportInput;
298
+ if (input) {
299
+ input.value = '';
300
+ input.click();
301
+ }
302
+ },
303
+
304
+ handleSkillsZipImportChange(event) {
305
+ const file = event && event.target && event.target.files ? event.target.files[0] : null;
306
+ if (file) {
307
+ void this.importSkillsFromZipFile(file);
308
+ }
309
+ },
310
+
311
+ resetSkillsZipImportInput() {
312
+ const el = this.$refs.skillsZipImportInput;
313
+ if (el) {
314
+ el.value = '';
315
+ }
316
+ },
317
+
318
+ async uploadSkillsZipStream(file) {
319
+ const fileName = (file && typeof file.name === 'string' && file.name.trim())
320
+ ? file.name.trim()
321
+ : `${this.skillsTargetApp}-skills.zip`;
322
+ const response = await fetch(`/api/import-skills-zip?targetApp=${encodeURIComponent(this.skillsTargetApp)}`, {
323
+ method: 'POST',
324
+ headers: {
325
+ 'x-codexmate-file-name': encodeURIComponent(fileName)
326
+ },
327
+ body: file
328
+ });
329
+ let payload = {};
330
+ try {
331
+ payload = await response.json();
332
+ } catch (_) {
333
+ payload = {
334
+ error: response.ok
335
+ ? 'ZIP 导入响应无效'
336
+ : `上传失败(HTTP ${response.status})`
337
+ };
338
+ }
339
+ if (!response.ok && !payload.error) {
340
+ payload.error = `上传失败(HTTP ${response.status})`;
341
+ }
342
+ return payload;
343
+ },
344
+
345
+ async importSkillsFromZipFile(file) {
346
+ if (this.skillsDeleting || this.skillsScanningImports || this.skillsZipImporting || this.skillsImporting || this.skillsExporting) return;
347
+ const maxSize = 20 * 1024 * 1024;
348
+ if (file.size > maxSize) {
349
+ this.showMessage('ZIP 文件过大,限制 20MB', 'error');
350
+ this.resetSkillsZipImportInput();
351
+ return;
352
+ }
353
+ this.skillsZipImporting = true;
354
+ try {
355
+ const res = await this.uploadSkillsZipStream(file);
356
+ if (res && res.error) {
357
+ this.showMessage(res.error, 'error');
358
+ return;
359
+ }
360
+ const importedCount = Array.isArray(res && res.imported) ? res.imported.length : 0;
361
+ const failedCount = Array.isArray(res && res.failed) ? res.failed.length : 0;
362
+ if (failedCount > 0 && importedCount > 0) {
363
+ this.showMessage(`已导入 ${importedCount} 个,失败 ${failedCount} 个`, 'error');
364
+ } else if (failedCount > 0) {
365
+ const first = res.failed[0] && res.failed[0].error ? res.failed[0].error : '导入失败';
366
+ this.showMessage(first, 'error');
367
+ } else {
368
+ this.showMessage(`已导入 ${importedCount} 个 skill 到 ${this.skillsTargetLabel}`, 'success');
369
+ }
370
+ await this.refreshSkillsList({ silent: true });
371
+ } catch (e) {
372
+ this.showMessage('ZIP 导入失败', 'error');
373
+ } finally {
374
+ this.skillsZipImporting = false;
375
+ this.resetSkillsZipImportInput();
376
+ await this.scanImportableSkills({ silent: true });
377
+ }
378
+ },
379
+
380
+ async exportSelectedSkills() {
381
+ if (this.skillsDeleting || this.skillsExporting || this.skillsZipImporting || this.skillsImporting) return;
382
+ const selected = Array.isArray(this.skillsSelectedNames)
383
+ ? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
384
+ : [];
385
+ if (!selected.length) {
386
+ this.showMessage('请先选择要导出的 skill', 'error');
387
+ return;
388
+ }
389
+ this.skillsExporting = true;
390
+ try {
391
+ const res = await api('export-skills', {
392
+ targetApp: this.skillsTargetApp,
393
+ names: selected
394
+ });
395
+ if (res && res.error) {
396
+ this.showMessage(res.error, 'error');
397
+ return;
398
+ }
399
+ if (!res || !res.fileName) {
400
+ this.showMessage('导出失败:未生成压缩包', 'error');
401
+ return;
402
+ }
403
+ const exportedCount = Array.isArray(res.exported) ? res.exported.length : 0;
404
+ const failedCount = Array.isArray(res.failed) ? res.failed.length : 0;
405
+ const downloadUrl = typeof res.downloadPath === 'string' && res.downloadPath.trim()
406
+ ? res.downloadPath.trim()
407
+ : `/download/${encodeURIComponent(res.fileName)}`;
408
+ const link = document.createElement('a');
409
+ link.href = downloadUrl;
410
+ link.download = res.fileName;
411
+ document.body.appendChild(link);
412
+ link.click();
413
+ document.body.removeChild(link);
414
+ if (failedCount > 0) {
415
+ this.showMessage(`已导出 ${exportedCount} 个,失败 ${failedCount} 个`, 'error');
416
+ } else {
417
+ this.showMessage(`已从 ${this.skillsTargetLabel} 导出 ${exportedCount} 个 skill`, 'success');
418
+ }
419
+ } catch (e) {
420
+ this.showMessage('导出 skill 失败', 'error');
421
+ } finally {
422
+ this.skillsExporting = false;
423
+ }
424
+ },
425
+
426
+ async deleteSelectedSkills() {
427
+ if (this.skillsDeleting || this.skillsZipImporting || this.skillsExporting || this.skillsImporting) return;
428
+ if (this.skillsScanningImports) {
429
+ this.showMessage('正在扫描导入源,请稍后再试', 'error');
430
+ return;
431
+ }
432
+ const selected = Array.isArray(this.skillsSelectedNames)
433
+ ? Array.from(new Set(this.skillsSelectedNames.map((item) => String(item || '').trim()).filter(Boolean)))
434
+ : [];
435
+ if (!selected.length) {
436
+ this.showMessage('请先选择要删除的 skill', 'error');
437
+ return;
438
+ }
439
+ const confirmed = await this.requestConfirmDialog({
440
+ title: '删除 Skills',
441
+ message: `确认从 ${this.skillsTargetLabel} 删除 ${selected.length} 个 skill 吗?此操作不可撤销。`,
442
+ confirmText: '删除',
443
+ cancelText: '取消',
444
+ confirmDisabled: () => this.skillsDeleting || this.skillsScanningImports,
445
+ danger: true
446
+ });
447
+ if (!confirmed) {
448
+ return;
449
+ }
450
+
451
+ this.skillsDeleting = true;
452
+ try {
453
+ const res = await api('delete-skills', {
454
+ targetApp: this.skillsTargetApp,
455
+ names: selected
456
+ });
457
+ if (res.error) {
458
+ this.showMessage(res.error, 'error');
459
+ return;
460
+ }
461
+
462
+ const deletedCount = Array.isArray(res.deleted) ? res.deleted.length : 0;
463
+ const failedList = Array.isArray(res.failed) ? res.failed : [];
464
+ const failedCount = failedList.length;
465
+ if (failedCount > 0 && deletedCount > 0) {
466
+ this.showMessage(`已删除 ${deletedCount} 个,失败 ${failedCount} 个`, 'error');
467
+ } else if (failedCount > 0) {
468
+ const first = failedList[0] && failedList[0].error ? failedList[0].error : '删除失败';
469
+ this.showMessage(first, 'error');
470
+ } else {
471
+ this.showMessage(`已从 ${this.skillsTargetLabel} 删除 ${deletedCount} 个 skill`, 'success');
472
+ }
473
+ await this.refreshSkillsList({ silent: true });
474
+ } catch (e) {
475
+ this.showMessage('删除 skill 失败', 'error');
476
+ } finally {
477
+ this.skillsDeleting = false;
478
+ await this.scanImportableSkills({ silent: true });
479
+ }
480
+ }
481
+ };
482
+ }