Skip to content

fix(sync): safely clean unreferenced attachments - #843

Merged
ctawiah merged 2 commits into
mainfrom
ctawiah/sync-attachment-cleanup-safety
Oct 8, 2026
Merged

ctawiah merged 2 commits into
mainfrom
ctawiah/sync-attachment-cleanup-safety

Conversation

@ctawiah

@ctawiah ctawiah commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Context

A local tool or skill file is no longer needed after the final synchronized variation stops referencing it. This layer completes the attachment lifecycle by finding those files and asking before removing them. It applies the same behavior to normal syncs and watch mode.

What changes

  • Finds local tool and skill files that are not referenced by any synchronized variation.
  • Prompts before deleting an unreferenced file.
  • Treats --yes as confirmation for attachment cleanup along with the rest of the sync.
  • Removes confirmed files as one transaction so a failed deletion can be rolled back safely.
  • Rejects unexpected paths, duplicate selections, non-regular files, and symbolic links before deleting anything.
  • Runs cleanup only after a successful sync or after confirming that there are no resource changes to apply.
  • Watches all managed source files directly instead of rebuilding the watch scope from project directories.
  • Passes watcher state into each sync run explicitly.

This cleanup only removes local files. It does not delete tools or skills from LaunchDarkly.

Review focus

  • Does cleanup wait until the final local reference has been removed?
  • Are interactive confirmation and --yes handled consistently?
  • Can a partial filesystem failure leave a deleted attachment file behind?
  • Does watch mode run the same cleanup and confirmation flow as a normal sync?
  • Are path and symbolic-link checks applied before any file is moved or removed?

Verification

  • go test ./internal/sync/local ./internal/sync/prompt ./internal/sync/detach
  • go test ./...
  • go vet ./internal/sync/... ./cmd/sync
  • git diff --check

Related changes

Review the stack in this order:

  1. Confirm destructive watch actions
  2. Guarantee prompt fingerprint convergence
  3. Add searchable attachment API foundations
  4. Reconcile variation attachments
  5. Attach tools and skills to variations
  6. Render attachment-aware review output
  7. Safely clean unreferenced attachments
  8. Persist sync manifests in LaunchDarkly

Note

Overview
Adds orphaned local attachment cleanup to the sync prompt flow: after a successful sync (or when the plan has no changes and the user declines apply), the CLI finds managed tools/*.json and skills/*.md files that no variation still references, lists them, and deletes only after interactive confirmation or --yes (with a second reference check right before delete).

The local store gains OrphanedAttachments and DeleteAttachments, using staged renames plus path/symlink/regular-file validation. commitDeletions now treats the staged rename as the commit point and cleans up backups best-effort (no partial rollback on backup removal failure).

Watch mode passes the file watcher into each sync explicitly, and SourceFiles includes all files under project subtrees in .launchdarkly (not just variation wrappers) so attachment edits trigger sync. Store.ProjectKeys is removed.

Reviewed by Cursor Bugbot for commit 69d7fbf. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread internal/sync/prompt/runner.go
@ctawiah
ctawiah force-pushed the ctawiah/sync-attachment-cleanup-safety branch 2 times, most recently from 0f4b180 to f183b15 Compare October 7, 2026 15:44

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f183b15. Configure here.

Comment thread internal/sync/prompt/terminal.go
Comment thread internal/sync/prompt/terminal.go
Base automatically changed from ctawiah/sync-attachment-review-output to main October 8, 2026 00:31
@ctawiah
ctawiah force-pushed the ctawiah/sync-attachment-cleanup-safety branch from f183b15 to 69d7fbf Compare October 8, 2026 00:38
@ctawiah
ctawiah merged commit 6b5be42 into main Oct 8, 2026
10 checks passed
@ctawiah
ctawiah deleted the ctawiah/sync-attachment-cleanup-safety branch October 8, 2026 00:44
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.

2 participants