codexmate 0.0.17 → 0.0.19
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.
- package/README.en.md +65 -33
- package/README.md +61 -37
- package/cli.js +1877 -408
- package/lib/text-diff.js +303 -0
- package/package.json +1 -1
- package/web-ui/app.js +1749 -447
- package/web-ui/index.html +580 -199
- package/web-ui/logic.mjs +390 -0
- package/web-ui/modules/config-mode.computed.mjs +1 -0
- package/web-ui/modules/skills.computed.mjs +26 -1
- package/web-ui/modules/skills.methods.mjs +160 -23
- package/web-ui/session-helpers.mjs +362 -0
- package/web-ui/styles.css +652 -13
- package/doc/CHANGELOG.md +0 -32
- package/doc/CHANGELOG.zh-CN.md +0 -34
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { buildSessionListParams } from './logic.mjs';
|
|
2
|
+
|
|
3
|
+
function clearSessionTimelineRefs(vm) {
|
|
4
|
+
if (typeof vm.clearSessionTimelineRefs === 'function') {
|
|
5
|
+
vm.clearSessionTimelineRefs();
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
vm.sessionMessageRefMap = Object.create(null);
|
|
9
|
+
if (vm && typeof vm === 'object' && Object.prototype.hasOwnProperty.call(vm, 'sessionMessageRefBinderMap')) {
|
|
10
|
+
vm.sessionMessageRefBinderMap = Object.create(null);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function switchMainTab(tab) {
|
|
15
|
+
const nextTab = typeof tab === 'string' ? tab : '';
|
|
16
|
+
const previousTab = this.mainTab;
|
|
17
|
+
const leavingSessions = previousTab === 'sessions' && nextTab !== 'sessions';
|
|
18
|
+
this.mainTab = nextTab;
|
|
19
|
+
|
|
20
|
+
if (leavingSessions) {
|
|
21
|
+
const teardown = () => {
|
|
22
|
+
if (this.mainTab === 'sessions') return;
|
|
23
|
+
if (typeof this.finalizeSessionTabTeardown === 'function') {
|
|
24
|
+
if (typeof this.suspendSessionTabRender === 'function') {
|
|
25
|
+
this.suspendSessionTabRender();
|
|
26
|
+
}
|
|
27
|
+
this.finalizeSessionTabTeardown();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (typeof this.teardownSessionTabRender === 'function') {
|
|
31
|
+
this.teardownSessionTabRender();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
if (typeof this.scheduleSessionTabDeferredTeardown === 'function') {
|
|
35
|
+
this.scheduleSessionTabDeferredTeardown(teardown);
|
|
36
|
+
} else if (typeof this.scheduleAfterFrame === 'function') {
|
|
37
|
+
this.scheduleAfterFrame(teardown);
|
|
38
|
+
} else {
|
|
39
|
+
teardown();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (nextTab === 'sessions' && !this.sessionsLoadedOnce) {
|
|
44
|
+
this.loadSessions();
|
|
45
|
+
}
|
|
46
|
+
if (nextTab === 'sessions') {
|
|
47
|
+
this.prepareSessionTabRender();
|
|
48
|
+
}
|
|
49
|
+
const shouldLoadTrashListOnSettingsEnter = nextTab === 'settings'
|
|
50
|
+
&& this.settingsTab === 'trash'
|
|
51
|
+
&& typeof this.loadSessionTrash === 'function';
|
|
52
|
+
if (shouldLoadTrashListOnSettingsEnter) {
|
|
53
|
+
this.loadSessionTrash({
|
|
54
|
+
forceRefresh: !!this.sessionTrashLoadedOnce
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const shouldPrimeTrashCountOnSettingsEnter = nextTab === 'settings'
|
|
58
|
+
&& this.settingsTab !== 'trash'
|
|
59
|
+
&& typeof this.loadSessionTrashCount === 'function';
|
|
60
|
+
if (shouldPrimeTrashCountOnSettingsEnter) {
|
|
61
|
+
this.sessionTrashLoadedOnce = false;
|
|
62
|
+
this.loadSessionTrashCount({ silent: true });
|
|
63
|
+
}
|
|
64
|
+
const shouldLoadSkillsMarketOnEnter = nextTab === 'market'
|
|
65
|
+
&& previousTab !== 'market'
|
|
66
|
+
&& typeof this.loadSkillsMarketOverview === 'function';
|
|
67
|
+
if (shouldLoadSkillsMarketOnEnter) {
|
|
68
|
+
let marketOverviewLoad = null;
|
|
69
|
+
try {
|
|
70
|
+
marketOverviewLoad = this.loadSkillsMarketOverview({ silent: true });
|
|
71
|
+
} catch (_) {
|
|
72
|
+
marketOverviewLoad = null;
|
|
73
|
+
}
|
|
74
|
+
void Promise.resolve(marketOverviewLoad).catch(() => {});
|
|
75
|
+
}
|
|
76
|
+
if (nextTab === 'config' && this.configMode === 'claude') {
|
|
77
|
+
const expectedTab = nextTab;
|
|
78
|
+
const expectedConfigMode = this.configMode;
|
|
79
|
+
const refresh = () => {
|
|
80
|
+
if (this.mainTab !== expectedTab || this.configMode !== expectedConfigMode) return;
|
|
81
|
+
this.refreshClaudeModelContext();
|
|
82
|
+
};
|
|
83
|
+
if (typeof this.scheduleAfterFrame === 'function') {
|
|
84
|
+
this.scheduleAfterFrame(refresh);
|
|
85
|
+
} else {
|
|
86
|
+
refresh();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function loadSessions(api) {
|
|
92
|
+
if (this.sessionsLoading) return;
|
|
93
|
+
this.sessionsLoading = true;
|
|
94
|
+
this.activeSessionDetailError = '';
|
|
95
|
+
let loadSucceeded = false;
|
|
96
|
+
const params = buildSessionListParams({
|
|
97
|
+
source: this.sessionFilterSource,
|
|
98
|
+
pathFilter: this.sessionPathFilter,
|
|
99
|
+
query: this.sessionQuery,
|
|
100
|
+
roleFilter: this.sessionRoleFilter,
|
|
101
|
+
timeRangePreset: this.sessionTimePreset
|
|
102
|
+
});
|
|
103
|
+
try {
|
|
104
|
+
const res = await api('list-sessions', params);
|
|
105
|
+
if (res.error) {
|
|
106
|
+
this.showMessage(res.error, 'error');
|
|
107
|
+
this.sessionsList = [];
|
|
108
|
+
this.activeSession = null;
|
|
109
|
+
this.activeSessionMessages = [];
|
|
110
|
+
this.resetSessionDetailPagination();
|
|
111
|
+
this.resetSessionPreviewMessageRender();
|
|
112
|
+
this.activeSessionDetailClipped = false;
|
|
113
|
+
this.cancelSessionTimelineSync();
|
|
114
|
+
this.sessionTimelineActiveKey = '';
|
|
115
|
+
clearSessionTimelineRefs(this);
|
|
116
|
+
} else {
|
|
117
|
+
loadSucceeded = true;
|
|
118
|
+
this.sessionsList = Array.isArray(res.sessions) ? res.sessions : [];
|
|
119
|
+
this.syncSessionPathOptionsForSource(
|
|
120
|
+
this.sessionFilterSource,
|
|
121
|
+
this.extractPathOptionsFromSessions(this.sessionsList),
|
|
122
|
+
true
|
|
123
|
+
);
|
|
124
|
+
if (this.sessionsList.length === 0) {
|
|
125
|
+
this.activeSession = null;
|
|
126
|
+
this.activeSessionMessages = [];
|
|
127
|
+
this.resetSessionDetailPagination();
|
|
128
|
+
this.resetSessionPreviewMessageRender();
|
|
129
|
+
this.activeSessionDetailClipped = false;
|
|
130
|
+
this.cancelSessionTimelineSync();
|
|
131
|
+
this.sessionTimelineActiveKey = '';
|
|
132
|
+
clearSessionTimelineRefs(this);
|
|
133
|
+
} else {
|
|
134
|
+
const oldKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
135
|
+
const matched = this.sessionsList.find(item => this.getSessionExportKey(item) === oldKey);
|
|
136
|
+
this.activeSession = matched || this.sessionsList[0];
|
|
137
|
+
this.activeSessionMessages = [];
|
|
138
|
+
this.resetSessionDetailPagination();
|
|
139
|
+
this.resetSessionPreviewMessageRender();
|
|
140
|
+
this.activeSessionDetailError = '';
|
|
141
|
+
this.activeSessionDetailClipped = false;
|
|
142
|
+
this.cancelSessionTimelineSync();
|
|
143
|
+
this.sessionTimelineActiveKey = '';
|
|
144
|
+
clearSessionTimelineRefs(this);
|
|
145
|
+
await this.loadActiveSessionDetail();
|
|
146
|
+
}
|
|
147
|
+
void this.loadSessionPathOptions({ source: this.sessionFilterSource });
|
|
148
|
+
}
|
|
149
|
+
} catch (e) {
|
|
150
|
+
this.sessionsList = [];
|
|
151
|
+
this.activeSession = null;
|
|
152
|
+
this.activeSessionMessages = [];
|
|
153
|
+
this.resetSessionDetailPagination();
|
|
154
|
+
this.resetSessionPreviewMessageRender();
|
|
155
|
+
this.activeSessionDetailClipped = false;
|
|
156
|
+
this.cancelSessionTimelineSync();
|
|
157
|
+
this.sessionTimelineActiveKey = '';
|
|
158
|
+
clearSessionTimelineRefs(this);
|
|
159
|
+
this.showMessage('加载会话失败', 'error');
|
|
160
|
+
} finally {
|
|
161
|
+
this.sessionsLoading = false;
|
|
162
|
+
if (loadSucceeded) {
|
|
163
|
+
this.sessionsLoadedOnce = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function loadActiveSessionDetail(api, options = {}) {
|
|
169
|
+
if (!this.activeSession) {
|
|
170
|
+
this.activeSessionMessages = [];
|
|
171
|
+
this.resetSessionDetailPagination();
|
|
172
|
+
this.resetSessionPreviewMessageRender();
|
|
173
|
+
this.activeSessionDetailError = '';
|
|
174
|
+
this.activeSessionDetailClipped = false;
|
|
175
|
+
this.cancelSessionTimelineSync();
|
|
176
|
+
this.sessionTimelineActiveKey = '';
|
|
177
|
+
clearSessionTimelineRefs(this);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const currentActiveSession = this.activeSession;
|
|
182
|
+
const requestSeq = ++this.sessionDetailRequestSeq;
|
|
183
|
+
this.sessionDetailLoading = true;
|
|
184
|
+
this.activeSessionDetailError = '';
|
|
185
|
+
const fallbackLimit = Number.isFinite(this.sessionDetailInitialMessageLimit)
|
|
186
|
+
? Math.max(1, Math.floor(this.sessionDetailInitialMessageLimit))
|
|
187
|
+
: 80;
|
|
188
|
+
const rawLimit = Number(this.sessionDetailMessageLimit);
|
|
189
|
+
const messageLimit = Number.isFinite(rawLimit)
|
|
190
|
+
? Math.max(1, Math.floor(rawLimit))
|
|
191
|
+
: fallbackLimit;
|
|
192
|
+
try {
|
|
193
|
+
const res = await api('session-detail', {
|
|
194
|
+
source: this.activeSession.source,
|
|
195
|
+
sessionId: this.activeSession.sessionId,
|
|
196
|
+
filePath: this.activeSession.filePath,
|
|
197
|
+
messageLimit
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (requestSeq !== this.sessionDetailRequestSeq) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (!this.activeSession || this.activeSession !== currentActiveSession) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (res.error) {
|
|
208
|
+
this.activeSessionMessages = [];
|
|
209
|
+
this.resetSessionPreviewMessageRender();
|
|
210
|
+
this.activeSessionDetailClipped = false;
|
|
211
|
+
this.activeSessionDetailError = res.error;
|
|
212
|
+
this.cancelSessionTimelineSync();
|
|
213
|
+
this.sessionTimelineActiveKey = '';
|
|
214
|
+
clearSessionTimelineRefs(this);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const rawMessages = Array.isArray(res.messages) ? res.messages : [];
|
|
219
|
+
const normalizedMessages = rawMessages.map((message) => Object.freeze(this.normalizeSessionMessage(message)));
|
|
220
|
+
this.activeSessionMessages = Object.freeze(normalizedMessages);
|
|
221
|
+
if (typeof this.invalidateSessionTimelineMeasurementCache === 'function') {
|
|
222
|
+
this.invalidateSessionTimelineMeasurementCache(true);
|
|
223
|
+
}
|
|
224
|
+
this.activeSessionDetailClipped = !!res.clipped;
|
|
225
|
+
const responseLimitRaw = Number(res.messageLimit);
|
|
226
|
+
this.sessionDetailMessageLimit = Number.isFinite(responseLimitRaw)
|
|
227
|
+
? Math.max(1, Math.floor(responseLimitRaw))
|
|
228
|
+
: messageLimit;
|
|
229
|
+
if (res.sourceLabel) {
|
|
230
|
+
this.activeSession.sourceLabel = res.sourceLabel;
|
|
231
|
+
}
|
|
232
|
+
if (res.sessionId) {
|
|
233
|
+
this.activeSession.sessionId = res.sessionId;
|
|
234
|
+
if (!this.activeSession.title) {
|
|
235
|
+
this.activeSession.title = res.sessionId;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (res.filePath) {
|
|
239
|
+
this.activeSession.filePath = res.filePath;
|
|
240
|
+
}
|
|
241
|
+
if (res.updatedAt) {
|
|
242
|
+
this.activeSession.updatedAt = res.updatedAt;
|
|
243
|
+
}
|
|
244
|
+
if (res.cwd) {
|
|
245
|
+
this.activeSession.cwd = res.cwd;
|
|
246
|
+
}
|
|
247
|
+
if (Number.isFinite(res.totalMessages)) {
|
|
248
|
+
this.syncActiveSessionMessageCount(res.totalMessages);
|
|
249
|
+
}
|
|
250
|
+
if (this.mainTab === 'sessions' && this.sessionPreviewRenderEnabled) {
|
|
251
|
+
const preserveVisibleCount = !!options.preserveVisibleCount;
|
|
252
|
+
const pendingVisibleRaw = Number(this.sessionPreviewPendingVisibleCount);
|
|
253
|
+
const pendingVisible = Number.isFinite(pendingVisibleRaw)
|
|
254
|
+
? Math.max(0, Math.floor(pendingVisibleRaw))
|
|
255
|
+
: 0;
|
|
256
|
+
if (preserveVisibleCount && pendingVisible > 0) {
|
|
257
|
+
this.sessionPreviewVisibleCount = Math.min(pendingVisible, this.activeSessionMessages.length);
|
|
258
|
+
} else {
|
|
259
|
+
this.primeSessionPreviewMessageRender();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
this.sessionPreviewPendingVisibleCount = 0;
|
|
263
|
+
this.$nextTick(() => {
|
|
264
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
this.updateSessionTimelineOffset();
|
|
268
|
+
if (this.sessionTimelineEnabled) {
|
|
269
|
+
this.scheduleSessionTimelineSync();
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
} catch (e) {
|
|
273
|
+
if (requestSeq !== this.sessionDetailRequestSeq) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (!this.activeSession || this.activeSession !== currentActiveSession) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
this.activeSessionMessages = [];
|
|
280
|
+
this.sessionPreviewPendingVisibleCount = 0;
|
|
281
|
+
this.resetSessionPreviewMessageRender();
|
|
282
|
+
this.activeSessionDetailClipped = false;
|
|
283
|
+
this.activeSessionDetailError = '加载会话内容失败: ' + e.message;
|
|
284
|
+
this.cancelSessionTimelineSync();
|
|
285
|
+
this.sessionTimelineActiveKey = '';
|
|
286
|
+
clearSessionTimelineRefs(this);
|
|
287
|
+
} finally {
|
|
288
|
+
if (requestSeq === this.sessionDetailRequestSeq) {
|
|
289
|
+
this.sessionDetailLoading = false;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export async function loadMoreSessionMessages(stepSize) {
|
|
295
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const total = Array.isArray(this.activeSessionMessages)
|
|
299
|
+
? this.activeSessionMessages.length
|
|
300
|
+
: 0;
|
|
301
|
+
if (total <= 0) {
|
|
302
|
+
this.sessionPreviewVisibleCount = 0;
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const step = Number.isFinite(stepSize)
|
|
306
|
+
? Math.max(1, Math.floor(stepSize))
|
|
307
|
+
: (Number.isFinite(this.sessionPreviewLoadStep)
|
|
308
|
+
? Math.max(1, Math.floor(this.sessionPreviewLoadStep))
|
|
309
|
+
: 40);
|
|
310
|
+
const current = Number.isFinite(this.sessionPreviewVisibleCount)
|
|
311
|
+
? Math.max(0, Math.floor(this.sessionPreviewVisibleCount))
|
|
312
|
+
: 0;
|
|
313
|
+
const targetVisible = current + step;
|
|
314
|
+
if (targetVisible <= total) {
|
|
315
|
+
this.sessionPreviewVisibleCount = Math.min(total, targetVisible);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
this.sessionPreviewVisibleCount = total;
|
|
320
|
+
if (this.sessionDetailLoading) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const totalKnownRaw = Number(this.activeSession && this.activeSession.messageCount);
|
|
325
|
+
const totalKnown = Number.isFinite(totalKnownRaw)
|
|
326
|
+
? Math.max(0, Math.floor(totalKnownRaw))
|
|
327
|
+
: 0;
|
|
328
|
+
const hasMoreOnDisk = this.activeSessionDetailClipped || (totalKnown > total);
|
|
329
|
+
if (!hasMoreOnDisk) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const currentLimitRaw = Number(this.sessionDetailMessageLimit);
|
|
334
|
+
const currentLimit = Number.isFinite(currentLimitRaw)
|
|
335
|
+
? Math.max(1, Math.floor(currentLimitRaw))
|
|
336
|
+
: Math.max(1, total);
|
|
337
|
+
const fetchStep = Number.isFinite(this.sessionDetailFetchStep)
|
|
338
|
+
? Math.max(1, Math.floor(this.sessionDetailFetchStep))
|
|
339
|
+
: 80;
|
|
340
|
+
const limitCapRaw = Number(this.sessionDetailMessageLimitCap);
|
|
341
|
+
const limitCap = Number.isFinite(limitCapRaw)
|
|
342
|
+
? Math.max(1, Math.floor(limitCapRaw))
|
|
343
|
+
: 1000;
|
|
344
|
+
|
|
345
|
+
let nextLimit = Math.max(currentLimit + fetchStep, targetVisible);
|
|
346
|
+
if (totalKnown > 0) {
|
|
347
|
+
nextLimit = Math.min(nextLimit, totalKnown);
|
|
348
|
+
}
|
|
349
|
+
nextLimit = Math.min(nextLimit, limitCap);
|
|
350
|
+
if (nextLimit <= currentLimit) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
this.sessionPreviewPendingVisibleCount = targetVisible;
|
|
355
|
+
this.sessionDetailMessageLimit = nextLimit;
|
|
356
|
+
this.sessionPreviewLoadingMore = true;
|
|
357
|
+
try {
|
|
358
|
+
await this.loadActiveSessionDetail({ preserveVisibleCount: true });
|
|
359
|
+
} finally {
|
|
360
|
+
this.sessionPreviewLoadingMore = false;
|
|
361
|
+
}
|
|
362
|
+
}
|