dsh-cothread-mcp 0.1.3 → 0.1.5
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 +7 -0
- package/package.json +1 -1
- package/src/automation.js +70 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.5
|
|
4
|
+
- Fix the automation session not appearing under the selected workspace. The session was created with the workspace's directory as its working directory, but a session only joins a workspace when the host is told the workspace itself, so opening the session showed it outside the workspace that was picked. The session is now created against the workspace, which makes the host attach it to that workspace's session list, and the automation task binds to the session the host actually created.
|
|
5
|
+
|
|
6
|
+
## 0.1.4
|
|
7
|
+
- Fix the automation task update failing with `cannot get property "sessions" without inject`. The session-naming helper read the host's session registry through the context's property access, which Cordis rejects unless the plugin declares the service as an injected dependency; the error escaped the task assembly and left the settings saved but the automation task unchanged. The service is now read the same lenient way as every other host service the plugin uses, so a missing registry only means the session stays unnamed.
|
|
8
|
+
|
|
3
9
|
## 0.1.3
|
|
4
10
|
- Remove the custom environment: only 正式环境 and 本地环境 remain. The environment picker in the settings page and the one in the sidebar's account menu no longer offer a custom option, and the custom service-address input is gone. A configuration saved with the old custom environment is normalized to 正式环境 instead of failing to load, so the plugin keeps working after the update. The authorization flow itself is unchanged.
|
|
5
11
|
- Match the sidebar entry to the native DSH account row: the account label keeps the native 14px weight, the environment name is 12px, and the row's inline padding is 8px on both sides, so the CoThread row, the MiniMax usage row and the native account row line up. The signed-in menu now offers 「自动化设置」 with a gear glyph instead of 「共序自动化」, and the sidebar panel entry uses the native workspace-tree glyph so its stroke weight and padding match the other panel rows.
|
|
@@ -30,6 +36,7 @@
|
|
|
30
36
|
- A project that has been saved once is locked: its project and workspace can no longer be changed, only its actions can still be adjusted, and switching project means deleting the row first.
|
|
31
37
|
- Deleting a project now inspects the automation task and session first and asks for a second confirmation that spells out the task title, task id and session id that will be ended and archived; only after confirming does the task end, the session get archived and the row disappear.
|
|
32
38
|
- 「打开自动化会话」 is now a single icon button next to the row, alongside the per-row save button.
|
|
39
|
+
|
|
33
40
|
## 0.1.1
|
|
34
41
|
|
|
35
42
|
- Widen `engines.dsh` to `>=0.2.1-rc.2 <0.3.0-0 || >=0.2.2-0 <0.3.0-0` so the declared host range admits the DSH 0.2.2 pre-release line this plugin is verified on. The previous single-clause range excluded 0.2.2 pre-releases even though the peer ranges already accepted them.
|
package/package.json
CHANGED
package/src/automation.js
CHANGED
|
@@ -115,6 +115,7 @@ export async function readMapping(ctx) {
|
|
|
115
115
|
title: typeof value.title === 'string' ? value.title : '',
|
|
116
116
|
cwd: typeof value.cwd === 'string' ? value.cwd : '',
|
|
117
117
|
seconds: Number(value.seconds) || 0,
|
|
118
|
+
...(typeof value.workspaceId === 'string' && value.workspaceId ? { workspaceId: value.workspaceId } : {}),
|
|
118
119
|
...(typeof value.sessionId === 'string' && value.sessionId ? { sessionId: value.sessionId } : {}),
|
|
119
120
|
...(typeof value.sessionName === 'string' && value.sessionName ? { sessionName: value.sessionName } : {}),
|
|
120
121
|
}
|
|
@@ -174,12 +175,25 @@ function liveSessionOf(task) {
|
|
|
174
175
|
return task.target.sessionId || ''
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* 记住的会话还能不能接着用。
|
|
180
|
+
*
|
|
181
|
+
* 会话已归档就不能复用。会话不在它该在的工作区里也不能:宿主在 session.create 里看到
|
|
182
|
+
* workspaceId 时,只复用工作区已经记着的会话,不在其中的会被另建一个——那样记住的还是
|
|
183
|
+
* 旧 id,映射与界面上挂的就对不上了。这种情况直接不复用,让宿主另建一个并挂进工作区。
|
|
184
|
+
*/
|
|
178
185
|
function reusableSession(saved, registry) {
|
|
179
186
|
const sessionId = saved && typeof saved.sessionId === 'string' ? saved.sessionId : ''
|
|
180
187
|
if (!sessionId) return ''
|
|
181
188
|
const archived = registry && Array.isArray(registry.archivedSessionIds) ? registry.archivedSessionIds : []
|
|
182
|
-
|
|
189
|
+
if (archived.includes(sessionId)) return ''
|
|
190
|
+
const workspaceId = saved && typeof saved.workspaceId === 'string' ? saved.workspaceId : ''
|
|
191
|
+
if (workspaceId && registry && typeof registry.get === 'function') {
|
|
192
|
+
const workspace = registry.get(workspaceId)
|
|
193
|
+
const member = workspace && Array.isArray(workspace.sessionIds) ? workspace.sessionIds : null
|
|
194
|
+
if (member && !member.includes(sessionId)) return ''
|
|
195
|
+
}
|
|
196
|
+
return sessionId
|
|
183
197
|
}
|
|
184
198
|
|
|
185
199
|
/** 把任务接回指定的会话;接不回就保持原样。 */
|
|
@@ -199,15 +213,17 @@ async function rebindTask(schedule, task, sessionId) {
|
|
|
199
213
|
* 不会因为第一次投递才生成会话而多出一个空会话。
|
|
200
214
|
*/
|
|
201
215
|
async function createTask(ctx, schedule, options) {
|
|
202
|
-
const { title, prompt, seconds, cwd, sessionId } = options || {}
|
|
216
|
+
const { title, prompt, seconds, cwd, sessionId, workspaceId } = options || {}
|
|
203
217
|
const timing = { kind: 'every', every_seconds: seconds }
|
|
204
218
|
const wanted = sessionId || `session-${randomUUID()}`
|
|
205
219
|
// 宿主要求「绑定某个会话」时那个会话已经存在,所以先把会话建出来,再让任务绑上去。
|
|
206
|
-
const made = await ensureSession(ctx, wanted, cwd, title)
|
|
220
|
+
const made = await ensureSession(ctx, wanted, cwd, title, workspaceId)
|
|
207
221
|
if (made.ok) {
|
|
222
|
+
// 宿主可能另建了一个会话,任务要绑的是它真正建出来的那个。
|
|
223
|
+
const bound = made.sessionId || wanted
|
|
208
224
|
try {
|
|
209
|
-
const task = await schedule.create({ title, prompt, timing, target: { kind: 'session', sessionId:
|
|
210
|
-
return { task, sessionId:
|
|
225
|
+
const task = await schedule.create({ title, prompt, timing, target: { kind: 'session', sessionId: bound } })
|
|
226
|
+
return { task, sessionId: bound, sessionName: nameSession(ctx, bound, title), sessionReady: true }
|
|
211
227
|
} catch {
|
|
212
228
|
// 绑定这个会话不成功时,退回由宿主预留一个新的会话。
|
|
213
229
|
}
|
|
@@ -222,28 +238,60 @@ async function createTask(ctx, schedule, options) {
|
|
|
222
238
|
* 任务用「新建会话并复用」时,宿主只是先预留一个会话 id,第一次投递才真正建出来;
|
|
223
239
|
* 这里提前把它建出来,保存后就能直接打开会话,任务也立刻绑在这个会话上。
|
|
224
240
|
*/
|
|
225
|
-
async function ensureSession(ctx, sessionId, cwd, title) {
|
|
241
|
+
async function ensureSession(ctx, sessionId, cwd, title, workspaceId = '') {
|
|
226
242
|
const controller = serviceOf(ctx, 'sessionController')
|
|
227
243
|
if (!controller || typeof controller.create !== 'function') return { ok: false, sessionId, reason: '当前 DSH 不支持直接创建会话' }
|
|
228
244
|
if (!sessionId) return { ok: false, sessionId: '', reason: '没有会话身份' }
|
|
229
245
|
const registry = serviceOf(ctx, 'workspaceRegistry')
|
|
230
246
|
const archived = registry && Array.isArray(registry.archivedSessionIds) ? registry.archivedSessionIds : []
|
|
231
247
|
if (archived.includes(sessionId)) return { ok: false, sessionId, reason: '会话已归档' }
|
|
248
|
+
let createdId = sessionId
|
|
232
249
|
try {
|
|
233
|
-
|
|
250
|
+
// 宿主的 session.create 里 workspaceId 与 cwd 互斥:只给 cwd 时,会话只是「拥有」这个
|
|
251
|
+
// 目录,并不会被加进工作区的会话列表,界面上打开会话就看不到它挂在选中的工作区下。
|
|
252
|
+
// 给了 workspaceId,宿主会用工作区的路径作 cwd,并把会话正式挂进该工作区。
|
|
253
|
+
const created = await controller.create(workspaceId ? { sessionId, workspaceId } : { sessionId, cwd })
|
|
254
|
+
// 宿主可能复用或另建一个会话,任务要绑的是它真正建出来的那个。
|
|
255
|
+
if (created && typeof created.sessionId === 'string' && created.sessionId) createdId = created.sessionId
|
|
234
256
|
} catch (error) {
|
|
235
257
|
const message = error && error.message ? error.message : '创建会话失败'
|
|
236
258
|
// 会话已经存在时不算失败,接着往下走命名。
|
|
237
259
|
if (!/exist|already/i.test(message)) return { ok: false, sessionId, reason: message }
|
|
238
260
|
}
|
|
239
|
-
|
|
240
|
-
|
|
261
|
+
// 会话早于本次改动建成、还没挂进工作区时,宿主不会替它补挂,这里补上。
|
|
262
|
+
await attachToWorkspace(ctx, workspaceId, createdId)
|
|
263
|
+
nameSession(ctx, createdId, title)
|
|
264
|
+
return { ok: true, sessionId: createdId }
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* 把会话挂进它该在的工作区。
|
|
269
|
+
*
|
|
270
|
+
* 宿主在 session.create 里带上 workspaceId 时会自己挂载;会话是先前留下的、已经存在,
|
|
271
|
+
* 宿主就不会补这一步,而工作区的会话列表是按挂载记录的,没有它会话就只是「属于」那个目录,
|
|
272
|
+
* 界面上打开会话看不到它挂在选中的工作区下。这里显式挂一次,幂等。
|
|
273
|
+
*/
|
|
274
|
+
async function attachToWorkspace(ctx, workspaceId, sessionId) {
|
|
275
|
+
if (!workspaceId || !sessionId) return false
|
|
276
|
+
const registry = serviceOf(ctx, 'workspaceRegistry')
|
|
277
|
+
if (!registry || typeof registry.get !== 'function') return false
|
|
278
|
+
const workspace = registry.get(workspaceId)
|
|
279
|
+
if (!workspace || typeof workspace.attachSession !== 'function') return false
|
|
280
|
+
try {
|
|
281
|
+
await workspace.attachSession(sessionId)
|
|
282
|
+
return true
|
|
283
|
+
} catch {
|
|
284
|
+
return false
|
|
285
|
+
}
|
|
241
286
|
}
|
|
242
287
|
|
|
243
288
|
/** 给自动化会话起个项目名,界面上就能看到它叫什么。 */
|
|
244
|
-
function nameSession(ctx, sessionId, title) {
|
|
289
|
+
export function nameSession(ctx, sessionId, title) {
|
|
245
290
|
if (!title) return ''
|
|
246
|
-
|
|
291
|
+
// 用 ctx.get 取,不用 ctx.sessions:Cordis 的属性访问会检查本插件 fiber 的 inject,
|
|
292
|
+
// 没声明 inject 就会抛 'cannot get property "sessions" without inject',
|
|
293
|
+
// 把整个自动化任务的更新一起带崩。ctx.get 是宽松的,取不到就当没有。
|
|
294
|
+
const sessions = serviceOf(ctx, 'sessions')
|
|
247
295
|
const titles = serviceOf(ctx, 'sessionTitle')
|
|
248
296
|
if (!sessions || typeof sessions.get !== 'function') return ''
|
|
249
297
|
const session = sessions.get(sessionId)
|
|
@@ -336,7 +384,7 @@ export async function syncAutomations(ctx, options) {
|
|
|
336
384
|
if (await deleteTask(schedule, extra.id)) { deleted++; deletedIds.add(extra.id) }
|
|
337
385
|
}
|
|
338
386
|
if (!task) {
|
|
339
|
-
const made = await createTask(ctx, schedule, { title, prompt, seconds, cwd, sessionId: reusableSession(mapping[key], registry) })
|
|
387
|
+
const made = await createTask(ctx, schedule, { title, prompt, seconds, cwd, workspaceId: row.workspaceId, sessionId: reusableSession(mapping[key], registry) })
|
|
340
388
|
task = made.task
|
|
341
389
|
created++
|
|
342
390
|
current = seconds
|
|
@@ -365,10 +413,12 @@ export async function syncAutomations(ctx, options) {
|
|
|
365
413
|
// 会话当场建出来:重启后不用等第一次巡检就能打开。
|
|
366
414
|
let sessionName = ''
|
|
367
415
|
if (sessionId) {
|
|
368
|
-
await ensureSession(ctx, sessionId, cwd, title)
|
|
416
|
+
const made = await ensureSession(ctx, sessionId, cwd, title, row.workspaceId)
|
|
417
|
+
// 宿主可能另建了会话,后面的映射要记真正在用的那个。
|
|
418
|
+
if (made.sessionId) sessionId = made.sessionId
|
|
369
419
|
sessionName = nameSession(ctx, sessionId, title)
|
|
370
420
|
}
|
|
371
|
-
next[key] = { id: task.id, title, cwd, seconds: current, ...(sessionId ? { sessionId } : {}), ...(sessionName ? { sessionName } : {}) }
|
|
421
|
+
next[key] = { id: task.id, title, cwd, seconds: current, ...(row.workspaceId ? { workspaceId: row.workspaceId } : {}), ...(sessionId ? { sessionId } : {}), ...(sessionName ? { sessionName } : {}) }
|
|
372
422
|
tasks.push({
|
|
373
423
|
key,
|
|
374
424
|
id: task.id,
|
|
@@ -473,7 +523,7 @@ export async function saveAutomation(ctx, options) {
|
|
|
473
523
|
let created = 0, updated = 0
|
|
474
524
|
let createdSession = null
|
|
475
525
|
if (!task) {
|
|
476
|
-
const made = await createTask(ctx, schedule, { title, prompt, seconds, cwd, sessionId: reusableSession(mapping[key], registry) })
|
|
526
|
+
const made = await createTask(ctx, schedule, { title, prompt, seconds, cwd, workspaceId: row.workspaceId, sessionId: reusableSession(mapping[key], registry) })
|
|
477
527
|
task = made.task
|
|
478
528
|
createdSession = made
|
|
479
529
|
created++
|
|
@@ -501,8 +551,10 @@ export async function saveAutomation(ctx, options) {
|
|
|
501
551
|
sessionReady = createdSession.sessionReady
|
|
502
552
|
sessionName = createdSession.sessionName
|
|
503
553
|
} else if (sessionId) {
|
|
504
|
-
const made = await ensureSession(ctx, sessionId, cwd, title)
|
|
554
|
+
const made = await ensureSession(ctx, sessionId, cwd, title, row.workspaceId)
|
|
505
555
|
sessionReady = made.ok
|
|
556
|
+
// 宿主可能另建了会话(原来的不在工作区里,不能复用),后面都要用真正建出来的那个。
|
|
557
|
+
if (made.sessionId) sessionId = made.sessionId
|
|
506
558
|
sessionName = nameSession(ctx, sessionId, title)
|
|
507
559
|
}
|
|
508
560
|
const next = {}
|
|
@@ -511,7 +563,7 @@ export async function saveAutomation(ctx, options) {
|
|
|
511
563
|
if (deletedIds.has(saved.id)) continue
|
|
512
564
|
next[entryKey] = saved
|
|
513
565
|
}
|
|
514
|
-
next[key] = { id: task.id, title, cwd, seconds, ...(sessionId ? { sessionId } : {}), ...(sessionName ? { sessionName } : {}) }
|
|
566
|
+
next[key] = { id: task.id, title, cwd, seconds, ...(row.workspaceId ? { workspaceId: row.workspaceId } : {}), ...(sessionId ? { sessionId } : {}), ...(sessionName ? { sessionName } : {}) }
|
|
515
567
|
await writeMapping(ctx, next)
|
|
516
568
|
return {
|
|
517
569
|
ok: true,
|