add: prompt-flag compatibility validation#12
Conversation
commit: |
1693b7e to
c31b5d7
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (10)**/*.{ts,tsx,js,jsx,json,md}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/core/**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.test.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/core/{cli,completion,output,prompt,resolve}/**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/core/resolve/**/*{flags,args,resolve}*.ts📄 CodeRabbit inference engine (src/core/resolve/AGENTS.md)
Files:
src/core/resolve/**/*.test.ts📄 CodeRabbit inference engine (src/core/resolve/AGENTS.md)
Files:
🧠 Learnings (10)📓 Common learnings📚 Learning: 2026-02-11T11:57:27.623ZApplied to files:
📚 Learning: 2026-02-12T15:52:24.166ZApplied to files:
📚 Learning: 2026-04-02T00:14:17.279ZApplied to files:
📚 Learning: 2026-04-06T11:25:57.444ZApplied to files:
📚 Learning: 2026-04-06T11:26:11.173ZApplied to files:
📚 Learning: 2026-04-06T11:28:55.224ZApplied to files:
📚 Learning: 2026-04-06T11:26:04.030ZApplied to files:
📚 Learning: 2026-04-06T18:24:44.371ZApplied to files:
📚 Learning: 2026-04-06T18:40:01.263ZApplied to files:
🔇 Additional comments (1)
📝 WalkthroughIntroduce prompt–flag kind compatibility checks (compile-time + runtime) to prevent invalid prompt configurations and fail fast (fixes Compile-time
Runtime
Tests & parity guard
Docs & tooling
Files of note
Impact
WalkthroughAdded compile-time and runtime enforcement tying prompt kinds to flag kinds. A compatibility map and validator ( Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as "CLI Resolver"
participant Validator as "validatePromptFlagCompatibility"
participant Resolver as "resolvePromptValueWithConfig"
participant Prompter as "prompter.promptOne"
CLI->>Resolver: request prompt resolution (flag, promptConfig)
Resolver->>Validator: validate(flag.flagKind, promptConfig.kind)
alt compatible
Validator-->>Resolver: ok
Resolver->>Prompter: promptOne(...)
Prompter-->>Resolver: user value
Resolver-->>CLI: { ok: true, value }
else incompatible
Validator-->>Resolver: ValidationError(CONSTRAINT_VIOLATED, details, suggest)
Resolver-->>CLI: { ok: false, error: ValidationError }
end
Suggested labels
Poem
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 inconclusive)
✅ Passed checks (8 passed)
📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches📝 Generate docstrings
Comment |
c31b5d7 to
f86a2ae
Compare
f86a2ae to
77d991a
Compare
- Add JSDoc to validatePromptFlagCompatibility(), resolvePromptValueWithConfig(), buildRequiredFlagSuggest(), and formatGeneratedSource() - Add Unreleased changelog entries for prompt compatibility validation, flagKind discriminator, and stdin-based meta build - Update resolve/AGENTS.md with compatibility map and new function - Update schema/AGENTS.md with flagKind phantom type docs https://claude.ai/code/session_01Xsmxjjw5T6t2jPLUdNMgDM
Replace barrel import from schema/index.ts with direct imports from command.ts and flag.ts. Fix resolve() mapping from flags.ts to index.ts. https://claude.ai/code/session_01Xsmxjjw5T6t2jPLUdNMgDM
|
@coderabbitai Is this a good architectural design for the repo overall, or is this a patch-job? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainLet me dig into the actual source files before I render me verdict, aye! 🏁 Script executed: Length of output: 50968
Architectural Assessment✅ What's done right (and done well)1. Fits the existing phantom-type pattern perfectly
2. Indexed-access map is the right TypeScript pattern type PromptConfigByFlagKind = {
readonly string: InputPromptConfig | SelectPromptConfig;
readonly number: InputPromptConfig;
readonly boolean: ConfirmPromptConfig;
readonly enum: SelectPromptConfig | InputPromptConfig;
readonly array: MultiselectPromptConfig;
readonly custom: PromptConfig;
};
type AllowedPromptConfig<C extends FlagConfig> = PromptConfigByFlagKind[C['flagKind']];A conditional type chain ( 3. Correct three-layer enforcement model
The broad 4. Fail-fast placement is correct
5. Tests are aspect-split and well-rounded Rejected combinations, exact error message content,
|
This comment was marked as low quality.
This comment was marked as low quality.
…AG_KINDS Ensures adding a new FlagKind without updating the runtime compatibility map is caught by tests (in addition to the Record<FlagKind, ...> compile-time guard). https://claude.ai/code/session_01Xsmxjjw5T6t2jPLUdNMgDM
This comment was marked as low quality.
This comment was marked as low quality.
Assert no stale keys exist in the runtime map that aren't in FLAG_KINDS. https://claude.ai/code/session_01Xsmxjjw5T6t2jPLUdNMgDM
Summary
Add compile-time and runtime validation to ensure prompt kinds are compatible with their corresponding flag types. This prevents invalid configurations like using
multiselectprompts with enum flags orconfirmprompts with string flags.Key Changes
Type-level validation: Introduced
AllowedPromptConfig<C>type that constrains which prompt kinds are allowed for each flag type:confirmonlyinputonlyinputorselectmultiselectonlyRuntime validation: Added
validatePromptFlagCompatibility()function that checks prompt-flag compatibility during resolution and returns aValidationErrorwith helpful suggestions if there's a mismatchUpdated
FlagBuilder.prompt()signature: Changed parameter type fromPromptConfigtoAllowedPromptConfig<C>to enforce type safety at the API levelComprehensive test coverage: Added 9 test cases covering:
Implementation Details
COMPATIBLE_PROMPT_KINDSlookup table to define valid combinationshttps://claude.ai/code/session_01Xsmxjjw5T6t2jPLUdNMgDM