Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(agent): add tools and skills management methods
Jiang Bohan6f6a4f82e43d
diff --git a/src/agent/async-agent.ts b/src/agent/async-agent.tsindex d6443b8b8d..aabe04b14b 100644--- a/src/agent/async-agent.ts+++ b/src/agent/async-agent.ts@@ -70,6 +70,67 @@ export class AsyncAgent {this.channel.close();}+ /** Get current active tool names */+ getActiveTools(): string[] {+ return this.agent.getActiveTools();+ }++ /**+ * Reload tools from credentials config.+ * Call this after updating tool status to apply changes immediately.+ */+ reloadTools(): string[] {+ return this.agent.reloadTools();+ }++ /**+ * Get all skills with their eligibility status.+ */+ getSkillsWithStatus(): Array<{+ id: string;+ name: string;+ description: string;+ source: string;+ eligible: boolean;+ reasons?: string[] | undefined;+ }> {+ return this.agent.getSkillsWithStatus();+ }++ /**+ * Get eligible skills only.+ */+ getEligibleSkills(): Array<{+ id: string;+ name: string;+ description: string;+ source: string;+ }> {+ return this.agent.getEligibleSkills();+ }++ /**+ * Reload skills from disk.+ */+ reloadSkills(): void {+ this.agent.reloadSkills();+ }++ /**+ * Set a tool's enabled status and persist to profile config.+ * Returns the new tools config, or undefined if no profile is loaded.+ */+ setToolStatus(toolName: string, enabled: boolean): { allow?: string[]; deny?: string[] } | undefined {+ return this.agent.setToolStatus(toolName, enabled);+ }++ /**+ * Get current profile ID, if any.+ */+ getProfileId(): string | undefined {+ return this.agent.getProfileId();+ }+private setupStreamEvents(): void {let currentStreamId: string | null = null;diff --git a/src/agent/profile/index.ts b/src/agent/profile/index.tsindex 43c4de574f..bc41e0461a 100644--- a/src/agent/profile/index.ts+++ b/src/agent/profile/index.ts@@ -169,4 +169,50 @@ export class ProfileManager {const profile = this.getProfile();return profile?.config;}++ /** 更新 tools 配置 */+ updateToolsConfig(toolsConfig: ToolsConfig): void {+ const profile = this.getOrCreateProfile(false);+ const currentConfig = profile.config ?? {};+ const newConfig: ProfileConfig = {+ ...currentConfig,+ tools: toolsConfig,+ };+ profile.config = newConfig;+ this.profile = profile;+ saveProfile({ id: this.profileId, config: newConfig }, { baseDir: this.baseDir });+ }++ /** 设置单个 tool 的启用状态 */+ setToolEnabled(toolName: string, enabled: boolean): ToolsConfig {+ const currentConfig = this.getToolsConfig() ?? {};+ const allow = new Set(currentConfig.allow ?? []);+ const deny = new Set(currentConfig.deny ?? []);++ if (enabled) {+ // Enable: add to allow, remove from deny+ allow.add(toolName);+ deny.delete(toolName);+ } else {+ // Disable: add to deny, remove from allow+ deny.add(toolName);+ allow.delete(toolName);+ }++ // Build new config object, only including non-empty arrays+ const newConfig: ToolsConfig = { ...currentConfig };+ if (allow.size > 0) {+ newConfig.allow = Array.from(allow);+ } else {+ delete newConfig.allow;+ }+ if (deny.size > 0) {+ newConfig.deny = Array.from(deny);+ } else {+ delete newConfig.deny;+ }++ this.updateToolsConfig(newConfig);+ return newConfig;+ }}diff --git a/src/agent/runner.ts b/src/agent/runner.tsindex 7ac62bc620..7a1d1c587d 100644--- a/src/agent/runner.ts+++ b/src/agent/runner.ts@@ -29,6 +29,8 @@ export class Agent {private readonly skillManager?: SkillManager;private readonly contextWindowGuard: ContextWindowGuardResult;private readonly debug: boolean;+ private toolsOptions: AgentOptions;+ private readonly originalToolsConfig?: ToolsConfig;/** Current session ID */readonly sessionId: string;@@ -78,15 +80,18 @@ export class Agent {);// Load Agent Profile (if profileId is specified)+ // Every Agent should have a Profile for memory, tools config, and other settingslet systemPrompt: string | undefined;if (options.profileId) {this.profile = new ProfileManager({profileId: options.profileId,baseDir: options.profileBaseDir,});+ // Ensure profile directory exists (creates with default templates if new)+ this.profile.getOrCreateProfile(true);systemPrompt = this.profile.buildSystemPrompt();} else if (options.systemPrompt) {- // Use provided systemPrompt directly+ // Use provided systemPrompt directly (no profile - memory tools won't work)systemPrompt = options.systemPrompt;}@@ -188,12 +193,15 @@ export class Agent {this.agent.setModel(model);+ // Save original tools config from options (for later merging during reload)+ this.originalToolsConfig = options.tools;+// Merge Profile tools config with options.tools (options takes precedence)const profileToolsConfig = this.profile?.getToolsConfig();const mergedToolsConfig = mergeToolsConfig(profileToolsConfig, options.tools);- const toolsOptions = mergedToolsConfig ? { ...options, tools: mergedToolsConfig } : options;+ this.toolsOptions = mergedToolsConfig ? { ...options, tools: mergedToolsConfig } : options;- const tools = resolveTools(toolsOptions);+ const tools = resolveTools(this.toolsOptions);if (this.debug) {if (profileToolsConfig) {console.error(`[debug] Profile tools config: ${JSON.stringify(profileToolsConfig)}`);@@ -269,4 +277,99 @@ export class Agent {this.agent.replaceMessages(result.kept);}}++ /**+ * Reload tools from profile config.+ * Call this after updating tool status to apply changes+ * without restarting the agent session.+ */+ reloadTools(): string[] {+ // Re-read profile tools config to get latest changes+ const profileToolsConfig = this.profile?.getToolsConfig();+ const mergedToolsConfig = mergeToolsConfig(profileToolsConfig, this.originalToolsConfig);+ this.toolsOptions = mergedToolsConfig+ ? { ...this.toolsOptions, tools: mergedToolsConfig }+ : this.toolsOptions;++ const tools = resolveTools(this.toolsOptions);+ this.agent.setTools(tools);+ if (this.debug) {+ console.error(`[debug] Reloaded ${tools.length} tools: ${tools.map(t => t.name).join(", ") || "(none)"}`);+ }+ return tools.map(t => t.name);+ }++ /** Get current active tool names */+ getActiveTools(): string[] {+ return this.agent.state.tools?.map(t => t.name) ?? [];+ }++ /**+ * Get all skills with their eligibility status.+ * Returns empty array if skills are disabled.+ */+ getSkillsWithStatus(): Array<{+ id: string;+ name: string;+ description: string;+ source: string;+ eligible: boolean;+ reasons?: string[] | undefined;+ }> {+ if (!this.skillManager) {+ return [];+ }+ return this.skillManager.listAllSkillsWithStatus();+ }++ /**+ * Get eligible skills only.+ * Returns empty array if skills are disabled.+ */+ getEligibleSkills(): Array<{+ id: string;+ name: string;+ description: string;+ source: string;+ }> {+ if (!this.skillManager) {+ return [];+ }+ return this.skillManager.listSkills();+ }++ /**+ * Reload skills from disk.+ * Call this after adding/removing skills to apply changes.+ */+ reloadSkills(): void {+ if (this.skillManager) {+ this.skillManager.reload();+ }+ }++ /**+ * Set a tool's enabled status and persist to profile config.+ * Returns the new tools config, or undefined if no profile is loaded.+ */+ setToolStatus(toolName: string, enabled: boolean): { allow?: string[]; deny?: string[] } | undefined {+ if (!this.profile) {+ return undefined;+ }+ const newConfig = this.profile.setToolEnabled(toolName, enabled);+ // Reload tools to apply changes+ this.reloadTools();+ // Build result object, only including defined properties+ const result: { allow?: string[]; deny?: string[] } = {};+ if (newConfig.allow) result.allow = newConfig.allow;+ if (newConfig.deny) result.deny = newConfig.deny;+ return result;+ }++ /**+ * Get current profile ID, if any.+ */+ getProfileId(): string | undefined {+ return this.profile?.getProfile()?.id;+ }}