Skip to content

Comments

feat(preference): add InputHintOption for structured input options#1378

Merged
whoAbhishekSah merged 11 commits intomainfrom
feat/preference-input-hints-object
Feb 16, 2026
Merged

feat(preference): add InputHintOption for structured input options#1378
whoAbhishekSah merged 11 commits intomainfrom
feat/preference-input-hints-object

Conversation

@whoAbhishekSah
Copy link
Member

@whoAbhishekSah whoAbhishekSah commented Feb 11, 2026

Summary

Add InputHintOption struct and InputOptions field to support user-friendly option display in preference traits. The value_description field is now returned in API responses showing the human-readable description for the selected value.

Changes

core/preference/preference.go

// New struct
type InputHintOption struct {
    Name        string  // Machine-readable identifier (e.g., "sq_km", "Mg")
    Description string  // User-friendly display (e.g., "Square Kilometers", "Megagram (Mg)")
}

// New field in Trait
InputOptions []InputHintOption  // Takes precedence over InputHints

// New field in Preference
ValueDescription string  // Human-readable description from InputOptions

core/preference/validator.go

  • Add NewSelectValidatorFromOptions() to validate against InputOptions names

core/preference/service.go

  • Create populates ValueDescription from matched trait's InputOptions
  • LoadUserPreferences populates ValueDescription for both DB and default preferences

internal/api/v1beta1connect/preferences.go

  • transformPreferenceToPB includes ValueDescription in response
  • transformPreferenceTraitToPB includes InputOptions in response

Example Response

ListCurrentUserPreferences now returns value_description:

{
    "preferences": [
        {
            "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "name": "newsletter",
            "value": "true",
            "resource_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "resource_type": "app/user",
            "scope_type": "",
            "scope_id": "",
            "value_description": "",
            "created_at": "2026-02-05T08:14:49.526Z",
            "updated_at": "2026-02-11T08:28:26.119Z"
        },
        {
            "id": "",
            "name": "unit_area",
            "value": "sq_km",
            "resource_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "resource_type": "app/user",
            "scope_type": "",
            "scope_id": "",
            "value_description": "Square Kilometers",
            "created_at": "0001-01-01T00:00:00.000Z",
            "updated_at": "0001-01-01T00:00:00.000Z"
        }
    ]
}

Note: value_description is populated for traits with input_options configured (like unit_area). For traits without input_options (like newsletter), it remains empty.

CreateCurrentUserPreferences also returns value_description in the response.

Usage

input_options:
  - name: sq_km
    description: Square Kilometers
  - name: sq_ft
    description: Square Feet
default: sq_km

Dependencies

🤖 Generated with Claude Code

Add InputHintOption struct with name and title fields for user-friendly
option display. The InputOptions field in Trait allows specifying both
machine-readable names and display titles.

- Add InputHintOption struct
- Add InputOptions field to Trait (takes precedence over InputHints)
- Add NewSelectValidatorFromOptions function

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Feb 16, 2026 10:31am

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds InputHintOption and InputOptions to Trait, Preference.ValueTitle, Trait.GetValueTitle, and NewSelectValidatorFromOptions; GetValidator now prefers InputOptions for select/combobox; service Create and LoadUserPreferences populate Preference.ValueTitle; API/schema and validation updated to include InputHintOption and value_title.

Changes

Cohort / File(s) Summary
Preference core
core/preference/preference.go
Added InputHintOption { Name, Title }; added Trait.InputOptions []InputHintOption and Preference.ValueTitle string; added Trait.GetValueTitle(value string) string; updated GetValidator() to prefer InputOptions for select/combobox inputs (falls back to InputHints).
Validator constructor
core/preference/validator.go
Added NewSelectValidatorFromOptions(options []InputHintOption) *SelectValidator which builds a SelectValidator from non-empty option Name values.
Service population
core/preference/service.go
Create now sets created.ValueTitle from the trait; LoadUserPreferences sets Preference.ValueTitle for existing and defaulted preferences using trait.GetValueTitle(...).
API schema & validation
proto/apidocs.swagger.yaml, proto/v1beta1/models.pb.validate.go
Added v1beta1InputHintOption type; added input_options to PreferenceTrait and value_title to Preference; generated validation methods/types for InputHintOption and integrated InputOptions validation into PreferenceTrait validation flow.
API conversion
internal/api/v1beta1connect/preferences.go
Transform maps Preference.ValueTitle and converts Trait.InputOptions into proto InputOptions (name/title pairs).
Build metadata
Makefile
Updated PROTON_COMMIT hash reference.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • rohilsurana
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive PR description uses 'value_description' and 'Description' fields, but code changes show 'ValueTitle' and 'Title' fields instead, creating ambiguity about actual implementation. Clarify whether the field is 'ValueTitle' or 'ValueDescription' and whether it's 'Title' or 'Description' in InputHintOption. Update description to match actual code implementation for consistency.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: adding InputHintOption for structured input options in preferences.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/preference-input-hints-object

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@core/preference/preference.go`:
- Around line 108-112: The TraitInputMultiselect branch incorrectly routes to
NewSelectValidatorFromOptions (used by TraitInputSelect/Combobox) causing
comma-separated values like "1,3" to fail SelectValidator.Validate; fix by
changing handling of TraitInputMultiselect in the switch so it does not use
SelectValidator: either return NewTextValidator() for TraitInputMultiselect
(simple fallback) or implement and return a new NewMultiselectValidator that
splits on commas, trims each token and validates each against the options
(mirroring SelectValidator logic for individual tokens). Update the branch that
currently checks len(t.InputOptions) > 0 (and the case label
TraitInputMultiselect) to use the chosen approach and ensure tests referencing
multiselect behavior pass.

In `@core/preference/validator.go`:
- Around line 59-70: NewSelectValidatorFromOptions currently appends raw
opt.Name values which can contain surrounding whitespace and cause mismatches;
update the function (NewSelectValidatorFromOptions) to trim whitespace (e.g.,
strings.TrimSpace) from each InputHintOption.Name before adding to allowedValues
and skip entries that are empty after trimming so the
SelectValidator.allowedValues list is normalized and matches NewSelectValidator
behavior.

- Add ValueTitle field to Preference struct
- Add GetValueTitle method to Trait for looking up title from InputOptions
- Populate ValueTitle in LoadUserPreferences from trait's InputOptions
- Only applies to select/combobox/multiselect input types

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@core/preference/preference.go`:
- Around line 132-140: The GetValueTitle method on Trait currently only matches
opt.Name exactly so comma-separated multiselect inputs like "opt1,opt2" return
empty; update Trait.GetValueTitle to detect if value contains commas, split by
"," (use strings.Split and strings.TrimSpace), look up each token against
t.InputOptions matching opt.Name to collect opt.Title values, then return the
joined titles (e.g., strings.Join with ", " or similar); ensure you add import
"strings" if not present and preserve existing exact-match behavior when value
has no commas.

- Update PROTON_COMMIT to include InputHintOption and value_title changes
- Regenerate proto stubs
- Fix multiselect to use text validator (not select validator)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coveralls
Copy link

coveralls commented Feb 11, 2026

Pull Request Test Coverage Report for Build 22059148885

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 46 of 53 (86.79%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 38.323%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core/preference/service.go 13 15 86.67%
internal/api/v1beta1connect/preferences.go 13 18 72.22%
Totals Coverage Status
Change from base Build 21744973149: 0.08%
Covered Lines: 16156
Relevant Lines: 42158

💛 - Coveralls

- Add ValueTitle to Preference proto response for human-readable display
- Add InputOptions to PreferenceTrait proto response for select/combobox

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The Create method now populates ValueTitle from the matched trait's
InputOptions before returning the created preference.

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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/preference/service.go (1)

136-151: ⚠️ Potential issue | 🟡 Minor

ValueTitle is inconsistently exposed across API implementations.

While Create and LoadUserPreferences correctly populate ValueTitle, the service methods Get and List do not enrich the response. More critically, the two API implementations handle this differently:

  • internal/api/v1beta1connect/preferences.go: includes ValueTitle in the transformed response
  • internal/api/v1beta1/preferences.go: omits ValueTitle from the response entirely

This creates inconsistent data shapes depending on which API endpoint (Connect vs REST) clients use. Align the implementations by either:

  1. Populating ValueTitle in Get and List service methods (consistent with Create)
  2. Or explicitly document this field only applies to Create responses
  3. Or update v1beta1 to include ValueTitle like v1beta1connect does

…nces

- Add tests verifying ValueTitle is populated from InputOptions
- Test Create method populates ValueTitle in response
- Test LoadUserPreferences populates ValueTitle for DB and default preferences

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…iption

Update proton commit to f0e1082c79c700a84e6da11ca75a80ab6420bc00.
Align handler with proto field renames: InputHintOption.title → description,
Preference.value_title → value_description.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The domain struct InputHintOption used Title (yaml: "title") but the
YAML config and proto both use "description", causing value_description
to always be empty. Renamed ValueTitle → ValueDescription and
GetValueTitle → GetValueDescription throughout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Consistent with NewSelectValidator which trims option names from
comma-separated input_hints.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@whoAbhishekSah whoAbhishekSah merged commit 1e2d00e into main Feb 16, 2026
8 checks passed
@whoAbhishekSah whoAbhishekSah deleted the feat/preference-input-hints-object branch February 16, 2026 10:36
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.

3 participants