codexmate 0.0.31 → 0.0.32

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 (145) hide show
  1. package/README.md +363 -363
  2. package/README.zh.md +371 -371
  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 -402
  9. package/cli/config-health.js +454 -454
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/local-bridge.js +324 -324
  13. package/cli/openai-bridge.js +1653 -1653
  14. package/cli/openclaw-config.js +629 -629
  15. package/cli/session-convert-args.js +69 -69
  16. package/cli/session-convert-io.js +82 -82
  17. package/cli/session-convert.js +150 -150
  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 +15829 -15778
  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 +426 -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 +647 -646
  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 +781 -765
  60. package/web-ui/modules/api.mjs +90 -90
  61. package/web-ui/modules/app.computed.dashboard.mjs +248 -248
  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 +693 -999
  65. package/web-ui/modules/app.constants.mjs +15 -15
  66. package/web-ui/modules/app.methods.agents.mjs +651 -632
  67. package/web-ui/modules/app.methods.claude-config.mjs +200 -200
  68. package/web-ui/modules/app.methods.codex-config.mjs +861 -841
  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 -774
  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 -529
  76. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  77. package/web-ui/modules/app.methods.session-actions.mjs +591 -591
  78. package/web-ui/modules/app.methods.session-browser.mjs +1012 -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 +537 -534
  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 +3177 -3174
  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 -482
  95. package/web-ui/partials/index/layout-footer.html +13 -13
  96. package/web-ui/partials/index/layout-header.html +503 -500
  97. package/web-ui/partials/index/modal-config-template-agents.html +185 -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 +136 -194
  104. package/web-ui/partials/index/panel-config-codex.html +197 -357
  105. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  106. package/web-ui/partials/index/panel-dashboard.html +219 -219
  107. package/web-ui/partials/index/panel-docs.html +115 -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 +313 -302
  112. package/web-ui/partials/index/panel-settings.html +190 -190
  113. package/web-ui/partials/index/panel-trash.html +83 -88
  114. package/web-ui/partials/index/panel-usage.html +138 -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 +591 -591
  118. package/web-ui/source-bundle.cjs +233 -233
  119. package/web-ui/styles/base-theme.css +281 -281
  120. package/web-ui/styles/bridge-pool.css +197 -197
  121. package/web-ui/styles/controls-forms.css +433 -422
  122. package/web-ui/styles/dashboard.css +406 -406
  123. package/web-ui/styles/docs-panel.css +245 -271
  124. package/web-ui/styles/feedback.css +108 -108
  125. package/web-ui/styles/health-check-dialog.css +144 -144
  126. package/web-ui/styles/layout-shell.css +638 -626
  127. package/web-ui/styles/modals-core.css +466 -466
  128. package/web-ui/styles/navigation-panels.css +391 -391
  129. package/web-ui/styles/openclaw-structured.css +266 -266
  130. package/web-ui/styles/plugins-panel.css +564 -564
  131. package/web-ui/styles/responsive.css +392 -454
  132. package/web-ui/styles/sessions-list.css +647 -417
  133. package/web-ui/styles/sessions-preview.css +407 -407
  134. package/web-ui/styles/sessions-toolbar-trash.css +518 -348
  135. package/web-ui/styles/sessions-usage.css +588 -1040
  136. package/web-ui/styles/settings-panel.css +349 -349
  137. package/web-ui/styles/skills-list.css +305 -305
  138. package/web-ui/styles/skills-market.css +429 -429
  139. package/web-ui/styles/task-orchestration.css +822 -822
  140. package/web-ui/styles/titles-cards.css +472 -472
  141. package/web-ui/styles/trash-panel.css +90 -90
  142. package/web-ui/styles/webhook.css +81 -81
  143. package/web-ui/styles.css +24 -24
  144. package/web-ui.html +17 -17
  145. package/web-ui/partials/index/panel-config-codex.html.bak +0 -337
@@ -1,482 +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
- 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
- }
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
+ }