Skip to content

Add dispatch prune to clean orphaned per-session config metadata #272

Description

@jongio

Description

Add a dispatch prune command that removes per-session metadata in config.json (tags, aliases, notes, favorites, hidden entries, launch stats) for sessions that no longer exist in the session store.

Use Case

Every time you tag, alias, star, hide, note, or launch a session, dispatch stores an entry keyed by session ID in config.json. When those sessions age out of the Copilot CLI store, their entries stay behind. Over months the config accumulates dead keys, stale aliases can shadow new ones, and the file becomes noisy to hand-edit. There is no supported way to clean it up short of editing JSON by hand.

Proposed Solution

Add cmd/dispatch/prune.go:

  • Load the config and the session store, build the set of live session IDs, and find entries in SessionTags, SessionAliases, SessionNotes, FavoriteSessions, HiddenSessions, and SessionLaunches whose ID is not present.
  • Default to a dry run that reports how many orphaned entries exist per category with a small sample.
  • --apply removes the orphaned entries and saves the config.
  • --json prints a machine-readable report.
  • Degrade gracefully when the store cannot be opened rather than deleting entries blindly.

Acceptance criteria

  • dispatch prune reports orphaned entries per category and changes nothing.
  • dispatch prune --apply removes only orphaned entries and persists the config.
  • dispatch prune --json prints a stable report object.
  • An unreadable or missing store is handled without removing anything and without a panic.
  • Tests cover no orphans, some orphans per category, the apply path, and the store-unavailable case.

Alternatives Considered

Folding this into dispatch doctor, rejected because doctor is read-only diagnostics and prune mutates the config. Auto-pruning on startup, rejected because silent deletion of user curation is surprising and unrecoverable.

Complexity

M

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestideaFeature idea from the idea pipeline

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions