codexmate 0.0.28 → 0.0.29

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 (142) 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 -1620
  7. package/cli/claude-proxy.js +1022 -1022
  8. package/cli/config-bootstrap.js +384 -384
  9. package/cli/config-health.js +338 -338
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/openai-bridge.js +1576 -1489
  13. package/cli/openclaw-config.js +629 -629
  14. package/cli/session-convert-args.js +65 -65
  15. package/cli/session-convert-io.js +82 -82
  16. package/cli/session-convert.js +43 -43
  17. package/cli/session-usage.concurrent.js +28 -28
  18. package/cli/session-usage.js +118 -118
  19. package/cli/session-usage.models.js +176 -176
  20. package/cli/skills.js +1141 -1141
  21. package/cli/zip-commands.js +510 -510
  22. package/cli.js +15340 -15264
  23. package/lib/automation.js +404 -404
  24. package/lib/cli-file-utils.js +151 -151
  25. package/lib/cli-models-utils.js +440 -440
  26. package/lib/cli-network-utils.js +190 -190
  27. package/lib/cli-path-utils.js +85 -85
  28. package/lib/cli-session-utils.js +121 -121
  29. package/lib/cli-sessions.js +417 -417
  30. package/lib/cli-utils.js +155 -155
  31. package/lib/cli-webhook.js +126 -0
  32. package/lib/download-artifacts.js +92 -92
  33. package/lib/mcp-stdio.js +453 -453
  34. package/lib/task-orchestrator.js +869 -869
  35. package/lib/text-diff.js +303 -303
  36. package/lib/workflow-engine.js +340 -340
  37. package/package.json +76 -76
  38. package/plugins/README.md +20 -20
  39. package/plugins/README.zh-CN.md +20 -20
  40. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  41. package/plugins/prompt-templates/computed.mjs +253 -253
  42. package/plugins/prompt-templates/index.mjs +8 -8
  43. package/plugins/prompt-templates/manifest.mjs +15 -15
  44. package/plugins/prompt-templates/methods.mjs +553 -553
  45. package/plugins/prompt-templates/overview.mjs +91 -91
  46. package/plugins/prompt-templates/ownership.mjs +19 -19
  47. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  48. package/plugins/prompt-templates/storage.mjs +64 -64
  49. package/plugins/registry.mjs +16 -16
  50. package/web-ui/app.js +639 -625
  51. package/web-ui/index.html +36 -35
  52. package/web-ui/logic.agents-diff.mjs +386 -386
  53. package/web-ui/logic.claude.mjs +168 -168
  54. package/web-ui/logic.codex.mjs +69 -56
  55. package/web-ui/logic.mjs +5 -5
  56. package/web-ui/logic.runtime.mjs +128 -128
  57. package/web-ui/logic.session-convert.mjs +70 -70
  58. package/web-ui/logic.sessions.mjs +765 -765
  59. package/web-ui/modules/api.mjs +90 -90
  60. package/web-ui/modules/app.computed.dashboard.mjs +225 -225
  61. package/web-ui/modules/app.computed.index.mjs +17 -17
  62. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  63. package/web-ui/modules/app.computed.session.mjs +999 -994
  64. package/web-ui/modules/app.constants.mjs +15 -15
  65. package/web-ui/modules/app.methods.agents.mjs +632 -632
  66. package/web-ui/modules/app.methods.claude-config.mjs +200 -190
  67. package/web-ui/modules/app.methods.codex-config.mjs +892 -892
  68. package/web-ui/modules/app.methods.index.mjs +94 -92
  69. package/web-ui/modules/app.methods.install.mjs +205 -205
  70. package/web-ui/modules/app.methods.navigation.mjs +761 -743
  71. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  72. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  73. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  74. package/web-ui/modules/app.methods.providers.mjs +493 -412
  75. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  76. package/web-ui/modules/app.methods.session-actions.mjs +593 -593
  77. package/web-ui/modules/app.methods.session-browser.mjs +984 -984
  78. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  79. package/web-ui/modules/app.methods.session-trash.mjs +438 -439
  80. package/web-ui/modules/app.methods.startup-claude.mjs +533 -533
  81. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  82. package/web-ui/modules/app.methods.webhook.mjs +79 -0
  83. package/web-ui/modules/config-mode.computed.mjs +124 -124
  84. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  85. package/web-ui/modules/i18n.dict.mjs +3131 -2109
  86. package/web-ui/modules/i18n.mjs +62 -56
  87. package/web-ui/modules/plugins.computed.mjs +3 -3
  88. package/web-ui/modules/plugins.methods.mjs +3 -3
  89. package/web-ui/modules/plugins.storage.mjs +11 -11
  90. package/web-ui/modules/provider-url-display.mjs +17 -17
  91. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  92. package/web-ui/modules/skills.computed.mjs +107 -107
  93. package/web-ui/modules/skills.methods.mjs +481 -481
  94. package/web-ui/partials/index/layout-footer.html +13 -13
  95. package/web-ui/partials/index/layout-header.html +500 -475
  96. package/web-ui/partials/index/modal-config-template-agents.html +174 -174
  97. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  98. package/web-ui/partials/index/modal-health-check.html +45 -45
  99. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  100. package/web-ui/partials/index/modal-skills.html +200 -200
  101. package/web-ui/partials/index/modals-basic.html +162 -165
  102. package/web-ui/partials/index/panel-config-claude.html +194 -188
  103. package/web-ui/partials/index/panel-config-codex.html +323 -312
  104. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  105. package/web-ui/partials/index/panel-dashboard.html +186 -186
  106. package/web-ui/partials/index/panel-docs.html +147 -147
  107. package/web-ui/partials/index/panel-market.html +177 -177
  108. package/web-ui/partials/index/panel-orchestration.html +391 -391
  109. package/web-ui/partials/index/panel-plugins.html +253 -253
  110. package/web-ui/partials/index/panel-sessions.html +316 -316
  111. package/web-ui/partials/index/panel-settings.html +190 -253
  112. package/web-ui/partials/index/panel-trash.html +88 -0
  113. package/web-ui/partials/index/panel-usage.html +371 -371
  114. package/web-ui/res/json5.min.js +1 -1
  115. package/web-ui/res/vue.global.prod.js +13 -13
  116. package/web-ui/session-helpers.mjs +576 -576
  117. package/web-ui/source-bundle.cjs +233 -233
  118. package/web-ui/styles/base-theme.css +281 -281
  119. package/web-ui/styles/controls-forms.css +422 -422
  120. package/web-ui/styles/dashboard.css +274 -274
  121. package/web-ui/styles/docs-panel.css +271 -247
  122. package/web-ui/styles/feedback.css +108 -108
  123. package/web-ui/styles/health-check-dialog.css +144 -144
  124. package/web-ui/styles/layout-shell.css +626 -606
  125. package/web-ui/styles/modals-core.css +466 -466
  126. package/web-ui/styles/navigation-panels.css +391 -391
  127. package/web-ui/styles/openclaw-structured.css +266 -266
  128. package/web-ui/styles/plugins-panel.css +523 -523
  129. package/web-ui/styles/responsive.css +454 -454
  130. package/web-ui/styles/sessions-list.css +419 -419
  131. package/web-ui/styles/sessions-preview.css +411 -411
  132. package/web-ui/styles/sessions-toolbar-trash.css +330 -330
  133. package/web-ui/styles/sessions-usage.css +1040 -1040
  134. package/web-ui/styles/settings-panel.css +349 -185
  135. package/web-ui/styles/skills-list.css +303 -303
  136. package/web-ui/styles/skills-market.css +406 -406
  137. package/web-ui/styles/task-orchestration.css +822 -822
  138. package/web-ui/styles/titles-cards.css +472 -472
  139. package/web-ui/styles/trash-panel.css +90 -0
  140. package/web-ui/styles/webhook.css +81 -0
  141. package/web-ui/styles.css +23 -21
  142. package/web-ui.html +17 -17
@@ -1,481 +1,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
- }
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
+ }
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
+ }