diff --git a/plugins/dsh-mail-bridge/src/index.ts b/plugins/dsh-mail-bridge/src/index.ts index 13ada26..61a8b97 100644 --- a/plugins/dsh-mail-bridge/src/index.ts +++ b/plugins/dsh-mail-bridge/src/index.ts @@ -624,6 +624,29 @@ export function apply(ctx: any, config: PluginConfig): void { }); } + // 把会话挂进工作区注册表 —— 这是让 DSH GUI 把它从「未分组」挪进对应项目 + // 的唯一路径。不挂的后果:会话永远落在 Ungrouped,人类在侧栏看不到它 + // 与项目的从属关系,也无法用 DSH 的工作区级操作(批量归档、重命名等)。 + // + // 失败不可怕:会话本身已经能用了,只是 GUI 分组不对。最常见失败是 + // 邮件里的 cwd 在 DSH 主机上不存在(跨主机场景),此时 mkdirSync + // 建不出目录,workspaceRegistry.create 也报错。 + if (cwd && handle) { + try { + const wr: any = (ctx as any).get?.('workspaceRegistry'); + if (wr?.create) { + const ws = await wr.create(cwd, cwd.split('/').pop() || cwd); + if (ws?.attachSession) { + await ws.attachSession(attemptSessionId as any); + } + } + } catch (e: any) { + // 工作区注册失败不影响会话功能:只有 GUI 分组会受影响。 + // 日志用 console.error 才进 journalctl(ctx.logger 不进)。 + console.error(`[dsh-mail-bridge] 工作区注册失败(不影响功能): ${e?.message || e}`); + } + } + const watching = awaitFirstTurn(handle.agent); handle.agent.followup(userMessage(promptText)); const outcome = await watching;