autosnippet
Version:
Extract code patterns into a knowledge base for AI coding assistants
57 lines (56 loc) • 2.62 kB
TypeScript
/**
* Snapshot Views — 面向消费者的衍生视图
*
* 核心理念:消费者不应直接操作 ProjectSnapshot 的每一个字段。
* View Factory 提供针对特定消费场景的轻量级投影。
*
* @module types/snapshot-views
*/
import type { AstSummary, BootstrapSessionShape, CallGraphResult, CodeEntityGraphResult, DependencyGraph, ExistingRecipeInfo, GuardAudit, LocalPackageModule, ProjectSnapshot, SnapshotFile, SnapshotTarget } from './project-snapshot.js';
/**
* BootstrapSession.snapshotCache 的类型化形状。
*
* 替代之前 `Record<string, unknown>` 的擦除类型,
* 消费端(dimension-complete-external、wiki-external)不再需要 `as` 手动转型。
*
*/
export interface SessionCacheShape {
readonly allFiles: readonly SnapshotFile[];
readonly astProjectSummary: AstSummary | null;
readonly codeEntityResult: CodeEntityGraphResult | null;
readonly callGraphResult: CallGraphResult | null;
readonly depGraphData: DependencyGraph | null;
readonly guardAudit: GuardAudit | null;
readonly langStats: Record<string, number>;
readonly primaryLang: string;
readonly targetsSummary: readonly SnapshotTarget[];
readonly localPackageModules: readonly LocalPackageModule[];
}
/** handler → dispatchPipelineFill → orchestrator 的统一入参 */
export interface PipelineFillView {
/** 完整的项目快照(类型化、不可变) */
readonly snapshot: ProjectSnapshot;
/** 运行时上下文(DI container、logger 等)— 使用 Record 以兼容各种 McpContext 子类型 */
readonly ctx: Record<string, unknown>;
/** 当前 bootstrap session(可选,rescan 场景可能为 null) */
readonly bootstrapSession: BootstrapSessionShape | null;
/** handler 构建的 target→files 映射 */
readonly targetFileMap: Record<string, unknown[]>;
/** 项目根路径 */
readonly projectRoot: string;
/** 已有 recipes(rescan 去重用) */
readonly existingRecipes?: ExistingRecipeInfo[];
}
/**
* 从 ProjectSnapshot 提取通用的 MCP 响应数据摘要。
*
* 注意:这只包含通用字段。各 handler 需要的特有字段
* (如 cleanup、bootstrapSession、rescan 等)仍然需要在 handler 中单独拼装。
*/
export declare function toResponseData(snapshot: ProjectSnapshot): Record<string, unknown>;
/**
* 从 ProjectSnapshot 提取 BootstrapSession 的 phase cache 数据。
*
* 替代当前 handler 中手动拼装的 setSnapshotCache({...}) 调用。
*/
export declare function toSessionCache(snapshot: ProjectSnapshot): SessionCacheShape;