Skip to content

feat(core,config): name where a missing required flag can be set - #811

Open
chenxin-yan wants to merge 3 commits into
mainfrom
feat/core-config-missing-flag-hints
Open

chenxin-yan wants to merge 3 commits into
mainfrom
feat/core-config-missing-flag-hints

Conversation

@chenxin-yan

@chenxin-yan chenxin-yan commented Dec 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

The error for a missing required flag now says where its value can be set. Before, a required setting taken with config.flag() named neither its environment variable nor its config file.

 $ cy status        # "server" from config.flag(), env CY_SERVER, nothing configured
-Error: Missing required flag "--server"
+Error: Missing required flag "--server": set $CY_SERVER or "server" in /home/me/.config/cy/config.json
dispatch
  defaults hooks                 # config: file values, plus hints for required flags no file gave
    collect defaults.hints       # only when a hook returns some
  preRun hooks                   # prompts() may still ask for the value
  validateParsed(node, bound, hints)
    missing required flag  ->  message + ": set " + env variables + hints
  • Core: the message names the flag's env variables, for any flag. A defaults hook may return hints: { args?, flags? }; Core uses them only for a required value still missing at validation. A flag with neither keeps its message.
  • Config: its defaults hook returns "<key>" in <file> for each required config flag no file gave, through one helper shared with config.get(), which now names both files for a key either may hold.
  • The message is the same under execute(), --json, typed run() and MCP. A check in an onError hook would not be: run() does not call those, and MCP uses run().

Evidence

  • Before: Missing required flag "--server" (exit 2).
    After: the messages above; an independent reviewer ran each documented case, including MCP over an in-memory transport (VALIDATION: Missing required flag "--server": set $CY_SERVER or "server" in …) and prompts() asking first on a terminal-like run.
  • New tests were red against the old sources. The reviewer's mutations (dropping hint collection, dropping config's hint, swapping file order) each fail a test.
  • pnpm run check 0, pnpm run check:types 0, RUNNER_TEMP=$(mktemp -d) pnpm run test 0 (226 files, 4170 passed).
  • Cost in every CLI: one check per defaults result on the success path; a minified one-flag CLI grows by 297 bytes (146 gzip).

Review findings fixed in the second commit: no suffix for a required list given empty (--tags ""), which no variable can fill; a required exclusive group names its listed members' variables; config builds hints only for required flags; config.get()'s error loses its trailing period; config's bump is a patch.

Not verified: the docs site build; Windows paths in the hint; MCP over stdio.

Merge Danger

Door: two-way

Blast Radius: messages

Error text changes for every required flag that has env, so a downstream test that asserts the whole message will fail. Missing required flag "--name" stays as the prefix. config.get()'s message changes too (both files, no trailing period). Known gap: a command without an action is validated without running defaults hooks, so it shows only the variables.


Opened by an AI agent on behalf of @chenxin-yan.

View guided diff Turn on auto-fix

Confidence Score: 5/5RetriggerView in Greptile

The PR appears safe to merge; the previous finding is fixed and no new actionable issues remain.

Summary

Missing required values now name their environment variables and places suggested by defaults hooks. Config errors name each file that may hold the setting.

  • Missing required-value errors point to places that can supply the value.
  • Config-backed errors name the files that may hold a missing setting.

Diagram

%%{init: {'theme': 'neutral', 'htmlLabels': false}}%%
flowchart TD
  A[defaults hooks] --> B[Collect values and hints]
  B --> C[preRun hooks may supply values]
  C --> D{Required value missing?}
  D -->|No| E[Run action]
  D -->|Yes| F{Value explicitly supplied?}
  F -->|Yes, empty list| G[Error without hints]
  F -->|No| H[Error names variables and hints]
Loading

Reviews (2) · Last reviewed commit: "fix(core): name no place for a required ..." · Reviewed by Greptile

`Missing required flag "--server"` named neither the environment variable
nor the config file a person would set it in.

- core: the message is followed by the flag's `env` variables:
  `Missing required flag "--token": set $APP_TOKEN`.
- core: a `defaults` hook may return `hints: { args?, flags? }`, places
  where a value it could not supply may be set. Core names them only in
  the error for a required argument or flag still missing at validation,
  after the variables. Hints bind nothing and leave `sources` unchanged.
- config: the `defaults` hook returns `"<key>" in <file>` for each config
  flag no file gave, naming every file that may hold the key. `get()`'s
  error is built by the same helper, so a `both` setting now names the
  project file as well as the user's.

The text is in the error itself, so it is the same under `execute()`,
`--json`, typed `run()` and MCP.
…up's variables

Review findings:
- A required list flag given empty on argv or through run() kept the suffix,
  though no variable or stored value applies to a flag that was given.
- A required exclusive group named none of its members' variables.
- config hints only for required flags; config.get()'s error loses its trailing
  period, as the flag's error has none; config's bump is a patch.
- Tests for the prototype-member guard; the json() duplicate is dropped.
@github-actions

github-actions Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Consumer type performance

Base: 9598b12 · PR merge: 91c7cb4

Top-level commands Base instantiations PR merge instantiations Δ
10 176,046 176,046 ±0 (±0.0%)
100 492,093 492,093 ±0 (±0.0%)
200 918,239 918,239 ±0 (±0.0%)
400 1,986,531 1,986,531 ±0 (±0.0%)
50 in one .add() 534,202 534,202 ±0 (±0.0%)
60 Contexts in one call 221,718 221,718 ±0 (±0.0%)
60 Extensions in one call 445,022 445,022 ±0 (±0.0%)

Check-time scaling (400 ÷ 200 commands): base 2.19× · PR merge 2.17×

TypeScript 7.0.2 · --checkers 1 · ⚠️ marks instantiation increases above the repository's advisory 10% threshold, or a check-time scaling ratio more than 20% above base: type-check cost growing faster than the command count.

@github-actions

github-actions Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

📦 Package size

Bundle cost (per entrypoint, minified + gzip)

Entry Base Head Δ
@crustjs/auth 24.63 KB 24.63 KB ±0
@crustjs/auth/oauth 23.03 KB 23.03 KB ±0
@crustjs/completion 10.81 KB 10.81 KB ±0
@crustjs/config 11.12 KB 11.16 KB +0.04 KB (+0.4%)
@crustjs/core 27.29 KB 27.45 KB +0.16 KB (+0.6%)
@crustjs/core/tooling 8.29 KB 8.40 KB +0.11 KB (+1.3%)
@crustjs/create 5.14 KB 5.14 KB ±0
@crustjs/effect 1.43 KB 1.43 KB ±0
@crustjs/env 0.99 KB 0.99 KB ±0
@crustjs/extensions 23.96 KB 23.96 KB ±0
@crustjs/man 1.89 KB 1.89 KB ±0
@crustjs/mcp 118.33 KB 118.33 KB ±0
@crustjs/openapi 21.93 KB 21.93 KB ±0
@crustjs/progress 5.03 KB 5.03 KB ±0
@crustjs/prompts 10.30 KB 10.30 KB ±0
@crustjs/prompts/extension 7.27 KB 7.27 KB ±0
@crustjs/prompts/testing 2.26 KB 2.26 KB ±0
@crustjs/skills 19.26 KB 19.26 KB ±0
@crustjs/store 7.41 KB 7.41 KB ±0
@crustjs/style 5.92 KB 5.92 KB ±0
@crustjs/testing 0.71 KB 0.71 KB ±0
@crustjs/testing/interactive 1.14 KB 1.14 KB ±0
@crustjs/tui 0.75 KB 0.75 KB ±0
@crustjs/utils/artifacts 0.95 KB 0.95 KB ±0
@crustjs/utils/error 0.12 KB 0.12 KB ±0
@crustjs/utils/json 0.89 KB 0.89 KB ±0
@crustjs/utils/package-manager 0.14 KB 0.14 KB ±0
@crustjs/utils/path 0.41 KB 0.41 KB ±0
@crustjs/utils/primitive 0.21 KB 0.21 KB ±0
@crustjs/utils/process 2.29 KB 2.29 KB ±0
@crustjs/utils/schema 0.26 KB 0.26 KB ±0
@crustjs/utils/search 0.90 KB 0.90 KB ±0
@crustjs/utils/signals 0.36 KB 0.36 KB ±0
@crustjs/utils/source 0.23 KB 0.23 KB ±0
@crustjs/utils/terminal 1.54 KB 1.54 KB ±0
@crustjs/utils/url 0.08 KB 0.08 KB ±0

Consumer bundles (minified + gzip)

Fixture apps from scripts/package-size-fixtures/, bundled against the measured tree. cli uses the finished-build define crust build applies (process.env.CRUST_INTERNAL_BUILD).

Fixture Base Head Δ
@crustjs/core cli 19.41 KB 19.57 KB +0.16 KB (+0.8%)
@crustjs/core error-only 0.75 KB 0.75 KB ±0
@crustjs/core tooling-docs 1.83 KB 1.83 KB ±0
@crustjs/extensions help-only 4.45 KB 4.45 KB ±0
@crustjs/extensions help-version 4.63 KB 4.63 KB ±0
@crustjs/style string-width 0.76 KB 0.76 KB ±0

Install size (npm pack)

Runtime footprint = unpacked bytes of the package plus its production dependencies graph, each installed copy counted once. Peer and optional peer dependencies (e.g. typescript) are excluded. These are npm unpacked bytes, not exact disk usage.

Package Tarball Unpacked Δ unpacked Runtime footprint Δ footprint
@crustjs/auth 42.70 KB 152.46 KB ±0 317.84 KB ±0
@crustjs/completion 25.70 KB 82.86 KB ±0 82.86 KB ±0
@crustjs/config 10.31 KB 31.45 KB +0.40 KB (+1.3%) 196.84 KB +0.40 KB (+0.2%)
@crustjs/core 117.92 KB 438.12 KB +1.90 KB (+0.4%) 512.31 KB +1.90 KB (+0.4%)
@crustjs/create 9.29 KB 29.95 KB ±0 104.14 KB ±0
@crustjs/effect 5.55 KB 16.06 KB ±0 16.06 KB ±0
@crustjs/env 4.03 KB 9.67 KB ±0 9.67 KB ±0
@crustjs/extensions 31.06 KB 99.77 KB ±0 444.66 KB ±0
@crustjs/man 4.51 KB 11.33 KB ±0 11.33 KB ±0
@crustjs/mcp 10.05 KB 32.13 KB ±0 106.32 KB ±0
@crustjs/openapi 45.77 KB 151.15 KB ±0 225.34 KB ±0
@crustjs/progress 7.50 KB 21.91 KB ±0 164.08 KB ±0
@crustjs/prompts 30.13 KB 111.54 KB ±0 253.70 KB ±0
@crustjs/skills 22.36 KB 77.13 KB ±0 352.75 KB ±0
@crustjs/store 25.03 KB 91.19 KB ±0 165.39 KB ±0
@crustjs/style 19.84 KB 67.97 KB ±0 67.97 KB ±0
@crustjs/testing 5.64 KB 15.64 KB ±0 15.64 KB ±0
@crustjs/tui 2.97 KB 6.90 KB ±0 6.90 KB ±0
@crustjs/utils 26.69 KB 74.19 KB ±0 74.19 KB ±0

Comment thread packages/core/src/parsing/parser.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ Approved with three non-blocking findings about empty lists and input precedence.

Approach: Formatting hints during required-value validation lets prompts and later defaults satisfy the value before Core reports an error.

Reviewed changes cover the extension contract, parser, config integration, docs, and changeset. All 321 tests across the three affected test files passed.

  • Core collects hints in extension order and adds them to missing-value errors alongside applicable environment variable names, including those of visible exclusive-group members.
  • Config shares the file-location formatter between config.flag() and config.get(), preserving the setting’s file key when the CLI flag has a different name.

Non-blocking

  • An explicit empty variadic argument advertises an ineffective fix. With run([], { args: { files: [] } }), the error suggests setting the saved profile. I populated the profile and reran the same call. It still failed because the explicit array wins. Suppress the stored hint when the caller supplied the empty argument, and keep it when the caller omitted files. Argument validation
  • An empty extension default hides a working environment override. With a required repeatable tags flag and a defaults hook returning flags: { tags: [] }, the error omits $TAGS. Setting TAGS=valid makes the same invocation succeed. Keep the environment hint when the defaults hook supplied the empty list. Flag source check
  • An empty first environment variable can mask an advertised fallback. For a comma-delimited required list with env: ["PRIMARY", "SECONDARY"], PRIMARY="" SECONDARY=valid still reports set $PRIMARY or $SECONDARY. The resolver selects PRIMARY before splitting it. In this case the diagnostic should tell the user to populate PRIMARY or unset it to use SECONDARY. Environment hint formatting

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.2-astra | 𝕏

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 12 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/core/src/parsing/parser.ts Resolved
Bot review findings (Greptile, cubic, Pullfrog): run([], { args: { files: [] } })
still suggested a stored value, which cannot replace a supplied one. The
argument check now reads its source as the flag check does. Docs: the hints
example states the flag's env, and config says an actionless command names
only the variables.
@chenxin-yan

Copy link
Copy Markdown
Owner Author

Review findings handled in commit e64230c67:

  • Greptile P2, cubic P2, Pullfrog: a required variadic argument given []: fixed. The argument check now reads the value's source, as the flag check does; the test was red before the fix.
  • cubic P3, extensions.mdx example: the text now states the flag's env.
  • cubic P3, config.mdx: added that a command without an action names only the variables.
  • Pullfrog, a defaults hook returning an empty list hides the variable: not changed. A hook-bound value and a bindInput value share one source, and for the second the variable really does not apply.
  • Pullfrog, an empty first variable masks a second: not changed. It needs the resolver's choice of variable in the message, which is a larger change than this PR.

Opened by an AI agent on behalf of @chenxin-yan.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No blocking issues. One case still hides a working profile hint.

Reviewed changes since 82535c3 cover required variadic arguments and the documentation for missing-value hints. All 265 tests in the command and parser suites passed.

  • Distinguished omitted arguments from explicit empty lists. The regression test confirms that run([]) shows the stored-value hint and run([], { args: { files: [] } }) suppresses it.
  • Clarified the documentation. The extension example identifies where $ACME_REGION comes from, and the config guide explains why commands without an action show only environment variables.

Non-blocking

  • An empty list from a later defaults hook hides an effective hint. With a profile hook first and a fallback hook returning args: { files: [] } second, run([]) reported only Missing required argument "<files>". Populating the profile with ["a.txt"] made the same invocation succeed. Preserve hints from earlier hooks that can supply the argument while keeping them suppressed for an explicit caller-supplied []. Argument validation

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6.2-astra | 𝕏

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