codexmate 0.0.20 → 0.0.21

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 (102) hide show
  1. package/README.en.md +349 -259
  2. package/README.md +284 -252
  3. package/cli/agents-files.js +162 -0
  4. package/cli/archive-helpers.js +446 -0
  5. package/cli/auth-profiles.js +359 -0
  6. package/cli/builtin-proxy.js +580 -0
  7. package/cli/claude-proxy.js +998 -0
  8. package/cli/config-bootstrap.js +384 -0
  9. package/cli/config-health.js +338 -338
  10. package/cli/openclaw-config.js +629 -0
  11. package/cli/skills.js +1141 -0
  12. package/cli/zip-commands.js +510 -0
  13. package/cli.js +13101 -13497
  14. package/lib/cli-file-utils.js +151 -151
  15. package/lib/cli-models-utils.js +419 -311
  16. package/lib/cli-network-utils.js +164 -164
  17. package/lib/cli-path-utils.js +69 -0
  18. package/lib/cli-session-utils.js +121 -121
  19. package/lib/cli-sessions.js +386 -0
  20. package/lib/cli-utils.js +155 -155
  21. package/lib/download-artifacts.js +77 -0
  22. package/lib/mcp-stdio.js +440 -440
  23. package/lib/task-orchestrator.js +869 -0
  24. package/lib/text-diff.js +303 -303
  25. package/lib/workflow-engine.js +340 -340
  26. package/package.json +74 -70
  27. package/res/json5.min.js +1 -1
  28. package/res/vue.global.prod.js +13 -0
  29. package/web-ui/app.js +530 -397
  30. package/web-ui/index.html +33 -30
  31. package/web-ui/logic.agents-diff.mjs +386 -386
  32. package/web-ui/logic.claude.mjs +168 -108
  33. package/web-ui/logic.mjs +5 -5
  34. package/web-ui/logic.runtime.mjs +124 -124
  35. package/web-ui/logic.sessions.mjs +581 -263
  36. package/web-ui/modules/api.mjs +90 -69
  37. package/web-ui/modules/app.computed.dashboard.mjs +113 -113
  38. package/web-ui/modules/app.computed.index.mjs +15 -13
  39. package/web-ui/modules/app.computed.main-tabs.mjs +195 -0
  40. package/web-ui/modules/app.computed.session.mjs +507 -141
  41. package/web-ui/modules/app.constants.mjs +15 -15
  42. package/web-ui/modules/app.methods.agents.mjs +493 -493
  43. package/web-ui/modules/app.methods.claude-config.mjs +174 -174
  44. package/web-ui/modules/app.methods.codex-config.mjs +640 -640
  45. package/web-ui/modules/app.methods.index.mjs +88 -86
  46. package/web-ui/modules/app.methods.install.mjs +149 -157
  47. package/web-ui/modules/app.methods.navigation.mjs +619 -478
  48. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -514
  49. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -337
  50. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -251
  51. package/web-ui/modules/app.methods.providers.mjs +363 -265
  52. package/web-ui/modules/app.methods.runtime.mjs +323 -323
  53. package/web-ui/modules/app.methods.session-actions.mjs +520 -457
  54. package/web-ui/modules/app.methods.session-browser.mjs +626 -435
  55. package/web-ui/modules/app.methods.session-timeline.mjs +448 -441
  56. package/web-ui/modules/app.methods.session-trash.mjs +422 -419
  57. package/web-ui/modules/app.methods.startup-claude.mjs +412 -406
  58. package/web-ui/modules/app.methods.task-orchestration.mjs +471 -0
  59. package/web-ui/modules/config-mode.computed.mjs +126 -124
  60. package/web-ui/modules/skills.computed.mjs +107 -107
  61. package/web-ui/modules/skills.methods.mjs +481 -481
  62. package/web-ui/partials/index/layout-footer.html +13 -69
  63. package/web-ui/partials/index/layout-header.html +402 -337
  64. package/web-ui/partials/index/modal-config-template-agents.html +125 -125
  65. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  66. package/web-ui/partials/index/modal-health-check.html +72 -72
  67. package/web-ui/partials/index/modal-openclaw-config.html +280 -275
  68. package/web-ui/partials/index/modal-skills.html +184 -184
  69. package/web-ui/partials/index/modals-basic.html +156 -196
  70. package/web-ui/partials/index/panel-config-claude.html +126 -100
  71. package/web-ui/partials/index/panel-config-codex.html +237 -237
  72. package/web-ui/partials/index/panel-config-openclaw.html +78 -84
  73. package/web-ui/partials/index/panel-docs.html +130 -0
  74. package/web-ui/partials/index/panel-market.html +174 -174
  75. package/web-ui/partials/index/panel-orchestration.html +397 -0
  76. package/web-ui/partials/index/panel-sessions.html +292 -387
  77. package/web-ui/partials/index/panel-settings.html +190 -166
  78. package/web-ui/partials/index/panel-usage.html +213 -0
  79. package/web-ui/session-helpers.mjs +559 -362
  80. package/web-ui/source-bundle.cjs +233 -233
  81. package/web-ui/styles/base-theme.css +271 -373
  82. package/web-ui/styles/controls-forms.css +360 -354
  83. package/web-ui/styles/docs-panel.css +182 -0
  84. package/web-ui/styles/feedback.css +108 -108
  85. package/web-ui/styles/health-check-dialog.css +144 -144
  86. package/web-ui/styles/layout-shell.css +376 -330
  87. package/web-ui/styles/modals-core.css +464 -449
  88. package/web-ui/styles/navigation-panels.css +348 -381
  89. package/web-ui/styles/openclaw-structured.css +266 -266
  90. package/web-ui/styles/responsive.css +450 -416
  91. package/web-ui/styles/sessions-list.css +400 -414
  92. package/web-ui/styles/sessions-preview.css +411 -405
  93. package/web-ui/styles/sessions-toolbar-trash.css +243 -243
  94. package/web-ui/styles/sessions-usage.css +628 -276
  95. package/web-ui/styles/skills-list.css +296 -298
  96. package/web-ui/styles/skills-market.css +335 -335
  97. package/web-ui/styles/task-orchestration.css +776 -0
  98. package/web-ui/styles/titles-cards.css +408 -407
  99. package/web-ui/styles.css +18 -16
  100. package/web-ui.html +17 -17
  101. package/res/screenshot.png +0 -0
  102. package/res/vue.global.js +0 -18552
@@ -1,419 +1,422 @@
1
- export function createSessionTrashMethods(options = {}) {
2
- const {
3
- api,
4
- sessionTrashListLimit = 500,
5
- sessionTrashPageSize = 200
6
- } = options;
7
-
8
- return {
9
- buildSessionTrashItemFromSession(session, result = {}) {
10
- const deletedAt = typeof result.deletedAt === 'string' && result.deletedAt
11
- ? result.deletedAt
12
- : new Date().toISOString();
13
- const source = session && session.source === 'claude' ? 'claude' : 'codex';
14
- return {
15
- trashId: typeof result.trashId === 'string' ? result.trashId : '',
16
- source,
17
- sourceLabel: session && typeof session.sourceLabel === 'string' && session.sourceLabel
18
- ? session.sourceLabel
19
- : (source === 'claude' ? 'Claude Code' : 'Codex'),
20
- sessionId: session && typeof session.sessionId === 'string' ? session.sessionId : '',
21
- title: session && typeof session.title === 'string' && session.title
22
- ? session.title
23
- : (session && typeof session.sessionId === 'string' ? session.sessionId : ''),
24
- cwd: session && typeof session.cwd === 'string' ? session.cwd : '',
25
- createdAt: session && typeof session.createdAt === 'string' ? session.createdAt : '',
26
- updatedAt: session && typeof session.updatedAt === 'string' ? session.updatedAt : '',
27
- deletedAt,
28
- messageCount: Number.isFinite(Number(result && result.messageCount))
29
- ? Math.max(0, Math.floor(Number(result.messageCount)))
30
- : (Number.isFinite(Number(session && session.messageCount))
31
- ? Math.max(0, Math.floor(Number(session.messageCount)))
32
- : 0),
33
- originalFilePath: session && typeof session.filePath === 'string' ? session.filePath : '',
34
- provider: session && typeof session.provider === 'string' ? session.provider : source,
35
- keywords: Array.isArray(session && session.keywords) ? session.keywords : [],
36
- capabilities: session && typeof session.capabilities === 'object' && session.capabilities
37
- ? session.capabilities
38
- : {},
39
- claudeIndexPath: '',
40
- claudeIndexEntry: null,
41
- trashFilePath: ''
42
- };
43
- },
44
-
45
- prependSessionTrashItem(item, options = {}) {
46
- if (!item || !item.trashId) {
47
- return;
48
- }
49
- const existing = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems : [];
50
- const filtered = existing.filter((entry) => this.getSessionTrashActionKey(entry) !== item.trashId);
51
- const nextItems = [item, ...filtered].slice(0, sessionTrashListLimit);
52
- const previousTotalCount = Number(this.sessionTrashTotalCount);
53
- const normalizedPreviousTotal = Number.isFinite(previousTotalCount) && previousTotalCount >= 0
54
- ? Math.max(existing.length, Math.floor(previousTotalCount))
55
- : existing.length;
56
- this.sessionTrashItems = nextItems;
57
- const previousVisibleCount = Number(this.sessionTrashVisibleCount);
58
- const normalizedPreviousVisibleCount = Number.isFinite(previousVisibleCount) && previousVisibleCount > 0
59
- ? Math.floor(previousVisibleCount)
60
- : sessionTrashPageSize;
61
- const wasFullyExpanded = normalizedPreviousVisibleCount >= existing.length
62
- || normalizedPreviousVisibleCount >= normalizedPreviousTotal;
63
- if (wasFullyExpanded) {
64
- this.sessionTrashVisibleCount = Math.min(
65
- normalizedPreviousVisibleCount + 1,
66
- nextItems.length || (normalizedPreviousVisibleCount + 1)
67
- );
68
- }
69
- const fallbackTotalCount = filtered.length === existing.length
70
- ? normalizedPreviousTotal + 1
71
- : normalizedPreviousTotal;
72
- this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
73
- options && options.totalCount !== undefined
74
- ? options.totalCount
75
- : fallbackTotalCount,
76
- nextItems
77
- );
78
- },
79
-
80
- normalizeSessionTrashTotalCount(totalCount, fallbackItems = this.sessionTrashItems) {
81
- const fallbackCount = Array.isArray(fallbackItems) ? fallbackItems.length : 0;
82
- const numericTotal = Number(totalCount);
83
- if (!Number.isFinite(numericTotal) || numericTotal < 0) {
84
- return fallbackCount;
85
- }
86
- return Math.floor(numericTotal);
87
- },
88
-
89
- getSessionTrashViewState() {
90
- if (this.sessionTrashLoading && !this.sessionTrashLoadedOnce) {
91
- return 'loading';
92
- }
93
- const totalCount = Number(this.sessionTrashCount);
94
- const normalizedTotalCount = Number.isFinite(totalCount) && totalCount >= 0
95
- ? Math.floor(totalCount)
96
- : 0;
97
- const hasVisibleItems = Array.isArray(this.sessionTrashItems) && this.sessionTrashItems.length > 0;
98
- if (this.sessionTrashLastLoadFailed && (!this.sessionTrashLoadedOnce || !hasVisibleItems)) {
99
- return 'retry';
100
- }
101
- if (!this.sessionTrashLoadedOnce) {
102
- return normalizedTotalCount > 0 ? 'retry' : 'empty';
103
- }
104
- if (normalizedTotalCount === 0) {
105
- return 'empty';
106
- }
107
- return hasVisibleItems ? 'list' : 'retry';
108
- },
109
-
110
- issueSessionTrashCountRequestToken() {
111
- const currentToken = Number(this.sessionTrashCountRequestToken);
112
- const nextToken = Number.isFinite(currentToken) && currentToken >= 0
113
- ? Math.floor(currentToken) + 1
114
- : 1;
115
- this.sessionTrashCountRequestToken = nextToken;
116
- return nextToken;
117
- },
118
-
119
- issueSessionTrashListRequestToken() {
120
- const currentToken = Number(this.sessionTrashListRequestToken);
121
- const nextToken = Number.isFinite(currentToken) && currentToken >= 0
122
- ? Math.floor(currentToken) + 1
123
- : 1;
124
- this.sessionTrashListRequestToken = nextToken;
125
- return nextToken;
126
- },
127
-
128
- invalidateSessionTrashRequests() {
129
- this.issueSessionTrashCountRequestToken();
130
- return this.issueSessionTrashListRequestToken();
131
- },
132
-
133
- isLatestSessionTrashCountRequestToken(token) {
134
- return Number(token) === Number(this.sessionTrashCountRequestToken);
135
- },
136
-
137
- isLatestSessionTrashListRequestToken(token) {
138
- return Number(token) === Number(this.sessionTrashListRequestToken);
139
- },
140
-
141
- resetSessionTrashVisibleCount() {
142
- const totalItems = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
143
- this.sessionTrashVisibleCount = Math.min(totalItems, sessionTrashPageSize) || sessionTrashPageSize;
144
- },
145
-
146
- loadMoreSessionTrashItems() {
147
- const totalItems = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
148
- const visibleCount = Number(this.sessionTrashVisibleCount);
149
- const safeVisibleCount = Number.isFinite(visibleCount) && visibleCount > 0
150
- ? Math.floor(visibleCount)
151
- : sessionTrashPageSize;
152
- this.sessionTrashVisibleCount = Math.min(totalItems, safeVisibleCount + sessionTrashPageSize);
153
- },
154
-
155
- clearActiveSessionState() {
156
- this.activeSession = null;
157
- this.activeSessionMessages = [];
158
- this.resetSessionDetailPagination();
159
- this.resetSessionPreviewMessageRender();
160
- this.activeSessionDetailError = '';
161
- this.activeSessionDetailClipped = false;
162
- this.cancelSessionTimelineSync();
163
- this.sessionTimelineActiveKey = '';
164
- this.clearSessionTimelineRefs();
165
- },
166
-
167
- async removeSessionFromCurrentList(session) {
168
- const sessionKey = this.getSessionExportKey(session);
169
- if (!sessionKey) {
170
- return;
171
- }
172
- const currentList = Array.isArray(this.sessionsList) ? [...this.sessionsList] : [];
173
- const removedIndex = currentList.findIndex((item) => this.getSessionExportKey(item) === sessionKey);
174
- if (removedIndex < 0) {
175
- return;
176
- }
177
- const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
178
- const renderedList = Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
179
- const renderedIndex = renderedList.findIndex((item) => this.getSessionExportKey(item) === sessionKey);
180
- let nextActiveKey = '';
181
- if (activeKey === sessionKey && renderedIndex >= 0) {
182
- const fallbackSession = renderedList[renderedIndex - 1] || renderedList[renderedIndex + 1] || null;
183
- nextActiveKey = fallbackSession ? this.getSessionExportKey(fallbackSession) : '';
184
- }
185
- currentList.splice(removedIndex, 1);
186
- this.sessionsList = currentList;
187
- this.syncSessionPathOptionsForSource(
188
- this.sessionFilterSource,
189
- this.extractPathOptionsFromSessions(currentList),
190
- false
191
- );
192
- if (activeKey !== sessionKey) {
193
- return;
194
- }
195
- if (currentList.length === 0) {
196
- this.clearActiveSessionState();
197
- return;
198
- }
199
- const nextSession = currentList.find((item) => this.getSessionExportKey(item) === nextActiveKey)
200
- || currentList[Math.min(removedIndex, currentList.length - 1)];
201
- if (!nextSession) {
202
- this.clearActiveSessionState();
203
- return;
204
- }
205
- await this.selectSession(nextSession);
206
- },
207
-
208
- normalizeSettingsTab(tab) {
209
- if (tab === 'trash' || tab === 'device') {
210
- return tab;
211
- }
212
- return 'backup';
213
- },
214
-
215
- async onSettingsTabClick(tab) {
216
- await this.switchSettingsTab(tab);
217
- },
218
-
219
- async switchSettingsTab(tab, options = {}) {
220
- const nextTab = this.normalizeSettingsTab(tab);
221
- this.settingsTab = nextTab;
222
- if (nextTab !== 'trash') {
223
- return;
224
- }
225
- const forceRefresh = options.forceRefresh === true;
226
- if (forceRefresh || !this.sessionTrashLoadedOnce) {
227
- await this.loadSessionTrash({ forceRefresh });
228
- }
229
- },
230
-
231
- async loadSessionTrashCount(options = {}) {
232
- if (this.sessionTrashCountLoading) {
233
- this.sessionTrashCountPendingOptions = {
234
- ...(this.sessionTrashCountPendingOptions || {}),
235
- ...(options || {})
236
- };
237
- return;
238
- }
239
- const requestToken = this.issueSessionTrashCountRequestToken();
240
- this.sessionTrashCountLoading = true;
241
- try {
242
- const res = await api('list-session-trash', { countOnly: true });
243
- if (!this.isLatestSessionTrashCountRequestToken(requestToken)) {
244
- return;
245
- }
246
- if (res.error) {
247
- if (options.silent !== true) {
248
- this.showMessage(res.error, 'error');
249
- }
250
- return;
251
- }
252
- this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
253
- res.totalCount,
254
- this.sessionTrashItems
255
- );
256
- this.sessionTrashCountLoadedOnce = true;
257
- } catch (e) {
258
- if (this.isLatestSessionTrashCountRequestToken(requestToken) && options.silent !== true) {
259
- this.showMessage('加载回收站数量失败', 'error');
260
- }
261
- } finally {
262
- this.sessionTrashCountLoading = false;
263
- const pendingOptions = this.sessionTrashCountPendingOptions;
264
- this.sessionTrashCountPendingOptions = null;
265
- if (pendingOptions) {
266
- await this.loadSessionTrashCount(pendingOptions);
267
- }
268
- }
269
- },
270
-
271
- getSessionTrashActionKey(item) {
272
- return item && typeof item.trashId === 'string' ? item.trashId : '';
273
- },
274
-
275
- isSessionTrashActionBusy(item) {
276
- const key = typeof item === 'string' ? item : this.getSessionTrashActionKey(item);
277
- return !!(key && (this.sessionTrashRestoring[key] || this.sessionTrashPurging[key]));
278
- },
279
-
280
- async loadSessionTrash(options = {}) {
281
- if (this.sessionTrashLoading) {
282
- this.sessionTrashPendingOptions = {
283
- ...(this.sessionTrashPendingOptions || {}),
284
- ...(options || {})
285
- };
286
- return;
287
- }
288
- const requestToken = this.issueSessionTrashListRequestToken();
289
- this.sessionTrashLoading = true;
290
- this.sessionTrashLastLoadFailed = false;
291
- let loadSucceeded = false;
292
- try {
293
- const res = await api('list-session-trash', {
294
- limit: sessionTrashListLimit,
295
- forceRefresh: !!options.forceRefresh
296
- });
297
- if (!this.isLatestSessionTrashListRequestToken(requestToken)) {
298
- return;
299
- }
300
- if (res.error) {
301
- this.sessionTrashLastLoadFailed = true;
302
- this.showMessage(res.error, 'error');
303
- return;
304
- }
305
- const nextItems = Array.isArray(res.items) ? res.items : [];
306
- this.sessionTrashItems = nextItems;
307
- this.resetSessionTrashVisibleCount();
308
- this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(res.totalCount, nextItems);
309
- this.sessionTrashCountLoadedOnce = true;
310
- this.sessionTrashLastLoadFailed = false;
311
- loadSucceeded = true;
312
- } catch (e) {
313
- if (this.isLatestSessionTrashListRequestToken(requestToken)) {
314
- this.sessionTrashLastLoadFailed = true;
315
- this.showMessage('加载回收站失败', 'error');
316
- }
317
- } finally {
318
- this.sessionTrashLoading = false;
319
- if (loadSucceeded) {
320
- this.sessionTrashLoadedOnce = true;
321
- }
322
- const pendingOptions = this.sessionTrashPendingOptions;
323
- this.sessionTrashPendingOptions = null;
324
- if (pendingOptions) {
325
- await this.loadSessionTrash(pendingOptions);
326
- }
327
- }
328
- },
329
-
330
- async restoreSessionTrash(item) {
331
- const key = this.getSessionTrashActionKey(item);
332
- if (!key || this.isSessionTrashActionBusy(key) || this.sessionTrashClearing) {
333
- return;
334
- }
335
- this.sessionTrashRestoring[key] = true;
336
- try {
337
- const res = await api('restore-session-trash', { trashId: key });
338
- if (res.error) {
339
- this.showMessage(res.error, 'error');
340
- return;
341
- }
342
- this.showMessage('会话已恢复', 'success');
343
- this.invalidateSessionTrashRequests();
344
- await this.loadSessionTrash({ forceRefresh: true });
345
- if (this.sessionsLoadedOnce) {
346
- await this.loadSessions();
347
- }
348
- } catch (e) {
349
- this.showMessage('恢复失败', 'error');
350
- } finally {
351
- this.sessionTrashRestoring[key] = false;
352
- }
353
- },
354
-
355
- async purgeSessionTrash(item) {
356
- const key = this.getSessionTrashActionKey(item);
357
- if (!key || this.isSessionTrashActionBusy(key) || this.sessionTrashClearing) {
358
- return;
359
- }
360
- const confirmed = await this.requestConfirmDialog({
361
- title: '彻底删除回收站记录',
362
- message: '该会话将从回收站永久删除,且无法恢复。',
363
- confirmText: '彻底删除',
364
- cancelText: '取消',
365
- danger: true
366
- });
367
- if (!confirmed) {
368
- return;
369
- }
370
- this.sessionTrashPurging[key] = true;
371
- try {
372
- const res = await api('purge-session-trash', { trashId: key });
373
- if (res.error) {
374
- this.showMessage(res.error, 'error');
375
- return;
376
- }
377
- this.showMessage('已彻底删除', 'success');
378
- this.invalidateSessionTrashRequests();
379
- await this.loadSessionTrash({ forceRefresh: true });
380
- } catch (e) {
381
- this.showMessage('彻底删除失败', 'error');
382
- } finally {
383
- this.sessionTrashPurging[key] = false;
384
- }
385
- },
386
-
387
- async clearSessionTrash() {
388
- const normalizedCount = Number(this.sessionTrashCount);
389
- if (this.sessionTrashClearing || !Number.isFinite(normalizedCount) || normalizedCount <= 0) {
390
- return;
391
- }
392
- const confirmed = await this.requestConfirmDialog({
393
- title: '清空回收站',
394
- message: '该操作会永久删除回收站中的全部会话,且无法恢复。',
395
- confirmText: '全部清空',
396
- cancelText: '取消',
397
- danger: true
398
- });
399
- if (!confirmed) {
400
- return;
401
- }
402
- this.sessionTrashClearing = true;
403
- try {
404
- const res = await api('purge-session-trash', { all: true });
405
- if (res.error) {
406
- this.showMessage(res.error, 'error');
407
- return;
408
- }
409
- this.showMessage('回收站已清空', 'success');
410
- this.invalidateSessionTrashRequests();
411
- await this.loadSessionTrash({ forceRefresh: true });
412
- } catch (e) {
413
- this.showMessage('清空回收站失败', 'error');
414
- } finally {
415
- this.sessionTrashClearing = false;
416
- }
417
- }
418
- };
419
- }
1
+ export function createSessionTrashMethods(options = {}) {
2
+ const {
3
+ api,
4
+ sessionTrashListLimit = 500,
5
+ sessionTrashPageSize = 200
6
+ } = options;
7
+
8
+ return {
9
+ buildSessionTrashItemFromSession(session, result = {}) {
10
+ const deletedAt = typeof result.deletedAt === 'string' && result.deletedAt
11
+ ? result.deletedAt
12
+ : new Date().toISOString();
13
+ const source = session && session.source === 'claude' ? 'claude' : 'codex';
14
+ return {
15
+ trashId: typeof result.trashId === 'string' ? result.trashId : '',
16
+ source,
17
+ sourceLabel: session && typeof session.sourceLabel === 'string' && session.sourceLabel
18
+ ? session.sourceLabel
19
+ : (source === 'claude' ? 'Claude Code' : 'Codex'),
20
+ sessionId: session && typeof session.sessionId === 'string' ? session.sessionId : '',
21
+ title: session && typeof session.title === 'string' && session.title
22
+ ? session.title
23
+ : (session && typeof session.sessionId === 'string' ? session.sessionId : ''),
24
+ cwd: session && typeof session.cwd === 'string' ? session.cwd : '',
25
+ createdAt: session && typeof session.createdAt === 'string' ? session.createdAt : '',
26
+ updatedAt: session && typeof session.updatedAt === 'string' ? session.updatedAt : '',
27
+ deletedAt,
28
+ messageCount: Number.isFinite(Number(result && result.messageCount))
29
+ ? Math.max(0, Math.floor(Number(result.messageCount)))
30
+ : (Number.isFinite(Number(session && session.messageCount))
31
+ ? Math.max(0, Math.floor(Number(session.messageCount)))
32
+ : 0),
33
+ originalFilePath: session && typeof session.filePath === 'string' ? session.filePath : '',
34
+ provider: session && typeof session.provider === 'string' ? session.provider : source,
35
+ keywords: Array.isArray(session && session.keywords) ? session.keywords : [],
36
+ capabilities: session && typeof session.capabilities === 'object' && session.capabilities
37
+ ? session.capabilities
38
+ : {},
39
+ claudeIndexPath: '',
40
+ claudeIndexEntry: null,
41
+ trashFilePath: ''
42
+ };
43
+ },
44
+
45
+ prependSessionTrashItem(item, options = {}) {
46
+ if (!item || !item.trashId) {
47
+ return;
48
+ }
49
+ const existing = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems : [];
50
+ const filtered = existing.filter((entry) => this.getSessionTrashActionKey(entry) !== item.trashId);
51
+ const nextItems = [item, ...filtered].slice(0, sessionTrashListLimit);
52
+ const previousTotalCount = Number(this.sessionTrashTotalCount);
53
+ const normalizedPreviousTotal = Number.isFinite(previousTotalCount) && previousTotalCount >= 0
54
+ ? Math.max(existing.length, Math.floor(previousTotalCount))
55
+ : existing.length;
56
+ this.sessionTrashItems = nextItems;
57
+ const previousVisibleCount = Number(this.sessionTrashVisibleCount);
58
+ const normalizedPreviousVisibleCount = Number.isFinite(previousVisibleCount) && previousVisibleCount > 0
59
+ ? Math.floor(previousVisibleCount)
60
+ : sessionTrashPageSize;
61
+ const wasFullyExpanded = normalizedPreviousVisibleCount >= existing.length
62
+ || normalizedPreviousVisibleCount >= normalizedPreviousTotal;
63
+ if (wasFullyExpanded) {
64
+ this.sessionTrashVisibleCount = Math.min(
65
+ normalizedPreviousVisibleCount + 1,
66
+ nextItems.length || (normalizedPreviousVisibleCount + 1)
67
+ );
68
+ }
69
+ const fallbackTotalCount = filtered.length === existing.length
70
+ ? normalizedPreviousTotal + 1
71
+ : normalizedPreviousTotal;
72
+ this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
73
+ options && options.totalCount !== undefined
74
+ ? options.totalCount
75
+ : fallbackTotalCount,
76
+ nextItems
77
+ );
78
+ },
79
+
80
+ normalizeSessionTrashTotalCount(totalCount, fallbackItems = this.sessionTrashItems) {
81
+ const fallbackCount = Array.isArray(fallbackItems) ? fallbackItems.length : 0;
82
+ const numericTotal = Number(totalCount);
83
+ if (!Number.isFinite(numericTotal) || numericTotal < 0) {
84
+ return fallbackCount;
85
+ }
86
+ return Math.floor(numericTotal);
87
+ },
88
+
89
+ getSessionTrashViewState() {
90
+ if (this.sessionTrashLoading && !this.sessionTrashLoadedOnce) {
91
+ return 'loading';
92
+ }
93
+ const totalCount = Number(this.sessionTrashCount);
94
+ const normalizedTotalCount = Number.isFinite(totalCount) && totalCount >= 0
95
+ ? Math.floor(totalCount)
96
+ : 0;
97
+ const hasVisibleItems = Array.isArray(this.sessionTrashItems) && this.sessionTrashItems.length > 0;
98
+ if (this.sessionTrashLastLoadFailed && (!this.sessionTrashLoadedOnce || !hasVisibleItems)) {
99
+ return 'retry';
100
+ }
101
+ if (!this.sessionTrashLoadedOnce) {
102
+ return normalizedTotalCount > 0 ? 'retry' : 'empty';
103
+ }
104
+ if (normalizedTotalCount === 0) {
105
+ return 'empty';
106
+ }
107
+ return hasVisibleItems ? 'list' : 'retry';
108
+ },
109
+
110
+ issueSessionTrashCountRequestToken() {
111
+ const currentToken = Number(this.sessionTrashCountRequestToken);
112
+ const nextToken = Number.isFinite(currentToken) && currentToken >= 0
113
+ ? Math.floor(currentToken) + 1
114
+ : 1;
115
+ this.sessionTrashCountRequestToken = nextToken;
116
+ return nextToken;
117
+ },
118
+
119
+ issueSessionTrashListRequestToken() {
120
+ const currentToken = Number(this.sessionTrashListRequestToken);
121
+ const nextToken = Number.isFinite(currentToken) && currentToken >= 0
122
+ ? Math.floor(currentToken) + 1
123
+ : 1;
124
+ this.sessionTrashListRequestToken = nextToken;
125
+ return nextToken;
126
+ },
127
+
128
+ invalidateSessionTrashRequests() {
129
+ this.issueSessionTrashCountRequestToken();
130
+ return this.issueSessionTrashListRequestToken();
131
+ },
132
+
133
+ isLatestSessionTrashCountRequestToken(token) {
134
+ return Number(token) === Number(this.sessionTrashCountRequestToken);
135
+ },
136
+
137
+ isLatestSessionTrashListRequestToken(token) {
138
+ return Number(token) === Number(this.sessionTrashListRequestToken);
139
+ },
140
+
141
+ resetSessionTrashVisibleCount() {
142
+ const totalItems = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
143
+ this.sessionTrashVisibleCount = Math.min(totalItems, sessionTrashPageSize) || sessionTrashPageSize;
144
+ },
145
+
146
+ loadMoreSessionTrashItems() {
147
+ const totalItems = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
148
+ const visibleCount = Number(this.sessionTrashVisibleCount);
149
+ const safeVisibleCount = Number.isFinite(visibleCount) && visibleCount > 0
150
+ ? Math.floor(visibleCount)
151
+ : sessionTrashPageSize;
152
+ this.sessionTrashVisibleCount = Math.min(totalItems, safeVisibleCount + sessionTrashPageSize);
153
+ },
154
+
155
+ clearActiveSessionState() {
156
+ this.activeSession = null;
157
+ this.activeSessionMessages = [];
158
+ this.resetSessionDetailPagination();
159
+ this.resetSessionPreviewMessageRender();
160
+ this.activeSessionDetailError = '';
161
+ this.activeSessionDetailClipped = false;
162
+ this.cancelSessionTimelineSync();
163
+ this.sessionTimelineActiveKey = '';
164
+ this.clearSessionTimelineRefs();
165
+ },
166
+
167
+ async removeSessionFromCurrentList(session) {
168
+ const sessionKey = this.getSessionExportKey(session);
169
+ if (!sessionKey) {
170
+ return;
171
+ }
172
+ const currentList = Array.isArray(this.sessionsList) ? [...this.sessionsList] : [];
173
+ const removedIndex = currentList.findIndex((item) => this.getSessionExportKey(item) === sessionKey);
174
+ if (removedIndex < 0) {
175
+ return;
176
+ }
177
+ const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
178
+ const renderedList = Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
179
+ const renderedIndex = renderedList.findIndex((item) => this.getSessionExportKey(item) === sessionKey);
180
+ let nextActiveKey = '';
181
+ if (activeKey === sessionKey && renderedIndex >= 0) {
182
+ const fallbackSession = renderedList[renderedIndex - 1] || renderedList[renderedIndex + 1] || null;
183
+ nextActiveKey = fallbackSession ? this.getSessionExportKey(fallbackSession) : '';
184
+ }
185
+ currentList.splice(removedIndex, 1);
186
+ this.sessionsList = currentList;
187
+ this.syncSessionPathOptionsForSource(
188
+ this.sessionFilterSource,
189
+ this.extractPathOptionsFromSessions(currentList),
190
+ false
191
+ );
192
+ if (activeKey !== sessionKey) {
193
+ return;
194
+ }
195
+ if (currentList.length === 0) {
196
+ this.clearActiveSessionState();
197
+ return;
198
+ }
199
+ const nextSession = currentList.find((item) => this.getSessionExportKey(item) === nextActiveKey)
200
+ || currentList[Math.min(removedIndex, currentList.length - 1)];
201
+ if (!nextSession) {
202
+ this.clearActiveSessionState();
203
+ return;
204
+ }
205
+ await this.selectSession(nextSession);
206
+ },
207
+
208
+ normalizeSettingsTab(tab) {
209
+ if (tab === 'trash' || tab === 'device') {
210
+ return tab;
211
+ }
212
+ return 'backup';
213
+ },
214
+
215
+ async onSettingsTabClick(tab) {
216
+ await this.switchSettingsTab(tab);
217
+ },
218
+
219
+ async switchSettingsTab(tab, options = {}) {
220
+ const nextTab = this.normalizeSettingsTab(tab);
221
+ this.settingsTab = nextTab;
222
+ if (nextTab !== 'trash') {
223
+ return;
224
+ }
225
+ const forceRefresh = options.forceRefresh === true;
226
+ if (forceRefresh || !this.sessionTrashLoadedOnce) {
227
+ await this.loadSessionTrash({ forceRefresh });
228
+ }
229
+ },
230
+
231
+ async loadSessionTrashCount(options = {}) {
232
+ if (this.sessionTrashCountLoading) {
233
+ this.sessionTrashCountPendingOptions = {
234
+ ...(this.sessionTrashCountPendingOptions || {}),
235
+ ...(options || {})
236
+ };
237
+ return;
238
+ }
239
+ const requestToken = this.issueSessionTrashCountRequestToken();
240
+ this.sessionTrashCountLoading = true;
241
+ try {
242
+ const res = await api('list-session-trash', { countOnly: true });
243
+ if (!this.isLatestSessionTrashCountRequestToken(requestToken)) {
244
+ return;
245
+ }
246
+ if (res.error) {
247
+ if (options.silent !== true) {
248
+ this.showMessage(res.error, 'error');
249
+ }
250
+ return;
251
+ }
252
+ this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(
253
+ res.totalCount,
254
+ this.sessionTrashItems
255
+ );
256
+ this.sessionTrashCountLoadedOnce = true;
257
+ } catch (e) {
258
+ if (this.isLatestSessionTrashCountRequestToken(requestToken) && options.silent !== true) {
259
+ this.showMessage('加载回收站数量失败', 'error');
260
+ }
261
+ } finally {
262
+ this.sessionTrashCountLoading = false;
263
+ const pendingOptions = this.sessionTrashCountPendingOptions;
264
+ this.sessionTrashCountPendingOptions = null;
265
+ if (pendingOptions) {
266
+ await this.loadSessionTrashCount(pendingOptions);
267
+ }
268
+ }
269
+ },
270
+
271
+ getSessionTrashActionKey(item) {
272
+ return item && typeof item.trashId === 'string' ? item.trashId : '';
273
+ },
274
+
275
+ isSessionTrashActionBusy(item) {
276
+ const key = typeof item === 'string' ? item : this.getSessionTrashActionKey(item);
277
+ return !!(key && (this.sessionTrashRestoring[key] || this.sessionTrashPurging[key]));
278
+ },
279
+
280
+ async loadSessionTrash(options = {}) {
281
+ if (this.sessionTrashLoading) {
282
+ this.sessionTrashPendingOptions = {
283
+ ...(this.sessionTrashPendingOptions || {}),
284
+ ...(options || {})
285
+ };
286
+ return;
287
+ }
288
+ const requestToken = this.issueSessionTrashListRequestToken();
289
+ this.sessionTrashLoading = true;
290
+ this.sessionTrashLastLoadFailed = false;
291
+ let loadSucceeded = false;
292
+ try {
293
+ const res = await api('list-session-trash', {
294
+ limit: sessionTrashListLimit,
295
+ forceRefresh: !!options.forceRefresh
296
+ });
297
+ if (!this.isLatestSessionTrashListRequestToken(requestToken)) {
298
+ return;
299
+ }
300
+ if (res.error) {
301
+ this.sessionTrashLastLoadFailed = true;
302
+ this.showMessage(res.error, 'error');
303
+ return;
304
+ }
305
+ const nextItems = Array.isArray(res.items) ? res.items : [];
306
+ this.sessionTrashItems = nextItems;
307
+ this.resetSessionTrashVisibleCount();
308
+ this.sessionTrashTotalCount = this.normalizeSessionTrashTotalCount(res.totalCount, nextItems);
309
+ this.sessionTrashCountLoadedOnce = true;
310
+ this.sessionTrashLastLoadFailed = false;
311
+ loadSucceeded = true;
312
+ } catch (e) {
313
+ if (this.isLatestSessionTrashListRequestToken(requestToken)) {
314
+ this.sessionTrashLastLoadFailed = true;
315
+ this.showMessage('加载回收站失败', 'error');
316
+ }
317
+ } finally {
318
+ this.sessionTrashLoading = false;
319
+ if (loadSucceeded) {
320
+ this.sessionTrashLoadedOnce = true;
321
+ }
322
+ const pendingOptions = this.sessionTrashPendingOptions;
323
+ this.sessionTrashPendingOptions = null;
324
+ if (pendingOptions) {
325
+ await this.loadSessionTrash(pendingOptions);
326
+ }
327
+ }
328
+ },
329
+
330
+ async restoreSessionTrash(item) {
331
+ const key = this.getSessionTrashActionKey(item);
332
+ if (!key || this.isSessionTrashActionBusy(key) || this.sessionTrashClearing) {
333
+ return;
334
+ }
335
+ this.sessionTrashRestoring[key] = true;
336
+ try {
337
+ const res = await api('restore-session-trash', { trashId: key });
338
+ if (res.error) {
339
+ this.showMessage(res.error, 'error');
340
+ return;
341
+ }
342
+ this.showMessage('会话已恢复', 'success');
343
+ if (typeof this.invalidateSessionsUsageData === 'function') {
344
+ this.invalidateSessionsUsageData({ preserveList: true });
345
+ }
346
+ this.invalidateSessionTrashRequests();
347
+ await this.loadSessionTrash({ forceRefresh: true });
348
+ if (this.sessionsLoadedOnce) {
349
+ await this.loadSessions();
350
+ }
351
+ } catch (e) {
352
+ this.showMessage('恢复失败', 'error');
353
+ } finally {
354
+ this.sessionTrashRestoring[key] = false;
355
+ }
356
+ },
357
+
358
+ async purgeSessionTrash(item) {
359
+ const key = this.getSessionTrashActionKey(item);
360
+ if (!key || this.isSessionTrashActionBusy(key) || this.sessionTrashClearing) {
361
+ return;
362
+ }
363
+ const confirmed = await this.requestConfirmDialog({
364
+ title: '彻底删除回收站记录',
365
+ message: '该会话将从回收站永久删除,且无法恢复。',
366
+ confirmText: '彻底删除',
367
+ cancelText: '取消',
368
+ danger: true
369
+ });
370
+ if (!confirmed) {
371
+ return;
372
+ }
373
+ this.sessionTrashPurging[key] = true;
374
+ try {
375
+ const res = await api('purge-session-trash', { trashId: key });
376
+ if (res.error) {
377
+ this.showMessage(res.error, 'error');
378
+ return;
379
+ }
380
+ this.showMessage('已彻底删除', 'success');
381
+ this.invalidateSessionTrashRequests();
382
+ await this.loadSessionTrash({ forceRefresh: true });
383
+ } catch (e) {
384
+ this.showMessage('彻底删除失败', 'error');
385
+ } finally {
386
+ this.sessionTrashPurging[key] = false;
387
+ }
388
+ },
389
+
390
+ async clearSessionTrash() {
391
+ const normalizedCount = Number(this.sessionTrashCount);
392
+ if (this.sessionTrashClearing || !Number.isFinite(normalizedCount) || normalizedCount <= 0) {
393
+ return;
394
+ }
395
+ const confirmed = await this.requestConfirmDialog({
396
+ title: '清空回收站',
397
+ message: '该操作会永久删除回收站中的全部会话,且无法恢复。',
398
+ confirmText: '全部清空',
399
+ cancelText: '取消',
400
+ danger: true
401
+ });
402
+ if (!confirmed) {
403
+ return;
404
+ }
405
+ this.sessionTrashClearing = true;
406
+ try {
407
+ const res = await api('purge-session-trash', { all: true });
408
+ if (res.error) {
409
+ this.showMessage(res.error, 'error');
410
+ return;
411
+ }
412
+ this.showMessage('回收站已清空', 'success');
413
+ this.invalidateSessionTrashRequests();
414
+ await this.loadSessionTrash({ forceRefresh: true });
415
+ } catch (e) {
416
+ this.showMessage('清空回收站失败', 'error');
417
+ } finally {
418
+ this.sessionTrashClearing = false;
419
+ }
420
+ }
421
+ };
422
+ }