autosnippet
Version:
Extract code patterns into a knowledge base for AI coding assistants
61 lines (60 loc) • 2.06 kB
TypeScript
/**
* NudgeGenerator — 探索引导信号生成器
*
* 从 ExplorationTracker.js 提取的 Nudge 生成逻辑。
* 按优先级队列生成每轮最多一条 nudge 注入 AI 上下文。
*
* 优先级 (高→低):
* 1. force_exit — 轮次耗尽
* 2. convergence — 信息饱和
* 3. budget_warning — 75% 预算消耗
* 4. reflection — 周期反思 / 停滞反思
* 5. (planning — 由 PlanTracker 处理)
*
* 设计原则:
* - 无状态(flags 从外部传入并返回更新)
* - 接受 state 快照,无循环依赖
* - Nudge 文本内联(未来可外置为 i18n JSON 模板)
*
* @module NudgeGenerator
*/
import type { ExplorationBudget, ExplorationTrace, FullExplorationMetrics, PipelineType } from './ExplorationStrategies.js';
/** 策略配置(NudgeGenerator 所需子集) */
interface NudgeStrategy {
name: string;
enableReflection: boolean;
reflectionInterval?: number;
enablePlanning: boolean;
}
/** NudgeGenerator 的状态输入 */
interface NudgeState {
phase: string;
metrics: FullExplorationMetrics;
budget: ExplorationBudget;
strategy: NudgeStrategy;
gracefulExitRound: number | null;
submitToolName: string;
/** 管线类型 — 统一场景判别(替代 submitToolName / strategy.name 字符串比较) */
pipelineType: PipelineType;
isTerminalPhase: boolean;
transitionFromPhase?: string | null;
}
export declare class NudgeGenerator {
#private;
/**
* 生成本轮的 Nudge(每轮最多一条)
*
* @param state 从 ExplorationTracker 传入的状态快照
* @param trace ActiveContext 实例 (反思用)
* @returns |null}
*/
generate(state: NudgeState, trace: ExplorationTrace | null): {
type: string;
text: string;
} | null;
/** 构建阶段转换 nudge 文本 */
buildTransitionNudge(state: NudgeState): string;
/** 获取当前阶段的上下文状态行(注入 systemPrompt 尾部) */
getPhaseContext(state: NudgeState): string;
}
export {};