Skip to content

refactor(contracts): declare the scroll reasons in one typed table with their owning command - #4820

Merged
thymikee merged 6 commits into
mainfrom
t3/typed-reasons-scroll
Nov 20, 2026
Merged

thymikee merged 6 commits into
mainfrom
t3/typed-reasons-scroll

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

error.details.reason is published vocabulary, but most reasons are string literals at new AppError(...) sites with no owner. This PR sets the pattern on the scroll family.

  • packages/contracts/src/scroll-reasons.ts declares SCROLL_REASONS: one row per reason, { reason, command }, typed by CommandReasonRow. No prose.
  • All 12 scroll construction sites read SCROLL_REASONS.<member>.reason. An undeclared reason does not compile. Wire values are unchanged; the tests that pin the literals are untouched.
  • The table supersedes SCROLL_REFRESH_REFUSALS and SCROLL_KEYBOARD_OCCLUDES_SURFACE_REASON. The runner row for the keyboard refusal carries no reason, so the table is its only source.
  • test/repo-guards/command-reason-owners.test.ts checks every row: its command is a CLI command and no two rows share a reason. The command reference will read the table directly when it prints refusal reasons.
  • commands.md now names the seven scroll reasons it omitted.

Not device-facing: behavior and wire output are unchanged.

Value

base head
R89 untyped reason sites 388 in 194 files 378 in 190 files
Scroll reasons with a declared owner 0 12
Scroll reasons checked against commands.md 0 12

Validation

At b844ca5, local: pnpm build; check:layering, check:fallow, check:production-exports, check:command-docs, check:daemon-wire-compat, check:quick all pass; 276 unit-core files (3373 tests) pass, including the eager-closure budget, repo guards, and the scroll tests in contracts, daemon, capture-kit, platform-apple and platform-android. CI owns the full suite.

Risk: the eager-closure budget admits a new table module only at flat statement weight. Here three superseded statements pay for it; later families need the same or a maintainer decision.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.47 MB 6.47 MB +804 B
Package (unpacked) 6.47 MB 6.47 MB +804 B
Package (download) 1.97 MB 1.97 MB +158 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 22.0 ms 23.8 ms +1.8 ms
CLI --help 48.0 ms 52.4 ms +4.3 ms

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on b844ca5. The verdict and the full list are in the summary comment.

Comment thread packages/contracts/package.json Resolved
@thymikee

Copy link
Copy Markdown
Member Author

The refactor looks sound at b844ca5, but one doc sentence names a reason that cannot arrive on the CLI. CI is green, including the diff-relevant jobs, Repo Guards & Compatibility and Lint/Typecheck/Package. Before merge, the commands.md sentence needs a fix.

The new sentence at website/docs/docs/commands.md:652 says an out-of-range --max-passes fails with details.reason scroll_max_passes_invalid. On the CLI, the flag parser enforces the same 1..200 bounds first (src/cli/parser/args.ts:319-324, bounds from flag-definitions-action.ts:181-185). It throws INVALID_ARGS "Invalid max-passes" with no reason, and the Node/MCP field bounds intercept it too. An agent that branches on that reason after a bad --max-passes never sees it. Could the sentence keep only the scroll_max_passes_requires_until half, or be scoped to a raw daemon route that can really deliver an out-of-range value? The rule is that every reason named in commands.md must be producible on a surface the sentence addresses. A raw daemon HTTP route was not traced end-to-end, so that route may exist.

Not blocking, and you can take or leave these: the assertion in scroll.test.ts:76 now compares the table to itself, so asserting the literal 'scroll_keyboard_occludes_surface' would keep it meaningful; publishedReasonsOf in scripts/command-docs/reasons.ts is not read by the generator, so one list should enumerate all published-reason tables, either by folding the owner into reasonTable() in runner-refusal-reason-docs.test.ts or by rendering it in generate.ts; and command-reason-owners.test.ts samples only scroll_no_progress, so asserting the full reason-to-command mapping for all 12 rows would pin every owner.

The open thread on the missing command-reasons.ts subpath export no longer applies, because its only consumer is the same-package scroll-reasons.ts and the table itself is exported, so it can be resolved: #4820 (comment)

Not verified here: the R89 388/194 to 378/190 counts were not re-measured. The diff removes 10 measured literals across 4 files, which matches the claimed deltas, and the R89 no-growth gate passes in CI. The local gate list from the PR body was not re-run. There are no conflicts.

thymikee and others added 3 commits November 20, 2026 17:24
…th their owning command

Every scroll details.reason is one row of SCROLL_REASONS, and each construction
site reads the row, so an undeclared reason does not compile. The wire values
are unchanged. The table supersedes SCROLL_REFRESH_REFUSALS and the
SCROLL_KEYBOARD_OCCLUDES_SURFACE_REASON constant. scripts/command-docs/reasons.ts
groups the rows by command for the command reference. commands.md now names
the seven scroll reasons it omitted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…contracts subpath

The published-reason docs guard reads the scroll table, a new guard holds each
reason to one owning command, and the contracts export snapshot lists the
scroll-reasons entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…heck every reason row's owner

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the t3/typed-reasons-scroll branch from b844ca5 to 56de069 Compare November 20, 2026 16:25
@thymikee

Copy link
Copy Markdown
Member Author

Fixed at 56de0692f2 (rebased onto current main).

  • Docs fix: the sentence no longer says an out-of-range --max-passes reaches scroll_max_passes_invalid from the CLI. It now says --max-passes without --until fails with scroll_max_passes_requires_until; the CLI, Node client and MCP reject an out-of-range value with INVALID_ARGS first; and a daemon request that still carries one fails with scroll_max_passes_invalid. The reason stays documented, so the reason-docs guard needs no waiver.
  • publishedReasonsOf (optional, taken): removed with scripts/command-docs/reasons.ts. It had no production reader, and the generator is being changed in docs(command-docs): generate the common option table and per-action option tables #4824; the reference will read the table when it prints reasons.
  • Owner test (optional, taken): command-reason-owners.test.ts now checks all 12 rows, not one sample: each command is a CLI command and no two rows share a reason.
  • scroll.test.ts:76 (optional, taken): the assertion pins the literal 'scroll_keyboard_occludes_surface' instead of reading it back from the table.

Local: build, typecheck, the owner and reason-docs guards, the Apple scroll tests, check:command-docs, doc-prose, fallow, production-exports, gate-manifest.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

One doc sentence still needs a fix at 56de069. The scroll_max_passes_invalid row, the guard test and the removal of scripts/command-docs/reasons.ts look right, so the earlier findings from #4820 (comment) are otherwise resolved.

The new sentence at commands.md:659 says the Node client and MCP reject an out-of-range --max-passes with INVALID_ARGS before the command runs, and that only a daemon request fails with scroll_max_passes_invalid. That is true only for the CLI (args.ts:320-325). The Node client writer (cli-grammar/common.ts:28) passes maxPasses straight through, and MCP admission (command-tools.ts:448-477) only rejects unknown keys. So client.interactions.scroll({ until, maxPasses: 500 }) and the MCP scroll tool reach the daemon and fail there with scroll_max_passes_invalid. An agent that branches on details.reason is told those surfaces never produce it. The rule the doc must satisfy is that it names only reasons some surface can deliver, and states the routing the code has: the CLI rejects the value with INVALID_ARGS while parsing flags, and the Node client, MCP and any daemon request fail with INVALID_ARGS and scroll_max_passes_invalid. Adding the bound check to the client or MCP admission would also make the sentence true, but that changes behavior beyond this PR.

Not verified here: the client and MCP routes were traced by reading the code and not run. A single client.interactions.scroll({ until, maxPasses: 500 }) call should show the daemon reason in details.reason.

Not blocking: COMMAND_REASON_TABLES in command-reason-owners.test.ts:7 is a second hand-kept list next to REASON_TABLES in runner-refusal-reason-docs.test.ts, so a new family has to be registered in both. When the second family lands, deriving both guards from one exported list would avoid that. Take it or leave it.

The only open inline thread, #4820 (comment) (reasons module not reachable from public exports), no longer applies and can be resolved. CommandReasonRow is now imported only by contracts/src/scroll-reasons.ts as a relative type import, and the scripts/command-docs/reasons.ts consumer is deleted.

CI is green at this head and there are no conflicts. Once the doc sentence is fixed, this is ready.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Fixed at 644859ae55. The sentence now follows the routing in the code: the CLI rejects an out-of-range --max-passes with INVALID_ARGS and no reason before the command runs; the Node client and MCP send the value to the daemon, which fails with INVALID_ARGS and scroll_max_passes_invalid. No bound check added. Docs-only change.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 644859a the routing sentence from the last review is fixed: the docs now say the CLI rejects an out-of-range --max-passes while parsing, and that the Node client, MCP and daemon requests fail with scroll_max_passes_invalid. CI is green and there are no conflicts. Review has nothing blocking left.

One precision note, take or leave: the missing-until sentence in commands.md#L659 promises scroll_max_passes_requires_until for any --max-passes without --until. When the value is also out of range, the CLI range check answers first with INVALID_ARGS and no reason. Stating the CLI range rejection first would cover that corner.

For a follow-up issue: the repo guards could register each command reason table once in the existing REASON_TABLES metadata, so a new family gets documentation coverage and owner validation together.

The earlier inline thread on the reasons module export no longer applies and can be resolved: #4820 (comment)

Not verified here: the Node client and MCP routes were traced by reading the code and not run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Optional precision taken at fc80f709a4: the sentence now says the CLI checks the range first, so a --max-passes that is out of range is rejected with INVALID_ARGS and no reason with or without --until. Only that sentence changed.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on fc80f70. The verdict and the full list are in the summary comment.

Comment thread website/docs/docs/commands.md Outdated
- `scroll refresh` is one slow pull down (`scroll up 0.4 --duration-ms 1200` by default; an amount, `--pixels`, or `--duration-ms` overrides it). On iOS, the pull runs down the middle of the screen. A list that sits only in the top or bottom part of the screen is not pulled.
- With a keyboard up, the scroll stays above the keyboard and leaves it open. The result reports this as `keyboardAvoided` and `keyboardMinY`. If too little room is left, end editing first. On Android, use `keyboard dismiss`. On iOS, use a visible dismissal control.
- A refused scroll names its cause in `details.reason`, and the hint gives the next step. The reasons are `scroll_refresh_not_at_top` (run `scroll top` first), `scroll_until_no_progress`, `scroll_until_edge_reached`, `scroll_keyboard_occludes_surface`, and `scroll_no_progress`.
- A refused scroll names its cause in `details.reason`, and the hint gives the next step. The reasons are `scroll_refresh_not_at_top` (run `scroll top` first), `scroll_keyboard_occludes_surface`, and `scroll_no_progress`. With `--until`, they are `scroll_until_pass_limit`, `scroll_until_edge_reached`, `scroll_until_no_progress`, and `scroll_until_capture_unreadable`. For `scroll top` and `scroll bottom`, they are `scroll_edge_pass_limit`, `scroll_edge_no_progress`, and `scroll_edge_capture_unreadable`. `--max-passes` without `--until` fails with `INVALID_ARGS` and `scroll_max_passes_requires_until`. The CLI checks the range first: it rejects an out-of-range `--max-passes` with `INVALID_ARGS` and no reason before the command runs, with or without `--until`. The Node client and MCP send the value to the daemon, which fails with `INVALID_ARGS` and `scroll_max_passes_invalid`.

@apex-sentinel-staging apex-sentinel-staging Bot Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on c03d507: marked fixed in c03d507 by thymikee in this comment; the code it pointed at changed.

🆕 🟡 Minor · commands.md says MCP out-of-range --max-passes fails in the daemon, but the tool input layer bounds it first

A caller that sends maxPasses: 500 through the MCP / AI SDK tool surface is refused at the tool-input layer, not by the daemon's assertScrollUntilCompatible, because scrollFields.maxPasses is integerField(..., { min: 1, max: SCROLL_UNTIL_MAX_PASSES }) and buildOptionField copies those bounds. The new commands.md sentence attributes a daemon reason (scroll_max_passes_invalid) to a path that may not reach it.

Suggested change

Confirm which layer refuses an out-of-range maxPasses for the MCP and AI SDK audiences and state that layer's error in commands.md; drop the claim that the daemon reports scroll_max_passes_invalid there if the tool schema rejects it first.

Details

Also raised here

Also raised at this location by persona senior-developer: commands.md says the range is checked first; the daemon checks until-presence first — The bullet at website/docs/docs/commands.md:659 states "The CLI checks the range first: it rejects an out-of-range --max-passes with INVALID_ARGS and no reason before the command runs", which holds for a CLI caller. The next sentence says the Node client and MCP "fail with INVALID_ARGS and scroll_max_passes_invalid", but assertScrollUntilCompatible tests until === undefined before the range, so scroll down --max-passes 500 from the Node client reports scroll_max_passes_requires_until and says nothing about the out-of-range value. Only a client that also passes --until reaches scroll_max_passes_invalid. Say the range error comes only for a request that carries until.

persona: javascript, senior-developer

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Both points confirmed and fixed at c03d507b8c. This time I ran the code instead of reading it:

  • MCP: runCommand goes through invoke, which calls the field reader. readInput({ direction: 'down', until, maxPasses: 500 }) throws INVALID_ARGS "Expected maxPasses to be at most 200." with no reason, with or without until. So MCP refuses before the daemon, like the CLI.
  • Node client: prepareDaemonCommandRequest('scroll', { …, maxPasses: 500 }) returns the request with maxPasses: 500 intact, so the value reaches the daemon.
  • Daemon order: assertScrollUntilCompatible tests until before the range, so the range reason needs a request that carries until.

The sentence now says: the CLI and MCP reject an out-of-range value with INVALID_ARGS and no reason; the Node client reaches the daemon, where the value fails with scroll_max_passes_invalid when until is present and scroll_max_passes_requires_until when it is not. I left the AI SDK out because I did not trace it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of c03d507

Since the review of fc80f70: 0 new · 0 still open · 1 no longer raised (1 marked fixed)

No open findings.

Reviewed with this repository's own Sentinel configuration (a1ddd51815ab).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

The earlier evidence request is now satisfied, and this PR is ready at c03d507. The docs now state the CLI/MCP range-first rule and the daemon ordering, which matches scroll-command.ts. Not blocking, and fine to take or leave: commands.md:659 lists scroll_edge_capture_unreadable only under scroll top and scroll bottom, but scroll refresh can also emit it during its initial top check, so one clause there would make it complete.

The one earlier inline thread on the range-first docs is fixed at this head, so it can be resolved: #4820 (comment)

All 23 checks pass, and the change since the last review is one docs sentence. No conflicts are known. Not verified here: the CLI and MCP paths were not executed, and the review relied on the declared min/max in the flag and field definitions plus the author's run. Nothing else needs to happen before merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@thymikee
thymikee merged commit a0106cf into main Nov 20, 2026
23 checks passed
@thymikee
thymikee deleted the t3/typed-reasons-scroll branch November 20, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant