Skip to content

MAI-47: add --cleanup-changelogs command + inline bump resilience#16

Merged
vsmash merged 4 commits into
developfrom
task/MAI-47_changelog_cleanup
May 19, 2026
Merged

MAI-47: add --cleanup-changelogs command + inline bump resilience#16
vsmash merged 4 commits into
developfrom
task/MAI-47_changelog_cleanup

Conversation

@vsmash
Copy link
Copy Markdown
Owner

@vsmash vsmash commented May 19, 2026

Summary

  • Adds --cleanup-changelogs flag that AI-cleans both CHANGELOG.md and .CHANGELOG_internal.md, backfilling missing/empty sections from git log and producing customer-friendly vs internal styles.
  • Adds inline bump resilience in lib/changelog.js: stops writing empty ## VERSION sections (the visible 5.12.9 / 5.12.1 mess), and — when AI mode is on + MAIASS_AI_CHANGELOG_CLEANUP=true (new env var, default true) — routes the regex-formatted entry through aiCleanSingleEntry() before commit. AI failure falls through to the regex output; the bump pipeline is never blocked.
  • Auto-picks the AI model by input size for cleanup: gpt-4o-mini ≤ 8 KB input, gpt-4o beyond. gpt-3.5-turbo is too instruction-blind for this task (hallucinates Author Name: MAI-XXX placeholders, fails to consolidate same-date patches). Override via new MAIASS_AI_CHANGELOG_MODEL env var.
  • Branch-safe: cleanup refuses on dirty tree, switches to $MAIASS_DEVELOPBRANCH (default develop), pulls --ff-only, runs, commits, optionally pushes (gated on MAIASS_AUTO_PUSH_COMMITS), then returns to the user's original branch.
  • The cleanup commit on this PR is the empirical proof — it's the AI cleaning this repo's own messy changelogs (5.12.9 / 5.12.1 empties filled or omitted, 5.12.8 / 5.12.10–13 backfilled, 5.11.x same-date patches consolidated, Author Name: MAI-XXX hallucination gone after prompt iteration).

Files

  • New: lib/changelog-cleanup.js — module, prompt builders, version→commit mapping, group-by-minor, AI call, branch-safety wrap, .bak + .gitignore plumbing.
  • Edit: lib/changelog.js — empty-section skip + maybeAICleanEntries() hook before existing prepend logic.
  • Edit: lib/maiass-variables.jsMAIASS_AI_CHANGELOG_CLEANUP (default true), MAIASS_AI_CHANGELOG_MODEL (optional override).
  • Edit: lib/flag-validator.js + maiass.mjs — flag registration + dispatch alongside --account-info.
  • Edit: .gitignore — auto-added entries for CHANGELOG.md.bak and .CHANGELOG_internal.md.bak.

Jira: https://velvary.atlassian.net/browse/MAI-47

Follow-ups already logged:

  • MAI-48 — auto-bump the commit-side AI model when the changeset exceeds gpt-3.5-turbo's effective capacity.
  • MAI-49 — PR-mode fallback for --cleanup-changelogs when direct push to develop is blocked by branch protection (caught in this PR's E2E run).
  • Bashmaiass parity is a separate task (not yet ticketed).

Test plan

  • node maiass.mjs --help lists --cleanup-changelogs.
  • MAIASS_AI_MODE=off node maiass.mjs --cleanup-changelogs → refuses with clear message + exit 1.
  • Run with dirty working tree → refuses with clear message + exit 1.
  • Run from a feature branch with MAIASS_AUTO_APPROVE_AI_SUGGESTIONS=true → switches to develop, runs, commits there, switches back. (Direct push will fail on protected develop; MAI-49 covers the fallback.)
  • After cleanup, .bak files exist and are listed in .gitignore.
  • Restart, run cleanup again with no real changes pending → "No changelog content changed — nothing to commit."
  • Run a normal version bump with MAIASS_AI_CHANGELOG_CLEANUP=false → identical regex output (no AI hop).
  • Run a normal version bump with default flag (true) → AI-cleaned entries in both files.

🤖 Generated with Claude Code

Harry Charound and others added 4 commits May 19, 2026 17:37
Closes the gap where AI-written commit messages corrupt the changelog
format and the rigid regex-based prepend either drops content or
prepends empty sections (visible in .CHANGELOG_internal.md before this
change: 5.12.9 / 5.12.1 empty, 5.12.8 / 5.12.10-13 missing entirely).

New module lib/changelog-cleanup.js:
  - `--cleanup-changelogs` flag (registered in flag-validator.js
    ALWAYS_VALID_FLAGS + dispatched alongside --account-info in maiass.mjs).
  - Walks each present changelog file (CHANGELOG.md / .CHANGELOG_internal.md)
    independently — no derivation between them.
  - Anchors version ranges on `Bumped version to X` commits rather than tags
    (tags are routinely missing for patch releases on this repo).
  - Sends one minor-version group per AI call, newest-first, with the
    existing block + git commits + commit date for every version in the
    group so the AI can backfill missing/empty sections AND fill missing
    date lines.
  - Internal house style keeps MAI-XXX + author; public strips both and
    rewrites in end-user voice. Consolidation rule with worked example
    forces same-date patches into one section with the latest patch as
    header.
  - Auto-picks the AI model based on input size (gpt-4o-mini for <=8 KB,
    gpt-4o beyond). gpt-3.5-turbo is too instruction-blind for this task.
    Override via new MAIASS_AI_CHANGELOG_MODEL env var.
  - Writes `<file>.bak` before each run (overwrites previous); restores
    on any AI / parse / I/O failure; auto-adds the .bak names to
    .gitignore.
  - Branch-safety wrap: refuses on dirty tree, forces checkout to
    $MAIASS_DEVELOPBRANCH (default develop), pulls --ff-only, runs,
    commits `chore: changelog cleanup via --cleanup-changelogs` to develop,
    optionally pushes (MAIASS_AUTO_PUSH_COMMITS), switches back.
  - Confirmation prompt before the branch dance unless
    MAIASS_AUTO_APPROVE_AI_SUGGESTIONS=true.

Inline bump resilience in lib/changelog.js:
  - New MAIASS_AI_CHANGELOG_CLEANUP env var (default true). When AI mode
    is on and the flag is true, the regex-formatted entries are routed
    through aiCleanSingleEntry() before writing — fixes the AI-disturbed
    commit-message case the user described. AI failure falls through to
    the regex output; the bump pipeline is never blocked.
  - Stops writing empty internal sections when no commits qualified —
    this was the visible "5.12.9 empty" bug.

Credits from cleanup AI calls flow through the existing
MAIASS_CREDITS_REMAINING env var, so the end-of-pipeline total naturally
includes cleanup spend.

Out of scope (tracked separately):
  - Bashmaiass parity — separate follow-up task.
  - MAI-48: auto-bump the commit-side AI model when the changeset
    exceeds gpt-3.5-turbo's effective capacity.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ensureGitignoreEntries() may modify .gitignore on develop (to add the
.bak filenames), so the cleanup commit's `git add` must include it —
otherwise the file stays modified and blocks the post-cleanup checkout
back to the user's original branch. Caught when running the cleanup
end-to-end on this repo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The AI consolidation rule under-applies when same-date patches aren't
adjacent in the version sequence. Caught after merging develop into a
feature branch: .CHANGELOG_internal.md kept `## 5.12.13` and `## 5.12.7`
as separate sections even though both were dated 13 May 2026 (because
5.12.8/9/10/11/12 sit between them in version order).

Fix: stop trusting the AI on consolidation. After each AI chunk returns,
parse it back into sections, bucket by normalised date key (strips the
optional weekday suffix so "13 May 2026 (Wednesday)" === "13 May 2026"),
and for each date with multiple sections produce one merged section
whose header is the latest patch number and whose body is the
concatenated bullets with line-level dedup.

Also re-applies the consolidator to the existing cleaned files in this
PR so the merge of develop into feature branches stops surfacing the
under-consolidation. Confirmed: `## 5.12.13` now contains all five
13-May entries including MAI-36 (which had been stuck on `## 5.12.7`).

Separate issue noted but not addressed here: the public CHANGELOG.md
dropped the MAI-36 entry entirely during the AI pass — judgement call
about user-visibility, not a consolidation bug.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vsmash vsmash merged commit 83d9c9d into develop May 19, 2026
8 checks passed
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.

1 participant