diff --git a/app/server/engine.js b/app/server/engine.js index ed957b9..a6a0776 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -1238,11 +1238,10 @@ function createSession(title, preferModelId, assistantType, user, workDir) { if (!modelId) throw Object.assign(new Error('无可用模型:请检查配置并重启服务'), { status_code: 503 }); } const id = genTaskId(); - // 手选目录:直接当作会话工作目录(不建 task-* 子目录);未选 = 老行为,在 workspace_root 下按 id 建档。 + // 手选目录:直接当作会话工作目录(不建 task-* 子目录);未选 = 沿用 workspace_root/<会话id>。 // 选中的目录必须已存在(normalizeWorkDir 已校验),绝不在用户目录里替它 mkdir。 + // 两种情况下目录都由工具执行时懒建(见 tools/executor.js 的 executeTool),纯文本对话不留空目录。 const wd = normalizeWorkDir(workDir); - const dir = wd || path.join(cfg.workspace_root, id); - if (!wd) fs.mkdirSync(dir, { recursive: true }); db.prepare( "INSERT INTO sessions (id, title, status, model_id, model_slot, last_model_id, held_at, assistant_type, user, work_dir, created_at, updated_at) VALUES (?,?,'held',?,?,?,?,?,?,?,?,?)" ).run(id, title || '', modelId, key.id, modelId, now(), assistantType || 'secretary', user || '', wd, now(), now()); diff --git a/app/server/tools/executor.js b/app/server/tools/executor.js index 123da0e..0cff066 100644 --- a/app/server/tools/executor.js +++ b/app/server/tools/executor.js @@ -1798,6 +1798,8 @@ const HANDLERS = { // (见 imageReceipt),image_rel 缺省表示本次不投递像素。 // 内置工具优先;未命中时交给 MCP 注册表(启动时发现的服务工具)。 async function executeTool(baseCtx, name, args) { + // 会话目录懒建:会话创建时不再占坑,第一次真用到工具才建(纯文本对话不留空目录)。 + try { if (baseCtx && baseCtx.taskDir) fs.mkdirSync(baseCtx.taskDir, { recursive: true }); } catch (_) {} const handler = HANDLERS[name]; if (handler) return handler(baseCtx, args || {}); if (mcp.hasTool(name)) return mcp.callTool(name, args || {}, baseCtx); // baseCtx.taskDir → X-Session-Dir 头下发给 MCP 服务