Skip to content

Extract shared engine/pai-paths.ts to dedupe migrator helpers#163

Merged
virtualian merged 1 commit intomainfrom
162-extract-shared-pai-paths
Apr 27, 2026
Merged

Extract shared engine/pai-paths.ts to dedupe migrator helpers#163
virtualian merged 1 commit intomainfrom
162-extract-shared-pai-paths

Conversation

@virtualian
Copy link
Copy Markdown
Owner

Summary

  • Closes Extract shared engine/pai-paths.ts: deduplicate getPaiHomeDir + cpFilter across three migrators (#160 follow-up) #162.
  • New engine/pai-paths.ts exports getPaiHome / getPaiSkillsDir / getPaiCommandsDir resolvers, an isJunkEntry(name, opts) predicate, and a makeCpFilter(opts) factory.
  • Each call site passes options that reproduce its prior local behaviour exactly:
    • skill-migration.ts: isJunkEntry(name) (default — backup-suffix is junk)
    • command-migration.ts: isJunkEntry(name, { extraEntries: COMMAND_EXTRA_JUNK }) (.gitkeep extension)
    • pai-runtime-migration.ts: makeCpFilter({ allowBackups: true }) (no backup-suffix matching, matching its prior local isIgnored)
    • actions.ts: getPaiHome() (replaces a 4th inlined copy that silently dropped the $HOME... prefix branch — latent bug closed as a side-benefit; surfaced by /simplify Reuse agent during review and approved as in-scope)
  • Diff: −127 / +142 across 5 files; net behaviour-preserving dedup with one incidental bug fix.

Out-of-scope follow-ups (not addressed here)

The /simplify review surfaced further duplication worth filing as separate issues:

  • migratePackmigrateCommand 80-line state machines (drift backup → renameSync+EXDEV/ENOTEMPTY fallback → symlinkSync rollback) — near-byte-identical
  • Backup-timestamp formatter new Date().toISOString().replace(/[:.]/g, "-") duplicated in skill-migration.ts:154 and command-migration.ts:148; lives next to BACKUP_SUFFIX_RE semantically
  • classifySkillDirclassifyCommandFile parallel structure
  • memory-migration.ts:88-94 IGNORED_BASENAMES + isIgnoredName could fold into isJunkEntry({ extraEntries, allowBackups: true })

Test plan

  • `bun test engine/skill-migration.test.ts engine/memory-migration.test.ts` from `Releases/v4.0.3+/.claude/PAI-Install/` — 25 pass / 0 fail / 84 expect() calls
  • grep for `homedir`, `IGNORED_ENTRIES`, `BACKUP_SUFFIX_RE`, local `isIgnored`, local resolvers across the four migration modules — no inlined copies remain
  • Public exports preserved: `migratePerPackSymlinks`, `classifySkillDir`, `migratePerPackCommands`, `classifyCommandFile`, `migratePaiRuntime`, plus `__testInternals` shape on `skill-migration.ts`
  • `Tools/verify-security-validator.sh` — runtime-level test against `~/.pai/`; only meaningful after a fresh install. Not gating this PR.

Three migration modules (skill-migration, command-migration,
pai-runtime-migration) inlined byte-identical PAI_DIR resolvers and
junk-file predicates; actions.ts had a 4th partial copy missing the
$HOME-prefix branch. Pure dedup refactor — 25 engine tests still pass.
@virtualian virtualian merged commit 2a44839 into main Apr 27, 2026
@virtualian virtualian deleted the 162-extract-shared-pai-paths branch April 27, 2026 20:37
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.

Extract shared engine/pai-paths.ts: deduplicate getPaiHomeDir + cpFilter across three migrators (#160 follow-up)

1 participant