-
-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Summary
Add an optional schema field to OutputConfig<T> so commands can register the Zod schema for their JSON output type. This enables:
-
Typed SDK generation — Build-time codegen can read schemas from the command tree and generate TypeScript return types automatically, eliminating the need for a manual type map.
-
JSON output documentation — The
--jsonmode can be documented with exact field-level schemas, including which fields are optional, enum values, nested structures, etc. -
Runtime validation — Optionally validate command output against the schema in dev/test modes to catch type drift.
-
JSON Schema generation — Export schemas as JSON Schema for consumers who want to validate output in other languages.
Proposed API
// In buildCommand:
output: {
human: formatIssueList,
schema: IssueListOutputSchema, // NEW — Zod schema for the JSON output
jsonExclude: ["humanOnlyField"],
}The schema describes the shape of the data AFTER jsonTransform and jsonExclude are applied — i.e., what the consumer actually receives.
Where schemas already exist
Most API response types in src/types/sentry.ts already have Zod schemas (e.g., SentryUserSchema, SentryTeamSchema, SpanListItemSchema). For list commands, the envelope { data: T[], hasMore: boolean, nextCursor?: string } would need a generic wrapper.
Integration points
src/lib/formatters/output.ts—OutputConfig<T>type gains optionalschemafieldsrc/lib/introspect.ts— Expose schema from command metadata for codegenscript/generate-sdk.ts— Read schemas to auto-generate typed return typesscript/generate-skill.ts— Could emit JSON Schema in SKILL.md for agent consumption
Context
This was identified during the library export work (#565) as the principled solution for typed SDK return values. Currently, a manual type map bridges the gap, but schema registration would make it automatic and self-documenting.