Skip to content

fix: move pre-existing .devcontainer aside instead of refusing to init - #21

Open
ai-anant wants to merge 1 commit into
cyfinoid:mainfrom
ai-anant:fix-6-devcontainer-conflict-preserve
Open

fix: move pre-existing .devcontainer aside instead of refusing to init#21
ai-anant wants to merge 1 commit into
cyfinoid:mainfrom
ai-anant:fix-6-devcontainer-conflict-preserve

Conversation

@ai-anant

@ai-anant ai-anant commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Closes #6. When a repo already ships its own .devcontainer/ (or an aidc-managed .cursor/rules/00-core-logics.mdc), aidc init / aidc claude aborted with:

[aidc] error: refusing to overwrite existing file: <PATH>/.devcontainer/devcontainer.json

This made aidc unusable on any repo that already had a devcontainer — exactly the scenario in the issue ("AIDC wont initialize if .devcontainer already exists").

Change

lib/aidc.shaidc::check_init_conflicts() no longer dies when a pre-existing managed path is found. Instead it:

  • Detects any aidc-managed path under the top-level dirs aidc scaffolds wholesale (.devcontainer/, .cursor/rules/).
  • Moves the whole top-level dir aside to <dir>.aidc-backup (numeric suffix .1, .2, … on collision) — user content is renamed, never deleted.
  • Prints a restore hint: mv .devcontainer.aidc-backup .devcontainer.
  • Then refresh_scaffold proceeds normally.

aidc::ensure_local_git_excludes() now also excludes .devcontainer.aidc-backup*/ so the backup dir doesn't pollute git status.

Behavior matrix:

Pre-existing state Before After
.devcontainer/devcontainer.json (typical VS Code devcontainer) error: refusing to overwrite moved to .devcontainer.aidc-backup, scaffold proceeds
.cursor/rules/00-core-logics.mdc error: refusing to overwrite .cursor moved to .cursor.aidc-backup, scaffold proceeds
.cursor/rules/my-user-rule.md (no aidc-managed path) scaffold proceeds unchanged — user rule kept alongside aidc's 00-core-logics.mdc
Already initialized (.ai-container/project.env present) no-op no-op (idempotent, re-init clean)

Verification

  • bash -n under bash 3.2.57 (the project floor) — clean
  • shellcheck --severity=warning on bin/aidc, lib/aidc.sh, all *.sh (mirrors shellcheck.yml) — clean
  • .github/scripts/bash-compat-check.sh under bash 3.2 — parse + smoke OK
  • tests/resolve-oauth-token.test.sh — 7/7 pass
  • .github/scripts/test-bootstrap-state.sh — 9/9 pass
  • python3 -m py_compile bin/aidc-clipboard-server — OK
  • End-to-end simulation (real aidc init): repo with pre-existing .devcontainer/ (devcontainer.json + scripts) + .cursor/rules/my-user-rule.md → init succeeds, originals preserved in .devcontainer.aidc-backup, user cursor rule untouched, scaffold complete. Second scenario with a .devcontainer.aidc-backup already present → backup correctly lands in .devcontainer.aidc-backup.1. Re-running aidc init on an initialized repo stays a clean no-op.

Fixes #6

When a repo already ships its own .devcontainer/ (or an aidc-managed
.cursor/rules/00-core-logics.mdc), 'aidc init' / 'aidc claude' aborted with
'error: refusing to overwrite existing file'. The pre-existing files are now
moved aside to <dir>.aidc-backup (with a numeric suffix on collision) and a
restore hint is printed, then the scaffold proceeds. User content is
preserved, never deleted.

The backup dirs are added to the per-repo git excludes so they don't pollute
git status.

Fixes cyfinoid#6
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.

AIDC wont initialize if .devcontainer already exists

1 participant