From 361e58b8d14a67687bab3cb8994b9f1b387c1371 Mon Sep 17 00:00:00 2001 From: thzxx Date: Fri, 5 Jun 2026 10:10:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8F=90=E7=A4=BA=E8=AF=8D?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=EF=BC=9AUSER.md=20=E7=A7=BB=E8=87=B3=20AGENT?= =?UTF-8?q?.md=20=E4=B9=8B=E5=90=8E=E3=80=81=E8=AE=B0=E5=BF=86/=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E7=A9=BA=E9=97=B4=E4=B9=8B=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/services/agent-engine.ts | 58 +++++++++++++-------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/renderer/services/agent-engine.ts b/src/renderer/services/agent-engine.ts index 54a4deb..935aac7 100644 --- a/src/renderer/services/agent-engine.ts +++ b/src/renderer/services/agent-engine.ts @@ -385,6 +385,35 @@ export async function runAgentLoop( systemPromptParts.push(`[AGENT.md] ${agentMdContent}`); } + // ── 扫描工作空间 USER.md ── + let userMdContent = ''; + if (workspaceDir) { + try { + const userResult = await window.metonaDesktop?.workspace.readFile( + workspaceDir.replace(/\/+$/, '') + '/USER.md' + ); + if (userResult?.success && userResult.content) { + userMdContent = userResult.content; + logInfo('USER.md 已从工作空间加载', `${userResult.lines || 0} 行`); + } + } catch { /* 工作空间 USER.md 不存在 */ } + } + + // fallback:读取内置 USER.md + if (!userMdContent) { + try { + const resp = await fetch('./USER.md'); + if (resp.ok) { + userMdContent = await resp.text(); + logInfo('USER.md 已从内置加载', `${userMdContent.length} 字符`); + } + } catch { /* 内置 USER.md 也不可用 */ } + } + + if (userMdContent) { + systemPromptParts.push(`[USER.md] ${userMdContent}`); + } + // 注入记忆上下文 if (isMemoryEnabled() && userContent) { const relevantMemories = searchMemories(userContent, 6); @@ -416,35 +445,6 @@ export async function runAgentLoop( } } - // ── 扫描工作空间 USER.md ── - let userMdContent = ''; - if (workspaceDir) { - try { - const userResult = await window.metonaDesktop?.workspace.readFile( - workspaceDir.replace(/\/+$/, '') + '/USER.md' - ); - if (userResult?.success && userResult.content) { - userMdContent = userResult.content; - logInfo('USER.md 已从工作空间加载', `${userResult.lines || 0} 行`); - } - } catch { /* 工作空间 USER.md 不存在 */ } - } - - // fallback:读取内置 USER.md - if (!userMdContent) { - try { - const resp = await fetch('./USER.md'); - if (resp.ok) { - userMdContent = await resp.text(); - logInfo('USER.md 已从内置加载', `${userMdContent.length} 字符`); - } - } catch { /* 内置 USER.md 也不可用 */ } - } - - if (userMdContent) { - systemPromptParts.push(`[USER.md] ${userMdContent}`); - } - // 组合 system prompt // 实时注入当前日期(来自系统时钟,非模型知识库)