调整提示词顺序:USER.md 移至 AGENT.md 之后、记忆/工作空间之前

This commit is contained in:
thzxx
2026-06-05 10:10:17 +08:00
parent 9a101b8a44
commit 361e58b8d1
+29 -29
View File
@@ -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
// 实时注入当前日期(来自系统时钟,非模型知识库)