fix(agent-core-v2): gate skill prompt injection

This commit is contained in:
_Kerman 2026-07-09 12:58:07 +08:00
parent 1f530d41a3
commit 14626234a4
3 changed files with 10 additions and 6 deletions

View file

@ -41,5 +41,5 @@ registerAgentProfile({
whenToUse:
'Use this agent when the parent agent needs a step-by-step implementation plan, key file identification, and architectural trade-off analysis before code changes are made.',
tools: PLAN_TOOLS,
systemPrompt: (context) => renderSystemPrompt(PLAN_ROLE, context),
systemPrompt: (context) => renderSystemPrompt(PLAN_ROLE, context, PLAN_TOOLS),
});

View file

@ -18,7 +18,11 @@ export const TASK_AGENT_ROLE_PREFIX =
'You must treat the parent agent as your caller. Do not directly ask the end user questions. ' +
'If something is unclear, explain the ambiguity in your final summary to the parent agent.';
export function renderSystemPrompt(roleAdditional: string, context: AgentProfileContext): string {
export function renderSystemPrompt(
roleAdditional: string,
context: AgentProfileContext,
tools: readonly string[],
): string {
const shellName = context.shellName ?? '';
const shellPath = context.shellPath ?? '';
return renderPrompt(SYSTEM_PROMPT_TEMPLATE, {
@ -30,6 +34,6 @@ export function renderSystemPrompt(roleAdditional: string, context: AgentProfile
KIMI_WORK_DIR_LS: context.cwdListing ?? '',
KIMI_AGENTS_MD: context.agentsMd ?? '',
KIMI_ADDITIONAL_DIRS_INFO: context.additionalDirsInfo ?? '',
KIMI_SKILLS: context.skills ?? '',
KIMI_SKILLS: tools.includes('Skill') ? (context.skills ?? '') : '',
});
}

View file

@ -101,7 +101,7 @@ registerAgentProfile({
name: 'agent',
description: 'Default Kimi Code agent',
tools: AGENT_TOOLS,
systemPrompt: (context) => renderSystemPrompt('', context),
systemPrompt: (context) => renderSystemPrompt('', context, AGENT_TOOLS),
});
registerAgentProfile({
@ -110,7 +110,7 @@ registerAgentProfile({
whenToUse:
'Use this agent for non-trivial software engineering work that may require reading files, editing code, running commands, and returning a compact but technically complete summary to the parent agent.',
tools: CODER_TOOLS,
systemPrompt: (context) => renderSystemPrompt(CODER_ROLE, context),
systemPrompt: (context) => renderSystemPrompt(CODER_ROLE, context, CODER_TOOLS),
summaryPolicy: DEFAULT_SUMMARY_POLICY,
});
@ -120,7 +120,7 @@ registerAgentProfile({
whenToUse:
'Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (e.g. "src/**/*.yaml"), search code for keywords (e.g. "database connection"), or answer questions about the codebase (e.g. "how does the auth module work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "thorough" for comprehensive analysis across multiple locations and naming conventions. Use this agent for any read-only exploration that will clearly require more than 3 search queries. Prefer launching multiple explore agents concurrently when investigating independent questions.',
tools: EXPLORE_TOOLS,
systemPrompt: (context) => renderSystemPrompt(EXPLORE_ROLE, context),
systemPrompt: (context) => renderSystemPrompt(EXPLORE_ROLE, context, EXPLORE_TOOLS),
promptPrefix: async ({ cwd, runner, log }) => {
try {
return await collectGitContext(runner, cwd, log);