pulse-coder-engine 0.0.1-alpha.13 → 0.0.1-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/built-in/index.cjs +41 -3
- package/dist/built-in/index.cjs.map +1 -1
- package/dist/built-in/index.js +41 -3
- package/dist/built-in/index.js.map +1 -1
- package/dist/index.cjs +41 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +41 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/built-in/index.ts","../../src/built-in/mcp-plugin/index.ts","../../src/built-in/skills-plugin/index.ts","../../src/built-in/plan-mode-plugin/index.ts","../../src/built-in/task-tracking-plugin/index.ts","../../src/built-in/sub-agent-plugin/index.ts","../../src/ai/index.ts","../../src/config/index.ts","../../src/prompt/system.ts","../../src/context/index.ts","../../src/core/loop.ts","../../src/tools/read.ts","../../src/tools/utils.ts","../../src/tools/write.ts","../../src/tools/edit.ts","../../src/tools/grep.ts","../../src/tools/ls.ts","../../src/tools/bash.ts","../../src/tools/tavily.ts","../../src/tools/clarify.ts","../../src/tools/index.ts"],"sourcesContent":["/**\n * Built-in plugins for Pulse Coder Engine\n * 引擎内置插件集合\n */\n\nimport { builtInMCPPlugin } from './mcp-plugin';\nimport { builtInSkillsPlugin } from './skills-plugin';\nimport { builtInPlanModePlugin } from './plan-mode-plugin';\nimport { builtInTaskTrackingPlugin } from './task-tracking-plugin';\nimport { SubAgentPlugin } from './sub-agent-plugin';\n\n/**\n * 默认内置插件列表\n * 这些插件会在引擎启动时自动加载\n */\nexport const builtInPlugins = [\n builtInMCPPlugin,\n builtInSkillsPlugin,\n builtInPlanModePlugin,\n builtInTaskTrackingPlugin,\n new SubAgentPlugin()\n];\n\n/**\n * 单独导出各个内置插件,便于外部使用\n */\nexport { builtInMCPPlugin } from './mcp-plugin';\nexport { builtInSkillsPlugin, BuiltInSkillRegistry } from './skills-plugin';\nexport { builtInPlanModePlugin, BuiltInPlanModeService } from './plan-mode-plugin';\nexport { builtInTaskTrackingPlugin, TaskListService } from './task-tracking-plugin';\nexport type { TaskStatus, WorkTask, WorkTaskListSnapshot } from './task-tracking-plugin';\nexport type {\n PlanMode,\n PlanIntentLabel,\n ToolCategory,\n ToolRisk,\n ToolMeta,\n ModePolicy,\n PlanModeEvent,\n PlanModeEventName,\n PlanModeTransitionResult,\n PlanModeService\n} from './plan-mode-plugin';\nexport { SubAgentPlugin } from './sub-agent-plugin';\n\nexport default builtInPlugins;","/**\n * Built-in MCP Plugin for Pulse Coder Engine\n * 将 MCP 功能作为引擎内置插件\n */\n\nimport { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\nimport { createMCPClient } from '@ai-sdk/mcp';\nimport { existsSync, readFileSync } from 'fs';\nimport * as path from 'path';\n\nexport interface MCPPluginConfig {\n servers: Record<string, { url: string }>;\n}\n\nexport async function loadMCPConfig(cwd: string): Promise<MCPPluginConfig> {\n // 优先读取 .pulse-coder/mcp.json,兼容旧版 .coder/mcp.json\n const newConfigPath = path.join(cwd, '.pulse-coder', 'mcp.json');\n const legacyConfigPath = path.join(cwd, '.coder', 'mcp.json');\n const configPath = existsSync(newConfigPath) ? newConfigPath : legacyConfigPath;\n\n if (!existsSync(configPath)) {\n return { servers: {} };\n }\n\n try {\n const content = readFileSync(configPath, 'utf-8');\n const parsed = JSON.parse(content);\n\n if (!parsed.servers || typeof parsed.servers !== 'object') {\n console.warn('[MCP] Invalid config: missing \"servers\" object');\n return { servers: {} };\n }\n\n return { servers: parsed.servers };\n } catch (error) {\n console.warn(`[MCP] Failed to load config: ${error instanceof Error ? error.message : 'Unknown error'}`);\n return { servers: {} };\n }\n}\n\nfunction createHTTPTransport(config: { url: string }) {\n return {\n type: 'http' as const,\n url: config.url\n };\n}\n\nexport const builtInMCPPlugin: EnginePlugin = {\n name: 'pulse-coder-engine/built-in-mcp',\n version: '1.0.0',\n\n async initialize(context: EnginePluginContext) {\n const config = await loadMCPConfig(process.cwd());\n\n const serverCount = Object.keys(config.servers).length;\n if (serverCount === 0) {\n console.log('[MCP] No MCP servers configured');\n return;\n }\n\n let loadedCount = 0;\n\n for (const [serverName, serverConfig] of Object.entries(config.servers)) {\n try {\n if (!serverConfig.url) {\n console.warn(`[MCP] Server \"${serverName}\" missing URL, skipping`);\n continue;\n }\n\n const transport = createHTTPTransport(serverConfig);\n const client = await createMCPClient({ transport });\n\n const tools = await client.tools();\n\n // 注册工具到引擎,使用命名空间前缀\n const namespacedTools = Object.fromEntries(\n Object.entries(tools).map(([toolName, tool]) => [\n `mcp_${serverName}_${toolName}`,\n tool as any\n ])\n );\n\n context.registerTools(namespacedTools);\n\n loadedCount++;\n console.log(`[MCP] Server \"${serverName}\" loaded (${Object.keys(tools).length} tools)`);\n\n // 注册服务供其他插件使用\n context.registerService(`mcp:${serverName}`, client);\n\n } catch (error) {\n console.warn(`[MCP] Failed to load server \"${serverName}\": ${error instanceof Error ? error.message : 'Unknown error'}`);\n }\n }\n\n if (loadedCount > 0) {\n console.log(`[MCP] Successfully loaded ${loadedCount}/${serverCount} MCP servers`);\n } else {\n console.warn('[MCP] No MCP servers were loaded successfully');\n }\n }\n};\n\nexport default builtInMCPPlugin;","/**\n * Built-in Skills Plugin for Pulse Coder Engine\n * 将技能系统作为引擎内置插件\n */\n\nimport { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\nimport { Tool } from '../../shared/types';\nimport { readFileSync } from 'fs';\nimport { globSync } from 'glob';\nimport matter from 'gray-matter';\nimport { homedir } from 'os';\nimport { z } from 'zod';\n\n/**\n * 技能信息接口\n */\nexport interface SkillInfo {\n name: string;\n description: string;\n location: string;\n content: string;\n metadata?: Record<string, any>;\n}\n\n/**\n * 技能注册表\n */\nexport class BuiltInSkillRegistry {\n private skills: Map<string, SkillInfo> = new Map();\n private initialized = false;\n\n /**\n * 初始化注册表,扫描并加载所有技能\n */\n async initialize(cwd: string): Promise<void> {\n if (this.initialized) {\n console.warn('SkillRegistry already initialized');\n return;\n }\n\n console.log('Scanning built-in skills...');\n const skillList = await this.scanSkills(cwd);\n\n this.skills.clear();\n for (const skill of skillList) {\n this.skills.set(skill.name, skill);\n }\n\n this.initialized = true;\n console.log(`Loaded ${this.skills.size} built-in skill(s)`);\n }\n\n /**\n * 扫描技能文件\n */\n private async scanSkills(cwd: string): Promise<SkillInfo[]> {\n const skills: SkillInfo[] = [];\n\n const scanPaths = [\n // 项目级技能(优先 .pulse-coder,兼容旧版 .coder 和 .claude)\n { base: cwd, pattern: '.pulse-coder/skills/**/SKILL.md' },\n { base: cwd, pattern: '.coder/skills/**/SKILL.md' },\n { base: cwd, pattern: '.claude/skills/**/SKILL.md' },\n // 用户级技能(优先 .pulse-coder,兼容旧版 .coder)\n { base: homedir(), pattern: '.pulse-coder/skills/**/SKILL.md' },\n { base: homedir(), pattern: '.coder/skills/**/SKILL.md' }\n ];\n\n for (const { base, pattern } of scanPaths) {\n try {\n const files = globSync(pattern, { cwd: base, absolute: true });\n\n for (const filePath of files) {\n try {\n const skillInfo = this.parseSkillFile(filePath);\n if (skillInfo) {\n skills.push(skillInfo);\n }\n } catch (error) {\n console.warn(`Failed to parse skill file ${filePath}:`, error);\n }\n }\n } catch (error) {\n console.debug(`Skip scanning ${pattern} in ${base}:`, error);\n }\n }\n\n return skills;\n }\n\n /**\n * 解析技能文件\n */\n private parseSkillFile(filePath: string): SkillInfo | null {\n try {\n const content = readFileSync(filePath, 'utf-8');\n const { data, content: markdownContent } = matter(content);\n\n if (!data.name || !data.description) {\n console.warn(`Skill file ${filePath} missing required fields (name or description)`);\n return null;\n }\n\n return {\n name: data.name,\n description: data.description,\n location: filePath,\n content: markdownContent,\n metadata: data\n };\n } catch (error) {\n console.warn(`Failed to read skill file ${filePath}:`, error);\n return null;\n }\n }\n\n /**\n * 获取所有技能\n */\n getAll(): SkillInfo[] {\n return Array.from(this.skills.values());\n }\n\n /**\n * 注册或更新一个技能(支持插件在运行期追加技能)\n */\n registerSkill(skill: SkillInfo): { skillName: string; replaced: boolean; total: number } {\n const name = skill.name?.trim();\n if (!name) {\n throw new Error('Skill name is required');\n }\n\n const existingKey = Array.from(this.skills.keys()).find((key) => key.toLowerCase() === name.toLowerCase());\n const replaced = existingKey !== undefined;\n\n if (existingKey && existingKey !== name) {\n this.skills.delete(existingKey);\n }\n\n this.skills.set(name, {\n ...skill,\n name\n });\n\n return {\n skillName: name,\n replaced,\n total: this.skills.size\n };\n }\n\n /**\n * 根据名称获取技能(大小写不敏感)\n */\n get(name: string): SkillInfo | undefined {\n const exact = this.skills.get(name);\n if (exact) {\n return exact;\n }\n\n const target = name.toLowerCase();\n return this.getAll().find((skill) => skill.name.toLowerCase() === target);\n }\n\n /**\n * 检查技能是否存在\n */\n has(name: string): boolean {\n return !!this.get(name);\n }\n\n /**\n * 搜索技能(模糊匹配)\n */\n search(keyword: string): SkillInfo[] {\n const lowerKeyword = keyword.toLowerCase();\n return this.getAll().filter(\n (skill) =>\n skill.name.toLowerCase().includes(lowerKeyword) ||\n skill.description.toLowerCase().includes(lowerKeyword)\n );\n }\n}\n\n/**\n * 技能工具参数 schema\n */\nconst skillToolSchema = z.object({\n name: z.string().describe('The name of the skill to execute')\n});\n\ntype SkillToolInput = z.infer<typeof skillToolSchema>;\n\n/**\n * 生成技能工具\n */\nfunction generateSkillTool(registry: BuiltInSkillRegistry): Tool<SkillToolInput, SkillInfo> {\n const getSkillsPrompt = (availableSkills: SkillInfo[]) => {\n return [\n \"If query matches an available skill's description or instruction [use skill], use the skill tool to get detailed instructions.\",\n \"Load a skill to get detailed instructions for a specific task.\",\n \"Skills provide specialized knowledge and step-by-step guidance.\",\n \"Use this when a task matches an available skill's description.\",\n \"Only the skills listed here are available:\",\n \"[!important] You should follow the skill's step-by-step guidance. If the skill is not complete, ask the user for more information.\",\n \"<available_skills>\",\n ...availableSkills.flatMap((skill) => [\n ` <skill>`,\n ` <name>${skill.name}</name>`,\n ` <description>${skill.description}</description>`,\n ` </skill>`\n ]),\n \"</available_skills>\"\n ].join(\" \");\n };\n\n return {\n name: \"skill\",\n description: getSkillsPrompt(registry.getAll()),\n inputSchema: skillToolSchema,\n execute: async ({ name }) => {\n const skill = registry.get(name);\n if (!skill) {\n throw new Error(`Skill ${name} not found`);\n }\n return skill;\n }\n };\n}\n\n/**\n * 内置技能插件\n */\nexport const builtInSkillsPlugin: EnginePlugin = {\n name: 'pulse-coder-engine/built-in-skills',\n version: '1.0.0',\n\n async initialize(context: EnginePluginContext) {\n const registry = new BuiltInSkillRegistry();\n await registry.initialize(process.cwd());\n\n context.registerService('skillRegistry', registry);\n context.registerTool('skill', generateSkillTool(registry));\n\n context.registerHook('beforeRun', ({ tools }) => {\n return {\n tools: {\n ...tools,\n skill: generateSkillTool(registry)\n }\n };\n });\n\n const skills = registry.getAll();\n if (skills.length === 0) {\n console.log('[Skills] No skills found');\n return;\n }\n\n console.log(`[Skills] Registered ${skills.length} skill(s)`);\n }\n};\n\nexport default builtInSkillsPlugin;","import type { EventEmitter } from 'events';\nimport type { ModelMessage } from 'ai';\n\nimport type { SystemPromptOption } from '../../shared/types';\nimport type { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\n\nexport type PlanMode = 'planning' | 'executing';\nexport type PlanIntentLabel = 'PLAN_ONLY' | 'EXECUTE_NOW' | 'UNCLEAR';\nexport type ToolCategory = 'read' | 'search' | 'write' | 'execute' | 'other';\nexport type ToolRisk = 'low' | 'medium' | 'high';\n\nexport type PlanModeEventName =\n | 'mode_entered'\n | 'execution_intent_detected'\n | 'mode_switched_by_intent'\n | 'disallowed_tool_attempt_in_planning';\n\nexport interface ToolMeta {\n name: string;\n category: ToolCategory;\n risk: ToolRisk;\n description: string;\n examples?: string[];\n}\n\nexport interface ModePolicy {\n mode: PlanMode;\n allowedCategories: ToolCategory[];\n disallowedCategories: ToolCategory[];\n notes?: string;\n}\n\nexport interface PlanModeEvent {\n name: PlanModeEventName;\n mode: PlanMode;\n timestamp: number;\n payload?: Record<string, unknown>;\n}\n\nexport interface PlanModeTransitionResult {\n modeBefore: PlanMode;\n modeAfter: PlanMode;\n switched: boolean;\n intent: PlanIntentLabel;\n userInput: string;\n}\n\nexport interface PlanModeService {\n getMode(): PlanMode;\n setMode(mode: PlanMode, reason?: string): void;\n detectIntent(input: string): PlanIntentLabel;\n processContextMessages(messages: ModelMessage[]): PlanModeTransitionResult;\n getModePolicy(mode?: PlanMode): ModePolicy;\n getToolMetadata(toolNames: string[]): ToolMeta[];\n buildPromptAppend(toolNames: string[], transition?: PlanModeTransitionResult): string;\n getEvents(limit?: number): PlanModeEvent[];\n}\n\ntype LoggerLike = EnginePluginContext['logger'];\n\nconst PLANNING_POLICY: ModePolicy = {\n mode: 'planning',\n allowedCategories: ['read', 'search', 'other'],\n disallowedCategories: ['write', 'execute'],\n notes:\n 'Planning mode is prompt-constrained only. Disallowed tool attempts are observed and logged, not hard-blocked.'\n};\n\nconst EXECUTING_POLICY: ModePolicy = {\n mode: 'executing',\n allowedCategories: ['read', 'search', 'write', 'execute', 'other'],\n disallowedCategories: []\n};\n\nconst EXECUTE_PATTERNS: RegExp[] = [\n /开始执行/i,\n /按这个计划做/i,\n /可以改代码了/i,\n /直接实现/i,\n /go\\s+ahead/i,\n /proceed/i,\n /implement\\s+it/i,\n /start\\s+implement/i,\n /start\\s+coding/i\n];\n\nconst NEGATIVE_PATTERNS: RegExp[] = [\n /先不(要)?执行/i,\n /先别执行/i,\n /不要执行/i,\n /暂时不要执行/i,\n /先别改代码/i,\n /先不要改代码/i,\n /先不要实现/i,\n /not\\s+now/i,\n /hold\\s+off/i,\n /do\\s+not\\s+(start|execute|implement|proceed)/i,\n /don't\\s+(start|execute|implement|proceed)/i\n];\n\nconst PLAN_PATTERNS: RegExp[] = [/先计划/i, /先分析/i, /先出方案/i, /plan\\s+first/i, /analysis\\s+first/i];\n\n\nfunction appendSystemPrompt(base: SystemPromptOption | undefined, append: string): SystemPromptOption {\n if (!append.trim()) {\n return base ?? { append: '' };\n }\n\n if (!base) {\n return { append };\n }\n\n if (typeof base === 'string') {\n return `${base}\\n\\n${append}`;\n }\n\n if (typeof base === 'function') {\n return () => `${base()}\\n\\n${append}`;\n }\n\n const currentAppend = base.append.trim();\n return {\n append: currentAppend ? `${currentAppend}\\n\\n${append}` : append\n };\n}\n\nconst KNOWN_TOOL_META: Record<string, Omit<ToolMeta, 'name'>> = {\n read: {\n category: 'read',\n risk: 'low',\n description: 'Read file contents from the workspace.'\n },\n ls: {\n category: 'read',\n risk: 'low',\n description: 'List files and directories.'\n },\n grep: {\n category: 'search',\n risk: 'low',\n description: 'Search text content across files.'\n },\n tavily: {\n category: 'search',\n risk: 'low',\n description: 'Search web results from external sources.'\n },\n skill: {\n category: 'search',\n risk: 'low',\n description: 'Load procedural guidance from installed skills.'\n },\n write: {\n category: 'write',\n risk: 'high',\n description: 'Create or overwrite file content.'\n },\n edit: {\n category: 'write',\n risk: 'high',\n description: 'Modify existing files using exact replacements.'\n },\n bash: {\n category: 'execute',\n risk: 'high',\n description: 'Execute shell commands.'\n },\n clarify: {\n category: 'other',\n risk: 'low',\n description: 'Ask the user a targeted clarification question.'\n },\n task_create: {\n category: 'other',\n risk: 'low',\n description: 'Create tracked task entries for planning and execution visibility.'\n },\n task_get: {\n category: 'other',\n risk: 'low',\n description: 'Inspect a task entry by ID.'\n },\n task_list: {\n category: 'other',\n risk: 'low',\n description: 'List task tracking entries and status summary.'\n },\n task_update: {\n category: 'other',\n risk: 'low',\n description: 'Update task tracking fields and status.'\n }\n};\n\nclass BuiltInPlanModeService implements PlanModeService {\n private mode: PlanMode;\n private readonly events: PlanModeEvent[] = [];\n\n constructor(\n private readonly logger: LoggerLike,\n private readonly eventEmitter: EventEmitter,\n initialMode: PlanMode = 'executing'\n ) {\n this.mode = initialMode;\n this.emitEvent('mode_entered', { reason: 'initialize' });\n }\n\n getMode(): PlanMode {\n return this.mode;\n }\n\n setMode(mode: PlanMode, reason: string = 'manual'): void {\n if (this.mode === mode) {\n return;\n }\n\n this.mode = mode;\n this.emitEvent('mode_entered', { reason });\n }\n\n detectIntent(input: string): PlanIntentLabel {\n const text = input.trim();\n if (!text) {\n return 'UNCLEAR';\n }\n\n if (NEGATIVE_PATTERNS.some((pattern) => pattern.test(text))) {\n return 'PLAN_ONLY';\n }\n\n if (EXECUTE_PATTERNS.some((pattern) => pattern.test(text))) {\n return 'EXECUTE_NOW';\n }\n\n if (PLAN_PATTERNS.some((pattern) => pattern.test(text))) {\n return 'PLAN_ONLY';\n }\n\n return 'UNCLEAR';\n }\n\n processContextMessages(messages: ModelMessage[]): PlanModeTransitionResult {\n const userInput = this.getLatestUserText(messages);\n const modeBefore = this.mode;\n\n if (!userInput) {\n return {\n modeBefore,\n modeAfter: this.mode,\n switched: false,\n intent: 'UNCLEAR',\n userInput: ''\n };\n }\n\n const intent = this.detectIntent(userInput);\n\n if (intent === 'EXECUTE_NOW') {\n this.emitEvent('execution_intent_detected', { intent, userInput });\n\n if (this.mode === 'planning') {\n this.mode = 'executing';\n this.emitEvent('mode_switched_by_intent', {\n from: 'planning',\n to: 'executing',\n userInput\n });\n this.emitEvent('mode_entered', {\n reason: 'intent',\n from: 'planning'\n });\n }\n }\n\n return {\n modeBefore,\n modeAfter: this.mode,\n switched: modeBefore !== this.mode,\n intent,\n userInput\n };\n }\n\n getModePolicy(mode: PlanMode = this.mode): ModePolicy {\n return mode === 'planning' ? PLANNING_POLICY : EXECUTING_POLICY;\n }\n\n getToolMetadata(toolNames: string[]): ToolMeta[] {\n return Array.from(new Set(toolNames)).sort().map((name) => this.inferToolMeta(name));\n }\n\n buildPromptAppend(toolNames: string[], transition?: PlanModeTransitionResult): string {\n const mode = this.mode;\n const policy = this.getModePolicy(mode);\n const toolMeta = this.getToolMetadata(toolNames);\n const shownTools = toolMeta.slice(0, 40);\n const omittedCount = toolMeta.length - shownTools.length;\n\n const lines: string[] = [\n '## Plan Mode Policy (Built-in Plugin)',\n `Current mode: ${mode.toUpperCase()}`,\n `Allowed tool categories: ${policy.allowedCategories.join(', ')}`,\n `Disallowed tool categories: ${policy.disallowedCategories.join(', ') || 'none'}`,\n policy.notes ? `Policy notes: ${policy.notes}` : ''\n ].filter(Boolean);\n\n if (mode === 'planning') {\n lines.push(\n 'Planning objective: prioritize reading, analysis, and plan generation.',\n 'In planning mode, do not intentionally perform write/edit/execute actions.',\n 'If implementation is requested but intent is not explicit, ask for execution authorization.',\n 'Before each tool call in planning mode, self-check category compliance.',\n 'Plan format must include: goals, assumptions, steps, risks, validation approach.'\n );\n } else {\n lines.push(\n 'Executing objective: follow the agreed plan before broad exploration.',\n 'Make targeted edits and keep changes scoped.',\n 'Report what changed and how it was validated.'\n );\n }\n\n if (transition?.switched && transition.modeAfter === 'executing') {\n lines.push(\n 'Mode transition: the latest user message explicitly authorized execution.',\n 'In your next reply, acknowledge switching to EXECUTING mode before implementation details.'\n );\n }\n\n lines.push('Tool metadata (prompt-level policy reference):');\n for (const meta of shownTools) {\n lines.push(`- ${meta.name}: category=${meta.category}, risk=${meta.risk}, ${meta.description}`);\n }\n\n if (omittedCount > 0) {\n lines.push(`- ... ${omittedCount} additional tool(s) omitted for brevity.`);\n }\n\n return lines.join('\\n');\n }\n\n getEvents(limit: number = 50): PlanModeEvent[] {\n return this.events.slice(-Math.max(0, limit));\n }\n\n observePotentialPolicyViolation(toolName: string, input: unknown): void {\n if (this.mode !== 'planning') {\n return;\n }\n\n const meta = this.inferToolMeta(toolName);\n const policy = this.getModePolicy('planning');\n\n if (!policy.disallowedCategories.includes(meta.category)) {\n return;\n }\n\n this.emitEvent('disallowed_tool_attempt_in_planning', {\n toolName,\n category: meta.category,\n risk: meta.risk,\n input\n });\n }\n\n private inferToolMeta(name: string): ToolMeta {\n const knownMeta = KNOWN_TOOL_META[name];\n if (knownMeta) {\n return {\n name,\n ...knownMeta\n };\n }\n\n if (name.startsWith('mcp_')) {\n return {\n name,\n category: 'execute',\n risk: 'medium',\n description: 'MCP external tool invocation.'\n };\n }\n\n if (name.endsWith('_agent')) {\n return {\n name,\n category: 'execute',\n risk: 'high',\n description: 'Sub-agent task execution tool.'\n };\n }\n\n if (/read|list|cat/i.test(name)) {\n return {\n name,\n category: 'read',\n risk: 'low',\n description: 'Likely a read-only inspection tool inferred by name.'\n };\n }\n\n if (/search|find|query|grep/i.test(name)) {\n return {\n name,\n category: 'search',\n risk: 'low',\n description: 'Likely a search tool inferred by name.'\n };\n }\n\n if (/write|edit|patch|update|create|delete|remove/i.test(name)) {\n return {\n name,\n category: 'write',\n risk: 'high',\n description: 'Likely a file-modifying tool inferred by name.'\n };\n }\n\n if (/bash|exec|run|shell|deploy|build|test/i.test(name)) {\n return {\n name,\n category: 'execute',\n risk: 'high',\n description: 'Likely a command execution tool inferred by name.'\n };\n }\n\n return {\n name,\n category: 'other',\n risk: 'low',\n description: 'Tool category could not be inferred with high confidence.'\n };\n }\n\n private getLatestUserText(messages: ModelMessage[]): string {\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (message.role !== 'user') {\n continue;\n }\n\n return this.messageContentToText(message.content);\n }\n\n return '';\n }\n\n private messageContentToText(content: ModelMessage['content']): string {\n if (typeof content === 'string') {\n return content;\n }\n\n if (!Array.isArray(content)) {\n return '';\n }\n\n const textParts: string[] = [];\n\n for (const part of content) {\n if (typeof part === 'string') {\n textParts.push(part);\n continue;\n }\n\n if (part && typeof part === 'object' && 'text' in part && typeof part.text === 'string') {\n textParts.push(part.text);\n }\n }\n\n return textParts.join('\\n');\n }\n\n private emitEvent(name: PlanModeEventName, payload?: Record<string, unknown>): void {\n const event: PlanModeEvent = {\n name,\n mode: this.mode,\n timestamp: Date.now(),\n payload\n };\n\n this.events.push(event);\n if (this.events.length > 500) {\n this.events.shift();\n }\n\n this.eventEmitter.emit(name, event);\n this.eventEmitter.emit('plan_mode_event', event);\n\n if (name === 'disallowed_tool_attempt_in_planning') {\n this.logger.warn('[PlanMode] Soft violation detected in planning mode', payload);\n return;\n }\n\n this.logger.info(`[PlanMode] ${name}`, payload);\n }\n}\n\nexport const builtInPlanModePlugin: EnginePlugin = {\n name: 'pulse-coder-engine/built-in-plan-mode',\n version: '1.0.0',\n\n async initialize(context: EnginePluginContext): Promise<void> {\n const service = new BuiltInPlanModeService(context.logger, context.events, 'executing');\n\n // Inject plan-mode system prompt before each LLM call\n context.registerHook('beforeLLMCall', ({ context: runContext, tools, systemPrompt }) => {\n const mode = service.getMode();\n if (mode === 'executing') {\n return;\n }\n\n const transition = service.processContextMessages(runContext.messages);\n const append = service.buildPromptAppend(Object.keys(tools), transition);\n const finalSystemPrompt = appendSystemPrompt(systemPrompt, append);\n\n return { systemPrompt: finalSystemPrompt };\n });\n\n // Observe tool calls for policy violations in planning mode\n context.registerHook('beforeToolCall', ({ name, input }) => {\n service.observePotentialPolicyViolation(name, input);\n });\n\n context.registerService('planMode', service);\n context.registerService('planModeService', service);\n\n context.logger.info('[PlanMode] Built-in plan mode plugin initialized', {\n mode: service.getMode()\n });\n }\n};\n\nexport { BuiltInPlanModeService };\n\nexport default builtInPlanModePlugin;\n","import { promises as fs } from 'fs';\nimport path from 'path';\nimport { homedir } from 'os';\nimport { randomUUID } from 'crypto';\nimport { z } from 'zod';\n\nimport type { BuiltInSkillRegistry, SkillInfo } from '../skills-plugin';\n\nimport type { Tool } from '../../shared/types';\nimport type { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\n\nconst TASK_STATUSES = ['pending', 'in_progress', 'completed', 'blocked'] as const;\n\nexport type TaskStatus = (typeof TASK_STATUSES)[number];\n\nexport interface WorkTask {\n id: string;\n title: string;\n details?: string;\n status: TaskStatus;\n dependencies: string[];\n blockedReason?: string;\n metadata?: Record<string, any>;\n createdAt: number;\n updatedAt: number;\n completedAt?: number;\n}\n\nexport interface WorkTaskListSnapshot {\n taskListId: string;\n storagePath: string;\n createdAt: number;\n updatedAt: number;\n total: number;\n tasks: WorkTask[];\n}\n\ninterface TaskListStoreFile {\n taskListId: string;\n createdAt: number;\n updatedAt: number;\n tasks: WorkTask[];\n}\n\ninterface CreateTaskInput {\n title: string;\n details?: string;\n status?: TaskStatus;\n dependencies?: string[];\n blockedReason?: string;\n metadata?: Record<string, any>;\n}\n\ninterface ListTaskOptions {\n statuses?: TaskStatus[];\n includeCompleted?: boolean;\n limit?: number;\n}\n\ninterface UpdateTaskInput {\n id: string;\n title?: string;\n details?: string;\n status?: TaskStatus;\n dependencies?: string[];\n blockedReason?: string;\n metadata?: Record<string, any>;\n delete?: boolean;\n}\n\nconst CREATE_TASK_ITEM_SCHEMA = z.object({\n title: z.string().min(1).describe('Task title'),\n details: z.string().optional().describe('Task details / acceptance notes'),\n status: z.enum(TASK_STATUSES).optional().describe('Initial status; defaults to pending'),\n dependencies: z.array(z.string()).optional().describe('Task IDs that must be completed first'),\n blockedReason: z.string().optional().describe('Reason when status is blocked'),\n metadata: z.record(z.string(), z.any()).optional().describe('Additional machine-readable metadata')\n});\n\nconst TASK_CREATE_INPUT_SCHEMA = z\n .object({\n title: z.string().min(1).optional().describe('Task title (single-task mode)'),\n details: z.string().optional().describe('Task details (single-task mode)'),\n status: z.enum(TASK_STATUSES).optional().describe('Initial status (single-task mode)'),\n dependencies: z.array(z.string()).optional().describe('Dependencies (single-task mode)'),\n blockedReason: z.string().optional().describe('Blocked reason (single-task mode)'),\n metadata: z.record(z.string(), z.any()).optional().describe('Metadata (single-task mode)'),\n tasks: z.array(CREATE_TASK_ITEM_SCHEMA).min(1).optional().describe('Batch create mode')\n })\n .refine((value) => !!value.tasks?.length || !!value.title, {\n message: 'Either provide `tasks` or `title` for single-task mode.'\n });\n\nconst TASK_GET_INPUT_SCHEMA = z.object({\n id: z.string().min(1).describe('Task ID to retrieve')\n});\n\nconst TASK_LIST_INPUT_SCHEMA = z.object({\n statuses: z.array(z.enum(TASK_STATUSES)).optional().describe('Filter by statuses'),\n includeCompleted: z.boolean().optional().describe('Set false to hide completed tasks'),\n limit: z.number().int().positive().max(500).optional().describe('Maximum tasks to return')\n});\nconst TASK_TRACKING_SKILL: SkillInfo = {\n name: 'task-tracking-workflow',\n description: 'Track complex execution with task tools and proceed directly without confirmation unless the user explicitly asks for confirmation.',\n location: 'pulse-coder-engine/built-in/task-tracking-plugin',\n content: `# Task Tracking Workflow\n\n## When to use\n- The request has multiple phases or deliverables.\n- Work may span multiple tool calls or sessions.\n- You need explicit progress visibility and blocker management.\n\n## Execution autonomy\n- Default behavior: execute directly and call tools without asking for confirmation.\n- Only ask for confirmation when the user explicitly requires confirmation.\n- If critical information is missing, ask only the minimum clarifying question needed to continue.\n\n## Required flow\n1. Start by reviewing existing tasks with \\`task_list\\`.\n2. If no suitable tasks exist, create focused tasks with \\`task_create\\` (prefer batch mode).\n3. Keep exactly one primary task in \\`in_progress\\` where possible.\n4. Update status with \\`task_update\\` after meaningful progress.\n5. Mark blockers with \\`status=blocked\\` and a concrete \\`blockedReason\\`.\n6. Mark done tasks as \\`completed\\` and move to the next actionable item.\n\n## Quality rules\n- Keep tasks atomic and verifiable.\n- Avoid single oversized umbrella tasks.\n- Reuse existing in-progress tasks instead of duplicating.\n- Keep dependency links explicit when order matters.`\n};\n\nconst TASK_UPDATE_INPUT_SCHEMA = z.object({\n id: z.string().min(1).describe('Task ID to update'),\n title: z.string().min(1).optional().describe('New title'),\n details: z.string().optional().describe('New details'),\n status: z.enum(TASK_STATUSES).optional().describe('New status'),\n dependencies: z.array(z.string()).optional().describe('Replace dependencies with this list'),\n blockedReason: z.string().optional().describe('Blocked reason, used with status=blocked'),\n metadata: z.record(z.string(), z.any()).optional().describe('Replace metadata object'),\n delete: z.boolean().optional().describe('Delete this task')\n});\n\nfunction normalizeTaskListId(raw: string): string {\n const trimmed = raw.trim();\n if (!trimmed) {\n return 'default';\n }\n\n return trimmed.replace(/[^a-zA-Z0-9._-]/g, '-').slice(0, 120) || 'default';\n}\n\nfunction now(): number {\n return Date.now();\n}\n\n\nfunction dedupeStrings(values: string[] | undefined): string[] {\n if (!values?.length) {\n return [];\n }\n\n return Array.from(new Set(values.map((value) => String(value).trim()).filter(Boolean)));\n}\n\nexport class TaskListService {\n taskListId: string;\n storagePath: string;\n\n private readonly storageDir: string;\n private initialized = false;\n private createdAt = now();\n private updatedAt = now();\n private tasks = new Map<string, WorkTask>();\n\n constructor(\n taskListId: string = TaskListService.resolveTaskListId(),\n storageDir: string = TaskListService.resolveStorageDir()\n ) {\n const normalized = normalizeTaskListId(taskListId);\n\n this.storageDir = storageDir;\n this.taskListId = normalized;\n this.storagePath = path.join(this.storageDir, `${normalized}.json`);\n }\n\n static resolveTaskListId(): string {\n return process.env.PULSE_CODER_TASK_LIST_ID\n || process.env.CLAUDE_CODE_TASK_LIST_ID\n || 'default';\n }\n\n static resolveStorageDir(): string {\n return process.env.PULSE_CODER_TASKS_DIR\n || path.join(homedir(), '.pulse-coder', 'tasks');\n }\n\n async initialize(): Promise<void> {\n if (this.initialized) {\n return;\n }\n\n await this.loadTaskList(this.taskListId);\n }\n\n async setTaskListId(taskListId: string): Promise<{ switched: boolean; taskListId: string; storagePath: string }> {\n await this.initialize();\n\n const normalized = normalizeTaskListId(taskListId);\n if (normalized === this.taskListId) {\n return {\n switched: false,\n taskListId: this.taskListId,\n storagePath: this.storagePath\n };\n }\n\n await this.loadTaskList(normalized);\n\n return {\n switched: true,\n taskListId: this.taskListId,\n storagePath: this.storagePath\n };\n }\n\n async createTask(input: CreateTaskInput): Promise<WorkTask> {\n await this.initialize();\n\n const timestamp = now();\n const status = input.status ?? 'pending';\n\n const task: WorkTask = {\n id: randomUUID(),\n title: input.title.trim(),\n details: input.details,\n status,\n dependencies: dedupeStrings(input.dependencies),\n blockedReason: status === 'blocked' ? input.blockedReason ?? 'Blocked without reason' : undefined,\n metadata: input.metadata,\n createdAt: timestamp,\n updatedAt: timestamp,\n completedAt: status === 'completed' ? timestamp : undefined\n };\n\n this.tasks.set(task.id, task);\n this.updatedAt = timestamp;\n await this.persist();\n\n return task;\n }\n\n async createTasks(inputs: CreateTaskInput[]): Promise<WorkTask[]> {\n const created: WorkTask[] = [];\n for (const input of inputs) {\n created.push(await this.createTask(input));\n }\n return created;\n }\n\n async listTasks(options?: ListTaskOptions): Promise<WorkTask[]> {\n await this.initialize();\n\n const statuses = options?.statuses?.length ? new Set(options.statuses) : null;\n const includeCompleted = options?.includeCompleted ?? true;\n\n let tasks = Array.from(this.tasks.values()).filter((task) => {\n if (!includeCompleted && task.status === 'completed') {\n return false;\n }\n if (statuses && !statuses.has(task.status)) {\n return false;\n }\n return true;\n });\n\n tasks = tasks.sort((a, b) => a.createdAt - b.createdAt);\n\n if (options?.limit && options.limit > 0) {\n tasks = tasks.slice(0, options.limit);\n }\n\n return tasks;\n }\n\n async getTask(id: string): Promise<WorkTask | null> {\n await this.initialize();\n return this.tasks.get(id) ?? null;\n }\n\n async updateTask(input: UpdateTaskInput): Promise<WorkTask | null> {\n await this.initialize();\n\n if (input.delete) {\n const deleted = this.tasks.delete(input.id);\n if (!deleted) {\n return null;\n }\n\n this.updatedAt = now();\n await this.persist();\n return null;\n }\n\n const existing = this.tasks.get(input.id);\n if (!existing) {\n return null;\n }\n\n const timestamp = now();\n const nextStatus = input.status ?? existing.status;\n\n const next: WorkTask = {\n ...existing,\n title: input.title !== undefined ? input.title : existing.title,\n details: input.details !== undefined ? input.details : existing.details,\n status: nextStatus,\n dependencies: input.dependencies !== undefined ? dedupeStrings(input.dependencies) : existing.dependencies,\n metadata: input.metadata !== undefined ? input.metadata : existing.metadata,\n blockedReason: this.resolveBlockedReason(nextStatus, input.blockedReason, existing.blockedReason),\n updatedAt: timestamp,\n completedAt: nextStatus === 'completed'\n ? (existing.completedAt ?? timestamp)\n : undefined\n };\n\n this.tasks.set(input.id, next);\n this.updatedAt = timestamp;\n await this.persist();\n\n return next;\n }\n\n async snapshot(options?: ListTaskOptions): Promise<WorkTaskListSnapshot> {\n const tasks = await this.listTasks(options);\n\n return {\n taskListId: this.taskListId,\n storagePath: this.storagePath,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n total: tasks.length,\n tasks\n };\n }\n\n private resolveBlockedReason(status: TaskStatus, blockedReasonInput: string | undefined, previous?: string): string | undefined {\n if (status !== 'blocked') {\n return undefined;\n }\n\n if (blockedReasonInput !== undefined) {\n return blockedReasonInput || 'Blocked without reason';\n }\n\n return previous ?? 'Blocked without reason';\n }\n\n private async loadTaskList(taskListId: string): Promise<void> {\n const normalized = normalizeTaskListId(taskListId);\n\n this.taskListId = normalized;\n this.storagePath = path.join(this.storageDir, `${normalized}.json`);\n\n await fs.mkdir(this.storageDir, { recursive: true });\n\n try {\n const raw = await fs.readFile(this.storagePath, 'utf-8');\n const parsed = JSON.parse(raw) as Partial<TaskListStoreFile>;\n\n const parsedTasks = Array.isArray(parsed.tasks) ? parsed.tasks : [];\n this.tasks = new Map(parsedTasks.filter((task): task is WorkTask => !!task?.id).map((task) => [task.id, task]));\n this.createdAt = typeof parsed.createdAt === 'number' ? parsed.createdAt : now();\n this.updatedAt = typeof parsed.updatedAt === 'number' ? parsed.updatedAt : now();\n } catch (error: any) {\n if (error?.code !== 'ENOENT') {\n throw error;\n }\n\n const timestamp = now();\n this.tasks = new Map();\n this.createdAt = timestamp;\n this.updatedAt = timestamp;\n await this.persist();\n }\n\n this.initialized = true;\n }\n\n private async persist(): Promise<void> {\n const payload: TaskListStoreFile = {\n taskListId: this.taskListId,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n tasks: Array.from(this.tasks.values()).sort((a, b) => a.createdAt - b.createdAt)\n };\n\n await fs.writeFile(this.storagePath, JSON.stringify(payload, null, 2), 'utf-8');\n }\n}\n\nfunction buildTaskCreateTool(service: TaskListService): Tool {\n return {\n name: 'task_create',\n description: 'Create one or more tracked tasks for complex work. Use this when work has multiple steps, dependencies, or blockers.',\n inputSchema: TASK_CREATE_INPUT_SCHEMA,\n execute: async ({ tasks, title, details, status, dependencies, blockedReason, metadata }) => {\n const items: CreateTaskInput[] = tasks?.length\n ? tasks\n : [{ title: title!, details, status, dependencies, blockedReason, metadata }];\n\n const created = await service.createTasks(items);\n\n return {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n createdCount: created.length,\n tasks: created\n };\n }\n };\n}\n\nfunction buildTaskGetTool(service: TaskListService): Tool {\n return {\n name: 'task_get',\n description: 'Get full details for a single task by task ID.',\n inputSchema: TASK_GET_INPUT_SCHEMA,\n execute: async ({ id }) => {\n const task = await service.getTask(id);\n if (!task) {\n throw new Error(`Task not found: ${id}`);\n }\n\n return {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n task\n };\n }\n };\n}\n\nfunction buildTaskListTool(service: TaskListService): Tool {\n return {\n name: 'task_list',\n description: 'List tasks and their current status. Use this to check progress before and after major changes.',\n inputSchema: TASK_LIST_INPUT_SCHEMA,\n execute: async ({ statuses, includeCompleted, limit }) => {\n const snapshot = await service.snapshot({ statuses, includeCompleted, limit });\n const completed = snapshot.tasks.filter((task) => task.status === 'completed').length;\n const inProgress = snapshot.tasks.filter((task) => task.status === 'in_progress').length;\n const pending = snapshot.tasks.filter((task) => task.status === 'pending').length;\n const blocked = snapshot.tasks.filter((task) => task.status === 'blocked').length;\n\n return {\n ...snapshot,\n summary: {\n total: snapshot.total,\n completed,\n inProgress,\n pending,\n blocked\n }\n };\n }\n };\n}\n\n\n\nfunction buildTaskUpdateTool(service: TaskListService): Tool {\n return {\n name: 'task_update',\n description: 'Update task fields, move status (pending/in_progress/completed/blocked), or delete tasks.',\n inputSchema: TASK_UPDATE_INPUT_SCHEMA,\n execute: async (input) => {\n const task = await service.updateTask(input);\n\n if (input.delete) {\n return {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n deleted: true,\n id: input.id\n };\n }\n\n if (!task) {\n throw new Error(`Task not found: ${input.id}`);\n }\n\n return {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n deleted: false,\n task\n };\n }\n };\n}\n\nexport const builtInTaskTrackingPlugin: EnginePlugin = {\n name: 'pulse-coder-engine/built-in-task-tracking',\n version: '1.0.0',\n dependencies: ['pulse-coder-engine/built-in-skills'],\n\n async initialize(context: EnginePluginContext): Promise<void> {\n const service = new TaskListService();\n await service.initialize();\n\n context.registerService('taskListService', service);\n context.registerService('taskTracking', service);\n\n const skillRegistry = context.getService<BuiltInSkillRegistry>('skillRegistry');\n if (skillRegistry) {\n const registration = skillRegistry.registerSkill(TASK_TRACKING_SKILL);\n context.logger.info('[TaskTracking] Registered built-in task tracking skill', registration);\n } else {\n context.logger.warn('[TaskTracking] skillRegistry service unavailable; skipped task tracking skill registration');\n }\n\n context.registerTools({\n task_create: buildTaskCreateTool(service),\n task_get: buildTaskGetTool(service),\n task_list: buildTaskListTool(service),\n task_update: buildTaskUpdateTool(service)\n });\n\n context.logger.info('[TaskTracking] Registered task tools', {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n skillRegistryAvailable: !!skillRegistry\n });\n }\n};\n\nexport default builtInTaskTrackingPlugin;\n","import { z } from 'zod';\nimport { promises as fs } from 'fs';\nimport path from 'path';\nimport type { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\nimport type { Context } from '../../shared/types.js';\nimport { loop } from '../../core/loop';\nimport { BuiltinToolsMap } from '../../tools';\nimport { Tool } from 'ai';\n\ninterface AgentConfig {\n name: string;\n description: string;\n systemPrompt: string;\n filePath: string;\n}\n\nclass ConfigLoader {\n\n async getAgentFilesInfo(configDirs: string[]) {\n const fileInfos: Array<{ files: string[], configDir: string }> = [];\n for (let configDir of configDirs) {\n try {\n await fs.access(configDir);\n\n const files = await fs.readdir(configDir);\n fileInfos.push({ files, configDir });\n } catch {\n continue;\n }\n }\n\n return fileInfos;\n }\n\n async loadAgentConfigs(configDir: string | string[] = ['.pulse-coder/agents', '.coder/agents']): Promise<AgentConfig[]> {\n const configs: AgentConfig[] = [];\n\n const configDirs = Array.isArray(configDir) ? configDir : [configDir];\n\n try {\n const filesInfo = await this.getAgentFilesInfo(configDirs);\n\n for (const fileInfo of filesInfo) {\n const files = fileInfo.files;\n for (const file of files) {\n if (file.endsWith('.md')) {\n const config = await this.parseConfig(path.join(fileInfo.configDir, file));\n if (config) configs.push(config);\n }\n }\n }\n } catch (error) {\n console.warn(`Failed to scan agent configs: ${error}`);\n }\n\n return configs;\n }\n\n private async parseConfig(filePath: string): Promise<AgentConfig | null> {\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n const lines = content.split('\\n');\n\n let name = '';\n let description = '';\n let systemPrompt = '';\n let inFrontmatter = false;\n let frontmatterEnd = false;\n\n for (const line of lines) {\n if (line.trim() === '---') {\n if (!inFrontmatter) {\n inFrontmatter = true;\n continue;\n } else {\n frontmatterEnd = true;\n continue;\n }\n }\n\n if (inFrontmatter && !frontmatterEnd) {\n const match = line.match(/^\\s*(\\w+)\\s*:\\s*(.+)$/);\n if (match) {\n const [, key, value] = match;\n if (key === 'name') name = value.trim();\n if (key === 'description') description = value.trim();\n }\n } else if (frontmatterEnd) {\n systemPrompt += line + '\\n';\n }\n }\n\n if (!name) {\n name = path.basename(filePath, '.md');\n }\n\n return {\n name: name.trim(),\n description: description.trim(),\n systemPrompt: systemPrompt.trim(),\n filePath\n };\n } catch (error) {\n console.warn(`Failed to parse agent config ${filePath}: ${error}`);\n return null;\n }\n }\n}\n\nclass AgentRunner {\n async runAgent(\n config: AgentConfig,\n task: string,\n context?: Record<string, any>,\n tools?: Record<string, any>\n ): Promise<string> {\n const subContext: Context = {\n messages: [\n { role: 'user', content: task }\n ]\n };\n\n if (context && Object.keys(context).length > 0) {\n subContext.messages.push({\n role: 'user',\n content: `上下文信息:\\n${JSON.stringify(context, null, 2)}`\n });\n }\n\n return await loop(subContext, { tools, systemPrompt: config.systemPrompt });\n }\n}\n\nexport class SubAgentPlugin implements EnginePlugin {\n name = 'sub-agent';\n version = '1.0.0';\n\n private configLoader = new ConfigLoader();\n private agentRunner = new AgentRunner();\n\n async initialize(context: EnginePluginContext): Promise<void> {\n try {\n const configs = await this.configLoader.loadAgentConfigs();\n\n for (const config of configs) {\n this.registerAgentTool(context, config);\n }\n\n context.logger.info(`SubAgentPlugin loaded ${configs.length} agents.`);\n } catch (error) {\n context.logger.error('Failed to initialize SubAgentPlugin', error as Error);\n }\n }\n\n private registerAgentTool(\n context: EnginePluginContext,\n config: AgentConfig\n ): void {\n const toolName = `${config.name}_agent`;\n\n const tool: Tool = {\n description: config.description,\n inputSchema: z.object({\n task: z.string().describe('要执行的任务描述'),\n context: z.any().optional().describe('任务上下文信息')\n }),\n execute: async ({ task, context: taskContext }: { task: string; context?: Record<string, any> }) => {\n // 延迟求值:在工具真正被调用时合并 builtin 工具与所有已注册插件工具,\n // 避免初始化阶段的静态快照导致后注册的插件工具缺失。\n const tools = { ...BuiltinToolsMap, ...context.getTools() };\n try {\n context.logger.info(`Running agent ${config.name}: ${task}`);\n const result = await this.agentRunner.runAgent(config, task, taskContext, tools);\n context.logger.info(`Agent ${config.name} completed successfully`);\n return result;\n } catch (error) {\n context.logger.error(`Agent ${config.name} failed`, error as Error);\n throw new Error(`Agent ${config.name} failed: ${error}`);\n }\n }\n };\n\n context.registerTool(toolName, tool);\n }\n\n async destroy(context: EnginePluginContext): Promise<void> {\n context.logger.info('SubAgentPlugin destroyed');\n }\n}\n\nexport default SubAgentPlugin;","import { generateText, streamText, tool, type ModelMessage, type StepResult, type Tool } from 'ai';\nimport { CoderAI, DEFAULT_MODEL, COMPACT_SUMMARY_MAX_TOKENS, OPENAI_REASONING_EFFORT } from '../config';\nimport z from 'zod';\nimport { generateSystemPrompt } from '../prompt';\nimport type { Tool as CoderTool, ToolExecutionContext, LLMProviderFactory, SystemPromptOption } from '../shared/types';\n\n\nconst providerOptions = { openai: { store: false, reasoningEffort: OPENAI_REASONING_EFFORT } }\n\n/** Resolve a SystemPromptOption into a final string. */\nconst resolveSystemPrompt = (option: SystemPromptOption | undefined): string => {\n const base = generateSystemPrompt();\n if (!option) return base;\n if (typeof option === 'string') return option;\n if (typeof option === 'function') return option();\n return `${base}\\n\\n${option.append}`;\n};\n\nexport const generateTextAI = (\n messages: ModelMessage[],\n tools: Record<string, Tool>,\n options?: { provider?: LLMProviderFactory; model?: string; systemPrompt?: SystemPromptOption }\n) => {\n const provider = options?.provider ?? CoderAI;\n const model = options?.model ?? DEFAULT_MODEL;\n\n return generateText({\n model: provider(model),\n system: resolveSystemPrompt(options?.systemPrompt),\n messages,\n tools,\n providerOptions,\n }) as unknown as ReturnType<typeof generateText> & { steps: StepResult<any>[]; finishReason: string };\n}\n\nexport interface StreamOptions {\n abortSignal?: AbortSignal;\n onStepFinish?: (event: StepResult<any>) => void;\n onChunk?: (event: { chunk: any }) => void;\n toolExecutionContext?: ToolExecutionContext;\n /** Custom LLM provider. Falls back to the default CoderAI provider when not set. */\n provider?: LLMProviderFactory;\n /** Model name to pass to the provider. Falls back to DEFAULT_MODEL when not set. */\n model?: string;\n /** Custom system prompt. See SystemPromptOption for the three supported forms. */\n systemPrompt?: SystemPromptOption;\n}\n\n/**\n * Wraps tools to inject ToolExecutionContext before execution\n */\nexport const wrapToolsWithContext = (\n tools: Record<string, CoderTool>,\n context?: ToolExecutionContext\n): Record<string, Tool> => {\n const wrappedTools: Record<string, Tool> = {};\n\n for (const [name, tool] of Object.entries(tools)) {\n wrappedTools[name] = {\n ...tool,\n execute: async (input: any) => {\n // Call the original execute with context\n return await tool.execute(input, context);\n }\n } as Tool;\n }\n\n return wrappedTools;\n};\n\nexport const streamTextAI = (messages: ModelMessage[], tools: Record<string, CoderTool>, options?: StreamOptions) => {\n const provider = options?.provider ?? CoderAI;\n const model = options?.model ?? DEFAULT_MODEL;\n\n // Wrap tools with execution context if provided\n const wrappedTools = options?.toolExecutionContext\n ? wrapToolsWithContext(tools, options.toolExecutionContext)\n : tools;\n\n const finalSystemPrompt = resolveSystemPrompt(options?.systemPrompt);\n\n return streamText({\n model: provider(model),\n system: finalSystemPrompt,\n messages,\n tools: wrappedTools as Record<string, Tool>,\n providerOptions,\n abortSignal: options?.abortSignal,\n onStepFinish: options?.onStepFinish,\n onChunk: options?.onChunk,\n }) as unknown as ReturnType<typeof streamText> & { steps: StepResult<any>[]; finishReason: string };\n}\n\nexport const summarizeMessages = async (\n messages: ModelMessage[],\n options?: { maxOutputTokens?: number; provider?: LLMProviderFactory; model?: string }\n): Promise<string> => {\n const provider = options?.provider ?? CoderAI;\n const model = options?.model ?? DEFAULT_MODEL;\n const SUMMARY_SYSTEM_PROMPT =\n '你是负责压缩对话上下文的助手。请基于给定历史消息,提炼关键事实与决策,避免臆测或扩展。';\n\n const SUMMARY_USER_PROMPT = [\n '请将以上对话压缩为以下格式,使用中文:',\n '[COMPACTED_CONTEXT]',\n '- 目标: ...',\n '- 进展: ...',\n '- 关键结果: ...',\n '- 文件与变更: ...',\n '- 关键片段: \"...\" / `...` / \"...\"',\n '- 待确认: ...',\n '',\n '要求:内容简洁准确,不要编造。',\n ].join('\\n');\n\n const result = await generateText({\n model: provider(model),\n system: SUMMARY_SYSTEM_PROMPT,\n messages: [\n ...messages,\n { role: 'user', content: SUMMARY_USER_PROMPT },\n ],\n maxOutputTokens: options?.maxOutputTokens ?? COMPACT_SUMMARY_MAX_TOKENS,\n providerOptions,\n });\n\n return result.text ?? '';\n}","import dotenv from \"dotenv\";\nimport { createOpenAI } from '@ai-sdk/openai';\nimport { createAnthropic } from \"@ai-sdk/anthropic\";\nimport { LanguageModel } from \"ai\";\n\ndotenv.config();\n\nexport const CoderAI = (process.env.USE_ANTHROPIC\n ? createAnthropic({\n apiKey: process.env.ANTHROPIC_API_KEY || '',\n baseURL: process.env.ANTHROPIC_API_URL || 'https://api.anthropic.com/v1'\n })\n : createOpenAI({\n apiKey: process.env.OPENAI_API_KEY || '',\n baseURL: process.env.OPENAI_API_URL || 'https://api.openai.com/v1'\n }).responses) as (model: string) => LanguageModel;\n\nexport const DEFAULT_MODEL = process.env.ANTHROPIC_MODEL || process.env.OPENAI_MODEL || 'novita/deepseek/deepseek_v3';\n\nexport const MAX_TURNS = 100;\nexport const MAX_ERROR_COUNT = 3;\nexport const MAX_STEPS = 100;\nexport const MAX_TOOL_OUTPUT_LENGTH = 30_000;\n\nexport const CONTEXT_WINDOW_TOKENS = Number(process.env.CONTEXT_WINDOW_TOKENS ?? 64_000);\nexport const COMPACT_TRIGGER = Number(process.env.COMPACT_TRIGGER ?? Math.floor(CONTEXT_WINDOW_TOKENS * 0.75));\nexport const COMPACT_TARGET = Number(process.env.COMPACT_TARGET ?? Math.floor(CONTEXT_WINDOW_TOKENS * 0.5));\nexport const KEEP_LAST_TURNS = Number(process.env.KEEP_LAST_TURNS ?? 6);\nexport const COMPACT_SUMMARY_MAX_TOKENS = Number(process.env.COMPACT_SUMMARY_MAX_TOKENS ?? 1200);\nexport const MAX_COMPACTION_ATTEMPTS = Number(process.env.MAX_COMPACTION_ATTEMPTS ?? 2);\nexport const OPENAI_REASONING_EFFORT = process.env.OPENAI_REASONING_EFFORT;\n\n// Clarification settings\nexport const CLARIFICATION_TIMEOUT = Number(process.env.CLARIFICATION_TIMEOUT ?? 300_000); // 5 minutes\nexport const CLARIFICATION_ENABLED = process.env.CLARIFICATION_ENABLED !== 'false';","import fs from 'fs';\nimport path from 'path';\n\nconst DEFAULT_PROMPT = `\nYou are Pulse Coder, the best coding agent on the planet.\n\nYou are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\n\n## Editing constraints\n- Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.\n- Only add comments if they are necessary to make a non-obvious block easier to understand.\n- Try to use apply_patch for single file edits, but it is fine to explore other options to make the edit if it does not work well. Do not use apply_patch for changes that are auto-generated (i.e. generating package.json or running a lint or format command like gofmt) or when scripting is more efficient (such as search and replacing a string across a codebase).\n\n## Skills\n- If query matches an available skill's description or instruction [use skill], use the skill tool to get detailed instructions.\n- You should Load a skill to get detailed instructions for a specific task. It always is a complex task that requires multiple steps.\n- You should check the skill is complete and follow the step-by-step guidance. If the skill is not complete, you should ask the user for more information.\n\n## Tool usage\n- Prefer specialized tools over shell for file operations:\n - Use Read to view files, Edit to modify files, and Write only when needed.\n - Use Glob to find files by name and Grep to search file contents.\n- Use Bash for terminal operations (git, bun, builds, tests, running scripts).\n- Run tool calls in parallel when neither call needs the other’s output; otherwise run sequentially.\n\n## Execution discipline\n- If the user gives a clear execution command (for example: \"start\", \"run\", \"execute\", \"do it now\", \"开始执行\", \"直接执行\"), execute the relevant tool calls immediately when safe and feasible.\n- Do not reply with intent-only messages (for example: \"I will do it\", \"starting now\") when a tool call can be made right away.\n- Do not claim completion unless tool execution has actually happened.\n- If execution cannot proceed, state exactly what is blocked and ask one targeted question with a recommended default.\n- Only ask before execution when one of these is true:\n - A required value is missing and cannot be inferred safely.\n - The action is destructive, irreversible, or changes production/security/billing posture.\n - Credentials/authorization are required and unavailable.\n- After each execution step, report factual outcomes (success/failure, key output, and next action).\n\n## Git and workspace hygiene\n- You may be in a dirty git worktree.\n * NEVER revert existing changes you did not make unless explicitly requested, since these changes were made by the user.\n * If asked to make a commit or code edits and there are unrelated changes to your work or changes that you didn't make in those files, don't revert those changes.\n * If the changes are in files you've touched recently, you should read carefully and understand how you can work with the changes rather than reverting them.\n * If the changes are in unrelated files, just ignore them and don't revert them.\n- Do not amend commits unless explicitly requested.\n- **NEVER** use destructive commands like \\`git reset --hard\\` or \\`git checkout--\\` unless specifically requested or approved by the user.\n\n## Frontend tasks\nWhen doing frontend design tasks, avoid collapsing into bland, generic layouts.\nAim for interfaces that feel intentional and deliberate.\n- Typography: Use expressive, purposeful fonts and avoid default stacks (Inter, Roboto, Arial, system).\n- Color & Look: Choose a clear visual direction; define CSS variables; avoid purple-on-white defaults. No purple bias or dark mode bias.\n- Motion: Use a few meaningful animations (page-load, staggered reveals) instead of generic micro-motions.\n- Background: Don't rely on flat, single-color backgrounds; use gradients, shapes, or subtle patterns to build atmosphere.\n- Overall: Avoid boilerplate layouts and interchangeable UI patterns. Vary themes, type families, and visual languages across outputs.\n- Ensure the page loads properly on both desktop and mobile.\n\nException: If working within an existing website or design system, preserve the established patterns, structure, and visual language.\n\n## Presenting your work and final message\n\nYou are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.\n\n- Default: be very concise; friendly coding teammate tone.\n- Default: do the work without asking questions. Treat short tasks as sufficient direction; infer missing details by reading the codebase and following existing conventions.\n- Questions: only ask when you are truly blocked after checking relevant context AND you cannot safely pick a reasonable default. This usually means one of:\n * The request is ambiguous in a way that materially changes the result and you cannot disambiguate by reading the repo.\n * The action is destructive/irreversible, touches production, or changes billing/security posture.\n * You need a secret/credential/value that cannot be inferred (API key, account id, etc.).\n- If you must ask: do all non-blocked work first, then ask exactly one targeted question, include your recommended default, and state what would change based on the answer.\n- Never ask permission questions like \"Should I proceed?\" or \"Do you want me to run tests?\"; proceed with the most reasonable option and mention what you did.\n\n## Clarification Tool\n\nUse the 'clarify' tool when you genuinely need information from the user to proceed. This tool pauses execution and waits for user input.\n\n**When to use clarify:**\n- The request is ambiguous in a way that materially affects the implementation and cannot be resolved by reading the codebase\n- You cannot safely infer the answer from existing code, conventions, or context\n- You need confirmation before destructive or irreversible actions (e.g., deleting resources, modifying production data)\n- You need specific values that cannot be guessed (API keys, account IDs, specific user choices between valid alternatives)\n\n**When NOT to use clarify:**\n- For trivial decisions you can make based on codebase conventions or common practices\n- For permission questions like \"Should I proceed?\" (just proceed with the best option)\n- For information that's likely in the codebase, configuration files, or documentation (read those first)\n- Multiple times in a row - complete all non-blocked work first, then ask one clear question\n- For choices where a reasonable default exists (use the default and mention what you chose)\n\n**How to use clarify:**\n- Ask ONE clear, specific question per clarification\n- Provide context if needed to help the user understand the choice\n- Include a recommended default answer when applicable\n- Explain briefly what would change based on the answer\n\nExample usage: Call clarify with a question, optional context, and optional default answer. The tool will pause and wait for the user's response.\n- For substantial work, summarize clearly; follow final-answer formatting.\n- Skip heavy formatting for simple confirmations.\n- Don't dump large files you've written; reference paths only.\n- No \"save/copy this file\" - User is on the same machine.\n- Offer logical next steps (tests, commits, build) briefly; add verify steps if you couldn't do something.\n- For code changes:\n * Lead with a quick explanation of the change, and then give more details on the context covering where and why a change was made. Do not start this explanation with \"summary\", just jump right in.\n * If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps.\n * When suggesting multiple options, use numeric lists for the suggestions so the user can quickly respond with a single number.\n- The user does not command execution outputs. When asked to show the output of a command (e.g. \\`git show\\`), relay the important details in your answer or summarize the key lines so the user understands the result.\n\n## Final answer structure and style guidelines\n\n- Plain text; CLI handles styling. Use structure only when it helps scanability.\n- Headers: optional; short Title Case (1-3 words) wrapped in **...**; no blank line before the first bullet; add only if they truly help.\n- Bullets: use - ; merge related points; keep to one line when possible; 4-6 per list ordered by importance; keep phrasing consistent.\n- Monospace: backticks for commands/paths/env vars/code ids and inline examples; use for literal keyword bullets; never combine with **.\n- Code samples or multi-line snippets should be wrapped in fenced code blocks; include an info string as often as possible.\n- Structure: group related bullets; order sections general -> specific -> supporting; for subsections, start with a bolded keyword bullet, then items; match complexity to the task.\n- Tone: collaborative, concise, factual; present tense, active voice; self-contained; no \"above/below\"; parallel wording.\n- Don'ts: no nested bullets/hierarchies; no ANSI codes; don't cram unrelated keywords; keep keyword lists short-wrap/reformat if long; avoid naming formatting styles in answers.\n- Adaptation: code explanations -> precise, structured with code refs; simple tasks -> lead with outcome; big changes -> logical walkthrough + rationale + next actions; casual one-offs -> plain sentences, no headers/bullets.\n- File References: When referencing files in your response follow the below rules:\n * Use inline code to make file paths clickable.\n * Each reference should have a stand alone path. Even if it's the same file.\n * Accepted: absolute, workspace-relative, a/ or b/ diff prefixes, or bare filename/suffix.\n * Optionally include line/column (1-based): :line[:column] or #Lline[Ccolumn] (column defaults to 1).\n * Do not use URIs like file://, vscode://, or https://.\n * Do not provide range of lines\n * Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5\n\nHere is some useful information about the environment you are running in:\n<env>\n Working directory: ${process.cwd()}\n Platform: darwin\n Today's date: ${new Date().toLocaleDateString()}\n</env>\n<files>\n\n</files>`;\n\nconst AGENTS_FILE_REGEX = /^agents\\.md$/i;\n\nconst loadAgentsPrompt = () => {\n try {\n const cwd = process.cwd();\n const entries = fs.readdirSync(cwd, { withFileTypes: true });\n const target = entries.find((entry) => entry.isFile() && AGENTS_FILE_REGEX.test(entry.name));\n\n if (!target) {\n return null;\n }\n\n const filePath = path.join(cwd, target.name);\n const content = fs.readFileSync(filePath, 'utf8').trim();\n\n return content.length > 0 ? content : null;\n } catch {\n return null;\n }\n};\n\nexport const generateSystemPrompt = () => {\n return loadAgentsPrompt() ?? DEFAULT_PROMPT;\n};\n\nexport default generateSystemPrompt;\n","import { pruneMessages, type ModelMessage } from \"ai\";\nimport { summarizeMessages } from \"../ai\";\nimport {\n COMPACT_TRIGGER,\n COMPACT_TARGET,\n KEEP_LAST_TURNS,\n} from \"../config/index\";\nimport type { Context, LLMProviderFactory } from \"../shared/types\";\n\ntype CompactResult = {\n didCompact: boolean;\n reason?: string;\n newMessages?: ModelMessage[];\n};\n\nconst ensureSummaryPrefix = (summary: string): string => {\n const trimmed = summary.trim();\n if (trimmed.length === 0) {\n return '';\n }\n if (trimmed.startsWith('[COMPACTED_CONTEXT]')) {\n return trimmed;\n }\n return `[COMPACTED_CONTEXT]\\n${trimmed}`;\n};\n\nconst safeStringify = (value: unknown): string => {\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nconst estimateTokens = (messages: ModelMessage[]): number => {\n let totalChars = 0;\n for (const message of messages) {\n totalChars += message.role.length;\n if (typeof message.content === 'string') {\n totalChars += message.content.length;\n } else {\n totalChars += safeStringify(message.content).length;\n }\n }\n return Math.ceil(totalChars / 4);\n};\n\nconst splitByTurns = (messages: ModelMessage[], keepLastTurns: number) => {\n const userIndices: number[] = [];\n messages.forEach((message, index) => {\n if (message.role === 'user') {\n userIndices.push(index);\n }\n });\n\n if (userIndices.length <= keepLastTurns) {\n return { oldMessages: [], recentMessages: messages };\n }\n\n const cutIndex = userIndices[userIndices.length - keepLastTurns];\n return {\n oldMessages: messages.slice(0, cutIndex),\n recentMessages: messages.slice(cutIndex),\n };\n};\n\nconst takeLastTurns = (messages: ModelMessage[], keepLastTurns: number): ModelMessage[] => {\n const userIndices: number[] = [];\n messages.forEach((message, index) => {\n if (message.role === 'user') {\n userIndices.push(index);\n }\n });\n\n if (userIndices.length === 0) {\n return messages;\n }\n\n if (userIndices.length <= keepLastTurns) {\n return messages;\n }\n\n const startIndex = userIndices[userIndices.length - keepLastTurns];\n return messages.slice(startIndex);\n};\n\nexport const maybeCompactContext = async (\n context: Context,\n options?: { force?: boolean; provider?: LLMProviderFactory; model?: string }\n): Promise<CompactResult> => {\n const { messages } = context;\n if (messages.length === 0) {\n return { didCompact: false };\n }\n\n const estimatedTokens = estimateTokens(messages);\n if (!options?.force && estimatedTokens < COMPACT_TRIGGER) {\n return { didCompact: false };\n }\n\n const { oldMessages, recentMessages } = splitByTurns(messages, KEEP_LAST_TURNS);\n if (oldMessages.length === 0) {\n return { didCompact: false };\n }\n\n try {\n const summary = await summarizeMessages(oldMessages, {\n provider: options?.provider,\n model: options?.model,\n });\n const summaryText = ensureSummaryPrefix(summary);\n if (!summaryText) {\n throw new Error('Empty summary result');\n }\n\n const nextMessages: ModelMessage[] = [\n { role: 'assistant', content: summaryText },\n ...recentMessages,\n ];\n\n if (estimateTokens(nextMessages) > COMPACT_TARGET) {\n const newMessages = takeLastTurns(messages, KEEP_LAST_TURNS);\n return { didCompact: true, reason: 'summary-too-large', newMessages };\n }\n\n return { didCompact: true, newMessages: nextMessages };\n } catch (error) {\n const pruned = pruneMessages({\n messages,\n reasoning: 'all',\n toolCalls: 'all',\n emptyMessages: 'remove',\n });\n const newMessages = takeLastTurns(pruned, KEEP_LAST_TURNS);\n return { didCompact: true, reason: 'fallback', newMessages };\n }\n};","import { ToolSet, type StepResult, type ModelMessage } from \"ai\";\nimport type { Context, ClarificationRequest, Tool, LLMProviderFactory, SystemPromptOption } from \"../shared/types\";\nimport type { EngineHookMap } from \"../plugin/EnginePlugin.js\";\nimport { streamTextAI } from \"../ai\";\nimport { maybeCompactContext } from \"../context\";\nimport {\n MAX_COMPACTION_ATTEMPTS,\n MAX_ERROR_COUNT,\n MAX_STEPS\n} from \"../config/index.js\";\n\n/**\n * Hook arrays passed into the loop by Engine.\n * Each array may contain handlers from multiple plugins + EngineOptions.\n */\nexport interface LoopHooks {\n beforeLLMCall?: Array<EngineHookMap['beforeLLMCall']>;\n afterLLMCall?: Array<EngineHookMap['afterLLMCall']>;\n beforeToolCall?: Array<EngineHookMap['beforeToolCall']>;\n afterToolCall?: Array<EngineHookMap['afterToolCall']>;\n}\n\nexport interface LoopOptions {\n onText?: (delta: string) => void;\n onToolCall?: (toolCall: any) => void;\n onToolResult?: (toolResult: any) => void;\n onStepFinish?: (step: StepResult<any>) => void;\n onClarificationRequest?: (request: ClarificationRequest) => Promise<string>;\n onCompacted?: (newMessages: ModelMessage[]) => void;\n onResponse?: (messages: StepResult<ToolSet>['response']['messages']) => void;\n abortSignal?: AbortSignal;\n\n tools?: Record<string, Tool>;\n\n /** Custom LLM provider factory. Overrides the default provider when set. */\n provider?: LLMProviderFactory;\n /** Model name passed to the provider. Overrides DEFAULT_MODEL when set. */\n model?: string;\n /** Custom system prompt. See SystemPromptOption for the three supported forms. */\n systemPrompt?: SystemPromptOption;\n\n /** Engine hook arrays – managed by Engine, not by callers directly. */\n hooks?: LoopHooks;\n}\n\n/** Wraps tools so each execute() passes through beforeToolCall / afterToolCall hooks. */\nfunction wrapToolsWithHooks(\n tools: Record<string, Tool>,\n beforeHooks: Array<EngineHookMap['beforeToolCall']>,\n afterHooks: Array<EngineHookMap['afterToolCall']>,\n): Record<string, Tool> {\n const wrapped: Record<string, Tool> = {};\n for (const [name, t] of Object.entries(tools)) {\n wrapped[name] = {\n ...t,\n execute: async (input: any, ctx: any) => {\n // Run all beforeToolCall hooks sequentially\n let finalInput = input;\n for (const hook of beforeHooks) {\n const result = await hook({ name, input: finalInput });\n if (result && 'input' in result) {\n finalInput = result.input;\n }\n }\n\n const output = await t.execute(finalInput, ctx);\n\n // Run all afterToolCall hooks sequentially\n let finalOutput = output;\n for (const hook of afterHooks) {\n const result = await hook({ name, input: finalInput, output: finalOutput });\n if (result && 'output' in result) {\n finalOutput = result.output;\n }\n }\n\n return finalOutput;\n },\n };\n }\n return wrapped;\n}\n\nexport async function loop(context: Context, options?: LoopOptions): Promise<string> {\n let errorCount = 0;\n let totalSteps = 0;\n let compactionAttempts = 0;\n\n const loopHooks = options?.hooks ?? {};\n\n while (true) {\n try {\n if (compactionAttempts < MAX_COMPACTION_ATTEMPTS) {\n const { didCompact, newMessages } = await maybeCompactContext(context, {\n provider: options?.provider,\n model: options?.model,\n });\n if (didCompact) {\n compactionAttempts++;\n\n if (newMessages) {\n options?.onCompacted?.(newMessages)\n }\n continue;\n }\n }\n\n let tools = options?.tools || {};\n let systemPrompt = options?.systemPrompt;\n\n // --- beforeLLMCall hooks ---\n if (loopHooks.beforeLLMCall?.length) {\n for (const hook of loopHooks.beforeLLMCall) {\n const result = await hook({ context, systemPrompt, tools });\n if (result) {\n if ('systemPrompt' in result && result.systemPrompt !== undefined) {\n systemPrompt = result.systemPrompt;\n }\n if ('tools' in result && result.tools !== undefined) {\n tools = result.tools;\n }\n }\n }\n }\n\n // Wrap tools with beforeToolCall / afterToolCall hooks\n const beforeToolHooks = loopHooks.beforeToolCall ?? [];\n const afterToolHooks = loopHooks.afterToolCall ?? [];\n if (beforeToolHooks.length || afterToolHooks.length) {\n tools = wrapToolsWithHooks(tools, beforeToolHooks, afterToolHooks);\n }\n\n // Prepare tool execution context\n const toolExecutionContext = {\n onClarificationRequest: options?.onClarificationRequest,\n abortSignal: options?.abortSignal\n };\n\n const result = streamTextAI(context.messages, tools, {\n abortSignal: options?.abortSignal,\n toolExecutionContext,\n provider: options?.provider,\n model: options?.model,\n systemPrompt,\n onStepFinish: (step) => {\n options?.onStepFinish?.(step);\n },\n onChunk: ({ chunk }) => {\n if (chunk.type === 'text-delta') {\n options?.onText?.(chunk.text);\n }\n if (chunk.type === 'tool-call') {\n options?.onToolCall?.(chunk);\n }\n if (chunk.type === 'tool-result') {\n options?.onToolResult?.(chunk);\n }\n },\n });\n\n const [text, steps, finishReason] = await Promise.all([\n result.text,\n result.steps,\n result.finishReason,\n ]);\n\n totalSteps += steps.length;\n\n for (const step of steps) {\n if (step.response?.messages?.length) {\n const messages = [...step.response.messages];\n options?.onResponse?.(messages);\n }\n }\n\n // --- afterLLMCall hooks ---\n if (loopHooks.afterLLMCall?.length) {\n for (const hook of loopHooks.afterLLMCall) {\n await hook({ context, finishReason, text });\n }\n }\n\n if (finishReason === 'stop') {\n if (!text) {\n continue;\n }\n return text || 'Task completed.';\n }\n\n if (finishReason === 'length') {\n if (compactionAttempts < MAX_COMPACTION_ATTEMPTS) {\n const { didCompact, newMessages } = await maybeCompactContext(context, {\n force: true,\n provider: options?.provider,\n model: options?.model,\n });\n if (didCompact) {\n compactionAttempts++;\n if (newMessages) {\n options?.onCompacted?.(newMessages)\n }\n continue;\n }\n }\n return text || 'Context limit reached.';\n }\n\n if (finishReason === 'content-filter') {\n return text || 'Content filtered.';\n }\n\n if (finishReason === 'error') {\n return text || 'Task failed.';\n }\n\n if (finishReason === 'tool-calls') {\n if (totalSteps >= MAX_STEPS) {\n return text || 'Max steps reached, task may be incomplete.';\n }\n continue;\n }\n\n if (!text) {\n continue;\n }\n\n return text || 'Task completed.';\n } catch (error: any) {\n if (options?.abortSignal?.aborted || error?.name === 'AbortError') {\n return 'Request aborted.';\n }\n\n errorCount++;\n if (errorCount >= MAX_ERROR_COUNT) {\n return `Failed after ${errorCount} errors: ${error?.message ?? String(error)}`;\n }\n\n if (isRetryableError(error)) {\n const delay = Math.min(2000 * Math.pow(2, errorCount - 1), 30000);\n await sleep(delay);\n continue;\n }\n\n return `Error: ${error?.message ?? String(error)}`;\n }\n }\n}\n\nfunction isRetryableError(error: any): boolean {\n const status = error?.status ?? error?.statusCode;\n return status === 429 || status === 500 || status === 502 || status === 503;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import z from \"zod\";\nimport { readFileSync, existsSync, statSync } from \"fs\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const ReadTool: Tool<\n { filePath: string; offset?: number; limit?: number },\n { content: string; totalLines?: number }\n> = {\n name: 'read',\n description: 'Read the contents of a file. Supports reading specific line ranges with offset and limit.',\n inputSchema: z.object({\n filePath: z.string().describe('The absolute path to the file to read'),\n offset: z.number().optional().describe('The line number to start reading from (0-based). Only provide if the file is too large to read at once.'),\n limit: z.number().optional().describe('The number of lines to read. Only provide if the file is too large to read at once.'),\n }),\n execute: async ({ filePath, offset, limit }) => {\n // Check if file exists\n if (!existsSync(filePath)) {\n throw new Error(`File does not exist: ${filePath}`);\n }\n\n // Check if it's a directory\n const stats = statSync(filePath);\n if (stats.isDirectory()) {\n throw new Error(`Cannot read directory: ${filePath}. Use 'ls' tool to list directory contents.`);\n }\n\n // Read the entire file\n const content = readFileSync(filePath, 'utf-8');\n const lines = content.split('\\n');\n const totalLines = lines.length;\n\n // If no offset/limit specified, return the entire file\n if (offset === undefined && limit === undefined) {\n return {\n content: truncateOutput(content),\n totalLines,\n };\n }\n\n // Apply offset and limit\n const startLine = offset || 0;\n const endLine = limit ? startLine + limit : lines.length;\n\n // Validate range\n if (startLine < 0 || startLine >= totalLines) {\n throw new Error(`Invalid offset: ${startLine}. File has ${totalLines} lines.`);\n }\n\n // Extract the requested lines\n const selectedLines = lines.slice(startLine, endLine);\n\n // Format with line numbers (1-based for display)\n const numberedContent = selectedLines\n .map((line, idx) => {\n const lineNum = startLine + idx + 1;\n return `${String(lineNum).padStart(6, ' ')}→${line}`;\n })\n .join('\\n');\n\n return {\n content: truncateOutput(numberedContent),\n totalLines,\n };\n },\n};\n\nexport default ReadTool;\n","import { MAX_TOOL_OUTPUT_LENGTH } from \"../config\";\n\nexport const truncateOutput = (output: string): string => {\n if (output.length <= MAX_TOOL_OUTPUT_LENGTH) {\n return output;\n }\n\n const half = Math.floor(MAX_TOOL_OUTPUT_LENGTH / 2);\n const removed = output.length - MAX_TOOL_OUTPUT_LENGTH;\n\n return (\n output.slice(0, half) +\n `\\n\\n... [truncated ${removed} characters] ...\\n\\n` +\n output.slice(-half)\n );\n};\n","import z from \"zod\";\nimport { writeFileSync, mkdirSync, existsSync } from \"fs\";\nimport { dirname } from \"path\";\nimport type { Tool } from \"../shared/types\";\n\nexport const WriteTool: Tool<\n { filePath: string; content: string },\n { success: boolean; created: boolean; bytes: number }\n> = {\n name: 'write',\n description: 'Write contents to a file. Automatically creates parent directories if they do not exist. Will overwrite existing files.',\n inputSchema: z.object({\n filePath: z.string().describe('The absolute path to the file to write (must be absolute, not relative)'),\n content: z.string().describe('The content to write to the file'),\n }),\n execute: async ({ filePath, content }) => {\n // Check if file already exists\n const fileExists = existsSync(filePath);\n\n // Get the directory path\n const dir = dirname(filePath);\n\n // Create parent directories if they don't exist\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n\n // Write the file\n writeFileSync(filePath, content, 'utf-8');\n\n // Calculate bytes written\n const bytes = Buffer.byteLength(content, 'utf-8');\n\n return {\n success: true,\n created: !fileExists,\n bytes,\n };\n },\n};\n\nexport default WriteTool;\n","import z from \"zod\";\nimport { readFileSync, writeFileSync } from \"fs\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const EditTool: Tool<\n { filePath: string; oldString: string; newString: string; replaceAll?: boolean },\n { success: boolean; replacements: number; preview?: string }\n> = {\n name: 'edit',\n description: 'Performs exact string replacements in files. Use this to edit existing files by replacing old_string with new_string.',\n inputSchema: z.object({\n filePath: z.string().describe('The absolute path to the file to modify'),\n oldString: z.string().describe('The exact text to replace (must match exactly)'),\n newString: z.string().describe('The text to replace it with (must be different from old_string)'),\n replaceAll: z.boolean().optional().default(false).describe('Replace all occurrences of old_string (default false)'),\n }),\n execute: async ({ filePath, oldString, newString, replaceAll = false }) => {\n // Validate that old and new strings are different\n if (oldString === newString) {\n throw new Error('old_string and new_string must be different');\n }\n\n // Read the file\n const content = readFileSync(filePath, 'utf-8');\n\n // Check if oldString exists in the file\n if (!content.includes(oldString)) {\n throw new Error(`old_string not found in file: ${filePath}`);\n }\n\n let newContent: string;\n let replacements = 0;\n\n if (replaceAll) {\n // Replace all occurrences\n const parts = content.split(oldString);\n replacements = parts.length - 1;\n newContent = parts.join(newString);\n } else {\n // Replace only the first occurrence\n const index = content.indexOf(oldString);\n if (index === -1) {\n throw new Error(`old_string not found in file: ${filePath}`);\n }\n\n // Check if the string is unique (appears only once)\n const secondIndex = content.indexOf(oldString, index + oldString.length);\n if (secondIndex !== -1) {\n throw new Error(\n 'old_string is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use replace_all to change every instance.'\n );\n }\n\n newContent = content.slice(0, index) + newString + content.slice(index + oldString.length);\n replacements = 1;\n }\n\n // Write the modified content back\n writeFileSync(filePath, newContent, 'utf-8');\n\n // Generate a preview of the changes (show the changed section with context)\n const changedIndex = newContent.indexOf(newString);\n const contextLength = 200;\n const start = Math.max(0, changedIndex - contextLength);\n const end = Math.min(newContent.length, changedIndex + newString.length + contextLength);\n const preview = truncateOutput(\n `...${newContent.slice(start, end)}...`\n );\n\n return {\n success: true,\n replacements,\n preview,\n };\n },\n};\n\nexport default EditTool;\n","import z from \"zod\";\nimport { execSync } from \"child_process\";\nimport { existsSync } from \"fs\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const GrepTool: Tool<\n {\n pattern: string;\n path?: string;\n glob?: string;\n type?: string;\n outputMode?: 'content' | 'files_with_matches' | 'count';\n context?: number;\n caseInsensitive?: boolean;\n headLimit?: number;\n offset?: number;\n multiline?: boolean;\n },\n { output: string; matches?: number }\n> = {\n name: 'grep',\n description: 'A powerful search tool built on ripgrep. Supports regex patterns, file filtering, and multiple output modes.',\n inputSchema: z.object({\n pattern: z.string().describe('The regular expression pattern to search for in file contents'),\n path: z.string().optional().describe('File or directory to search in. Defaults to current working directory.'),\n glob: z.string().optional().describe('Glob pattern to filter files (e.g. \"*.js\", \"*.{ts,tsx}\")'),\n type: z.string().optional().describe('File type to search (e.g., js, py, rust, go, java, ts, tsx, json, md)'),\n outputMode: z.enum(['content', 'files_with_matches', 'count']).optional().default('files_with_matches')\n .describe('Output mode: \"content\" shows matching lines, \"files_with_matches\" shows file paths, \"count\" shows match counts'),\n context: z.number().optional().describe('Number of lines to show before and after each match (only with output_mode: \"content\")'),\n caseInsensitive: z.boolean().optional().default(false).describe('Case insensitive search'),\n headLimit: z.number().optional().default(0).describe('Limit output to first N lines/entries. 0 means unlimited.'),\n offset: z.number().optional().default(0).describe('Skip first N lines/entries before applying head_limit'),\n multiline: z.boolean().optional().default(false).describe('Enable multiline mode where patterns can span lines'),\n }),\n execute: async ({\n pattern,\n path = '.',\n glob,\n type,\n outputMode = 'files_with_matches',\n context,\n caseInsensitive = false,\n headLimit = 0,\n offset = 0,\n multiline = false,\n }) => {\n // Build ripgrep command\n const args: string[] = ['rg'];\n\n // Pattern\n args.push(pattern);\n\n // Case sensitivity\n if (caseInsensitive) {\n args.push('-i');\n }\n\n // Output mode\n if (outputMode === 'files_with_matches') {\n args.push('-l'); // --files-with-matches\n } else if (outputMode === 'count') {\n args.push('-c'); // --count\n } else if (outputMode === 'content') {\n args.push('-n'); // Show line numbers\n if (context !== undefined) {\n args.push(`-C${context}`);\n }\n }\n\n // Multiline mode\n if (multiline) {\n args.push('-U'); // --multiline\n args.push('--multiline-dotall');\n }\n\n // File filtering\n if (glob) {\n args.push('--glob', glob);\n }\n if (type) {\n args.push('--type', type);\n }\n\n // Path\n if (path && path !== '.') {\n // Verify path exists\n if (!existsSync(path)) {\n throw new Error(`Path does not exist: ${path}`);\n }\n args.push(path);\n }\n\n // Build the command string\n let command = args.map(arg => {\n // Quote arguments that contain spaces or special characters\n if (arg.includes(' ') || arg.includes('$') || arg.includes('*')) {\n return `'${arg.replace(/'/g, \"'\\\\''\")}'`;\n }\n return arg;\n }).join(' ');\n\n // Add tail/head for offset/limit\n if (offset > 0) {\n command += ` | tail -n +${offset + 1}`;\n }\n if (headLimit > 0) {\n command += ` | head -n ${headLimit}`;\n }\n\n try {\n const output = execSync(command, {\n encoding: 'utf-8',\n maxBuffer: 1024 * 1024 * 10, // 10MB\n shell: '/bin/bash',\n });\n\n // Count matches for count mode\n let matches: number | undefined;\n if (outputMode === 'count') {\n matches = output.split('\\n').filter(line => line.trim()).length;\n } else if (outputMode === 'files_with_matches') {\n matches = output.split('\\n').filter(line => line.trim()).length;\n }\n\n return {\n output: truncateOutput(output || '(no matches found)'),\n matches,\n };\n } catch (error: any) {\n // Exit code 1 means no matches found (not an error)\n if (error.status === 1) {\n return {\n output: '(no matches found)',\n matches: 0,\n };\n }\n\n // Other errors\n throw new Error(\n `grep failed: ${error.stderr || error.message}\\nCommand: ${command}`\n );\n }\n },\n};\n\nexport default GrepTool;\n","import z from \"zod\";\nimport { readdirSync } from \"fs\";\nimport type { Tool } from \"../shared/types\";\n\nexport const LsTool: Tool<\n { path?: string },\n { files: string[] }\n> = {\n name: 'ls',\n description: 'List files and directories in a given path',\n inputSchema: z.object({\n path: z.string().optional().describe('The path to list files from (defaults to current directory)'),\n }),\n execute: async ({ path = '.' }) => {\n const files = readdirSync(path);\n return { files };\n },\n};\n\nexport default LsTool;\n","import z from \"zod\";\nimport { execSync } from \"child_process\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const BashTool: Tool<\n { command: string; timeout?: number; cwd?: string; description?: string },\n { output: string; error?: string; exitCode?: number }\n> = {\n name: 'bash',\n description: 'Execute a bash command and return the output. Supports timeout and working directory configuration.',\n inputSchema: z.object({\n command: z.string().describe('The bash command to execute'),\n timeout: z.number().optional().describe('Optional timeout in milliseconds (max 600000ms / 10 minutes). Defaults to 120000ms (2 minutes).'),\n cwd: z.string().optional().describe('Optional working directory for command execution. Defaults to current directory.'),\n description: z.string().optional().describe('Optional description of what this command does (for logging/debugging)'),\n }),\n execute: async ({ command, timeout = 120000, cwd, description }) => {\n // Validate timeout\n if (timeout && (timeout < 0 || timeout > 600000)) {\n throw new Error('Timeout must be between 0 and 600000ms (10 minutes)');\n }\n\n try {\n const output = execSync(command, {\n encoding: 'utf-8',\n maxBuffer: 1024 * 1024 * 10, // 10MB\n timeout: timeout || 120000,\n cwd: cwd || process.cwd(),\n shell: '/bin/bash',\n });\n return {\n output: truncateOutput(output || '(command completed with no output)'),\n exitCode: 0,\n };\n } catch (error: any) {\n const exitCode = error.status || error.code || 1;\n const stdout = String(error.stdout || '');\n const stderr = String(error.stderr || error.message || '');\n\n // Check if it's a timeout error\n if (error.killed && error.signal === 'SIGTERM') {\n return {\n output: truncateOutput(stdout),\n error: truncateOutput(`Command timed out after ${timeout}ms\\n${stderr}`),\n exitCode,\n };\n }\n\n return {\n output: truncateOutput(stdout),\n error: truncateOutput(stderr),\n exitCode,\n };\n }\n },\n};\n\nexport default BashTool;\n","import z from \"zod\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const TavilyTool: Tool<\n { query: string; maxResults?: number },\n { results: Array<{ title: string; url: string; content: string; score?: number }> }\n> = {\n name: 'tavily',\n description: 'Search the web using Tavily API',\n inputSchema: z.object({\n query: z.string().describe('The search query'),\n maxResults: z.number().optional().default(5).describe('Maximum number of results to return'),\n }),\n execute: async ({ query, maxResults = 5 }) => {\n const apiKey = process.env.TAVILY_API_KEY;\n\n if (!apiKey) {\n throw new Error('TAVILY_API_KEY environment variable is not set');\n }\n\n const response = await fetch('https://api.tavily.com/search', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n api_key: apiKey,\n query,\n max_results: maxResults,\n search_depth: 'basic',\n include_answer: false,\n include_raw_content: false,\n include_images: false,\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Tavily API error: ${response.status} ${response.statusText}`);\n }\n\n const data = await response.json();\n\n return {\n results: data.results?.map((result: any) => ({\n title: result.title || '',\n url: result.url || '',\n content: truncateOutput(result.content || ''),\n score: result.score || 0,\n })) || [],\n };\n },\n};\n\nexport default TavilyTool;\n","import z from \"zod\";\nimport type { Tool, ToolExecutionContext } from \"../shared/types\";\nimport { CLARIFICATION_TIMEOUT } from \"../config/index.js\";\nimport { randomUUID } from \"crypto\";\n\nexport interface ClarifyInput {\n question: string;\n context?: string;\n defaultAnswer?: string;\n timeout?: number;\n}\n\nexport interface ClarifyOutput {\n answer: string;\n timedOut: boolean;\n}\n\nexport const ClarifyTool: Tool<ClarifyInput, ClarifyOutput> = {\n name: 'clarify',\n description: 'Ask the user a clarifying question and wait for their response. Use this when you need information from the user to proceed with the task.',\n inputSchema: z.object({\n question: z.string().describe('The question to ask the user'),\n context: z.string().optional().describe('Additional context to help the user answer'),\n defaultAnswer: z.string().optional().describe('Default answer if user does not respond within timeout'),\n timeout: z.number().optional().describe('Timeout in milliseconds (default: 5 minutes)')\n }),\n execute: async (input, toolContext) => {\n if (!toolContext?.onClarificationRequest) {\n throw new Error('Clarification is not supported in this context. The clarify tool requires a CLI interface with user interaction.');\n }\n\n const timeout = input.timeout ?? CLARIFICATION_TIMEOUT;\n const requestId = randomUUID();\n\n try {\n // Create a promise that rejects on timeout\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => {\n reject(new Error(`Clarification request timed out after ${timeout}ms`));\n }, timeout);\n });\n\n // Race between user response and timeout\n const answer = await Promise.race([\n toolContext.onClarificationRequest({\n id: requestId,\n question: input.question,\n context: input.context,\n defaultAnswer: input.defaultAnswer,\n timeout\n }),\n timeoutPromise\n ]);\n\n return {\n answer,\n timedOut: false\n };\n } catch (error: any) {\n // If timeout occurred and we have a default answer, use it\n if (error?.message?.includes('timed out') && input.defaultAnswer) {\n return {\n answer: input.defaultAnswer,\n timedOut: true\n };\n }\n\n // Otherwise, re-throw the error\n throw error;\n }\n },\n};\n\nexport default ClarifyTool;\n","import { ReadTool } from './read';\nimport { WriteTool } from './write';\nimport { EditTool } from './edit';\nimport { GrepTool } from './grep';\nimport { LsTool } from './ls';\nimport { BashTool } from './bash';\nimport { TavilyTool } from './tavily';\nimport { ClarifyTool } from './clarify';\nimport { Tool } from 'ai';\n// import { SkillTool } from './skill;\n\nexport const BuiltinTools = [\n ReadTool,\n WriteTool,\n EditTool,\n GrepTool,\n LsTool,\n BashTool,\n TavilyTool,\n ClarifyTool,\n] as const;\n\nexport const BuiltinToolsMap = BuiltinTools.reduce((acc, toolInstance) => {\n acc[toolInstance.name] = toolInstance;\n return acc;\n}, {} as Record<string, any>);\n\nexport const getFinalToolsMap = (customTools?: Record<string, Tool>) => {\n if (!customTools) {\n return BuiltinToolsMap;\n }\n return { ...BuiltinToolsMap, ...customTools };\n};\n\nexport {\n ReadTool,\n WriteTool,\n EditTool,\n GrepTool,\n LsTool,\n BashTool,\n TavilyTool,\n ClarifyTool,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,iBAAgC;AAChC,gBAAyC;AACzC,WAAsB;AAMtB,eAAsB,cAAc,KAAuC;AAEzE,QAAM,gBAAqB,UAAK,KAAK,gBAAgB,UAAU;AAC/D,QAAM,mBAAwB,UAAK,KAAK,UAAU,UAAU;AAC5D,QAAM,iBAAa,sBAAW,aAAa,IAAI,gBAAgB;AAE/D,MAAI,KAAC,sBAAW,UAAU,GAAG;AAC3B,WAAO,EAAE,SAAS,CAAC,EAAE;AAAA,EACvB;AAEA,MAAI;AACF,UAAM,cAAU,wBAAa,YAAY,OAAO;AAChD,UAAM,SAAS,KAAK,MAAM,OAAO;AAEjC,QAAI,CAAC,OAAO,WAAW,OAAO,OAAO,YAAY,UAAU;AACzD,cAAQ,KAAK,gDAAgD;AAC7D,aAAO,EAA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d,kBAAQ,OAAO,MAAM,SAAS,OAAO,IAAI,WAAW,KAAc;AAClE,gBAAM,IAAI,MAAM,SAAS,OAAO,IAAI,YAAY,KAAK,EAAE;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAEA,YAAQ,aAAa,UAAUA,KAAI;AAAA,EACrC;AAAA,EAEA,MAAM,QAAQ,SAA6C;AACzD,YAAQ,OAAO,KAAK,0BAA0B;AAAA,EAChD;AACF;;;AL7KO,IAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,IAAI,eAAe;AACrB;AAwBA,IAAO,mBAAQ;","names":["tool","import_fs","matter","import_fs","import_os","import_zod","path","fs","import_zod","import_fs","import_path","dotenv","import_fs","import_path","fs","path","tool","import_ai","result","import_zod","import_fs","z","import_zod","import_fs","import_path","z","import_zod","import_fs","z","import_zod","import_fs","z","path","import_zod","import_fs","z","path","import_zod","import_child_process","z","import_zod","z","import_zod","import_crypto","z","fs","path","tool"]}
|
|
1
|
+
{"version":3,"sources":["../../src/built-in/index.ts","../../src/built-in/mcp-plugin/index.ts","../../src/built-in/skills-plugin/index.ts","../../src/built-in/plan-mode-plugin/index.ts","../../src/built-in/task-tracking-plugin/index.ts","../../src/built-in/sub-agent-plugin/index.ts","../../src/ai/index.ts","../../src/config/index.ts","../../src/prompt/system.ts","../../src/context/index.ts","../../src/core/loop.ts","../../src/tools/read.ts","../../src/tools/utils.ts","../../src/tools/write.ts","../../src/tools/edit.ts","../../src/tools/grep.ts","../../src/tools/ls.ts","../../src/tools/bash.ts","../../src/tools/tavily.ts","../../src/tools/clarify.ts","../../src/tools/index.ts"],"sourcesContent":["/**\n * Built-in plugins for Pulse Coder Engine\n * 引擎内置插件集合\n */\n\nimport { builtInMCPPlugin } from './mcp-plugin';\nimport { builtInSkillsPlugin } from './skills-plugin';\nimport { builtInPlanModePlugin } from './plan-mode-plugin';\nimport { builtInTaskTrackingPlugin } from './task-tracking-plugin';\nimport { SubAgentPlugin } from './sub-agent-plugin';\n\n/**\n * 默认内置插件列表\n * 这些插件会在引擎启动时自动加载\n */\nexport const builtInPlugins = [\n builtInMCPPlugin,\n builtInSkillsPlugin,\n builtInPlanModePlugin,\n builtInTaskTrackingPlugin,\n new SubAgentPlugin()\n];\n\n/**\n * 单独导出各个内置插件,便于外部使用\n */\nexport { builtInMCPPlugin } from './mcp-plugin';\nexport { builtInSkillsPlugin, BuiltInSkillRegistry } from './skills-plugin';\nexport { builtInPlanModePlugin, BuiltInPlanModeService } from './plan-mode-plugin';\nexport { builtInTaskTrackingPlugin, TaskListService } from './task-tracking-plugin';\nexport type { TaskStatus, WorkTask, WorkTaskListSnapshot } from './task-tracking-plugin';\nexport type {\n PlanMode,\n PlanIntentLabel,\n ToolCategory,\n ToolRisk,\n ToolMeta,\n ModePolicy,\n PlanModeEvent,\n PlanModeEventName,\n PlanModeTransitionResult,\n PlanModeService\n} from './plan-mode-plugin';\nexport { SubAgentPlugin } from './sub-agent-plugin';\n\nexport default builtInPlugins;","/**\n * Built-in MCP Plugin for Pulse Coder Engine\n * 将 MCP 功能作为引擎内置插件\n */\n\nimport { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\nimport { createMCPClient } from '@ai-sdk/mcp';\nimport { existsSync, readFileSync } from 'fs';\nimport * as path from 'path';\n\nexport interface MCPPluginConfig {\n servers: Record<string, { url: string }>;\n}\n\nexport async function loadMCPConfig(cwd: string): Promise<MCPPluginConfig> {\n // 优先读取 .pulse-coder/mcp.json,兼容旧版 .coder/mcp.json\n const newConfigPath = path.join(cwd, '.pulse-coder', 'mcp.json');\n const legacyConfigPath = path.join(cwd, '.coder', 'mcp.json');\n const configPath = existsSync(newConfigPath) ? newConfigPath : legacyConfigPath;\n\n if (!existsSync(configPath)) {\n return { servers: {} };\n }\n\n try {\n const content = readFileSync(configPath, 'utf-8');\n const parsed = JSON.parse(content);\n\n if (!parsed.servers || typeof parsed.servers !== 'object') {\n console.warn('[MCP] Invalid config: missing \"servers\" object');\n return { servers: {} };\n }\n\n return { servers: parsed.servers };\n } catch (error) {\n console.warn(`[MCP] Failed to load config: ${error instanceof Error ? error.message : 'Unknown error'}`);\n return { servers: {} };\n }\n}\n\nfunction createHTTPTransport(config: { url: string }) {\n return {\n type: 'http' as const,\n url: config.url\n };\n}\n\nexport const builtInMCPPlugin: EnginePlugin = {\n name: 'pulse-coder-engine/built-in-mcp',\n version: '1.0.0',\n\n async initialize(context: EnginePluginContext) {\n const config = await loadMCPConfig(process.cwd());\n\n const serverCount = Object.keys(config.servers).length;\n if (serverCount === 0) {\n console.log('[MCP] No MCP servers configured');\n return;\n }\n\n let loadedCount = 0;\n\n for (const [serverName, serverConfig] of Object.entries(config.servers)) {\n try {\n if (!serverConfig.url) {\n console.warn(`[MCP] Server \"${serverName}\" missing URL, skipping`);\n continue;\n }\n\n const transport = createHTTPTransport(serverConfig);\n const client = await createMCPClient({ transport });\n\n const tools = await client.tools();\n\n // 注册工具到引擎,使用命名空间前缀\n const namespacedTools = Object.fromEntries(\n Object.entries(tools).map(([toolName, tool]) => [\n `mcp_${serverName}_${toolName}`,\n tool as any\n ])\n );\n\n context.registerTools(namespacedTools);\n\n loadedCount++;\n console.log(`[MCP] Server \"${serverName}\" loaded (${Object.keys(tools).length} tools)`);\n\n // 注册服务供其他插件使用\n context.registerService(`mcp:${serverName}`, client);\n\n } catch (error) {\n console.warn(`[MCP] Failed to load server \"${serverName}\": ${error instanceof Error ? error.message : 'Unknown error'}`);\n }\n }\n\n if (loadedCount > 0) {\n console.log(`[MCP] Successfully loaded ${loadedCount}/${serverCount} MCP servers`);\n } else {\n console.warn('[MCP] No MCP servers were loaded successfully');\n }\n }\n};\n\nexport default builtInMCPPlugin;","/**\n * Built-in Skills Plugin for Pulse Coder Engine\n * 将技能系统作为引擎内置插件\n */\n\nimport { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\nimport { Tool } from '../../shared/types';\nimport { readFileSync } from 'fs';\nimport { globSync } from 'glob';\nimport matter from 'gray-matter';\nimport { homedir } from 'os';\nimport { z } from 'zod';\n\n/**\n * 技能信息接口\n */\nexport interface SkillInfo {\n name: string;\n description: string;\n location: string;\n content: string;\n metadata?: Record<string, any>;\n}\n\n/**\n * 技能注册表\n */\nexport class BuiltInSkillRegistry {\n private skills: Map<string, SkillInfo> = new Map();\n private initialized = false;\n\n /**\n * 初始化注册表,扫描并加载所有技能\n */\n async initialize(cwd: string): Promise<void> {\n if (this.initialized) {\n console.warn('SkillRegistry already initialized');\n return;\n }\n\n console.log('Scanning built-in skills...');\n const skillList = await this.scanSkills(cwd);\n\n this.skills.clear();\n for (const skill of skillList) {\n this.skills.set(skill.name, skill);\n }\n\n this.initialized = true;\n console.log(`Loaded ${this.skills.size} built-in skill(s)`);\n }\n\n /**\n * 扫描技能文件\n */\n private async scanSkills(cwd: string): Promise<SkillInfo[]> {\n const skills: SkillInfo[] = [];\n\n const scanPaths = [\n // 项目级技能(优先 .pulse-coder,兼容旧版 .coder 和 .claude)\n { base: cwd, pattern: '.pulse-coder/skills/**/SKILL.md' },\n { base: cwd, pattern: '.coder/skills/**/SKILL.md' },\n { base: cwd, pattern: '.claude/skills/**/SKILL.md' },\n // 用户级技能(优先 .pulse-coder,兼容旧版 .coder)\n { base: homedir(), pattern: '.pulse-coder/skills/**/SKILL.md' },\n { base: homedir(), pattern: '.coder/skills/**/SKILL.md' }\n ];\n\n for (const { base, pattern } of scanPaths) {\n try {\n const files = globSync(pattern, { cwd: base, absolute: true });\n\n for (const filePath of files) {\n try {\n const skillInfo = this.parseSkillFile(filePath);\n if (skillInfo) {\n skills.push(skillInfo);\n }\n } catch (error) {\n console.warn(`Failed to parse skill file ${filePath}:`, error);\n }\n }\n } catch (error) {\n console.debug(`Skip scanning ${pattern} in ${base}:`, error);\n }\n }\n\n return skills;\n }\n\n /**\n * 解析技能文件\n */\n private parseSkillFile(filePath: string): SkillInfo | null {\n try {\n const content = readFileSync(filePath, 'utf-8');\n const { data, content: markdownContent } = matter(content);\n\n if (!data.name || !data.description) {\n console.warn(`Skill file ${filePath} missing required fields (name or description)`);\n return null;\n }\n\n return {\n name: data.name,\n description: data.description,\n location: filePath,\n content: markdownContent,\n metadata: data\n };\n } catch (error) {\n console.warn(`Failed to read skill file ${filePath}:`, error);\n return null;\n }\n }\n\n /**\n * 获取所有技能\n */\n getAll(): SkillInfo[] {\n return Array.from(this.skills.values());\n }\n\n /**\n * 注册或更新一个技能(支持插件在运行期追加技能)\n */\n registerSkill(skill: SkillInfo): { skillName: string; replaced: boolean; total: number } {\n const name = skill.name?.trim();\n if (!name) {\n throw new Error('Skill name is required');\n }\n\n const existingKey = Array.from(this.skills.keys()).find((key) => key.toLowerCase() === name.toLowerCase());\n const replaced = existingKey !== undefined;\n\n if (existingKey && existingKey !== name) {\n this.skills.delete(existingKey);\n }\n\n this.skills.set(name, {\n ...skill,\n name\n });\n\n return {\n skillName: name,\n replaced,\n total: this.skills.size\n };\n }\n\n /**\n * 根据名称获取技能(大小写不敏感)\n */\n get(name: string): SkillInfo | undefined {\n const exact = this.skills.get(name);\n if (exact) {\n return exact;\n }\n\n const target = name.toLowerCase();\n return this.getAll().find((skill) => skill.name.toLowerCase() === target);\n }\n\n /**\n * 检查技能是否存在\n */\n has(name: string): boolean {\n return !!this.get(name);\n }\n\n /**\n * 搜索技能(模糊匹配)\n */\n search(keyword: string): SkillInfo[] {\n const lowerKeyword = keyword.toLowerCase();\n return this.getAll().filter(\n (skill) =>\n skill.name.toLowerCase().includes(lowerKeyword) ||\n skill.description.toLowerCase().includes(lowerKeyword)\n );\n }\n}\n\n/**\n * 技能工具参数 schema\n */\nconst skillToolSchema = z.object({\n name: z.string().describe('The name of the skill to execute')\n});\n\ntype SkillToolInput = z.infer<typeof skillToolSchema>;\n\n/**\n * 生成技能工具\n */\nfunction generateSkillTool(registry: BuiltInSkillRegistry): Tool<SkillToolInput, SkillInfo> {\n const getSkillsPrompt = (availableSkills: SkillInfo[]) => {\n return [\n \"If query matches an available skill's description or instruction [use skill], use the skill tool to get detailed instructions.\",\n \"Load a skill to get detailed instructions for a specific task.\",\n \"Skills provide specialized knowledge and step-by-step guidance.\",\n \"Use this when a task matches an available skill's description.\",\n \"Only the skills listed here are available:\",\n \"[!important] You should follow the skill's step-by-step guidance. If the skill is not complete, ask the user for more information.\",\n \"<available_skills>\",\n ...availableSkills.flatMap((skill) => [\n ` <skill>`,\n ` <name>${skill.name}</name>`,\n ` <description>${skill.description}</description>`,\n ` </skill>`\n ]),\n \"</available_skills>\"\n ].join(\" \");\n };\n\n return {\n name: \"skill\",\n description: getSkillsPrompt(registry.getAll()),\n inputSchema: skillToolSchema,\n execute: async ({ name }) => {\n const skill = registry.get(name);\n if (!skill) {\n throw new Error(`Skill ${name} not found`);\n }\n return skill;\n }\n };\n}\n\n/**\n * 内置技能插件\n */\nexport const builtInSkillsPlugin: EnginePlugin = {\n name: 'pulse-coder-engine/built-in-skills',\n version: '1.0.0',\n\n async initialize(context: EnginePluginContext) {\n const registry = new BuiltInSkillRegistry();\n await registry.initialize(process.cwd());\n\n context.registerService('skillRegistry', registry);\n context.registerTool('skill', generateSkillTool(registry));\n\n context.registerHook('beforeRun', ({ tools }) => {\n return {\n tools: {\n ...tools,\n skill: generateSkillTool(registry)\n }\n };\n });\n\n const skills = registry.getAll();\n if (skills.length === 0) {\n console.log('[Skills] No skills found');\n return;\n }\n\n console.log(`[Skills] Registered ${skills.length} skill(s)`);\n }\n};\n\nexport default builtInSkillsPlugin;","import type { EventEmitter } from 'events';\nimport type { ModelMessage } from 'ai';\n\nimport type { SystemPromptOption } from '../../shared/types';\nimport type { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\n\nexport type PlanMode = 'planning' | 'executing';\nexport type PlanIntentLabel = 'PLAN_ONLY' | 'EXECUTE_NOW' | 'UNCLEAR';\nexport type ToolCategory = 'read' | 'search' | 'write' | 'execute' | 'other';\nexport type ToolRisk = 'low' | 'medium' | 'high';\n\nexport type PlanModeEventName =\n | 'mode_entered'\n | 'execution_intent_detected'\n | 'mode_switched_by_intent'\n | 'disallowed_tool_attempt_in_planning';\n\nexport interface ToolMeta {\n name: string;\n category: ToolCategory;\n risk: ToolRisk;\n description: string;\n examples?: string[];\n}\n\nexport interface ModePolicy {\n mode: PlanMode;\n allowedCategories: ToolCategory[];\n disallowedCategories: ToolCategory[];\n notes?: string;\n}\n\nexport interface PlanModeEvent {\n name: PlanModeEventName;\n mode: PlanMode;\n timestamp: number;\n payload?: Record<string, unknown>;\n}\n\nexport interface PlanModeTransitionResult {\n modeBefore: PlanMode;\n modeAfter: PlanMode;\n switched: boolean;\n intent: PlanIntentLabel;\n userInput: string;\n}\n\nexport interface PlanModeService {\n getMode(): PlanMode;\n setMode(mode: PlanMode, reason?: string): void;\n detectIntent(input: string): PlanIntentLabel;\n processContextMessages(messages: ModelMessage[]): PlanModeTransitionResult;\n getModePolicy(mode?: PlanMode): ModePolicy;\n getToolMetadata(toolNames: string[]): ToolMeta[];\n buildPromptAppend(toolNames: string[], transition?: PlanModeTransitionResult): string;\n getEvents(limit?: number): PlanModeEvent[];\n}\n\ntype LoggerLike = EnginePluginContext['logger'];\n\nconst PLANNING_POLICY: ModePolicy = {\n mode: 'planning',\n allowedCategories: ['read', 'search', 'other'],\n disallowedCategories: ['write', 'execute'],\n notes:\n 'Planning mode is prompt-constrained only. Disallowed tool attempts are observed and logged, not hard-blocked.'\n};\n\nconst EXECUTING_POLICY: ModePolicy = {\n mode: 'executing',\n allowedCategories: ['read', 'search', 'write', 'execute', 'other'],\n disallowedCategories: []\n};\n\nconst EXECUTE_PATTERNS: RegExp[] = [\n /开始执行/i,\n /按这个计划做/i,\n /可以改代码了/i,\n /直接实现/i,\n /go\\s+ahead/i,\n /proceed/i,\n /implement\\s+it/i,\n /start\\s+implement/i,\n /start\\s+coding/i\n];\n\nconst NEGATIVE_PATTERNS: RegExp[] = [\n /先不(要)?执行/i,\n /先别执行/i,\n /不要执行/i,\n /暂时不要执行/i,\n /先别改代码/i,\n /先不要改代码/i,\n /先不要实现/i,\n /not\\s+now/i,\n /hold\\s+off/i,\n /do\\s+not\\s+(start|execute|implement|proceed)/i,\n /don't\\s+(start|execute|implement|proceed)/i\n];\n\nconst PLAN_PATTERNS: RegExp[] = [/先计划/i, /先分析/i, /先出方案/i, /plan\\s+first/i, /analysis\\s+first/i];\n\n\nfunction appendSystemPrompt(base: SystemPromptOption | undefined, append: string): SystemPromptOption {\n if (!append.trim()) {\n return base ?? { append: '' };\n }\n\n if (!base) {\n return { append };\n }\n\n if (typeof base === 'string') {\n return `${base}\\n\\n${append}`;\n }\n\n if (typeof base === 'function') {\n return () => `${base()}\\n\\n${append}`;\n }\n\n const currentAppend = base.append.trim();\n return {\n append: currentAppend ? `${currentAppend}\\n\\n${append}` : append\n };\n}\n\nconst KNOWN_TOOL_META: Record<string, Omit<ToolMeta, 'name'>> = {\n read: {\n category: 'read',\n risk: 'low',\n description: 'Read file contents from the workspace.'\n },\n ls: {\n category: 'read',\n risk: 'low',\n description: 'List files and directories.'\n },\n grep: {\n category: 'search',\n risk: 'low',\n description: 'Search text content across files.'\n },\n tavily: {\n category: 'search',\n risk: 'low',\n description: 'Search web results from external sources.'\n },\n skill: {\n category: 'search',\n risk: 'low',\n description: 'Load procedural guidance from installed skills.'\n },\n write: {\n category: 'write',\n risk: 'high',\n description: 'Create or overwrite file content.'\n },\n edit: {\n category: 'write',\n risk: 'high',\n description: 'Modify existing files using exact replacements.'\n },\n bash: {\n category: 'execute',\n risk: 'high',\n description: 'Execute shell commands.'\n },\n clarify: {\n category: 'other',\n risk: 'low',\n description: 'Ask the user a targeted clarification question.'\n },\n task_create: {\n category: 'other',\n risk: 'low',\n description: 'Create tracked task entries for planning and execution visibility.'\n },\n task_get: {\n category: 'other',\n risk: 'low',\n description: 'Inspect a task entry by ID.'\n },\n task_list: {\n category: 'other',\n risk: 'low',\n description: 'List task tracking entries and status summary.'\n },\n task_update: {\n category: 'other',\n risk: 'low',\n description: 'Update task tracking fields and status.'\n }\n};\n\nclass BuiltInPlanModeService implements PlanModeService {\n private mode: PlanMode;\n private readonly events: PlanModeEvent[] = [];\n\n constructor(\n private readonly logger: LoggerLike,\n private readonly eventEmitter: EventEmitter,\n initialMode: PlanMode = 'executing'\n ) {\n this.mode = initialMode;\n this.emitEvent('mode_entered', { reason: 'initialize' });\n }\n\n getMode(): PlanMode {\n return this.mode;\n }\n\n setMode(mode: PlanMode, reason: string = 'manual'): void {\n if (this.mode === mode) {\n return;\n }\n\n this.mode = mode;\n this.emitEvent('mode_entered', { reason });\n }\n\n detectIntent(input: string): PlanIntentLabel {\n const text = input.trim();\n if (!text) {\n return 'UNCLEAR';\n }\n\n if (NEGATIVE_PATTERNS.some((pattern) => pattern.test(text))) {\n return 'PLAN_ONLY';\n }\n\n if (EXECUTE_PATTERNS.some((pattern) => pattern.test(text))) {\n return 'EXECUTE_NOW';\n }\n\n if (PLAN_PATTERNS.some((pattern) => pattern.test(text))) {\n return 'PLAN_ONLY';\n }\n\n return 'UNCLEAR';\n }\n\n processContextMessages(messages: ModelMessage[]): PlanModeTransitionResult {\n const userInput = this.getLatestUserText(messages);\n const modeBefore = this.mode;\n\n if (!userInput) {\n return {\n modeBefore,\n modeAfter: this.mode,\n switched: false,\n intent: 'UNCLEAR',\n userInput: ''\n };\n }\n\n const intent = this.detectIntent(userInput);\n\n if (intent === 'EXECUTE_NOW') {\n this.emitEvent('execution_intent_detected', { intent, userInput });\n\n if (this.mode === 'planning') {\n this.mode = 'executing';\n this.emitEvent('mode_switched_by_intent', {\n from: 'planning',\n to: 'executing',\n userInput\n });\n this.emitEvent('mode_entered', {\n reason: 'intent',\n from: 'planning'\n });\n }\n }\n\n return {\n modeBefore,\n modeAfter: this.mode,\n switched: modeBefore !== this.mode,\n intent,\n userInput\n };\n }\n\n getModePolicy(mode: PlanMode = this.mode): ModePolicy {\n return mode === 'planning' ? PLANNING_POLICY : EXECUTING_POLICY;\n }\n\n getToolMetadata(toolNames: string[]): ToolMeta[] {\n return Array.from(new Set(toolNames)).sort().map((name) => this.inferToolMeta(name));\n }\n\n buildPromptAppend(toolNames: string[], transition?: PlanModeTransitionResult): string {\n const mode = this.mode;\n const policy = this.getModePolicy(mode);\n const toolMeta = this.getToolMetadata(toolNames);\n const shownTools = toolMeta.slice(0, 40);\n const omittedCount = toolMeta.length - shownTools.length;\n\n const lines: string[] = [\n '## Plan Mode Policy (Built-in Plugin)',\n `Current mode: ${mode.toUpperCase()}`,\n `Allowed tool categories: ${policy.allowedCategories.join(', ')}`,\n `Disallowed tool categories: ${policy.disallowedCategories.join(', ') || 'none'}`,\n policy.notes ? `Policy notes: ${policy.notes}` : ''\n ].filter(Boolean);\n\n if (mode === 'planning') {\n lines.push(\n 'Planning objective: prioritize reading, analysis, and plan generation.',\n 'In planning mode, do not intentionally perform write/edit/execute actions.',\n 'If implementation is requested but intent is not explicit, ask for execution authorization.',\n 'Before each tool call in planning mode, self-check category compliance.',\n 'Plan format must include: goals, assumptions, steps, risks, validation approach.'\n );\n } else {\n lines.push(\n 'Executing objective: follow the agreed plan before broad exploration.',\n 'Make targeted edits and keep changes scoped.',\n 'Report what changed and how it was validated.'\n );\n }\n\n if (transition?.switched && transition.modeAfter === 'executing') {\n lines.push(\n 'Mode transition: the latest user message explicitly authorized execution.',\n 'In your next reply, acknowledge switching to EXECUTING mode before implementation details.'\n );\n }\n\n lines.push('Tool metadata (prompt-level policy reference):');\n for (const meta of shownTools) {\n lines.push(`- ${meta.name}: category=${meta.category}, risk=${meta.risk}, ${meta.description}`);\n }\n\n if (omittedCount > 0) {\n lines.push(`- ... ${omittedCount} additional tool(s) omitted for brevity.`);\n }\n\n return lines.join('\\n');\n }\n\n getEvents(limit: number = 50): PlanModeEvent[] {\n return this.events.slice(-Math.max(0, limit));\n }\n\n observePotentialPolicyViolation(toolName: string, input: unknown): void {\n if (this.mode !== 'planning') {\n return;\n }\n\n const meta = this.inferToolMeta(toolName);\n const policy = this.getModePolicy('planning');\n\n if (!policy.disallowedCategories.includes(meta.category)) {\n return;\n }\n\n this.emitEvent('disallowed_tool_attempt_in_planning', {\n toolName,\n category: meta.category,\n risk: meta.risk,\n input\n });\n }\n\n private inferToolMeta(name: string): ToolMeta {\n const knownMeta = KNOWN_TOOL_META[name];\n if (knownMeta) {\n return {\n name,\n ...knownMeta\n };\n }\n\n if (name.startsWith('mcp_')) {\n return {\n name,\n category: 'execute',\n risk: 'medium',\n description: 'MCP external tool invocation.'\n };\n }\n\n if (name.endsWith('_agent')) {\n return {\n name,\n category: 'execute',\n risk: 'high',\n description: 'Sub-agent task execution tool.'\n };\n }\n\n if (/read|list|cat/i.test(name)) {\n return {\n name,\n category: 'read',\n risk: 'low',\n description: 'Likely a read-only inspection tool inferred by name.'\n };\n }\n\n if (/search|find|query|grep/i.test(name)) {\n return {\n name,\n category: 'search',\n risk: 'low',\n description: 'Likely a search tool inferred by name.'\n };\n }\n\n if (/write|edit|patch|update|create|delete|remove/i.test(name)) {\n return {\n name,\n category: 'write',\n risk: 'high',\n description: 'Likely a file-modifying tool inferred by name.'\n };\n }\n\n if (/bash|exec|run|shell|deploy|build|test/i.test(name)) {\n return {\n name,\n category: 'execute',\n risk: 'high',\n description: 'Likely a command execution tool inferred by name.'\n };\n }\n\n return {\n name,\n category: 'other',\n risk: 'low',\n description: 'Tool category could not be inferred with high confidence.'\n };\n }\n\n private getLatestUserText(messages: ModelMessage[]): string {\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (message.role !== 'user') {\n continue;\n }\n\n return this.messageContentToText(message.content);\n }\n\n return '';\n }\n\n private messageContentToText(content: ModelMessage['content']): string {\n if (typeof content === 'string') {\n return content;\n }\n\n if (!Array.isArray(content)) {\n return '';\n }\n\n const textParts: string[] = [];\n\n for (const part of content) {\n if (typeof part === 'string') {\n textParts.push(part);\n continue;\n }\n\n if (part && typeof part === 'object' && 'text' in part && typeof part.text === 'string') {\n textParts.push(part.text);\n }\n }\n\n return textParts.join('\\n');\n }\n\n private emitEvent(name: PlanModeEventName, payload?: Record<string, unknown>): void {\n const event: PlanModeEvent = {\n name,\n mode: this.mode,\n timestamp: Date.now(),\n payload\n };\n\n this.events.push(event);\n if (this.events.length > 500) {\n this.events.shift();\n }\n\n this.eventEmitter.emit(name, event);\n this.eventEmitter.emit('plan_mode_event', event);\n\n if (name === 'disallowed_tool_attempt_in_planning') {\n this.logger.warn('[PlanMode] Soft violation detected in planning mode', payload);\n return;\n }\n\n this.logger.info(`[PlanMode] ${name}`, payload);\n }\n}\n\nexport const builtInPlanModePlugin: EnginePlugin = {\n name: 'pulse-coder-engine/built-in-plan-mode',\n version: '1.0.0',\n\n async initialize(context: EnginePluginContext): Promise<void> {\n const service = new BuiltInPlanModeService(context.logger, context.events, 'executing');\n\n // Inject plan-mode system prompt before each LLM call\n context.registerHook('beforeLLMCall', ({ context: runContext, tools, systemPrompt }) => {\n const mode = service.getMode();\n if (mode === 'executing') {\n return;\n }\n\n const transition = service.processContextMessages(runContext.messages);\n const append = service.buildPromptAppend(Object.keys(tools), transition);\n const finalSystemPrompt = appendSystemPrompt(systemPrompt, append);\n\n return { systemPrompt: finalSystemPrompt };\n });\n\n // Observe tool calls for policy violations in planning mode\n context.registerHook('beforeToolCall', ({ name, input }) => {\n service.observePotentialPolicyViolation(name, input);\n });\n\n context.registerService('planMode', service);\n context.registerService('planModeService', service);\n\n context.logger.info('[PlanMode] Built-in plan mode plugin initialized', {\n mode: service.getMode()\n });\n }\n};\n\nexport { BuiltInPlanModeService };\n\nexport default builtInPlanModePlugin;\n","import { promises as fs } from 'fs';\nimport path from 'path';\nimport { homedir } from 'os';\nimport { randomUUID } from 'crypto';\nimport { z } from 'zod';\n\nimport type { BuiltInSkillRegistry, SkillInfo } from '../skills-plugin';\n\nimport type { Tool } from '../../shared/types';\nimport type { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\n\nconst TASK_STATUSES = ['pending', 'in_progress', 'completed', 'blocked'] as const;\n\nexport type TaskStatus = (typeof TASK_STATUSES)[number];\n\nexport interface WorkTask {\n id: string;\n title: string;\n details?: string;\n status: TaskStatus;\n dependencies: string[];\n blockedReason?: string;\n metadata?: Record<string, any>;\n createdAt: number;\n updatedAt: number;\n completedAt?: number;\n}\n\nexport interface WorkTaskListSnapshot {\n taskListId: string;\n storagePath: string;\n createdAt: number;\n updatedAt: number;\n total: number;\n tasks: WorkTask[];\n}\n\ninterface TaskListStoreFile {\n taskListId: string;\n createdAt: number;\n updatedAt: number;\n tasks: WorkTask[];\n}\n\ninterface CreateTaskInput {\n title: string;\n details?: string;\n status?: TaskStatus;\n dependencies?: string[];\n blockedReason?: string;\n metadata?: Record<string, any>;\n}\n\ninterface ListTaskOptions {\n statuses?: TaskStatus[];\n includeCompleted?: boolean;\n limit?: number;\n}\n\ninterface UpdateTaskInput {\n id: string;\n title?: string;\n details?: string;\n status?: TaskStatus;\n dependencies?: string[];\n blockedReason?: string;\n metadata?: Record<string, any>;\n delete?: boolean;\n}\n\nconst CREATE_TASK_ITEM_SCHEMA = z.object({\n title: z.string().min(1).describe('Task title'),\n details: z.string().optional().describe('Task details / acceptance notes'),\n status: z.enum(TASK_STATUSES).optional().describe('Initial status; defaults to pending'),\n dependencies: z.array(z.string()).optional().describe('Task IDs that must be completed first'),\n blockedReason: z.string().optional().describe('Reason when status is blocked'),\n metadata: z.record(z.string(), z.any()).optional().describe('Additional machine-readable metadata')\n});\n\nconst TASK_CREATE_INPUT_SCHEMA = z\n .object({\n title: z.string().min(1).optional().describe('Task title (single-task mode)'),\n details: z.string().optional().describe('Task details (single-task mode)'),\n status: z.enum(TASK_STATUSES).optional().describe('Initial status (single-task mode)'),\n dependencies: z.array(z.string()).optional().describe('Dependencies (single-task mode)'),\n blockedReason: z.string().optional().describe('Blocked reason (single-task mode)'),\n metadata: z.record(z.string(), z.any()).optional().describe('Metadata (single-task mode)'),\n tasks: z.array(CREATE_TASK_ITEM_SCHEMA).min(1).optional().describe('Batch create mode')\n })\n .refine((value) => !!value.tasks?.length || !!value.title, {\n message: 'Either provide `tasks` or `title` for single-task mode.'\n });\n\nconst TASK_GET_INPUT_SCHEMA = z.object({\n id: z.string().min(1).describe('Task ID to retrieve')\n});\n\nconst TASK_LIST_INPUT_SCHEMA = z.object({\n statuses: z.array(z.enum(TASK_STATUSES)).optional().describe('Filter by statuses'),\n includeCompleted: z.boolean().optional().describe('Set false to hide completed tasks'),\n limit: z.number().int().positive().max(500).optional().describe('Maximum tasks to return')\n});\nconst TASK_TRACKING_SKILL: SkillInfo = {\n name: 'task-tracking-workflow',\n description: 'Track complex execution with task tools and proceed directly without confirmation unless the user explicitly asks for confirmation.',\n location: 'pulse-coder-engine/built-in/task-tracking-plugin',\n content: `# Task Tracking Workflow\n\n## When to use\n- The request has multiple phases or deliverables.\n- Work may span multiple tool calls or sessions.\n- You need explicit progress visibility and blocker management.\n\n## Execution autonomy\n- Default behavior: execute directly and call tools without asking for confirmation.\n- Only ask for confirmation when the user explicitly requires confirmation.\n- If critical information is missing, ask only the minimum clarifying question needed to continue.\n\n## Required flow\n1. Start by reviewing existing tasks with \\`task_list\\`.\n2. If no suitable tasks exist, create focused tasks with \\`task_create\\` (prefer batch mode).\n3. Keep exactly one primary task in \\`in_progress\\` where possible.\n4. Update status with \\`task_update\\` after meaningful progress.\n5. Mark blockers with \\`status=blocked\\` and a concrete \\`blockedReason\\`.\n6. Mark done tasks as \\`completed\\` and move to the next actionable item.\n\n## Quality rules\n- Keep tasks atomic and verifiable.\n- Avoid single oversized umbrella tasks.\n- Reuse existing in-progress tasks instead of duplicating.\n- Keep dependency links explicit when order matters.`\n};\n\nconst TASK_UPDATE_INPUT_SCHEMA = z.object({\n id: z.string().min(1).describe('Task ID to update'),\n title: z.string().min(1).optional().describe('New title'),\n details: z.string().optional().describe('New details'),\n status: z.enum(TASK_STATUSES).optional().describe('New status'),\n dependencies: z.array(z.string()).optional().describe('Replace dependencies with this list'),\n blockedReason: z.string().optional().describe('Blocked reason, used with status=blocked'),\n metadata: z.record(z.string(), z.any()).optional().describe('Replace metadata object'),\n delete: z.boolean().optional().describe('Delete this task')\n});\n\nfunction normalizeTaskListId(raw: string): string {\n const trimmed = raw.trim();\n if (!trimmed) {\n return 'default';\n }\n\n return trimmed.replace(/[^a-zA-Z0-9._-]/g, '-').slice(0, 120) || 'default';\n}\n\nfunction now(): number {\n return Date.now();\n}\n\n\nfunction dedupeStrings(values: string[] | undefined): string[] {\n if (!values?.length) {\n return [];\n }\n\n return Array.from(new Set(values.map((value) => String(value).trim()).filter(Boolean)));\n}\n\nexport class TaskListService {\n taskListId: string;\n storagePath: string;\n\n private readonly storageDir: string;\n private initialized = false;\n private createdAt = now();\n private updatedAt = now();\n private tasks = new Map<string, WorkTask>();\n\n constructor(\n taskListId: string = TaskListService.resolveTaskListId(),\n storageDir: string = TaskListService.resolveStorageDir()\n ) {\n const normalized = normalizeTaskListId(taskListId);\n\n this.storageDir = storageDir;\n this.taskListId = normalized;\n this.storagePath = path.join(this.storageDir, `${normalized}.json`);\n }\n\n static resolveTaskListId(): string {\n return process.env.PULSE_CODER_TASK_LIST_ID\n || process.env.CLAUDE_CODE_TASK_LIST_ID\n || 'default';\n }\n\n static resolveStorageDir(): string {\n return process.env.PULSE_CODER_TASKS_DIR\n || path.join(homedir(), '.pulse-coder', 'tasks');\n }\n\n async initialize(): Promise<void> {\n if (this.initialized) {\n return;\n }\n\n await this.loadTaskList(this.taskListId);\n }\n\n async setTaskListId(taskListId: string): Promise<{ switched: boolean; taskListId: string; storagePath: string }> {\n await this.initialize();\n\n const normalized = normalizeTaskListId(taskListId);\n if (normalized === this.taskListId) {\n return {\n switched: false,\n taskListId: this.taskListId,\n storagePath: this.storagePath\n };\n }\n\n await this.loadTaskList(normalized);\n\n return {\n switched: true,\n taskListId: this.taskListId,\n storagePath: this.storagePath\n };\n }\n\n async createTask(input: CreateTaskInput): Promise<WorkTask> {\n await this.initialize();\n\n const timestamp = now();\n const status = input.status ?? 'pending';\n\n const task: WorkTask = {\n id: randomUUID(),\n title: input.title.trim(),\n details: input.details,\n status,\n dependencies: dedupeStrings(input.dependencies),\n blockedReason: status === 'blocked' ? input.blockedReason ?? 'Blocked without reason' : undefined,\n metadata: input.metadata,\n createdAt: timestamp,\n updatedAt: timestamp,\n completedAt: status === 'completed' ? timestamp : undefined\n };\n\n this.tasks.set(task.id, task);\n this.updatedAt = timestamp;\n await this.persist();\n\n return task;\n }\n\n async createTasks(inputs: CreateTaskInput[]): Promise<WorkTask[]> {\n const created: WorkTask[] = [];\n for (const input of inputs) {\n created.push(await this.createTask(input));\n }\n return created;\n }\n\n async listTasks(options?: ListTaskOptions): Promise<WorkTask[]> {\n await this.initialize();\n\n const statuses = options?.statuses?.length ? new Set(options.statuses) : null;\n const includeCompleted = options?.includeCompleted ?? true;\n\n let tasks = Array.from(this.tasks.values()).filter((task) => {\n if (!includeCompleted && task.status === 'completed') {\n return false;\n }\n if (statuses && !statuses.has(task.status)) {\n return false;\n }\n return true;\n });\n\n tasks = tasks.sort((a, b) => a.createdAt - b.createdAt);\n\n if (options?.limit && options.limit > 0) {\n tasks = tasks.slice(0, options.limit);\n }\n\n return tasks;\n }\n\n async getTask(id: string): Promise<WorkTask | null> {\n await this.initialize();\n return this.tasks.get(id) ?? null;\n }\n\n async updateTask(input: UpdateTaskInput): Promise<WorkTask | null> {\n await this.initialize();\n\n if (input.delete) {\n const deleted = this.tasks.delete(input.id);\n if (!deleted) {\n return null;\n }\n\n this.updatedAt = now();\n await this.persist();\n return null;\n }\n\n const existing = this.tasks.get(input.id);\n if (!existing) {\n return null;\n }\n\n const timestamp = now();\n const nextStatus = input.status ?? existing.status;\n\n const next: WorkTask = {\n ...existing,\n title: input.title !== undefined ? input.title : existing.title,\n details: input.details !== undefined ? input.details : existing.details,\n status: nextStatus,\n dependencies: input.dependencies !== undefined ? dedupeStrings(input.dependencies) : existing.dependencies,\n metadata: input.metadata !== undefined ? input.metadata : existing.metadata,\n blockedReason: this.resolveBlockedReason(nextStatus, input.blockedReason, existing.blockedReason),\n updatedAt: timestamp,\n completedAt: nextStatus === 'completed'\n ? (existing.completedAt ?? timestamp)\n : undefined\n };\n\n this.tasks.set(input.id, next);\n this.updatedAt = timestamp;\n await this.persist();\n\n return next;\n }\n\n async snapshot(options?: ListTaskOptions): Promise<WorkTaskListSnapshot> {\n const tasks = await this.listTasks(options);\n\n return {\n taskListId: this.taskListId,\n storagePath: this.storagePath,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n total: tasks.length,\n tasks\n };\n }\n\n private resolveBlockedReason(status: TaskStatus, blockedReasonInput: string | undefined, previous?: string): string | undefined {\n if (status !== 'blocked') {\n return undefined;\n }\n\n if (blockedReasonInput !== undefined) {\n return blockedReasonInput || 'Blocked without reason';\n }\n\n return previous ?? 'Blocked without reason';\n }\n\n private async loadTaskList(taskListId: string): Promise<void> {\n const normalized = normalizeTaskListId(taskListId);\n\n this.taskListId = normalized;\n this.storagePath = path.join(this.storageDir, `${normalized}.json`);\n\n await fs.mkdir(this.storageDir, { recursive: true });\n\n try {\n const raw = await fs.readFile(this.storagePath, 'utf-8');\n const parsed = JSON.parse(raw) as Partial<TaskListStoreFile>;\n\n const parsedTasks = Array.isArray(parsed.tasks) ? parsed.tasks : [];\n this.tasks = new Map(parsedTasks.filter((task): task is WorkTask => !!task?.id).map((task) => [task.id, task]));\n this.createdAt = typeof parsed.createdAt === 'number' ? parsed.createdAt : now();\n this.updatedAt = typeof parsed.updatedAt === 'number' ? parsed.updatedAt : now();\n } catch (error: any) {\n if (error?.code !== 'ENOENT') {\n throw error;\n }\n\n const timestamp = now();\n this.tasks = new Map();\n this.createdAt = timestamp;\n this.updatedAt = timestamp;\n await this.persist();\n }\n\n this.initialized = true;\n }\n\n private async persist(): Promise<void> {\n const payload: TaskListStoreFile = {\n taskListId: this.taskListId,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n tasks: Array.from(this.tasks.values()).sort((a, b) => a.createdAt - b.createdAt)\n };\n\n await fs.writeFile(this.storagePath, JSON.stringify(payload, null, 2), 'utf-8');\n }\n}\n\nfunction buildTaskCreateTool(service: TaskListService): Tool {\n return {\n name: 'task_create',\n description: 'Create one or more tracked tasks for complex work. Use this when work has multiple steps, dependencies, or blockers.',\n inputSchema: TASK_CREATE_INPUT_SCHEMA,\n execute: async ({ tasks, title, details, status, dependencies, blockedReason, metadata }) => {\n const items: CreateTaskInput[] = tasks?.length\n ? tasks\n : [{ title: title!, details, status, dependencies, blockedReason, metadata }];\n\n const created = await service.createTasks(items);\n\n return {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n createdCount: created.length,\n tasks: created\n };\n }\n };\n}\n\nfunction buildTaskGetTool(service: TaskListService): Tool {\n return {\n name: 'task_get',\n description: 'Get full details for a single task by task ID.',\n inputSchema: TASK_GET_INPUT_SCHEMA,\n execute: async ({ id }) => {\n const task = await service.getTask(id);\n if (!task) {\n throw new Error(`Task not found: ${id}`);\n }\n\n return {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n task\n };\n }\n };\n}\n\nfunction buildTaskListTool(service: TaskListService): Tool {\n return {\n name: 'task_list',\n description: 'List tasks and their current status. Use this to check progress before and after major changes.',\n inputSchema: TASK_LIST_INPUT_SCHEMA,\n execute: async ({ statuses, includeCompleted, limit }) => {\n const snapshot = await service.snapshot({ statuses, includeCompleted, limit });\n const completed = snapshot.tasks.filter((task) => task.status === 'completed').length;\n const inProgress = snapshot.tasks.filter((task) => task.status === 'in_progress').length;\n const pending = snapshot.tasks.filter((task) => task.status === 'pending').length;\n const blocked = snapshot.tasks.filter((task) => task.status === 'blocked').length;\n\n return {\n ...snapshot,\n summary: {\n total: snapshot.total,\n completed,\n inProgress,\n pending,\n blocked\n }\n };\n }\n };\n}\n\n\n\nfunction buildTaskUpdateTool(service: TaskListService): Tool {\n return {\n name: 'task_update',\n description: 'Update task fields, move status (pending/in_progress/completed/blocked), or delete tasks.',\n inputSchema: TASK_UPDATE_INPUT_SCHEMA,\n execute: async (input) => {\n const task = await service.updateTask(input);\n\n if (input.delete) {\n return {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n deleted: true,\n id: input.id\n };\n }\n\n if (!task) {\n throw new Error(`Task not found: ${input.id}`);\n }\n\n return {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n deleted: false,\n task\n };\n }\n };\n}\n\nexport const builtInTaskTrackingPlugin: EnginePlugin = {\n name: 'pulse-coder-engine/built-in-task-tracking',\n version: '1.0.0',\n dependencies: ['pulse-coder-engine/built-in-skills'],\n\n async initialize(context: EnginePluginContext): Promise<void> {\n const service = new TaskListService();\n await service.initialize();\n\n context.registerService('taskListService', service);\n context.registerService('taskTracking', service);\n\n const skillRegistry = context.getService<BuiltInSkillRegistry>('skillRegistry');\n if (skillRegistry) {\n const registration = skillRegistry.registerSkill(TASK_TRACKING_SKILL);\n context.logger.info('[TaskTracking] Registered built-in task tracking skill', registration);\n } else {\n context.logger.warn('[TaskTracking] skillRegistry service unavailable; skipped task tracking skill registration');\n }\n\n context.registerTools({\n task_create: buildTaskCreateTool(service),\n task_get: buildTaskGetTool(service),\n task_list: buildTaskListTool(service),\n task_update: buildTaskUpdateTool(service)\n });\n\n context.logger.info('[TaskTracking] Registered task tools', {\n taskListId: service.taskListId,\n storagePath: service.storagePath,\n skillRegistryAvailable: !!skillRegistry\n });\n }\n};\n\nexport default builtInTaskTrackingPlugin;\n","import { z } from 'zod';\nimport { promises as fs } from 'fs';\nimport path from 'path';\nimport type { EnginePlugin, EnginePluginContext } from '../../plugin/EnginePlugin';\nimport type { Context } from '../../shared/types.js';\nimport { loop } from '../../core/loop';\nimport { BuiltinToolsMap } from '../../tools';\nimport { Tool } from 'ai';\n\ninterface AgentConfig {\n name: string;\n description: string;\n systemPrompt: string;\n filePath: string;\n}\n\nclass ConfigLoader {\n\n async getAgentFilesInfo(configDirs: string[]) {\n const fileInfos: Array<{ files: string[], configDir: string }> = [];\n for (let configDir of configDirs) {\n try {\n await fs.access(configDir);\n\n const files = await fs.readdir(configDir);\n fileInfos.push({ files, configDir });\n } catch {\n continue;\n }\n }\n\n return fileInfos;\n }\n\n async loadAgentConfigs(configDir: string | string[] = ['.pulse-coder/agents', '.coder/agents']): Promise<AgentConfig[]> {\n const configs: AgentConfig[] = [];\n\n const configDirs = Array.isArray(configDir) ? configDir : [configDir];\n\n try {\n const filesInfo = await this.getAgentFilesInfo(configDirs);\n\n for (const fileInfo of filesInfo) {\n const files = fileInfo.files;\n for (const file of files) {\n if (file.endsWith('.md')) {\n const config = await this.parseConfig(path.join(fileInfo.configDir, file));\n if (config) configs.push(config);\n }\n }\n }\n } catch (error) {\n console.warn(`Failed to scan agent configs: ${error}`);\n }\n\n return configs;\n }\n\n private async parseConfig(filePath: string): Promise<AgentConfig | null> {\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n const lines = content.split('\\n');\n\n let name = '';\n let description = '';\n let systemPrompt = '';\n let inFrontmatter = false;\n let frontmatterEnd = false;\n\n for (const line of lines) {\n if (line.trim() === '---') {\n if (!inFrontmatter) {\n inFrontmatter = true;\n continue;\n } else {\n frontmatterEnd = true;\n continue;\n }\n }\n\n if (inFrontmatter && !frontmatterEnd) {\n const match = line.match(/^\\s*(\\w+)\\s*:\\s*(.+)$/);\n if (match) {\n const [, key, value] = match;\n if (key === 'name') name = value.trim();\n if (key === 'description') description = value.trim();\n }\n } else if (frontmatterEnd) {\n systemPrompt += line + '\\n';\n }\n }\n\n if (!name) {\n name = path.basename(filePath, '.md');\n }\n\n return {\n name: name.trim(),\n description: description.trim(),\n systemPrompt: systemPrompt.trim(),\n filePath\n };\n } catch (error) {\n console.warn(`Failed to parse agent config ${filePath}: ${error}`);\n return null;\n }\n }\n}\n\nclass AgentRunner {\n async runAgent(\n config: AgentConfig,\n task: string,\n context?: Record<string, any>,\n tools?: Record<string, any>\n ): Promise<string> {\n const subContext: Context = {\n messages: [\n { role: 'user', content: task }\n ]\n };\n\n if (context && Object.keys(context).length > 0) {\n subContext.messages.push({\n role: 'user',\n content: `上下文信息:\\n${JSON.stringify(context, null, 2)}`\n });\n }\n\n return await loop(subContext, { tools, systemPrompt: config.systemPrompt });\n }\n}\n\nexport class SubAgentPlugin implements EnginePlugin {\n name = 'sub-agent';\n version = '1.0.0';\n\n private configLoader = new ConfigLoader();\n private agentRunner = new AgentRunner();\n\n async initialize(context: EnginePluginContext): Promise<void> {\n try {\n const configs = await this.configLoader.loadAgentConfigs();\n\n for (const config of configs) {\n this.registerAgentTool(context, config);\n }\n\n context.logger.info(`SubAgentPlugin loaded ${configs.length} agents.`);\n } catch (error) {\n context.logger.error('Failed to initialize SubAgentPlugin', error as Error);\n }\n }\n\n private registerAgentTool(\n context: EnginePluginContext,\n config: AgentConfig\n ): void {\n const toolName = `${config.name}_agent`;\n\n const tool: Tool = {\n description: config.description,\n inputSchema: z.object({\n task: z.string().describe('要执行的任务描述'),\n context: z.any().optional().describe('任务上下文信息')\n }),\n execute: async ({ task, context: taskContext }: { task: string; context?: Record<string, any> }) => {\n // 延迟求值:在工具真正被调用时合并 builtin 工具与所有已注册插件工具,\n // 避免初始化阶段的静态快照导致后注册的插件工具缺失。\n const tools = { ...BuiltinToolsMap, ...context.getTools() };\n try {\n context.logger.info(`Running agent ${config.name}: ${task}`);\n const result = await this.agentRunner.runAgent(config, task, taskContext, tools);\n context.logger.info(`Agent ${config.name} completed successfully`);\n return result;\n } catch (error) {\n context.logger.error(`Agent ${config.name} failed`, error as Error);\n throw new Error(`Agent ${config.name} failed: ${error}`);\n }\n }\n };\n\n context.registerTool(toolName, tool);\n }\n\n async destroy(context: EnginePluginContext): Promise<void> {\n context.logger.info('SubAgentPlugin destroyed');\n }\n}\n\nexport default SubAgentPlugin;","import { generateText, streamText, tool, type ModelMessage, type StepResult, type Tool } from 'ai';\nimport { CoderAI, DEFAULT_MODEL, COMPACT_SUMMARY_MAX_TOKENS, OPENAI_REASONING_EFFORT } from '../config';\nimport z from 'zod';\nimport { generateSystemPrompt } from '../prompt';\nimport type { Tool as CoderTool, ToolExecutionContext, LLMProviderFactory, SystemPromptOption } from '../shared/types';\n\n\nconst providerOptions = { openai: { store: false, reasoningEffort: OPENAI_REASONING_EFFORT } }\n\n/** Resolve a SystemPromptOption into a final string. */\nconst resolveSystemPrompt = (option: SystemPromptOption | undefined): string => {\n const base = generateSystemPrompt();\n if (!option) return base;\n if (typeof option === 'string') return option;\n if (typeof option === 'function') return option();\n return `${base}\\n\\n${option.append}`;\n};\n\nexport const generateTextAI = (\n messages: ModelMessage[],\n tools: Record<string, Tool>,\n options?: { provider?: LLMProviderFactory; model?: string; systemPrompt?: SystemPromptOption }\n) => {\n const provider = options?.provider ?? CoderAI;\n const model = options?.model ?? DEFAULT_MODEL;\n\n return generateText({\n model: provider(model),\n system: resolveSystemPrompt(options?.systemPrompt),\n messages,\n tools,\n providerOptions,\n }) as unknown as ReturnType<typeof generateText> & { steps: StepResult<any>[]; finishReason: string };\n}\n\nexport interface StreamOptions {\n abortSignal?: AbortSignal;\n onStepFinish?: (event: StepResult<any>) => void;\n onChunk?: (event: { chunk: any }) => void;\n toolExecutionContext?: ToolExecutionContext;\n /** Custom LLM provider. Falls back to the default CoderAI provider when not set. */\n provider?: LLMProviderFactory;\n /** Model name to pass to the provider. Falls back to DEFAULT_MODEL when not set. */\n model?: string;\n /** Custom system prompt. See SystemPromptOption for the three supported forms. */\n systemPrompt?: SystemPromptOption;\n}\n\n/**\n * Wraps tools to inject ToolExecutionContext before execution\n */\nexport const wrapToolsWithContext = (\n tools: Record<string, CoderTool>,\n context?: ToolExecutionContext\n): Record<string, Tool> => {\n const wrappedTools: Record<string, Tool> = {};\n\n for (const [name, tool] of Object.entries(tools)) {\n wrappedTools[name] = {\n ...tool,\n execute: async (input: any) => {\n // Call the original execute with context\n return await tool.execute(input, context);\n }\n } as Tool;\n }\n\n return wrappedTools;\n};\n\nexport const streamTextAI = (messages: ModelMessage[], tools: Record<string, CoderTool>, options?: StreamOptions) => {\n const provider = options?.provider ?? CoderAI;\n const model = options?.model ?? DEFAULT_MODEL;\n\n // Wrap tools with execution context if provided\n const wrappedTools = options?.toolExecutionContext\n ? wrapToolsWithContext(tools, options.toolExecutionContext)\n : tools;\n\n const finalSystemPrompt = resolveSystemPrompt(options?.systemPrompt);\n\n return streamText({\n model: provider(model),\n system: finalSystemPrompt,\n messages,\n tools: wrappedTools as Record<string, Tool>,\n providerOptions,\n abortSignal: options?.abortSignal,\n onStepFinish: options?.onStepFinish,\n onChunk: options?.onChunk,\n }) as unknown as ReturnType<typeof streamText> & { steps: StepResult<any>[]; finishReason: string };\n}\n\nexport const summarizeMessages = async (\n messages: ModelMessage[],\n options?: { maxOutputTokens?: number; provider?: LLMProviderFactory; model?: string }\n): Promise<string> => {\n const provider = options?.provider ?? CoderAI;\n const model = options?.model ?? DEFAULT_MODEL;\n const SUMMARY_SYSTEM_PROMPT =\n '你是负责压缩对话上下文的助手。请基于给定历史消息,提炼关键事实与决策,避免臆测或扩展。';\n\n const SUMMARY_USER_PROMPT = [\n '请将以上对话压缩为以下格式,使用中文:',\n '[COMPACTED_CONTEXT]',\n '- 目标: ...',\n '- 进展: ...',\n '- 关键结果: ...',\n '- 文件与变更: ...',\n '- 关键片段: \"...\" / `...` / \"...\"',\n '- 待确认: ...',\n '',\n '要求:内容简洁准确,不要编造。',\n ].join('\\n');\n\n const result = await generateText({\n model: provider(model),\n system: SUMMARY_SYSTEM_PROMPT,\n messages: [\n ...messages,\n { role: 'user', content: SUMMARY_USER_PROMPT },\n ],\n maxOutputTokens: options?.maxOutputTokens ?? COMPACT_SUMMARY_MAX_TOKENS,\n providerOptions,\n });\n\n return result.text ?? '';\n}","import dotenv from \"dotenv\";\nimport { createOpenAI } from '@ai-sdk/openai';\nimport { createAnthropic } from \"@ai-sdk/anthropic\";\nimport { LanguageModel } from \"ai\";\n\ndotenv.config();\n\nexport const CoderAI = (process.env.USE_ANTHROPIC\n ? createAnthropic({\n apiKey: process.env.ANTHROPIC_API_KEY || '',\n baseURL: process.env.ANTHROPIC_API_URL || 'https://api.anthropic.com/v1'\n })\n : createOpenAI({\n apiKey: process.env.OPENAI_API_KEY || '',\n baseURL: process.env.OPENAI_API_URL || 'https://api.openai.com/v1'\n }).responses) as (model: string) => LanguageModel;\n\nexport const DEFAULT_MODEL = process.env.ANTHROPIC_MODEL || process.env.OPENAI_MODEL || 'novita/deepseek/deepseek_v3';\n\nexport const MAX_TURNS = 100;\nexport const MAX_ERROR_COUNT = 3;\nexport const MAX_STEPS = 100;\nexport const MAX_TOOL_OUTPUT_LENGTH = 30_000;\n\nexport const CONTEXT_WINDOW_TOKENS = Number(process.env.CONTEXT_WINDOW_TOKENS ?? 64_000);\nexport const COMPACT_TRIGGER = Number(process.env.COMPACT_TRIGGER ?? Math.floor(CONTEXT_WINDOW_TOKENS * 0.75));\nexport const COMPACT_TARGET = Number(process.env.COMPACT_TARGET ?? Math.floor(CONTEXT_WINDOW_TOKENS * 0.5));\nexport const KEEP_LAST_TURNS = Number(process.env.KEEP_LAST_TURNS ?? 6);\nexport const COMPACT_SUMMARY_MAX_TOKENS = Number(process.env.COMPACT_SUMMARY_MAX_TOKENS ?? 1200);\nexport const MAX_COMPACTION_ATTEMPTS = Number(process.env.MAX_COMPACTION_ATTEMPTS ?? 2);\nexport const OPENAI_REASONING_EFFORT = process.env.OPENAI_REASONING_EFFORT;\n\n// Clarification settings\nexport const CLARIFICATION_TIMEOUT = Number(process.env.CLARIFICATION_TIMEOUT ?? 300_000); // 5 minutes\nexport const CLARIFICATION_ENABLED = process.env.CLARIFICATION_ENABLED !== 'false';","import fs from 'fs';\nimport path from 'path';\n\nconst DEFAULT_PROMPT = `\nYou are Pulse Coder, the best coding agent on the planet.\n\nYou are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\n\n## Editing constraints\n- Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.\n- Only add comments if they are necessary to make a non-obvious block easier to understand.\n- Try to use apply_patch for single file edits, but it is fine to explore other options to make the edit if it does not work well. Do not use apply_patch for changes that are auto-generated (i.e. generating package.json or running a lint or format command like gofmt) or when scripting is more efficient (such as search and replacing a string across a codebase).\n\n## Skills\n- If query matches an available skill's description or instruction [use skill], use the skill tool to get detailed instructions.\n- You should Load a skill to get detailed instructions for a specific task. It always is a complex task that requires multiple steps.\n- You should check the skill is complete and follow the step-by-step guidance. If the skill is not complete, you should ask the user for more information.\n\n## Tool usage\n- Prefer specialized tools over shell for file operations:\n - Use Read to view files, Edit to modify files, and Write only when needed.\n - Use Glob to find files by name and Grep to search file contents.\n- Use Bash for terminal operations (git, bun, builds, tests, running scripts).\n- Run tool calls in parallel when neither call needs the other’s output; otherwise run sequentially.\n\n## Execution discipline\n- If the user gives a clear execution command (for example: \"start\", \"run\", \"execute\", \"do it now\", \"开始执行\", \"直接执行\"), execute the relevant tool calls immediately when safe and feasible.\n- Do not reply with intent-only messages (for example: \"I will do it\", \"starting now\") when a tool call can be made right away.\n- Do not claim completion unless tool execution has actually happened.\n- If execution cannot proceed, state exactly what is blocked and ask one targeted question with a recommended default.\n- Only ask before execution when one of these is true:\n - A required value is missing and cannot be inferred safely.\n - The action is destructive, irreversible, or changes production/security/billing posture.\n - Credentials/authorization are required and unavailable.\n- After each execution step, report factual outcomes (success/failure, key output, and next action).\n\n## Git and workspace hygiene\n- You may be in a dirty git worktree.\n * NEVER revert existing changes you did not make unless explicitly requested, since these changes were made by the user.\n * If asked to make a commit or code edits and there are unrelated changes to your work or changes that you didn't make in those files, don't revert those changes.\n * If the changes are in files you've touched recently, you should read carefully and understand how you can work with the changes rather than reverting them.\n * If the changes are in unrelated files, just ignore them and don't revert them.\n- Do not amend commits unless explicitly requested.\n- **NEVER** use destructive commands like \\`git reset --hard\\` or \\`git checkout--\\` unless specifically requested or approved by the user.\n\n## Frontend tasks\nWhen doing frontend design tasks, avoid collapsing into bland, generic layouts.\nAim for interfaces that feel intentional and deliberate.\n- Typography: Use expressive, purposeful fonts and avoid default stacks (Inter, Roboto, Arial, system).\n- Color & Look: Choose a clear visual direction; define CSS variables; avoid purple-on-white defaults. No purple bias or dark mode bias.\n- Motion: Use a few meaningful animations (page-load, staggered reveals) instead of generic micro-motions.\n- Background: Don't rely on flat, single-color backgrounds; use gradients, shapes, or subtle patterns to build atmosphere.\n- Overall: Avoid boilerplate layouts and interchangeable UI patterns. Vary themes, type families, and visual languages across outputs.\n- Ensure the page loads properly on both desktop and mobile.\n\nException: If working within an existing website or design system, preserve the established patterns, structure, and visual language.\n\n## Presenting your work and final message\n\nYou are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.\n\n- Default: be very concise; friendly coding teammate tone.\n- Default: do the work without asking questions. Treat short tasks as sufficient direction; infer missing details by reading the codebase and following existing conventions.\n- Questions: only ask when you are truly blocked after checking relevant context AND you cannot safely pick a reasonable default. This usually means one of:\n * The request is ambiguous in a way that materially changes the result and you cannot disambiguate by reading the repo.\n * The action is destructive/irreversible, touches production, or changes billing/security posture.\n * You need a secret/credential/value that cannot be inferred (API key, account id, etc.).\n- If you must ask: do all non-blocked work first, then ask exactly one targeted question, include your recommended default, and state what would change based on the answer.\n- Never ask permission questions like \"Should I proceed?\" or \"Do you want me to run tests?\"; proceed with the most reasonable option and mention what you did.\n\n## Clarification Tool\n\nUse the 'clarify' tool when you genuinely need information from the user to proceed. This tool pauses execution and waits for user input.\n\n**When to use clarify:**\n- The request is ambiguous in a way that materially affects the implementation and cannot be resolved by reading the codebase\n- You cannot safely infer the answer from existing code, conventions, or context\n- You need confirmation before destructive or irreversible actions (e.g., deleting resources, modifying production data)\n- You need specific values that cannot be guessed (API keys, account IDs, specific user choices between valid alternatives)\n\n**When NOT to use clarify:**\n- For trivial decisions you can make based on codebase conventions or common practices\n- For permission questions like \"Should I proceed?\" (just proceed with the best option)\n- For information that's likely in the codebase, configuration files, or documentation (read those first)\n- Multiple times in a row - complete all non-blocked work first, then ask one clear question\n- For choices where a reasonable default exists (use the default and mention what you chose)\n\n**How to use clarify:**\n- Ask ONE clear, specific question per clarification\n- Provide context if needed to help the user understand the choice\n- Include a recommended default answer when applicable\n- Explain briefly what would change based on the answer\n\nExample usage: Call clarify with a question, optional context, and optional default answer. The tool will pause and wait for the user's response.\n- For substantial work, summarize clearly; follow final-answer formatting.\n- Skip heavy formatting for simple confirmations.\n- Don't dump large files you've written; reference paths only.\n- No \"save/copy this file\" - User is on the same machine.\n- Offer logical next steps (tests, commits, build) briefly; add verify steps if you couldn't do something.\n- For code changes:\n * Lead with a quick explanation of the change, and then give more details on the context covering where and why a change was made. Do not start this explanation with \"summary\", just jump right in.\n * If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps.\n * When suggesting multiple options, use numeric lists for the suggestions so the user can quickly respond with a single number.\n- The user does not command execution outputs. When asked to show the output of a command (e.g. \\`git show\\`), relay the important details in your answer or summarize the key lines so the user understands the result.\n\n## Final answer structure and style guidelines\n\n- Plain text; CLI handles styling. Use structure only when it helps scanability.\n- Headers: optional; short Title Case (1-3 words) wrapped in **...**; no blank line before the first bullet; add only if they truly help.\n- Bullets: use - ; merge related points; keep to one line when possible; 4-6 per list ordered by importance; keep phrasing consistent.\n- Monospace: backticks for commands/paths/env vars/code ids and inline examples; use for literal keyword bullets; never combine with **.\n- Code samples or multi-line snippets should be wrapped in fenced code blocks; include an info string as often as possible.\n- Structure: group related bullets; order sections general -> specific -> supporting; for subsections, start with a bolded keyword bullet, then items; match complexity to the task.\n- Tone: collaborative, concise, factual; present tense, active voice; self-contained; no \"above/below\"; parallel wording.\n- Don'ts: no nested bullets/hierarchies; no ANSI codes; don't cram unrelated keywords; keep keyword lists short-wrap/reformat if long; avoid naming formatting styles in answers.\n- Adaptation: code explanations -> precise, structured with code refs; simple tasks -> lead with outcome; big changes -> logical walkthrough + rationale + next actions; casual one-offs -> plain sentences, no headers/bullets.\n- File References: When referencing files in your response follow the below rules:\n * Use inline code to make file paths clickable.\n * Each reference should have a stand alone path. Even if it's the same file.\n * Accepted: absolute, workspace-relative, a/ or b/ diff prefixes, or bare filename/suffix.\n * Optionally include line/column (1-based): :line[:column] or #Lline[Ccolumn] (column defaults to 1).\n * Do not use URIs like file://, vscode://, or https://.\n * Do not provide range of lines\n * Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\\repo\\project\\main.rs:12:5\n\nHere is some useful information about the environment you are running in:\n<env>\n Working directory: ${process.cwd()}\n Platform: darwin\n Today's date: ${new Date().toLocaleDateString()}\n</env>\n<files>\n\n</files>`;\n\nconst AGENTS_FILE_REGEX = /^agents\\.md$/i;\n\nconst loadAgentsPrompt = () => {\n try {\n const cwd = process.cwd();\n const entries = fs.readdirSync(cwd, { withFileTypes: true });\n const target = entries.find((entry) => entry.isFile() && AGENTS_FILE_REGEX.test(entry.name));\n\n if (!target) {\n return null;\n }\n\n const filePath = path.join(cwd, target.name);\n const content = fs.readFileSync(filePath, 'utf8').trim();\n\n return content.length > 0 ? content : null;\n } catch {\n return null;\n }\n};\n\nexport const generateSystemPrompt = () => {\n return loadAgentsPrompt() ?? DEFAULT_PROMPT;\n};\n\nexport default generateSystemPrompt;\n","import { pruneMessages, type ModelMessage } from \"ai\";\nimport { summarizeMessages } from \"../ai\";\nimport {\n COMPACT_TRIGGER,\n COMPACT_TARGET,\n KEEP_LAST_TURNS,\n} from \"../config/index\";\nimport type { Context, LLMProviderFactory } from \"../shared/types\";\n\ntype CompactResult = {\n didCompact: boolean;\n reason?: string;\n newMessages?: ModelMessage[];\n};\n\nconst ensureSummaryPrefix = (summary: string): string => {\n const trimmed = summary.trim();\n if (trimmed.length === 0) {\n return '';\n }\n if (trimmed.startsWith('[COMPACTED_CONTEXT]')) {\n return trimmed;\n }\n return `[COMPACTED_CONTEXT]\\n${trimmed}`;\n};\n\nconst safeStringify = (value: unknown): string => {\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nconst estimateTokens = (messages: ModelMessage[]): number => {\n let totalChars = 0;\n for (const message of messages) {\n totalChars += message.role.length;\n if (typeof message.content === 'string') {\n totalChars += message.content.length;\n } else {\n totalChars += safeStringify(message.content).length;\n }\n }\n return Math.ceil(totalChars / 4);\n};\n\nconst splitByTurns = (messages: ModelMessage[], keepLastTurns: number) => {\n const userIndices: number[] = [];\n messages.forEach((message, index) => {\n if (message.role === 'user') {\n userIndices.push(index);\n }\n });\n\n if (userIndices.length <= keepLastTurns) {\n return { oldMessages: [], recentMessages: messages };\n }\n\n const cutIndex = userIndices[userIndices.length - keepLastTurns];\n return {\n oldMessages: messages.slice(0, cutIndex),\n recentMessages: messages.slice(cutIndex),\n };\n};\n\nconst takeLastTurns = (messages: ModelMessage[], keepLastTurns: number): ModelMessage[] => {\n const userIndices: number[] = [];\n messages.forEach((message, index) => {\n if (message.role === 'user') {\n userIndices.push(index);\n }\n });\n\n if (userIndices.length === 0) {\n return messages;\n }\n\n if (userIndices.length <= keepLastTurns) {\n return messages;\n }\n\n const startIndex = userIndices[userIndices.length - keepLastTurns];\n return messages.slice(startIndex);\n};\n\nexport const maybeCompactContext = async (\n context: Context,\n options?: { force?: boolean; provider?: LLMProviderFactory; model?: string }\n): Promise<CompactResult> => {\n const { messages } = context;\n if (messages.length === 0) {\n return { didCompact: false };\n }\n\n const estimatedTokens = estimateTokens(messages);\n if (!options?.force && estimatedTokens < COMPACT_TRIGGER) {\n return { didCompact: false };\n }\n\n const { oldMessages, recentMessages } = splitByTurns(messages, KEEP_LAST_TURNS);\n if (oldMessages.length === 0) {\n return { didCompact: false };\n }\n\n try {\n const summary = await summarizeMessages(oldMessages, {\n provider: options?.provider,\n model: options?.model,\n });\n const summaryText = ensureSummaryPrefix(summary);\n if (!summaryText) {\n throw new Error('Empty summary result');\n }\n\n const nextMessages: ModelMessage[] = [\n { role: 'assistant', content: summaryText },\n ...recentMessages,\n ];\n\n if (estimateTokens(nextMessages) > COMPACT_TARGET) {\n const newMessages = takeLastTurns(messages, KEEP_LAST_TURNS);\n return { didCompact: true, reason: 'summary-too-large', newMessages };\n }\n\n return { didCompact: true, newMessages: nextMessages };\n } catch (error) {\n const pruned = pruneMessages({\n messages,\n reasoning: 'all',\n toolCalls: 'all',\n emptyMessages: 'remove',\n });\n const newMessages = takeLastTurns(pruned, KEEP_LAST_TURNS);\n return { didCompact: true, reason: 'fallback', newMessages };\n }\n};","import { ToolSet, type StepResult, type ModelMessage } from \"ai\";\nimport type { Context, ClarificationRequest, Tool, LLMProviderFactory, SystemPromptOption } from \"../shared/types\";\nimport type { EngineHookMap } from \"../plugin/EnginePlugin.js\";\nimport { streamTextAI } from \"../ai\";\nimport { maybeCompactContext } from \"../context\";\nimport {\n MAX_COMPACTION_ATTEMPTS,\n MAX_ERROR_COUNT,\n MAX_STEPS\n} from \"../config/index.js\";\n\n/**\n * Hook arrays passed into the loop by Engine.\n * Each array may contain handlers from multiple plugins + EngineOptions.\n */\nexport interface LoopHooks {\n beforeLLMCall?: Array<EngineHookMap['beforeLLMCall']>;\n afterLLMCall?: Array<EngineHookMap['afterLLMCall']>;\n beforeToolCall?: Array<EngineHookMap['beforeToolCall']>;\n afterToolCall?: Array<EngineHookMap['afterToolCall']>;\n}\n\nexport interface LoopOptions {\n onText?: (delta: string) => void;\n onToolCall?: (toolCall: any) => void;\n onToolResult?: (toolResult: any) => void;\n onStepFinish?: (step: StepResult<any>) => void;\n onClarificationRequest?: (request: ClarificationRequest) => Promise<string>;\n onCompacted?: (newMessages: ModelMessage[]) => void;\n onResponse?: (messages: StepResult<ToolSet>['response']['messages']) => void;\n abortSignal?: AbortSignal;\n\n tools?: Record<string, Tool>;\n\n /** Custom LLM provider factory. Overrides the default provider when set. */\n provider?: LLMProviderFactory;\n /** Model name passed to the provider. Overrides DEFAULT_MODEL when set. */\n model?: string;\n /** Custom system prompt. See SystemPromptOption for the three supported forms. */\n systemPrompt?: SystemPromptOption;\n\n /** Engine hook arrays – managed by Engine, not by callers directly. */\n hooks?: LoopHooks;\n}\n\n/** Wraps tools so each execute() passes through beforeToolCall / afterToolCall hooks. */\nfunction wrapToolsWithHooks(\n tools: Record<string, Tool>,\n beforeHooks: Array<EngineHookMap['beforeToolCall']>,\n afterHooks: Array<EngineHookMap['afterToolCall']>,\n): Record<string, Tool> {\n const wrapped: Record<string, Tool> = {};\n for (const [name, t] of Object.entries(tools)) {\n wrapped[name] = {\n ...t,\n execute: async (input: any, ctx: any) => {\n // Run all beforeToolCall hooks sequentially\n let finalInput = input;\n for (const hook of beforeHooks) {\n const result = await hook({ name, input: finalInput });\n if (result && 'input' in result) {\n finalInput = result.input;\n }\n }\n\n const output = await t.execute(finalInput, ctx);\n\n // Run all afterToolCall hooks sequentially\n let finalOutput = output;\n for (const hook of afterHooks) {\n const result = await hook({ name, input: finalInput, output: finalOutput });\n if (result && 'output' in result) {\n finalOutput = result.output;\n }\n }\n\n return finalOutput;\n },\n };\n }\n return wrapped;\n}\n\nexport async function loop(context: Context, options?: LoopOptions): Promise<string> {\n let errorCount = 0;\n let totalSteps = 0;\n let compactionAttempts = 0;\n\n const loopHooks = options?.hooks ?? {};\n\n while (true) {\n try {\n if (options?.abortSignal?.aborted) {\n return 'Request aborted.';\n }\n\n if (compactionAttempts < MAX_COMPACTION_ATTEMPTS) {\n const { didCompact, newMessages } = await maybeCompactContext(context, {\n provider: options?.provider,\n model: options?.model,\n });\n if (didCompact) {\n compactionAttempts++;\n\n if (newMessages) {\n options?.onCompacted?.(newMessages)\n }\n continue;\n }\n }\n\n if (options?.abortSignal?.aborted) {\n return 'Request aborted.';\n }\n\n let tools = options?.tools || {};\n let systemPrompt = options?.systemPrompt;\n\n // --- beforeLLMCall hooks ---\n if (loopHooks.beforeLLMCall?.length) {\n for (const hook of loopHooks.beforeLLMCall) {\n const result = await hook({ context, systemPrompt, tools });\n if (result) {\n if ('systemPrompt' in result && result.systemPrompt !== undefined) {\n systemPrompt = result.systemPrompt;\n }\n if ('tools' in result && result.tools !== undefined) {\n tools = result.tools;\n }\n }\n }\n }\n\n // Wrap tools with beforeToolCall / afterToolCall hooks\n const beforeToolHooks = loopHooks.beforeToolCall ?? [];\n const afterToolHooks = loopHooks.afterToolCall ?? [];\n if (beforeToolHooks.length || afterToolHooks.length) {\n tools = wrapToolsWithHooks(tools, beforeToolHooks, afterToolHooks);\n }\n\n // Prepare tool execution context\n const toolExecutionContext = {\n onClarificationRequest: options?.onClarificationRequest,\n abortSignal: options?.abortSignal\n };\n\n if (options?.abortSignal?.aborted) {\n return 'Request aborted.';\n }\n\n const result = streamTextAI(context.messages, tools, {\n abortSignal: options?.abortSignal,\n toolExecutionContext,\n provider: options?.provider,\n model: options?.model,\n systemPrompt,\n onStepFinish: (step) => {\n options?.onStepFinish?.(step);\n },\n onChunk: ({ chunk }) => {\n if (chunk.type === 'text-delta') {\n options?.onText?.(chunk.text);\n }\n if (chunk.type === 'tool-call') {\n options?.onToolCall?.(chunk);\n }\n if (chunk.type === 'tool-result') {\n options?.onToolResult?.(chunk);\n }\n },\n });\n\n const [text, steps, finishReason] = await Promise.all([\n result.text,\n result.steps,\n result.finishReason,\n ]);\n\n totalSteps += steps.length;\n\n for (const step of steps) {\n if (step.response?.messages?.length) {\n const messages = [...step.response.messages];\n options?.onResponse?.(messages);\n }\n }\n\n // --- afterLLMCall hooks ---\n if (loopHooks.afterLLMCall?.length) {\n for (const hook of loopHooks.afterLLMCall) {\n await hook({ context, finishReason, text });\n }\n }\n\n if (options?.abortSignal?.aborted) {\n return 'Request aborted.';\n }\n\n if (finishReason === 'stop') {\n if (!text) {\n continue;\n }\n return text || 'Task completed.';\n }\n\n if (finishReason === 'length') {\n if (compactionAttempts < MAX_COMPACTION_ATTEMPTS) {\n const { didCompact, newMessages } = await maybeCompactContext(context, {\n force: true,\n provider: options?.provider,\n model: options?.model,\n });\n if (didCompact) {\n compactionAttempts++;\n if (newMessages) {\n options?.onCompacted?.(newMessages)\n }\n continue;\n }\n }\n return text || 'Context limit reached.';\n }\n\n if (finishReason === 'content-filter') {\n return text || 'Content filtered.';\n }\n\n if (finishReason === 'error') {\n return text || 'Task failed.';\n }\n\n if (finishReason === 'tool-calls') {\n if (totalSteps >= MAX_STEPS) {\n return text || 'Max steps reached, task may be incomplete.';\n }\n continue;\n }\n\n if (!text) {\n continue;\n }\n\n return text || 'Task completed.';\n } catch (error: any) {\n if (options?.abortSignal?.aborted || error?.name === 'AbortError') {\n return 'Request aborted.';\n }\n\n errorCount++;\n if (errorCount >= MAX_ERROR_COUNT) {\n return `Failed after ${errorCount} errors: ${error?.message ?? String(error)}`;\n }\n\n if (isRetryableError(error)) {\n const delay = Math.min(2000 * Math.pow(2, errorCount - 1), 30000);\n await sleep(delay, options?.abortSignal);\n continue;\n }\n\n return `Error: ${error?.message ?? String(error)}`;\n }\n }\n}\n\nfunction isRetryableError(error: any): boolean {\n const status = error?.status ?? error?.statusCode;\n return status === 429 || status === 500 || status === 502 || status === 503;\n}\n\nfunction sleep(ms: number, abortSignal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (abortSignal?.aborted) {\n const abortError = new Error('Aborted');\n abortError.name = 'AbortError';\n reject(abortError);\n return;\n }\n\n let timeoutId: ReturnType<typeof setTimeout>;\n\n const onAbort = () => {\n clearTimeout(timeoutId);\n if (abortSignal) {\n abortSignal.removeEventListener('abort', onAbort);\n }\n const abortError = new Error('Aborted');\n abortError.name = 'AbortError';\n reject(abortError);\n };\n\n timeoutId = setTimeout(() => {\n if (abortSignal) {\n abortSignal.removeEventListener('abort', onAbort);\n }\n resolve();\n }, ms);\n\n if (abortSignal) {\n abortSignal.addEventListener('abort', onAbort, { once: true });\n }\n });\n}\n","import z from \"zod\";\nimport { readFileSync, existsSync, statSync } from \"fs\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const ReadTool: Tool<\n { filePath: string; offset?: number; limit?: number },\n { content: string; totalLines?: number }\n> = {\n name: 'read',\n description: 'Read the contents of a file. Supports reading specific line ranges with offset and limit.',\n inputSchema: z.object({\n filePath: z.string().describe('The absolute path to the file to read'),\n offset: z.number().optional().describe('The line number to start reading from (0-based). Only provide if the file is too large to read at once.'),\n limit: z.number().optional().describe('The number of lines to read. Only provide if the file is too large to read at once.'),\n }),\n execute: async ({ filePath, offset, limit }) => {\n // Check if file exists\n if (!existsSync(filePath)) {\n throw new Error(`File does not exist: ${filePath}`);\n }\n\n // Check if it's a directory\n const stats = statSync(filePath);\n if (stats.isDirectory()) {\n throw new Error(`Cannot read directory: ${filePath}. Use 'ls' tool to list directory contents.`);\n }\n\n // Read the entire file\n const content = readFileSync(filePath, 'utf-8');\n const lines = content.split('\\n');\n const totalLines = lines.length;\n\n // If no offset/limit specified, return the entire file\n if (offset === undefined && limit === undefined) {\n return {\n content: truncateOutput(content),\n totalLines,\n };\n }\n\n // Apply offset and limit\n const startLine = offset || 0;\n const endLine = limit ? startLine + limit : lines.length;\n\n // Validate range\n if (startLine < 0 || startLine >= totalLines) {\n throw new Error(`Invalid offset: ${startLine}. File has ${totalLines} lines.`);\n }\n\n // Extract the requested lines\n const selectedLines = lines.slice(startLine, endLine);\n\n // Format with line numbers (1-based for display)\n const numberedContent = selectedLines\n .map((line, idx) => {\n const lineNum = startLine + idx + 1;\n return `${String(lineNum).padStart(6, ' ')}→${line}`;\n })\n .join('\\n');\n\n return {\n content: truncateOutput(numberedContent),\n totalLines,\n };\n },\n};\n\nexport default ReadTool;\n","import { MAX_TOOL_OUTPUT_LENGTH } from \"../config\";\n\nexport const truncateOutput = (output: string): string => {\n if (output.length <= MAX_TOOL_OUTPUT_LENGTH) {\n return output;\n }\n\n const half = Math.floor(MAX_TOOL_OUTPUT_LENGTH / 2);\n const removed = output.length - MAX_TOOL_OUTPUT_LENGTH;\n\n return (\n output.slice(0, half) +\n `\\n\\n... [truncated ${removed} characters] ...\\n\\n` +\n output.slice(-half)\n );\n};\n","import z from \"zod\";\nimport { writeFileSync, mkdirSync, existsSync } from \"fs\";\nimport { dirname } from \"path\";\nimport type { Tool } from \"../shared/types\";\n\nexport const WriteTool: Tool<\n { filePath: string; content: string },\n { success: boolean; created: boolean; bytes: number }\n> = {\n name: 'write',\n description: 'Write contents to a file. Automatically creates parent directories if they do not exist. Will overwrite existing files.',\n inputSchema: z.object({\n filePath: z.string().describe('The absolute path to the file to write (must be absolute, not relative)'),\n content: z.string().describe('The content to write to the file'),\n }),\n execute: async ({ filePath, content }) => {\n // Check if file already exists\n const fileExists = existsSync(filePath);\n\n // Get the directory path\n const dir = dirname(filePath);\n\n // Create parent directories if they don't exist\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n\n // Write the file\n writeFileSync(filePath, content, 'utf-8');\n\n // Calculate bytes written\n const bytes = Buffer.byteLength(content, 'utf-8');\n\n return {\n success: true,\n created: !fileExists,\n bytes,\n };\n },\n};\n\nexport default WriteTool;\n","import z from \"zod\";\nimport { readFileSync, writeFileSync } from \"fs\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const EditTool: Tool<\n { filePath: string; oldString: string; newString: string; replaceAll?: boolean },\n { success: boolean; replacements: number; preview?: string }\n> = {\n name: 'edit',\n description: 'Performs exact string replacements in files. Use this to edit existing files by replacing old_string with new_string.',\n inputSchema: z.object({\n filePath: z.string().describe('The absolute path to the file to modify'),\n oldString: z.string().describe('The exact text to replace (must match exactly)'),\n newString: z.string().describe('The text to replace it with (must be different from old_string)'),\n replaceAll: z.boolean().optional().default(false).describe('Replace all occurrences of old_string (default false)'),\n }),\n execute: async ({ filePath, oldString, newString, replaceAll = false }) => {\n // Validate that old and new strings are different\n if (oldString === newString) {\n throw new Error('old_string and new_string must be different');\n }\n\n // Read the file\n const content = readFileSync(filePath, 'utf-8');\n\n // Check if oldString exists in the file\n if (!content.includes(oldString)) {\n throw new Error(`old_string not found in file: ${filePath}`);\n }\n\n let newContent: string;\n let replacements = 0;\n\n if (replaceAll) {\n // Replace all occurrences\n const parts = content.split(oldString);\n replacements = parts.length - 1;\n newContent = parts.join(newString);\n } else {\n // Replace only the first occurrence\n const index = content.indexOf(oldString);\n if (index === -1) {\n throw new Error(`old_string not found in file: ${filePath}`);\n }\n\n // Check if the string is unique (appears only once)\n const secondIndex = content.indexOf(oldString, index + oldString.length);\n if (secondIndex !== -1) {\n throw new Error(\n 'old_string is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use replace_all to change every instance.'\n );\n }\n\n newContent = content.slice(0, index) + newString + content.slice(index + oldString.length);\n replacements = 1;\n }\n\n // Write the modified content back\n writeFileSync(filePath, newContent, 'utf-8');\n\n // Generate a preview of the changes (show the changed section with context)\n const changedIndex = newContent.indexOf(newString);\n const contextLength = 200;\n const start = Math.max(0, changedIndex - contextLength);\n const end = Math.min(newContent.length, changedIndex + newString.length + contextLength);\n const preview = truncateOutput(\n `...${newContent.slice(start, end)}...`\n );\n\n return {\n success: true,\n replacements,\n preview,\n };\n },\n};\n\nexport default EditTool;\n","import z from \"zod\";\nimport { execSync } from \"child_process\";\nimport { existsSync } from \"fs\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const GrepTool: Tool<\n {\n pattern: string;\n path?: string;\n glob?: string;\n type?: string;\n outputMode?: 'content' | 'files_with_matches' | 'count';\n context?: number;\n caseInsensitive?: boolean;\n headLimit?: number;\n offset?: number;\n multiline?: boolean;\n },\n { output: string; matches?: number }\n> = {\n name: 'grep',\n description: 'A powerful search tool built on ripgrep. Supports regex patterns, file filtering, and multiple output modes.',\n inputSchema: z.object({\n pattern: z.string().describe('The regular expression pattern to search for in file contents'),\n path: z.string().optional().describe('File or directory to search in. Defaults to current working directory.'),\n glob: z.string().optional().describe('Glob pattern to filter files (e.g. \"*.js\", \"*.{ts,tsx}\")'),\n type: z.string().optional().describe('File type to search (e.g., js, py, rust, go, java, ts, tsx, json, md)'),\n outputMode: z.enum(['content', 'files_with_matches', 'count']).optional().default('files_with_matches')\n .describe('Output mode: \"content\" shows matching lines, \"files_with_matches\" shows file paths, \"count\" shows match counts'),\n context: z.number().optional().describe('Number of lines to show before and after each match (only with output_mode: \"content\")'),\n caseInsensitive: z.boolean().optional().default(false).describe('Case insensitive search'),\n headLimit: z.number().optional().default(0).describe('Limit output to first N lines/entries. 0 means unlimited.'),\n offset: z.number().optional().default(0).describe('Skip first N lines/entries before applying head_limit'),\n multiline: z.boolean().optional().default(false).describe('Enable multiline mode where patterns can span lines'),\n }),\n execute: async ({\n pattern,\n path = '.',\n glob,\n type,\n outputMode = 'files_with_matches',\n context,\n caseInsensitive = false,\n headLimit = 0,\n offset = 0,\n multiline = false,\n }) => {\n // Build ripgrep command\n const args: string[] = ['rg'];\n\n // Pattern\n args.push(pattern);\n\n // Case sensitivity\n if (caseInsensitive) {\n args.push('-i');\n }\n\n // Output mode\n if (outputMode === 'files_with_matches') {\n args.push('-l'); // --files-with-matches\n } else if (outputMode === 'count') {\n args.push('-c'); // --count\n } else if (outputMode === 'content') {\n args.push('-n'); // Show line numbers\n if (context !== undefined) {\n args.push(`-C${context}`);\n }\n }\n\n // Multiline mode\n if (multiline) {\n args.push('-U'); // --multiline\n args.push('--multiline-dotall');\n }\n\n // File filtering\n if (glob) {\n args.push('--glob', glob);\n }\n if (type) {\n args.push('--type', type);\n }\n\n // Path\n if (path && path !== '.') {\n // Verify path exists\n if (!existsSync(path)) {\n throw new Error(`Path does not exist: ${path}`);\n }\n args.push(path);\n }\n\n // Build the command string\n let command = args.map(arg => {\n // Quote arguments that contain spaces or special characters\n if (arg.includes(' ') || arg.includes('$') || arg.includes('*')) {\n return `'${arg.replace(/'/g, \"'\\\\''\")}'`;\n }\n return arg;\n }).join(' ');\n\n // Add tail/head for offset/limit\n if (offset > 0) {\n command += ` | tail -n +${offset + 1}`;\n }\n if (headLimit > 0) {\n command += ` | head -n ${headLimit}`;\n }\n\n try {\n const output = execSync(command, {\n encoding: 'utf-8',\n maxBuffer: 1024 * 1024 * 10, // 10MB\n shell: '/bin/bash',\n });\n\n // Count matches for count mode\n let matches: number | undefined;\n if (outputMode === 'count') {\n matches = output.split('\\n').filter(line => line.trim()).length;\n } else if (outputMode === 'files_with_matches') {\n matches = output.split('\\n').filter(line => line.trim()).length;\n }\n\n return {\n output: truncateOutput(output || '(no matches found)'),\n matches,\n };\n } catch (error: any) {\n // Exit code 1 means no matches found (not an error)\n if (error.status === 1) {\n return {\n output: '(no matches found)',\n matches: 0,\n };\n }\n\n // Other errors\n throw new Error(\n `grep failed: ${error.stderr || error.message}\\nCommand: ${command}`\n );\n }\n },\n};\n\nexport default GrepTool;\n","import z from \"zod\";\nimport { readdirSync } from \"fs\";\nimport type { Tool } from \"../shared/types\";\n\nexport const LsTool: Tool<\n { path?: string },\n { files: string[] }\n> = {\n name: 'ls',\n description: 'List files and directories in a given path',\n inputSchema: z.object({\n path: z.string().optional().describe('The path to list files from (defaults to current directory)'),\n }),\n execute: async ({ path = '.' }) => {\n const files = readdirSync(path);\n return { files };\n },\n};\n\nexport default LsTool;\n","import z from \"zod\";\nimport { execSync } from \"child_process\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const BashTool: Tool<\n { command: string; timeout?: number; cwd?: string; description?: string },\n { output: string; error?: string; exitCode?: number }\n> = {\n name: 'bash',\n description: 'Execute a bash command and return the output. Supports timeout and working directory configuration.',\n inputSchema: z.object({\n command: z.string().describe('The bash command to execute'),\n timeout: z.number().optional().describe('Optional timeout in milliseconds (max 600000ms / 10 minutes). Defaults to 120000ms (2 minutes).'),\n cwd: z.string().optional().describe('Optional working directory for command execution. Defaults to current directory.'),\n description: z.string().optional().describe('Optional description of what this command does (for logging/debugging)'),\n }),\n execute: async ({ command, timeout = 120000, cwd, description }) => {\n // Validate timeout\n if (timeout && (timeout < 0 || timeout > 600000)) {\n throw new Error('Timeout must be between 0 and 600000ms (10 minutes)');\n }\n\n try {\n const output = execSync(command, {\n encoding: 'utf-8',\n maxBuffer: 1024 * 1024 * 10, // 10MB\n timeout: timeout || 120000,\n cwd: cwd || process.cwd(),\n shell: '/bin/bash',\n });\n return {\n output: truncateOutput(output || '(command completed with no output)'),\n exitCode: 0,\n };\n } catch (error: any) {\n const exitCode = error.status || error.code || 1;\n const stdout = String(error.stdout || '');\n const stderr = String(error.stderr || error.message || '');\n\n // Check if it's a timeout error\n if (error.killed && error.signal === 'SIGTERM') {\n return {\n output: truncateOutput(stdout),\n error: truncateOutput(`Command timed out after ${timeout}ms\\n${stderr}`),\n exitCode,\n };\n }\n\n return {\n output: truncateOutput(stdout),\n error: truncateOutput(stderr),\n exitCode,\n };\n }\n },\n};\n\nexport default BashTool;\n","import z from \"zod\";\nimport type { Tool } from \"../shared/types\";\nimport { truncateOutput } from \"./utils\";\n\nexport const TavilyTool: Tool<\n { query: string; maxResults?: number },\n { results: Array<{ title: string; url: string; content: string; score?: number }> }\n> = {\n name: 'tavily',\n description: 'Search the web using Tavily API',\n inputSchema: z.object({\n query: z.string().describe('The search query'),\n maxResults: z.number().optional().default(5).describe('Maximum number of results to return'),\n }),\n execute: async ({ query, maxResults = 5 }) => {\n const apiKey = process.env.TAVILY_API_KEY;\n\n if (!apiKey) {\n throw new Error('TAVILY_API_KEY environment variable is not set');\n }\n\n const response = await fetch('https://api.tavily.com/search', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n api_key: apiKey,\n query,\n max_results: maxResults,\n search_depth: 'basic',\n include_answer: false,\n include_raw_content: false,\n include_images: false,\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Tavily API error: ${response.status} ${response.statusText}`);\n }\n\n const data = await response.json();\n\n return {\n results: data.results?.map((result: any) => ({\n title: result.title || '',\n url: result.url || '',\n content: truncateOutput(result.content || ''),\n score: result.score || 0,\n })) || [],\n };\n },\n};\n\nexport default TavilyTool;\n","import z from \"zod\";\nimport type { Tool, ToolExecutionContext } from \"../shared/types\";\nimport { CLARIFICATION_TIMEOUT } from \"../config/index.js\";\nimport { randomUUID } from \"crypto\";\n\nexport interface ClarifyInput {\n question: string;\n context?: string;\n defaultAnswer?: string;\n timeout?: number;\n}\n\nexport interface ClarifyOutput {\n answer: string;\n timedOut: boolean;\n}\n\nexport const ClarifyTool: Tool<ClarifyInput, ClarifyOutput> = {\n name: 'clarify',\n description: 'Ask the user a clarifying question and wait for their response. Use this when you need information from the user to proceed with the task.',\n inputSchema: z.object({\n question: z.string().describe('The question to ask the user'),\n context: z.string().optional().describe('Additional context to help the user answer'),\n defaultAnswer: z.string().optional().describe('Default answer if user does not respond within timeout'),\n timeout: z.number().optional().describe('Timeout in milliseconds (default: 5 minutes)')\n }),\n execute: async (input, toolContext) => {\n if (!toolContext?.onClarificationRequest) {\n throw new Error('Clarification is not supported in this context. The clarify tool requires a CLI interface with user interaction.');\n }\n\n const timeout = input.timeout ?? CLARIFICATION_TIMEOUT;\n const requestId = randomUUID();\n\n try {\n // Create a promise that rejects on timeout\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => {\n reject(new Error(`Clarification request timed out after ${timeout}ms`));\n }, timeout);\n });\n\n // Race between user response and timeout\n const answer = await Promise.race([\n toolContext.onClarificationRequest({\n id: requestId,\n question: input.question,\n context: input.context,\n defaultAnswer: input.defaultAnswer,\n timeout\n }),\n timeoutPromise\n ]);\n\n return {\n answer,\n timedOut: false\n };\n } catch (error: any) {\n // If timeout occurred and we have a default answer, use it\n if (error?.message?.includes('timed out') && input.defaultAnswer) {\n return {\n answer: input.defaultAnswer,\n timedOut: true\n };\n }\n\n // Otherwise, re-throw the error\n throw error;\n }\n },\n};\n\nexport default ClarifyTool;\n","import { ReadTool } from './read';\nimport { WriteTool } from './write';\nimport { EditTool } from './edit';\nimport { GrepTool } from './grep';\nimport { LsTool } from './ls';\nimport { BashTool } from './bash';\nimport { TavilyTool } from './tavily';\nimport { ClarifyTool } from './clarify';\nimport { Tool } from 'ai';\n// import { SkillTool } from './skill;\n\nexport const BuiltinTools = [\n ReadTool,\n WriteTool,\n EditTool,\n GrepTool,\n LsTool,\n BashTool,\n TavilyTool,\n ClarifyTool,\n] as const;\n\nexport const BuiltinToolsMap = BuiltinTools.reduce((acc, toolInstance) => {\n acc[toolInstance.name] = toolInstance;\n return acc;\n}, {} as Record<string, any>);\n\nexport const getFinalToolsMap = (customTools?: Record<string, Tool>) => {\n if (!customTools) {\n return BuiltinToolsMap;\n }\n return { ...BuiltinToolsMap, ...customTools };\n};\n\nexport {\n ReadTool,\n WriteTool,\n EditTool,\n GrepTool,\n LsTool,\n BashTool,\n TavilyTool,\n ClarifyTool,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,iBAAgC;AAChC,gBAAyC;AACzC,WAAsB;AAMtB,eAAsB,cAAc,KAAuC;AAEzE,QAAM,gBAAqB,UAAK,KAAK,gBAAgB,UAAU;AAC/D,QAAM,mBAAwB,UAAK,KAAK,UAAU,UAAU;AAC5D,QAAM,iBAAa,sBAAW,aAAa,IAAI,gBAAgB;AAE/D,MAAI,KAAC,sBAAW,UAAU,GAAG;AAC3B,WAAO,EAAE,SAAS,CAAC,EAAE;AAAA,EACvB;AAEA,MAAI;AACF,UAAM,cAAU,wBAAa,YAAY,OAAO;AAChD,UAAM,SAAS,KAAK,MAAM,OAAO;AAEjC,QAAI,CAAC,OAAO,WAAW,OAAO,OAAO,YAAY,UAAU;AACzD,cAAQ,KAAK,gDAAgD;AAC7D,aAAO,EAAE,SAAS,CAAC,EAAE;AAAA,IACvB;AAEA,WAAO,EAAE,SAAS,OAAO,QAAQ;AAAA,EACnC,SAAS,OAAO;AACd,YAAQ,KAAK,gCAAgC,iBAAiB,QAAQ,MAAM,UAAU,eAAe,EAAE;AACvG,WAAO,EAAE,SAAS,CAAC,EAAE;AAAA,EACvB;AACF;AAEA,SAAS,oBAAoB,QAAyB;AACpD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,KAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAiC;AAAA,EAC5C,MAAM;AAAA,EACN,SAAS;AAAA,EAET,MAAM,WAA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MAChD,CAAC;AAAA,MACD,SAAS,OAAO,EAAE,MAAM,SAAS,YAAY,MAAuD;AAGlG,cAAM,QAAQ,EAAE,GAAG,iBAAiB,GAAG,QAAQ,SAAS,EAAE;AAC1D,YAAI;AACF,kBAAQ,OAAO,KAAK,iBAAiB,OAAO,IAAI,KAAK,IAAI,EAAE;AAC3D,gBAAM,SAAS,MAAM,KAAK,YAAY,SAAS,QAAQ,MAAM,aAAa,KAAK;AAC/E,kBAAQ,OAAO,KAAK,SAAS,OAAO,IAAI,yBAAyB;AACjE,iBAAO;AAAA,QACT,SAAS,OAAO;AACd,kBAAQ,OAAO,MAAM,SAAS,OAAO,IAAI,WAAW,KAAc;AAClE,gBAAM,IAAI,MAAM,SAAS,OAAO,IAAI,YAAY,KAAK,EAAE;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAEA,YAAQ,aAAa,UAAUA,KAAI;AAAA,EACrC;AAAA,EAEA,MAAM,QAAQ,SAA6C;AACzD,YAAQ,OAAO,KAAK,0BAA0B;AAAA,EAChD;AACF;;;AL7KO,IAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,IAAI,eAAe;AACrB;AAwBA,IAAO,mBAAQ;","names":["tool","import_fs","matter","import_fs","import_os","import_zod","path","fs","import_zod","import_fs","import_path","dotenv","import_fs","import_path","fs","path","tool","import_ai","result","import_zod","import_fs","z","import_zod","import_fs","import_path","z","import_zod","import_fs","z","import_zod","import_fs","z","path","import_zod","import_fs","z","path","import_zod","import_child_process","z","import_zod","z","import_zod","import_crypto","z","fs","path","tool"]}
|