Repository navigation
refactor(config): write a mutation's one value instead of merging the whole config - #4160
Conversation
… whole config The four user-config mutations (the two skip-prompt flags, the commit-generation command, a project's worktree-path) each change one value, but the save serialized the whole config and diff-merged it into the file. That merge had to reconstruct everything it didn't mean to change: comments and trailing comments, values written at their defaults, inline vs standard tables and their headers, pipeline spellings, hook aliases, and deprecated or retired spellings the load path rewrites only in memory. No library does that merge; tools that edit user-owned TOML (cargo add, uv, poetry) set values by key path instead. Each mutation now returns a `ConfigEdit` — the tables, key, and value it changed — which is applied to the file parsed as a `toml_edit` document. An existing value keeps its decor; a missing table is created implicit (inline inside an inline table); nothing else in the file is touched, so a save no longer writes a deprecated key's canonical spelling beside the original (`[select]` gaining `[switch.picker]`). When the edited file wouldn't load as the mutated config — a deprecated `[commit-generation]` whose migration declines once `[commit.generation]` exists — the edit goes into the migrated file instead, so that section's template isn't stranded. A mutation also no longer replaces the in-memory config with the file's: it applies the same change to it, so system config, `WORKTRUNK_*` variables, and `--config-set` still hold for the rest of the command. The merge engine, its whole-struct serialization, the save-side hook-alias rename, and the implicit-header handling in `replace_inline_with_table` (now private to `deprecation`, its only caller) go, along with the unit tests that pinned the merge. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
ConfigFile::edited's fallback rewrites the whole file, not just the edit's path. migrate_content_doc runs every RulePass::Load rule over the document, and two of those (migrate_commit_generation_in, migrate_select_doc) call drop_unsupported_keys — so accepting the commit-generation prompt on a config that happens to hold a deprecated [commit-generation] also migrates an unrelated [select] and deletes keys the user wrote.
Run against this PR's head and against f0aa111, same input, set_commit_generation_command("llm"):
Repro and both outputs
# my config
[commit-generation]
template = "T"
mystery = "keep me"
# picker look
[select]
pager = "delta"
bogus-key = 1
[list]
made-up = trueThis PR — [select] migrated, bogus-key and mystery gone:
# my config
[commit.generation]
template = "T"
command = "llm"
# picker look
[switch.picker]
pager = "delta"
[list]
made-up = truef0aa111 — both keys kept, but the file is left with duplicated sections and a bare [switch] header:
# my config
[commit-generation]
template = "T"
mystery = "keep me"
# picker look
[select]
pager = "delta"
bogus-key = 1
[list]
made-up = true
[commit.generation]
command = "llm"
template = "T"
[switch]
[switch.picker]
pager = "delta"The new output is the better file — that is the bug this PR fixes, and [select] bogus-key has been warning "is no longer supported and will be removed" on every command all along. What's worth a decision is that a config mutation is now a second materializer of migrations. CLAUDE.md § Config Deprecation states the model as "the user materializes migrations via wt config update", and prompt_commit_generation_setup previews exactly what it will write — "Would add to <path>:" followed by the two-line [commit.generation] stanza, then "Added to user config:" with the same stanza — while the write can move sections and remove keys elsewhere in the file. edited's doc ("the edit goes into the migrated file instead, which writes those migrations too") reads as scoped to the edit's path.
Either the doc and the prompt should say what the fallback can do, or the fallback should report it: migrate_content_doc discards the Deprecations the drops produce (&mut Vec::new()), and surfacing them through format_deprecation_warnings when the fallback fires would put the removal in front of the user at the moment it happens. Your call which — the inline suggestion is only the doc half.
Separately, three doc comments in src/config/user/mutation.rs still describe reload_from, the function this PR deletes: set_skip_shell_integration_prompt and set_skip_commit_generation_prompt say "Acquires lock, reloads from disk, sets flag if not already set, and saves", and set_commit_generation_command says "Acquires lock, reloads from disk, sets the command, and saves". Not reloading self from disk is the PR's own headline change, so these now say the opposite of what the code does. test_reload_from_permission_error in src/config/user/tests.rs carries the same stale name and comment. All four are outside the diff — happy to push a commit fixing them if you'd like.
Not approving: .claude/skills/running-tend/references/review-pr.md § "Data-Loss Surface: Hold for Human Review" holds a PR whose diff "widens what an existing one can delete" on a file worktrunk writes on the user's behalf, and this widens drop_unsupported_keys from wt config update to the config mutations. It asks for a review request to @max-sixty, which is moot here since you authored it — so this is just the hold, not a blocker I'd defend past your answer.
Verified locally at f8a4d48: cargo test --lib config::user (154 passed) and cargo test --test integration approval_save (19 passed).
…th it The fallback that writes an edit into the migrated file carries every load-path migration, not just the one on the edit's path, so it can also move an unrelated deprecated section and drop keys its destination has no field for. `wt config update` is otherwise what materializes migrations, so a mutation that does it now warns with the file's path, and the docstring says what the fallback carries. Also drops `reload_from` from four doc comments and two test names, which the function's removal left describing nothing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The new report fires before the write: ensure_config_parses and write_atomically both run after the two eprintln!s, so a save that fails leaves the user told their config was migrated when it wasn't — in prompt_commit_generation that prints directly above its own ↳ Config save failed; add manually to …. Reorder suggested inline.
Two smaller things about the message itself:
↳ To review, run wt config showlands three lines aboveprompt_commit_generation's↳ View config: wt config show, and that's the normal case rather than an edge one.set_commit_generation_commandon a file holding a deprecated[commit-generation]is the only mutation that can reach the fallback — a root-level skip flag or aprojects.<id>.worktree-pathstill loads asexpectedonce the migrations run, so those stayAsWritten. The warning already names the path, so dropping the hint costs nothing.- "Migrated deprecated settings" describes a move, and the write also deletes.
CLAUDE.md§ Config Deprecation rests "this does not conflict with 'never silently drop a key'" ondrop_unsupported_keysreporting each removal, butmigrate_content_docdiscards thoseDeprecations(&mut Vec::new()), so on this path nothing names the keys that went — and a laterwt config showreads the already-migrated file, so it can't recover them either. Naming the deletion in the message, or threading theVecthrough toformat_deprecation_warnings, would close that; it's the residual of the earlier thread rather than a new objection.
Not approving, for the same reason as last round: .claude/skills/running-tend/references/review-pr.md § "Data-Loss Surface: Hold for Human Review" holds a diff that widens what an existing deletion can reach on a file worktrunk writes on the user's behalf, and this still moves drop_unsupported_keys from wt config update onto the mutation path.
…s it dropped The warning fired before the write, so a failed write reported a migration the file never took. It now follows the write, and names each key the migrations removed for want of a field in its destination (`[select] height`), which nothing else records — `migrate_doc` reports what the load-path rules changed. The "run wt config show" hint goes: the one prompt that reaches this fallback already prints it. The test's fixture now carries such a key, so the snapshot pins the removal rather than only the move. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
All three confirmed at f62100f: the report now sits after ensure_config_parses and write_atomically, whose ? returns before it, so a failed save says nothing; the fixture's [select] height makes the snapshot pin the deletion as well as the move; the banner reads Mutation error path tests, and no reload_from reference is left in src/config/user/ (approvals.rs has its own, unrelated). cargo test --lib config::user — 155 passed.
codecov/patch fails at this head, and both gaps look real rather than relocated lines:
-
src/config/user/mutation.rs#L94-L99— the three lines of the newdroppedblock. The outerEdited::Migratedarm is covered, so whatever reaches it has an emptydropped;test_edit_takes_the_migrations_when_one_lands_on_its_pathasserts thedroppedvalue but callsConfigFile::editeddirectly, one level under the warning. Driving the same fixture throughset_commit_generation_commandwould cover it — worth a test rather than a note, since this output is whatCLAUDE.md§ Config Deprecation rests "does not conflict with 'never silently drop a key'" on. -
src/config/deprecation.rs#L1069—replace_inline_with_table's trailing-comment branch. Codecov's file report for the base has the same line, assrc/config/mod.rs:213, hit atf0aa111; the coverage went with the deleted merge tests, which held the onlycommit = { generation = { command = "old" } } # trailingfixture. The branch is still live on the load path, so a unit test indeprecation.rscloses it:Probe: the branch still fires under
migrate_contentcommit = { stage = "all" } # trailing [commit-generation] template = "T"
[commit] # trailing stage = "all" [commit.generation] template = "T"
One new thing inline, on what the dropped filter leaves out.
Still not approving, same reason as the last two rounds: .claude/skills/running-tend/references/review-pr.md § "Data-Loss Surface: Hold for Human Review" holds a diff that widens what an existing deletion reaches on a file worktrunk writes for the user, and this still moves drop_unsupported_keys from wt config update onto the mutation path. The failing codecov/patch is its own gate under CLAUDE.md § Coverage.
…ust dropped keys The report filtered the load-path migrations down to `UnsupportedKey`, so a removal a `Structural` rule performs — `list.task-timeout-ms` — went unnamed while the line above claimed to name what was removed. The kinds now go through `format_warning_lines`, the same rendering the load path uses, so every change is named in the vocabulary it already has. The tests that reach this cover the two lines codecov reported missed: the mutation-path report (through a `[select]` key with no home in `[switch.picker]`), and `replace_inline_with_table`'s trailing-comment branch, whose only fixture went with the deleted merge tests. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
format_warning_lines is the load path's renderer, and the load path has already run over the same file in the same process — so the mutation now reprints its lines verbatim, in a tense the write has just falsified.
Both emissions in one process, at 52cea19
A throwaway integration test calling UserConfig::load_with_warnings() and then set_commit_generation_command("llm", …), over
[commit-generation]
template = "MY TEMPLATE {{ git_diff }}"
[select]
pager = "delta"
height = 5===== load path =====
▲ User config: [commit-generation] is deprecated in favor of [commit.generation]
▲ User config: [select] is deprecated in favor of [switch.picker]
▲ User config: [select] height is no longer supported and will be removed
↳ To see details, run wt config show; to apply updates, run wt config update
===== mutation path =====
▲ Migrated deprecated settings @ ~/…/config.toml — the setting being written can't be read beside them
▲ User config: [commit-generation] is deprecated in favor of [commit.generation]
▲ User config: [select] is deprecated in favor of [switch.picker]
▲ User config: [select] height is no longer supported and will be removed
===== end =====
The overlap is structural rather than a property of this fixture: migrate_doc runs RulePass::Load and detect_deprecations_from_doc runs RulePass::Update over the same DEPRECATION_RULES in the same order, so the mutation's changes are always a subset of what the load already reported, rendered through the same function under the same User config label. check_and_migrate's WARNED_DEPRECATED_PATHS dedup only covers its own emitter.
That wording is right where it comes from: on the load path wt config update is still ahead, so "is deprecated in favor of" and "will be removed" name outstanding work. Under "Migrated deprecated settings" the same words describe the file the write just produced — [commit-generation] isn't deprecated in that file, it's absent from it, and [select] height isn't going to be removed, it's gone. The last line is the one CLAUDE.md § Config Deprecation rests "this does not conflict with 'never silently drop a key'" on, and after the write a wt config show reads the migrated file, so nothing downstream can name the key either.
The dropped block this replaces had the tense right and the coverage wrong; routing through the load path's renderer inverts both rather than fixing one. A past-tense rendering of the kinds gets both, and stops the report repeating a block the user has already seen this command — a sibling match beside format_warning_lines in deprecation.rs would keep the vocabulary where the kinds live, so "Adding a deprecation" still touches one file.
One inline note on where the new deprecation test landed.
codecov/patch passes at this head, so that gate from the last round is clear. Still not approving, for the standing reason only — the hold in .claude/skills/running-tend/references/review-pr.md § "Data-Loss Surface: Hold for Human Review", unchanged since the first round.
…hat happened Reusing the load path's renderer printed "is deprecated in favor of" and "will be removed" for sections the write had just moved and keys it had just removed, and repeated lines the same command had already printed at load. A sibling `format_applied_lines` renders the same kinds in past tense — "Moved [commit-generation] to [commit.generation]", "Removed [select] height, which its replacement has no field for" — so a new `DeprecationKind` is still worded in one file, and `format_warning_lines` goes back to private. Also moves the new inline-parent-comment test above the create-hooks doc comment it had wedged itself under. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Both findings are fixed at b862c65. I checked the report end to end rather than through the new snapshot alone — a throwaway test that runs the load path and then set_commit_generation_command over a config holding [commit-generation], [select] height, and [list] task-timeout-ms:
===== load path =====
▲ User config: [commit-generation] is deprecated in favor of [commit.generation]
▲ User config: [select] is deprecated in favor of [switch.picker]
▲ User config: [select] height is no longer supported and will be removed
▲ User config: list.task-timeout-ms is no longer used — list.timeout-ms bounds the collect phase
↳ To see details, run wt config show; to apply updates, run wt config update
===== mutation path =====
▲ Migrated deprecated settings @ …/config.toml — the setting being written can't be read beside them
▲ Moved [commit-generation] to [commit.generation]
▲ Moved [select] to [switch.picker]
▲ Removed [select] height, which its replacement has no field for
▲ Removed list.task-timeout-ms, which nothing reads
The second block now says what the write did, in its own words rather than the load path's, and ListTaskTimeout — the kind that fell through _ => None two rounds ago — is still named. The create-hooks doc comment is back on test_migrate_create_hooks_renames_every_shape.
codecov/patch fails at this head — 89.09% of diff against a 98.31% target — and the whole gap is the new function: 24 of deprecation.rs's 100 patch lines are missed, all of them arms of format_applied_lines that the single snapshot in test_edit_takes_the_migrations_when_one_lands_on_its_path never reaches. mutation.rs and persistence.rs are both at 100%. Inline: the sibling of test_format_deprecation_warnings_all_kinds closes all 24, and I ran it.
One documentation note, since the split changes a property CLAUDE.md states outright. § Config Deprecation says "Each DeprecationKind carries its own display payload, so format_deprecation_warnings() is one match over the kinds", and step (2) of "Adding a deprecation" is "a DeprecationKind variant plus its match arm in format_deprecation_warnings()". After this commit a variant needs an arm in format_warning_lines and one in format_applied_lines. The compiler catches a missing arm, so nothing can silently go unworded — but the recipe now names half the work, and the property it justifies is "one file", which is what the commit message says. Worth moving the sentence to that wording.
Not approving, for the standing reason only — the hold in .claude/skills/running-tend/references/review-pr.md § "Data-Loss Surface: Hold for Human Review", unchanged since the first round.
`format_applied_lines` had one snapshot, through the three kinds a config mutation's own fixture reaches, leaving its other arms unrun. It now has the sibling of `test_format_deprecation_warnings_all_kinds`, over the same kinds in the same order. CLAUDE.md's deprecation recipe said a kind's wording is one match in `format_deprecation_warnings()`; it is two, in one file, and says so. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Both of last round's findings are closed at 9ac47cdc, and the two gates I'd
named are clear:
test_format_applied_lines_all_kindscarries all nineDeprecationKind
variants and both branches of the twoScopedSectionsarms, so every arm of
format_applied_linesis run.cargo test --lib config::deprecation::tests::test_format
— 4 passed.codecov/patchpasses at this head, which was the whole of the
89.09% gap two rounds ago.- The
CLAUDE.mdsentence matches the code: wording a kind is now a match in
format_warning_lines()and one informat_applied_lines(), and step (2) of
"Adding a deprecation" names both.
Nothing new in the increment.
What still holds the verdict is the same thing as in every round since the
first, and it is now the only thing: .claude/skills/running-tend/references/review-pr.md
§ "Data-Loss Surface: Hold for Human Review" holds a diff that widens what an
existing deletion reaches on a file worktrunk writes on the user's behalf, and
this moves drop_unsupported_keys from wt config update onto the config
mutation path. That section asks for a human sign-off rather than mine; you're
the author, so there's no one for me to request it from. Merging over this is
your call, and I have no finding left to argue against it.
…wn (#4123) ## Problem `[projects."example.com/org/repo".list]` is valid config, accepted on load — and every command printed `unknown field projects.example.com/org/repo.list` for it. A section equal to its default is skipped during serialization, so it is absent from the round-tripped view `diff_tables` compares the raw file against. `seed_schema_skeleton` exists to rescue exactly that, but it restored only *top-level* keys: an emptied `[list]` read as known, the same section one level down read as unknown. All seven `UserProjectOverrides` sections carrying `skip_serializing_if = "is_default"` are affected — `list`, `commit`, `merge`, `remove`, `switch`, `step`, `forge`. ## Solution `WorktrunkConfig` gains `valid_scoped_keys()` — a top-level key whose entries are themselves schema-typed tables, with the valid keys for one entry. User config returns `("projects", UserProjectOverrides schema keys)`; project config has no such key and keeps the default `None`. `seed_schema_skeleton` applies the same restore inside each entry. Only schema-valid keys are seeded, so a genuine unknown in that scope still warns. The `UserProjectOverrides` key list has one home — `user_project_override_keys()`, shared with `is_user_project_override_key`. `remove_section_key_in` in `deprecation.rs` already described this false positive in a comment and worked around it by deleting the section it emptied. That comment is updated to match the fixed behavior; the deletion itself is unchanged. ## Scope after #4160 This PR originally carried a second half, against `UserConfig::save_to`'s `merge_tables` stale-key sweep: `compute_unknown_tree` fed both the warning and the preserve set that a whole-config rewrite consulted, so making a section stop reading as unknown also changed what a save kept. #4160 replaced that rewrite with a single-value edit through `toml_edit` and deleted `save_to` and `merge_tables` outright, so `compute_unknown_tree` now feeds the warning only. Merging `main` dropped that half and its test (`test_save_to_existing_file_keeps_section_holding_only_unknown_keys`, which called the removed `save_to`). What remains is a warning-path fix with no save-path behavior change. The "empty `[projects."<id>".list]` is now dropped on save" note in the earlier description no longer applies — nothing rewrites the file wholesale for it to apply to. ## Testing - `empty_per_project_section_is_known` — the reported input produces an empty tree and no warnings. Fails before the change with `NestedUnknown { path: "projects.example.com/org/repo.list" }`. - `unknown_key_in_per_project_scope_still_warns` — three cases that must keep warning: an unknown sibling section, an unknown key nested inside a known section, and a root-only user setting (`skip-shell-integration-prompt`) that has no per-project form. `cargo test --lib config::` is 537 passed at the merged head; `cargo fmt --check` and `cargo clippy --lib --tests` are clean. Reported by @zach-hammad-vs from source inspection; the reproduction above confirms it. Closes #4115 — automated triage --------- Co-authored-by: worktrunk-bot <[email protected]>
The four user-config mutations — the two skip-prompt flags, the commit-generation command, a project's
worktree-path— each change one value, but saving serialized the wholeUserConfigand diff-merged it intoconfig.toml. That merge had to reconstruct everything it didn't mean to change, and #4151 and #4156 spent several review rounds on its cases: trailing comments, values written at their defaults, inline vs standard tables and their headers, pipeline spellings, hook aliases, deprecated spellings. No crate does this merge (the closest, patchloom, fails three of those cases; toml-rs/toml#231 has asked for one since 2021), and tools that edit user-owned TOML — cargo add, uv, poetry, jj, mise — set values by key path instead.Each mutation now returns a
ConfigEdit(tables, key, value), applied to the file parsed as atoml_editdocument:[select]gaining[switch.picker], after whichselectwarned as unknown on every command), and retired template variables,pre-createaliases, and deprecated sections stay as written untilwt config update.[commit-generation]migrates to[commit.generation]only while the canonical table is absent, so writing the command there directly would strand the section's template.ConfigFile::editedchecks that the edited file loads as the mutated config and otherwise applies the edit after the load-time migrations. That file carries every load-path migration, so it can also move an unrelated deprecated section and drop keys their destinations have no field for — the one place a mutation materializes migrations rather thanwt config update. It is reported once the write lands, naming each change in the tense of a write that happened (format_applied_lines, the past-tense sibling of the load path's renderer).selfto keep it current, so system config,WORKTRUNK_*variables, and--config-setstill hold for the rest of the command. Previously a first-run prompt dropped them —--config-set 'commit.stage="none"'staged everything oncewt step commithad asked about commit generation.Removed: the merge engine and whole-struct serialization in
src/config/user/persistence.rs, the save-side hook-alias rename, and the implicit-header branch ofreplace_inline_with_table, which moves intodeprecation.rsbeside its only caller. The unit tests that pinned the merge go;test_config_edit_changes_only_its_valuecovers the edit's table shapes, and one integration test runs two mutations over a file holding comments, defaults, aliases, a deprecated section, and inline and array-of-tables entries.🤖 Generated with Claude Code