dsh-cothread-mcp 0.1.7 → 0.1.8
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/CHANGELOG.md +2 -0
- package/package.json +1 -1
- package/src/automation.js +59 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.8
|
|
4
|
+
- Clean up the duplicate sessions an earlier version left behind. Saving an automation row now archives the same-named sessions it does not use and detaches them from the workspace, so the workspace list shows only the session the task is actually bound to. The cleanup collects the sessions before acting, because detaching one changes the very list it walks.
|
|
3
5
|
## 0.1.7
|
|
4
6
|
- Fix the automation task creating a new session on every save, which left a pile of sessions in the workspace and moved the conversation away from the one that had the actual content. The host only reuses a session that has not run a turn yet, so an automation session that had already run was replaced by a fresh one each time. The session is now reused as long as it exists, and the task is bound to the same-named session that already has turns, so the conversation stays where it was.
|
|
5
7
|
## 0.1.6
|
package/package.json
CHANGED
package/src/automation.js
CHANGED
|
@@ -361,6 +361,61 @@ async function sessionExists(ctx, sessionId) {
|
|
|
361
361
|
return false
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* 清理这个项目留下的重复会话。
|
|
366
|
+
*
|
|
367
|
+
* 早期版本每保存一次就新建一个会话,工作区里会攒下一堆同名会话,界面上看着很乱,
|
|
368
|
+
* 真正在用的那一个反而不好找。这里把同名、但不是任务当前绑着的那些归档并移出工作区:
|
|
369
|
+
* 归档后界面默认不显示,移出后工作区的会话列表里也不再占位置。
|
|
370
|
+
*/
|
|
371
|
+
async function cleanDuplicateSessions(ctx, workspaceId, cwd, title, keepId) {
|
|
372
|
+
if (!workspaceId || !cwd || !title) return 0
|
|
373
|
+
const registry = serviceOf(ctx, 'workspaceRegistry')
|
|
374
|
+
if (!registry || typeof registry.get !== 'function') return 0
|
|
375
|
+
const workspace = registry.get(workspaceId)
|
|
376
|
+
if (!workspace) return 0
|
|
377
|
+
const query = serviceOf(ctx, 'sessionQuery')
|
|
378
|
+
const sessions = serviceOf(ctx, 'sessions')
|
|
379
|
+
const archived = Array.isArray(registry.archivedSessionIds) ? registry.archivedSessionIds : []
|
|
380
|
+
// 先把要清的会话找齐,再动手。
|
|
381
|
+
// 边遍历边 detach 会改动工作区那份会话列表,遍历会漏掉元素,清不干净。
|
|
382
|
+
const members = Array.isArray(workspace.sessionIds) ? [...workspace.sessionIds] : []
|
|
383
|
+
const doomed = []
|
|
384
|
+
for (const id of members) {
|
|
385
|
+
if (!id || id === keepId || archived.includes(id)) continue
|
|
386
|
+
const live = sessions && typeof sessions.get === 'function' ? sessions.get(id) : undefined
|
|
387
|
+
let name = ''
|
|
388
|
+
if (live) {
|
|
389
|
+
name = await sessionTitleOf(ctx, live)
|
|
390
|
+
} else if (query && typeof query.observeSession === 'function') {
|
|
391
|
+
try {
|
|
392
|
+
const observation = await query.observeSession(id)
|
|
393
|
+
for (const event of (observation && observation.events) || []) {
|
|
394
|
+
if (event && event.type === 'session/title' && event.title) name = String(event.title)
|
|
395
|
+
}
|
|
396
|
+
} catch {
|
|
397
|
+
// 读不到标题的会话不是这个项目的,不动它。
|
|
398
|
+
continue
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (name !== title) continue
|
|
402
|
+
doomed.push(id)
|
|
403
|
+
}
|
|
404
|
+
let cleaned = 0
|
|
405
|
+
for (const id of doomed) {
|
|
406
|
+
const done = await archiveSession(registry, id)
|
|
407
|
+
if (!done.archived) continue
|
|
408
|
+
if (typeof workspace.detachSession === 'function') {
|
|
409
|
+
try {
|
|
410
|
+
await workspace.detachSession(id)
|
|
411
|
+
} catch {
|
|
412
|
+
// 移不出去就只归档,界面默认也不显示它。
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
cleaned++
|
|
416
|
+
}
|
|
417
|
+
return cleaned
|
|
418
|
+
}
|
|
364
419
|
/**
|
|
365
420
|
* 把会话挂进它该在的工作区。
|
|
366
421
|
*
|
|
@@ -555,6 +610,8 @@ export async function syncAutomations(ctx, options) {
|
|
|
555
610
|
if (made.sessionId) sessionId = made.sessionId
|
|
556
611
|
sessionName = nameSession(ctx, sessionId, title)
|
|
557
612
|
}
|
|
613
|
+
// 清掉这个项目早期版本留下的重复会话,只留任务绑着的那个。
|
|
614
|
+
await cleanDuplicateSessions(ctx, row.workspaceId, cwd, title, sessionId)
|
|
558
615
|
next[key] = { id: task.id, title, cwd, seconds: current, ...(row.workspaceId ? { workspaceId: row.workspaceId } : {}), ...(sessionId ? { sessionId } : {}), ...(sessionName ? { sessionName } : {}) }
|
|
559
616
|
tasks.push({
|
|
560
617
|
key,
|
|
@@ -692,6 +749,8 @@ export async function saveAutomation(ctx, options) {
|
|
|
692
749
|
}
|
|
693
750
|
// 早期版本留下的会话还在「未分组」里,先把它们归位到选中的工作区。
|
|
694
751
|
await adoptOrphanSessions(ctx, row.workspaceId, cwd)
|
|
752
|
+
// 早期版本每保存一次就新建一个会话,这里把多余的同名会话清掉,只留任务绑着的那个。
|
|
753
|
+
await cleanDuplicateSessions(ctx, row.workspaceId, cwd, title, sessionId)
|
|
695
754
|
// 会话当场建出来:保存完就能打开它,任务也已经绑在它上面。
|
|
696
755
|
let sessionReady = false
|
|
697
756
|
let sessionName = ''
|