codexmate 0.0.22 → 0.0.24

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 (66) hide show
  1. package/README.md +5 -3
  2. package/README.zh.md +8 -5
  3. package/cli/auth-profiles.js +23 -7
  4. package/cli/doctor-core.js +903 -0
  5. package/cli/import-skills-url.js +334 -0
  6. package/cli.js +304 -208
  7. package/lib/cli-models-utils.js +0 -40
  8. package/lib/cli-network-utils.js +28 -2
  9. package/package.json +5 -2
  10. package/plugins/README.md +20 -0
  11. package/plugins/README.zh-CN.md +20 -0
  12. package/plugins/prompt-templates/comment-polish/index.mjs +25 -0
  13. package/plugins/prompt-templates/computed.mjs +253 -0
  14. package/plugins/prompt-templates/index.mjs +8 -0
  15. package/plugins/prompt-templates/manifest.mjs +15 -0
  16. package/plugins/prompt-templates/methods.mjs +619 -0
  17. package/plugins/prompt-templates/overview.mjs +90 -0
  18. package/plugins/prompt-templates/ownership.mjs +19 -0
  19. package/plugins/prompt-templates/rule-ack/index.mjs +21 -0
  20. package/plugins/prompt-templates/storage.mjs +64 -0
  21. package/plugins/registry.mjs +16 -0
  22. package/res/logo-pack.webp +0 -0
  23. package/web-ui/app.js +68 -34
  24. package/web-ui/index.html +4 -3
  25. package/web-ui/modules/app.computed.dashboard.mjs +22 -22
  26. package/web-ui/modules/app.computed.main-tabs.mjs +9 -2
  27. package/web-ui/modules/app.methods.agents.mjs +91 -3
  28. package/web-ui/modules/app.methods.codex-config.mjs +153 -164
  29. package/web-ui/modules/app.methods.install.mjs +16 -0
  30. package/web-ui/modules/app.methods.navigation.mjs +76 -0
  31. package/web-ui/modules/app.methods.runtime.mjs +24 -2
  32. package/web-ui/modules/app.methods.session-browser.mjs +73 -1
  33. package/web-ui/modules/app.methods.startup-claude.mjs +12 -0
  34. package/web-ui/modules/app.methods.task-orchestration.mjs +96 -11
  35. package/web-ui/modules/config-mode.computed.mjs +1 -3
  36. package/web-ui/modules/i18n.dict.mjs +2039 -0
  37. package/web-ui/modules/i18n.mjs +2 -1555
  38. package/web-ui/modules/plugins.computed.mjs +2 -219
  39. package/web-ui/modules/plugins.methods.mjs +2 -619
  40. package/web-ui/modules/plugins.storage.mjs +11 -37
  41. package/web-ui/modules/sessions-filters-url.mjs +85 -0
  42. package/web-ui/partials/index/layout-header.html +38 -34
  43. package/web-ui/partials/index/modal-config-template-agents.html +3 -4
  44. package/web-ui/partials/index/modal-health-check.html +33 -60
  45. package/web-ui/partials/index/panel-config-claude.html +56 -15
  46. package/web-ui/partials/index/panel-config-codex.html +68 -19
  47. package/web-ui/partials/index/panel-config-openclaw.html +8 -3
  48. package/web-ui/partials/index/panel-dashboard.html +186 -0
  49. package/web-ui/partials/index/panel-docs.html +1 -1
  50. package/web-ui/partials/index/panel-market.html +3 -0
  51. package/web-ui/partials/index/panel-orchestration.html +105 -111
  52. package/web-ui/partials/index/panel-plugins.html +48 -12
  53. package/web-ui/partials/index/panel-sessions.html +12 -3
  54. package/web-ui/partials/index/panel-settings.html +1 -1
  55. package/web-ui/partials/index/panel-usage.html +7 -6
  56. package/web-ui/styles/controls-forms.css +16 -2
  57. package/web-ui/styles/dashboard.css +274 -0
  58. package/web-ui/styles/layout-shell.css +11 -5
  59. package/web-ui/styles/navigation-panels.css +8 -0
  60. package/web-ui/styles/plugins-panel.css +5 -0
  61. package/web-ui/styles/sessions-list.css +3 -3
  62. package/web-ui/styles/sessions-usage.css +37 -0
  63. package/web-ui/styles/skills-market.css +12 -2
  64. package/web-ui/styles/task-orchestration.css +57 -11
  65. package/web-ui/styles.css +1 -0
  66. package/res/logo.png +0 -0
@@ -1,620 +1,3 @@
1
- import {
2
- persistPromptTemplatesToStorage,
3
- readPromptTemplatesFromStorage
4
- } from './plugins.storage.mjs';
1
+ import { createPluginsMethods } from '../../plugins/prompt-templates/methods.mjs';
5
2
 
6
- function createId(prefix = 'tpl') {
7
- const rand = Math.random().toString(16).slice(2, 10);
8
- return `${prefix}_${Date.now().toString(16)}_${rand}`;
9
- }
10
-
11
- function nowIso() {
12
- return new Date().toISOString();
13
- }
14
-
15
- function normalizePromptTemplateDraft(draft) {
16
- const safe = draft && typeof draft === 'object' ? draft : {};
17
- return {
18
- id: typeof safe.id === 'string' ? safe.id : '',
19
- name: typeof safe.name === 'string' ? safe.name : '',
20
- description: typeof safe.description === 'string' ? safe.description : '',
21
- template: typeof safe.template === 'string' ? safe.template : '',
22
- createdAt: typeof safe.createdAt === 'string' ? safe.createdAt : '',
23
- updatedAt: typeof safe.updatedAt === 'string' ? safe.updatedAt : '',
24
- isBuiltin: safe.isBuiltin === true
25
- };
26
- }
27
-
28
- function buildBuiltinCommentPolishTemplate(t) {
29
- const tr = (key, fallback, params = null) => (typeof t === 'function' ? t(key, params) : fallback);
30
- const line1 = tr('plugins.builtin.commentPolish.line1', '轻微收敛以下代码注释');
31
- return {
32
- id: 'builtin_comment_polish',
33
- name: tr('plugins.builtin.commentPolish.name', '代码注释润色'),
34
- description: tr('plugins.builtin.commentPolish.desc', '轻微收敛以下代码注释 {{code}}'),
35
- template: [
36
- line1,
37
- '',
38
- '{{code}}'
39
- ].join('\n'),
40
- createdAt: nowIso(),
41
- updatedAt: nowIso(),
42
- isBuiltin: true
43
- };
44
- }
45
-
46
- function ensureBuiltinTemplates(rawList, builtins) {
47
- const list = Array.isArray(rawList) ? rawList.filter(Boolean) : [];
48
- const builtinList = Array.isArray(builtins) ? builtins.filter(Boolean) : [];
49
- // Built-ins are fixed and should not be overridden. Also, clean up any legacy built-ins
50
- // that may have been persisted previously.
51
- const rest = list.filter((item) => !(item && item.isBuiltin === true));
52
- return [...builtinList, ...rest];
53
- }
54
-
55
- export function createPluginsMethods() {
56
- return {
57
- resetPromptComposerVarValues() {
58
- this.promptComposerVarValuesRaw = {};
59
- if (typeof this.$nextTick === 'function') {
60
- this.$nextTick(() => {
61
- const first = this.$refs && this.$refs.promptComposerFirstField
62
- ? this.$refs.promptComposerFirstField
63
- : null;
64
- if (first && typeof first.focus === 'function') first.focus();
65
- });
66
- }
67
- },
68
-
69
- selectPromptComposerTemplate(id) {
70
- const next = typeof id === 'string' ? id.trim() : '';
71
- if (!next) return;
72
- if (next === this.promptComposerSelectedTemplateId) return;
73
- this.promptComposerSelectedTemplateId = next;
74
- // Reset values when switching template to avoid leaking unrelated vars.
75
- this.promptComposerVarValuesRaw = {};
76
- if (typeof this.$nextTick === 'function') {
77
- this.$nextTick(() => {
78
- const first = this.$refs && this.$refs.promptComposerFirstField
79
- ? this.$refs.promptComposerFirstField
80
- : null;
81
- if (first && typeof first.focus === 'function') first.focus();
82
- });
83
- }
84
- },
85
-
86
- onPromptComposerInput() {
87
- const raw = typeof this.promptComposerCommand === 'string' ? this.promptComposerCommand : '';
88
- const text = raw.trimStart();
89
- if (!text.startsWith('/')) {
90
- if (this.promptComposerPickerVisible) {
91
- this.promptComposerPickerVisible = false;
92
- }
93
- return;
94
- }
95
-
96
- const lower = text.toLowerCase();
97
- const isPluginCommand = lower.startsWith('/pl') || lower.startsWith('/plugin') || lower.startsWith('/plugins');
98
- if (!isPluginCommand) return;
99
-
100
- // Support "/plugin foo" to prefill search keyword with "foo"
101
- const after = text.replace(/^\/plugins?\b/i, '').trim();
102
- this.promptComposerPickerKeyword = after;
103
- if (!this.promptComposerPickerVisible) {
104
- this.openPromptComposerPicker({ keepKeyword: true });
105
- }
106
- },
107
-
108
- onPromptComposerKeydown(event) {
109
- const e = event || null;
110
- if (!e || e.key !== 'Enter') return;
111
- if (e.shiftKey) return;
112
- e.preventDefault();
113
-
114
- if (this.promptComposerPickerVisible) {
115
- const list = Array.isArray(this.promptComposerPickerList) ? this.promptComposerPickerList : [];
116
- if (list.length) {
117
- this.usePromptTemplateInComposer(list[0].id);
118
- }
119
- return;
120
- }
121
-
122
- const value = typeof this.promptComposerCommand === 'string' ? this.promptComposerCommand.trim() : '';
123
- const lower = value.toLowerCase();
124
- if (lower === '/plugin' || lower === '/plugins' || lower === '/pl') {
125
- this.openPromptComposerPicker();
126
- return;
127
- }
128
- },
129
-
130
- onPromptComposerPickerKeydown(event) {
131
- const e = event || null;
132
- if (!e) return;
133
- if (e.key === 'Enter' && !e.shiftKey) {
134
- e.preventDefault();
135
- const list = Array.isArray(this.promptComposerPickerList) ? this.promptComposerPickerList : [];
136
- if (list.length) {
137
- this.usePromptTemplateInComposer(list[0].id);
138
- }
139
- return;
140
- }
141
- if (e.key === 'Escape') {
142
- e.preventDefault();
143
- this.closePromptComposerPicker();
144
- }
145
- },
146
-
147
- openPromptComposerPicker(options = {}) {
148
- this.promptComposerPickerVisible = true;
149
- if (!(options && options.keepKeyword)) {
150
- this.promptComposerPickerKeyword = '';
151
- }
152
- if (typeof this.$nextTick === 'function') {
153
- this.$nextTick(() => {
154
- const input = this.$refs && this.$refs.promptComposerPickerSearch
155
- ? this.$refs.promptComposerPickerSearch
156
- : null;
157
- if (input && typeof input.focus === 'function') input.focus();
158
- });
159
- }
160
- },
161
-
162
- closePromptComposerPicker() {
163
- this.promptComposerPickerVisible = false;
164
- if (typeof this.$nextTick === 'function') {
165
- this.$nextTick(() => {
166
- const input = this.$refs && this.$refs.promptComposerCommandInput
167
- ? this.$refs.promptComposerCommandInput
168
- : null;
169
- if (input && typeof input.focus === 'function') input.focus();
170
- });
171
- }
172
- },
173
-
174
- usePromptTemplateInComposer(id) {
175
- const next = typeof id === 'string' ? id.trim() : '';
176
- if (!next) return;
177
- this.promptComposerSelectedTemplateId = next;
178
- this.promptComposerVarValuesRaw = {};
179
- this.promptComposerCommand = '';
180
- this.promptComposerPickerVisible = false;
181
- this.promptTemplatesMode = 'compose';
182
- if (typeof this.$nextTick === 'function') {
183
- this.$nextTick(() => {
184
- // Focus the first placeholder field if it exists.
185
- const firstVar = this.$refs && this.$refs.promptComposerFirstField
186
- ? this.$refs.promptComposerFirstField
187
- : null;
188
- if (firstVar && typeof firstVar.focus === 'function') firstVar.focus();
189
- });
190
- }
191
- },
192
-
193
- resetPromptComposer() {
194
- this.promptComposerCommand = '';
195
- this.promptComposerSelectedTemplateId = '';
196
- this.promptComposerVarValuesRaw = {};
197
- this.promptComposerPickerVisible = false;
198
- this.promptComposerPickerKeyword = '';
199
- },
200
-
201
- setPromptComposerVarValue(name, value) {
202
- const key = typeof name === 'string' ? name.trim() : '';
203
- if (!key) return;
204
- const current = this.promptComposerVarValuesRaw && typeof this.promptComposerVarValuesRaw === 'object'
205
- ? this.promptComposerVarValuesRaw
206
- : {};
207
- const next = { ...current };
208
- next[key] = value == null ? '' : String(value);
209
- this.promptComposerVarValuesRaw = next;
210
- },
211
-
212
- async copyPromptComposerRendered() {
213
- const text = typeof this.promptComposerRendered === 'string' ? this.promptComposerRendered.trim() : '';
214
- if (!text) {
215
- this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.empty') : 'Nothing to copy', 'info');
216
- return;
217
- }
218
- try {
219
- if (navigator.clipboard && window.isSecureContext) {
220
- await navigator.clipboard.writeText(text);
221
- this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
222
- return;
223
- }
224
- } catch (_) {}
225
- const ok = typeof this.fallbackCopyText === 'function' ? this.fallbackCopyText(text) : false;
226
- if (ok) {
227
- this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
228
- return;
229
- }
230
- this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.fail') : 'Copy failed', 'error');
231
- },
232
-
233
- selectPlugin(pluginId) {
234
- const id = typeof pluginId === 'string' ? pluginId.trim() : '';
235
- if (!id) return;
236
- this.pluginsActiveId = id;
237
- },
238
-
239
- async loadPluginsOverview(options = {}) {
240
- const silent = !!(options && options.silent);
241
- const forceRefresh = !!(options && options.forceRefresh);
242
- if (this.pluginsLoading) return false;
243
-
244
- const shouldReload = forceRefresh || this.promptTemplatesLoadedOnce !== true;
245
- if (!shouldReload) return true;
246
-
247
- this.pluginsLoading = true;
248
- try {
249
- const t = typeof this.t === 'function' ? this.t : null;
250
- const rawList = readPromptTemplatesFromStorage(localStorage);
251
- const normalized = ensureBuiltinTemplates(rawList, [buildBuiltinCommentPolishTemplate(t)]);
252
- this.promptTemplatesListRaw = normalized;
253
- // Keep built-in templates in sync (and ensure they exist).
254
- persistPromptTemplatesToStorage(normalized, localStorage);
255
-
256
- this.promptTemplatesLoadedOnce = true;
257
- if (!this.pluginsActiveId) {
258
- this.pluginsActiveId = 'prompt-templates';
259
- }
260
-
261
- if (!this.promptTemplatesMode) {
262
- this.promptTemplatesMode = 'compose';
263
- }
264
- if (this.promptTemplatesMode !== 'compose' && this.promptTemplatesMode !== 'manage') {
265
- this.promptTemplatesMode = 'compose';
266
- }
267
- if (this.mainTab === 'plugins') {
268
- // UX default: always start from Compose when user enters Plugins.
269
- this.promptTemplatesMode = 'compose';
270
- }
271
-
272
- // With a single built-in template, Compose should be ready-to-use without extra steps.
273
- if (this.mainTab === 'plugins' && this.promptTemplatesMode === 'compose') {
274
- const list = Array.isArray(this.promptTemplatesList) ? this.promptTemplatesList : [];
275
- const exists = list.some((item) => item && item.id === this.promptComposerSelectedTemplateId);
276
- if (!this.promptComposerSelectedTemplateId || !exists) {
277
- this.promptComposerSelectedTemplateId = 'builtin_comment_polish';
278
- }
279
- if (!this.promptComposerVarValuesRaw || typeof this.promptComposerVarValuesRaw !== 'object') {
280
- this.promptComposerVarValuesRaw = {};
281
- }
282
- }
283
-
284
- // In Compose mode we keep the flow lightweight and do not auto-select a template.
285
- // In Manage mode we can auto-select the first template for convenience.
286
- if (this.promptTemplatesMode === 'manage') {
287
- const currentSelected = typeof this.promptTemplateSelectedId === 'string'
288
- ? this.promptTemplateSelectedId
289
- : '';
290
- const first = Array.isArray(this.promptTemplatesList) && this.promptTemplatesList.length
291
- ? this.promptTemplatesList[0]
292
- : null;
293
- if (!currentSelected && first) {
294
- this.selectPromptTemplate(first.id);
295
- }
296
- }
297
-
298
- // When entering the Plugins tab, focus the command input by default (better UX).
299
- if (this.mainTab === 'plugins' && this.promptTemplatesMode === 'compose' && typeof this.$nextTick === 'function') {
300
- this.$nextTick(() => {
301
- const input = this.$refs && this.$refs.promptComposerCodeInput
302
- ? this.$refs.promptComposerCodeInput
303
- : null;
304
- if (input && typeof input.focus === 'function') input.focus();
305
- });
306
- }
307
- return true;
308
- } catch (e) {
309
- if (!silent) {
310
- this.showMessage(typeof this.t === 'function' ? this.t('toast.plugins.loadFail') : 'Failed to load plugins', 'error');
311
- }
312
- return false;
313
- } finally {
314
- this.pluginsLoading = false;
315
- }
316
- },
317
-
318
- selectPromptTemplate(id) {
319
- const next = typeof id === 'string' ? id.trim() : '';
320
- if (!next) return;
321
- const list = this.promptTemplatesList;
322
- const entry = list.find((item) => item.id === next);
323
- if (!entry) return;
324
- this.promptTemplateSelectedId = next;
325
- this.promptTemplatesMode = 'manage';
326
- this.promptTemplateDraftRaw = {
327
- id: entry.id,
328
- name: entry.name,
329
- description: entry.description,
330
- template: entry.template,
331
- createdAt: entry.createdAt,
332
- updatedAt: entry.updatedAt,
333
- isBuiltin: entry.isBuiltin === true
334
- };
335
- this.promptTemplateVarValuesRaw = {};
336
- },
337
-
338
- createPromptTemplate() {
339
- const id = createId('prompt');
340
- const name = typeof this.t === 'function'
341
- ? this.t('plugins.promptTemplates.manage.newTemplateName')
342
- : 'New template';
343
- const draft = {
344
- id,
345
- name,
346
- description: '',
347
- template: '',
348
- createdAt: nowIso(),
349
- updatedAt: nowIso(),
350
- isBuiltin: false
351
- };
352
- this.promptTemplateDraftRaw = draft;
353
- this.promptTemplateSelectedId = id;
354
- this.promptTemplateVarValuesRaw = {};
355
- },
356
-
357
- resetPromptVariableValues() {
358
- this.promptTemplateVarValuesRaw = {};
359
- },
360
-
361
- addPromptTemplateVariable() {
362
- const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
363
- if (!draft || !draft.id) return;
364
- if (draft.isBuiltin) {
365
- this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotEditable') : 'Built-in templates are not editable', 'error');
366
- return;
367
- }
368
- // Use project-style modal (no native prompt).
369
- this.promptTemplateVarDraftName = 'var';
370
- this.promptTemplateVarDraftError = '';
371
- this.showPromptTemplateVarModal = true;
372
- if (typeof this.$nextTick === 'function') {
373
- this.$nextTick(() => {
374
- const input = this.$refs && this.$refs.promptTemplateVarNameInput
375
- ? this.$refs.promptTemplateVarNameInput
376
- : null;
377
- if (input && typeof input.focus === 'function') input.focus();
378
- });
379
- }
380
- },
381
-
382
- closePromptTemplateVarModal() {
383
- this.showPromptTemplateVarModal = false;
384
- this.promptTemplateVarDraftError = '';
385
- },
386
-
387
- confirmAddPromptTemplateVariable() {
388
- const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
389
- if (!draft || !draft.id) return;
390
- if (draft.isBuiltin) {
391
- this.promptTemplateVarDraftError = typeof this.t === 'function'
392
- ? this.t('toast.templates.builtinNotEditable')
393
- : 'Built-in templates are not editable';
394
- return;
395
- }
396
- const key = typeof this.promptTemplateVarDraftName === 'string'
397
- ? this.promptTemplateVarDraftName.trim()
398
- : '';
399
- if (!key) {
400
- this.promptTemplateVarDraftError = typeof this.t === 'function'
401
- ? this.t('toast.templates.varNameRequired')
402
- : 'Variable name is required';
403
- return;
404
- }
405
- if (!/^[a-zA-Z0-9_.-]+$/.test(key)) {
406
- this.promptTemplateVarDraftError = typeof this.t === 'function'
407
- ? this.t('toast.templates.varNameInvalid')
408
- : 'Variable name may only contain letters, numbers, underscore, dash, dot';
409
- return;
410
- }
411
- const placeholder = `{{${key}}}`;
412
- const current = typeof draft.template === 'string' ? draft.template : '';
413
- if (current.includes(placeholder)) {
414
- this.promptTemplateVarDraftError = typeof this.t === 'function'
415
- ? this.t('toast.templates.varExists')
416
- : 'Variable already exists';
417
- return;
418
- }
419
- const nextText = current && !current.endsWith('\n')
420
- ? `${current}\n${placeholder}\n`
421
- : `${current}${placeholder}\n`;
422
- this.promptTemplateDraftRaw = { ...draft, template: nextText };
423
- this.showPromptTemplateVarModal = false;
424
- this.promptTemplateVarDraftError = '';
425
- this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.varAdded') : 'Variable added', 'success');
426
- },
427
-
428
- setPromptVariableValue(name, value) {
429
- const key = typeof name === 'string' ? name.trim() : '';
430
- if (!key) return;
431
- const next = { ...(this.promptTemplateVarValuesRaw && typeof this.promptTemplateVarValuesRaw === 'object' ? this.promptTemplateVarValuesRaw : {}) };
432
- next[key] = value == null ? '' : String(value);
433
- this.promptTemplateVarValuesRaw = next;
434
- },
435
-
436
- async copyRenderedPrompt() {
437
- const text = typeof this.renderedPrompt === 'string' ? this.renderedPrompt.trim() : '';
438
- if (!text) {
439
- this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.empty') : 'Nothing to copy', 'info');
440
- return;
441
- }
442
- try {
443
- if (navigator.clipboard && window.isSecureContext) {
444
- await navigator.clipboard.writeText(text);
445
- this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
446
- return;
447
- }
448
- } catch (_) {}
449
- const ok = typeof this.fallbackCopyText === 'function' ? this.fallbackCopyText(text) : false;
450
- if (ok) {
451
- this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.ok') : 'Copied', 'success');
452
- return;
453
- }
454
- this.showMessage(typeof this.t === 'function' ? this.t('toast.copy.fail') : 'Copy failed', 'error');
455
- },
456
-
457
- async savePromptTemplate() {
458
- const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
459
- if (draft.isBuiltin) {
460
- this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotModifiable') : 'Built-in templates are read-only. Duplicate first.', 'error');
461
- return false;
462
- }
463
- const name = draft.name.trim();
464
- if (!name) {
465
- this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.nameRequired') : 'Template name is required', 'error');
466
- return false;
467
- }
468
- const nextId = draft.id ? draft.id : createId('prompt');
469
- const list = Array.isArray(this.promptTemplatesListRaw) ? [...this.promptTemplatesListRaw] : [];
470
- const now = nowIso();
471
- const entry = {
472
- ...draft,
473
- id: nextId,
474
- name,
475
- updatedAt: now,
476
- createdAt: draft.createdAt || now,
477
- isBuiltin: draft.isBuiltin === true
478
- };
479
- const index = list.findIndex((item) => item && item.id === nextId);
480
- if (index >= 0) {
481
- list[index] = entry;
482
- } else {
483
- list.unshift(entry);
484
- }
485
- this.promptTemplatesListRaw = list;
486
- persistPromptTemplatesToStorage(list, localStorage);
487
- this.promptTemplateDraftRaw = entry;
488
- this.promptTemplateSelectedId = nextId;
489
- this.showMessage(typeof this.t === 'function' ? this.t('toast.save.ok') : 'Saved', 'success');
490
- return true;
491
- },
492
-
493
- duplicatePromptTemplate() {
494
- const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
495
- if (!draft.id) return;
496
- if (draft.isBuiltin) {
497
- this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotDuplicable') : 'Built-in templates cannot be duplicated', 'error');
498
- return;
499
- }
500
- const nextId = createId('prompt');
501
- this.promptTemplateDraftRaw = {
502
- ...draft,
503
- id: nextId,
504
- name: `${draft.name || 'Template'} (copy)`,
505
- createdAt: nowIso(),
506
- updatedAt: nowIso(),
507
- isBuiltin: false
508
- };
509
- this.promptTemplateSelectedId = nextId;
510
- this.promptTemplateVarValuesRaw = {};
511
- },
512
-
513
- async deletePromptTemplate() {
514
- const draft = normalizePromptTemplateDraft(this.promptTemplateDraftRaw);
515
- if (!draft.id) return;
516
- if (draft.isBuiltin) {
517
- this.showMessage(typeof this.t === 'function' ? this.t('toast.templates.builtinNotDeletable') : 'Built-in templates cannot be deleted', 'error');
518
- return;
519
- }
520
- const t = typeof this.t === 'function' ? this.t : null;
521
- const confirmed = await this.requestConfirmDialog({
522
- title: t ? t('toast.templates.deleteTitle') : 'Delete template',
523
- message: t ? t('toast.templates.deleteMessage', { name: draft.name || draft.id }) : `Delete “${draft.name || draft.id}”? This action cannot be undone.`,
524
- confirmText: t ? t('toast.templates.deleteConfirm') : 'Delete',
525
- cancelText: t ? t('toast.templates.deleteCancel') : 'Cancel',
526
- danger: true
527
- });
528
- if (!confirmed) return;
529
-
530
- const list = Array.isArray(this.promptTemplatesListRaw) ? this.promptTemplatesListRaw : [];
531
- const next = list.filter((item) => !(item && item.id === draft.id));
532
- this.promptTemplatesListRaw = next;
533
- persistPromptTemplatesToStorage(next, localStorage);
534
- this.promptTemplateDraftRaw = null;
535
- this.promptTemplateSelectedId = '';
536
- const first = this.promptTemplatesList && this.promptTemplatesList.length ? this.promptTemplatesList[0] : null;
537
- if (first) this.selectPromptTemplate(first.id);
538
- this.showMessage(typeof this.t === 'function' ? this.t('toast.delete.ok') : 'Deleted', 'success');
539
- },
540
-
541
- exportPromptTemplates() {
542
- const list = this.promptTemplatesList;
543
- if (!Array.isArray(list) || !list.length) {
544
- this.showMessage(typeof this.t === 'function' ? this.t('toast.export.empty') : 'Nothing to export', 'info');
545
- return;
546
- }
547
- const payload = JSON.stringify(list.map((item) => ({
548
- id: item.id,
549
- name: item.name,
550
- description: item.description,
551
- template: item.template,
552
- createdAt: item.createdAt,
553
- updatedAt: item.updatedAt,
554
- isBuiltin: item.isBuiltin
555
- })), null, 2);
556
- if (typeof this.downloadTextFile === 'function') {
557
- this.downloadTextFile(`prompt-templates-${Date.now()}.json`, payload, 'application/json;charset=utf-8');
558
- this.showMessage(typeof this.t === 'function' ? this.t('toast.export.ok') : 'Exported', 'success');
559
- return;
560
- }
561
- this.showMessage(typeof this.t === 'function' ? this.t('toast.export.notSupported') : 'Export not supported', 'error');
562
- },
563
-
564
- triggerPromptTemplatesImport() {
565
- const input = this.$refs && this.$refs.promptTemplatesImportInput
566
- ? this.$refs.promptTemplatesImportInput
567
- : null;
568
- if (!input) {
569
- this.showMessage(typeof this.t === 'function' ? this.t('toast.import.notAvailable') : 'Import is not available', 'error');
570
- return;
571
- }
572
- input.value = '';
573
- input.click();
574
- },
575
-
576
- async handlePromptTemplatesImportChange(event) {
577
- const input = event && event.target ? event.target : null;
578
- const file = input && input.files && input.files[0] ? input.files[0] : null;
579
- if (!file) return;
580
- let text = '';
581
- try {
582
- text = await file.text();
583
- } catch (_) {
584
- this.showMessage(typeof this.t === 'function' ? this.t('toast.import.readFileFail') : 'Failed to read file', 'error');
585
- return;
586
- }
587
- let parsed;
588
- try {
589
- parsed = JSON.parse(text);
590
- } catch (_) {
591
- this.showMessage(typeof this.t === 'function' ? this.t('toast.import.invalidJson') : 'Invalid JSON', 'error');
592
- return;
593
- }
594
- if (!Array.isArray(parsed)) {
595
- this.showMessage(typeof this.t === 'function' ? this.t('toast.import.expectedArray') : 'Expected an array', 'error');
596
- return;
597
- }
598
- const list = Array.isArray(this.promptTemplatesListRaw) ? [...this.promptTemplatesListRaw] : [];
599
- for (const item of parsed) {
600
- const draft = normalizePromptTemplateDraft(item);
601
- if (!draft.name || !draft.template) continue;
602
- const id = draft.id ? draft.id : createId('prompt');
603
- const now = nowIso();
604
- const entry = {
605
- ...draft,
606
- id,
607
- createdAt: draft.createdAt || now,
608
- updatedAt: now,
609
- isBuiltin: false
610
- };
611
- const index = list.findIndex((existing) => existing && existing.id === id);
612
- if (index >= 0) list[index] = entry;
613
- else list.unshift(entry);
614
- }
615
- this.promptTemplatesListRaw = list;
616
- persistPromptTemplatesToStorage(list, localStorage);
617
- this.showMessage(typeof this.t === 'function' ? this.t('toast.import.ok') : 'Imported', 'success');
618
- }
619
- };
620
- }
3
+ export { createPluginsMethods };
@@ -1,37 +1,11 @@
1
- const STORAGE_KEY = 'codexmate.plugins.promptTemplates.v1';
2
-
3
- export function readPromptTemplatesFromStorage(storage = localStorage) {
4
- if (!storage) return [];
5
- let raw = '';
6
- try {
7
- raw = storage.getItem(STORAGE_KEY) || '';
8
- } catch (_) {
9
- raw = '';
10
- }
11
- if (!raw) return [];
12
- try {
13
- const parsed = JSON.parse(raw);
14
- if (!Array.isArray(parsed)) return [];
15
- return parsed;
16
- } catch (_) {
17
- return [];
18
- }
19
- }
20
-
21
- export function persistPromptTemplatesToStorage(list, storage = localStorage) {
22
- if (!storage) return false;
23
- try {
24
- storage.setItem(STORAGE_KEY, JSON.stringify(Array.isArray(list) ? list : []));
25
- return true;
26
- } catch (_) {
27
- return false;
28
- }
29
- }
30
-
31
- export function clearPromptTemplatesStorage(storage = localStorage) {
32
- if (!storage) return;
33
- try {
34
- storage.removeItem(STORAGE_KEY);
35
- } catch (_) {}
36
- }
37
-
1
+ import {
2
+ readPromptTemplatesFromStorage,
3
+ persistPromptTemplatesToStorage,
4
+ clearPromptTemplatesStorage
5
+ } from '../../plugins/prompt-templates/storage.mjs';
6
+
7
+ export {
8
+ readPromptTemplatesFromStorage,
9
+ persistPromptTemplatesToStorage,
10
+ clearPromptTemplatesStorage
11
+ };