From a80c858ce59dd4fdaa216b1d6bd8a022fef3bc25 Mon Sep 17 00:00:00 2001 From: Jiang Bohan Date: Wed, 4 Feb 2026 03:12:12 +0800 Subject: [PATCH] feat(agent): add profile name and user content management Add methods to ProfileManager, Agent, and AsyncAgent for: - Getting/setting agent display name (stored in config.json) - Getting/setting user.md content This enables the desktop app to manage agent settings. Co-Authored-By: Claude Opus 4.5 --- src/agent/async-agent.ts | 28 ++++++++++++++++++++++++++++ src/agent/profile/index.ts | 37 +++++++++++++++++++++++++++++++++++++ src/agent/profile/types.ts | 2 ++ src/agent/runner.ts | 28 ++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) diff --git a/src/agent/async-agent.ts b/src/agent/async-agent.ts index 86ae5d90..cee3b3e8 100644 --- a/src/agent/async-agent.ts +++ b/src/agent/async-agent.ts @@ -148,4 +148,32 @@ export class AsyncAgent { getProfileId(): string | undefined { return this.agent.getProfileId(); } + + /** + * Get agent display name from profile config. + */ + getAgentName(): string | undefined { + return this.agent.getAgentName(); + } + + /** + * Update agent display name in profile config. + */ + setAgentName(name: string): void { + this.agent.setAgentName(name); + } + + /** + * Get user.md content from profile. + */ + getUserContent(): string | undefined { + return this.agent.getUserContent(); + } + + /** + * Update user.md content in profile. + */ + setUserContent(content: string): void { + this.agent.setUserContent(content); + } } diff --git a/src/agent/profile/index.ts b/src/agent/profile/index.ts index bc41e046..556dead3 100644 --- a/src/agent/profile/index.ts +++ b/src/agent/profile/index.ts @@ -13,7 +13,10 @@ import { loadProfile, profileExists, saveProfile, + writeProfileConfig, + writeProfileFile, } from "./storage.js"; +import { PROFILE_FILES } from "./types.js"; export { type AgentProfile, type CreateProfileOptions, type ProfileConfig, type ProfileManagerOptions } from "./types.js"; export { DEFAULT_TEMPLATES } from "./templates.js"; @@ -215,4 +218,38 @@ export class ProfileManager { this.updateToolsConfig(newConfig); return newConfig; } + + /** 获取 Agent 名称 */ + getName(): string | undefined { + const profile = this.getProfile(); + return profile?.config?.name; + } + + /** 更新 Agent 名称 */ + updateName(name: string): void { + const profile = this.getOrCreateProfile(false); + const currentConfig = profile.config ?? {}; + const newConfig: ProfileConfig = { + ...currentConfig, + name, + }; + profile.config = newConfig; + this.profile = profile; + writeProfileConfig(this.profileId, newConfig, { baseDir: this.baseDir }); + } + + /** 获取 user.md 内容 */ + getUserContent(): string | undefined { + const profile = this.getProfile(); + return profile?.user; + } + + /** 更新 user.md 内容 */ + updateUserContent(content: string): void { + writeProfileFile(this.profileId, PROFILE_FILES.user, content, { baseDir: this.baseDir }); + // Update cached profile + if (this.profile) { + this.profile.user = content; + } + } } diff --git a/src/agent/profile/types.ts b/src/agent/profile/types.ts index 4565d7df..db313ceb 100644 --- a/src/agent/profile/types.ts +++ b/src/agent/profile/types.ts @@ -15,6 +15,8 @@ export const PROFILE_FILES = { /** Profile config.json structure */ export interface ProfileConfig { + /** Agent display name */ + name?: string; /** Tools policy configuration */ tools?: ToolsConfig; /** Default LLM provider */ diff --git a/src/agent/runner.ts b/src/agent/runner.ts index bdc9e203..9a013e93 100644 --- a/src/agent/runner.ts +++ b/src/agent/runner.ts @@ -532,4 +532,32 @@ export class Agent { getProfileId(): string | undefined { return this.profile?.getProfile()?.id; } + + /** + * Get agent display name from profile config. + */ + getAgentName(): string | undefined { + return this.profile?.getName(); + } + + /** + * Update agent display name in profile config. + */ + setAgentName(name: string): void { + this.profile?.updateName(name); + } + + /** + * Get user.md content from profile. + */ + getUserContent(): string | undefined { + return this.profile?.getUserContent(); + } + + /** + * Update user.md content in profile. + */ + setUserContent(content: string): void { + this.profile?.updateUserContent(content); + } }