Repository navigation
S18: specToCode TypeScript generator - #858
Merged
Merged
Conversation
specToCode(spec) renders a validated AgentSpec v2 as a readable, deterministic TypeScript ES module: a createAgent({...}) call with plain data inlined via toTsLiteral and the reference sections written as calls to the package-root spec resolvers (resolveToolRef, resolveSkillRef, memoryFromSpec, subagentFromSpec, handoffFromSpec, guardrailsFromSpec, permissionsFromSpec, hooksFromSpec, outputFromSpec, resolveMcpServers, jsonSchemaToStandardSchema, specV2ToAgent) against a module-level host. Only the resolvers actually used are imported. Handoffs resolve subagent targets through a const subagents record and a host resolveHandoffAgent that throws for targets the file does not define; triggers/abortListeners/flow/evals end the module as a commented 'export const spec'.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
src/spec/generators/typescript.ts— newspecToCode(spec, options?): renders a validated AgentSpec v2 as a readable, deterministic TypeScript ES module. Data keys are inlined; the reference sections (tools, mcpServers, skills, memory, subagents, handoffs, guardrails, permissions, hooks, output) render as calls to the package-root spec resolvers against a module-levelhost.instructionsrenders as a template literal with theinstructionsByFamilytail resolved at generation time ({ file }→await readFile+ conditionalnode:fs/promisesimport),promptRef→prompt,modelstays a'provider/model'string. Option order follows a fixed KEY_ORDER; only the resolvers actually used are imported (sorted). When handoffs exist, the subagents record is hoisted toconst subagentsandhost.resolveHandoffAgentresolves subagent targets or throws "handoff target '' is not defined in this file".triggers/abortListeners/flow/evalsend the module as a commentedexport const spec = { ... } as const;. Not exported from the package root (that is S23).src/spec/generators/tsLiteral.ts— newtoTsLiteral(value, indent)/tsObjectKeyprinter: single-quoted strings, identifier-safe keys bare, inline ≤ 80 cols else one element per line, 2-space indent.src/utils/plainErrors.test.ts— ALLOWED entry for the generatedthrow new Error(literal (generated modules cannot import SDKError).typescript.test.ts(15 tests: minimal inline snapshot, full-section file snapshot, determinism/key order, minimal imports, template-literal escape round-trip, readFile import, family tail, handoff resolvers, triggers trailer, transpileModule syntax check over 4 cases) andtsLiteral.test.ts(8 tests).Notes: package default is
'lousho'(renamed from@lousho/build-ai-agent);resolveToolRefis emitted with its real signature(ref, { ...host, agentName }, 'tools.<i>').How tested
npx vitest run src/spec/generators— 38 tests pass (incl. plainErrors)npx tsc --noEmit,npm run typecheck:tests,npm run lint— cleannpm run test:coverage(with--coverage.reportOnFailureso the report writes despite the known failures) — 7179 pass; pre-existing failures only:templates.test.tsREADME checks (CRLF checkout on Windows; index is LF), one flakyconnect.test.tsMCP timing test; runRegistry checkpoint flake did not reproducenpm run fallow,npm run docs:ratchet,npm run api:check,npm run docs:llms:check,npm run size-check— cleanAcceptance criteria
createAgent({ name, model, instructions })callts.transpileModule, ESNext/ES2022)${x}and `\n` survive (evaluating the template literal gives the original)export const spec = { triggers: [...] } as const;blockGenerated with Devin