Skip to content

Setup: edit an existing User config in place - #138

Merged
JacobStephens2 merged 3 commits into
mainfrom
issue-128
Sep 29, 2026
Merged

JacobStephens2 merged 3 commits into
mainfrom
issue-128

Conversation

@JacobStephens2

@JacobStephens2 JacobStephens2 commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

thirdshift setup over an existing User config now edits it in place with toml_edit (pure Rust, so it builds under musl per ADR-0003), instead of leaving it as it was.

 setup
   read the User config
   none → write DEFAULTS
   parse it as a Run would → refuse: exit 1, file untouched
-  "already set up"
+  complete(text)
+    missing key in an existing section → appended at the end of that section, with its comment from DEFAULTS
+    missing section                    → appended after the file's last line
+    no email.to and no "# to =" line   → the commented-out example goes just above email.from
+  unchanged → say so, write nothing
+  changed   → replace the file through a temp file, keeping its permissions

Before, with a partial User config:

# My machine
[merge]
always = true   # trust

[email]
to = "me@example.com"  # inbox

After thirdshift setup </dev/null:

# My machine
[merge]
always = true   # trust

[email]
to = "me@example.com"  # inbox
always = false                  # every Run sends a Run notification, without the email word; default false
from = "onboarding@resend.dev"  # the sender; default onboarding@resend.dev, which only delivers to your Resend account's address

[launch]
pull = false     # every Run first fast-forwards your checkout of the Base branch; default false

[logs]
dir = "~/.thirdshift/logs"   # where session logs go; default ~/.thirdshift/logs

Evidence

  • Before: on main, setup over an existing User config returns "already set up" after parsing it and writes nothing, so a partial file gains none of its missing keys.
    After: cargo test passes in full, clippy is clean, and tests/setup.rs has 10 of 10 passing, including:
    • a partial config keeps its values and hand-written comments, and gains every missing key with its comment
    • a complete, hand-edited config is left byte for byte as it was
    • invalid TOML, an unknown key and a wrongly typed value each exit 1 with the same stderr a Run gives, and the file is unchanged
    • a Run on the completed file is still a Merge run and still writes its logs to the custom logs.dir
    • running setup twice adds the commented-out email.to line only once
  • Unit tests on complete cover dotted keys, inline tables, no trailing newline, and trailing comments. They also check that a Run parses the result with the settings it had before, and that running complete a second time changes nothing.

Merge Danger

Door: two-way

This rewrites users' files, but only by adding lines, and it never rewrites a file that is already complete. Reverting the PR restores the old behavior.

Blast Radius: small

Only thirdshift setup over an existing User config is affected. A Run, email-test, update, version and help don't change. The only new dependency is toml_edit.

Unaddressed findings

Standards

  • The table and inline-table arms repeat the same missing-key loop (Duplicated Code). Skipped: the two insert through different toml_edit APIs and one drops comments, so a closure-taking helper wouldn't make it clearer.
  • The email section is special-cased by name (Primitive Obsession). Skipped: email.to is the one key with no default, so the special case is real.
  • has_commented_out_email_to rescans the raw text. Partly addressed: it now matches an [email] header exactly. The rescan stays because toml_edit scatters comments across key decor, the next header and the document trailer.
  • The same behavior is tested through both the unit and integration seams. Skipped: the integration test covers the acceptance criterion, and the unit tests cover edge cases cheaply.

Spec

  • A key added to an inline table gets no comment. Skipped: TOML has no place for a comment inside an inline table. The README and the doc comment now say so.
  • Dotted email.* keys don't get the commented-out email.to line. Skipped: it's a rare form and there's no natural place for the line. The keys themselves are still added.
  • Adding the commented-out email.to line is scope creep. Skipped: it keeps "the file lists every key the installed version knows" true, and matches the file Setup writes from scratch.
  • A comment at the end of a section ends up below the keys added to it. Skipped: this is how toml_edit attaches such comments. The comment is kept, and the settings and their order are unchanged.
  • Missing sections go at the end, not in merge, launch, email, logs order. Skipped: that order is for new files. Inserting sections between the user's own would move their text.

Closes #128

🤖 Generated with Claude Code

JacobStephens2 and others added 3 commits September 29, 2026 22:53
With toml_edit, Setup keeps an existing User config's values, comments and
key order, and adds each key this version knows but the file lacks at its
default with its comment. A User config a Run would refuse is refused the
same way and left untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Setup replaces the User config through a temporary file, keeping its
permissions, so a failed write can't truncate it. The commented-out
email.to check matches only an [email] header, the unreachable arm says
so, and the README notes inline tables and the email.to line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new User config gets the suggested GitHub email as email.to (#129);
an existing one is still completed in place (#128).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JacobStephens2
JacobStephens2 merged commit f610ac6 into main Sep 29, 2026
13 checks passed
@JacobStephens2
JacobStephens2 deleted the issue-128 branch September 29, 2026 23:12
@JacobStephens2 JacobStephens2 mentioned this pull request Sep 30, 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.

Setup: edit an existing User config in place

1 participant