Skip to content

docs(skills): count the shapes of real inputs in the reach line - #303

Open
schiller-manuel wants to merge 1 commit into
docs/explore-grammar-from-callersfrom
docs/grammar-shapes-from-real-inputs
Open

schiller-manuel wants to merge 1 commit into
docs/explore-grammar-from-callersfrom
docs/grammar-shapes-from-real-inputs

Conversation

@schiller-manuel

Copy link
Copy Markdown
Contributor

A downstream project's code transform had laws that said "every module". No history generated JSX, a nested block, or a transform that rebuilds a node, although the package's own benchmark corpus is .tsx modules. The oracle and the gap check were green, and the ORC-004 range control was a sentence in limits that nothing checked against those inputs.

This PR is docs only. It gives the recipe with today's API: label each real input with a function the author writes, declare the labels as measured states, and label each history in reached. Each unit's reach line then shows a 0 for every shape of a real input that no generated history had. A probe below shows that the recipe works with no framework change, so no new option is proposed for approval.

Stacked on #270 (docs/explore-grammar-from-callers), because both PRs edit the same ORC-004 reconstruction line and the same list in explore step 4.

What changed

  • Design skill, step 5: the ORC-004 reconstruction control also covers "each shape that the package's real inputs have". A new bullet after it, Count the shapes of real inputs, gives three steps:

    1. A function from an input to its shapes, in the domain's own words (node types, config keys, the kinds of a log's entries). It names shapes and judges nothing, so it may use production's parser.
    2. When the file loads, label every real input and declare each label in measured.
    3. In reached, label the history's input and keep the labels that a real input has, together with the driver's own reach values, which reached replaces.

    It ends with what to do about a 0: widen the grammar, or state the shape in limits. A shape that a law depends on goes in states, where the property fails to load until a constructed history (one the arbitrary can generate) enters it.

  • Explore skill, step 4: below docs(skills): draft the history grammar from what real callers do #270's "What its callers do between calls", a bullet What shapes its real inputs have. It covers the corpus, benchmark inputs, and the inputs of ordinary tests. Label them, compare the labels with the drafted grammar, and make each missing shape a history dimension or a stated limit. It points to the design bullet.

The probe (on origin/main, 0175017)

The scratch package is oracle-gaps/.scratch-shapes (ignored, deleted afterwards), run with the real CLI and Vitest.

Production uses the TypeScript parser, with a generic walk:

// The names a module reads: every identifier except a declared variable's own
// name and the property name after a dot, once each, sorted.
export function referencedNames(source: string): Array<string> {
  const file = ts.createSourceFile(`module.tsx`, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX)
  const names = new Set<string>()
  const visit = (node: ts.Node): void => {
    if (ts.isIdentifier(node)) {
      const parent = node.parent
      const declares = ts.isVariableDeclaration(parent) && parent.name === node
      const member = ts.isPropertyAccessExpression(parent) && parent.name === node
      if (!declares && !member) names.add(node.text)
    }
    ts.forEachChild(node, visit)
  }
  visit(file)
  return [...names].sort()
}
  • Grammar: up to four statements, each const x = e or f(e, e). An expression is a name, a digit, a property read a.b, or e + e. The model states the rule: a name is read where it stands as an expression, as a callee, or as the object of a property read. Law: "For every module, referencedNames returns each name the module reads, once, sorted." One calibration drops a read name.
  • Corpus: corpus/route.tsx, a route module with a component function, an if block, and two JSX elements with attributes; corpus/loader.ts, two statements.

1. Green, and nothing names the missing shapes. The oracle passes 8 of 8 tests. The gap check (node index.mjs --package .scratch-shapes --source src/names.ts --config vitest.config.mjs --seed 42) reports 21 mutants, 21 killed, 0 gaps. The walk is generic, so flat modules reach every line. Meanwhile production is wrong on the corpus:

corpus/route.tsx ["Empty","List","Posts","component","createRoute","empty","items","path","posts","reason","usePosts"]

component and path are object keys, and items and reason are JSX attribute names. None of them is read.

2. The recipe with today's API (the labeller lists ts.SyntaxKind names, and the corpus is read with readdirSync when the file loads):

measured: [`an empty module`, ...[...realShapes].sort().map((shape) => `shape ${shape}`)],
reached: (plan, trace) => [
  ...trace.filter(({ checkpoint }) => checkpoint === `reach`).map(({ value }) => String(value)),
  ...[...shapesOf(render(plan))].filter((shape) => realShapes.has(shape)).map((shape) => `shape ${shape}`),
],

It prints (random unit; the fixed-seed unit has the same zeros):

scratch.referenced-names random seed: generated reach {"an empty module":15,"shape BinaryExpression":64,"shape Block":0,"shape CallExpression":61,"shape EndOfFileToken":100,"shape EqualsEqualsEqualsToken":0,"shape ExpressionStatement":61,"shape FunctionDeclaration":0,"shape Identifier":85,"shape IfStatement":0,"shape JsxAttribute":0,"shape JsxAttributes":0,"shape JsxExpression":0,"shape JsxSelfClosingElement":0,"shape NoSubstitutionTemplateLiteral":0,"shape NumericLiteral":54,"shape ObjectLiteralExpression":0,"shape PlusToken":64,"shape PropertyAccessExpression":55,"shape PropertyAssignment":0,"shape ReturnStatement":0,"shape SourceFile":100,"shape VariableDeclaration":58,"shape VariableDeclarationList":58,"shape VariableStatement":58}

The corpus has 24 shapes, and 12 of them (50%) were never generated: Block, EqualsEqualsEqualsToken, FunctionDeclaration, IfStatement, JsxAttribute, JsxAttributes, JsxExpression, JsxSelfClosingElement, NoSubstitutionTemplateLiteral, ObjectLiteralExpression, PropertyAssignment, ReturnStatement. The gap check with the recipe in place still says 21 mutants, 21 killed, 0 gaps. The line goes to its test-output.log, and the driver's own state (an empty module) is kept.

3. The gate. With states: ['shape JsxAttribute'] (taken out of measured), the file fails to load:

Error: scratch.referenced-names: no constructed history enters shape JsxAttribute. A required state needs a constructed history; a state that is only counted belongs in `measured`.

The History type has no JSX, so no constructed history can enter that state until the grammar writes JSX.

4. Widening the grammar finds the bug. Add <T attr={e} /> as an expression, and owe the tag and the value's reads but not the attribute name. The oracle then fails 2 of 8 tests (both campaign units), and shrinks to:

History: [{"kind":"const","name":"a","init":{"jsx":{"tag":"A","attr":"a","value":{"num":0}}}}]

Why docs, and not a framework option

The suggested hint was: parse the package's own inputs, list their node types, and report the ones no history produced. What exists already covers each part:

  • Labels on real inputs: measured takes any list of names, and it can be computed when the file loads.
  • Labels on drawn histories: reached(plan, trace, expected) receives every judged history. A history arbitrary sampled in a separate test (the arbitrary is the author's own value, so that is possible) would be a separate draw, and an oracle file cannot hold such a test (oracle/no-unit-test). reached sees exactly the histories that each unit judged.
  • Report the ones never produced: every unit prints each declared state, zeros included (ORC-015).
  • Fail on one that matters: a state in states needs a constructed history that the arbitrary takes back.

So the framework stays domain-neutral, and the cost is about ten lines in the oracle file.

Evidence

Docs only, so no RED/GREEN and no changeset (a docs-only skill PR):

git grep -c "Count the shapes of real inputs" origin/main -- packages/oracles/skills   # no match
git grep -c "Count the shapes of real inputs" HEAD -- packages/oracles/skills          # oracles-design/SKILL.md:1, oracles-explore/SKILL.md:1
  • The probe above ran on origin/main 0175017. Both gap-check runs end with oracle-gaps: done completed, 0 gaps.
  • The snippet in the skill has the same form as the probe's oracle file, which ran green. Prettier formats it unchanged.
  • npx -y pnpm@11.1.0 run build, lint:check, format:check and typecheck pass at the root. No test is added, so the shard checks are unchanged.

Overlap

Limits

  • The recipe compares shapes one at a time. A combination that no history generated (JSX inside a nested block, or a transform that rebuilds the node it reads) shows up only if the labeller also emits labels for pairs, such as a parent and child node type. The skill does not ask for pairs.
  • "Real inputs" are the ones the package has. Inputs that only callers have still come from docs(skills): draft the history grammar from what real callers do #270's step.
  • With about 100 node types, the reach line is long, and the zeros have to be read out of it. A unit counts only its own histories, so a shape that only a constructed history writes shows in that unit's line and still has a 0 in the generated units.
  • A history with several inputs (a workflow of transforms, say) needs every input it builds labelled, not only the first.

For approval

  1. The docs rule: count the shapes of real inputs in the reach line (design step 5), and list them when drafting the grammar (explore step 4).
  2. Question, not built: a framework option. If reading zeros out of a long reach line proves too costly, a generated source could take realInputs: { inputs, labels } and print one more line per passing unit, <id> <unit> shapes not generated: …. It would add no states, and it would be the recipe in one option. I recommend waiting until a real oracle finds the reach line too hard to read.

🤖 Generated with Claude Code

A grammar drafted by hand can miss shapes that the package's own inputs
have, and the oracle and the gap check stay green. The design skill's step
5 gives the recipe with today's API: a labelling function from an input to
its shapes, the real inputs' labels as measured states, and `reached`
labelling each history's input, so a 0 in a generated unit's reach line
names a shape no generated history had. The explore skill's step 4 lists
the real inputs' shapes beside the callers' operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7824fc3f-39e7-48cf-92f6-50e99372c1c5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-25T21:21:55.561389Z 5492785 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5492785

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/TanStack/oracles/@tanstack/eslint-plugin-oracles@303
npm i https://pkg.pr.new/TanStack/oracles/@tanstack/oracles@303

commit: 5492785

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