Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(profile): add config.json support for profile configuration

Jiang Bohan9467ac9fffc4
diff --git a/src/agent/profile/index.ts b/src/agent/profile/index.ts
index 5f0fc87aea..5f8820153d 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 fa8493fe6e..6507288a10 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 d6bc0c37a2..81db3cbca8 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 */