@hoplogic/spec 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -0
- package/dist/index.cjs +1120 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +183 -0
- package/dist/index.d.ts +183 -0
- package/dist/index.js +1102 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/grammar.ts","../src/spec-parser.ts","../src/spec-validator.ts","../src/plan-spec.ts","../src/format-repair.ts"],"names":["escapeRegex"],"mappings":";;;AAeO,IAAM,UAAA,GAA0B;AAAA,EACrC,YAAA,EAAc;AAAA,IACZ,QAAA,EAAU,0BAAA;AAAA,IACV,SAAA,EAAW,0BAAA;AAAA,IACX,WAAA,EAAa,0BAAA;AAAA,IACb,SAAA,EAAW,0BAAA;AAAA,IACX,aAAA,EAAe,0BAAA;AAAA,IACf,aAAA,EAAe;AAAA,GACjB;AAAA,EACA,OAAA,EAAS;AAAA,IACP,cAAA,EAAM,WAAA;AAAA,IACN,cAAA,EAAM,MAAA;AAAA,IACN,cAAA,EAAM,QAAA;AAAA,IACN,cAAA,EAAM,SAAA;AAAA,IACN,0BAAA,EAAQ,eAAA;AAAA,IACR,cAAA,EAAM,UAAA;AAAA,IACN,cAAA,EAAM,aAAA;AAAA,IACN,cAAA,EAAM,aAAA;AAAA,IACN,cAAA,EAAM,WAAA;AAAA,IACN,0BAAA,EAAQ,YAAA;AAAA,IACR,0BAAA,EAAQ,aAAA;AAAA,IACR,0BAAA,EAAQ,gBAAA;AAAA,IACR,cAAA,EAAM,QAAA;AAAA,IACN,0BAAA,EAAQ,aAAA;AAAA,IACR,0BAAA,EAAQ,SAAA;AAAA,IACR,0BAAA,EAAQ,aAAA;AAAA,IACR,oBAAA,EAAO,aAAA;AAAA,IACP,oBAAA,EAAY,aAAA;AAAA,IACZ,iBAAA,EAAS,aAAA;AA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,0BAAA,CAA2B,IAAA,EAAM,QAAQ,CAAC,CAAA;AAAA,QAC3D;AAAA,MACF;AAAA,IACF,CAAA,MAAO;AACL,MAAA,KAAA,MAAW,CAAC,CAAA,EAAG,CAAC,KAAK,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAG;AACzC,QAAA,MAAM,YAAY,IAAA,GAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,GAAK,CAAA;AAC1C,QAAA,IAAI,OAAO,MAAM,QAAA,EAAU;AACzB,UAAA,MAAM,CAAA,GAAI,EAAE,IAAA,EAAK;AACjB,UAAA,IAAI,EAAE,UAAA,CAAW,GAAG,CAAA,EAAG,MAAA,CAAO,KAAK,SAAS,CAAA;AAAA,eAAA,IACnC,EAAE,UAAA,CAAW,GAAG,CAAA,EAAG,MAAA,CAAO,KAAK,SAAS,CAAA;AAAA,QACnD,CAAA,MAAA,IAAW,OAAO,CAAA,KAAM,QAAA,IAAY,MAAM,IAAA,EAAM;AAC9C,UAAA,MAAA,CAAO,IAAA,CAAK,GAAG,0BAAA,CAA2B,CAAA,EAAG,SAAS,CAAC,CAAA;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["/** Bilingual grammar configuration for HopSpec parsing */\n\nexport interface SpecGrammar {\n /** Section display names, keyed by logical name */\n sectionNames: Record<string, string>\n /** Attribute key mapping: display name → internal field name */\n attrMap: Record<string, string>\n /** Step header prefix (e.g., \"步骤\" or \"Step\") */\n stepPrefix: string\n /** Step type label for loop parenthetical */\n loopLabel: string\n /** Step type label for branch parenthetical */\n branchLabel: string\n}\n\nexport const ZH_GRAMMAR: SpecGrammar = {\n sectionNames: {\n overview: \"任务概述\",\n input_def: \"输入定义\",\n constraints: \"硬性约束\",\n execution: \"执行流程\",\n output_format: \"输出格式\",\n input_example: \"输入日志示例\",\n },\n attrMap: {\n \"类型\": \"step_type\",\n \"任务\": \"task\",\n \"输入\": \"inputs\",\n \"输出\": \"outputs\",\n \"输出格式\": \"return_format\",\n \"核验\": \"verifier\",\n \"说明\": \"description\",\n \"逻辑\": \"description\",\n \"条件\": \"condition\",\n \"遍历集合\": \"collection\",\n \"元素变量\": \"element_var\",\n \"最大轮次\": \"max_iterations\",\n \"动作\": \"action\",\n \"目标循环\": \"target_loop\",\n \"退出标识\": \"exit_id\",\n \"调用目标\": \"call_target\",\n \"工具域\": \"tool_domain\",\n \"Hoplet路径\": \"hoplet_path\",\n \"MCP服务\": \"mcp_service\",\n \"RAG知识库\": \"rag_collection\",\n \"展开模式\": \"expand_mode\",\n \"最大步数\": \"max_steps\",\n \"最大轮数\": \"max_rounds\",\n \"允许类型\": \"allowed_types\",\n \"固化路径\": \"solidified_spec\",\n \"最大深度\": \"max_depth\",\n },\n stepPrefix: \"步骤\",\n loopLabel: \"loop\",\n branchLabel: \"branch\",\n}\n\nexport const EN_GRAMMAR: SpecGrammar = {\n sectionNames: {\n overview: \"Overview\",\n input_def: \"Input Definition\",\n constraints: \"Constraints\",\n execution: \"Execution Flow\",\n output_format: \"Output Format\",\n input_example: \"Input Example\",\n },\n attrMap: {\n \"Type\": \"step_type\",\n \"Task\": \"task\",\n \"Input\": \"inputs\",\n \"Output\": \"outputs\",\n \"Output Format\": \"return_format\",\n \"Verify\": \"verifier\",\n \"Description\": \"description\",\n \"Logic\": \"description\",\n \"Condition\": \"condition\",\n \"Collection\": \"collection\",\n \"Element Variable\": \"element_var\",\n \"Max Iterations\": \"max_iterations\",\n \"Action\": \"action\",\n \"Target Loop\": \"target_loop\",\n \"Exit ID\": \"exit_id\",\n \"Call Target\": \"call_target\",\n \"Tool Domain\": \"tool_domain\",\n \"Hoplet Path\": \"hoplet_path\",\n \"MCP Service\": \"mcp_service\",\n \"RAG Collection\": \"rag_collection\",\n \"Expand Mode\": \"expand_mode\",\n \"Max Steps\": \"max_steps\",\n \"Max Rounds\": \"max_rounds\",\n \"Allowed Types\": \"allowed_types\",\n \"Solidified Spec\": \"solidified_spec\",\n \"Max Depth\": \"max_depth\",\n },\n stepPrefix: \"Step\",\n loopLabel: \"loop\",\n branchLabel: \"branch\",\n}\n\n/** Detect grammar from markdown content */\nexport function detectGrammar(markdown: string): SpecGrammar {\n // Check for Chinese execution section header\n if (markdown.includes(\"## 执行流程\") || markdown.includes(\"#### 步骤\")) {\n return ZH_GRAMMAR\n }\n if (markdown.includes(\"## Execution Flow\") || markdown.includes(\"#### Step\")) {\n return EN_GRAMMAR\n }\n // Default to Chinese\n return ZH_GRAMMAR\n}\n","/**\n * spec-parser.ts — HopSpec Markdown parser\n * Parses HopSpec markdown into StepInfo tree structure.\n * Port of hop_engine/jit/spec_parser.py (~327 lines)\n */\n\nimport type { StepInfo, ParsedSpec, VerifyStrategy, LoopMode, ExpandMode } from \"./types\"\nimport { type SpecGrammar, detectGrammar } from \"./grammar\"\n\n// ─── Regex patterns ────────────────────────────────────────────\n\n/** Attribute line: `- key: value` or `- key: value` */\nconst ATTR_RE = /^(?<indent>\\s*)-\\s+(?<key>[^::]+)[::]\\s*(?<value>.+)$/\n\n/** Section header: `## Title` */\nconst SECTION_RE = /^##\\s+(.+)$/\n\n/** Build step header regex from grammar prefix */\nfunction makeStepHeaderRe(grammar: SpecGrammar): RegExp {\n const prefix = escapeRegex(grammar.stepPrefix)\n // Allow optional space between prefix and ID (English: \"Step 1\", Chinese: \"步骤1\")\n // Name capture stops before parenthetical like (loop)\n return new RegExp(\n `^(?<indent>\\\\s*)####\\\\s+${prefix}\\\\s*(?<id>[\\\\d.]+)(?:[::]\\\\s*(?<name>[^((\\\\s]+))?`\n )\n}\n\nfunction escapeRegex(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")\n}\n\n// ─── Section extraction ────────────────────────────────────────\n\n/** Extract all `## Section` titles and their content */\nfunction extractSections(markdown: string): Record<string, string> {\n const sections: Record<string, string> = {}\n const lines = markdown.split(\"\\n\")\n let currentTitle = \"\"\n let currentLines: string[] = []\n\n for (const line of lines) {\n const m = SECTION_RE.exec(line)\n if (m) {\n if (currentTitle) {\n sections[currentTitle] = currentLines.join(\"\\n\").trim()\n }\n currentTitle = m[1]!.trim()\n currentLines = []\n } else {\n currentLines.push(line)\n }\n }\n if (currentTitle) {\n sections[currentTitle] = currentLines.join(\"\\n\").trim()\n }\n return sections\n}\n\n/** Extract lines belonging to the execution flow section */\nfunction extractExecutionSection(markdown: string, grammar: SpecGrammar): string[] {\n const executionTitle = grammar.sectionNames[\"execution\"] ?? \"执行流程\"\n const lines = markdown.split(\"\\n\")\n const result: string[] = []\n let inSection = false\n\n for (const line of lines) {\n const m = SECTION_RE.exec(line)\n if (m) {\n const title = m[1]!.trim()\n if (title === executionTitle) {\n inSection = true\n continue\n } else if (inSection) {\n break\n }\n }\n if (inSection) {\n result.push(line)\n }\n }\n return result\n}\n\n// ─── Step block splitting ──────────────────────────────────────\n\ninterface StepBlock {\n indent: number\n header: string\n body: string[]\n}\n\n/** Split execution section lines into step blocks */\nfunction splitIntoStepBlocks(lines: string[], stepHeaderRe: RegExp): StepBlock[] {\n const blocks: StepBlock[] = []\n let currentBlock: StepBlock | null = null\n\n for (const line of lines) {\n const m = stepHeaderRe.exec(line)\n if (m) {\n if (currentBlock) blocks.push(currentBlock)\n const indentStr = m.groups?.[\"indent\"] ?? \"\"\n currentBlock = {\n indent: indentStr.length,\n header: line,\n body: [],\n }\n } else if (currentBlock) {\n currentBlock.body.push(line)\n }\n }\n if (currentBlock) blocks.push(currentBlock)\n return blocks\n}\n\n// ─── Attribute parsing ─────────────────────────────────────────\n\n/** Parse `- key: value` attribute lines from a step body */\nfunction parseStepAttrs(\n bodyLines: string[],\n attrMap: Record<string, string>,\n): Record<string, string> {\n const attrs: Record<string, string> = {}\n\n for (const line of bodyLines) {\n const m = ATTR_RE.exec(line)\n if (!m) continue\n\n const key = m.groups?.[\"key\"]?.trim() ?? \"\"\n const value = m.groups?.[\"value\"]?.trim() ?? \"\"\n const mappedKey = attrMap[key]\n if (mappedKey) {\n attrs[mappedKey] = value\n }\n }\n return attrs\n}\n\n// ─── Input/Output parsing ──────────────────────────────────────\n\nconst EMPTY_MARKERS = new Set([\"(无)\", \"(none)\", \"无\", \"none\", \"(无)\"])\n\n/** Parse comma-separated input list, respecting empty markers */\nfunction parseInputs(raw: string): string[] {\n const trimmed = raw.trim()\n if (!trimmed || EMPTY_MARKERS.has(trimmed)) return []\n return trimmed.split(/[,,]/).map(s => s.trim()).filter(Boolean)\n}\n\n/** Parse comma-separated output list */\nfunction parseOutputs(raw: string): string[] {\n const trimmed = raw.trim()\n if (!trimmed) return []\n return trimmed.split(/[,,]/).map(s => s.trim()).filter(Boolean)\n}\n\n// ─── Verifier mapping ──────────────────────────────────────────\n\nfunction mapVerifyStrategy(raw: string): VerifyStrategy {\n const trimmed = raw.trim()\n if (trimmed === \"逆向\" || trimmed.toLowerCase() === \"reverse\") return \"reverse\"\n if (trimmed === \"正向交叉\" || trimmed.toLowerCase() === \"forward_cross\") return \"forward_cross\"\n return \"none\"\n}\n\n// ─── StepInfo construction ─────────────────────────────────────\n\nfunction createStepInfo(partial: Partial<StepInfo> & { step_id: string }): StepInfo {\n return {\n step_id: partial.step_id,\n step_name: partial.step_name ?? \"\",\n step_type: partial.step_type ?? \"code\",\n description: partial.description ?? \"\",\n task: partial.task ?? \"\",\n inputs: partial.inputs ?? {},\n outputs: partial.outputs ?? {},\n return_format: partial.return_format ?? \"\",\n verify_strategy: partial.verify_strategy ?? \"none\",\n children: partial.children ?? [],\n loop_mode: partial.loop_mode,\n collection: partial.collection,\n element_var: partial.element_var,\n condition: partial.condition,\n max_iterations: partial.max_iterations,\n branch_condition: partial.branch_condition,\n call_target: partial.call_target,\n call_path: partial.call_path,\n flow_action: partial.flow_action,\n exit_id: partial.exit_id,\n expand_mode: partial.expand_mode,\n max_steps: partial.max_steps,\n }\n}\n\n/** Build StepInfo from parsed attributes */\nfunction buildStepFromAttrs(\n stepId: string,\n stepName: string,\n attrs: Record<string, string>,\n): StepInfo {\n const stepType = attrs[\"step_type\"] ?? \"code\"\n\n const step = createStepInfo({\n step_id: stepId,\n step_name: stepName || `step${stepId.replace(/\\./g, \"_\")}`,\n step_type: stepType as StepInfo[\"step_type\"],\n })\n\n // Common fields\n if (attrs[\"task\"]) step.task = attrs[\"task\"]\n if (attrs[\"description\"]) step.description = attrs[\"description\"]\n if (attrs[\"return_format\"]) step.return_format = attrs[\"return_format\"]\n\n // Inputs/Outputs as Record<string, string> (name → name for simple list)\n if (attrs[\"inputs\"]) {\n const names = parseInputs(attrs[\"inputs\"])\n step.inputs = Object.fromEntries(names.map(n => [n, n]))\n }\n if (attrs[\"outputs\"]) {\n const names = parseOutputs(attrs[\"outputs\"])\n step.outputs = Object.fromEntries(names.map(n => [n, n]))\n }\n\n // Verifier\n if (attrs[\"verifier\"]) {\n step.verify_strategy = mapVerifyStrategy(attrs[\"verifier\"])\n }\n\n // Loop-specific\n if (stepType === \"loop\") {\n if (attrs[\"collection\"]) {\n step.loop_mode = \"for-each\" as LoopMode\n step.collection = attrs[\"collection\"]\n step.element_var = attrs[\"element_var\"] ?? \"\"\n } else if (attrs[\"condition\"]) {\n step.loop_mode = \"while\" as LoopMode\n step.condition = attrs[\"condition\"]\n }\n if (attrs[\"max_iterations\"]) {\n const n = parseInt(attrs[\"max_iterations\"], 10)\n if (!isNaN(n)) step.max_iterations = n\n }\n }\n\n // Branch-specific\n if (stepType === \"branch\" && attrs[\"condition\"]) {\n step.branch_condition = attrs[\"condition\"]\n }\n\n // Flow-specific\n if (stepType === \"flow\") {\n step.flow_action = attrs[\"action\"] ?? \"exit\"\n if (attrs[\"exit_id\"]) step.exit_id = attrs[\"exit_id\"]\n }\n\n // Call-specific\n if (stepType === \"call\") {\n step.call_target = attrs[\"call_target\"] ?? \"\"\n step.call_path = attrs[\"hoplet_path\"] ?? attrs[\"tool_domain\"] ?? attrs[\"mcp_service\"] ?? attrs[\"rag_collection\"] ?? \"\"\n }\n\n // Subtask-specific\n if (stepType === \"subtask\") {\n step.expand_mode = (attrs[\"expand_mode\"] ?? \"static\") as ExpandMode\n if (attrs[\"max_steps\"]) {\n const n = parseInt(attrs[\"max_steps\"], 10)\n if (!isNaN(n)) step.max_steps = n\n }\n }\n\n return step\n}\n\n// ─── Recursive tree builder ────────────────────────────────────\n\n/** Recursively build StepInfo tree from step blocks */\nfunction buildTree(\n blocks: StepBlock[],\n stepHeaderRe: RegExp,\n grammar: SpecGrammar,\n): StepInfo[] {\n const steps: StepInfo[] = []\n let i = 0\n\n while (i < blocks.length) {\n const block = blocks[i]!\n const { indent, header, body } = block\n\n // Parse step ID and name from header\n const m = stepHeaderRe.exec(header)\n if (!m) { i++; continue }\n\n const stepId = m.groups?.[\"id\"] ?? \"\"\n const stepName = m.groups?.[\"name\"] ?? \"\"\n\n // Parse attributes from body\n const attrs = parseStepAttrs(body, grammar.attrMap)\n\n // Check for type hint in header parenthetical: \"步骤1: name(loop)\"\n const parenMatch = header.match(/[((]\\s*(\\w+)\\s*[))]/)\n if (parenMatch && !attrs[\"step_type\"]) {\n attrs[\"step_type\"] = parenMatch[1]!\n }\n\n // Build step\n const step = buildStepFromAttrs(stepId, stepName, attrs)\n\n // Collect child blocks (greater indent)\n const childBlocks: StepBlock[] = []\n let j = i + 1\n while (j < blocks.length && blocks[j]!.indent > indent) {\n childBlocks.push(blocks[j]!)\n j++\n }\n\n if (childBlocks.length > 0) {\n step.children = buildTree(childBlocks, stepHeaderRe, grammar)\n }\n\n steps.push(step)\n i = j\n }\n\n return steps\n}\n\n// ─── Public API ────────────────────────────────────────────────\n\n/** Parse HopSpec markdown into a StepInfo tree */\nexport function parseSpec(markdown: string, grammar?: SpecGrammar): StepInfo[] {\n const g = grammar ?? detectGrammar(markdown)\n const stepHeaderRe = makeStepHeaderRe(g)\n const execLines = extractExecutionSection(markdown, g)\n const blocks = splitIntoStepBlocks(execLines, stepHeaderRe)\n return buildTree(blocks, stepHeaderRe, g)\n}\n\n/** Parse full HopSpec markdown including sections */\nexport function parseFullSpec(markdown: string, grammar?: SpecGrammar): ParsedSpec {\n const g = grammar ?? detectGrammar(markdown)\n const sections = extractSections(markdown)\n const steps = parseSpec(markdown, g)\n\n // Extract title from first `# Title` line\n const titleMatch = markdown.match(/^#\\s+(.+)$/m)\n const title = titleMatch ? titleMatch[1]!.trim() : \"\"\n\n // Extract description from overview section\n const overviewKey = g.sectionNames[\"overview\"] ?? \"任务概述\"\n const description = sections[overviewKey] ?? \"\"\n\n // Extract input/output format\n const inputKey = g.sectionNames[\"input_def\"] ?? \"输入定义\"\n const outputKey = g.sectionNames[\"output_format\"] ?? \"输出格式\"\n\n return {\n sections,\n steps,\n title,\n description,\n input_format: sections[inputKey] ?? \"\",\n output_format: sections[outputKey] ?? \"\",\n }\n}\n","/**\n * spec-validator.ts — StepInfo tree deterministic validator\n * Port of hop_engine/jit/spec_validator.py (~655 lines)\n * 6 independent validation checks: structure, type, tree, dataflow, verifier, naming\n */\n\nimport type { StepInfo } from \"./types\"\nimport { type SpecGrammar, ZH_GRAMMAR } from \"./grammar\"\n\n// ─── Types ─────────────────────────────────────────────────────\n\nexport interface ValidationError {\n check: string // \"structure\" | \"type\" | \"tree\" | \"dataflow\" | \"verifier\" | \"naming\"\n step_id: string\n message: string\n level: \"error\" | \"warning\"\n}\n\nexport type SpecMode = \"aot\" | \"jit\"\n\n// ─── Constants ─────────────────────────────────────────────────\n\nconst VALID_TYPES = new Set<string>([\"LLM\", \"call\", \"loop\", \"branch\", \"code\", \"flow\", \"subtask\"])\nconst VALID_EXPAND_MODES = new Set([\"static\", \"dynamic\", \"think\", \"seq_think\"])\nconst SNAKE_CASE_RE = /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/\nconst INPUT_VAR_RE = /^\\s*-\\s*`(\\w+)`/\n\n// ─── Check 1: Structure ────────────────────────────────────────\n\nfunction checkStructure(\n steps: StepInfo[],\n sections: Record<string, string>,\n grammar: SpecGrammar,\n): ValidationError[] {\n const errors: ValidationError[] = []\n\n // Check required sections\n const requiredLogical = [\"overview\", \"input_def\", \"constraints\", \"execution\", \"output_format\", \"input_example\"]\n const missing: string[] = []\n for (const logical of requiredLogical) {\n const displayName = grammar.sectionNames[logical]\n if (displayName && !(displayName in sections)) {\n missing.push(displayName)\n }\n }\n if (missing.length > 0) {\n errors.push({\n check: \"structure\",\n step_id: \"\",\n message: `Missing required sections: ${missing.join(\", \")}`,\n level: \"error\",\n })\n }\n\n // Check empty execution flow\n if (steps.length === 0) {\n errors.push({\n check: \"structure\",\n step_id: \"\",\n message: \"Execution flow is empty (no steps)\",\n level: \"error\",\n })\n return errors\n }\n\n // Check last step is flow:exit\n const lastStep = steps[steps.length - 1]!\n if (lastStep.step_type !== \"flow\" || lastStep.flow_action !== \"exit\") {\n errors.push({\n check: \"structure\",\n step_id: lastStep.step_id,\n message: `Last top-level step must be flow(action=exit), got ${lastStep.step_type}${lastStep.flow_action ? `:${lastStep.flow_action}` : \"\"}`,\n level: \"error\",\n })\n }\n\n return errors\n}\n\n// ─── Check 2: Types ────────────────────────────────────────────\n\nfunction checkTypes(steps: StepInfo[], mode: SpecMode): ValidationError[] {\n const errors: ValidationError[] = []\n checkTypesRecursive(steps, false, mode, errors)\n return errors\n}\n\nfunction checkTypesRecursive(\n steps: StepInfo[],\n inLoop: boolean,\n mode: SpecMode,\n errors: ValidationError[],\n): void {\n for (const step of steps) {\n // Valid step_type\n if (!VALID_TYPES.has(step.step_type)) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: `Invalid step_type \"${step.step_type}\". Valid: ${[...VALID_TYPES].join(\", \")}`,\n level: \"error\",\n })\n continue\n }\n\n // flow:continue/break must be inside loop\n if (step.step_type === \"flow\" && (step.flow_action === \"continue\" || step.flow_action === \"break\")) {\n if (!inLoop) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: `flow:${step.flow_action} can only appear inside a loop`,\n level: \"error\",\n })\n }\n }\n\n // Container must have children\n if ((step.step_type === \"loop\" || step.step_type === \"branch\") && step.children.length === 0) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: `${step.step_type} step must have children`,\n level: \"error\",\n })\n }\n\n // Subtask rules\n if (step.step_type === \"subtask\") {\n checkSubtask(step, errors)\n }\n\n // JIT: while loop must have max_iterations > 0\n if (mode === \"jit\" && step.step_type === \"loop\" && step.loop_mode === \"while\") {\n if (!step.max_iterations || step.max_iterations <= 0) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: \"JIT mode: while loop must have max_iterations > 0\",\n level: \"error\",\n })\n }\n }\n\n // Recurse into children\n const childInLoop = inLoop || step.step_type === \"loop\"\n if (step.children.length > 0) {\n checkTypesRecursive(step.children, childInLoop, mode, errors)\n }\n }\n}\n\nfunction checkSubtask(step: StepInfo, errors: ValidationError[]): void {\n const mode = step.expand_mode ?? \"static\"\n if (!VALID_EXPAND_MODES.has(mode)) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: `Invalid expand_mode \"${mode}\". Valid: ${[...VALID_EXPAND_MODES].join(\", \")}`,\n level: \"error\",\n })\n return\n }\n\n if (mode === \"static\") {\n if (step.children.length === 0) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: \"subtask(static) must have children\",\n level: \"error\",\n })\n }\n } else {\n // dynamic / think / seq_think\n if (step.children.length > 0) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: `subtask(${mode}) must NOT have children (generated at runtime)`,\n level: \"error\",\n })\n }\n if (!step.task) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: `subtask(${mode}) must have task description`,\n level: \"error\",\n })\n }\n if (Object.keys(step.outputs).length === 0) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: `subtask(${mode}) must declare outputs`,\n level: \"error\",\n })\n }\n if (step.max_steps !== undefined && step.max_steps <= 0) {\n errors.push({\n check: \"type\",\n step_id: step.step_id,\n message: `subtask(${mode}) max_steps must be > 0`,\n level: \"error\",\n })\n }\n }\n}\n\n// ─── Check 3: Tree structure ───────────────────────────────────\n\nfunction checkTree(steps: StepInfo[]): ValidationError[] {\n const errors: ValidationError[] = []\n checkTreeRecursive(steps, [], errors)\n return errors\n}\n\nfunction checkTreeRecursive(\n steps: StepInfo[],\n ancestorLoops: string[],\n errors: ValidationError[],\n): void {\n for (const step of steps) {\n // flow:continue/break must reference valid ancestor loop\n if (step.step_type === \"flow\" && (step.flow_action === \"continue\" || step.flow_action === \"break\")) {\n if (step.exit_id && !ancestorLoops.includes(step.exit_id)) {\n errors.push({\n check: \"tree\",\n step_id: step.step_id,\n message: `flow:${step.flow_action} target \"${step.exit_id}\" not found in ancestor loops: [${ancestorLoops.join(\", \")}]`,\n level: \"error\",\n })\n }\n }\n\n // branch must have condition\n if (step.step_type === \"branch\") {\n if (!step.branch_condition) {\n errors.push({\n check: \"tree\",\n step_id: step.step_id,\n message: \"branch step must have a condition\",\n level: \"error\",\n })\n }\n }\n\n // loop must have collection (for-each) OR condition (while), not both/neither\n if (step.step_type === \"loop\") {\n const hasCollection = !!step.collection\n const hasCondition = !!step.condition\n if (!hasCollection && !hasCondition) {\n errors.push({\n check: \"tree\",\n step_id: step.step_id,\n message: \"loop must have either collection (for-each) or condition (while)\",\n level: \"error\",\n })\n }\n }\n\n // Recurse with updated ancestor loops\n const newLoops = step.step_type === \"loop\"\n ? [...ancestorLoops, step.step_name]\n : ancestorLoops\n if (step.children.length > 0) {\n checkTreeRecursive(step.children, newLoops, errors)\n }\n }\n}\n\n// ─── Check 4: Data flow ────────────────────────────────────────\n\nfunction checkDataflow(\n steps: StepInfo[],\n sections: Record<string, string>,\n grammar: SpecGrammar,\n): ValidationError[] {\n const errors: ValidationError[] = []\n\n // Extract input variables from input section\n const inputKey = grammar.sectionNames[\"input_def\"] ?? \"输入定义\"\n const inputSection = sections[inputKey] ?? \"\"\n const available = new Set<string>()\n for (const line of inputSection.split(\"\\n\")) {\n const m = INPUT_VAR_RE.exec(line)\n if (m?.[1]) available.add(m[1])\n }\n\n checkDataflowRecursive(steps, available, errors)\n return errors\n}\n\nfunction checkDataflowRecursive(\n steps: StepInfo[],\n available: Set<string>,\n errors: ValidationError[],\n): void {\n for (const step of steps) {\n // Check inputs are available\n for (const input of Object.keys(step.inputs)) {\n if (!available.has(input)) {\n errors.push({\n check: \"dataflow\",\n step_id: step.step_id,\n message: `Input variable \"${input}\" not produced by prior steps`,\n level: \"error\",\n })\n }\n }\n\n // Loop: check collection exists, scope element_var\n if (step.step_type === \"loop\" && step.loop_mode === \"for-each\" && step.collection) {\n if (!available.has(step.collection)) {\n errors.push({\n check: \"dataflow\",\n step_id: step.step_id,\n message: `Loop collection \"${step.collection}\" not produced by prior steps`,\n level: \"error\",\n })\n }\n // Create child scope with element_var\n const childAvailable = new Set(available)\n if (step.element_var) childAvailable.add(step.element_var)\n checkDataflowRecursive(step.children, childAvailable, errors)\n } else if (step.children.length > 0) {\n // Branch/subtask(static)/while-loop: inherit parent scope\n const childAvailable = new Set(available)\n checkDataflowRecursive(step.children, childAvailable, errors)\n // Expose child outputs\n for (const child of step.children) {\n for (const out of Object.keys(child.outputs)) {\n available.add(out)\n }\n }\n }\n\n // Register outputs\n for (const out of Object.keys(step.outputs)) {\n available.add(out)\n }\n }\n}\n\n// ─── Check 5: Verifier coverage ────────────────────────────────\n\nfunction checkVerifierCoverage(steps: StepInfo[]): ValidationError[] {\n const errors: ValidationError[] = []\n checkVerifierRecursive(steps, errors)\n return errors\n}\n\nfunction checkVerifierRecursive(steps: StepInfo[], errors: ValidationError[]): void {\n for (const step of steps) {\n if (step.step_type === \"LLM\" && step.verify_strategy === \"none\") {\n errors.push({\n check: \"verifier\",\n step_id: step.step_id,\n message: `LLM step \"${step.step_name}\" has no explicit verify strategy (default: reverse)`,\n level: \"warning\",\n })\n }\n if (step.children.length > 0) {\n checkVerifierRecursive(step.children, errors)\n }\n }\n}\n\n// ─── Check 6: Naming ───────────────────────────────────────────\n\nfunction checkNaming(steps: StepInfo[], mode: SpecMode): ValidationError[] {\n const errors: ValidationError[] = []\n const seen = new Set<string>()\n checkNamingRecursive(steps, mode, seen, errors)\n return errors\n}\n\nfunction checkNamingRecursive(\n steps: StepInfo[],\n mode: SpecMode,\n seen: Set<string>,\n errors: ValidationError[],\n): void {\n for (const step of steps) {\n const name = step.step_name\n if (!name) continue\n\n // Uniqueness\n if (seen.has(name)) {\n errors.push({\n check: \"naming\",\n step_id: step.step_id,\n message: `Duplicate step_name \"${name}\"`,\n level: \"error\",\n })\n }\n seen.add(name)\n\n // AOT: snake_case required\n if (mode === \"aot\" && !SNAKE_CASE_RE.test(name)) {\n errors.push({\n check: \"naming\",\n step_id: step.step_id,\n message: `step_name \"${name}\" must be snake_case (AOT mode)`,\n level: \"error\",\n })\n }\n\n if (step.children.length > 0) {\n checkNamingRecursive(step.children, mode, seen, errors)\n }\n }\n}\n\n// ─── Public API ────────────────────────────────────────────────\n\n/**\n * Validate a StepInfo tree with all 6 checks.\n * Returns errors + warnings. Empty array = valid.\n */\nexport function validateSpec(\n steps: StepInfo[],\n mode: SpecMode = \"jit\",\n sections?: Record<string, string>,\n grammar?: SpecGrammar,\n): ValidationError[] {\n const g = grammar ?? ZH_GRAMMAR\n const s = sections ?? {}\n\n return [\n ...checkStructure(steps, s, g),\n ...checkTypes(steps, mode),\n ...checkTree(steps),\n ...checkDataflow(steps, s, g),\n ...checkVerifierCoverage(steps),\n ...checkNaming(steps, mode),\n ]\n}\n","/**\n * plan-spec.ts — PlanSpec parse/serialize/validate/tree operations\n * Port of hop_engine/jit/plan_spec.py (~1103 lines)\n */\n\nimport type { PlanSpec, PlanStep, PlanValidationError, PlanStepType, PlanStepStatus } from \"./plan-types\"\n\n// ─── Constants ─────────────────────────────────────────────────\n\nconst VALID_STEP_TYPES = new Set<PlanStepType>([\"reason\", \"act\", \"check\", \"decide\", \"subtask\"])\nconst CONTAINER_TYPES = new Set<PlanStepType>([\"decide\", \"subtask\"])\n\n/** Status marker → status mapping */\nconst MARKER_TO_STATUS: Record<string, PlanStepStatus> = {\n \"[x]\": \"done\",\n \"[>]\": \"active\",\n \"[!]\": \"blocked\",\n \"[-]\": \"skipped\",\n}\n\n/** Status → marker mapping */\nconst STATUS_TO_MARKER: Record<PlanStepStatus, string> = {\n done: \"[x]\",\n active: \"[>]\",\n blocked: \"[!]\",\n skipped: \"[-]\",\n pending: \"\",\n}\n\n// ─── Regex patterns ────────────────────────────────────────────\n\n/**\n * Step line pattern:\n * \" 1.2. [x] step_name [act] Description text → outputs | result\"\n * or without name:\n * \" 1.2. [x] [act] Description text → outputs | result\"\n */\nconst STEP_RE = /^(?<indent>\\s*)(?<id>[\\d.]+)\\.\\s*(?:(?<marker>\\[[ x>!\\-]\\])\\s*)?(?:(?<name>[a-z_]\\w*)\\s+)?(?:\\[(?<type>\\w+)\\])\\s*(?<desc>[^→|]*?)(?:\\s*(?:→|->)\\s*(?<outputs>[^|]*?))?(?:\\s*\\|\\s*(?<result>.*))?$/\n\n/** Header line: \"# Plan: Title\" */\nconst TITLE_RE = /^#\\s+Plan:\\s*(.+)$/\n\n/** Goal line */\nconst GOAL_RE = /^Goal:\\s*(.+)$/\n\n/** Status line */\nconst STATUS_RE = /^Status:\\s*(DONE|ABORTED)(?:\\s+(.*))?$/\n\n/** Constraint line */\nconst CONSTRAINT_RE = /^-\\s+(.+)$/\n\n/** Detail line (> indented body) */\nconst DETAIL_RE = /^(\\s*)>\\s?(.*)$/\n\n// ─── Parser ────────────────────────────────────────────────────\n\ninterface RawStepLine {\n indent: number\n id: string\n status: PlanStepStatus\n name: string\n type: PlanStepType\n description: string\n outputs: string\n result: string\n detail: string[]\n}\n\n/** Parse a PlanSpec markdown string into a PlanSpec structure */\nexport function parsePlan(markdown: string): PlanSpec {\n const lines = markdown.split(\"\\n\")\n let title = \"\"\n let goal = \"\"\n const constraints: string[] = []\n let status: \"DONE\" | \"ABORTED\" | undefined\n let abortReason: string | undefined\n\n let phase: \"header\" | \"constraints\" | \"steps\" = \"header\"\n const rawSteps: RawStepLine[] = []\n let currentStepIdx = -1\n\n for (const line of lines) {\n // Status line\n const statusMatch = STATUS_RE.exec(line)\n if (statusMatch) {\n status = statusMatch[1] as \"DONE\" | \"ABORTED\"\n abortReason = statusMatch[2]?.trim() || undefined\n continue\n }\n\n // Title\n const titleMatch = TITLE_RE.exec(line)\n if (titleMatch) {\n title = titleMatch[1]!.trim()\n continue\n }\n\n // Goal\n const goalMatch = GOAL_RE.exec(line)\n if (goalMatch) {\n goal = goalMatch[1]!.trim()\n continue\n }\n\n // Constraints section\n if (line.startsWith(\"Constraints:\")) {\n phase = \"constraints\"\n continue\n }\n\n // Steps section\n if (line.startsWith(\"## Steps\")) {\n phase = \"steps\"\n continue\n }\n\n if (phase === \"constraints\") {\n const cm = CONSTRAINT_RE.exec(line)\n if (cm) {\n constraints.push(cm[1]!.trim())\n } else if (line.trim() === \"\" || line.startsWith(\"#\")) {\n // End of constraints\n }\n continue\n }\n\n if (phase === \"steps\") {\n // Try step line\n const sm = STEP_RE.exec(line)\n if (sm) {\n const marker = sm.groups?.[\"marker\"] ?? \"\"\n const stepStatus = MARKER_TO_STATUS[marker] ?? \"pending\" as PlanStepStatus\n rawSteps.push({\n indent: (sm.groups?.[\"indent\"] ?? \"\").length,\n id: sm.groups?.[\"id\"] ?? \"\",\n status: stepStatus,\n name: sm.groups?.[\"name\"] ?? \"\",\n type: (sm.groups?.[\"type\"] ?? \"act\") as PlanStepType,\n description: (sm.groups?.[\"desc\"] ?? \"\").trim(),\n outputs: (sm.groups?.[\"outputs\"] ?? \"\").trim(),\n result: (sm.groups?.[\"result\"] ?? \"\").trim(),\n detail: [],\n })\n currentStepIdx = rawSteps.length - 1\n continue\n }\n\n // Try detail line (> ...)\n const dm = DETAIL_RE.exec(line)\n if (dm && currentStepIdx >= 0) {\n rawSteps[currentStepIdx]!.detail.push(dm[2] ?? \"\")\n continue\n }\n }\n }\n\n // Build tree from flat raw steps using indentation\n const steps = buildPlanTree(rawSteps)\n\n return {\n title,\n goal,\n constraints,\n steps,\n status,\n abort_reason: abortReason,\n }\n}\n\n/** Build tree from flat raw steps using indentation */\nfunction buildPlanTree(rawSteps: RawStepLine[]): PlanStep[] {\n const result: PlanStep[] = []\n let i = 0\n\n while (i < rawSteps.length) {\n const raw = rawSteps[i]!\n const indent = raw.indent\n\n const step: PlanStep = {\n step_id: raw.id,\n step_type: raw.type,\n description: raw.description,\n status: raw.status,\n result: raw.result || undefined,\n outputs: raw.outputs || undefined,\n inputs: undefined,\n detail: raw.detail.length > 0 ? raw.detail.join(\"\\n\") : undefined,\n children: [],\n }\n\n // Extract inputs from detail (first line starting with ←)\n if (step.detail) {\n const inputMatch = step.detail.match(/←\\s*(.+)/)\n if (inputMatch) {\n step.inputs = inputMatch[1]!.trim()\n }\n }\n\n // Collect children (greater indent)\n const childRaws: RawStepLine[] = []\n let j = i + 1\n while (j < rawSteps.length && rawSteps[j]!.indent > indent) {\n childRaws.push(rawSteps[j]!)\n j++\n }\n\n if (childRaws.length > 0) {\n step.children = buildPlanTree(childRaws)\n }\n\n // Set step_name if provided\n if (raw.name) {\n (step as PlanStep & { step_name?: string }).step_name = raw.name\n }\n\n result.push(step)\n i = j\n }\n\n return result\n}\n\n// ─── Serializer ────────────────────────────────────────────────\n\n/** Serialize PlanSpec back to markdown */\nexport function serializePlan(plan: PlanSpec): string {\n const lines: string[] = []\n\n if (plan.status) {\n lines.push(`Status: ${plan.status}${plan.abort_reason ? ` ${plan.abort_reason}` : \"\"}`)\n }\n\n lines.push(`# Plan: ${plan.title}`)\n lines.push(`Goal: ${plan.goal}`)\n\n if (plan.constraints.length > 0) {\n lines.push(\"Constraints:\")\n for (const c of plan.constraints) {\n lines.push(`- ${c}`)\n }\n }\n\n lines.push(\"## Steps\")\n serializeSteps(plan.steps, 0, lines)\n\n return lines.join(\"\\n\") + \"\\n\"\n}\n\nfunction serializeSteps(steps: PlanStep[], depth: number, lines: string[]): void {\n const indent = \" \".repeat(depth)\n\n for (const step of steps) {\n const marker = STATUS_TO_MARKER[step.status]\n const markerStr = marker ? `${marker} ` : \"\"\n const outputStr = step.outputs ? ` → ${step.outputs}` : \"\"\n const resultStr = step.result ? ` | ${step.result}` : \"\"\n\n lines.push(`${indent}${step.step_id}. ${markerStr}[${step.step_type}] ${step.description}${outputStr}${resultStr}`)\n\n if (step.detail) {\n for (const dl of step.detail.split(\"\\n\")) {\n lines.push(`${indent} > ${dl}`)\n }\n }\n\n if (step.children.length > 0) {\n serializeSteps(step.children, depth + 1, lines)\n }\n }\n}\n\n// ─── Validator ─────────────────────────────────────────────────\n\n/** Validate PlanSpec structure */\nexport function validatePlan(plan: PlanSpec): PlanValidationError[] {\n const errors: PlanValidationError[] = []\n\n if (!plan.title) {\n errors.push({ step_id: \"\", message: \"Plan must have a title\", level: \"error\" })\n }\n if (!plan.goal) {\n errors.push({ step_id: \"\", message: \"Plan must have a goal\", level: \"error\" })\n }\n if (plan.steps.length === 0) {\n errors.push({ step_id: \"\", message: \"Plan must have at least one step\", level: \"error\" })\n }\n\n validateSteps(plan.steps, errors)\n return errors\n}\n\nfunction validateSteps(steps: PlanStep[], errors: PlanValidationError[]): void {\n const ids = new Set<string>()\n\n for (const step of steps) {\n // Duplicate ID check\n if (ids.has(step.step_id)) {\n errors.push({\n step_id: step.step_id,\n message: `Duplicate step_id \"${step.step_id}\"`,\n level: \"error\",\n })\n }\n ids.add(step.step_id)\n\n // Valid step type\n if (!VALID_STEP_TYPES.has(step.step_type)) {\n errors.push({\n step_id: step.step_id,\n message: `Invalid step_type \"${step.step_type}\"`,\n level: \"error\",\n })\n }\n\n // Container check\n if (CONTAINER_TYPES.has(step.step_type) && step.children.length === 0) {\n errors.push({\n step_id: step.step_id,\n message: `${step.step_type} step should have children`,\n level: \"warning\",\n })\n }\n\n // Non-container with children\n if (!CONTAINER_TYPES.has(step.step_type) && step.children.length > 0) {\n errors.push({\n step_id: step.step_id,\n message: `${step.step_type} step should not have children`,\n level: \"warning\",\n })\n }\n\n // Recurse\n if (step.children.length > 0) {\n validateSteps(step.children, errors)\n }\n }\n}\n\n// ─── Tree operations ───────────────────────────────────────────\n\n/** Find a step by ID in the PlanSpec tree */\nexport function findStep(plan: PlanSpec, stepId: string): PlanStep | undefined {\n return findStepInList(plan.steps, stepId)\n}\n\nfunction findStepInList(steps: PlanStep[], stepId: string): PlanStep | undefined {\n for (const step of steps) {\n if (step.step_id === stepId) return step\n if (step.children.length > 0) {\n const found = findStepInList(step.children, stepId)\n if (found) return found\n }\n }\n return undefined\n}\n\n/** Count total steps (including children) */\nexport function countSteps(plan: PlanSpec): number {\n return countStepList(plan.steps)\n}\n\nfunction countStepList(steps: PlanStep[]): number {\n let count = 0\n for (const step of steps) {\n count++\n if (step.children.length > 0) {\n count += countStepList(step.children)\n }\n }\n return count\n}\n\n/** Count steps by status */\nexport function countByStatus(plan: PlanSpec): Record<PlanStepStatus, number> {\n const counts: Record<PlanStepStatus, number> = {\n pending: 0, active: 0, done: 0, blocked: 0, skipped: 0,\n }\n countStatusRecursive(plan.steps, counts)\n return counts\n}\n\nfunction countStatusRecursive(steps: PlanStep[], counts: Record<PlanStepStatus, number>): void {\n for (const step of steps) {\n counts[step.status]++\n if (step.children.length > 0) {\n countStatusRecursive(step.children, counts)\n }\n }\n}\n","/**\n * format-repair.ts — LLM JSON output repair utilities\n * Port of hop_engine/utils/format_repair.py\n *\n * Handles common LLM output issues:\n * - JSON wrapped in markdown fences\n * - Pseudo-JSON with unquoted keys\n * - Serialization residue (stringified dicts/lists inside proper structures)\n */\n\n// ─── Known keys for pseudo-JSON parsing ─────────────────────\n\nconst KNOWN_KEYS = new Set([\n \"fact\", \"logic\", \"explanation\", \"severity\",\n \"type\", \"location\", \"evidence\", \"verdict\",\n \"cause\", \"result\", \"description\", \"reason\",\n])\n\n/** Register additional known keys for pseudo-JSON parsing */\nexport function registerKnownKeys(...keys: string[]): void {\n for (const k of keys) {\n KNOWN_KEYS.add(k)\n }\n}\n\n// ─── parse_result ───────────────────────────────────────────\n\n/**\n * Parse raw LLM output into a dict or list.\n * Handles: dict/list passthrough, JSON string, markdown-fenced JSON.\n * Falls back to empty dict for unparseable input.\n */\nexport function parseResult(raw: unknown): Record<string, unknown> | unknown[] {\n // Passthrough for dict/list\n if (typeof raw === \"object\" && raw !== null) {\n if (Array.isArray(raw)) return raw\n return raw as Record<string, unknown>\n }\n\n if (typeof raw !== \"string\") return {}\n\n const s = (raw as string).trim()\n if (!s) return {}\n\n // Try extracting JSON from markdown fence\n const fenceMatch = s.match(/```(?:json)?\\s*\\n?([\\s\\S]*?)\\n?\\s*```/)\n if (fenceMatch) {\n try {\n const parsed = JSON.parse(fenceMatch[1]!)\n if (typeof parsed === \"object\" && parsed !== null) return parsed\n } catch { /* fall through */ }\n }\n\n // Try direct JSON parse\n try {\n const parsed = JSON.parse(s)\n if (typeof parsed === \"object\" && parsed !== null) return parsed\n } catch { /* fall through */ }\n\n // Fallback\n return {}\n}\n\n// ─── coerce_to_dict ─────────────────────────────────────────\n\n/**\n * Two-stage parsing: JSON.parse → regex pseudo-JSON.\n * Returns the parsed dict, or undefined if unparseable.\n */\nexport function coerceToDict(item: unknown): Record<string, unknown> | undefined {\n // Passthrough\n if (typeof item === \"object\" && item !== null && !Array.isArray(item)) {\n return item as Record<string, unknown>\n }\n\n if (typeof item !== \"string\") return undefined\n\n const s = item.trim()\n if (!s.startsWith(\"{\")) return undefined\n\n // Stage 1: standard JSON\n try {\n const parsed = JSON.parse(s)\n if (typeof parsed === \"object\" && parsed !== null && !Array.isArray(parsed)) {\n return parsed\n }\n } catch { /* fall through to pseudo-JSON */ }\n\n // Stage 2: pseudo-JSON with known keys\n return parsePseudoJson(s)\n}\n\n/**\n * Parse pseudo-JSON like: {fact: Revenue grew 15%, severity: High}\n * Splits by commas before known keys using lookahead pattern.\n */\nfunction parsePseudoJson(s: string): Record<string, unknown> | undefined {\n // Strip outer braces\n const inner = s.slice(1, -1).trim()\n if (!inner) return {}\n\n // Build split pattern: comma before known keys\n const keyPatterns = [...KNOWN_KEYS].map(k => escapeRegex(k)).join(\"|\")\n const splitPattern = new RegExp(`[,,]\\\\s*(?=(${keyPatterns})\\\\s*:)`)\n\n const parts = inner.split(splitPattern).filter(p => p !== undefined)\n const result: Record<string, unknown> = {}\n let foundAny = false\n\n for (const part of parts) {\n const trimmed = part.trim()\n if (!trimmed) continue\n\n // Find first colon\n const colonIdx = trimmed.indexOf(\":\")\n if (colonIdx < 0) continue\n\n const key = trimmed.slice(0, colonIdx).trim().replace(/^[\"']|[\"']$/g, \"\")\n if (!key) continue\n\n let value = trimmed.slice(colonIdx + 1).trim()\n // Strip trailing commas and quotes\n value = value.replace(/[,,]\\s*$/, \"\").replace(/^[\"']|[\"']$/g, \"\")\n\n result[key] = value\n foundAny = true\n }\n\n return foundAny ? result : undefined\n}\n\nfunction escapeRegex(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")\n}\n\n// ─── coerce_to_list ─────────────────────────────────────────\n\n/**\n * Restore stringified list to array.\n * Handles standard JSON arrays and pseudo-JSON arrays.\n */\nfunction coerceToList(item: unknown): unknown[] | undefined {\n if (Array.isArray(item)) return item\n if (typeof item !== \"string\") return undefined\n\n const s = item.trim()\n if (!s.startsWith(\"[\")) return undefined\n\n // Stage 1: standard JSON\n try {\n const parsed = JSON.parse(s)\n if (Array.isArray(parsed)) return parsed\n } catch { /* fall through */ }\n\n // Stage 2: extract {...} blocks\n const inner = s.slice(1, -1).trim()\n if (!inner) return []\n\n const blocks = inner.match(/\\{(?:[^{}]*|\\{[^{}]*\\})*\\}/g)\n if (!blocks || blocks.length === 0) return undefined\n\n const result: unknown[] = []\n for (const block of blocks) {\n const dict = coerceToDict(block)\n result.push(dict ?? block)\n }\n return result\n}\n\n// ─── repair_value ───────────────────────────────────────────\n\n/**\n * Recursively repair serialization residue.\n * - Strings starting with '{' → try to parse as dict\n * - Strings starting with '[' → try to parse as list\n * - Lists → recursively repair each item\n * - Dicts → recursively repair each value\n */\nexport function repairValue(val: unknown): unknown {\n if (typeof val === \"string\") {\n const s = val.trim()\n if (s.startsWith(\"{\")) {\n // Try standard JSON first\n try {\n const parsed = JSON.parse(s)\n if (typeof parsed === \"object\" && parsed !== null && !Array.isArray(parsed)) {\n return repairValue(parsed)\n }\n } catch { /* try pseudo-JSON */ }\n const dict = coerceToDict(s)\n if (dict) return dict\n return val // unfixable\n }\n if (s.startsWith(\"[\")) {\n try {\n const parsed = JSON.parse(s)\n if (Array.isArray(parsed)) return parsed.map(item => repairValue(item))\n } catch { /* try pseudo-JSON list */ }\n const list = coerceToList(s)\n if (list) return list.map(item => repairValue(item))\n return val // unfixable\n }\n return val\n }\n\n if (Array.isArray(val)) {\n return val.map(item => repairValue(item))\n }\n\n if (typeof val === \"object\" && val !== null) {\n const result: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(val)) {\n result[k] = repairValue(v)\n }\n return result\n }\n\n return val\n}\n\n// ─── detect_serialization_residue ───────────────────────────\n\n/**\n * Recursively detect serialization residue, returning problem paths.\n * Returns an array of path strings describing where residue was found.\n */\nexport function detectSerializationResidue(data: unknown, path = \"\"): string[] {\n const issues: string[] = []\n\n if (typeof data === \"object\" && data !== null) {\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const itemPath = `${path}[${i}]`\n const item = data[i]\n if (typeof item === \"string\") {\n const s = item.trim()\n if (s.startsWith(\"{\")) issues.push(itemPath)\n else if (s.startsWith(\"[\")) issues.push(itemPath)\n } else if (typeof item === \"object\" && item !== null) {\n issues.push(...detectSerializationResidue(item, itemPath))\n }\n }\n } else {\n for (const [k, v] of Object.entries(data)) {\n const fieldPath = path ? `${path}.${k}` : k\n if (typeof v === \"string\") {\n const s = v.trim()\n if (s.startsWith(\"{\")) issues.push(fieldPath)\n else if (s.startsWith(\"[\")) issues.push(fieldPath)\n } else if (typeof v === \"object\" && v !== null) {\n issues.push(...detectSerializationResidue(v, fieldPath))\n }\n }\n }\n }\n\n return issues\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/** Step type enum matching Python's 7 atomic types */
|
|
2
|
+
type StepType = "LLM" | "call" | "loop" | "branch" | "code" | "flow" | "subtask";
|
|
3
|
+
/** Verification strategy */
|
|
4
|
+
type VerifyStrategy = "reverse" | "forward_cross" | "none";
|
|
5
|
+
/** Subtask expand mode */
|
|
6
|
+
type ExpandMode = "static" | "dynamic" | "think";
|
|
7
|
+
/** Loop mode */
|
|
8
|
+
type LoopMode = "for-each" | "while";
|
|
9
|
+
/** A single step in the HopSpec tree */
|
|
10
|
+
interface StepInfo {
|
|
11
|
+
step_id: string;
|
|
12
|
+
step_name: string;
|
|
13
|
+
step_type: StepType;
|
|
14
|
+
description: string;
|
|
15
|
+
task: string;
|
|
16
|
+
inputs: Record<string, string>;
|
|
17
|
+
outputs: Record<string, string>;
|
|
18
|
+
return_format: string;
|
|
19
|
+
verify_strategy: VerifyStrategy;
|
|
20
|
+
children: StepInfo[];
|
|
21
|
+
loop_mode?: LoopMode;
|
|
22
|
+
collection?: string;
|
|
23
|
+
element_var?: string;
|
|
24
|
+
condition?: string;
|
|
25
|
+
max_iterations?: number;
|
|
26
|
+
branch_condition?: string;
|
|
27
|
+
call_target?: string;
|
|
28
|
+
call_path?: string;
|
|
29
|
+
flow_action?: string;
|
|
30
|
+
exit_id?: string;
|
|
31
|
+
expand_mode?: ExpandMode;
|
|
32
|
+
max_steps?: number;
|
|
33
|
+
}
|
|
34
|
+
/** Parsed spec sections */
|
|
35
|
+
interface SpecSection {
|
|
36
|
+
title: string;
|
|
37
|
+
content: string;
|
|
38
|
+
}
|
|
39
|
+
/** Full parsed spec result */
|
|
40
|
+
interface ParsedSpec {
|
|
41
|
+
sections: Record<string, string>;
|
|
42
|
+
steps: StepInfo[];
|
|
43
|
+
title: string;
|
|
44
|
+
description: string;
|
|
45
|
+
input_format: string;
|
|
46
|
+
output_format: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Bilingual grammar configuration for HopSpec parsing */
|
|
50
|
+
interface SpecGrammar {
|
|
51
|
+
/** Section display names, keyed by logical name */
|
|
52
|
+
sectionNames: Record<string, string>;
|
|
53
|
+
/** Attribute key mapping: display name → internal field name */
|
|
54
|
+
attrMap: Record<string, string>;
|
|
55
|
+
/** Step header prefix (e.g., "步骤" or "Step") */
|
|
56
|
+
stepPrefix: string;
|
|
57
|
+
/** Step type label for loop parenthetical */
|
|
58
|
+
loopLabel: string;
|
|
59
|
+
/** Step type label for branch parenthetical */
|
|
60
|
+
branchLabel: string;
|
|
61
|
+
}
|
|
62
|
+
declare const ZH_GRAMMAR: SpecGrammar;
|
|
63
|
+
declare const EN_GRAMMAR: SpecGrammar;
|
|
64
|
+
/** Detect grammar from markdown content */
|
|
65
|
+
declare function detectGrammar(markdown: string): SpecGrammar;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* spec-parser.ts — HopSpec Markdown parser
|
|
69
|
+
* Parses HopSpec markdown into StepInfo tree structure.
|
|
70
|
+
* Port of hop_engine/jit/spec_parser.py (~327 lines)
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/** Parse HopSpec markdown into a StepInfo tree */
|
|
74
|
+
declare function parseSpec(markdown: string, grammar?: SpecGrammar): StepInfo[];
|
|
75
|
+
/** Parse full HopSpec markdown including sections */
|
|
76
|
+
declare function parseFullSpec(markdown: string, grammar?: SpecGrammar): ParsedSpec;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* spec-validator.ts — StepInfo tree deterministic validator
|
|
80
|
+
* Port of hop_engine/jit/spec_validator.py (~655 lines)
|
|
81
|
+
* 6 independent validation checks: structure, type, tree, dataflow, verifier, naming
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
interface ValidationError {
|
|
85
|
+
check: string;
|
|
86
|
+
step_id: string;
|
|
87
|
+
message: string;
|
|
88
|
+
level: "error" | "warning";
|
|
89
|
+
}
|
|
90
|
+
type SpecMode = "aot" | "jit";
|
|
91
|
+
/**
|
|
92
|
+
* Validate a StepInfo tree with all 6 checks.
|
|
93
|
+
* Returns errors + warnings. Empty array = valid.
|
|
94
|
+
*/
|
|
95
|
+
declare function validateSpec(steps: StepInfo[], mode?: SpecMode, sections?: Record<string, string>, grammar?: SpecGrammar): ValidationError[];
|
|
96
|
+
|
|
97
|
+
/** PlanSpec step type (5 types) */
|
|
98
|
+
type PlanStepType = "reason" | "act" | "check" | "decide" | "subtask";
|
|
99
|
+
/** PlanSpec step status */
|
|
100
|
+
type PlanStepStatus = "pending" | "active" | "done" | "blocked" | "skipped";
|
|
101
|
+
/** A single step in the PlanSpec tree */
|
|
102
|
+
interface PlanStep {
|
|
103
|
+
step_id: string;
|
|
104
|
+
step_type: PlanStepType;
|
|
105
|
+
description: string;
|
|
106
|
+
status: PlanStepStatus;
|
|
107
|
+
result?: string;
|
|
108
|
+
outputs?: string;
|
|
109
|
+
inputs?: string;
|
|
110
|
+
detail?: string;
|
|
111
|
+
children: PlanStep[];
|
|
112
|
+
}
|
|
113
|
+
/** Parsed PlanSpec */
|
|
114
|
+
interface PlanSpec {
|
|
115
|
+
title: string;
|
|
116
|
+
goal: string;
|
|
117
|
+
constraints: string[];
|
|
118
|
+
steps: PlanStep[];
|
|
119
|
+
status?: "DONE" | "ABORTED";
|
|
120
|
+
abort_reason?: string;
|
|
121
|
+
}
|
|
122
|
+
/** PlanSpec validation error */
|
|
123
|
+
interface PlanValidationError {
|
|
124
|
+
step_id: string;
|
|
125
|
+
message: string;
|
|
126
|
+
level: "error" | "warning";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* plan-spec.ts — PlanSpec parse/serialize/validate/tree operations
|
|
131
|
+
* Port of hop_engine/jit/plan_spec.py (~1103 lines)
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
/** Parse a PlanSpec markdown string into a PlanSpec structure */
|
|
135
|
+
declare function parsePlan(markdown: string): PlanSpec;
|
|
136
|
+
/** Serialize PlanSpec back to markdown */
|
|
137
|
+
declare function serializePlan(plan: PlanSpec): string;
|
|
138
|
+
/** Validate PlanSpec structure */
|
|
139
|
+
declare function validatePlan(plan: PlanSpec): PlanValidationError[];
|
|
140
|
+
/** Find a step by ID in the PlanSpec tree */
|
|
141
|
+
declare function findStep(plan: PlanSpec, stepId: string): PlanStep | undefined;
|
|
142
|
+
/** Count total steps (including children) */
|
|
143
|
+
declare function countSteps(plan: PlanSpec): number;
|
|
144
|
+
/** Count steps by status */
|
|
145
|
+
declare function countByStatus(plan: PlanSpec): Record<PlanStepStatus, number>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* format-repair.ts — LLM JSON output repair utilities
|
|
149
|
+
* Port of hop_engine/utils/format_repair.py
|
|
150
|
+
*
|
|
151
|
+
* Handles common LLM output issues:
|
|
152
|
+
* - JSON wrapped in markdown fences
|
|
153
|
+
* - Pseudo-JSON with unquoted keys
|
|
154
|
+
* - Serialization residue (stringified dicts/lists inside proper structures)
|
|
155
|
+
*/
|
|
156
|
+
/** Register additional known keys for pseudo-JSON parsing */
|
|
157
|
+
declare function registerKnownKeys(...keys: string[]): void;
|
|
158
|
+
/**
|
|
159
|
+
* Parse raw LLM output into a dict or list.
|
|
160
|
+
* Handles: dict/list passthrough, JSON string, markdown-fenced JSON.
|
|
161
|
+
* Falls back to empty dict for unparseable input.
|
|
162
|
+
*/
|
|
163
|
+
declare function parseResult(raw: unknown): Record<string, unknown> | unknown[];
|
|
164
|
+
/**
|
|
165
|
+
* Two-stage parsing: JSON.parse → regex pseudo-JSON.
|
|
166
|
+
* Returns the parsed dict, or undefined if unparseable.
|
|
167
|
+
*/
|
|
168
|
+
declare function coerceToDict(item: unknown): Record<string, unknown> | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* Recursively repair serialization residue.
|
|
171
|
+
* - Strings starting with '{' → try to parse as dict
|
|
172
|
+
* - Strings starting with '[' → try to parse as list
|
|
173
|
+
* - Lists → recursively repair each item
|
|
174
|
+
* - Dicts → recursively repair each value
|
|
175
|
+
*/
|
|
176
|
+
declare function repairValue(val: unknown): unknown;
|
|
177
|
+
/**
|
|
178
|
+
* Recursively detect serialization residue, returning problem paths.
|
|
179
|
+
* Returns an array of path strings describing where residue was found.
|
|
180
|
+
*/
|
|
181
|
+
declare function detectSerializationResidue(data: unknown, path?: string): string[];
|
|
182
|
+
|
|
183
|
+
export { EN_GRAMMAR, type ExpandMode, type LoopMode, type ParsedSpec, type PlanSpec, type PlanStep, type PlanStepStatus, type PlanStepType, type PlanValidationError, type SpecGrammar, type SpecSection, type StepInfo, type StepType, type VerifyStrategy, ZH_GRAMMAR, coerceToDict, countByStatus, countSteps, detectGrammar, detectSerializationResidue, findStep, parseFullSpec, parsePlan, parseResult, parseSpec, registerKnownKeys, repairValue, serializePlan, validatePlan, validateSpec };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/** Step type enum matching Python's 7 atomic types */
|
|
2
|
+
type StepType = "LLM" | "call" | "loop" | "branch" | "code" | "flow" | "subtask";
|
|
3
|
+
/** Verification strategy */
|
|
4
|
+
type VerifyStrategy = "reverse" | "forward_cross" | "none";
|
|
5
|
+
/** Subtask expand mode */
|
|
6
|
+
type ExpandMode = "static" | "dynamic" | "think";
|
|
7
|
+
/** Loop mode */
|
|
8
|
+
type LoopMode = "for-each" | "while";
|
|
9
|
+
/** A single step in the HopSpec tree */
|
|
10
|
+
interface StepInfo {
|
|
11
|
+
step_id: string;
|
|
12
|
+
step_name: string;
|
|
13
|
+
step_type: StepType;
|
|
14
|
+
description: string;
|
|
15
|
+
task: string;
|
|
16
|
+
inputs: Record<string, string>;
|
|
17
|
+
outputs: Record<string, string>;
|
|
18
|
+
return_format: string;
|
|
19
|
+
verify_strategy: VerifyStrategy;
|
|
20
|
+
children: StepInfo[];
|
|
21
|
+
loop_mode?: LoopMode;
|
|
22
|
+
collection?: string;
|
|
23
|
+
element_var?: string;
|
|
24
|
+
condition?: string;
|
|
25
|
+
max_iterations?: number;
|
|
26
|
+
branch_condition?: string;
|
|
27
|
+
call_target?: string;
|
|
28
|
+
call_path?: string;
|
|
29
|
+
flow_action?: string;
|
|
30
|
+
exit_id?: string;
|
|
31
|
+
expand_mode?: ExpandMode;
|
|
32
|
+
max_steps?: number;
|
|
33
|
+
}
|
|
34
|
+
/** Parsed spec sections */
|
|
35
|
+
interface SpecSection {
|
|
36
|
+
title: string;
|
|
37
|
+
content: string;
|
|
38
|
+
}
|
|
39
|
+
/** Full parsed spec result */
|
|
40
|
+
interface ParsedSpec {
|
|
41
|
+
sections: Record<string, string>;
|
|
42
|
+
steps: StepInfo[];
|
|
43
|
+
title: string;
|
|
44
|
+
description: string;
|
|
45
|
+
input_format: string;
|
|
46
|
+
output_format: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Bilingual grammar configuration for HopSpec parsing */
|
|
50
|
+
interface SpecGrammar {
|
|
51
|
+
/** Section display names, keyed by logical name */
|
|
52
|
+
sectionNames: Record<string, string>;
|
|
53
|
+
/** Attribute key mapping: display name → internal field name */
|
|
54
|
+
attrMap: Record<string, string>;
|
|
55
|
+
/** Step header prefix (e.g., "步骤" or "Step") */
|
|
56
|
+
stepPrefix: string;
|
|
57
|
+
/** Step type label for loop parenthetical */
|
|
58
|
+
loopLabel: string;
|
|
59
|
+
/** Step type label for branch parenthetical */
|
|
60
|
+
branchLabel: string;
|
|
61
|
+
}
|
|
62
|
+
declare const ZH_GRAMMAR: SpecGrammar;
|
|
63
|
+
declare const EN_GRAMMAR: SpecGrammar;
|
|
64
|
+
/** Detect grammar from markdown content */
|
|
65
|
+
declare function detectGrammar(markdown: string): SpecGrammar;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* spec-parser.ts — HopSpec Markdown parser
|
|
69
|
+
* Parses HopSpec markdown into StepInfo tree structure.
|
|
70
|
+
* Port of hop_engine/jit/spec_parser.py (~327 lines)
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/** Parse HopSpec markdown into a StepInfo tree */
|
|
74
|
+
declare function parseSpec(markdown: string, grammar?: SpecGrammar): StepInfo[];
|
|
75
|
+
/** Parse full HopSpec markdown including sections */
|
|
76
|
+
declare function parseFullSpec(markdown: string, grammar?: SpecGrammar): ParsedSpec;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* spec-validator.ts — StepInfo tree deterministic validator
|
|
80
|
+
* Port of hop_engine/jit/spec_validator.py (~655 lines)
|
|
81
|
+
* 6 independent validation checks: structure, type, tree, dataflow, verifier, naming
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
interface ValidationError {
|
|
85
|
+
check: string;
|
|
86
|
+
step_id: string;
|
|
87
|
+
message: string;
|
|
88
|
+
level: "error" | "warning";
|
|
89
|
+
}
|
|
90
|
+
type SpecMode = "aot" | "jit";
|
|
91
|
+
/**
|
|
92
|
+
* Validate a StepInfo tree with all 6 checks.
|
|
93
|
+
* Returns errors + warnings. Empty array = valid.
|
|
94
|
+
*/
|
|
95
|
+
declare function validateSpec(steps: StepInfo[], mode?: SpecMode, sections?: Record<string, string>, grammar?: SpecGrammar): ValidationError[];
|
|
96
|
+
|
|
97
|
+
/** PlanSpec step type (5 types) */
|
|
98
|
+
type PlanStepType = "reason" | "act" | "check" | "decide" | "subtask";
|
|
99
|
+
/** PlanSpec step status */
|
|
100
|
+
type PlanStepStatus = "pending" | "active" | "done" | "blocked" | "skipped";
|
|
101
|
+
/** A single step in the PlanSpec tree */
|
|
102
|
+
interface PlanStep {
|
|
103
|
+
step_id: string;
|
|
104
|
+
step_type: PlanStepType;
|
|
105
|
+
description: string;
|
|
106
|
+
status: PlanStepStatus;
|
|
107
|
+
result?: string;
|
|
108
|
+
outputs?: string;
|
|
109
|
+
inputs?: string;
|
|
110
|
+
detail?: string;
|
|
111
|
+
children: PlanStep[];
|
|
112
|
+
}
|
|
113
|
+
/** Parsed PlanSpec */
|
|
114
|
+
interface PlanSpec {
|
|
115
|
+
title: string;
|
|
116
|
+
goal: string;
|
|
117
|
+
constraints: string[];
|
|
118
|
+
steps: PlanStep[];
|
|
119
|
+
status?: "DONE" | "ABORTED";
|
|
120
|
+
abort_reason?: string;
|
|
121
|
+
}
|
|
122
|
+
/** PlanSpec validation error */
|
|
123
|
+
interface PlanValidationError {
|
|
124
|
+
step_id: string;
|
|
125
|
+
message: string;
|
|
126
|
+
level: "error" | "warning";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* plan-spec.ts — PlanSpec parse/serialize/validate/tree operations
|
|
131
|
+
* Port of hop_engine/jit/plan_spec.py (~1103 lines)
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
/** Parse a PlanSpec markdown string into a PlanSpec structure */
|
|
135
|
+
declare function parsePlan(markdown: string): PlanSpec;
|
|
136
|
+
/** Serialize PlanSpec back to markdown */
|
|
137
|
+
declare function serializePlan(plan: PlanSpec): string;
|
|
138
|
+
/** Validate PlanSpec structure */
|
|
139
|
+
declare function validatePlan(plan: PlanSpec): PlanValidationError[];
|
|
140
|
+
/** Find a step by ID in the PlanSpec tree */
|
|
141
|
+
declare function findStep(plan: PlanSpec, stepId: string): PlanStep | undefined;
|
|
142
|
+
/** Count total steps (including children) */
|
|
143
|
+
declare function countSteps(plan: PlanSpec): number;
|
|
144
|
+
/** Count steps by status */
|
|
145
|
+
declare function countByStatus(plan: PlanSpec): Record<PlanStepStatus, number>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* format-repair.ts — LLM JSON output repair utilities
|
|
149
|
+
* Port of hop_engine/utils/format_repair.py
|
|
150
|
+
*
|
|
151
|
+
* Handles common LLM output issues:
|
|
152
|
+
* - JSON wrapped in markdown fences
|
|
153
|
+
* - Pseudo-JSON with unquoted keys
|
|
154
|
+
* - Serialization residue (stringified dicts/lists inside proper structures)
|
|
155
|
+
*/
|
|
156
|
+
/** Register additional known keys for pseudo-JSON parsing */
|
|
157
|
+
declare function registerKnownKeys(...keys: string[]): void;
|
|
158
|
+
/**
|
|
159
|
+
* Parse raw LLM output into a dict or list.
|
|
160
|
+
* Handles: dict/list passthrough, JSON string, markdown-fenced JSON.
|
|
161
|
+
* Falls back to empty dict for unparseable input.
|
|
162
|
+
*/
|
|
163
|
+
declare function parseResult(raw: unknown): Record<string, unknown> | unknown[];
|
|
164
|
+
/**
|
|
165
|
+
* Two-stage parsing: JSON.parse → regex pseudo-JSON.
|
|
166
|
+
* Returns the parsed dict, or undefined if unparseable.
|
|
167
|
+
*/
|
|
168
|
+
declare function coerceToDict(item: unknown): Record<string, unknown> | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* Recursively repair serialization residue.
|
|
171
|
+
* - Strings starting with '{' → try to parse as dict
|
|
172
|
+
* - Strings starting with '[' → try to parse as list
|
|
173
|
+
* - Lists → recursively repair each item
|
|
174
|
+
* - Dicts → recursively repair each value
|
|
175
|
+
*/
|
|
176
|
+
declare function repairValue(val: unknown): unknown;
|
|
177
|
+
/**
|
|
178
|
+
* Recursively detect serialization residue, returning problem paths.
|
|
179
|
+
* Returns an array of path strings describing where residue was found.
|
|
180
|
+
*/
|
|
181
|
+
declare function detectSerializationResidue(data: unknown, path?: string): string[];
|
|
182
|
+
|
|
183
|
+
export { EN_GRAMMAR, type ExpandMode, type LoopMode, type ParsedSpec, type PlanSpec, type PlanStep, type PlanStepStatus, type PlanStepType, type PlanValidationError, type SpecGrammar, type SpecSection, type StepInfo, type StepType, type VerifyStrategy, ZH_GRAMMAR, coerceToDict, countByStatus, countSteps, detectGrammar, detectSerializationResidue, findStep, parseFullSpec, parsePlan, parseResult, parseSpec, registerKnownKeys, repairValue, serializePlan, validatePlan, validateSpec };
|