Skip to content

fix(config): keep hook pipelines' spelling and comments on save; expand ~ in PI_CODING_AGENT_DIR - #4151

Merged
max-sixty merged 3 commits into
mainfrom
release-followups
Sep 16, 2026
Merged

max-sixty merged 3 commits into
mainfrom
release-followups

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Two small fixes found while reviewing v0.78.0.

A config save rewrote hook pipelines into another spelling, dropping their comments. A pipeline serializes in one spelling whatever the file used: one step as its lone table, more as an inline array of tables. So every user-config save (declining the commit-generation offer, say) found an untouched pipeline "changed" and rewrote it:

  • [[post-start]] blocks — the documented form — lost the comment above them; a one-step pipeline became [post-start], and a longer one collapsed into an inline array moved to the top of the file.
  • post-start = [{ … }] became a [post-start] table with the comment above it rendered inside the brackets. Since fix(config): refuse to write a config rewrite that is not valid TOML #4140 the save refuses to write TOML it can't read back, and prompts whose decline path ignores the save error came back on every run.

merge_tables now re-spells the desired pipeline the way the file writes it (in_existing_spelling) before comparing, and merges [[…]] blocks block by block. An untouched pipeline stays byte-identical; a step the load rewrote (template migration renaming repo_root) changes alone, keeping its trailing comment. test_saving_config_mutation_keeps_each_pipeline_spelling_and_its_comments covers the inline array, one [[post-switch]] block, and two [[pre-start]] blocks; it fails without the change.

wt config plugins pi install ignored ~ in $PI_CODING_AGENT_DIR. Pi expands a leading ~ there (getAgentDir → normalizePath), so a quoted PI_CODING_AGENT_DIR="~/x" means a directory under home; wt created a literal ~ directory under the cwd. pi_agent_dir now uses worktrunk::path::expand_tilde, and test_pi_install_honors_agent_dir_override covers the ~/… case. omp.rs is unchanged: oh-my-pi resolves the same variable with a plain path.resolve.

This was written by Claude Code on behalf of max-sixty

🤖 Generated with Claude Code

max-sixty and others added 2 commits September 16, 2026 14:50
…~ in PI_CODING_AGENT_DIR

A one-step pipeline written as an array (`post-start = [{ … }]`) serializes
back as a `[post-start]` table, so any config save rewrote the line and the
comment or blank line above it rendered inside the header's brackets. Since
the save path refuses to write TOML it can't parse, the save failed, and a
declined prompt that ignores that error came back on every run. Route every
value that becomes a standard table through the header-decor helper, renamed
`replace_value_with_table`.

Pi expands a leading `~` in `$PI_CODING_AGENT_DIR`; `wt config plugins pi
install` created a literal `~` directory under the cwd instead. oh-my-pi
resolves the variable without expansion, so `omp.rs` is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new branch keys on is_value(), which excludes Item::ArrayOfTables — so the [[hook]] block form still loses the comment above it on save. That form is the documented one: wt hook --help (after_long_help in src/cli/mod.rs, mirrored in hook.md) says "A pipeline is a sequence of [[hook]] blocks run in order", and the inline-array spelling this PR fixes appears in no user-facing doc.

I ran set_commit_generation_command against the merge commit for both step counts.

Observed input and output

One step in:

worktree-path = "../x"

# start the dev server
[[post-start]]
server = "npm run dev"

out — comment gone:

worktree-path = "../x"

[post-start]
server = "npm run dev"

Two steps in:

worktree-path = "../x"

# share the build cache, then install
[[post-start]]
copy = "wt step copy-ignored"

[[post-start]]
install = "pnpm install"

out — comment gone, and the documented block form collapsed into an inline array:

worktree-path = "../x"
post-start= [{ copy = "wt step copy-ignored" }, { install = "pnpm install" }]

Two separate mechanisms, neither reached by this diff. For one step, the comment sits on the array-of-tables' first table decor — aot.get(0).decor().prefix() holds "\n# start the dev server\n" while the key's leaf decor is "" — so even with the branch condition widened to is_array_of_tables(), replace_value_with_table's prefix read would need a fallback to that first-table decor. For two steps the desired item is an array rather than a table, so it never reaches either table branch: replace_keeping_decor takes it, as_value() returns None for an array-of-tables, and the decor is dropped along with the block formatting.

Both predate this PR, and neither produces unparsable TOML, so ensure_config_parses doesn't refuse the save — the user just silently loses a comment in a file worktrunk wrote on their behalf. Flagging it rather than fixing it here because the second case needs a path this diff doesn't add; the decision is whether it lands in this PR or a follow-up, given the PR's stated subject is comments above a one-step pipeline and this is the documented spelling of one.

The rest reads clean: the rename propagated with no stale references, widening the suffix read from as_inline_table() to as_value() is a strict superset, the inline-table branch still shadows the new one so no key takes both paths, and the Pi change reuses the existing expand_tilde helper with the omp divergence documented at both sites.

Comment thread src/config/user/persistence.rs Resolved
A pipeline serializes as a lone table (one step) or an inline array of
tables, whatever the file used, so every save found an untouched
`[[post-start]]` pipeline changed: it dropped the comment above the
blocks and rewrote them as `[post-start]` or an inline array. Re-spell the
desired pipeline the way the file writes it before comparing, and merge
`[[...]]` blocks block by block. This also covers the inline-array case
the previous commit handled by converting to a table, so that branch and
the helper rename are reverted.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty max-sixty changed the title fix(config): keep comments above a one-step pipeline on save; expand ~ in PI_CODING_AGENT_DIR fix(config): keep hook pipelines' spelling and comments on save; expand ~ in PI_CODING_AGENT_DIR Sep 16, 2026
@max-sixty
max-sixty merged commit 55d87b3 into main Sep 16, 2026
40 checks passed
@max-sixty
max-sixty deleted the release-followups branch September 16, 2026 22:31
max-sixty added a commit that referenced this pull request Sep 17, 2026
… whole config (#4160)

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 whole `UserConfig` and diff-merged it
into `config.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 a `toml_edit` document:

- **Only that value changes.** An existing value keeps its decor; a
missing table is created implicit, or inline inside an inline table; an
existing table is edited in whatever form the file writes it. So a save
no longer writes a deprecated key's canonical spelling beside the
original (`[select]` gaining `[switch.picker]`, after which `select`
warned as unknown on every command), and retired template variables,
`pre-create` aliases, and deprecated sections stay as written until `wt
config update`.
- **An edit the load wouldn't read goes into the migrated file.** A
deprecated `[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::edited`
checks 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 than `wt 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).
- **The in-memory config is no longer replaced by the file's.** The
mutator runs on the file's config to decide what to write and on `self`
to keep it current, so system config, `WORKTRUNK_*` variables, and
`--config-set` still hold for the rest of the command. Previously a
first-run prompt dropped them — `--config-set 'commit.stage="none"'`
staged everything once `wt step commit` had 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 of `replace_inline_with_table`, which moves
into `deprecation.rs` beside its only caller. The unit tests that pinned
the merge go; `test_config_edit_changes_only_its_value` covers 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.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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