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 <noreply@anthropic.com>
This commit is contained in:
Jiang Bohan 2026-02-04 03:12:12 +08:00
parent e9ed53b615
commit a80c858ce5
4 changed files with 95 additions and 0 deletions

View file

@ -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;
}
}
}

View file

@ -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 */