v0.9.0: SOUL.md/AGENT.md/USER.md 化为工作空间文件,去掉代码内硬编码提示词

- 版本号 v1.1.0 → v0.9.0
- AGENT_SYSTEM_PROMPT + TOOL_USAGE_GUIDE 提取为 AGENT.md(工作空间优先,内置 fallback)
- SOUL.md 同级改造(工作空间优先,内置 fallback)
- 删除 inferUserProfile 自动用户画像,改为 USER.md 手动编辑
- 三个 .md 内置版本放在 src/renderer/public/(Vite publicDir 自动复制)
This commit is contained in:
thzxx
2026-06-05 09:35:39 +08:00
parent 968350861d
commit 988efd1733
8 changed files with 194 additions and 127 deletions
+42 -4
View File
@@ -697,6 +697,7 @@ export async function sendMessage(): Promise<void> {
// ── 扫描工作空间 SOUL.md ──
let soulContent = '';
let soulMdContent = '';
const workspaceDir = getWorkspaceDirPath();
if (workspaceDir) {
try {
@@ -704,9 +705,44 @@ export async function sendMessage(): Promise<void> {
workspaceDir.replace(/\/+$/, '') + '/SOUL.md'
);
if (soulResult?.success && soulResult.content) {
soulContent = `[SOUL.md] ${soulResult.content}`;
soulMdContent = soulResult.content;
}
} catch { /* SOUL.md 不存在,静默跳过 */ }
} catch { /* 工作空间 SOUL.md 不存在 */ }
}
// fallback:读取内置 SOUL.md
if (!soulMdContent) {
try {
const resp = await fetch('./SOUL.md');
if (resp.ok) {
soulMdContent = await resp.text();
}
} catch { /* 内置 SOUL.md 也不可用 */ }
}
if (soulMdContent) {
soulContent = `[SOUL.md] ${soulMdContent}`;
}
// ── 扫描工作空间 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;
}
} catch { /* 工作空间 USER.md 不存在 */ }
}
if (!userMdContent) {
try {
const resp = await fetch('./USER.md');
if (resp.ok) {
userMdContent = await resp.text();
}
} catch { /* 内置 USER.md 也不可用 */ }
}
// ── Agent 记忆注入 ──
@@ -716,7 +752,8 @@ export async function sendMessage(): Promise<void> {
const relevantMemories = searchMemories(userMessage, 6);
if (relevantMemories.length > 0) {
const memoryContext = buildMemoryContext(relevantMemories);
chatParams.system = (soulContent ? soulContent + '\n\n' : '') + memoryContext;
const parts = [soulContent, userMdContent ? `[USER.md] ${userMdContent}` : '', memoryContext].filter(Boolean);
chatParams.system = parts.join('\n\n');
for (const m of relevantMemories) {
await markMemoryUsed(m.id);
}
@@ -725,7 +762,8 @@ export async function sendMessage(): Promise<void> {
}
}
if (soulContent && !chatParams.system) {
chatParams.system = soulContent;
const parts = [soulContent, userMdContent ? `[USER.md] ${userMdContent}` : ''].filter(Boolean);
chatParams.system = parts.join('\n\n');
}
// 存入 state 供 chat-area 渲染系统提示词卡片