autosnippet
Version:
Extract code patterns into a knowledge base for AI coding assistants
400 lines (399 loc) • 10.7 kB
TypeScript
/**
* composite.js — 组合工具 + 元工具 (6)
*
* 34. analyze_code Guard + Recipe 搜索组合
* 35. knowledge_overview 知识库全貌一次获取
* 36. submit_with_check 查重 + 提交组合
* ── get_tool_details 元工具: 查询工具 Schema
* ── plan_task 元工具: 任务规划
* ── review_my_output 元工具: 自我质量审查
*/
import { type ToolHandlerContext } from './_shared.js';
export interface AnalyzeCodeParams {
code: string;
language?: string;
filePath?: string;
}
export interface KnowledgeOverviewParams {
includeTopRecipes?: boolean;
limit?: number;
}
export interface SubmitWithCheckParams {
content?: {
markdown?: string;
pattern?: string;
rationale?: string;
[key: string]: unknown;
};
title?: string;
description?: string;
trigger?: string;
kind?: string;
topicHint?: string;
whenClause?: string;
doClause?: string;
dontClause?: string;
coreCode?: string;
tags?: string[];
reasoning?: {
whyStandard?: string;
sources?: string[];
confidence?: number;
};
headers?: string[];
usageGuide?: string;
scope?: string;
complexity?: string;
sourceFile?: string;
threshold?: number;
knowledgeType?: string;
/** 被替代的旧 Recipe ID(进化架构入口) */
supersedes?: string;
[key: string]: unknown;
}
export interface PlanTaskParams {
steps?: Array<{
id: number;
action: string;
tool?: string;
depends_on?: number[];
}>;
strategy?: string;
estimated_iterations?: number;
}
export interface ReviewMyOutputParams {
check_rules?: string[];
}
export declare const analyzeCode: {
name: string;
description: string;
parameters: {
type: string;
properties: {
code: {
type: string;
description: string;
};
language: {
type: string;
description: string;
};
filePath: {
type: string;
description: string;
};
};
required: string[];
};
handler: (params: AnalyzeCodeParams, ctx: ToolHandlerContext) => Promise<Record<string, unknown>>;
};
export declare const knowledgeOverview: {
name: string;
description: string;
parameters: {
type: string;
properties: {
includeTopRecipes: {
type: string;
description: string;
};
limit: {
type: string;
description: string;
};
};
};
handler: (params: KnowledgeOverviewParams, ctx: ToolHandlerContext) => Promise<Record<string, unknown>>;
};
export declare const submitWithCheck: {
name: string;
description: string;
parameters: {
type: string;
properties: {
content: {
type: string;
description: string;
};
title: {
type: string;
description: string;
};
description: {
type: string;
description: string;
};
trigger: {
type: string;
description: string;
};
kind: {
type: string;
enum: string[];
};
topicHint: {
type: string;
enum: string[];
};
whenClause: {
type: string;
description: string;
};
doClause: {
type: string;
description: string;
};
dontClause: {
type: string;
description: string;
};
coreCode: {
type: string;
description: string;
};
tags: {
type: string;
items: {
type: string;
};
};
reasoning: {
type: string;
description: string;
};
headers: {
type: string;
items: {
type: string;
};
description: string;
};
usageGuide: {
type: string;
description: string;
};
scope: {
type: string;
enum: string[];
description: string;
};
complexity: {
type: string;
enum: string[];
description: string;
};
sourceFile: {
type: string;
description: string;
};
threshold: {
type: string;
description: string;
};
supersedes: {
type: string;
description: string;
};
};
required: string[];
};
handler: (params: SubmitWithCheckParams, ctx: ToolHandlerContext) => Promise<{
submitted: boolean;
status: string;
reason: string;
errors: string[];
warnings: string[];
_meta: {
confidence: string;
hint: string;
};
error?: undefined;
similar?: undefined;
highestSimilarity?: undefined;
} | {
submitted: boolean;
reason: string;
error: string;
status?: undefined;
errors?: undefined;
warnings?: undefined;
_meta?: undefined;
similar?: undefined;
highestSimilarity?: undefined;
} | {
submitted: boolean;
reason: string;
similar: {
file: string;
title: string;
similarity: number;
}[];
highestSimilarity: number;
_meta: {
confidence: string;
hint: string;
};
status?: undefined;
errors?: undefined;
warnings?: undefined;
error?: undefined;
} | {
_meta: {
confidence: string;
hint: string;
};
_supersedeProposal?: {
proposalId: string;
} | undefined;
submitted: boolean;
entry: unknown;
similar: {
file: string;
title: string;
similarity: number;
}[];
status?: undefined;
reason?: undefined;
errors?: undefined;
warnings?: undefined;
error?: undefined;
highestSimilarity?: undefined;
}>;
};
/**
* get_tool_details — 查询工具的完整参数 schema
*
* 与 Cline .clinerules 按需加载类似:
* System Prompt 只包含工具名+一行描述,LLM 需要调用某个工具前
* 先通过此元工具获取完整参数定义,避免 prompt 过长浪费 token。
*/
export declare const getToolDetails: {
name: string;
description: string;
parameters: {
type: string;
properties: {
toolName: {
type: string;
description: string;
};
};
required: string[];
};
handler: ({ toolName }: {
toolName: string;
}, context: ToolHandlerContext) => Promise<{
error: string;
availableTools?: undefined;
name?: undefined;
description?: undefined;
parameters?: undefined;
} | {
error: string;
availableTools: any;
name?: undefined;
description?: undefined;
parameters?: undefined;
} | {
name: any;
description: any;
parameters: any;
error?: undefined;
availableTools?: undefined;
}>;
};
export declare const planTask: {
name: string;
description: string;
parameters: {
type: string;
properties: {
steps: {
type: string;
description: string;
items: {
type: string;
properties: {
id: {
type: string;
description: string;
};
action: {
type: string;
description: string;
};
tool: {
type: string;
description: string;
};
depends_on: {
type: string;
items: {
type: string;
};
description: string;
};
};
required: string[];
};
};
strategy: {
type: string;
description: string;
};
estimated_iterations: {
type: string;
description: string;
};
};
required: string[];
};
handler: (params: PlanTaskParams, context: ToolHandlerContext) => Promise<{
status: string;
stepCount: number;
strategy: string;
message: string;
}>;
};
export declare const reviewMyOutput: {
name: string;
description: string;
parameters: {
type: string;
properties: {
check_rules: {
type: string;
description: string;
items: {
type: string;
};
};
};
};
handler: (params: ReviewMyOutputParams, context: ToolHandlerContext) => Promise<{
status: string;
message: string;
checkedCount?: undefined;
passedCount?: undefined;
failedCount?: undefined;
details?: undefined;
} | {
status: string;
checkedCount: number;
message: string;
passedCount?: undefined;
failedCount?: undefined;
details?: undefined;
} | {
status: string;
checkedCount: number;
passedCount: number;
failedCount: number;
details: {
title: string;
passed: boolean;
issueCount: number;
}[];
message: string;
}>;
};