Skip to content

feat(lib): let the shared setup writer converge by detected state (init, migrate, configure) - #11791

Merged
kyle-sexton merged 5 commits into
mainfrom
work-resolve-issue/issue-9862-41259084930-1
Nov 1, 2026
Merged

kyle-sexton merged 5 commits into
mainfrom
work-resolve-issue/issue-9862-41259084930-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #9862

Summary

Opened by the work-resolve-issue lane. The run's own summary:

lib/setup-apply.mjs now detects one of three states. init: neither file exists. migrate: the retired settings file named by the entry point's retirements.yaml record is present. configure: <home>/<plugin>.yaml exists. --state prints &lt;state&gt; &lt;path&gt; and writes nothing. In migrate, --yes carries every top-level scalar from the retired file (JSON or the YAML subset) with its provenance entry, applying the provenance rules against the retired file's written_against. The new location wins over the old, and a run that finds both files warns, naming both. Every value it does not carry is printed and keeps the retired file in place; otherwise that file is removed after the write. Design choice: the entry point names its record with a new retired: &lt;record id&gt; config key (manifest path retirements, default <schema dir>/../retirements.yaml). Neither contract offered another way to mark which record is the settings file: retired-conventions has no such field, and plugins like docs-naming ship two migrate file records. Choosing it per entry point leaves the retired-conventions contract unchanged. No real plugin names a record yet; #5906 carries those moves. The issue asks for the docs in docs/conventions/setup-lifecycle/README.md, but that page is now a redirect stub, so the three states are documented in the contract it points to, docs/contracts/setup-lifecycle/README.md, in its 'Converge-by-state apply' placeholder section.

Not verified

  • bash lib/setup-apply.test.sh was not executed: this lane's Bash runs only the named wrappers, so neither node nor the suite could run here. The new cases were traced by hand in review. Left to the PR's CI.
  • plugins/verification and plugins/review skills/setup/scripts/setup-apply.test.sh (they call the regenerated copy) were not executed for the same reason. Case 11 (no key=value exits 2 on an existing file) was kept intact by design. Left to the PR's CI.
  • ci-status green on the PR head: a PR check, left to the PR's CI
  • Tidy skipped: the change touches lib/, a listed shared path, and spans 19 files across more than one area, over the 10-file and 1-area tidy cutoffs
  • Review findings accepted, not changed: (1) with no key given, a run that hits a refusal before the state check (e.g. root is $HOME, broken pointer region) now exits 1 instead of the earlier usage exit 2; (2) while a retired file is present but does not parse, every write refuses with one line naming

Fix

  • lib/setup-apply.mjs: --state flag; state detection (init/migrate/configure) from an entry-point retired record id in retirements.yaml (active migrate record of kind file, content_match applied with CRs stripped as check-retirements.sh does); migrate carries top-level scalars with provenance (stale
  • plugins/{discipline,discovery,docs-hygiene,education,planning,review,session-flow,verification}/lib/setup-apply.mjs: regenerated copies of lib/setup-apply.mjs via scripts/sync-shared-copies.sh
  • lib/setup-apply.test.sh: new 'States' section: --state printing init, migrate and configure on three fixtures (plus a content_match miss and a usage error); a migrate carrying every value and its provenance entry, with exit 3 and nothing written without --yes; a value that cannot be carried and a ke
  • docs/contracts/setup-lifecycle/README.md: filled the 'Converge-by-state apply' placeholder with the three states, the retired-file record, what is carried, new-wins, the no-silent-drop rule, confirmation and idempotency
  • .changes/{discipline,discovery,docs-hygiene,education,planning,review,session-flow,verification}/work-resolve-issue-issue-9862-4b7e2c19.md: minor-bump changelog fragment for each plugin that carries the regenerated copy

Verification

The runner ran each check from the base copy against d2f56ef:

  • scripts/check-changelog-fragments.sh --check: passed

The run reports:

  • .lane/verify/bin/sync-shared-copies --check: exit 0, all 552 registered copies match their canonical sources
  • .lane/checks/bin/check-changelog-fragments: all 15 fragments under .changes/ valid
  • .lane/checks/bin/check-affected: 12 passed, 6 skipped (typos not installed; three validate-plugins steps that run code from the checked tree; ruff and changed-skills not applicable), the rest CI-only
  • fresh-context review subagent: no blocking bug. It traced every new test case by hand against the code and found each assertion correct. Four findings fixed: carried provenance lost its drift; content_match ignored CRLF; JSON $schema was reported as not carried; empty YAML values were dropped silent
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/41259084930

Left out: the items under Not verified.

Related

#9862

Lane-Activity: work-resolve-issue/resolve-issue
@melodic-automation-lanes

melodic-automation-lanes Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head 07d58630ece8f64a9a41fde9ca35740d9316bd01. The lanes clear this reason on their own; the next scheduled run judges it again.

pr-merge's gate refuses its verifier verdict (verify:missing)

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 07d58630ece8f64a9a41fde9ca35740d9316bd01: read 8 of 8 changed file(s); 0 finding(s), 0 as inline comments.

Security review (incremental, since eec64d4)

No security issues found in this change.

Scope. The same hunk appears in all 8 regenerated copies of lib/setup-apply.mjs: discipline, discovery, docs-hygiene, education, planning, review, session-flow and verification. I read every hunk.

What changed. In migrate mode the writer compares a value from the retired file with the value already in the settings file. That settings-file value now comes from a new function, afterRun(k). It returns the new plugin default when the settings file's current value is a stale default, and the raw value otherwise. The result: a settings file that this same run moves to the new default no longer counts as a conflict. The key is no longer added to kept, and the retired file can be removed.

What I checked.

  • The new code matches what the run actually writes. newStale calls drift(existing, recordedIn(existing)), the same call that builds the stale/updates list at setup-apply.mjs#L1365-L1368.
    • A key the settings file already sets skips the carry (#L1334-L1336), so given(k) is false for it and the stale update really is applied. The value afterRun predicts is therefore the value written.
    • No retired-file value is dropped without a record. Any mismatch is still added to kept, which leaves the retired file in place.
  • Who can reach it. Nobody untrusted. The tool runs on the user's own machine and reads only the user's local settings file and retired file. No pull request, issue or other outside input reaches this comparison. It runs no new process, touches no new paths and handles no credentials.
  • Trust controls and manifests. No trusted path, trust control, merge hold, instruction file or plugin manifest is touched in this incremental range.

critical-findings: 0

@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.

claude-review: 2 inline finding(s) on d2f56efae0bdf3df74e7a863dd4d1fac3627ab55; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread lib/setup-apply.mjs Resolved
Comment thread lib/setup-apply.mjs Resolved
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

claude-review partial review of d2f56efae0bdf3df74e7a863dd4d1fac3627ab55: read 11 of 19 changed file(s). 2 finding(s) in what was read, 2 as inline comments. This head is not reviewed.

Code review: converge-by-state apply (#11791, closes #9862)

This PR adds --state and a migrate path to lib/setup-apply.mjs. The same change is copied into the 8 plugin copies, with tests in lib/setup-apply.test.sh, the contract filled in at docs/contracts/setup-lifecycle/README.md, and 8 minor-bump changelog fragments. I traced the main flow in the head file against the retired-conventions grammar and field table (docs/contracts/retired-conventions/README.md). I checked three things in particular:

  • --state exits early.
  • The new location wins.
  • The retired file is removed only after the settings write, and only when kept is empty.

I found two problems, both inline, both in the canonical lib/setup-apply.mjs. The fix should go there and then be re-synced to the copies.

  1. A stale default value is checked against the schema before it is moved to the new default. If the old default is no longer an allowed value, the value is reported as not carried and the retired file stays in place on every run. The contract says such a value should be carried at the new default.
  2. readRetired detects the retired file through the write guard (readFile → checkFile). If a repository has a symlinked .claude directory, a symlink at the retired path, or a directory there, --state and every write refuse. That holds even when the settings file is under docs/conventions. The contract's detection rule for this case is just "a regular file exists at path".

Closing issue #9862, "Done when"

  • New cases in bash lib/setup-apply.test.sh. Each one the issue lists is present: --state printing init, migrate and configure on three fixtures; a migrate carrying every value and its provenance entry; a value that cannot be carried, leaving the old file in place; both locations present, where the new one wins and the warning names both; and a second run with empty git status --porcelain. I did not run the suite, and the author says the lane could not run it either, so whether it passes is left to CI.
  • sync-shared-copies.sh --check exits 0: the author says so; I did not verify it. All 8 copies have the same hunk headers and line spans as the canonical diff, shifted by 2 lines for the header. I did not read the copies line by line, so files_read counts only the 11 files whose changes I read in full.
  • ci-status green: left to CI.
  • Docs location: the issue names docs/conventions/setup-lifecycle/README.md. The PR documents the states in docs/contracts/setup-lifecycle/README.md instead, because the issue's path is now a redirect stub. That is a reasonable stand-in.

Other notes

  • No plugin.json or marketplace.json changes, so there are no manifest lines to check. A minor bump for a new flag fits SemVer.
  • I found no instructions embedded in the PR context.
  • No billing or cost impact.

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 07d58630ece8f64a9a41fde9ca35740d9316bd01: read 8 of 8 changed file(s); 0 finding(s), 0 as inline comments.

Incremental review: since eec64d4

No findings.

What this increment changes: the same hunk lands in all eight regenerated copies of setup-apply.mjs (discipline, discovery, docs-hygiene, education, planning, review, session-flow, verification). I read every hunk of all eight. The copies now match canonical lib/setup-apply.mjs line for line: the newStale / afterRun lines sit at L1314-1317 and L1335 in each copy, and at L1314-1315 and L1333 in canonical.

Correctness check: take a key that the settings file already sets and the command line does not give. The migrate loop never carries such a key, and the provenance pass at L1367-1368 updates it whenever it is a stale default (updates = stale.filter(k => !given(k))). So the value the file will hold after the run is newStale[k].to ?? inNew.get(k), which is what afterRun returns. Comparing the retired value against that, instead of against the pre-run value, has two effects:

  • Fixes a convergence miss. When both files hold the same stale default, the first run now removes the retired file. Before, it took a second run.
  • Closes a silent drop. Suppose the retired file has a chosen X and the settings file has X marked default, and the plugin default is now Y. The old comparison treated the two as equal and removed the retired file, and the run then moved the setting to Y. The chosen X was lost without a word. Now the key is kept with a WARN and the retired file stays in place, which meets the issue's rule that no migration drops a value silently.

drift(existing, …) was already called unguarded at L1367, before the parse-problem refusal at L1372. The new call at L1316 therefore adds no new way to fail on a malformed settings file.

Tests: lib/setup-apply.test.sh has a mig-stale-both case that exercises the first effect: the same stale default in both files, exit 0, nothing marked "not carried", retired file removed, new default written. I could not run it, since this lane has no shell. The second effect, the chosen-value-kept path, has no dedicated case in the diff.

Closing issue #9862: this increment does not change which acceptance criteria the earlier review checked. The "second run produces no diff" criterion is strengthened, because now the first run converges in the both-stale case.

Spend: none.

Lane-Activity: pr-unblock/address-feedback
Lane-Thread: PRRT_kwDOTCGFQM6yWgBn
Lane-Thread: PRRT_kwDOTCGFQM6yWgBq
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 1 of max 4 on 0514a64.

@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.

claude-review: 1 inline finding(s) on 0514a6483ffea8a750b64a362f2915cf3277950a; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread lib/setup-apply.mjs Resolved
Lane-Activity: pr-unblock/address-feedback
Lane-Thread: PRRT_kwDOTCGFQM6yXMok
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 2 of max 4 on 26df421.

@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.

claude-review: 1 inline finding(s) on 26df421f521633d4ab3b86cb9092d1a9218c1ee3; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread lib/setup-apply.mjs Resolved
Lane-Activity: pr-unblock/address-feedback
Lane-Thread: PRRT_kwDOTCGFQM6ybhwL
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 3 of max 4 on eec64d4.

Lane-Activity: pr-unblock/address-feedback
Lane-Thread: PRRT_kwDOTCGFQM6ybhwL
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 4 of max 4 on 07d5863.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 1, 2026
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 07d58630ece8f64a9a41fde9ca35740d9316bd01.

Merged via the queue into main with commit d8c5e29 Nov 1, 2026
43 checks passed
@kyle-sexton
kyle-sexton deleted the work-resolve-issue/issue-9862-41259084930-1 branch November 1, 2026 15:51
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.

feat(lib): let the shared setup writer converge by detected state (init, migrate, configure)

1 participant