codexmate 0.0.18 → 0.0.20

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 (73) hide show
  1. package/README.en.md +34 -17
  2. package/README.md +34 -25
  3. package/cli/config-health.js +338 -0
  4. package/cli.js +1570 -839
  5. package/lib/cli-models-utils.js +186 -27
  6. package/lib/cli-network-utils.js +117 -101
  7. package/package.json +8 -1
  8. package/web-ui/app.js +379 -5754
  9. package/web-ui/index.html +15 -2079
  10. package/web-ui/logic.agents-diff.mjs +386 -0
  11. package/web-ui/logic.claude.mjs +108 -0
  12. package/web-ui/logic.mjs +5 -793
  13. package/web-ui/logic.runtime.mjs +124 -0
  14. package/web-ui/logic.sessions.mjs +263 -0
  15. package/web-ui/modules/api.mjs +69 -0
  16. package/web-ui/modules/app.computed.dashboard.mjs +113 -0
  17. package/web-ui/modules/app.computed.index.mjs +13 -0
  18. package/web-ui/modules/app.computed.session.mjs +141 -0
  19. package/web-ui/modules/app.constants.mjs +15 -0
  20. package/web-ui/modules/app.methods.agents.mjs +493 -0
  21. package/web-ui/modules/app.methods.claude-config.mjs +174 -0
  22. package/web-ui/modules/app.methods.codex-config.mjs +640 -0
  23. package/web-ui/modules/app.methods.index.mjs +86 -0
  24. package/web-ui/modules/app.methods.install.mjs +157 -0
  25. package/web-ui/modules/app.methods.navigation.mjs +478 -0
  26. package/web-ui/modules/app.methods.openclaw-core.mjs +514 -0
  27. package/web-ui/modules/app.methods.openclaw-editing.mjs +337 -0
  28. package/web-ui/modules/app.methods.openclaw-persist.mjs +251 -0
  29. package/web-ui/modules/app.methods.providers.mjs +265 -0
  30. package/web-ui/modules/app.methods.runtime.mjs +323 -0
  31. package/web-ui/modules/app.methods.session-actions.mjs +457 -0
  32. package/web-ui/modules/app.methods.session-browser.mjs +435 -0
  33. package/web-ui/modules/app.methods.session-timeline.mjs +441 -0
  34. package/web-ui/modules/app.methods.session-trash.mjs +419 -0
  35. package/web-ui/modules/app.methods.startup-claude.mjs +406 -0
  36. package/web-ui/modules/config-mode.computed.mjs +1 -0
  37. package/web-ui/modules/skills.computed.mjs +26 -1
  38. package/web-ui/modules/skills.methods.mjs +154 -23
  39. package/web-ui/partials/index/layout-footer.html +69 -0
  40. package/web-ui/partials/index/layout-header.html +337 -0
  41. package/web-ui/partials/index/modal-config-template-agents.html +125 -0
  42. package/web-ui/partials/index/modal-confirm-toast.html +32 -0
  43. package/web-ui/partials/index/modal-health-check.html +72 -0
  44. package/web-ui/partials/index/modal-openclaw-config.html +275 -0
  45. package/web-ui/partials/index/modal-skills.html +184 -0
  46. package/web-ui/partials/index/modals-basic.html +196 -0
  47. package/web-ui/partials/index/panel-config-claude.html +100 -0
  48. package/web-ui/partials/index/panel-config-codex.html +237 -0
  49. package/web-ui/partials/index/panel-config-openclaw.html +84 -0
  50. package/web-ui/partials/index/panel-market.html +174 -0
  51. package/web-ui/partials/index/panel-sessions.html +387 -0
  52. package/web-ui/partials/index/panel-settings.html +166 -0
  53. package/web-ui/session-helpers.mjs +12 -0
  54. package/web-ui/source-bundle.cjs +233 -0
  55. package/web-ui/styles/base-theme.css +373 -0
  56. package/web-ui/styles/controls-forms.css +354 -0
  57. package/web-ui/styles/feedback.css +108 -0
  58. package/web-ui/styles/health-check-dialog.css +144 -0
  59. package/web-ui/styles/layout-shell.css +330 -0
  60. package/web-ui/styles/modals-core.css +449 -0
  61. package/web-ui/styles/navigation-panels.css +381 -0
  62. package/web-ui/styles/openclaw-structured.css +266 -0
  63. package/web-ui/styles/responsive.css +416 -0
  64. package/web-ui/styles/sessions-list.css +414 -0
  65. package/web-ui/styles/sessions-preview.css +405 -0
  66. package/web-ui/styles/sessions-toolbar-trash.css +243 -0
  67. package/web-ui/styles/sessions-usage.css +276 -0
  68. package/web-ui/styles/skills-list.css +298 -0
  69. package/web-ui/styles/skills-market.css +335 -0
  70. package/web-ui/styles/titles-cards.css +407 -0
  71. package/web-ui/styles.css +16 -4499
  72. package/doc/CHANGELOG.md +0 -32
  73. package/doc/CHANGELOG.zh-CN.md +0 -34
@@ -0,0 +1,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
+ 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
+ }