@hoplogic/engine 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 +112 -0
- package/dist/index.cjs +651 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +249 -0
- package/dist/index.d.ts +249 -0
- package/dist/index.js +639 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/execution-types.ts","../src/validators.ts","../src/response-format.ts","../src/spec-executor.ts","../src/hop-jit.ts","../src/llm-protocol.ts"],"names":["detectSerializationResidue","z","parseResult","repairValue","parseFullSpec","validateSpec"],"mappings":";;;;;;AA8BO,SAAS,gBAAA,GAAmC;AACjD,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,CAAA;AAAA,IACb,eAAA,EAAiB,CAAA;AAAA,IACjB,YAAA,EAAc,CAAA;AAAA,IACd,aAAA,EAAe,CAAA;AAAA,IACf,SAAA,EAAW,CAAA;AAAA,IACX,YAAA,EAAc;AAAA,GAChB;AACF;ACpBO,SAAS,cAAA,CACd,QACA,YAAA,EACc;AAEd,EAAA,IAAI,MAAA,KAAW,IAAA,IAAQ,MAAA,KAAW,MAAA,EAAW;AAC3C,IAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,EAAO,MAAA,EAAQ,6BAAA,EAA8B;AAAA,EAChE;AAGA,EAAA,IAAI,YAAA,IAAgB,YAAA,CAAa,MAAA,GAAS,CAAA,EAAG;AAC3C,IAAA,IAAI,OAAO,MAAA,KAAW,QAAA,IAAY,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,EAAG;AACvD,MAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,EAAO,MAAA,EAAQ,CAAA,2BAAA,EAA8B,aAAa,IAAA,CAAK,IAAI,CAAC,CAAA,OAAA,EAAU,MAAM,OAAA,CAAQ,MAAM,IAAI,OAAA,GAAU,OAAO,MAAM,CAAA,CA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D,IAAA,MAAM,SAAS,MAAM,IAAA,CAAK,cAAc,OAAA,CAAQ,IAAA,CAAK,WAAW,KAAK,CAAA;AAGrE,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAA;AACrB,IAAA,IAAA,CAAK,iBAAA,GAAoB,MAAA;AAEzB,IAAA,OAAO;AAAA,MACL,QAAQ,MAAA,CAAO,MAAA;AAAA,MACf,QAAQ,MAAA,CAAO,MAAA;AAAA,MACf,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,MAAM,IAAA,CAAK,SAAA;AAAA,MACX,kBAAkB,IAAA,CAAK;AAAA,KACzB;AAAA,EACF;AAAA;AAAA,EAGA,MAAA,GAAe;AACb,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAA;AACrB,IAAA,IAAA,CAAK,SAAA,GAAY,MAAA;AACjB,IAAA,IAAA,CAAK,wBAAwB,EAAC;AAC9B,IAAA,IAAA,CAAK,iBAAA,GAAoB,MAAA;AAAA,EAC3B;AAAA;AAAA,EAGA,IAAI,UAAA,GAAsB;AACxB,IAAA,OAAO,IAAA,CAAK,aAAA,KAAkB,MAAA,IAAa,IAAA,CAAK,SAAA,KAAc,MAAA;AAAA,EAChE;AACF;;;AChLO,SAAS,UAAU,MAAA,EAA4B;AACpD,EAAA,OAAO,MAAA,KAAW,IAAA;AACpB;AAGO,SAAS,WAAW,MAAA,EAA4B;AACrD,EAAA,OAAO,MAAA,KAAW,QAAQ,MAAA,KAAW,MAAA;AACvC","file":"index.cjs","sourcesContent":["import type { HopStatus } from \"./llm-protocol\"\n\n/** Result of executing a single step */\nexport interface StepResult {\n step_id: string\n status: HopStatus\n output: unknown\n retries: number\n error?: string\n}\n\n/** Result of executing a full spec */\nexport interface ExecutionResult {\n status: HopStatus\n output: unknown\n steps: StepResult[]\n stats: ExecutionStats\n}\n\n/** Execution statistics */\nexport interface ExecutionStats {\n total_steps: number\n completed_steps: number\n failed_steps: number\n total_retries: number\n llm_calls: number\n verify_calls: number\n}\n\n/** Create empty execution stats */\nexport function createEmptyStats(): ExecutionStats {\n return {\n total_steps: 0,\n completed_steps: 0,\n failed_steps: 0,\n total_retries: 0,\n llm_calls: 0,\n verify_calls: 0,\n }\n}\n","/**\n * validators.ts — Verification functions\n * Port of hop_engine/validators/result_validators.py\n *\n * Three verification strategies:\n * - formatVerifier: local JSON structure check (no LLM)\n * - reverseVerify: LLM-based reverse verification\n * - forwardCrossVerify: 3-way concurrent LLM verification\n */\n\nimport type { HopVerifier, VerifyResult } from \"./llm-protocol\"\nimport { detectSerializationResidue } from \"@hoplogic/spec\"\n\n// ─── Format verifier (local, no LLM) ───────────────────────\n\n/**\n * Verify that a result has the expected structure and no serialization residue.\n * Returns immediately without LLM calls.\n */\nexport function formatVerifier(\n result: unknown,\n expectedKeys?: string[],\n): VerifyResult {\n // Null/undefined check\n if (result === null || result === undefined) {\n return { passed: false, reason: \"Result is null or undefined\" }\n }\n\n // If expected keys provided, check they exist\n if (expectedKeys && expectedKeys.length > 0) {\n if (typeof result !== \"object\" || Array.isArray(result)) {\n return { passed: false, reason: `Expected object with keys [${expectedKeys.join(\", \")}], got ${Array.isArray(result) ? \"array\" : typeof result}` }\n }\n\n const obj = result as Record<string, unknown>\n const missing = expectedKeys.filter(k => !(k in obj))\n if (missing.length > 0) {\n return { passed: false, reason: `Missing expected keys: ${missing.join(\", \")}` }\n }\n }\n\n // Check for serialization residue\n if (typeof result === \"object\" && result !== null) {\n const residue = detectSerializationResidue(result)\n if (residue.length > 0) {\n return { passed: false, reason: `Serialization residue detected at: ${residue.join(\", \")}` }\n }\n }\n\n return { passed: true, reason: \"Format check passed\" }\n}\n\n// ─── Reverse verify (LLM-based) ────────────────────────────\n\n/**\n * Reverse verification: ask a verifier LLM to independently check\n * whether the result correctly answers the task given the context.\n */\nexport async function reverseVerify(\n verifier: HopVerifier,\n task: string,\n context: string,\n result: string,\n): Promise<VerifyResult> {\n return verifier.verify(task, context, result)\n}\n\n// ─── Forward cross verify (3-way concurrent) ────────────────\n\n/**\n * Forward cross verification: run 3 concurrent verifications\n * and return passed only if majority (2+) agree.\n */\nexport async function forwardCrossVerify(\n verifier: HopVerifier,\n task: string,\n context: string,\n result: string,\n): Promise<VerifyResult> {\n const results = await Promise.allSettled([\n verifier.verify(task, context, result),\n verifier.verify(task, context, result),\n verifier.verify(task, context, result),\n ])\n\n let passCount = 0\n let failCount = 0\n const reasons: string[] = []\n\n for (const r of results) {\n if (r.status === \"fulfilled\") {\n if (r.value.passed) passCount++\n else failCount++\n reasons.push(r.value.reason)\n } else {\n failCount++\n reasons.push(`Verification error: ${r.reason}`)\n }\n }\n\n const passed = passCount >= 2\n return {\n passed,\n reason: passed\n ? `Cross-verification passed (${passCount}/3 agree)`\n : `Cross-verification failed (${failCount}/3 disagree): ${reasons.filter((_r, i) => {\n const res = results[i]\n return res?.status === \"fulfilled\" && !res.value.passed || res?.status === \"rejected\"\n }).join(\"; \")}`,\n }\n}\n","/**\n * response-format.ts — Zod schema dynamic builder\n * Port of create_response_format_model from hop_engine/utils/utils.py\n *\n * Builds Zod schemas from HopSpec return_format strings:\n * - Simple types: str, int, float, bool, list, dict\n * - Dict format: {\"key\": type, \"key2\": type}\n * - Tuple syntax: {\"key\": (type, \"description\")} (description stored in metadata)\n * - List types: list[str], list[int], list[dict]\n */\n\nimport { z } from \"zod\"\n\n// ─── Type map ───────────────────────────────────────────────\n\n/** Map from type string to Zod schema */\nconst TYPE_MAP: Record<string, z.ZodType> = {\n \"str\": z.string(),\n \"string\": z.string(),\n \"int\": z.number().int(),\n \"integer\": z.number().int(),\n \"float\": z.number(),\n \"number\": z.number(),\n \"bool\": z.boolean(),\n \"boolean\": z.boolean(),\n \"list\": z.array(z.unknown()),\n \"dict\": z.record(z.unknown()),\n \"list[str]\": z.array(z.string()),\n \"List[str]\": z.array(z.string()),\n \"list[int]\": z.array(z.number().int()),\n \"List[int]\": z.array(z.number().int()),\n \"list[dict]\": z.array(z.record(z.unknown())),\n \"List[dict]\": z.array(z.record(z.unknown())),\n \"list[float]\": z.array(z.number()),\n \"List[float]\": z.array(z.number()),\n}\n\n/** Resolve a type string to a Zod schema */\nfunction resolveType(typeStr: string): z.ZodType {\n return TYPE_MAP[typeStr.trim()] ?? z.string()\n}\n\n// ─── Tuple syntax regex ─────────────────────────────────────\n\n/** Match (Type, \"description\") */\nconst TUPLE_RE = /^\\(\\s*(.+?)\\s*,\\s*\"((?:[^\"\\\\]|\\\\.)*)\"\\s*\\)$/\n\n// ─── Top-level comma splitter ───────────────────────────────\n\n/**\n * Split on top-level commas, respecting brackets and quotes.\n * Handles: {}, [], (), \"\", ''\n */\nfunction splitTopLevel(s: string): string[] {\n const parts: string[] = []\n let current = \"\"\n let depth = 0\n let inString: string | null = null\n\n for (let i = 0; i < s.length; i++) {\n const ch = s[i]!\n if (inString) {\n current += ch\n if (ch === inString && s[i - 1] !== \"\\\\\") {\n inString = null\n }\n continue\n }\n if (ch === '\"' || ch === \"'\") {\n inString = ch\n current += ch\n continue\n }\n if (ch === \"{\" || ch === \"[\" || ch === \"(\") {\n depth++\n current += ch\n continue\n }\n if (ch === \"}\" || ch === \"]\" || ch === \")\") {\n depth--\n current += ch\n continue\n }\n if (ch === \",\" && depth === 0) {\n parts.push(current.trim())\n current = \"\"\n continue\n }\n current += ch\n }\n if (current.trim()) {\n parts.push(current.trim())\n }\n return parts\n}\n\n// ─── Format parser ──────────────────────────────────────────\n\ninterface FieldDef {\n type: z.ZodType\n description?: string\n}\n\n/**\n * Parse a return format string into a map of field → Zod type.\n * Supports:\n * - Dict format: {\"key\": type, \"key2\": (type, \"desc\")}\n * - Non-dict: treated as single \"result\" field\n * - Empty: returns undefined\n */\nexport function parseReturnFormat(formatStr: string): Record<string, FieldDef> | undefined {\n const trimmed = formatStr.trim()\n if (!trimmed) return undefined\n\n // Dict format\n if (trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\")) {\n const inner = trimmed.slice(1, -1).trim()\n if (!inner) return {}\n\n const parts = splitTopLevel(inner)\n const result: Record<string, FieldDef> = {}\n\n for (const part of parts) {\n // Find the colon separator (key: value)\n const colonIdx = part.indexOf(\":\")\n if (colonIdx < 0) continue\n\n const key = part.slice(0, colonIdx).trim().replace(/^[\"']|[\"']$/g, \"\")\n if (!key) continue\n\n const valStr = part.slice(colonIdx + 1).trim()\n\n // Check tuple syntax: (Type, \"description\")\n const tupleMatch = TUPLE_RE.exec(valStr)\n if (tupleMatch) {\n const innerType = resolveType(tupleMatch[1]!)\n const desc = tupleMatch[2]!.replace(/\\\\\"/g, '\"')\n result[key] = { type: innerType, description: desc }\n } else {\n // Simple type string\n result[key] = { type: resolveType(valStr) }\n }\n }\n return result\n }\n\n // Non-dict: single result field\n return { result: { type: z.string(), description: trimmed } }\n}\n\n// ─── Zod schema builder ─────────────────────────────────────\n\n/**\n * Create a Zod response schema from a format string.\n * Wraps the user's fields in the standard HOP meta-fields:\n * - explanation: string\n * - final_answer: user's format\n * - confidence: \"OK\" | \"LACK_OF_INFO\" | \"UNCERTAIN\"\n */\nexport function createResponseFormat(formatStr: string): z.ZodType {\n const fields = parseReturnFormat(formatStr)\n\n let answerSchema: z.ZodType\n if (!fields || Object.keys(fields).length === 0) {\n answerSchema = z.string()\n } else if (Object.keys(fields).length === 1 && \"result\" in fields) {\n answerSchema = fields[\"result\"]!.type\n } else {\n // Build object schema from fields\n const shape: Record<string, z.ZodType> = {}\n for (const [key, def] of Object.entries(fields)) {\n shape[key] = def.type\n }\n answerSchema = z.object(shape)\n }\n\n return z.object({\n explanation: z.string(),\n final_answer: answerSchema,\n confidence: z.enum([\"OK\", \"LACK_OF_INFO\", \"UNCERTAIN\"]),\n missing_info: z.record(z.object({\n field: z.string(),\n description: z.string(),\n importance: z.string(),\n })).nullable().optional(),\n suggestions: z.array(z.string()).nullable().optional(),\n })\n}\n\n/**\n * Create a Zod schema for just the data portion (without meta-fields).\n * Useful for validating step output directly.\n */\nexport function createDataSchema(formatStr: string): z.ZodType {\n const fields = parseReturnFormat(formatStr)\n\n if (!fields || Object.keys(fields).length === 0) {\n return z.string()\n }\n if (Object.keys(fields).length === 1 && \"result\" in fields) {\n return fields[\"result\"]!.type\n }\n\n const shape: Record<string, z.ZodType> = {}\n for (const [key, def] of Object.entries(fields)) {\n shape[key] = def.type\n }\n return z.object(shape)\n}\n","/**\n * spec-executor.ts — Step orchestrator\n * Port of hop_engine/jit/spec_executor.py\n *\n * Executes a StepInfo tree by dispatching each step to the appropriate handler:\n * - LLM steps: query LLM, verify, retry\n * - code steps: evaluate expressions (sandboxed)\n * - loop steps: iterate over collection or while condition\n * - branch steps: conditional execution\n * - flow steps: exit, continue, break\n * - call steps: invoke external tools\n * - subtask steps: delegate to sub-executor\n */\n\nimport type { StepInfo } from \"@hoplogic/spec\"\nimport type { HopLLM, HopVerifier, LLMOptions, VerifyResult, HopStatus } from \"./llm-protocol\"\nimport type { StepResult, ExecutionResult, ExecutionStats } from \"./execution-types\"\nimport { createEmptyStats } from \"./execution-types\"\nimport { formatVerifier, reverseVerify } from \"./validators\"\nimport { parseReturnFormat } from \"./response-format\"\nimport { parseResult, repairValue } from \"@hoplogic/spec\"\n\n// ─── Flow control signals ───────────────────────────────────\n\n/** Signal for flow:exit */\nclass ExitSignal {\n constructor(\n public readonly exitId: string | undefined,\n public readonly output: unknown,\n ) {}\n}\n\n/** Signal for flow:continue/break */\nclass LoopSignal {\n constructor(\n public readonly action: \"continue\" | \"break\",\n public readonly targetId?: string,\n ) {}\n}\n\n// ─── Executor ───────────────────────────────────────────────\n\nexport interface SpecExecutorOptions {\n llm: HopLLM\n verifier?: HopVerifier\n maxRetries?: number\n}\n\nexport class SpecExecutor {\n private llm: HopLLM\n private verifier: HopVerifier | undefined\n private maxRetries: number\n\n constructor(options: SpecExecutorOptions) {\n this.llm = options.llm\n this.verifier = options.verifier\n this.maxRetries = options.maxRetries ?? 3\n }\n\n /** Execute a StepInfo tree with given input variables */\n async execute(\n steps: StepInfo[],\n input: Record<string, unknown>,\n ): Promise<ExecutionResult> {\n const stats = createEmptyStats()\n const scope = new Map<string, unknown>(Object.entries(input))\n const stepResults: StepResult[] = []\n\n let finalStatus: HopStatus = \"ok\"\n let finalOutput: unknown = {}\n\n try {\n for (const step of steps) {\n stats.total_steps++\n const result = await this.executeStep(step, scope, stats)\n stepResults.push(result)\n\n if (result.status !== \"ok\") {\n finalStatus = result.status\n finalOutput = result.output\n break\n }\n }\n } catch (e) {\n if (e instanceof ExitSignal) {\n finalOutput = e.output\n } else {\n throw e\n }\n }\n\n // Collect final output from scope\n if (finalOutput === undefined || (typeof finalOutput === \"object\" && finalOutput !== null && Object.keys(finalOutput as Record<string, unknown>).length === 0)) {\n finalOutput = Object.fromEntries(scope)\n }\n\n return {\n status: finalStatus,\n output: finalOutput,\n steps: stepResults,\n stats,\n }\n }\n\n /** Execute a single step, dispatching by type */\n private async executeStep(\n step: StepInfo,\n scope: Map<string, unknown>,\n stats: ExecutionStats,\n ): Promise<StepResult> {\n switch (step.step_type) {\n case \"LLM\":\n return this.executeLLM(step, scope, stats)\n case \"code\":\n return this.executeCode(step, scope, stats)\n case \"loop\":\n return this.executeLoop(step, scope, stats)\n case \"branch\":\n return this.executeBranch(step, scope, stats)\n case \"flow\":\n return this.executeFlow(step, scope)\n case \"call\":\n return this.executeCall(step, scope, stats)\n case \"subtask\":\n return this.executeSubtask(step, scope, stats)\n default:\n return {\n step_id: step.step_id,\n status: \"fail\",\n output: null,\n retries: 0,\n error: `Unknown step type: ${step.step_type}`,\n }\n }\n }\n\n // ─── LLM step ───────────────────────────────────────────\n\n private async executeLLM(\n step: StepInfo,\n scope: Map<string, unknown>,\n stats: ExecutionStats,\n ): Promise<StepResult> {\n const prompt = this.buildPrompt(step, scope)\n const options: LLMOptions = {}\n\n // Build response format if specified\n if (step.return_format) {\n const fields = parseReturnFormat(step.return_format)\n if (fields) {\n options.systemPrompt = `Respond in JSON format with these fields: ${Object.keys(fields).join(\", \")}`\n }\n }\n\n let lastError = \"\"\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n stats.llm_calls++\n const llmResult = await this.llm.query(prompt, options)\n\n if (!llmResult.success) {\n lastError = llmResult.content\n if (attempt < this.maxRetries) continue\n break\n }\n\n // Parse LLM output\n const parsed = parseResult(llmResult.content)\n const repaired = repairValue(parsed) as Record<string, unknown>\n\n // Format verification (always, local check)\n const expectedKeys = step.return_format\n ? Object.keys(parseReturnFormat(step.return_format) ?? {})\n : undefined\n const fmtCheck = formatVerifier(repaired, expectedKeys?.length ? expectedKeys : undefined)\n if (!fmtCheck.passed) {\n lastError = fmtCheck.reason\n if (attempt < this.maxRetries) continue\n break\n }\n\n // Reverse verification (if verifier provided and strategy demands it)\n if (this.verifier && step.verify_strategy !== \"none\") {\n stats.verify_calls++\n const verifyResult = await reverseVerify(\n this.verifier,\n step.task || step.description,\n JSON.stringify(Object.fromEntries(scope)),\n JSON.stringify(repaired),\n )\n if (!verifyResult.passed) {\n lastError = verifyResult.reason\n if (attempt < this.maxRetries) continue\n break\n }\n }\n\n // Success — store outputs in scope\n this.storeOutputs(step, repaired, scope)\n return {\n step_id: step.step_id,\n status: \"ok\",\n output: repaired,\n retries: attempt,\n }\n }\n\n return {\n step_id: step.step_id,\n status: \"fail\",\n output: null,\n retries: this.maxRetries,\n error: lastError,\n }\n }\n\n // ─── Code step ──────────────────────────────────────────\n\n private executeCode(\n step: StepInfo,\n scope: Map<string, unknown>,\n stats: ExecutionStats,\n ): Promise<StepResult> {\n stats.total_steps // count already incremented\n // Code steps in TS simply pass through — the description is documentation\n // Output variables are set to empty defaults\n for (const key of Object.keys(step.outputs)) {\n if (!scope.has(key)) {\n scope.set(key, null)\n }\n }\n return Promise.resolve({\n step_id: step.step_id,\n status: \"ok\",\n output: Object.fromEntries(\n Object.keys(step.outputs).map(k => [k, scope.get(k)])\n ),\n retries: 0,\n })\n }\n\n // ─── Loop step ──────────────────────────────────────────\n\n private async executeLoop(\n step: StepInfo,\n scope: Map<string, unknown>,\n stats: ExecutionStats,\n ): Promise<StepResult> {\n if (step.loop_mode === \"for-each\" && step.collection) {\n const collection = scope.get(step.collection)\n if (!Array.isArray(collection)) {\n return {\n step_id: step.step_id,\n status: \"fail\",\n output: null,\n retries: 0,\n error: `Loop collection \"${step.collection}\" is not an array`,\n }\n }\n\n const results: unknown[] = []\n for (const item of collection) {\n if (step.element_var) {\n scope.set(step.element_var, item)\n }\n try {\n for (const child of step.children) {\n stats.total_steps++\n const childResult = await this.executeStep(child, scope, stats)\n if (childResult.status !== \"ok\") {\n return { step_id: step.step_id, status: childResult.status, output: results, retries: 0, error: childResult.error }\n }\n }\n results.push(item)\n } catch (e) {\n if (e instanceof LoopSignal) {\n if (e.action === \"break\") break\n if (e.action === \"continue\") continue\n }\n throw e\n }\n }\n\n this.storeOutputs(step, results, scope)\n return { step_id: step.step_id, status: \"ok\", output: results, retries: 0 }\n }\n\n if (step.loop_mode === \"while\" && step.condition) {\n const maxIter = step.max_iterations ?? 10\n let iteration = 0\n const results: unknown[] = []\n\n while (iteration < maxIter) {\n iteration++\n try {\n for (const child of step.children) {\n stats.total_steps++\n const childResult = await this.executeStep(child, scope, stats)\n if (childResult.status !== \"ok\") {\n return { step_id: step.step_id, status: childResult.status, output: results, retries: 0, error: childResult.error }\n }\n }\n results.push(iteration)\n } catch (e) {\n if (e instanceof LoopSignal) {\n if (e.action === \"break\") break\n if (e.action === \"continue\") continue\n }\n throw e\n }\n }\n\n this.storeOutputs(step, results, scope)\n return { step_id: step.step_id, status: \"ok\", output: results, retries: 0 }\n }\n\n return {\n step_id: step.step_id,\n status: \"fail\",\n output: null,\n retries: 0,\n error: \"Loop step missing collection or condition\",\n }\n }\n\n // ─── Branch step ────────────────────────────────────────\n\n private async executeBranch(\n step: StepInfo,\n scope: Map<string, unknown>,\n stats: ExecutionStats,\n ): Promise<StepResult> {\n // Execute children (branch condition is evaluated externally in real engine;\n // here we always execute children as the condition was already checked)\n for (const child of step.children) {\n stats.total_steps++\n const childResult = await this.executeStep(child, scope, stats)\n if (childResult.status !== \"ok\") {\n return { step_id: step.step_id, status: childResult.status, output: null, retries: 0, error: childResult.error }\n }\n }\n return { step_id: step.step_id, status: \"ok\", output: null, retries: 0 }\n }\n\n // ─── Flow step ──────────────────────────────────────────\n\n private executeFlow(\n step: StepInfo,\n scope: Map<string, unknown>,\n ): Promise<StepResult> {\n if (step.flow_action === \"exit\") {\n const output = Object.fromEntries(\n Object.keys(step.outputs).map(k => [k, scope.get(k)])\n )\n throw new ExitSignal(step.exit_id, output)\n }\n\n if (step.flow_action === \"continue\" || step.flow_action === \"break\") {\n throw new LoopSignal(step.flow_action, step.exit_id)\n }\n\n return Promise.resolve({\n step_id: step.step_id,\n status: \"ok\",\n output: null,\n retries: 0,\n })\n }\n\n // ─── Call step ──────────────────────────────────────────\n\n private executeCall(\n step: StepInfo,\n scope: Map<string, unknown>,\n _stats: ExecutionStats,\n ): Promise<StepResult> {\n // Call steps require external tool integration — stub for now\n // Output variables are set to placeholders\n for (const key of Object.keys(step.outputs)) {\n scope.set(key, `[call:${step.call_target}:${key}]`)\n }\n return Promise.resolve({\n step_id: step.step_id,\n status: \"ok\",\n output: Object.fromEntries(\n Object.keys(step.outputs).map(k => [k, scope.get(k)])\n ),\n retries: 0,\n })\n }\n\n // ─── Subtask step ───────────────────────────────────────\n\n private async executeSubtask(\n step: StepInfo,\n scope: Map<string, unknown>,\n stats: ExecutionStats,\n ): Promise<StepResult> {\n if (step.expand_mode === \"static\" || !step.expand_mode) {\n // Execute inline children\n for (const child of step.children) {\n stats.total_steps++\n const childResult = await this.executeStep(child, scope, stats)\n if (childResult.status !== \"ok\") {\n return { step_id: step.step_id, status: childResult.status, output: null, retries: 0, error: childResult.error }\n }\n }\n return { step_id: step.step_id, status: \"ok\", output: null, retries: 0 }\n }\n\n // Dynamic/think subtasks would need JIT generation — stub for now\n for (const key of Object.keys(step.outputs)) {\n scope.set(key, `[subtask:${step.expand_mode}:${key}]`)\n }\n return {\n step_id: step.step_id,\n status: \"ok\",\n output: Object.fromEntries(\n Object.keys(step.outputs).map(k => [k, scope.get(k)])\n ),\n retries: 0,\n }\n }\n\n // ─── Helpers ────────────────────────────────────────────\n\n private buildPrompt(step: StepInfo, scope: Map<string, unknown>): string {\n const parts: string[] = []\n if (step.task) parts.push(`Task: ${step.task}`)\n if (step.description) parts.push(`Description: ${step.description}`)\n\n // Include inputs from scope\n const inputs = Object.keys(step.inputs)\n if (inputs.length > 0) {\n parts.push(\"Context:\")\n for (const key of inputs) {\n const val = scope.get(key)\n parts.push(` ${key}: ${JSON.stringify(val)}`)\n }\n }\n\n if (step.return_format) {\n parts.push(`Output format: ${step.return_format}`)\n }\n\n return parts.join(\"\\n\")\n }\n\n private storeOutputs(\n step: StepInfo,\n result: unknown,\n scope: Map<string, unknown>,\n ): void {\n const outputKeys = Object.keys(step.outputs)\n if (outputKeys.length === 0) return\n\n if (typeof result === \"object\" && result !== null && !Array.isArray(result)) {\n const obj = result as Record<string, unknown>\n for (const key of outputKeys) {\n if (key in obj) {\n scope.set(key, obj[key])\n }\n }\n } else if (outputKeys.length === 1) {\n scope.set(outputKeys[0]!, result)\n }\n }\n}\n","/**\n * hop-jit.ts — Top-level JIT orchestrator\n * Port of hop_engine/jit/hop_jit.py\n *\n * Ties together parser, validator, and executor into a single entry point:\n * - runSpec(markdown, input) — parse → validate → execute\n * - resume(feedback) — inject feedback and continue from NEED_INPUT checkpoint\n * - cancel() — discard pending execution state\n */\n\nimport { parseFullSpec, validateSpec } from \"@hoplogic/spec\"\nimport type { StepInfo, SpecGrammar } from \"@hoplogic/spec\"\nimport type { HopLLM, HopVerifier, HopStatus } from \"./llm-protocol\"\nimport type { ExecutionResult, ExecutionStats } from \"./execution-types\"\nimport { SpecExecutor, type SpecExecutorOptions } from \"./spec-executor\"\n\n// ─── Types ──────────────────────────────────────────────────\n\nexport type SpecMode = \"aot\" | \"jit\"\n\nexport interface HopJITOptions {\n llm: HopLLM\n verifier?: HopVerifier\n maxRetries?: number\n grammar?: SpecGrammar\n}\n\nexport interface RunSpecOptions {\n /** Skip validation (debug only) */\n skipValidation?: boolean\n /** Validation mode: \"aot\" for human-audited, \"jit\" for LLM-generated */\n mode?: SpecMode\n}\n\nexport interface JITResult {\n status: HopStatus\n output: unknown\n steps: ExecutionResult[\"steps\"]\n stats: ExecutionStats\n /** Parsed spec (StepInfo tree) */\n spec: StepInfo[]\n /** Validation errors (empty if skipValidation or all passed) */\n validationErrors: Array<{ check: string; step_id: string; message: string; level: string }>\n /** Set when executor signals NEED_INPUT — call resume(feedback) to continue */\n needInput?: NeedInputInfo\n}\n\nexport interface NeedInputInfo {\n diagnosis: string\n suggestions: string[]\n step_id: string\n round: number\n}\n\n// ─── HopJIT ─────────────────────────────────────────────────\n\nexport class HopJIT {\n private llm: HopLLM\n private verifier: HopVerifier | undefined\n private maxRetries: number\n private grammar: SpecGrammar | undefined\n\n // Resume state\n private _liveExecutor: SpecExecutor | undefined\n private _liveSpec: StepInfo[] | undefined\n private _liveValidationErrors: JITResult[\"validationErrors\"] = []\n private _pendingNeedInput: NeedInputInfo | undefined\n\n constructor(options: HopJITOptions) {\n this.llm = options.llm\n this.verifier = options.verifier\n this.maxRetries = options.maxRetries ?? 3\n this.grammar = options.grammar\n }\n\n /**\n * Parse and execute a HopSpec markdown document.\n *\n * Flow: parse → validate → execute\n * Returns a JITResult with execution output, stats, and validation info.\n */\n async runSpec(\n markdown: string,\n input: Record<string, unknown>,\n options?: RunSpecOptions,\n ): Promise<JITResult> {\n // Phase 1: Parse (full spec to get both steps and sections)\n const parsed = parseFullSpec(markdown, this.grammar)\n const steps = parsed.steps\n const sections = parsed.sections\n\n // Phase 2: Validate (unless skipped)\n const mode = options?.mode ?? \"jit\"\n let validationErrors: JITResult[\"validationErrors\"] = []\n\n if (!options?.skipValidation) {\n validationErrors = validateSpec(steps, mode, sections, this.grammar)\n }\n\n // Store for potential resume\n this._liveSpec = steps\n this._liveValidationErrors = validationErrors\n\n // Check for truly fatal errors: empty step list or all steps unrecognized\n // Other validation errors (missing sections, dataflow) are informational in JIT mode\n if (steps.length === 0) {\n this._liveExecutor = undefined\n return {\n status: \"fail\",\n output: null,\n steps: [],\n stats: { total_steps: 0, completed_steps: 0, failed_steps: 0, total_retries: 0, llm_calls: 0, verify_calls: 0 },\n spec: steps,\n validationErrors,\n }\n }\n\n // Phase 3: Execute\n const executorOpts: SpecExecutorOptions = {\n llm: this.llm,\n verifier: this.verifier,\n maxRetries: this.maxRetries,\n }\n const executor = new SpecExecutor(executorOpts)\n this._liveExecutor = executor\n\n const result = await executor.execute(steps, input)\n\n // Clear resume state on completion\n this._liveExecutor = undefined\n this._pendingNeedInput = undefined\n\n return {\n status: result.status,\n output: result.output,\n steps: result.steps,\n stats: result.stats,\n spec: steps,\n validationErrors,\n }\n }\n\n /**\n * Resume execution from a NEED_INPUT checkpoint.\n * Injects feedback and continues from the interrupted step.\n *\n * @throws Error if no pending execution to resume\n */\n async resume(feedback: string): Promise<JITResult> {\n if (!this._liveExecutor || !this._liveSpec) {\n throw new Error(\"No pending execution to resume\")\n }\n\n // For now, re-execute with feedback injected into input.\n // Full checkpoint/resume would require executor-level support.\n const input: Record<string, unknown> = { _feedback: feedback }\n const result = await this._liveExecutor.execute(this._liveSpec, input)\n\n // Clear resume state\n this._liveExecutor = undefined\n this._pendingNeedInput = undefined\n\n return {\n status: result.status,\n output: result.output,\n steps: result.steps,\n stats: result.stats,\n spec: this._liveSpec,\n validationErrors: this._liveValidationErrors,\n }\n }\n\n /** Cancel any pending execution and clear resume state. */\n cancel(): void {\n this._liveExecutor = undefined\n this._liveSpec = undefined\n this._liveValidationErrors = []\n this._pendingNeedInput = undefined\n }\n\n /** Whether there is a pending execution that can be resumed. */\n get hasPending(): boolean {\n return this._liveExecutor !== undefined && this._liveSpec !== undefined\n }\n}\n","import type { z } from \"zod\"\n\n// ─── Status ─────────────────────────────────────────────────\n\n/** HOP execution status — mirrors Python HopStatus enum */\nexport type HopStatus = \"ok\" | \"fail\" | \"uncertain\" | \"lack_of_info\"\n\n/** Check if a status indicates success */\nexport function isSuccess(status: HopStatus): boolean {\n return status === \"ok\"\n}\n\n/** Check if a status indicates a terminal failure */\nexport function isTerminal(status: HopStatus): boolean {\n return status === \"ok\" || status === \"fail\"\n}\n\n// ─── LLM Protocol ───────────────────────────────────────────\n\n/** LLM query options */\nexport interface LLMOptions {\n temperature?: number\n maxTokens?: number\n responseFormat?: z.ZodType\n systemPrompt?: string\n}\n\n/** LLM query result */\nexport interface LLMResult {\n success: boolean\n content: string\n raw?: unknown\n}\n\n/** Verification result */\nexport interface VerifyResult {\n passed: boolean\n reason: string\n status?: HopStatus\n}\n\n/**\n * LLM Protocol — injected by the consuming project.\n * opencode uses AI SDK, other projects bring their own adapter.\n */\nexport interface HopLLM {\n query(prompt: string, options?: LLMOptions): Promise<LLMResult>\n}\n\n/**\n * Verifier Protocol — for reverse/forward cross verification.\n * The consuming project provides the LLM-backed implementation.\n */\nexport interface HopVerifier {\n verify(task: string, context: string, result: string): Promise<VerifyResult>\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { StepInfo, SpecGrammar } from '@hoplogic/spec';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** HOP execution status — mirrors Python HopStatus enum */
|
|
5
|
+
type HopStatus = "ok" | "fail" | "uncertain" | "lack_of_info";
|
|
6
|
+
/** Check if a status indicates success */
|
|
7
|
+
declare function isSuccess(status: HopStatus): boolean;
|
|
8
|
+
/** Check if a status indicates a terminal failure */
|
|
9
|
+
declare function isTerminal(status: HopStatus): boolean;
|
|
10
|
+
/** LLM query options */
|
|
11
|
+
interface LLMOptions {
|
|
12
|
+
temperature?: number;
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
responseFormat?: z.ZodType;
|
|
15
|
+
systemPrompt?: string;
|
|
16
|
+
}
|
|
17
|
+
/** LLM query result */
|
|
18
|
+
interface LLMResult {
|
|
19
|
+
success: boolean;
|
|
20
|
+
content: string;
|
|
21
|
+
raw?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Verification result */
|
|
24
|
+
interface VerifyResult {
|
|
25
|
+
passed: boolean;
|
|
26
|
+
reason: string;
|
|
27
|
+
status?: HopStatus;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* LLM Protocol — injected by the consuming project.
|
|
31
|
+
* opencode uses AI SDK, other projects bring their own adapter.
|
|
32
|
+
*/
|
|
33
|
+
interface HopLLM {
|
|
34
|
+
query(prompt: string, options?: LLMOptions): Promise<LLMResult>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Verifier Protocol — for reverse/forward cross verification.
|
|
38
|
+
* The consuming project provides the LLM-backed implementation.
|
|
39
|
+
*/
|
|
40
|
+
interface HopVerifier {
|
|
41
|
+
verify(task: string, context: string, result: string): Promise<VerifyResult>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Result of executing a single step */
|
|
45
|
+
interface StepResult {
|
|
46
|
+
step_id: string;
|
|
47
|
+
status: HopStatus;
|
|
48
|
+
output: unknown;
|
|
49
|
+
retries: number;
|
|
50
|
+
error?: string;
|
|
51
|
+
}
|
|
52
|
+
/** Result of executing a full spec */
|
|
53
|
+
interface ExecutionResult {
|
|
54
|
+
status: HopStatus;
|
|
55
|
+
output: unknown;
|
|
56
|
+
steps: StepResult[];
|
|
57
|
+
stats: ExecutionStats;
|
|
58
|
+
}
|
|
59
|
+
/** Execution statistics */
|
|
60
|
+
interface ExecutionStats {
|
|
61
|
+
total_steps: number;
|
|
62
|
+
completed_steps: number;
|
|
63
|
+
failed_steps: number;
|
|
64
|
+
total_retries: number;
|
|
65
|
+
llm_calls: number;
|
|
66
|
+
verify_calls: number;
|
|
67
|
+
}
|
|
68
|
+
/** Create empty execution stats */
|
|
69
|
+
declare function createEmptyStats(): ExecutionStats;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* spec-executor.ts — Step orchestrator
|
|
73
|
+
* Port of hop_engine/jit/spec_executor.py
|
|
74
|
+
*
|
|
75
|
+
* Executes a StepInfo tree by dispatching each step to the appropriate handler:
|
|
76
|
+
* - LLM steps: query LLM, verify, retry
|
|
77
|
+
* - code steps: evaluate expressions (sandboxed)
|
|
78
|
+
* - loop steps: iterate over collection or while condition
|
|
79
|
+
* - branch steps: conditional execution
|
|
80
|
+
* - flow steps: exit, continue, break
|
|
81
|
+
* - call steps: invoke external tools
|
|
82
|
+
* - subtask steps: delegate to sub-executor
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
interface SpecExecutorOptions {
|
|
86
|
+
llm: HopLLM;
|
|
87
|
+
verifier?: HopVerifier;
|
|
88
|
+
maxRetries?: number;
|
|
89
|
+
}
|
|
90
|
+
declare class SpecExecutor {
|
|
91
|
+
private llm;
|
|
92
|
+
private verifier;
|
|
93
|
+
private maxRetries;
|
|
94
|
+
constructor(options: SpecExecutorOptions);
|
|
95
|
+
/** Execute a StepInfo tree with given input variables */
|
|
96
|
+
execute(steps: StepInfo[], input: Record<string, unknown>): Promise<ExecutionResult>;
|
|
97
|
+
/** Execute a single step, dispatching by type */
|
|
98
|
+
private executeStep;
|
|
99
|
+
private executeLLM;
|
|
100
|
+
private executeCode;
|
|
101
|
+
private executeLoop;
|
|
102
|
+
private executeBranch;
|
|
103
|
+
private executeFlow;
|
|
104
|
+
private executeCall;
|
|
105
|
+
private executeSubtask;
|
|
106
|
+
private buildPrompt;
|
|
107
|
+
private storeOutputs;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* hop-jit.ts — Top-level JIT orchestrator
|
|
112
|
+
* Port of hop_engine/jit/hop_jit.py
|
|
113
|
+
*
|
|
114
|
+
* Ties together parser, validator, and executor into a single entry point:
|
|
115
|
+
* - runSpec(markdown, input) — parse → validate → execute
|
|
116
|
+
* - resume(feedback) — inject feedback and continue from NEED_INPUT checkpoint
|
|
117
|
+
* - cancel() — discard pending execution state
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
type SpecMode = "aot" | "jit";
|
|
121
|
+
interface HopJITOptions {
|
|
122
|
+
llm: HopLLM;
|
|
123
|
+
verifier?: HopVerifier;
|
|
124
|
+
maxRetries?: number;
|
|
125
|
+
grammar?: SpecGrammar;
|
|
126
|
+
}
|
|
127
|
+
interface RunSpecOptions {
|
|
128
|
+
/** Skip validation (debug only) */
|
|
129
|
+
skipValidation?: boolean;
|
|
130
|
+
/** Validation mode: "aot" for human-audited, "jit" for LLM-generated */
|
|
131
|
+
mode?: SpecMode;
|
|
132
|
+
}
|
|
133
|
+
interface JITResult {
|
|
134
|
+
status: HopStatus;
|
|
135
|
+
output: unknown;
|
|
136
|
+
steps: ExecutionResult["steps"];
|
|
137
|
+
stats: ExecutionStats;
|
|
138
|
+
/** Parsed spec (StepInfo tree) */
|
|
139
|
+
spec: StepInfo[];
|
|
140
|
+
/** Validation errors (empty if skipValidation or all passed) */
|
|
141
|
+
validationErrors: Array<{
|
|
142
|
+
check: string;
|
|
143
|
+
step_id: string;
|
|
144
|
+
message: string;
|
|
145
|
+
level: string;
|
|
146
|
+
}>;
|
|
147
|
+
/** Set when executor signals NEED_INPUT — call resume(feedback) to continue */
|
|
148
|
+
needInput?: NeedInputInfo;
|
|
149
|
+
}
|
|
150
|
+
interface NeedInputInfo {
|
|
151
|
+
diagnosis: string;
|
|
152
|
+
suggestions: string[];
|
|
153
|
+
step_id: string;
|
|
154
|
+
round: number;
|
|
155
|
+
}
|
|
156
|
+
declare class HopJIT {
|
|
157
|
+
private llm;
|
|
158
|
+
private verifier;
|
|
159
|
+
private maxRetries;
|
|
160
|
+
private grammar;
|
|
161
|
+
private _liveExecutor;
|
|
162
|
+
private _liveSpec;
|
|
163
|
+
private _liveValidationErrors;
|
|
164
|
+
private _pendingNeedInput;
|
|
165
|
+
constructor(options: HopJITOptions);
|
|
166
|
+
/**
|
|
167
|
+
* Parse and execute a HopSpec markdown document.
|
|
168
|
+
*
|
|
169
|
+
* Flow: parse → validate → execute
|
|
170
|
+
* Returns a JITResult with execution output, stats, and validation info.
|
|
171
|
+
*/
|
|
172
|
+
runSpec(markdown: string, input: Record<string, unknown>, options?: RunSpecOptions): Promise<JITResult>;
|
|
173
|
+
/**
|
|
174
|
+
* Resume execution from a NEED_INPUT checkpoint.
|
|
175
|
+
* Injects feedback and continues from the interrupted step.
|
|
176
|
+
*
|
|
177
|
+
* @throws Error if no pending execution to resume
|
|
178
|
+
*/
|
|
179
|
+
resume(feedback: string): Promise<JITResult>;
|
|
180
|
+
/** Cancel any pending execution and clear resume state. */
|
|
181
|
+
cancel(): void;
|
|
182
|
+
/** Whether there is a pending execution that can be resumed. */
|
|
183
|
+
get hasPending(): boolean;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* response-format.ts — Zod schema dynamic builder
|
|
188
|
+
* Port of create_response_format_model from hop_engine/utils/utils.py
|
|
189
|
+
*
|
|
190
|
+
* Builds Zod schemas from HopSpec return_format strings:
|
|
191
|
+
* - Simple types: str, int, float, bool, list, dict
|
|
192
|
+
* - Dict format: {"key": type, "key2": type}
|
|
193
|
+
* - Tuple syntax: {"key": (type, "description")} (description stored in metadata)
|
|
194
|
+
* - List types: list[str], list[int], list[dict]
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
interface FieldDef {
|
|
198
|
+
type: z.ZodType;
|
|
199
|
+
description?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Parse a return format string into a map of field → Zod type.
|
|
203
|
+
* Supports:
|
|
204
|
+
* - Dict format: {"key": type, "key2": (type, "desc")}
|
|
205
|
+
* - Non-dict: treated as single "result" field
|
|
206
|
+
* - Empty: returns undefined
|
|
207
|
+
*/
|
|
208
|
+
declare function parseReturnFormat(formatStr: string): Record<string, FieldDef> | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Create a Zod response schema from a format string.
|
|
211
|
+
* Wraps the user's fields in the standard HOP meta-fields:
|
|
212
|
+
* - explanation: string
|
|
213
|
+
* - final_answer: user's format
|
|
214
|
+
* - confidence: "OK" | "LACK_OF_INFO" | "UNCERTAIN"
|
|
215
|
+
*/
|
|
216
|
+
declare function createResponseFormat(formatStr: string): z.ZodType;
|
|
217
|
+
/**
|
|
218
|
+
* Create a Zod schema for just the data portion (without meta-fields).
|
|
219
|
+
* Useful for validating step output directly.
|
|
220
|
+
*/
|
|
221
|
+
declare function createDataSchema(formatStr: string): z.ZodType;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* validators.ts — Verification functions
|
|
225
|
+
* Port of hop_engine/validators/result_validators.py
|
|
226
|
+
*
|
|
227
|
+
* Three verification strategies:
|
|
228
|
+
* - formatVerifier: local JSON structure check (no LLM)
|
|
229
|
+
* - reverseVerify: LLM-based reverse verification
|
|
230
|
+
* - forwardCrossVerify: 3-way concurrent LLM verification
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Verify that a result has the expected structure and no serialization residue.
|
|
235
|
+
* Returns immediately without LLM calls.
|
|
236
|
+
*/
|
|
237
|
+
declare function formatVerifier(result: unknown, expectedKeys?: string[]): VerifyResult;
|
|
238
|
+
/**
|
|
239
|
+
* Reverse verification: ask a verifier LLM to independently check
|
|
240
|
+
* whether the result correctly answers the task given the context.
|
|
241
|
+
*/
|
|
242
|
+
declare function reverseVerify(verifier: HopVerifier, task: string, context: string, result: string): Promise<VerifyResult>;
|
|
243
|
+
/**
|
|
244
|
+
* Forward cross verification: run 3 concurrent verifications
|
|
245
|
+
* and return passed only if majority (2+) agree.
|
|
246
|
+
*/
|
|
247
|
+
declare function forwardCrossVerify(verifier: HopVerifier, task: string, context: string, result: string): Promise<VerifyResult>;
|
|
248
|
+
|
|
249
|
+
export { type ExecutionResult, type ExecutionStats, HopJIT, type HopJITOptions, type HopLLM, type HopStatus, type HopVerifier, type JITResult, type LLMOptions, type LLMResult, type NeedInputInfo, type RunSpecOptions, SpecExecutor, type SpecExecutorOptions, type SpecMode, type StepResult, type VerifyResult, createDataSchema, createEmptyStats, createResponseFormat, formatVerifier, forwardCrossVerify, isSuccess, isTerminal, parseReturnFormat, reverseVerify };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { StepInfo, SpecGrammar } from '@hoplogic/spec';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** HOP execution status — mirrors Python HopStatus enum */
|
|
5
|
+
type HopStatus = "ok" | "fail" | "uncertain" | "lack_of_info";
|
|
6
|
+
/** Check if a status indicates success */
|
|
7
|
+
declare function isSuccess(status: HopStatus): boolean;
|
|
8
|
+
/** Check if a status indicates a terminal failure */
|
|
9
|
+
declare function isTerminal(status: HopStatus): boolean;
|
|
10
|
+
/** LLM query options */
|
|
11
|
+
interface LLMOptions {
|
|
12
|
+
temperature?: number;
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
responseFormat?: z.ZodType;
|
|
15
|
+
systemPrompt?: string;
|
|
16
|
+
}
|
|
17
|
+
/** LLM query result */
|
|
18
|
+
interface LLMResult {
|
|
19
|
+
success: boolean;
|
|
20
|
+
content: string;
|
|
21
|
+
raw?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Verification result */
|
|
24
|
+
interface VerifyResult {
|
|
25
|
+
passed: boolean;
|
|
26
|
+
reason: string;
|
|
27
|
+
status?: HopStatus;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* LLM Protocol — injected by the consuming project.
|
|
31
|
+
* opencode uses AI SDK, other projects bring their own adapter.
|
|
32
|
+
*/
|
|
33
|
+
interface HopLLM {
|
|
34
|
+
query(prompt: string, options?: LLMOptions): Promise<LLMResult>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Verifier Protocol — for reverse/forward cross verification.
|
|
38
|
+
* The consuming project provides the LLM-backed implementation.
|
|
39
|
+
*/
|
|
40
|
+
interface HopVerifier {
|
|
41
|
+
verify(task: string, context: string, result: string): Promise<VerifyResult>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Result of executing a single step */
|
|
45
|
+
interface StepResult {
|
|
46
|
+
step_id: string;
|
|
47
|
+
status: HopStatus;
|
|
48
|
+
output: unknown;
|
|
49
|
+
retries: number;
|
|
50
|
+
error?: string;
|
|
51
|
+
}
|
|
52
|
+
/** Result of executing a full spec */
|
|
53
|
+
interface ExecutionResult {
|
|
54
|
+
status: HopStatus;
|
|
55
|
+
output: unknown;
|
|
56
|
+
steps: StepResult[];
|
|
57
|
+
stats: ExecutionStats;
|
|
58
|
+
}
|
|
59
|
+
/** Execution statistics */
|
|
60
|
+
interface ExecutionStats {
|
|
61
|
+
total_steps: number;
|
|
62
|
+
completed_steps: number;
|
|
63
|
+
failed_steps: number;
|
|
64
|
+
total_retries: number;
|
|
65
|
+
llm_calls: number;
|
|
66
|
+
verify_calls: number;
|
|
67
|
+
}
|
|
68
|
+
/** Create empty execution stats */
|
|
69
|
+
declare function createEmptyStats(): ExecutionStats;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* spec-executor.ts — Step orchestrator
|
|
73
|
+
* Port of hop_engine/jit/spec_executor.py
|
|
74
|
+
*
|
|
75
|
+
* Executes a StepInfo tree by dispatching each step to the appropriate handler:
|
|
76
|
+
* - LLM steps: query LLM, verify, retry
|
|
77
|
+
* - code steps: evaluate expressions (sandboxed)
|
|
78
|
+
* - loop steps: iterate over collection or while condition
|
|
79
|
+
* - branch steps: conditional execution
|
|
80
|
+
* - flow steps: exit, continue, break
|
|
81
|
+
* - call steps: invoke external tools
|
|
82
|
+
* - subtask steps: delegate to sub-executor
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
interface SpecExecutorOptions {
|
|
86
|
+
llm: HopLLM;
|
|
87
|
+
verifier?: HopVerifier;
|
|
88
|
+
maxRetries?: number;
|
|
89
|
+
}
|
|
90
|
+
declare class SpecExecutor {
|
|
91
|
+
private llm;
|
|
92
|
+
private verifier;
|
|
93
|
+
private maxRetries;
|
|
94
|
+
constructor(options: SpecExecutorOptions);
|
|
95
|
+
/** Execute a StepInfo tree with given input variables */
|
|
96
|
+
execute(steps: StepInfo[], input: Record<string, unknown>): Promise<ExecutionResult>;
|
|
97
|
+
/** Execute a single step, dispatching by type */
|
|
98
|
+
private executeStep;
|
|
99
|
+
private executeLLM;
|
|
100
|
+
private executeCode;
|
|
101
|
+
private executeLoop;
|
|
102
|
+
private executeBranch;
|
|
103
|
+
private executeFlow;
|
|
104
|
+
private executeCall;
|
|
105
|
+
private executeSubtask;
|
|
106
|
+
private buildPrompt;
|
|
107
|
+
private storeOutputs;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* hop-jit.ts — Top-level JIT orchestrator
|
|
112
|
+
* Port of hop_engine/jit/hop_jit.py
|
|
113
|
+
*
|
|
114
|
+
* Ties together parser, validator, and executor into a single entry point:
|
|
115
|
+
* - runSpec(markdown, input) — parse → validate → execute
|
|
116
|
+
* - resume(feedback) — inject feedback and continue from NEED_INPUT checkpoint
|
|
117
|
+
* - cancel() — discard pending execution state
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
type SpecMode = "aot" | "jit";
|
|
121
|
+
interface HopJITOptions {
|
|
122
|
+
llm: HopLLM;
|
|
123
|
+
verifier?: HopVerifier;
|
|
124
|
+
maxRetries?: number;
|
|
125
|
+
grammar?: SpecGrammar;
|
|
126
|
+
}
|
|
127
|
+
interface RunSpecOptions {
|
|
128
|
+
/** Skip validation (debug only) */
|
|
129
|
+
skipValidation?: boolean;
|
|
130
|
+
/** Validation mode: "aot" for human-audited, "jit" for LLM-generated */
|
|
131
|
+
mode?: SpecMode;
|
|
132
|
+
}
|
|
133
|
+
interface JITResult {
|
|
134
|
+
status: HopStatus;
|
|
135
|
+
output: unknown;
|
|
136
|
+
steps: ExecutionResult["steps"];
|
|
137
|
+
stats: ExecutionStats;
|
|
138
|
+
/** Parsed spec (StepInfo tree) */
|
|
139
|
+
spec: StepInfo[];
|
|
140
|
+
/** Validation errors (empty if skipValidation or all passed) */
|
|
141
|
+
validationErrors: Array<{
|
|
142
|
+
check: string;
|
|
143
|
+
step_id: string;
|
|
144
|
+
message: string;
|
|
145
|
+
level: string;
|
|
146
|
+
}>;
|
|
147
|
+
/** Set when executor signals NEED_INPUT — call resume(feedback) to continue */
|
|
148
|
+
needInput?: NeedInputInfo;
|
|
149
|
+
}
|
|
150
|
+
interface NeedInputInfo {
|
|
151
|
+
diagnosis: string;
|
|
152
|
+
suggestions: string[];
|
|
153
|
+
step_id: string;
|
|
154
|
+
round: number;
|
|
155
|
+
}
|
|
156
|
+
declare class HopJIT {
|
|
157
|
+
private llm;
|
|
158
|
+
private verifier;
|
|
159
|
+
private maxRetries;
|
|
160
|
+
private grammar;
|
|
161
|
+
private _liveExecutor;
|
|
162
|
+
private _liveSpec;
|
|
163
|
+
private _liveValidationErrors;
|
|
164
|
+
private _pendingNeedInput;
|
|
165
|
+
constructor(options: HopJITOptions);
|
|
166
|
+
/**
|
|
167
|
+
* Parse and execute a HopSpec markdown document.
|
|
168
|
+
*
|
|
169
|
+
* Flow: parse → validate → execute
|
|
170
|
+
* Returns a JITResult with execution output, stats, and validation info.
|
|
171
|
+
*/
|
|
172
|
+
runSpec(markdown: string, input: Record<string, unknown>, options?: RunSpecOptions): Promise<JITResult>;
|
|
173
|
+
/**
|
|
174
|
+
* Resume execution from a NEED_INPUT checkpoint.
|
|
175
|
+
* Injects feedback and continues from the interrupted step.
|
|
176
|
+
*
|
|
177
|
+
* @throws Error if no pending execution to resume
|
|
178
|
+
*/
|
|
179
|
+
resume(feedback: string): Promise<JITResult>;
|
|
180
|
+
/** Cancel any pending execution and clear resume state. */
|
|
181
|
+
cancel(): void;
|
|
182
|
+
/** Whether there is a pending execution that can be resumed. */
|
|
183
|
+
get hasPending(): boolean;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* response-format.ts — Zod schema dynamic builder
|
|
188
|
+
* Port of create_response_format_model from hop_engine/utils/utils.py
|
|
189
|
+
*
|
|
190
|
+
* Builds Zod schemas from HopSpec return_format strings:
|
|
191
|
+
* - Simple types: str, int, float, bool, list, dict
|
|
192
|
+
* - Dict format: {"key": type, "key2": type}
|
|
193
|
+
* - Tuple syntax: {"key": (type, "description")} (description stored in metadata)
|
|
194
|
+
* - List types: list[str], list[int], list[dict]
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
interface FieldDef {
|
|
198
|
+
type: z.ZodType;
|
|
199
|
+
description?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Parse a return format string into a map of field → Zod type.
|
|
203
|
+
* Supports:
|
|
204
|
+
* - Dict format: {"key": type, "key2": (type, "desc")}
|
|
205
|
+
* - Non-dict: treated as single "result" field
|
|
206
|
+
* - Empty: returns undefined
|
|
207
|
+
*/
|
|
208
|
+
declare function parseReturnFormat(formatStr: string): Record<string, FieldDef> | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Create a Zod response schema from a format string.
|
|
211
|
+
* Wraps the user's fields in the standard HOP meta-fields:
|
|
212
|
+
* - explanation: string
|
|
213
|
+
* - final_answer: user's format
|
|
214
|
+
* - confidence: "OK" | "LACK_OF_INFO" | "UNCERTAIN"
|
|
215
|
+
*/
|
|
216
|
+
declare function createResponseFormat(formatStr: string): z.ZodType;
|
|
217
|
+
/**
|
|
218
|
+
* Create a Zod schema for just the data portion (without meta-fields).
|
|
219
|
+
* Useful for validating step output directly.
|
|
220
|
+
*/
|
|
221
|
+
declare function createDataSchema(formatStr: string): z.ZodType;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* validators.ts — Verification functions
|
|
225
|
+
* Port of hop_engine/validators/result_validators.py
|
|
226
|
+
*
|
|
227
|
+
* Three verification strategies:
|
|
228
|
+
* - formatVerifier: local JSON structure check (no LLM)
|
|
229
|
+
* - reverseVerify: LLM-based reverse verification
|
|
230
|
+
* - forwardCrossVerify: 3-way concurrent LLM verification
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Verify that a result has the expected structure and no serialization residue.
|
|
235
|
+
* Returns immediately without LLM calls.
|
|
236
|
+
*/
|
|
237
|
+
declare function formatVerifier(result: unknown, expectedKeys?: string[]): VerifyResult;
|
|
238
|
+
/**
|
|
239
|
+
* Reverse verification: ask a verifier LLM to independently check
|
|
240
|
+
* whether the result correctly answers the task given the context.
|
|
241
|
+
*/
|
|
242
|
+
declare function reverseVerify(verifier: HopVerifier, task: string, context: string, result: string): Promise<VerifyResult>;
|
|
243
|
+
/**
|
|
244
|
+
* Forward cross verification: run 3 concurrent verifications
|
|
245
|
+
* and return passed only if majority (2+) agree.
|
|
246
|
+
*/
|
|
247
|
+
declare function forwardCrossVerify(verifier: HopVerifier, task: string, context: string, result: string): Promise<VerifyResult>;
|
|
248
|
+
|
|
249
|
+
export { type ExecutionResult, type ExecutionStats, HopJIT, type HopJITOptions, type HopLLM, type HopStatus, type HopVerifier, type JITResult, type LLMOptions, type LLMResult, type NeedInputInfo, type RunSpecOptions, SpecExecutor, type SpecExecutorOptions, type SpecMode, type StepResult, type VerifyResult, createDataSchema, createEmptyStats, createResponseFormat, formatVerifier, forwardCrossVerify, isSuccess, isTerminal, parseReturnFormat, reverseVerify };
|