Skip to content

Conversation

@seefeldb
Copy link
Contributor

@seefeldb seefeldb commented Nov 3, 2025

The recipe() function now accepts just a function parameter without requiring a name or schema. This provides a more ergonomic API for simple recipes where the schema can be inferred from default values.

Changes:

  • Added function-only overload to recipe() that accepts just a function
  • Updated implementation to handle undefined argumentSchema
  • Refactored schema creation logic to eliminate code duplication
  • Schema generated from function-only recipes does not have a description field
  • Added tests for function-only recipe syntax
  • Added transformer fixtures for recipes without names

Usage:
recipe((input: { x: number }) => { return { result: derive(input.x, x => x * 2 }; });

🤖 Generated with Claude Code


Summary by cubic

recipe() can now be called with just a function, without a name or schema. For simple recipes, the input schema is inferred from defaults; when the function parameter is typed, the transformer injects toSchema automatically.

  • New Features

    • Added a function-only overload to recipe() in the API and runner.
    • When called with only a function, argumentSchema is handled as undefined and inferred from defaults.
    • Generated schemas for function-only recipes omit the description field.
    • Transformer supports single-parameter recipe() calls by injecting toSchema when the input param has a type annotation.
    • Transformer preserves the recipe name when transforming recipe("name", (input: T) => ...).
    • Updated the rollout plan to mark “Make name parameter in recipe optional” as done.
  • Refactors

    • Removed redundant recipe names across patterns and internals; adopted function-only syntax with no behavior changes.

Written for commit 409a66d. Summary will update automatically on new commits.

The recipe() function now accepts just a function parameter without
requiring a name or schema. This provides a more ergonomic API for
simple recipes where the schema can be inferred from default values.

Changes:
- Added function-only overload to recipe() that accepts just a function
- Updated implementation to handle undefined argumentSchema
- Refactored schema creation logic to eliminate code duplication
- Schema generated from function-only recipes does not have a description field
- Added tests for function-only recipe syntax
- Added transformer fixtures for recipes without names

Usage:
  recipe((input: { x: any }) => {
    input.x.setDefault(42);
    return { result: input.x * 2 };
  });

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@seefeldb seefeldb requested a review from mathpirate November 3, 2025 20:59
seefeldb and others added 2 commits November 3, 2025 12:59
Remove recipe name parameters throughout the codebase where the names
don't add meaningful value. Names were mostly duplicating information
already available from the file name or [NAME] symbol.

Changes:
- built-in.ts: Removed type parameter, use type inference
- opaque-ref.ts: Removed "mapping function" name from internal map
- Multiple pattern files: Removed redundant names, use inline types

Files updated:
- array-in-cell-ast-nocomponents, charm-ref-in-cell, charms-ref-in-cell
- cheeseboard, common-tools, counter, ct-render, dice
- instantiate-recipe, linkedlist-in-cell, llm, nested-counter, output_schema

All patterns still function identically using the more concise
function-only syntax.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 10 files

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 15 files

seefeldb and others added 4 commits November 3, 2025 14:00
Add transformer support for recipe() calls without explicit type arguments.
When recipe() is called with just a function parameter that has a type
annotation, the transformer now infers and injects the schema automatically.

Examples:
- recipe((state: State) => ...) → recipe(toSchema(State), (state) => ...)
- recipe("name", (state: State) => ...) → recipe(toSchema(State), (state) => ...)

This change maintains backward compatibility by only transforming when
an explicit type annotation is present on the function parameter.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

Reviewed changes from recent commits (found 3 issues).

3 issues found across 27 files

Prompt for AI agents (all 3 issues)

Understand the root cause of the following 3 issues and fix them.


<file name="packages/ts-transformers/src/transformers/schema-injection.ts">

<violation number="1" location="packages/ts-transformers/src/transformers/schema-injection.ts:228">
This rewrite drops the recipe name when callers pass `recipe(&quot;name&quot;, (input: T) =&gt; ...)`, so the resulting schema no longer carries its description. Please preserve the original string argument when rebuilding the call.</violation>
</file>

<file name="docs/common/RECIPES.md">

<violation number="1" location="docs/common/RECIPES.md:18">
This bullet still claims the arguments are a descriptive name and a function, but with the new overload the name is optional—please update the wording to reflect that.</violation>

<violation number="2" location="docs/common/RECIPES.md:703">
The reactive string example now references `notification.count`, but the surrounding text and previous version use `notifications.count`, so this snippet no longer compiles as written.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

… parameter

Add test fixtures demonstrating that recipe() with explicit type arguments
but no name parameter correctly transforms and injects schemas.

New fixtures:
- counter-recipe-no-name: recipe<RecipeState>((state) => ...)
- map-single-capture-with-type-arg-no-name: recipe<State>((state) => ...)
- jsx-conditional-rendering-no-name: recipe<State>((state) => ...)
- map-handler-reference-with-type-arg-no-name: recipe<State>((state) => ...)

These fixtures validate that the transformer handles recipe() calls with
type arguments but without the optional name parameter, ensuring schema
injection works correctly in this configuration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
seefeldb and others added 2 commits November 3, 2025 15:01
…name", (input: T) => ...)

Previously, when transforming recipe calls with both a name string and a typed
parameter like `recipe("MyRecipe", (input: Input) => ...)`, the transformer
would drop the name argument, resulting in `recipe(toSchema<Input>(), (input) => ...)`.

This caused the resulting schema to lose its description.

Now the transformer correctly preserves the name argument, producing:
`recipe("MyRecipe", toSchema<Input>(), (input) => ...)`

Added test fixture to verify the fix.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 11 files

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

@seefeldb seefeldb merged commit 4ebf35c into main Nov 3, 2025
9 checks passed
@seefeldb seefeldb deleted the feat/no-longer-require-name-parameter-for-recipe branch November 3, 2025 23:16
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.

2 participants