Skip to content

Refactor replacements.json structure to eliminate duplication #6

@Helmi

Description

@Helmi

Description

The current replacements.json file has a confusing dual structure where project information is stored in both _auto_discovered.projects and project_names.replacements. This creates redundancy and makes the configuration harder to understand and maintain.

Context

  • Project Area: Configuration system / Text-to-Speech replacements
  • Complexity: 4/10 (Moderate - involves refactoring and migration)
  • User Impact: Improves configuration clarity and maintainability

Current Problem

  1. Projects are stored in two places:
    • _auto_discovered.projects (with rich metadata: folder, display_name, pronunciation)
    • project_names.replacements (simple key-value pairs)
  2. The TTS system prioritizes _auto_discovered which is why user replacements work
  3. Auto-discovery adds entries to BOTH locations, creating duplication
  4. README documentation doesn't match the actual structure being used

Technical Details

Affected Files:

  • src/ccnotify/notify.py - Core replacement logic (5 functions to update)
    • load_replacements() (line 430)
    • auto_add_project_to_replacements() (line 287)
    • apply_project_name_replacement() (line 445)
    • get_project_pronunciation() (line 457)
    • apply_command_replacement() (line 474)
  • README.md - Documentation update for "Pronunciation Customization" section
  • User config files - Will need automatic migration

Requirements

  1. Consolidate project storage to a single projects section
  2. Maintain rich metadata structure (folder, display_name, pronunciation)
  3. Provide automatic migration for existing configurations
  4. Add comprehensive examples for commands and patterns
  5. Update documentation to reflect the new structure

Proposed Structure

{
  "projects": {
    "ccnotify": {
      "folder": "-Users-helmi-code-ccnotify",
      "display_name": "CCNotify",
      "pronunciation": "CC notify"
    },
    "agent-zero": {
      "folder": "-Users-helmi-code-agent-zero",
      "display_name": "Agent Zero",
      "pronunciation": "agent zero"
    }
  },
  "commands": {
    "ls": "list",
    "cd": "change directory",
    "rm": "remove",
    "mkdir": "make directory",
    "npm": "N P M",
    "uvx": "U V X"
  },
  "patterns": [
    {
      "pattern": "npm run (\\\\w+)",
      "replacement": "N P M run {1}"
    },
    {
      "pattern": "git (push|pull|commit)",
      "replacement": "git {1}"
    },
    {
      "pattern": "(.+)\\\\.py",
      "replacement": "{1} python file"
    }
  ]
}

Implementation Steps

  • Update load_replacements() to use new default structure
  • Modify auto_add_project_to_replacements() to write to projects section
  • Update get_project_pronunciation() to read from projects[name].pronunciation
  • Update apply_project_name_replacement() to use projects[name].display_name
  • Add migration logic to convert old format to new on first load
  • Add comprehensive command and pattern examples
  • Update README documentation
  • Test migration with existing configurations

Acceptance Criteria

  • No duplicate project data in configuration
  • Existing user configurations are automatically migrated
  • TTS pronunciations continue to work correctly
  • README accurately documents the new structure
  • Rich metadata (folder, display_name, pronunciation) is preserved

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions