Repository navigation
fix(bootstrap,setup): back up .mcp.json before reformatting; keep a hand-edited governance workflow (#374) - #377
Merged
Conversation
…and-edited governance workflow (#374) - Adding mcpServers.charter to an existing .mcp.json that would be re-serialized differently backs it up to .charter/.backup/mcp.json.<ts> first (Updated .mcp.json (backup: ...), setup.details.mcpBackup); a failed backup writes nothing and warns. Canonically formatted files need no backup. - bootstrap/setup --ci github refresh charter-governance.yml only when it matches a known Charter template (current npm/pnpm or a historical variant recovered from git history, hashed in commands/github-workflow.ts; CRLF, trailing whitespace and a pinned CLI version normalized). A hand-edited workflow is kept with a warning; --force backs it up to .charter/.backup/github-workflows-charter-governance.yml.<ts> and replaces it. - Docs and CHANGELOG. Closes #374 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ow refresh (#374 review) - A known Charter workflow is refreshed without --force only when the refresh widens nothing: same normalized permissions and on: triggers, no new git push step. KNOWN_WORKFLOWS carries a per-version safe flag (only the current npm and pnpm templates); workflowWidening re-checks at run time and names the widening. Older contents: read templates are kept in bootstrap and setup with a warning (reason would-widen-permissions); --force backs them up and says what widened in the Replaced line. - The --force hint names what else --force does in each command and that deleting the workflow and re-running replaces only it. - A failed workflow backup under --force: not replaced (backup failed), listed in notReplaced, exit 1 in both setup and bootstrap. - JSON: new workflow fields use '/'; bootstrap gains setup.details.workflow. - Docs: pin/BOM normalization, notReplaced, ci-integration re-run section, docs-snippets; CHANGELOG. - Tests: widening kept/replaced (bootstrap and setup), same-permission refresh, BOM, notReplaced and exit codes, CRLF .mcp.json, KNOWN_WORKFLOWS guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…backup # Conflicts: # CHANGELOG.md # docs-snippets/charter-cli-reference.md
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iffing (#374 review round 3) - Drop the run-time workflowWidening diff. KNOWN_WORKFLOWS entries carry a package manager, a safe flag and a hand-written refreshChanges; unsafe ones (every pre-badge template) are kept unless --force, with that text. - Hand-edited workflows: no claim about the edit; the warning and the Replaced line state what the current template grants (TEMPLATE_PERMISSIONS). JSON: reason + templatePermissions (+ changes for older templates). - npm<->pnpm refresh is named: Updated ... (package manager npm -> pnpm; adds pnpm/action-setup@v4), packageManagerChange in JSON. - A failed --force backup (workflow, or .mcp.json replacing mcpServers.charter) fails bootstrap's setup step, status partial, "Bootstrap finished with failures.", exit 1. Setup: reason in notReplaced, replace added to replaced. - Bootstrap kept[] uses the platform separator for the workflow. - origin labels name the first commit; governance-gaps check accepts charter-governance.yml (and charter.yml). - Docs: pin claim corrected; CHANGELOG, cli-reference, ci-integration, snippets. - Tests: every historical template via bootstrap and setup (fixture), hand edits (flow style, job-level, quoted on, write-all, narrowed), pm swap, JSON status on exit 1, setup notReplaced reason, mcp --force exit 1, gaps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es; precise failure summary (#374) - An older template whose upgrade also switches npm<->pnpm: the kept warning and the Replaced line add "package manager npm -> pnpm (adds pnpm/action-setup@v4)"; JSON carries packageManagerChange. - "Bootstrap finished with failures." only when bootstrap exits 1; a failed step that exits 0 (doctor WARN checks) keeps "Bootstrap complete.". - A setup step failed by a backup: the banner names the cause and files, and the next step says to make .charter/.backup writable and re-run. - Setup wording and comments match the static descriptions. - Tests: pm switch on upgrade (kept, Replaced, setup JSON), doctor-only summary, banner, .mcp.json add-entry backup failure under --force (exit 0), old templates' on: has no push/workflow_dispatch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #374
.mcp.json reformatting
When bootstrap adds
mcpServers.charterto an existing.mcp.jsonthat lacks it, it re-serializes the whole file withJSON.stringify(root, null, 2).JSON.stringify(parsed, null, 2) + '\n'(a CRLF copy counts as different),.mcp.jsonis first backed up to.charter/.backup/mcp.json.<ts>.Updated .mcp.json (backup: …), and JSON carriessetup.details.mcpBackup.Behavior change under
--force: if the backup fails while--forceis replacing an existingmcpServers.charterentry,.mcp.jsonis listed insetup.details.notReplaced, the setup step fails, and bootstrap exits 1. On main this case exited 0.charter-governance.yml
The logic lives in the new module
packages/cli/src/commands/github-workflow.ts. It never diffs YAML.Known templates.
KNOWN_WORKFLOWSlists the 9 templates recovered from the history ofsetup.ts. Each entry records:hash;origin, the first commit that generated it;packageManager;safeflag;refreshChanges.Only the two current templates (npm and pnpm, from 003ec8d) are safe. All 7 older ones had
contents: readand ran onpull_requestonly, so they carry the same text:contents: read → write; adds push and workflow_dispatch triggers; adds a step that commits and pushes to the repo.What the current template grants.
TEMPLATE_PERMISSIONSis one fixed line:the current Charter template grants contents: write and pull-requests: write, runs on push, pull_request and workflow_dispatch, and has a step that commits and pushes to the repo. A test checks it against the template.Comparison. Before hashing, the workflow is normalized:
A pinned
@stackbilt/[email protected]is normalized as well. The only template that pinned one (04b1442) is unsafe, so a pinned workflow is always kept unless--forceis passed.Outcomes (the same for
bootstrap --ci githubandsetup --ci github):--force--forceUpdated … (package manager npm → pnpm; adds pnpm/action-setup@v4)(packageManagerChangein JSON)refreshChanges(reason: would-widen-permissions, pluschanges)Replaced … (backup: …; changes: …)TEMPLATE_PERMISSIONSand says to review it before using--force(reason: hand-edited, plustemplatePermissions)Replaced … (backup: …; the current Charter template grants …)When the backup fails under
--force:Not replaced … (backup failed; see warning), lists the file insetup.details.notReplaced, fails the setup step (status: "partial") and printsBootstrap finished with failures.;CI policy gate: not replaced (backup failed)and adds{ file, detail, reason }tonotReplaced;The warnings also say what else
--forcedoes in each command, and that deleting the workflow and re-running replaces only the workflow.Changes from main:
setup --forcebacks up before replacing;setup --ci githubwithout--forcenow refreshes the other package manager's current template (with the note above), where it used to leave it alone;Bootstrap finished with failures.instead ofBootstrap complete.whenever any step failed;.github/workflows/charter.yml, which Charter never generates. It now acceptscharter-governance.ymlorcharter.yml.JSON:
setup.details.keptlists a kept workflow, using the platform separator like the.charter/entries.New:
setup.details.replaced: [{ file, backup, reason, note }],setup.details.notReplaced: [{ file, detail, reason? }],setup.details.workflow: { file, action, reason?, changes?, templatePermissions?, backup?, packageManagerChange? }.workflow.kept,notReplaced,reason,changes,templatePermissions,packageManagerChange,backupandwarning.The workflow is also added to top-level
replacedandnotReplaced, each withreason.Path separators:
kept,created,updatedandworkflow.pathkeep the platform separator, as before. The newreplaced,notReplacedandworkflowfields use/, asbackupdoes.applyManagedFileis removed; nothing else called it.Docs
docs/cli-reference.md: bootstrap and setup--ciand--force, and the global--forcerow.docs/ci-integration.md: a new "Re-running setup or bootstrap" section.docs-snippets/charter-cli-reference.md.[Unreleased], with both init --guided with non-TTY stdin exits 0 mid-questionnaire without writing anything #375 and bootstrap rewrites .mcp.json formatting and overwrites a hand-edited charter-governance.yml with no backup #374 entries.Tests
packages/cli/src/__tests__/workflow-mcp-backup.test.tshas 62 tests. The fixturefixtures/charter-governance-history.jsonholds all 7 historical templates.--yesand setup, and each produces the exact static message.on:,write-alland narrowedcontents: readare all kept with theTEMPLATE_PERMISSIONSwarning, and nothing in the output claims a widening orx: y → z. Each is also replaced under--force, with the template line in the output.status: "partial"with the setup step failed; setupnotReplacedwithreason; setup top-levelreplaced;.mcp.jsonbackup failure under--force.safeflag;KNOWN_WORKFLOWSone to one, withoriginstarting at the fixture's commit;TEMPLATE_PERMISSIONSmatches the template.Full suite, run serially: 1691 passed, 3 failed. The 3 are the known Windows-only failures (bootstrap #307, context-refresh, serve-context), which also fail on main.
🤖 Generated with Claude Code