Skip to content

feat(field): add WithSuggestedValue for GUI-only defaults - #1024

Merged
johnallers merged 1 commit into
mainfrom
john.allers/suggested-value
Jul 22, 2026
Merged

feat(field): add WithSuggestedValue for GUI-only defaults#1024
johnallers merged 1 commit into
mainfrom
john.allers/suggested-value

Conversation

@c1-squire-dev

@c1-squire-dev c1-squire-dev Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

WithDefaultValue feeds two independent consumers of a field's default:

  1. Runtime/flag defaultpkg/cli/cli.go registers it as the cobra flag default, and v.BindPFlags + v.Unmarshal inject it into the connector config even when the stored config omits the field.
  2. Schema exportpkg/field/marshal.go emits it as the exported schema default, which the c1 GUI uses to pre-populate the field for a new connector.

Because of (1), adding a default to an existing field is a breaking change: existing connectors whose stored config never set the field suddenly have the default injected at runtime, bypassing any connector-side "unset ⇒ use my own defaults" logic.

Real example: baton-confluence added WithDefaultValue to its noun/verb fields. Existing connectors that relied on the empty-input path (which expands to the connector's full noun/verb set) silently started syncing a narrower set.

Change

Add WithSuggestedValue, a default surfaced only in the exported schema (GUI pre-population). It is not registered as the flag default, so nothing is injected at runtime when the field is unset.

  • New SchemaField.SuggestedValue field + WithSuggestedValue(value any) option.
  • New GetExportedDefaultValue[T] helper: prefers SuggestedValue, falls back to DefaultValue.
  • marshal.go (schema export) now uses GetExportedDefaultValue; cli.go (flag default) is unchanged and still uses DefaultValue.

WithDefaultValue behavior is untouched, so connectors depending on it are unaffected. When both are set, the suggested value wins for schema export while the default value still governs the flag default.

Usage

nounsField = field.StringSliceField(
    "noun",
    field.WithSuggestedValue(defaultNouns), // GUI pre-fill only; no runtime injection
    field.WithRequired(false),
)

Tests

TestSuggestedValue and TestSuggestedValuePrecedence in pkg/field/struct_test.go cover the split (runtime default stays empty; exported schema carries the suggested value; precedence when both set). pkg/field/..., pkg/cli/..., pkg/config/... all pass.

🤖 Generated with Claude Code

WithDefaultValue feeds both the CLI/runtime flag default (which viper
injects into the connector config when a field is left unset) and the
exported config schema default (which the c1 GUI uses to pre-populate a
field when configuring a new connector).

That coupling makes adding a default to an existing field a breaking
change: existing connectors whose stored config omits the field suddenly
have the default injected at runtime, bypassing any connector-side
"unset means use my own defaults" handling.

WithSuggestedValue sets a default that is surfaced ONLY in the exported
schema (GUI pre-population). It is not registered as the flag default, so
nothing is injected at runtime when the field is unset. Existing
connectors keep their prior behavior; new connectors get the suggested
value pre-filled in the GUI and stored explicitly.

WithDefaultValue is unchanged, so existing connectors depending on its
behavior are unaffected. When both are set, the suggested value wins for
schema export while the default value still governs the flag default.

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
@c1-squire-dev
c1-squire-dev Bot requested a review from a team July 21, 2026 19:58
@github-actions

Copy link
Copy Markdown
Contributor

General PR Review: feat(field): add WithSuggestedValue for GUI-only defaults

Blocking Issues: 0 | Suggestions: 1 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 76f90611805f.
Review mode: full
View review run

Review Summary

The full PR diff was scanned for security and correctness. This adds a WithSuggestedValue field option plus a SuggestedValue struct field and a GetExportedDefaultValue helper, wiring the schema-export path (schemaFieldToV1) to prefer the suggested value while the CLI/runtime flag default (GetDefaultValue, used in pkg/cli/cli.go) is untouched. The change is additive and backward-compatible: SchemaField gains an optional field, all struct literals are keyed so the field reordering is safe, and the runtime default path is unchanged. No security or blocking correctness issues found.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • pkg/field/struct_test.go:143-182: Tests only exercise the StringSliceVariant path. Since GetExportedDefaultValue is generic, a small table covering int/bool/string/map variants would guard the export precedence across all field types.
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/field/struct_test.go`:
- Around line 143-182: The suggested-value and precedence tests only cover StringSliceField.
  Add table-driven cases (or additional tests) exercising IntField, BoolField, StringField,
  and StringMapField with WithSuggestedValue (and with both WithDefaultValue + WithSuggestedValue)
  to confirm GetExportedDefaultValue precedence and schemaFieldToV1 export behavior hold for every variant.

@github-actions github-actions 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 found.

@johnallers
johnallers merged commit d3702a5 into main Jul 22, 2026
10 checks passed
@johnallers
johnallers deleted the john.allers/suggested-value branch July 22, 2026 18:47
c1-squire-dev Bot added a commit to ConductorOne/baton-confluence that referenced this pull request Jul 22, 2026
Repin from the pre-release branch pseudo-version to the released
v0.20.1, which includes WithSuggestedValue (ConductorOne/baton-sdk#1024).

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
c1-squire-dev Bot added a commit to ConductorOne/baton-confluence that referenced this pull request Jul 22, 2026
Adding WithDefaultValue to the noun/verb fields registered them as
CLI/runtime flag defaults, which viper injects into the connector config
even when a connector's stored config omits them. connector.New treats
an empty noun/verb as "use the full default set", so existing connectors
that never set these fields silently began syncing the narrower config
default set instead of their historical full set — a breaking change.

Switch to WithSuggestedValue (baton-sdk), which surfaces the defaults
ONLY in the exported config schema (so the c1 GUI still pre-populates
them for new connectors) without registering them as flag defaults.
Existing connectors that leave the fields unset now see an empty value
at runtime again and retain their prior behavior.

Depends on baton-sdk WithSuggestedValue (ConductorOne/baton-sdk#1024);
the go.mod pin must be updated to the released SDK version before merge.

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
c1-squire-dev Bot added a commit to ConductorOne/baton-confluence that referenced this pull request Jul 22, 2026
Repin from the pre-release branch pseudo-version to the released
v0.20.1, which includes WithSuggestedValue (ConductorOne/baton-sdk#1024).

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
johnallers added a commit to ConductorOne/baton-confluence that referenced this pull request Jul 22, 2026
* fix(config): use WithSuggestedValue for noun/verb defaults

Adding WithDefaultValue to the noun/verb fields registered them as
CLI/runtime flag defaults, which viper injects into the connector config
even when a connector's stored config omits them. connector.New treats
an empty noun/verb as "use the full default set", so existing connectors
that never set these fields silently began syncing the narrower config
default set instead of their historical full set — a breaking change.

Switch to WithSuggestedValue (baton-sdk), which surfaces the defaults
ONLY in the exported config schema (so the c1 GUI still pre-populates
them for new connectors) without registering them as flag defaults.
Existing connectors that leave the fields unset now see an empty value
at runtime again and retain their prior behavior.

Depends on baton-sdk WithSuggestedValue (ConductorOne/baton-sdk#1024);
the go.mod pin must be updated to the released SDK version before merge.

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>

* chore: bump baton-sdk to v0.20.1 for WithSuggestedValue

Repin from the pre-release branch pseudo-version to the released
v0.20.1, which includes WithSuggestedValue (ConductorOne/baton-sdk#1024).

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>

* chore: remove unnecessary comments in config.go

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>

---------

Co-authored-by: John Allers <john.allers@c1.ai>
Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
@kans kans mentioned this pull request Jul 23, 2026
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.

2 participants