mirror of
https://gh-proxy.org/https://github.com/klinsmaya/LobsterAI.git
synced 2026-11-08 01:06:44 +08:00
feat: 为 Agent 身份设定添加默认模板
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
Your name is LobsterAI, a full-scenario personal assistant agent developed by NetEase Youdao. You are available 24/7 and can autonomously handle everyday productivity tasks, including data analysis, PPT creation, video generation, document writing, information search, email workflows, scheduled jobs, and more. You and the user share the same workspace, collaborating to achieve the user's goals.
|
||||
|
||||
# Style
|
||||
- Keep your response language consistent with the user's input language. Only switch languages when the user explicitly requests a different language.
|
||||
- Be concise and direct. State the solution first, then explain if needed. The complexity of the answer should match the task.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
import crypto from 'crypto';
|
||||
import { app } from 'electron';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
@@ -354,6 +355,18 @@ export function migrateSqliteToMemoryMd(
|
||||
// Bootstrap file management (IDENTITY.md, USER.md, SOUL.md)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const DEFAULT_IDENTITY_ZH = '你的名字是 LobsterAI,一个由网易有道开发的全场景个人助理 Agent。你 7×24 小时在线,能够自主处理日常生产力任务,包括数据分析、PPT 制作、视频生成、文档撰写、信息搜索、邮件工作流、定时任务等。你和用户共享同一个工作空间,协同完成用户的目标。';
|
||||
const DEFAULT_IDENTITY_EN = 'Your name is LobsterAI, a full-scenario personal assistant agent developed by NetEase Youdao. You are available 24/7 and can autonomously handle everyday productivity tasks, including data analysis, PPT creation, video generation, document writing, information search, email workflows, scheduled jobs, and more. You and the user share the same workspace, collaborating to achieve the user\'s goals.';
|
||||
|
||||
function getDefaultIdentity(): string {
|
||||
try {
|
||||
const locale = app.getLocale();
|
||||
return locale.startsWith('zh') ? DEFAULT_IDENTITY_ZH : DEFAULT_IDENTITY_EN;
|
||||
} catch {
|
||||
return DEFAULT_IDENTITY_EN;
|
||||
}
|
||||
}
|
||||
|
||||
const BOOTSTRAP_ALLOWLIST = new Set(['IDENTITY.md', 'USER.md', 'SOUL.md']);
|
||||
|
||||
function validateBootstrapFilename(filename: string): void {
|
||||
@@ -389,6 +402,20 @@ export function writeBootstrapFile(workingDirectory: string | undefined, filenam
|
||||
console.log(`${TAG} writeBootstrapFile: wrote ${filename} (${content.length} chars) to ${filePath}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure IDENTITY.md exists in the workspace with built-in default content.
|
||||
* Only writes if the file doesn't exist or is empty — never overwrites user content.
|
||||
*/
|
||||
export function ensureDefaultIdentity(workingDirectory: string | undefined): void {
|
||||
const filePath = resolveBootstrapFilePath(workingDirectory, 'IDENTITY.md');
|
||||
const existing = readFileOrEmpty(filePath);
|
||||
if (existing.trim()) return; // already has content, don't overwrite
|
||||
const defaultContent = getDefaultIdentity();
|
||||
ensureDir(filePath);
|
||||
fs.writeFileSync(filePath, defaultContent, 'utf8');
|
||||
console.log(`${TAG} ensureDefaultIdentity: wrote default IDENTITY.md to ${filePath}`);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Workspace change sync
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
syncMemoryFileOnWorkspaceChange,
|
||||
readBootstrapFile,
|
||||
writeBootstrapFile,
|
||||
ensureDefaultIdentity,
|
||||
} from './libs/openclawMemoryFile';
|
||||
import {
|
||||
OpenClawChannelSessionSync,
|
||||
@@ -637,6 +638,13 @@ const bootstrapOpenClawEngine = async (options: { forceReinstall?: boolean; reas
|
||||
console.log(`[OpenClaw] bootstrap: MCP bridge setup done (${elapsed()}), result=${bridgeResult ? `${bridgeResult.tools.length} tools` : 'null'}`);
|
||||
console.log(`[OpenClaw] bootstrap: mcpBridgeServer=${mcpBridgeServer?.callbackUrl || 'null'}, mcpServerManager.tools=${mcpServerManager?.toolManifest?.length ?? 'null'}, secret=${mcpBridgeSecret ? 'set' : 'null'}`);
|
||||
|
||||
// Ensure IDENTITY.md has default content in the current workspace
|
||||
try {
|
||||
ensureDefaultIdentity(getCoworkStore().getConfig().workingDirectory);
|
||||
} catch (err) {
|
||||
console.warn('[OpenClaw] bootstrap: ensureDefaultIdentity failed (non-fatal):', err);
|
||||
}
|
||||
|
||||
const syncResult = await syncOpenClawConfig({
|
||||
reason: `bootstrap:${reason}`,
|
||||
restartGatewayIfRunning: false,
|
||||
@@ -2376,6 +2384,12 @@ if (!gotTheLock) {
|
||||
if (syncResult.error) {
|
||||
console.warn('[OpenClaw Memory] Workspace sync failed:', syncResult.error);
|
||||
}
|
||||
// Ensure IDENTITY.md has default content in the new workspace
|
||||
try {
|
||||
ensureDefaultIdentity(normalizedConfig.workingDirectory);
|
||||
} catch (err) {
|
||||
console.warn('[OpenClaw] ensureDefaultIdentity failed (non-fatal):', err);
|
||||
}
|
||||
}
|
||||
|
||||
const nextConfig = getCoworkStore().getConfig();
|
||||
|
||||
Reference in New Issue
Block a user