Skip to content

feat: runtime#63

Draft
LeonardoTrapani wants to merge 12 commits intomasterfrom
runtime
Draft

feat: runtime#63
LeonardoTrapani wants to merge 12 commits intomasterfrom
runtime

Conversation

@LeonardoTrapani
Copy link
Contributor

@LeonardoTrapani LeonardoTrapani commented Feb 10, 2026

Greptile Overview

Greptile Summary

This PR adds a new “runtime” workflow that exposes the existing xschema pipeline via (1) a new Go CLI subcommand xschema convert that reads a JSON array of schema inputs from stdin and emits a JSON array of conversion results to stdout, and (2) a new TypeScript package @xschemadev/runtime that spawns the CLI to provide a programmatic convert() API.

To support runtime selection, each TS adapter package now exports an adapter metadata object and core introduces an XSchemaAdapter type. The web docs are updated with a runtime overview and API reference.

Key issues to address before merging:

  • xschema convert constructs retriever.RetrievedSchema values without SourceURI, but downstream processing/bundling uses SourceURI as the base for $ref resolution and for cache seeding/error context; relative refs can break.
  • @xschemadev/runtime writes to the child stdin without handling backpressure or stdin errors; large payloads can hang.
  • The “planned” Python runtime docs currently describe adapter as a string, which conflicts with the TypeScript runtime’s adapter: XSchemaAdapter object shape and will mislead users.

Confidence Score: 3/5

  • This PR is mergeable after fixing a couple of runtime-critical edge cases around $ref base URIs and process I/O handling.
  • The overall feature wiring is coherent (new CLI subcommand + TS wrapper + adapter metadata), but there are at least two concrete issues that can cause incorrect behavior/hangs in realistic usage: missing SourceURI in convert breaks relative $ref resolution in processor/bundler, and the runtime wrapper ignores stdin backpressure/error handling when sending JSON to the child process. Docs also currently diverge on adapter shape for the planned Python API.
  • cli/cmd/convert.go, typescript/packages/runtime/src/index.ts, web/content/docs/runtime/getting-started/python.mdx

Important Files Changed

Filename Overview
cli/cmd/convert.go Adds new xschema convert command reading schema array from stdin and generating JSON results; missing RetrievedSchema.SourceURI will break relative $ref resolution/bundling context.
cli/cmd/convert_test.go Adds integration-style tests for convert command; relies on built adapter CLI + bunx, but generally fine.
typescript/packages/runtime/package.json Introduces new @xschemadev/runtime package definition; exports dist entrypoints.
typescript/packages/runtime/src/index.ts Adds runtime convert() that spawns xschema convert; missing stdin backpressure/error handling can hang on large payloads.
web/content/docs/runtime/getting-started/python.mdx Updates planned Python runtime docs; currently describes adapter as string which conflicts with TS runtime's XSchemaAdapter object shape.

Sequence Diagram

sequenceDiagram
    participant UserCode as User code (@xschemadev/runtime)
    participant Runtime as runtime.convert()
    participant XS as xschema CLI
    participant Proc as processor.Process
    participant Gen as generator.GenerateAll

    UserCode->>Runtime: convert(schemas, {adapter, cwd?, allowFetch?})
    Runtime->>XS: spawn("xschema", ["convert","--adapter", adapter.id, ...])
    Runtime->>XS: stdin.write(JSON.stringify(schemas))
    XS->>Proc: Process(retrievedSchemas, {Fetcher, Cache, ...})
    Proc->>Proc: crawlAndFetch external $ref (if allowed)
    Proc->>Proc: bundle schemas (uses SourceURI as base)
    XS->>Gen: GenerateAll(processed, lang, projectRoot)
    Gen-->>XS: []ConvertResult
    XS-->>Runtime: stdout (JSON)
    Runtime-->>UserCode: parsed ConvertResult[]
    XS-->>Runtime: stderr (errors/verbose)
Loading

@vercel
Copy link

vercel bot commented Feb 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
xschema Ready Ready Preview, Comment Feb 10, 2026 11:40am

Request Review

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +90 to +97
if len(inputs) == 0 {
fmt.Fprintln(cmd.OutOrStdout(), "[]")
return nil
}

// Convert to retriever.RetrievedSchema with inline source type
schemas := make([]retriever.RetrievedSchema, len(inputs))
for i, in := range inputs {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing SourceURI breaks refs

retriever.RetrievedSchema.SourceURI is used as the base URI for resolving relative $ref values and for bundler error context/caching. In convert, schemas are constructed without SourceURI, so any schema containing relative refs (or circular refs that rely on cache seeding) can fail or resolve incorrectly. Consider setting a stable synthetic URI per input (e.g. inline://<namespace>/<id>), or accept sourceURI in ConvertSchemaInput and plumb it through.

Prompt To Fix With AI
This is a comment left during a code review.
Path: cli/cmd/convert.go
Line: 90:97

Comment:
**Missing SourceURI breaks refs**

`retriever.RetrievedSchema.SourceURI` is used as the base URI for resolving relative `$ref` values and for bundler error context/caching. In `convert`, schemas are constructed without `SourceURI`, so any schema containing relative refs (or circular refs that rely on cache seeding) can fail or resolve incorrectly. Consider setting a stable synthetic URI per input (e.g. `inline://<namespace>/<id>`), or accept `sourceURI` in `ConvertSchemaInput` and plumb it through.


How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +58 to +66
```
</Tab>
<Tab value="poetry">
```bash
poetry add xschema-runtime
```
</Tab>
</Tabs>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python API mismatch

This planned Python snippet calls convert(..., adapter="@xschemadev/zod"), but the TypeScript runtime you just introduced requires adapter: XSchemaAdapter (object with .id). If Python is intended to “mirror” the TS API, the docs should match one shape consistently; otherwise users will copy/paste an API that can’t exist alongside the current TS design.

Prompt To Fix With AI
This is a comment left during a code review.
Path: web/content/docs/runtime/getting-started/python.mdx
Line: 58:66

Comment:
**Python API mismatch**

This planned Python snippet calls `convert(..., adapter="@xschemadev/zod")`, but the TypeScript runtime you just introduced requires `adapter: XSchemaAdapter` (object with `.id`). If Python is intended to “mirror” the TS API, the docs should match one shape consistently; otherwise users will copy/paste an API that can’t exist alongside the current TS design.


How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +30 to +38
schemas: SchemaInput | SchemaInput[],
options: ConvertOptions,
): Promise<ConvertResult[]> {
const input = Array.isArray(schemas) ? schemas : [schemas];
const bin = options.executablePath ?? "xschema";

const args = ["convert", "--adapter", options.adapter.id];
if (options.allowFetch) args.push("--allow-fetch");
if (options.cwd) args.push("--project", options.cwd);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backpressure can hang

child.stdin.write(JSON.stringify(input)); child.stdin.end(); ignores backpressure and write errors. If write() returns false (large schema payloads) or emits an error, the subprocess may never receive the full input/EOF, and this promise can hang. Consider handling the write() return value (wait for drain) and listening for child.stdin.on("error", ...).

Prompt To Fix With AI
This is a comment left during a code review.
Path: typescript/packages/runtime/src/index.ts
Line: 30:38

Comment:
**Backpressure can hang**

`child.stdin.write(JSON.stringify(input)); child.stdin.end();` ignores backpressure and write errors. If `write()` returns `false` (large schema payloads) or emits an `error`, the subprocess may never receive the full input/EOF, and this promise can hang. Consider handling the `write()` return value (wait for `drain`) and listening for `child.stdin.on("error", ...)`.


How can I resolve this? If you propose a fix, please make it concise.

@LeonardoTrapani LeonardoTrapani marked this pull request as draft February 11, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant