/** * Artifact Schema Registry — 契约层模块。 * * 职责边界: * - 负责:ArtifactSchema 等 契约层职责 * - 不负责:不属于本模块的职责由对应模块承担 * * 被谁调用:契约验证、注册表查询 * 调用谁:artifact_contract_registry * * 数据流:契约定义 → 验证逻辑 → 通过/拒绝结果 * 持久化:无持久化(纯计算/内存态) */ import type { ArtifactKind } from "./artifact_contract_registry.js"; /** 产物结构 Schema — 定义输出文档必须满足的结构约束 */ export interface ArtifactSchema { /** 产物类型 */ kind: ArtifactKind; /** 必填章节标题(关键文本,用于 markdown heading 匹配) */ required_sections: string[]; /** 必填表格关键词(用于 markdown table 匹配) */ required_tables: string[]; /** 仅在适用时出现的表格;出现后仍校验列与数据行 */ conditional_tables?: string[]; /** 已声明表格的必填列名(tableName → columnName[]) */ required_fields?: Record; /** 必填表格允许为空时,必须同时存在的显式计数证据 */ empty_table_evidence?: Record; /** 必填附属产物(文件路径模式或关键词描述) */ required_artifacts?: string[]; /** 禁止出现的空白/占位标记 */ forbidden_gaps?: string[]; /** 对应的模板文件名(由 domain contract 在 templates/{domain}/ 或 templates/shared/ 中消费) */ template_file?: string; } /** * 获取指定产物类型的 Schema。 * @returns Schema 或 undefined(未知类型) */ export declare function getArtifactSchema(kind: ArtifactKind): ArtifactSchema | undefined; /** * 检查指定产物类型是否有已注册的 Schema。 */ export declare function hasArtifactSchema(kind: string): boolean; /** * 获取所有已注册的 Schema(不含 custom)。 */ export declare function getAllArtifactSchemas(): ArtifactSchema[]; /** * 获取所有已注册 Schema 的 kind 列表。 */ export declare function getRegisteredSchemaKinds(): ArtifactKind[]; /** * 获取有实质结构约束的 Schema 列表(required_sections 或 required_tables 非空)。 */ export declare function getStructuralSchemas(): ArtifactSchema[]; /** * 灵活的章节标题匹配 — 容许编号前缀(如 "1. "、"2.1 ")。 * * 匹配规则: * - `## 页面元数据` → 匹配 section "页面元数据" * - `## 1. 页面元数据` → 匹配 section "页面元数据" * - `### 2.1 色彩` → 匹配 section "色彩" */ export declare function matchSection(content: string, sectionName: string): boolean; /** * 在内容中查找所有缺失的必填章节。 * @returns 缺失的章节名称列表 */ export declare function findMissingSections(content: string, schema: ArtifactSchema): string[]; /** * 在内容中查找所有缺失的必填表格。 * 代码围栏内的表格内容不视为真实产物表格(避免模板范例误判)。 * @returns 缺失的表格名称列表 */ export declare function findMissingTables(content: string, schema: ArtifactSchema): string[]; /** 必填表格列不匹配检测( :表存在但列头与 schema.required_fields 不符。 * 补 findMissingTables 漏检——findMissingTables 在"表存在(keyword 在)但列不符"时 return false 不报, * 致列不符场景无报错,用户 grep 才发现真因。本函数报"列不匹配"含期望/实际列,治"缺表格"误导 + 补漏检。 */ export interface MismatchedTableFinding { table: string; expected_fields: string[]; actual_fields: string[]; } export declare function findMismatchedTables(content: string, schema: ArtifactSchema): MismatchedTableFinding[]; /** 必填表格数据行缺失列值 */ export interface IncompleteTableRowFinding { /** schema.required_tables 中的表格名 */ table_keyword: string; /** 数据行行号(1-based) */ line_number: number; /** 该行为空或占位的必填列 */ missing_fields: string[]; } /** * 检测必填表格已有数据行但必填列为空/占位。 * 代码围栏内表格不视为真实产物表格。 */ export declare function findIncompleteRequiredTableRows(content: string, schema: ArtifactSchema): IncompleteTableRowFinding[]; /** * 将 ArtifactSchema 格式化为可注入 prompt 的结构约束文本。 * * 输出格式: * ``` * ## 产物结构约束:prototype_spec * 必填章节:页面元数据、设计令牌、页面布局树... * 必填表格:素材证据表、组件契约表... * 表格必填列: * 素材证据表 → 素材/契约、版本或时间、具体位置... * ... * ``` */ export declare function formatSchemaForPrompt(schema: ArtifactSchema): string; /** 空表格发现 */ export interface EmptyTableFinding { /** 表格 header 关键词 */ table_keyword: string; /** 表格起始行号(1-based) */ line_number: number; /** 是否为必填表格 */ is_required: boolean; /** 是否由 schema 声明的显式零计数证据合法化 */ empty_allowed: boolean; } /** * 检测空表格 — 表格有 header 和 separator 但无数据行。 * * 与 schema.required_tables 做关键词匹配,必填表格空 → is_required=true。 * 代码围栏内的空表格不视为真实产物内容(避免模板范例误判)。 */ export declare function findEmptyTables(content: string, schema: ArtifactSchema): EmptyTableFinding[]; export interface ParsedMarkdownTable { headers: string[]; rows: Array<{ line_number: number; cells: string[]; }>; /** 表格之前最近的 Markdown 标题,用于区分列相似的条件表 */ section_heading?: string; } export declare function extractMarkdownTables(content: string): ParsedMarkdownTable[]; export declare function normalizeCell(cell: string): string;