From 9467ac9fffc452d1979d8d6b87e9e95dafb47492 Mon Sep 17 00:00:00 2001 From: Jiang Bohan Date: Sat, 31 Jan 2026 01:57:47 +0800 Subject: [PATCH] feat(profile): add config.json support for profile configuration Add ProfileConfig interface with tools, provider, model, and thinkingLevel settings. ProfileManager now exposes getToolsConfig() and getProfileConfig() methods. Co-Authored-By: Claude Opus 4.5 --- src/agent/profile/index.ts | 17 +++++++++++++++-- src/agent/profile/storage.ts | 35 +++++++++++++++++++++++++++++++++-- src/agent/profile/types.ts | 17 +++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/agent/profile/index.ts b/src/agent/profile/index.ts index 5f0fc87a..5f882015 100644 --- a/src/agent/profile/index.ts +++ b/src/agent/profile/index.ts @@ -4,7 +4,8 @@ * 管理 agent 的身份、人格、记忆等配置 */ -import type { AgentProfile, CreateProfileOptions, ProfileManagerOptions } from "./types.js"; +import type { AgentProfile, CreateProfileOptions, ProfileConfig, ProfileManagerOptions } from "./types.js"; +import type { ToolsConfig } from "../tools/policy.js"; import { DEFAULT_TEMPLATES } from "./templates.js"; import { ensureProfileDir, @@ -14,7 +15,7 @@ import { saveProfile, } from "./storage.js"; -export { type AgentProfile, type CreateProfileOptions, type ProfileManagerOptions } from "./types.js"; +export { type AgentProfile, type CreateProfileOptions, type ProfileConfig, type ProfileManagerOptions } from "./types.js"; export { DEFAULT_TEMPLATES } from "./templates.js"; export { getProfileDir, profileExists } from "./storage.js"; @@ -152,4 +153,16 @@ export class ProfileManager { return parts.join("\n\n"); } + + /** 获取 tools 配置 */ + getToolsConfig(): ToolsConfig | undefined { + const profile = this.getProfile(); + return profile?.config?.tools; + } + + /** 获取完整的 profile config */ + getProfileConfig(): ProfileConfig | undefined { + const profile = this.getProfile(); + return profile?.config; + } } diff --git a/src/agent/profile/storage.ts b/src/agent/profile/storage.ts index fa8493fe..6507288a 100644 --- a/src/agent/profile/storage.ts +++ b/src/agent/profile/storage.ts @@ -4,7 +4,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { join } from "node:path"; -import { PROFILE_FILES, type AgentProfile } from "./types.js"; +import { PROFILE_FILES, type AgentProfile, type ProfileConfig } from "./types.js"; import { DATA_DIR } from "../../shared/index.js"; const DEFAULT_BASE_DIR = join(DATA_DIR, "agent-profiles"); @@ -60,6 +60,33 @@ export function writeProfileFile( writeFileSync(filePath, content, "utf-8"); } +/** 读取 config.json */ +export function readProfileConfig( + profileId: string, + options?: StorageOptions, +): ProfileConfig | undefined { + const content = readProfileFile(profileId, PROFILE_FILES.config, options); + if (!content) { + return undefined; + } + try { + return JSON.parse(content) as ProfileConfig; + } catch { + // Invalid JSON, return undefined + return undefined; + } +} + +/** 写入 config.json */ +export function writeProfileConfig( + profileId: string, + config: ProfileConfig, + options?: StorageOptions, +): void { + const content = JSON.stringify(config, null, 2); + writeProfileFile(profileId, PROFILE_FILES.config, content, options); +} + /** 加载完整的 AgentProfile */ export function loadProfile(profileId: string, options?: StorageOptions): AgentProfile { return { @@ -69,12 +96,13 @@ export function loadProfile(profileId: string, options?: StorageOptions): AgentP tools: readProfileFile(profileId, PROFILE_FILES.tools, options), memory: readProfileFile(profileId, PROFILE_FILES.memory, options), bootstrap: readProfileFile(profileId, PROFILE_FILES.bootstrap, options), + config: readProfileConfig(profileId, options), }; } /** 保存 AgentProfile(只写入非空字段) */ export function saveProfile(profile: AgentProfile, options?: StorageOptions): void { - const { id, soul, identity, tools, memory, bootstrap } = profile; + const { id, soul, identity, tools, memory, bootstrap, config } = profile; if (soul !== undefined) { writeProfileFile(id, PROFILE_FILES.soul, soul, options); @@ -91,4 +119,7 @@ export function saveProfile(profile: AgentProfile, options?: StorageOptions): vo if (bootstrap !== undefined) { writeProfileFile(id, PROFILE_FILES.bootstrap, bootstrap, options); } + if (config !== undefined) { + writeProfileConfig(id, config, options); + } } diff --git a/src/agent/profile/types.ts b/src/agent/profile/types.ts index d6bc0c37..81db3cbc 100644 --- a/src/agent/profile/types.ts +++ b/src/agent/profile/types.ts @@ -2,6 +2,8 @@ * Agent Profile Type Definitions */ +import type { ToolsConfig } from "../tools/policy.js"; + /** Profile filename constants */ export const PROFILE_FILES = { soul: "soul.md", @@ -9,8 +11,21 @@ export const PROFILE_FILES = { tools: "tools.md", memory: "memory.md", bootstrap: "bootstrap.md", + config: "config.json", } as const; +/** Profile config.json structure */ +export interface ProfileConfig { + /** Tools policy configuration */ + tools?: ToolsConfig; + /** Default LLM provider */ + provider?: string; + /** Default model */ + model?: string; + /** Default thinking level */ + thinkingLevel?: string; +} + /** Agent Profile configuration */ export interface AgentProfile { /** Profile ID */ @@ -25,6 +40,8 @@ export interface AgentProfile { memory?: string | undefined; /** Initial context - guidance information for each conversation */ bootstrap?: string | undefined; + /** Profile configuration (from config.json) */ + config?: ProfileConfig | undefined; } /** Profile Manager options */