调整提示词顺序:USER.md 移至 AGENT.md 之后、记忆/工作空间之前
This commit is contained in:
@@ -385,6 +385,35 @@ export async function runAgentLoop(
|
|||||||
systemPromptParts.push(`[AGENT.md] ${agentMdContent}`);
|
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) {
|
if (isMemoryEnabled() && userContent) {
|
||||||
const relevantMemories = searchMemories(userContent, 6);
|
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
|
// 组合 system prompt
|
||||||
|
|
||||||
// 实时注入当前日期(来自系统时钟,非模型知识库)
|
// 实时注入当前日期(来自系统时钟,非模型知识库)
|
||||||
|
|||||||
Reference in New Issue
Block a user