codexmate 0.0.25 → 0.0.26

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 (135) hide show
  1. package/README.md +416 -413
  2. package/README.zh.md +349 -346
  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 +1079 -1079
  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 +997 -997
  13. package/cli/openclaw-config.js +629 -629
  14. package/cli/session-convert-args.js +65 -0
  15. package/cli/session-convert-io.js +82 -0
  16. package/cli/session-convert.js +43 -0
  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 +15218 -14736
  23. package/lib/automation.js +404 -404
  24. package/lib/cli-file-utils.js +151 -151
  25. package/lib/cli-models-utils.js +379 -379
  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/download-artifacts.js +92 -92
  32. package/lib/mcp-stdio.js +453 -453
  33. package/lib/task-orchestrator.js +869 -869
  34. package/lib/text-diff.js +303 -303
  35. package/lib/workflow-engine.js +340 -340
  36. package/package.json +74 -74
  37. package/plugins/README.md +20 -20
  38. package/plugins/README.zh-CN.md +20 -20
  39. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  40. package/plugins/prompt-templates/computed.mjs +253 -253
  41. package/plugins/prompt-templates/index.mjs +8 -8
  42. package/plugins/prompt-templates/manifest.mjs +15 -15
  43. package/plugins/prompt-templates/methods.mjs +619 -619
  44. package/plugins/prompt-templates/overview.mjs +90 -90
  45. package/plugins/prompt-templates/ownership.mjs +19 -19
  46. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  47. package/plugins/prompt-templates/storage.mjs +64 -64
  48. package/plugins/registry.mjs +16 -16
  49. package/web-ui/app.js +625 -612
  50. package/web-ui/index.html +35 -35
  51. package/web-ui/logic.agents-diff.mjs +386 -386
  52. package/web-ui/logic.claude.mjs +168 -168
  53. package/web-ui/logic.mjs +5 -5
  54. package/web-ui/logic.runtime.mjs +128 -128
  55. package/web-ui/logic.session-convert.mjs +70 -0
  56. package/web-ui/logic.sessions.mjs +709 -614
  57. package/web-ui/modules/api.mjs +90 -90
  58. package/web-ui/modules/app.computed.dashboard.mjs +171 -128
  59. package/web-ui/modules/app.computed.index.mjs +17 -17
  60. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  61. package/web-ui/modules/app.computed.session.mjs +946 -670
  62. package/web-ui/modules/app.constants.mjs +15 -15
  63. package/web-ui/modules/app.methods.agents.mjs +632 -632
  64. package/web-ui/modules/app.methods.claude-config.mjs +179 -174
  65. package/web-ui/modules/app.methods.codex-config.mjs +860 -784
  66. package/web-ui/modules/app.methods.index.mjs +92 -92
  67. package/web-ui/modules/app.methods.install.mjs +205 -205
  68. package/web-ui/modules/app.methods.navigation.mjs +743 -695
  69. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  70. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  71. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  72. package/web-ui/modules/app.methods.providers.mjs +404 -404
  73. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  74. package/web-ui/modules/app.methods.session-actions.mjs +596 -544
  75. package/web-ui/modules/app.methods.session-browser.mjs +985 -722
  76. package/web-ui/modules/app.methods.session-timeline.mjs +479 -448
  77. package/web-ui/modules/app.methods.session-trash.mjs +424 -424
  78. package/web-ui/modules/app.methods.startup-claude.mjs +522 -417
  79. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  80. package/web-ui/modules/config-mode.computed.mjs +124 -124
  81. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  82. package/web-ui/modules/i18n.dict.mjs +2113 -2055
  83. package/web-ui/modules/i18n.mjs +56 -56
  84. package/web-ui/modules/plugins.computed.mjs +3 -3
  85. package/web-ui/modules/plugins.methods.mjs +3 -3
  86. package/web-ui/modules/plugins.storage.mjs +11 -11
  87. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  88. package/web-ui/modules/skills.computed.mjs +107 -107
  89. package/web-ui/modules/skills.methods.mjs +481 -481
  90. package/web-ui/partials/index/layout-footer.html +13 -13
  91. package/web-ui/partials/index/layout-header.html +475 -475
  92. package/web-ui/partials/index/modal-config-template-agents.html +174 -174
  93. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  94. package/web-ui/partials/index/modal-health-check.html +45 -45
  95. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  96. package/web-ui/partials/index/modal-skills.html +200 -200
  97. package/web-ui/partials/index/modals-basic.html +165 -165
  98. package/web-ui/partials/index/panel-config-claude.html +184 -179
  99. package/web-ui/partials/index/panel-config-codex.html +283 -283
  100. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  101. package/web-ui/partials/index/panel-dashboard.html +186 -186
  102. package/web-ui/partials/index/panel-docs.html +147 -147
  103. package/web-ui/partials/index/panel-market.html +177 -177
  104. package/web-ui/partials/index/panel-orchestration.html +391 -391
  105. package/web-ui/partials/index/panel-plugins.html +279 -279
  106. package/web-ui/partials/index/panel-sessions.html +326 -303
  107. package/web-ui/partials/index/panel-settings.html +258 -258
  108. package/web-ui/partials/index/panel-usage.html +342 -361
  109. package/web-ui/res/json5.min.js +1 -1
  110. package/web-ui/res/vue.global.prod.js +13 -13
  111. package/web-ui/session-helpers.mjs +576 -573
  112. package/web-ui/source-bundle.cjs +233 -233
  113. package/web-ui/styles/base-theme.css +268 -264
  114. package/web-ui/styles/controls-forms.css +423 -423
  115. package/web-ui/styles/dashboard.css +274 -274
  116. package/web-ui/styles/docs-panel.css +247 -247
  117. package/web-ui/styles/feedback.css +108 -108
  118. package/web-ui/styles/health-check-dialog.css +144 -144
  119. package/web-ui/styles/layout-shell.css +603 -603
  120. package/web-ui/styles/modals-core.css +464 -464
  121. package/web-ui/styles/navigation-panels.css +390 -390
  122. package/web-ui/styles/openclaw-structured.css +266 -266
  123. package/web-ui/styles/plugins-panel.css +523 -523
  124. package/web-ui/styles/responsive.css +454 -454
  125. package/web-ui/styles/sessions-list.css +415 -398
  126. package/web-ui/styles/sessions-preview.css +411 -411
  127. package/web-ui/styles/sessions-toolbar-trash.css +330 -268
  128. package/web-ui/styles/sessions-usage.css +945 -912
  129. package/web-ui/styles/settings-panel.css +166 -166
  130. package/web-ui/styles/skills-list.css +303 -303
  131. package/web-ui/styles/skills-market.css +406 -406
  132. package/web-ui/styles/task-orchestration.css +822 -822
  133. package/web-ui/styles/titles-cards.css +408 -408
  134. package/web-ui/styles.css +21 -21
  135. package/web-ui.html +17 -17
@@ -1,544 +1,596 @@
1
- import {
2
- normalizeConfigTemplateDiffConfirmEnabled,
3
- persistConfigTemplateDiffConfirmEnabledToStorage
4
- } from './config-template-confirm-pref.mjs';
5
-
6
- export function createSessionActionMethods(options = {}) {
7
- const {
8
- api,
9
- apiBase
10
- } = options;
11
-
12
- return {
13
- getSessionStandaloneContext() {
14
- try {
15
- const url = new URL(window.location.href);
16
- if (url.pathname !== '/session') {
17
- return { requested: false, params: null, error: '' };
18
- }
19
-
20
- const source = (url.searchParams.get('source') || '').trim().toLowerCase();
21
- const sessionId = (url.searchParams.get('sessionId') || url.searchParams.get('id') || '').trim();
22
- const filePath = (url.searchParams.get('filePath') || url.searchParams.get('path') || '').trim();
23
- let error = '';
24
- if (!source) {
25
- error = '缺少 source 参数';
26
- } else if (source !== 'codex' && source !== 'claude') {
27
- error = 'source 仅支持 codex 或 claude';
28
- }
29
- if (!sessionId && !filePath) {
30
- error = error ? `${error},还缺少 sessionId 或 filePath` : '缺少 sessionId 或 filePath 参数';
31
- }
32
-
33
- if (error) {
34
- return { requested: true, params: null, error };
35
- }
36
-
37
- return {
38
- requested: true,
39
- params: {
40
- source,
41
- sessionId,
42
- filePath
43
- },
44
- error: ''
45
- };
46
- } catch (_) {
47
- return { requested: false, params: null, error: '' };
48
- }
49
- },
50
-
51
- initSessionStandalone() {
52
- const context = this.getSessionStandaloneContext();
53
- if (!context.requested) return;
54
-
55
- this.sessionStandalone = true;
56
- this.mainTab = 'sessions';
57
- this.prepareSessionTabRender();
58
-
59
- if (context.error || !context.params) {
60
- this.sessionStandaloneError = `会话链接参数不完整:${context.error || '参数解析失败'}`;
61
- return;
62
- }
63
-
64
- const sourceLabel = context.params.source === 'codex' ? 'Codex' : 'Claude Code';
65
- this.activeSession = {
66
- source: context.params.source,
67
- sourceLabel,
68
- sessionId: context.params.sessionId,
69
- filePath: context.params.filePath,
70
- title: context.params.sessionId || context.params.filePath || '会话'
71
- };
72
- this.activeSessionMessages = [];
73
- this.activeSessionDetailError = '';
74
- this.activeSessionDetailClipped = false;
75
- this.cancelSessionTimelineSync();
76
- this.sessionTimelineActiveKey = '';
77
- this.clearSessionTimelineRefs();
78
- this.sessionStandaloneError = '';
79
- this.sessionStandaloneText = '';
80
- this.sessionStandaloneTitle = this.activeSession.title || '会话';
81
- this.sessionStandaloneSourceLabel = sourceLabel;
82
- this.loadSessionStandalonePlain();
83
- },
84
-
85
- buildSessionStandaloneUrl(session) {
86
- if (!session) return '';
87
- const source = typeof session.source === 'string' ? session.source.trim().toLowerCase() : '';
88
- if (!source || (source !== 'codex' && source !== 'claude')) return '';
89
- const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
90
- const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
91
- if (!sessionId && !filePath) return '';
92
- const origin = window.location.origin && window.location.origin !== 'null'
93
- ? window.location.origin
94
- : (typeof apiBase === 'string' ? apiBase.trim() : '');
95
- if (!origin) return '';
96
- const params = new URLSearchParams();
97
- params.set('source', source);
98
- if (sessionId) params.set('sessionId', sessionId);
99
- if (filePath) params.set('filePath', filePath);
100
- return `${origin}/session?${params.toString()}`;
101
- },
102
-
103
- openSessionStandalone(session) {
104
- const url = this.buildSessionStandaloneUrl(session);
105
- if (!url) {
106
- this.showMessage('无法生成链接', 'error');
107
- return;
108
- }
109
- window.open(url, '_blank', 'noopener');
110
- },
111
-
112
- getSessionExportKey(session) {
113
- return `${session.source || 'unknown'}:${session.sessionId || ''}:${session.filePath || ''}`;
114
- },
115
-
116
- isResumeCommandAvailable(session) {
117
- if (!session) return false;
118
- const source = String(session.source || '').trim().toLowerCase();
119
- const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
120
- return (source === 'codex' || source === 'codebuddy' || source === 'gemini') && !!sessionId;
121
- },
122
-
123
- isCloneAvailable(session) {
124
- if (!session) return false;
125
- const source = String(session.source || '').trim().toLowerCase();
126
- const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
127
- const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
128
- return source === 'codex' && (!!sessionId || !!filePath);
129
- },
130
-
131
- isDeleteAvailable(session) {
132
- if (!session) return false;
133
- const source = String(session.source || '').trim().toLowerCase();
134
- if (source !== 'codex' && source !== 'claude') return false;
135
- const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
136
- const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
137
- return !!sessionId || !!filePath;
138
- },
139
-
140
- buildResumeCommand(session) {
141
- const source = session && session.source ? String(session.source).trim().toLowerCase() : '';
142
- const sessionId = session && session.sessionId ? String(session.sessionId).trim() : '';
143
- const arg = this.quoteResumeArg(sessionId);
144
- if (source === 'codebuddy') {
145
- return `codebuddy -r ${arg}`;
146
- }
147
- if (source === 'gemini') {
148
- return `gemini -r ${arg}`;
149
- }
150
- if (this.sessionResumeWithYolo) {
151
- return `codex --yolo resume ${arg}`;
152
- }
153
- return `codex resume ${arg}`;
154
- },
155
-
156
- quoteShellArg(value) {
157
- const text = typeof value === 'string' ? value : String(value || '');
158
- if (!text) return "''";
159
- if (/^[a-zA-Z0-9._-]+$/.test(text)) return text;
160
- const escaped = text.replace(/'/g, "'\\''");
161
- return `'${escaped}'`;
162
- },
163
-
164
- quoteResumeArg(value) {
165
- return this.quoteShellArg(value);
166
- },
167
-
168
- normalizeShareCommandPrefix(value) {
169
- const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
170
- if (normalized === 'codexmate') {
171
- return 'codexmate';
172
- }
173
- return 'npm start';
174
- },
175
-
176
- normalizeSessionTrashEnabled(value) {
177
- if (value === false) return false;
178
- const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
179
- if (normalized === '0' || normalized === 'false' || normalized === 'off' || normalized === 'no') {
180
- return false;
181
- }
182
- return true;
183
- },
184
-
185
- normalizeConfigTemplateDiffConfirmEnabled(value) {
186
- return normalizeConfigTemplateDiffConfirmEnabled(value);
187
- },
188
-
189
- setSessionTrashEnabled(value) {
190
- const enabled = this.normalizeSessionTrashEnabled(value);
191
- this.sessionTrashEnabled = enabled;
192
- try {
193
- localStorage.setItem('codexmateSessionTrashEnabled', enabled ? 'true' : 'false');
194
- } catch (_) {}
195
- },
196
-
197
- setConfigTemplateDiffConfirmEnabled(value) {
198
- const enabled = this.normalizeConfigTemplateDiffConfirmEnabled(value);
199
- this.configTemplateDiffConfirmEnabled = enabled;
200
- persistConfigTemplateDiffConfirmEnabledToStorage(enabled);
201
- },
202
-
203
- getShareCommandPrefixInvocation() {
204
- const prefix = this.normalizeShareCommandPrefix(this.shareCommandPrefix);
205
- return prefix === 'codexmate' ? 'codexmate' : 'npm start';
206
- },
207
-
208
- setShareCommandPrefix(value) {
209
- const normalized = this.normalizeShareCommandPrefix(value);
210
- this.shareCommandPrefix = normalized;
211
- try {
212
- localStorage.setItem('codexmateShareCommandPrefix', normalized);
213
- } catch (_) {}
214
- },
215
-
216
- fallbackCopyText(text) {
217
- let textarea = null;
218
- try {
219
- textarea = document.createElement('textarea');
220
- textarea.value = text;
221
- textarea.setAttribute('readonly', '');
222
- textarea.style.position = 'fixed';
223
- textarea.style.top = '-9999px';
224
- textarea.style.left = '-9999px';
225
- textarea.style.opacity = '0';
226
- document.body.appendChild(textarea);
227
- textarea.select();
228
- textarea.setSelectionRange(0, textarea.value.length);
229
- return document.execCommand('copy');
230
- } catch (_) {
231
- return false;
232
- } finally {
233
- if (textarea && textarea.parentNode) {
234
- textarea.parentNode.removeChild(textarea);
235
- }
236
- }
237
- },
238
-
239
- copyAgentsContent() {
240
- const text = typeof this.agentsContent === 'string' ? this.agentsContent : '';
241
- if (!text) {
242
- this.showMessage('没有可复制内容', 'info');
243
- return;
244
- }
245
- const ok = this.fallbackCopyText(text);
246
- if (ok) {
247
- this.showMessage('已复制', 'success');
248
- return;
249
- }
250
- this.showMessage('复制失败', 'error');
251
- },
252
-
253
- exportAgentsContent() {
254
- const text = typeof this.agentsContent === 'string' ? this.agentsContent : '';
255
- if (!text) {
256
- this.showMessage('没有可导出内容', 'info');
257
- return;
258
- }
259
- const now = new Date();
260
- const year = String(now.getFullYear());
261
- const month = String(now.getMonth() + 1).padStart(2, '0');
262
- const day = String(now.getDate()).padStart(2, '0');
263
- const hour = String(now.getHours()).padStart(2, '0');
264
- const minute = String(now.getMinutes()).padStart(2, '0');
265
- const second = String(now.getSeconds()).padStart(2, '0');
266
- const fileName = `agent-${year}${month}${day}-${hour}${minute}${second}.txt`;
267
- this.downloadTextFile(fileName, text, 'text/plain;charset=utf-8');
268
- this.showMessage(`已导出 ${fileName}`, 'success');
269
- },
270
-
271
- async copyInstallCommand(cmd) {
272
- const text = typeof cmd === 'string' ? cmd.trim() : '';
273
- if (!text) {
274
- this.showMessage('没有可复制内容', 'info');
275
- return;
276
- }
277
- try {
278
- if (navigator.clipboard && window.isSecureContext) {
279
- await navigator.clipboard.writeText(text);
280
- this.showMessage('已复制命令', 'success');
281
- return;
282
- }
283
- } catch (_) {}
284
- const ok = this.fallbackCopyText(text);
285
- if (ok) {
286
- this.showMessage('已复制命令', 'success');
287
- return;
288
- }
289
- this.showMessage('复制失败', 'error');
290
- },
291
-
292
- async copyResumeCommand(session) {
293
- if (!this.isResumeCommandAvailable(session)) {
294
- this.showMessage('不支持此操作', 'error');
295
- return;
296
- }
297
- const command = this.buildResumeCommand(session);
298
- const ok = this.fallbackCopyText(command);
299
- if (ok) {
300
- this.showMessage('已复制', 'success');
301
- return;
302
- }
303
- try {
304
- if (navigator.clipboard && window.isSecureContext) {
305
- await navigator.clipboard.writeText(command);
306
- this.showMessage('已复制', 'success');
307
- return;
308
- }
309
- } catch (_) {}
310
- this.showMessage('复制失败', 'error');
311
- },
312
-
313
- buildProviderShareCommand(payload) {
314
- if (!payload || typeof payload !== 'object') return '';
315
- const name = typeof payload.name === 'string' ? payload.name.trim() : '';
316
- const baseUrl = typeof payload.baseUrl === 'string' ? payload.baseUrl.trim() : '';
317
- const apiKey = typeof payload.apiKey === 'string' ? payload.apiKey : '';
318
- const model = typeof payload.model === 'string' ? payload.model.trim() : '';
319
- const bridge = typeof payload.bridge === 'string' ? payload.bridge.trim() : '';
320
- if (!name || !baseUrl) return '';
321
-
322
- const cli = this.getShareCommandPrefixInvocation();
323
- const nameArg = this.quoteShellArg(name);
324
- const urlArg = this.quoteShellArg(baseUrl);
325
- const keyArg = apiKey ? this.quoteShellArg(apiKey) : '';
326
- const switchCmd = `${cli} switch ${nameArg}`;
327
- const bridgeArgs = bridge ? ` --bridge ${this.quoteShellArg(bridge)}` : '';
328
- const addCmd = apiKey
329
- ? `${cli} add ${nameArg} ${urlArg} ${keyArg}${bridgeArgs}`
330
- : `${cli} add ${nameArg} ${urlArg}${bridgeArgs}`;
331
- const modelCmd = model ? ` && ${cli} use ${this.quoteShellArg(model)}` : '';
332
- return `${addCmd} && ${switchCmd}${modelCmd}`;
333
- },
334
-
335
- buildClaudeShareCommand(payload) {
336
- if (!payload || typeof payload !== 'object') return '';
337
- const baseUrl = typeof payload.baseUrl === 'string' ? payload.baseUrl.trim() : '';
338
- const apiKey = typeof payload.apiKey === 'string' ? payload.apiKey : '';
339
- const model = typeof payload.model === 'string' && payload.model.trim()
340
- ? payload.model.trim()
341
- : 'glm-4.7';
342
- if (!baseUrl || !apiKey) return '';
343
- const urlArg = this.quoteShellArg(baseUrl);
344
- const keyArg = this.quoteShellArg(apiKey);
345
- const modelArg = this.quoteShellArg(model);
346
- return `${this.getShareCommandPrefixInvocation()} claude ${urlArg} ${keyArg} ${modelArg}`;
347
- },
348
-
349
- async copyProviderShareCommand(provider) {
350
- const name = provider && typeof provider.name === 'string' ? provider.name.trim() : '';
351
- if (!name) {
352
- this.showMessage('参数无效', 'error');
353
- return;
354
- }
355
- if (!this.shouldAllowProviderShare(provider)) {
356
- this.showMessage('不可分享', 'info');
357
- return;
358
- }
359
- if (this.providerShareLoading[name]) {
360
- return;
361
- }
362
- this.providerShareLoading[name] = true;
363
- try {
364
- const res = await api('export-provider', { name });
365
- if (res && res.error) {
366
- this.showMessage(res.error, 'error');
367
- return;
368
- }
369
- const command = this.buildProviderShareCommand(res && res.payload ? res.payload : null);
370
- if (!command) {
371
- this.showMessage('生成命令失败', 'error');
372
- return;
373
- }
374
- const ok = this.fallbackCopyText(command);
375
- if (ok) {
376
- this.showMessage('已复制', 'success');
377
- return;
378
- }
379
- try {
380
- if (navigator.clipboard && window.isSecureContext) {
381
- await navigator.clipboard.writeText(command);
382
- this.showMessage('已复制', 'success');
383
- return;
384
- }
385
- } catch (_) {}
386
- this.showMessage('复制失败', 'error');
387
- } catch (_) {
388
- this.showMessage('生成命令失败', 'error');
389
- } finally {
390
- this.providerShareLoading[name] = false;
391
- }
392
- },
393
-
394
- async copyClaudeShareCommand(name) {
395
- const config = this.claudeConfigs[name];
396
- if (!config) {
397
- this.showMessage('配置不存在', 'error');
398
- return;
399
- }
400
- if (this.claudeShareLoading[name]) return;
401
- this.claudeShareLoading[name] = true;
402
- try {
403
- const res = await api('export-claude-share', { config });
404
- if (res && res.error) {
405
- this.showMessage(res.error, 'error');
406
- return;
407
- }
408
- const command = this.buildClaudeShareCommand(res && res.payload ? res.payload : null);
409
- if (!command) {
410
- this.showMessage('生成命令失败', 'error');
411
- return;
412
- }
413
- const ok = this.fallbackCopyText(command);
414
- if (ok) {
415
- this.showMessage('已复制', 'success');
416
- return;
417
- }
418
- try {
419
- if (navigator.clipboard && window.isSecureContext) {
420
- await navigator.clipboard.writeText(command);
421
- this.showMessage('已复制', 'success');
422
- return;
423
- }
424
- } catch (_) {}
425
- this.showMessage('复制失败', 'error');
426
- } catch (_) {
427
- this.showMessage('生成命令失败', 'error');
428
- } finally {
429
- this.claudeShareLoading[name] = false;
430
- }
431
- },
432
-
433
- async cloneSession(session) {
434
- if (!this.isCloneAvailable(session)) {
435
- this.showMessage('不支持此操作', 'error');
436
- return;
437
- }
438
- const key = this.getSessionExportKey(session);
439
- if (this.sessionCloning[key]) {
440
- return;
441
- }
442
- this.sessionCloning[key] = true;
443
- try {
444
- const res = await api('clone-session', {
445
- source: session.source,
446
- sessionId: session.sessionId,
447
- filePath: session.filePath
448
- });
449
- if (res.error) {
450
- this.showMessage(res.error, 'error');
451
- return;
452
- }
453
-
454
- this.showMessage('操作成功', 'success');
455
- if (typeof this.invalidateSessionsUsageData === 'function') {
456
- this.invalidateSessionsUsageData({ preserveList: true });
457
- }
458
- try {
459
- await this.loadSessions();
460
- if (res.sessionId) {
461
- const matched = this.sessionsList.find(item => item.source === 'codex' && item.sessionId === res.sessionId);
462
- if (matched) {
463
- await this.selectSession(matched);
464
- }
465
- }
466
- } catch (_) {
467
- // The clone already succeeded remotely; keep the success result.
468
- }
469
- } catch (_) {
470
- this.showMessage('克隆失败', 'error');
471
- } finally {
472
- this.sessionCloning[key] = false;
473
- }
474
- },
475
-
476
- async deleteSession(session) {
477
- if (!this.isDeleteAvailable(session)) {
478
- this.showMessage('不支持此操作', 'error');
479
- return;
480
- }
481
- const useTrash = this.sessionTrashEnabled !== false;
482
- if (!useTrash && typeof this.requestConfirmDialog === 'function') {
483
- const confirmed = await this.requestConfirmDialog({
484
- title: '直接删除会话',
485
- message: '关闭回收站后,删除会话将直接永久删除,且无法恢复。',
486
- confirmText: '直接删除',
487
- cancelText: '取消',
488
- danger: true
489
- });
490
- if (!confirmed) {
491
- return;
492
- }
493
- }
494
- const key = this.getSessionExportKey(session);
495
- if (this.sessionDeleting[key]) {
496
- return;
497
- }
498
- this.sessionDeleting[key] = true;
499
- try {
500
- const action = useTrash ? 'trash-session' : 'delete-session';
501
- const res = await api(action, {
502
- source: session.source,
503
- sessionId: session.sessionId,
504
- filePath: session.filePath
505
- });
506
- if (!res || res.error) {
507
- this.showMessage((res && res.error) || '删除失败', 'error');
508
- return;
509
- }
510
- this.removeSessionPin(session);
511
- if (useTrash) {
512
- this.invalidateSessionTrashRequests();
513
- this.showMessage('已移入回收站', 'success');
514
- if (this.sessionTrashLoadedOnce) {
515
- this.prependSessionTrashItem(this.buildSessionTrashItemFromSession(session, res), {
516
- totalCount: res && res.totalCount !== undefined ? res.totalCount : undefined
517
- });
518
- } else {
519
- this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
520
- res && res.totalCount !== undefined
521
- ? res.totalCount
522
- : (this.normalizeSessionTrashTotalCount(this.sessionTrashTotalCount, this.sessionTrashItems) + 1),
523
- this.sessionTrashItems
524
- );
525
- }
526
- } else {
527
- this.showMessage('已删除', 'success');
528
- }
529
- if (typeof this.invalidateSessionsUsageData === 'function') {
530
- this.invalidateSessionsUsageData({ preserveList: true });
531
- }
532
- try {
533
- await this.removeSessionFromCurrentList(session);
534
- } catch (_) {
535
- // The delete already succeeded remotely; keep the success result.
536
- }
537
- } catch (_) {
538
- this.showMessage('删除失败', 'error');
539
- } finally {
540
- this.sessionDeleting[key] = false;
541
- }
542
- }
543
- };
544
- }
1
+ import {
2
+ normalizeConfigTemplateDiffConfirmEnabled,
3
+ persistConfigTemplateDiffConfirmEnabledToStorage
4
+ } from './config-template-confirm-pref.mjs';
5
+
6
+ export function createSessionActionMethods(options = {}) {
7
+ const {
8
+ api,
9
+ apiBase
10
+ } = options;
11
+
12
+ return {
13
+ isDerivedSessionId(value) {
14
+ const sessionId = typeof value === 'string' ? value.trim() : String(value || '');
15
+ if (!sessionId) return false;
16
+ return /-\d{8}-\d{6}-[0-9a-f]{6}$/i.test(sessionId);
17
+ },
18
+
19
+ isDerivedSession(session) {
20
+ if (!session || typeof session !== 'object') return false;
21
+ if (session.derived === true) return true;
22
+ if (this.isDerivedSessionId(session.sessionId)) return true;
23
+ const rawFilePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
24
+ if (!rawFilePath) return false;
25
+ const normalized = rawFilePath.replace(/\\/g, '/');
26
+ if (normalized.includes('/.codexmate/sessions/derived/')) return true;
27
+ if (normalized.includes('/codexmate-derived/')) return true;
28
+ return false;
29
+ },
30
+
31
+ getSessionStandaloneContext() {
32
+ try {
33
+ const url = new URL(window.location.href);
34
+ if (url.pathname !== '/session') {
35
+ return { requested: false, params: null, error: '' };
36
+ }
37
+
38
+ const source = (url.searchParams.get('source') || '').trim().toLowerCase();
39
+ const sessionId = (url.searchParams.get('sessionId') || url.searchParams.get('id') || '').trim();
40
+ const filePath = (url.searchParams.get('filePath') || url.searchParams.get('path') || '').trim();
41
+ const maxMessagesRaw = (url.searchParams.get('maxMessages') || '').trim();
42
+ const maxMessages = Number(maxMessagesRaw);
43
+ let error = '';
44
+ if (!source) {
45
+ error = '缺少 source 参数';
46
+ } else if (source !== 'codex' && source !== 'claude') {
47
+ error = 'source 仅支持 codex claude';
48
+ }
49
+ if (!sessionId && !filePath) {
50
+ error = error ? `${error},还缺少 sessionId 或 filePath` : '缺少 sessionId 或 filePath 参数';
51
+ }
52
+
53
+ if (error) {
54
+ return { requested: true, params: null, error };
55
+ }
56
+
57
+ return {
58
+ requested: true,
59
+ params: {
60
+ source,
61
+ sessionId,
62
+ filePath,
63
+ maxMessages: Number.isFinite(maxMessages) && maxMessages > 0 ? Math.floor(maxMessages) : 0
64
+ },
65
+ error: ''
66
+ };
67
+ } catch (_) {
68
+ return { requested: false, params: null, error: '' };
69
+ }
70
+ },
71
+
72
+ initSessionStandalone() {
73
+ const context = this.getSessionStandaloneContext();
74
+ if (!context.requested) return;
75
+
76
+ this.sessionStandalone = true;
77
+ this.mainTab = 'sessions';
78
+ this.prepareSessionTabRender();
79
+
80
+ if (context.error || !context.params) {
81
+ this.sessionStandaloneError = `会话链接参数不完整:${context.error || '参数解析失败'}`;
82
+ return;
83
+ }
84
+
85
+ const sourceLabel = context.params.source === 'codex' ? 'Codex' : 'Claude Code';
86
+ this.activeSession = {
87
+ source: context.params.source,
88
+ sourceLabel,
89
+ sessionId: context.params.sessionId,
90
+ filePath: context.params.filePath,
91
+ title: context.params.sessionId || context.params.filePath || '会话',
92
+ maxMessages: context.params.maxMessages || 50
93
+ };
94
+ this.activeSessionMessages = [];
95
+ this.activeSessionDetailError = '';
96
+ this.activeSessionDetailClipped = false;
97
+ this.cancelSessionTimelineSync();
98
+ this.sessionTimelineActiveKey = '';
99
+ this.clearSessionTimelineRefs();
100
+ this.sessionStandaloneError = '';
101
+ this.sessionStandaloneText = '';
102
+ this.sessionStandaloneTitle = this.activeSession.title || '会话';
103
+ this.sessionStandaloneSourceLabel = sourceLabel;
104
+ this.loadSessionStandalonePlain();
105
+ },
106
+
107
+ buildSessionStandaloneUrl(session) {
108
+ if (!session) return '';
109
+ const source = typeof session.source === 'string' ? session.source.trim().toLowerCase() : '';
110
+ if (!source || (source !== 'codex' && source !== 'claude')) return '';
111
+ const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
112
+ const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
113
+ if (!sessionId && !filePath) return '';
114
+ const origin = window.location.origin && window.location.origin !== 'null'
115
+ ? window.location.origin
116
+ : (typeof apiBase === 'string' ? apiBase.trim() : '');
117
+ if (!origin) return '';
118
+ const params = new URLSearchParams();
119
+ params.set('source', source);
120
+ if (sessionId) params.set('sessionId', sessionId);
121
+ if (filePath) params.set('filePath', filePath);
122
+ return `${origin}/session?${params.toString()}`;
123
+ },
124
+
125
+ openSessionStandalone(session) {
126
+ const url = this.buildSessionStandaloneUrl(session);
127
+ if (!url) {
128
+ this.showMessage('无法生成链接', 'error');
129
+ return;
130
+ }
131
+ window.open(url, '_blank', 'noopener');
132
+ },
133
+
134
+ getSessionExportKey(session) {
135
+ return `${session.source || 'unknown'}:${session.sessionId || ''}:${session.filePath || ''}`;
136
+ },
137
+
138
+ isResumeCommandAvailable(session) {
139
+ if (!session) return false;
140
+ const source = String(session.source || '').trim().toLowerCase();
141
+ const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
142
+ const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
143
+ if (source === 'claude') {
144
+ return !!sessionId || !!this.extractClaudeResumeKeyFromFilePath(filePath);
145
+ }
146
+ if (source === 'gemini') {
147
+ return !!sessionId || !!this.extractClaudeResumeKeyFromFilePath(filePath);
148
+ }
149
+ return (source === 'codex' || source === 'codebuddy' || source === 'gemini') && !!sessionId;
150
+ },
151
+
152
+ isCloneAvailable(session) {
153
+ if (!session) return false;
154
+ const source = String(session.source || '').trim().toLowerCase();
155
+ const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
156
+ const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
157
+ return source === 'codex' && (!!sessionId || !!filePath);
158
+ },
159
+
160
+ isDeleteAvailable(session) {
161
+ if (!session) return false;
162
+ const source = String(session.source || '').trim().toLowerCase();
163
+ if (source !== 'codex' && source !== 'claude') return false;
164
+ const sessionId = typeof session.sessionId === 'string' ? session.sessionId.trim() : '';
165
+ const filePath = typeof session.filePath === 'string' ? session.filePath.trim() : '';
166
+ return !!sessionId || !!filePath;
167
+ },
168
+
169
+ buildResumeCommand(session) {
170
+ const source = session && session.source ? String(session.source).trim().toLowerCase() : '';
171
+ const sessionId = session && session.sessionId ? String(session.sessionId).trim() : '';
172
+ const filePath = session && session.filePath ? String(session.filePath).trim() : '';
173
+ const resumeKey = (source === 'claude' || source === 'gemini')
174
+ ? (sessionId || this.extractClaudeResumeKeyFromFilePath(filePath))
175
+ : sessionId;
176
+ const arg = this.quoteResumeArg(resumeKey);
177
+ if (source === 'codebuddy') {
178
+ return `codebuddy -r ${arg}`;
179
+ }
180
+ if (source === 'gemini') {
181
+ return `gemini -r ${arg}`;
182
+ }
183
+ if (source === 'claude') {
184
+ return `claude -r ${arg}`;
185
+ }
186
+ if (this.sessionResumeWithYolo) {
187
+ return `codex --yolo resume ${arg}`;
188
+ }
189
+ return `codex resume ${arg}`;
190
+ },
191
+
192
+ extractClaudeResumeKeyFromFilePath(filePath) {
193
+ const value = typeof filePath === 'string' ? filePath.trim() : '';
194
+ if (!value) return '';
195
+ const normalized = value.replace(/\\/g, '/');
196
+ const base = normalized.split('/').pop() || '';
197
+ if (!base) return '';
198
+ const lower = base.toLowerCase();
199
+ if (lower.endsWith('.jsonl')) {
200
+ return base.slice(0, -6);
201
+ }
202
+ if (lower.endsWith('.json')) {
203
+ return base.slice(0, -5);
204
+ }
205
+ return base;
206
+ },
207
+
208
+ quoteShellArg(value) {
209
+ const text = typeof value === 'string' ? value : String(value || '');
210
+ if (!text) return "''";
211
+ if (/^[a-zA-Z0-9._-]+$/.test(text)) return text;
212
+ const escaped = text.replace(/'/g, "'\\''");
213
+ return `'${escaped}'`;
214
+ },
215
+
216
+ quoteResumeArg(value) {
217
+ return this.quoteShellArg(value);
218
+ },
219
+
220
+ normalizeShareCommandPrefix(value) {
221
+ const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
222
+ if (normalized === 'codexmate') {
223
+ return 'codexmate';
224
+ }
225
+ return 'npm start';
226
+ },
227
+
228
+ normalizeSessionTrashEnabled(value) {
229
+ if (value === false) return false;
230
+ const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
231
+ if (normalized === '0' || normalized === 'false' || normalized === 'off' || normalized === 'no') {
232
+ return false;
233
+ }
234
+ return true;
235
+ },
236
+
237
+ normalizeConfigTemplateDiffConfirmEnabled(value) {
238
+ return normalizeConfigTemplateDiffConfirmEnabled(value);
239
+ },
240
+
241
+ setSessionTrashEnabled(value) {
242
+ const enabled = this.normalizeSessionTrashEnabled(value);
243
+ this.sessionTrashEnabled = enabled;
244
+ try {
245
+ localStorage.setItem('codexmateSessionTrashEnabled', enabled ? 'true' : 'false');
246
+ } catch (_) {}
247
+ },
248
+
249
+ setConfigTemplateDiffConfirmEnabled(value) {
250
+ const enabled = this.normalizeConfigTemplateDiffConfirmEnabled(value);
251
+ this.configTemplateDiffConfirmEnabled = enabled;
252
+ persistConfigTemplateDiffConfirmEnabledToStorage(enabled);
253
+ },
254
+
255
+ getShareCommandPrefixInvocation() {
256
+ const prefix = this.normalizeShareCommandPrefix(this.shareCommandPrefix);
257
+ return prefix === 'codexmate' ? 'codexmate' : 'npm start';
258
+ },
259
+
260
+ setShareCommandPrefix(value) {
261
+ const normalized = this.normalizeShareCommandPrefix(value);
262
+ this.shareCommandPrefix = normalized;
263
+ try {
264
+ localStorage.setItem('codexmateShareCommandPrefix', normalized);
265
+ } catch (_) {}
266
+ },
267
+
268
+ fallbackCopyText(text) {
269
+ let textarea = null;
270
+ try {
271
+ textarea = document.createElement('textarea');
272
+ textarea.value = text;
273
+ textarea.setAttribute('readonly', '');
274
+ textarea.style.position = 'fixed';
275
+ textarea.style.top = '-9999px';
276
+ textarea.style.left = '-9999px';
277
+ textarea.style.opacity = '0';
278
+ document.body.appendChild(textarea);
279
+ textarea.select();
280
+ textarea.setSelectionRange(0, textarea.value.length);
281
+ return document.execCommand('copy');
282
+ } catch (_) {
283
+ return false;
284
+ } finally {
285
+ if (textarea && textarea.parentNode) {
286
+ textarea.parentNode.removeChild(textarea);
287
+ }
288
+ }
289
+ },
290
+
291
+ copyAgentsContent() {
292
+ const text = typeof this.agentsContent === 'string' ? this.agentsContent : '';
293
+ if (!text) {
294
+ this.showMessage('没有可复制内容', 'info');
295
+ return;
296
+ }
297
+ const ok = this.fallbackCopyText(text);
298
+ if (ok) {
299
+ this.showMessage('已复制', 'success');
300
+ return;
301
+ }
302
+ this.showMessage('复制失败', 'error');
303
+ },
304
+
305
+ exportAgentsContent() {
306
+ const text = typeof this.agentsContent === 'string' ? this.agentsContent : '';
307
+ if (!text) {
308
+ this.showMessage('没有可导出内容', 'info');
309
+ return;
310
+ }
311
+ const now = new Date();
312
+ const year = String(now.getFullYear());
313
+ const month = String(now.getMonth() + 1).padStart(2, '0');
314
+ const day = String(now.getDate()).padStart(2, '0');
315
+ const hour = String(now.getHours()).padStart(2, '0');
316
+ const minute = String(now.getMinutes()).padStart(2, '0');
317
+ const second = String(now.getSeconds()).padStart(2, '0');
318
+ const fileName = `agent-${year}${month}${day}-${hour}${minute}${second}.txt`;
319
+ this.downloadTextFile(fileName, text, 'text/plain;charset=utf-8');
320
+ this.showMessage(`已导出 ${fileName}`, 'success');
321
+ },
322
+
323
+ async copyInstallCommand(cmd) {
324
+ const text = typeof cmd === 'string' ? cmd.trim() : '';
325
+ if (!text) {
326
+ this.showMessage('没有可复制内容', 'info');
327
+ return;
328
+ }
329
+ try {
330
+ if (navigator.clipboard && window.isSecureContext) {
331
+ await navigator.clipboard.writeText(text);
332
+ this.showMessage('已复制命令', 'success');
333
+ return;
334
+ }
335
+ } catch (_) {}
336
+ const ok = this.fallbackCopyText(text);
337
+ if (ok) {
338
+ this.showMessage('已复制命令', 'success');
339
+ return;
340
+ }
341
+ this.showMessage('复制失败', 'error');
342
+ },
343
+
344
+ async copyResumeCommand(session) {
345
+ if (!this.isResumeCommandAvailable(session)) {
346
+ this.showMessage('不支持此操作', 'error');
347
+ return;
348
+ }
349
+ const command = this.buildResumeCommand(session);
350
+ const ok = this.fallbackCopyText(command);
351
+ if (ok) {
352
+ this.showMessage('已复制', 'success');
353
+ return;
354
+ }
355
+ try {
356
+ if (navigator.clipboard && window.isSecureContext) {
357
+ await navigator.clipboard.writeText(command);
358
+ this.showMessage('已复制', 'success');
359
+ return;
360
+ }
361
+ } catch (_) {}
362
+ this.showMessage('复制失败', 'error');
363
+ },
364
+
365
+ buildProviderShareCommand(payload) {
366
+ if (!payload || typeof payload !== 'object') return '';
367
+ const name = typeof payload.name === 'string' ? payload.name.trim() : '';
368
+ const baseUrl = typeof payload.baseUrl === 'string' ? payload.baseUrl.trim() : '';
369
+ const apiKey = typeof payload.apiKey === 'string' ? payload.apiKey : '';
370
+ const model = typeof payload.model === 'string' ? payload.model.trim() : '';
371
+ const bridge = typeof payload.bridge === 'string' ? payload.bridge.trim() : '';
372
+ if (!name || !baseUrl) return '';
373
+
374
+ const cli = this.getShareCommandPrefixInvocation();
375
+ const nameArg = this.quoteShellArg(name);
376
+ const urlArg = this.quoteShellArg(baseUrl);
377
+ const keyArg = apiKey ? this.quoteShellArg(apiKey) : '';
378
+ const switchCmd = `${cli} switch ${nameArg}`;
379
+ const bridgeArgs = bridge ? ` --bridge ${this.quoteShellArg(bridge)}` : '';
380
+ const addCmd = apiKey
381
+ ? `${cli} add ${nameArg} ${urlArg} ${keyArg}${bridgeArgs}`
382
+ : `${cli} add ${nameArg} ${urlArg}${bridgeArgs}`;
383
+ const modelCmd = model ? ` && ${cli} use ${this.quoteShellArg(model)}` : '';
384
+ return `${addCmd} && ${switchCmd}${modelCmd}`;
385
+ },
386
+
387
+ buildClaudeShareCommand(payload) {
388
+ if (!payload || typeof payload !== 'object') return '';
389
+ const baseUrl = typeof payload.baseUrl === 'string' ? payload.baseUrl.trim() : '';
390
+ const apiKey = typeof payload.apiKey === 'string' ? payload.apiKey : '';
391
+ const model = typeof payload.model === 'string' && payload.model.trim()
392
+ ? payload.model.trim()
393
+ : 'glm-4.7';
394
+ if (!baseUrl || !apiKey) return '';
395
+ const urlArg = this.quoteShellArg(baseUrl);
396
+ const keyArg = this.quoteShellArg(apiKey);
397
+ const modelArg = this.quoteShellArg(model);
398
+ return `${this.getShareCommandPrefixInvocation()} claude ${urlArg} ${keyArg} ${modelArg}`;
399
+ },
400
+
401
+ async copyProviderShareCommand(provider) {
402
+ const name = provider && typeof provider.name === 'string' ? provider.name.trim() : '';
403
+ if (!name) {
404
+ this.showMessage('参数无效', 'error');
405
+ return;
406
+ }
407
+ if (!this.shouldAllowProviderShare(provider)) {
408
+ this.showMessage('不可分享', 'info');
409
+ return;
410
+ }
411
+ if (this.providerShareLoading[name]) {
412
+ return;
413
+ }
414
+ this.providerShareLoading[name] = true;
415
+ try {
416
+ const res = await api('export-provider', { name });
417
+ if (res && res.error) {
418
+ this.showMessage(res.error, 'error');
419
+ return;
420
+ }
421
+ const command = this.buildProviderShareCommand(res && res.payload ? res.payload : null);
422
+ if (!command) {
423
+ this.showMessage('生成命令失败', 'error');
424
+ return;
425
+ }
426
+ const ok = this.fallbackCopyText(command);
427
+ if (ok) {
428
+ this.showMessage('已复制', 'success');
429
+ return;
430
+ }
431
+ try {
432
+ if (navigator.clipboard && window.isSecureContext) {
433
+ await navigator.clipboard.writeText(command);
434
+ this.showMessage('已复制', 'success');
435
+ return;
436
+ }
437
+ } catch (_) {}
438
+ this.showMessage('复制失败', 'error');
439
+ } catch (_) {
440
+ this.showMessage('生成命令失败', 'error');
441
+ } finally {
442
+ this.providerShareLoading[name] = false;
443
+ }
444
+ },
445
+
446
+ async copyClaudeShareCommand(name) {
447
+ const config = this.claudeConfigs[name];
448
+ if (!config) {
449
+ this.showMessage('配置不存在', 'error');
450
+ return;
451
+ }
452
+ if (this.claudeShareLoading[name]) return;
453
+ this.claudeShareLoading[name] = true;
454
+ try {
455
+ const res = await api('export-claude-share', { config });
456
+ if (res && res.error) {
457
+ this.showMessage(res.error, 'error');
458
+ return;
459
+ }
460
+ const command = this.buildClaudeShareCommand(res && res.payload ? res.payload : null);
461
+ if (!command) {
462
+ this.showMessage('生成命令失败', 'error');
463
+ return;
464
+ }
465
+ const ok = this.fallbackCopyText(command);
466
+ if (ok) {
467
+ this.showMessage('已复制', 'success');
468
+ return;
469
+ }
470
+ try {
471
+ if (navigator.clipboard && window.isSecureContext) {
472
+ await navigator.clipboard.writeText(command);
473
+ this.showMessage('已复制', 'success');
474
+ return;
475
+ }
476
+ } catch (_) {}
477
+ this.showMessage('复制失败', 'error');
478
+ } catch (_) {
479
+ this.showMessage('生成命令失败', 'error');
480
+ } finally {
481
+ this.claudeShareLoading[name] = false;
482
+ }
483
+ },
484
+
485
+ async cloneSession(session) {
486
+ if (!this.isCloneAvailable(session)) {
487
+ this.showMessage('不支持此操作', 'error');
488
+ return;
489
+ }
490
+ const key = this.getSessionExportKey(session);
491
+ if (this.sessionCloning[key]) {
492
+ return;
493
+ }
494
+ this.sessionCloning[key] = true;
495
+ try {
496
+ const res = await api('clone-session', {
497
+ source: session.source,
498
+ sessionId: session.sessionId,
499
+ filePath: session.filePath
500
+ });
501
+ if (res.error) {
502
+ this.showMessage(res.error, 'error');
503
+ return;
504
+ }
505
+
506
+ this.showMessage('操作成功', 'success');
507
+ if (typeof this.invalidateSessionsUsageData === 'function') {
508
+ this.invalidateSessionsUsageData({ preserveList: true });
509
+ }
510
+ try {
511
+ await this.loadSessions();
512
+ if (res.sessionId) {
513
+ const matched = this.sessionsList.find(item => item.source === 'codex' && item.sessionId === res.sessionId);
514
+ if (matched) {
515
+ await this.selectSession(matched);
516
+ }
517
+ }
518
+ } catch (_) {
519
+ // The clone already succeeded remotely; keep the success result.
520
+ }
521
+ } catch (_) {
522
+ this.showMessage('克隆失败', 'error');
523
+ } finally {
524
+ this.sessionCloning[key] = false;
525
+ }
526
+ },
527
+
528
+ async deleteSession(session) {
529
+ if (!this.isDeleteAvailable(session)) {
530
+ this.showMessage('不支持此操作', 'error');
531
+ return;
532
+ }
533
+ const useTrash = this.sessionTrashEnabled !== false;
534
+ if (!useTrash && typeof this.requestConfirmDialog === 'function') {
535
+ const confirmed = await this.requestConfirmDialog({
536
+ title: '直接删除会话',
537
+ message: '关闭回收站后,删除会话将直接永久删除,且无法恢复。',
538
+ confirmText: '直接删除',
539
+ cancelText: '取消',
540
+ danger: true
541
+ });
542
+ if (!confirmed) {
543
+ return;
544
+ }
545
+ }
546
+ const key = this.getSessionExportKey(session);
547
+ if (this.sessionDeleting[key]) {
548
+ return;
549
+ }
550
+ this.sessionDeleting[key] = true;
551
+ try {
552
+ const action = useTrash ? 'trash-session' : 'delete-session';
553
+ const res = await api(action, {
554
+ source: session.source,
555
+ sessionId: session.sessionId,
556
+ filePath: session.filePath
557
+ });
558
+ if (!res || res.error) {
559
+ this.showMessage((res && res.error) || '删除失败', 'error');
560
+ return;
561
+ }
562
+ this.removeSessionPin(session);
563
+ if (useTrash) {
564
+ this.invalidateSessionTrashRequests();
565
+ this.showMessage('已移入回收站', 'success');
566
+ if (this.sessionTrashLoadedOnce) {
567
+ this.prependSessionTrashItem(this.buildSessionTrashItemFromSession(session, res), {
568
+ totalCount: res && res.totalCount !== undefined ? res.totalCount : undefined
569
+ });
570
+ } else {
571
+ this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
572
+ res && res.totalCount !== undefined
573
+ ? res.totalCount
574
+ : (this.normalizeSessionTrashTotalCount(this.sessionTrashTotalCount, this.sessionTrashItems) + 1),
575
+ this.sessionTrashItems
576
+ );
577
+ }
578
+ } else {
579
+ this.showMessage('已删除', 'success');
580
+ }
581
+ if (typeof this.invalidateSessionsUsageData === 'function') {
582
+ this.invalidateSessionsUsageData({ preserveList: true });
583
+ }
584
+ try {
585
+ await this.removeSessionFromCurrentList(session);
586
+ } catch (_) {
587
+ // The delete already succeeded remotely; keep the success result.
588
+ }
589
+ } catch (_) {
590
+ this.showMessage('删除失败', 'error');
591
+ } finally {
592
+ this.sessionDeleting[key] = false;
593
+ }
594
+ }
595
+ };
596
+ }