Skip to content

[rig-sampler] Add s.literal helper for single-value enum constraints - #34

Merged
pelikhan merged 1 commit into
mainfrom
rig-sampler/14-changelog-categorizer-da7cc4a21e1f6f8a
Jul 23, 2026
Merged

[rig-sampler] Add s.literal helper for single-value enum constraints#34
pelikhan merged 1 commit into
mainfrom
rig-sampler/14-changelog-categorizer-da7cc4a21e1f6f8a

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Sample run

Ran sample 14-changelog-categorizer.ts (a validation-plan agent) through the stub harness. The agent produced valid JSON in 1 turn with no repair. Output schema used s.array(s.string) for commands and manualChecks, and s.string for rationale.

What the run revealed

The schema helpers are well-used in samples, and enum-based constraint is a recurring pattern. However, when a field must be exactly one specific value (e.g. a "done" status sentinel or a fixed protocol token), authors must write s.enum("done") — which works but doesn't clearly signal "single literal" intent. It can also be confused with "one of many choices".

Change

Added s.literal<T>(value: T, description?: string): EnumSchema<[T]> to the s helpers:

s.literal("done")               // accepts only "done"; infers as "done"
s.literal(42)                   // accepts only 42; infers as 42
s.literal(true, "must be true") // with description
  • Implemented as a thin wrapper around the existing EnumSchema/serializeSchema path (no new logic).
  • Inferred TypeScript type is the narrow literal T, not a union.
  • Documented with JSDoc + examples in rig.ts.
  • Header summary line updated.
  • 5 new unit tests added in src/rig.test.ts covering serialization, validation (pass/fail), and description propagation.
  • All 141 existing tests continue to pass.

Generated by Daily Rig Sampler · 86.5 AIC · ⌖ 8.21 AIC · ⊞ 5.2K ·

Adds s.literal(value, description?) as a more expressive alternative
to s.enum(value) when only one exact value is valid. The inferred
TypeScript type is the literal itself (e.g. s.literal("done") infers
as "done").

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review July 23, 2026 12:26
@pelikhan
pelikhan merged commit be1c13a into main Jul 23, 2026
1 check passed
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skills-Based Review

Applied /tdd - approving with one non-blocking suggestion on test duplication.

  • Minor test duplication: the 'converts literal schemas' case in the toJsonSchema block repeats three assertions already in the new s.literal suite. Low risk but worth cleaning.

Positive highlights:

  • Clean thin-wrapper, no new logic, delegates to existing EnumSchema path
  • const T generic correctly narrows the inferred type to the literal
  • Tests cover serialization, validation accept/reject, and description propagation
  • JSDoc examples and header summary updated

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 27.2 AIC · ⌖ 5.76 AIC · ⊞ 6.3K
Comment /matt to run again

Comment thread src/rig.test.ts
expect(toJsonSchema(s.literal("done"))).toEqual({ type: "string", enum: ["done"] });
expect(toJsonSchema(s.literal(42))).toEqual({ enum: [42] });
expect(toJsonSchema(s.literal(true, "must be true"))).toEqual({ enum: [true], description: "must be true" });
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/tdd] These three assertions duplicate the ones in the new s.literal describe block below (lines ~1186–1219). Keeping them in both places will cause drift if the behaviour changes.

💡 Suggestion

Remove this "converts literal schemas" test case from the toJsonSchema describe block entirely — the dedicated s.literal suite already covers serialization exhaustively. Alternatively, replace the three expects with a single representative assert here and add a comment pointing to the full suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant