Skip to content

Fix missing user context migration for v4.x upgrades#846

Closed
catchingknives wants to merge 1 commit intodanielmiessler:mainfrom
catchingknives:fix/v4-user-context-migration
Closed

Fix missing user context migration for v4.x upgrades#846
catchingknives wants to merge 1 commit intodanielmiessler:mainfrom
catchingknives:fix/v4-user-context-migration

Conversation

@catchingknives
Copy link

Summary

  • v4.0 moved user context from skills/PAI/USER/ (v2.5–v3.0) and skills/CORE/USER/ (v2.4) to a new canonical location at PAI/USER/, with CONTEXT_ROUTING.md pointing there
  • The installer never migrates existing user files during upgrades — PAI/USER/ is created empty while user data stays stranded at the old skills/ path
  • Result: 27 of 47 context-routed paths are broken after upgrading. Sessions that search for files write to whichever copy they find first, fragmenting user data across two directories

Fix

Adds a migration step to runRepository() that runs on upgrades:

  1. Recursively copies user files from skills/PAI/USER/ (or skills/CORE/USER/) to PAI/USER/, skipping files that already exist at the destination
  2. Replaces the legacy directory with a symlink (skills/PAI/USER → ../../PAI/USER) so the PAI skill's relative USER/ paths continue to resolve correctly
  3. Only runs when installType === "upgrade" — fresh installs are unaffected

Affected versions

Users upgrading from v2.4, v2.5, or v3.0 to v4.0.0 or v4.0.1.

Test plan

  • Fresh install: verify PAI/USER/ is created with directories + README, migration is skipped
  • Upgrade from v3.0: verify files are copied from skills/PAI/USER/ to PAI/USER/, legacy dir replaced with symlink
  • Upgrade from v2.4: verify files are copied from skills/CORE/USER/ to PAI/USER/
  • Re-run installer after migration: verify symlink is detected and migration is skipped (idempotent)
  • Verify context routing resolves correctly after migration (e.g., PAI/USER/TELOS/BELIEFS.md exists and contains user data)

🤖 Generated with Claude Code

In v2.5–v3.0, user context files (ABOUTME.md, TELOS/, CONTACTS.md,
etc.) lived at skills/PAI/USER/ (or skills/CORE/USER/ in v2.4).
v4.0 introduced PAI/USER/ as the canonical location and
CONTEXT_ROUTING.md points there, but the installer never migrated
existing files during upgrades. This leaves user data stranded at
the old path while context routing points to an empty directory,
breaking 27 of 47 routed paths.

Adds a migration step to runRepository() that:
- Copies user files from skills/PAI/USER or skills/CORE/USER to
  PAI/USER (skip-if-exists to preserve any files already there)
- Replaces the legacy directory with a symlink to PAI/USER so the
  skill's relative USER/ paths continue to resolve correctly
- Only runs on upgrades (fresh installs unaffected)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@danielmiessler
Copy link
Owner

Thank you @catchingknives! The user context migration is merged into PAI v4.0.3. Excellent work — the copyMissing helper with symlink replacement is exactly the right approach for preserving backwards compatibility while migrating to the v4.x canonical paths.

Fix included in: Releases/v4.0.3

danielmiessler added a commit that referenced this pull request Mar 2, 2026
- #800: Inference.ts JSON array parsing (objects + arrays)
- #836: CONTEXT_ROUTING.md dead reference cleanup (29 refs removed)
- #817: WorldThreatModelHarness $PAI_DIR portability
- #846: User context migration for v2.5/v3.0 upgraders

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
HyggeHacker pushed a commit to HyggeHacker/Personal_AI_Infrastructure that referenced this pull request Mar 2, 2026
…nielmiessler#836, danielmiessler#817, danielmiessler#846)

- PR danielmiessler#800: Inference.ts JSON array parsing (dual-candidate strategy)
- PR danielmiessler#836: CONTEXT_ROUTING.md dead reference cleanup (75→31 lines)
- PR danielmiessler#817: WorldThreatModelHarness $PAI_DIR portability (10 instances)
- PR danielmiessler#846: Installer user context migration (copyMissing + migrateUserContext)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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