Skip to Content
PhasesPhase: Key reference unification, preserve module, and regex documentation

Phase: Key reference unification, preserve module, and regex documentation

Status: completed (core + CLI + docs). cleanup --ask shipped — see interactive-key-confirmation.md and the active sprint hub.

Goal

Disprove the mismatch: “rich signals exist, but policy and command behavior are not unified.” Align CLI and core around:

  • core/preserve — single implementation of catalog preserve rules (copyKeys / copyPrefixes) and helpers to filter candidate paths.
  • reference config — defaults + per-command overrides (cleanup, fill, sync, generate) for how literal vs uncertain key evidence is interpreted; schema designed for forward-compatible extension (passthrough where appropriate).
  • buildKeyReferenceContext — one builder combining keySites + dynamic scans (with commented-call filtering and partial/prefix extraction).
  • Commands — cleanup, fill, and sync use the same resolved reference policy + context; fill respects preserve and uncertain prefixes by default.
  • Ripgrep — string-presence evidence (not key proof); structured hits (file:line) for warnings; guard / warn / off.
  • Honest documentationDetection limits, extraction, key-sites-and-dynamic (linked from CLI docs, web /api, and exports).

UX / DX principles locked in

AudienceWhat we optimize for
CLI usersPredictable defaults (reference + preserve); destructive commands fail closed in CI without --yes; logs explain why a key was skipped (uncertain prefix, rg hit).
Integrators (/core)Same types and merge rules as CLI; exports in @zamdevio/i18nprune/core include canAsk, isPreservePath, buildKeyReferenceContext, resolveReferenceConfig.
DocsNo fake accuracy percentages; limits and indirection patterns are explicit; cross-links to docs/regex/*.

Decisions (frozen for this phase)

TopicDecision
Config layoutTop-level reference sibling to policies: reference.defaults + reference.commands.<name> partial overrides, deep-merged per command.
FillrespectPreserve default true; uncertain protect skips fills under uncertain key prefixes (same prefix set as cleanup).
SyncWhen uncertainKeyPolicy is protect, merge + prune keep extra target keys under uncertain prefixes.
rgstringPresence: guard / warn / off; JSON locations for human detail only.
AccuracyHonest narrative only; see Detection limits.

Implementation checklist

  • packages/cli/src/core/preserve/isPreservePath, filterOutPreservedPaths, partitionPreserve.
  • isPreservePath only from core/preserve (not re-exported from core/json).
  • packages/cli/src/core/reference/resolveReferenceConfig, buildKeyReferenceContext, pathUnderAnyUncertainPrefix.
  • packages/cli/src/core/ask/canAsk (gate.ts); interactive gate used by generate, cleanup, fill, locales delete, missing.
  • KeySites: comment skip; uncertainPrefix on template_partial.
  • mergeToTemplateShape + pruneToTemplateShapeuncertainKeepPrefixes for sync.
  • Wire cleanup, fill, sync; rg JSON locations + stringPresence.
  • Config schema + DEFAULT_CONFIG + defineConfig merge for reference.
  • Tests: preserve, reference resolve, merge/prune, schema, canAsk gate.
  • Docs: docs/regex/*, this phase file, cross-links in exports and web (see below).

Documentation map

DocPurpose
docs/regex/README.mdOverview + Detection limits anchor
docs/regex/extraction.mdCall extraction + known gaps table
docs/regex/key-sites-and-dynamic.mdPipelines + merged-text caveats
docs/regex/ripgrep.mdString presence vs static keys
docs/cli/prompts/README.mdPer-command vs shared prompt layout
docs/phases/interactive-key-confirmation.md--ask / grouping / --yes precedence (planned)
docs/exports/core.mdLinks detection limits for API users

Completion criteria

  • Tests passing (pnpm exec vitest run packages/cli).
  • Single isPreservePath in core/preserve.
  • Honest limits documented and linkable (#detection-limits on hosts that slugify headings).

Artifacts

AreaLocation
Preservepackages/cli/src/core/preserve/index.ts
Ask gatepackages/cli/src/core/ask/gate.ts
Reference config + mergepackages/cli/src/core/reference/resolve.ts, types/config/reference.ts, config/schema.ts
Key contextpackages/cli/src/core/reference/context.ts, paths.ts
Public exportspackages/cli/src/exports/core.ts