fix: reopen preserved coding projects when selecting their folder

This commit is contained in:
2026-09-21 15:39:57 +08:00
parent 576edb2720
commit 6aa30a57b4
5 changed files with 186 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
# Task: Fix reopening a removed coding project folder
## Identity
- Task ID: 20260921-readd-project-8f4a2c
- Mode: Feature
- Branch: codex/20260921-readd-project-8f4a2c-readd-project
- Worktree: D:\Datas\OthersProjects\.codex-worktrees\makelore\20260921-readd-project-8f4a2c
- Base commit: 576edb2720c00c317b931ea8d33076efae1a0925
- Owner: codex
- Status: Ready for Integration
## Scope
- Diagnose and fix the reported create/use/remove/recreate sequence when the user directly selects the original Code project folder.
- Own the bounded Main project-service correction, project identity unit/Electron regressions, README behavior description, and this record.
## Intent And Constraints
- Concurrent Task Gate Passed: official check/start/status succeeded with the exact identity, feature mode, branch, worktree and main base above. The primary worktree belongs to `20260921-merge-disabled-model-2209f56a`; it remains untouched, including its existing untracked records.
- Planning Gate Passed after loading the entry/active task/memory index, positioning, integrated state, decision index and ADR-008, system architecture, domain/success criteria and relevant evidence/reflection/commitment context. Positioning remains a template; current code, README and accepted ADRs supply the actual product facts.
- Read the 150 peer task records' scope/intent/promotion sections. Historical empty records remain unknown coordination state. Completed project-scaffold and conversation-management work supplies compatible context; no concrete conflicting decision or dependency blocks this isolated repair. No subagents used.
- Keep project identity, type, Agents, Conversations and knowledge project-owned. Do not erase `.makelore`, migrate old namespaces, create a new persistent authority, change Host request/response shapes, change Pi, touch user projects, merge main, install or publish.
- Use diagnosing-bugs with a deterministic real Main-service regression. The exact existing-config guard throws after the catalog has been emptied; this direct evidence makes additional speculative hypothesis ranking and temporary instrumentation unnecessary.
## Outcome
- Root cause: removeProject deletes only the application catalog entry, correctly leaving project files intact. createProject previously always called createLocalCodingProject, whose metadata creation rejects an existing `.makelore/project.json`; the route maps that rejection to the screenshot's `该编程项目已经存在。`.
- Direct-directory creation with the ordinary automatic-identity choice now reads existing metadata inside the current serialized activation transition. Valid projects are registered/opened and projected through getConfig, retaining identity/type/Agents/Conversations/knowledge and the existing missing-identity backfill. Invalid configuration is reported without overwriting or registering it.
- New child-directory name collisions and explicit bind operations preserve their existing creation conflict behavior. Selecting an already registered folder reuses its catalog entry. No new dependency, wrapper, migration or UI control is needed.
- README now explains removal and reattachment. UI before: the original folder leaves the creation dialog showing the duplicate-project error. UI after: the same confirmation reopens the preserved project and enters chat.
## Verification
- Red: `pnpm exec vitest run tests/unit/coding-project-identity.test.ts -t 'reopens a removed project'` failed with `CodingProjectServiceError: Coding project already exists` at the production createProject seam (12 ms test time). The unchanged command passed after the fix.
- Green: 43 tests across coding-project-identity, coding-projects-schema-v2, coding-projects-facade and coding-workspace-store. Regressions cover byte-preserved config/conversation files, Agent/type/identity preservation, knowledge contents, repeated selection, invalid existing metadata, child-directory and explicit-bind conflicts, and legacy identity backfill.
- `pnpm run typecheck` passed. Changed-file ESLint passed for project-service and the two changed test files. `pnpm run build:vite` passed all production targets.
- Additional strict Main-service compilation reports one pre-existing TS2322 at project-service.ts:215 (`config.projectId` is `string | undefined` where `string` is required). Compiling the exact base-commit source through the same command reproduces the identical diagnostic; no new diagnostic was introduced. The temporary baseline source was removed. This existing type contract is outside the reattachment correction.
- `pnpm exec playwright test tests/e2e/coding-project-identity.spec.ts`: 2/2 passed, including real UI creation, removal from Project Configuration, selecting the same directory and returning to chat with unchanged configuration/knowledge. Uses isolated temporary user data and project files, no paid provider call.
- Toolchain: repository-pinned pnpm 10.33.4; frozen-lockfile installation succeeded without lockfile changes. The full unrelated suite and installed-package/native macOS/Linux verification were not run.
## Follow-ups
- Integrate this branch and rebuild the client before the user's installed version benefits from the correction. No merge, installer, installation, push or deployment was performed by this task.
## Promotion Candidates
- Target: `.project-docs/40-domain/business-rules.md` and current-state at Integration Gate. Proposal: document that ordinary direct-folder project creation reconnects valid existing metadata; removing a project forgets its catalog registration and preserves its disk state. Evidence: reproduced failure, bounded Main change, 43 unit regressions and 2 real Electron UI tests. Future impact: prevent reintroducing destructive cleanup or treating a preserved project as an unopenable duplicate. Semantic conflicts: none with ADR-008 identity/configuration ownership. Human confirmation: no additional product-direction decision needed for this bounded defect correction; canonical writes remain Integration-only.