codexmate 0.0.19 → 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 (67) hide show
  1. package/README.en.md +8 -4
  2. package/README.md +8 -4
  3. package/cli/config-health.js +338 -0
  4. package/cli.js +1136 -584
  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 +381 -5532
  9. package/web-ui/index.html +15 -2231
  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/partials/index/layout-footer.html +69 -0
  37. package/web-ui/partials/index/layout-header.html +337 -0
  38. package/web-ui/partials/index/modal-config-template-agents.html +125 -0
  39. package/web-ui/partials/index/modal-confirm-toast.html +32 -0
  40. package/web-ui/partials/index/modal-health-check.html +72 -0
  41. package/web-ui/partials/index/modal-openclaw-config.html +275 -0
  42. package/web-ui/partials/index/modal-skills.html +184 -0
  43. package/web-ui/partials/index/modals-basic.html +196 -0
  44. package/web-ui/partials/index/panel-config-claude.html +100 -0
  45. package/web-ui/partials/index/panel-config-codex.html +237 -0
  46. package/web-ui/partials/index/panel-config-openclaw.html +84 -0
  47. package/web-ui/partials/index/panel-market.html +174 -0
  48. package/web-ui/partials/index/panel-sessions.html +387 -0
  49. package/web-ui/partials/index/panel-settings.html +166 -0
  50. package/web-ui/source-bundle.cjs +233 -0
  51. package/web-ui/styles/base-theme.css +373 -0
  52. package/web-ui/styles/controls-forms.css +354 -0
  53. package/web-ui/styles/feedback.css +108 -0
  54. package/web-ui/styles/health-check-dialog.css +144 -0
  55. package/web-ui/styles/layout-shell.css +330 -0
  56. package/web-ui/styles/modals-core.css +449 -0
  57. package/web-ui/styles/navigation-panels.css +381 -0
  58. package/web-ui/styles/openclaw-structured.css +266 -0
  59. package/web-ui/styles/responsive.css +416 -0
  60. package/web-ui/styles/sessions-list.css +414 -0
  61. package/web-ui/styles/sessions-preview.css +405 -0
  62. package/web-ui/styles/sessions-toolbar-trash.css +243 -0
  63. package/web-ui/styles/sessions-usage.css +276 -0
  64. package/web-ui/styles/skills-list.css +298 -0
  65. package/web-ui/styles/skills-market.css +335 -0
  66. package/web-ui/styles/titles-cards.css +407 -0
  67. package/web-ui/styles.css +16 -4668
@@ -0,0 +1,435 @@
1
+ import {
2
+ buildSessionFilterCacheState,
3
+ isSessionQueryEnabled,
4
+ normalizeSessionMessageRole,
5
+ normalizeSessionPathFilter
6
+ } from '../logic.mjs';
7
+
8
+ export function createSessionBrowserMethods(options = {}) {
9
+ const {
10
+ api,
11
+ loadSessionsHelper,
12
+ loadActiveSessionDetailHelper
13
+ } = options;
14
+
15
+ return {
16
+ normalizeSessionPathValue(value) {
17
+ return normalizeSessionPathFilter(value);
18
+ },
19
+
20
+ mergeSessionPathOptions(baseList = [], incomingList = []) {
21
+ const merged = [];
22
+ const seen = new Set();
23
+ const append = (items) => {
24
+ if (!Array.isArray(items)) return;
25
+ for (const item of items) {
26
+ const value = this.normalizeSessionPathValue(item);
27
+ if (!value) continue;
28
+ const key = value.toLowerCase();
29
+ if (seen.has(key)) continue;
30
+ seen.add(key);
31
+ merged.push(value);
32
+ }
33
+ };
34
+
35
+ append(baseList);
36
+ append(incomingList);
37
+ return merged;
38
+ },
39
+
40
+ extractPathOptionsFromSessions(sessions) {
41
+ const paths = [];
42
+ if (!Array.isArray(sessions)) {
43
+ return paths;
44
+ }
45
+
46
+ const seen = new Set();
47
+ for (const session of sessions) {
48
+ const value = this.normalizeSessionPathValue(session && session.cwd ? session.cwd : '');
49
+ if (!value) continue;
50
+ const key = value.toLowerCase();
51
+ if (seen.has(key)) continue;
52
+ seen.add(key);
53
+ paths.push(value);
54
+ }
55
+ return paths;
56
+ },
57
+
58
+ syncSessionPathOptionsForSource(source, nextOptions, mergeWithExisting = false) {
59
+ const targetSource = source === 'claude' ? 'claude' : (source === 'all' ? 'all' : 'codex');
60
+ const current = Array.isArray(this.sessionPathOptionsMap[targetSource])
61
+ ? this.sessionPathOptionsMap[targetSource]
62
+ : [];
63
+ const merged = mergeWithExisting
64
+ ? this.mergeSessionPathOptions(current, nextOptions)
65
+ : this.mergeSessionPathOptions([], nextOptions);
66
+ this.sessionPathOptionsMap = {
67
+ ...this.sessionPathOptionsMap,
68
+ [targetSource]: merged
69
+ };
70
+ this.refreshSessionPathOptions(targetSource);
71
+ },
72
+
73
+ refreshSessionPathOptions(source) {
74
+ const targetSource = source === 'claude' ? 'claude' : (source === 'all' ? 'all' : 'codex');
75
+ const base = Array.isArray(this.sessionPathOptionsMap[targetSource])
76
+ ? [...this.sessionPathOptionsMap[targetSource]]
77
+ : [];
78
+ const selected = this.normalizeSessionPathValue(this.sessionPathFilter);
79
+ if (selected && !base.some(item => item.toLowerCase() === selected.toLowerCase())) {
80
+ base.unshift(selected);
81
+ }
82
+ if (targetSource === this.sessionFilterSource) {
83
+ this.sessionPathOptions = base;
84
+ }
85
+ },
86
+
87
+ async loadSessionPathOptions(options = {}) {
88
+ const source = options.source === 'claude' ? 'claude' : (options.source === 'all' ? 'all' : 'codex');
89
+ const forceRefresh = !!options.forceRefresh;
90
+ const loaded = !!this.sessionPathOptionsLoadedMap[source];
91
+ if (!forceRefresh && loaded) {
92
+ if (source === this.sessionFilterSource) {
93
+ this.sessionPathOptionsLoading = false;
94
+ }
95
+ return;
96
+ }
97
+
98
+ const nextSeqMap = {
99
+ ...(this.sessionPathRequestSeqMap || {})
100
+ };
101
+ const requestSeq = (Number(nextSeqMap[source]) || 0) + 1;
102
+ nextSeqMap[source] = requestSeq;
103
+ this.sessionPathRequestSeqMap = nextSeqMap;
104
+ if (source === this.sessionFilterSource) {
105
+ this.sessionPathOptionsLoading = true;
106
+ }
107
+ try {
108
+ const res = await api('list-session-paths', {
109
+ source,
110
+ limit: 500,
111
+ forceRefresh
112
+ });
113
+ if (requestSeq !== Number(((this.sessionPathRequestSeqMap || {})[source]) || 0)) {
114
+ return;
115
+ }
116
+ if (res && !res.error && Array.isArray(res.paths)) {
117
+ this.syncSessionPathOptionsForSource(source, res.paths, true);
118
+ this.sessionPathOptionsLoadedMap = {
119
+ ...this.sessionPathOptionsLoadedMap,
120
+ [source]: true
121
+ };
122
+ }
123
+ } catch (_) {
124
+ // 路径补全失败不影响会话主流程
125
+ } finally {
126
+ if (
127
+ source === this.sessionFilterSource
128
+ && requestSeq === Number(((this.sessionPathRequestSeqMap || {})[source]) || 0)
129
+ ) {
130
+ this.sessionPathOptionsLoading = false;
131
+ }
132
+ }
133
+ },
134
+
135
+ onSessionResumeYoloChange() {
136
+ const value = this.sessionResumeWithYolo ? '1' : '0';
137
+ localStorage.setItem('codexmateSessionResumeYolo', value);
138
+ },
139
+
140
+ restoreSessionFilterCache() {
141
+ const sourceCache = localStorage.getItem('codexmateSessionFilterSource');
142
+ const pathCache = localStorage.getItem('codexmateSessionPathFilter');
143
+ const cached = buildSessionFilterCacheState(sourceCache, pathCache);
144
+ this.sessionFilterSource = cached.source;
145
+ this.sessionPathFilter = cached.pathFilter;
146
+ this.refreshSessionPathOptions(this.sessionFilterSource);
147
+ },
148
+
149
+ persistSessionFilterCache() {
150
+ const cached = buildSessionFilterCacheState(this.sessionFilterSource, this.sessionPathFilter);
151
+ localStorage.setItem('codexmateSessionFilterSource', cached.source);
152
+ if (cached.pathFilter) {
153
+ localStorage.setItem('codexmateSessionPathFilter', cached.pathFilter);
154
+ } else {
155
+ localStorage.removeItem('codexmateSessionPathFilter');
156
+ }
157
+ },
158
+
159
+ normalizeSessionPinnedMap(raw) {
160
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
161
+ return {};
162
+ }
163
+ const next = {};
164
+ for (const [key, value] of Object.entries(raw)) {
165
+ if (!key) continue;
166
+ const numeric = Number(value);
167
+ if (!Number.isFinite(numeric) || numeric <= 0) continue;
168
+ next[key] = Math.floor(numeric);
169
+ }
170
+ return next;
171
+ },
172
+
173
+ restoreSessionPinnedMap() {
174
+ const cached = localStorage.getItem('codexmateSessionPinnedMap');
175
+ if (!cached) {
176
+ this.sessionPinnedMap = {};
177
+ return;
178
+ }
179
+ try {
180
+ const parsed = JSON.parse(cached);
181
+ this.sessionPinnedMap = this.normalizeSessionPinnedMap(parsed);
182
+ } catch (_) {
183
+ this.sessionPinnedMap = {};
184
+ localStorage.removeItem('codexmateSessionPinnedMap');
185
+ }
186
+ },
187
+
188
+ persistSessionPinnedMap() {
189
+ const payload = (this.sessionPinnedMap && typeof this.sessionPinnedMap === 'object')
190
+ ? this.sessionPinnedMap
191
+ : {};
192
+ localStorage.setItem('codexmateSessionPinnedMap', JSON.stringify(payload));
193
+ },
194
+
195
+ shouldPruneSessionPinnedMap(sessions = this.sessionsList) {
196
+ if (!Array.isArray(sessions) || sessions.length === 0) {
197
+ return false;
198
+ }
199
+ if (this.sessionFilterSource !== 'all') {
200
+ return false;
201
+ }
202
+ if (this.sessionPathFilter) {
203
+ return false;
204
+ }
205
+ if (this.sessionQuery && isSessionQueryEnabled(this.sessionFilterSource)) {
206
+ return false;
207
+ }
208
+ if (this.sessionRoleFilter && this.sessionRoleFilter !== 'all') {
209
+ return false;
210
+ }
211
+ if (this.sessionTimePreset && this.sessionTimePreset !== 'all') {
212
+ return false;
213
+ }
214
+ return true;
215
+ },
216
+
217
+ pruneSessionPinnedMap(sessions = this.sessionsList) {
218
+ const current = (this.sessionPinnedMap && typeof this.sessionPinnedMap === 'object')
219
+ ? this.sessionPinnedMap
220
+ : {};
221
+ const list = Array.isArray(sessions) ? sessions : [];
222
+ if (Object.keys(current).length === 0 || !this.shouldPruneSessionPinnedMap(list)) {
223
+ return;
224
+ }
225
+ const validKeys = new Set(list.map((session) => this.getSessionExportKey(session)).filter(Boolean));
226
+ const next = {};
227
+ let changed = false;
228
+ for (const [key, value] of Object.entries(current)) {
229
+ if (!validKeys.has(key)) {
230
+ changed = true;
231
+ continue;
232
+ }
233
+ next[key] = value;
234
+ }
235
+ if (!changed) {
236
+ return;
237
+ }
238
+ this.sessionPinnedMap = next;
239
+ this.persistSessionPinnedMap();
240
+ },
241
+
242
+ getSessionPinTimestamp(session) {
243
+ if (!session) return 0;
244
+ const key = this.getSessionExportKey(session);
245
+ if (!key) return 0;
246
+ const raw = this.sessionPinnedMap && this.sessionPinnedMap[key];
247
+ const numeric = Number(raw);
248
+ return Number.isFinite(numeric) && numeric > 0 ? Math.floor(numeric) : 0;
249
+ },
250
+
251
+ isSessionPinned(session) {
252
+ return this.getSessionPinTimestamp(session) > 0;
253
+ },
254
+
255
+ toggleSessionPin(session) {
256
+ if (!session) return;
257
+ const key = this.getSessionExportKey(session);
258
+ if (!key) return;
259
+ const current = (this.sessionPinnedMap && typeof this.sessionPinnedMap === 'object')
260
+ ? this.sessionPinnedMap
261
+ : {};
262
+ const next = { ...current };
263
+ if (next[key]) {
264
+ delete next[key];
265
+ } else {
266
+ next[key] = Date.now();
267
+ }
268
+ this.sessionPinnedMap = next;
269
+ this.persistSessionPinnedMap();
270
+ },
271
+
272
+ removeSessionPin(session) {
273
+ if (!session) return;
274
+ const key = this.getSessionExportKey(session);
275
+ if (!key) return;
276
+ const current = (this.sessionPinnedMap && typeof this.sessionPinnedMap === 'object')
277
+ ? this.sessionPinnedMap
278
+ : {};
279
+ if (!current[key]) return;
280
+ const next = { ...current };
281
+ delete next[key];
282
+ this.sessionPinnedMap = next;
283
+ this.persistSessionPinnedMap();
284
+ },
285
+
286
+ async onSessionSourceChange() {
287
+ this.refreshSessionPathOptions(this.sessionFilterSource);
288
+ this.persistSessionFilterCache();
289
+ await this.loadSessions();
290
+ },
291
+
292
+ async onSessionPathFilterChange() {
293
+ this.persistSessionFilterCache();
294
+ await this.loadSessions();
295
+ },
296
+
297
+ async onSessionFilterChange() {
298
+ await this.loadSessions();
299
+ },
300
+
301
+ async clearSessionFilters() {
302
+ this.sessionFilterSource = 'all';
303
+ this.sessionPathFilter = '';
304
+ this.sessionQuery = '';
305
+ this.sessionRoleFilter = 'all';
306
+ this.sessionTimePreset = 'all';
307
+ this.persistSessionFilterCache();
308
+ await this.onSessionSourceChange();
309
+ },
310
+
311
+ normalizeSessionMessage(message) {
312
+ const fallback = {
313
+ role: 'assistant',
314
+ normalizedRole: 'assistant',
315
+ roleLabel: 'Assistant',
316
+ text: typeof message === 'string' ? message : '',
317
+ timestamp: ''
318
+ };
319
+ const safeMessage = message && typeof message === 'object' ? message : fallback;
320
+ const normalizedRole = normalizeSessionMessageRole(
321
+ safeMessage.normalizedRole || safeMessage.role
322
+ );
323
+ const roleLabel = normalizedRole === 'user'
324
+ ? 'User'
325
+ : (normalizedRole === 'system' ? 'System' : 'Assistant');
326
+ return {
327
+ ...safeMessage,
328
+ role: normalizedRole,
329
+ normalizedRole,
330
+ roleLabel
331
+ };
332
+ },
333
+
334
+ getRecordKey(message) {
335
+ if (!message || !Number.isInteger(message.recordLineIndex) || message.recordLineIndex < 0) {
336
+ return '';
337
+ }
338
+ return String(message.recordLineIndex);
339
+ },
340
+
341
+ getRecordRenderKey(message, idx) {
342
+ const recordKey = this.getRecordKey(message);
343
+ if (recordKey) {
344
+ return `record-${recordKey}`;
345
+ }
346
+ return `record-fallback-${idx}-${message && message.timestamp ? message.timestamp : ''}`;
347
+ },
348
+
349
+ syncActiveSessionMessageCount(messageCount) {
350
+ if (!Number.isFinite(messageCount) || messageCount < 0) return;
351
+ if (this.activeSession) {
352
+ this.activeSession.messageCount = messageCount;
353
+ }
354
+ const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
355
+ if (!activeKey) return;
356
+ const matched = this.sessionsList.find(item => this.getSessionExportKey(item) === activeKey);
357
+ if (matched) {
358
+ matched.messageCount = messageCount;
359
+ }
360
+ },
361
+
362
+ async loadSessions() {
363
+ const result = await loadSessionsHelper.call(this, api);
364
+ this.pruneSessionPinnedMap(this.sessionsList);
365
+ return result;
366
+ },
367
+
368
+ async selectSession(session) {
369
+ if (!session) return;
370
+ if (this.activeSession && this.getSessionExportKey(this.activeSession) === this.getSessionExportKey(session)) return;
371
+ this.activeSession = session;
372
+ this.activeSessionMessages = [];
373
+ this.resetSessionDetailPagination();
374
+ this.resetSessionPreviewMessageRender();
375
+ this.activeSessionDetailError = '';
376
+ this.activeSessionDetailClipped = false;
377
+ this.cancelSessionTimelineSync();
378
+ this.sessionTimelineActiveKey = '';
379
+ this.clearSessionTimelineRefs();
380
+ await this.loadActiveSessionDetail();
381
+ },
382
+
383
+ async loadSessionStandalonePlain() {
384
+ if (!this.activeSession) {
385
+ this.sessionStandaloneRequestSeq += 1;
386
+ this.sessionStandaloneLoading = false;
387
+ this.sessionStandaloneText = '';
388
+ this.sessionStandaloneTitle = '会话';
389
+ this.sessionStandaloneSourceLabel = '';
390
+ this.sessionStandaloneError = '';
391
+ return;
392
+ }
393
+
394
+ const requestSeq = ++this.sessionStandaloneRequestSeq;
395
+ const sessionSnapshot = this.activeSession;
396
+ this.sessionStandaloneLoading = true;
397
+ this.sessionStandaloneError = '';
398
+ try {
399
+ const res = await api('session-plain', {
400
+ source: sessionSnapshot.source,
401
+ sessionId: sessionSnapshot.sessionId,
402
+ filePath: sessionSnapshot.filePath
403
+ });
404
+
405
+ if (requestSeq !== this.sessionStandaloneRequestSeq) {
406
+ return;
407
+ }
408
+
409
+ if (res.error) {
410
+ this.sessionStandaloneText = '';
411
+ this.sessionStandaloneError = res.error;
412
+ return;
413
+ }
414
+
415
+ this.sessionStandaloneSourceLabel = res.sourceLabel || sessionSnapshot.sourceLabel || '';
416
+ this.sessionStandaloneTitle = res.sessionId || sessionSnapshot.title || '会话';
417
+ this.sessionStandaloneText = typeof res.text === 'string' ? res.text : '';
418
+ } catch (e) {
419
+ if (requestSeq !== this.sessionStandaloneRequestSeq) {
420
+ return;
421
+ }
422
+ this.sessionStandaloneText = '';
423
+ this.sessionStandaloneError = '加载会话内容失败: ' + e.message;
424
+ } finally {
425
+ if (requestSeq === this.sessionStandaloneRequestSeq) {
426
+ this.sessionStandaloneLoading = false;
427
+ }
428
+ }
429
+ },
430
+
431
+ async loadActiveSessionDetail(options = {}) {
432
+ return loadActiveSessionDetailHelper.call(this, api, options);
433
+ }
434
+ };
435
+ }