detailed-removal-plan.json•12.5 kB
{
  "schema": "memory_document_v2",
  "metadata": {
    "id": "detailed-removal-plan",
    "title": "詳細な不要コード削除計画",
    "documentType": "plan",
    "path": "detailed-removal-plan.json",
    "tags": [
      "plan",
      "cleanup",
      "refactoring",
      "template-removal",
      "markdown-removal"
    ],
    "lastModified": "2025-03-28T19:30:00.000Z",
    "createdAt": "2025-03-28T19:10:00.000Z",
    "version": 1
  },
  "content": {
    "overview": {
      "description": "テンプレート関連コードとマークダウン関連コードの詳細な削除計画。参照関係、削除順序、影響範囲を明確にし、安全に不要コードを削除する。migrationディレクトリは将来的な分離を見据えて現状維持。",
      "executionStrategy": "トップダウンアプローチ - 最初にAPIエンドポイントとコントローラーから削除し、次にサービス層、最後にリポジトリと基底クラスを削除する。各ステップでビルドテストを実行して影響を確認する。"
    },
    "templateRelatedCode": {
      "analysis": {
        "status": "中途半端な実装状態",
        "usagePattern": "GlobalControllerでのみ参照されているが、実際には機能していない",
        "codeQuality": "Template クラスはスケルトン実装のみ。実質的な機能は削除されている状態"
      },
      "removalPriority": "high",
      "components": [
        {
          "name": "Template Interface & Related Types",
          "files": [
            "/packages/mcp/src/domain/templates/ITemplateRepository.ts",
            "/packages/mcp/src/domain/templates/Template.ts",
            "/packages/mcp/src/domain/templates/Section.ts",
            "/packages/mcp/src/domain/templates/types.ts"
          ],
          "removeDependencies": [
            "Language クラスとの依存関係"
          ],
          "considerations": "最後に削除する。まず上位レイヤーからの参照を全て削除する"
        },
        {
          "name": "Template Repository Implementation",
          "files": [
            "/packages/mcp/src/infrastructure/templates/FileTemplateRepository.ts",
            "/packages/mcp/src/infrastructure/templates/JsonTemplateLoader.ts",
            "/packages/mcp/src/infrastructure/templates/TemplateRenderer.ts",
            "/packages/mcp/src/infrastructure/templates/interfaces/ITemplateLoader.ts"
          ],
          "considerations": "DIコンテナでの参照を削除した後に削除"
        },
        {
          "name": "Template Service",
          "files": [
            "/packages/mcp/src/application/templates/TemplateService.ts"
          ],
          "considerations": "コントローラーからの参照を削除した後に削除"
        },
        {
          "name": "Template Controller",
          "files": [
            "/packages/mcp/src/interface/controllers/TemplateController.ts",
            "/packages/mcp/src/interface/controllers/interfaces/ITemplateController.ts"
          ],
          "considerations": "GlobalControllerからの参照を削除した後に削除。controllers/index.tsからのexportも削除"
        },
        {
          "name": "DI Container References",
          "files": [
            "/packages/mcp/src/main/di/providers.ts"
          ],
          "considerations": "templateRepositoryとtemplateServiceの登録部分を削除。GlobalControllerへのオプション注入も削除",
          "codeSnippets": [
            {
              "description": "templateRepositoryの登録",
              "location": "registerInfrastructureServices関数内",
              "startLine": 138,
              "endLine": 175
            },
            {
              "description": "templateServiceの登録",
              "location": "registerApplicationServices関数内",
              "startLine": 415,
              "endLine": 420
            }
          ]
        },
        {
          "name": "GlobalController References",
          "files": [
            "/packages/mcp/src/interface/controllers/GlobalController.ts"
          ],
          "considerations": "templateControllerの参照とインジェクションを削除",
          "codeSnippets": [
            {
              "description": "templateControllerのフィールド宣言",
              "location": "クラス宣言直後",
              "startLine": 28
            },
            {
              "description": "templateControllerのDI",
              "location": "コンストラクタのoptions内",
              "startLine": 42
            }
          ]
        }
      ],
      "testFiles": [
        "/packages/mcp/tests/unit/domain/templates/Template.test.ts",
        "/packages/mcp/tests/unit/domain/templates/Section.test.ts",
        "/packages/mcp/tests/unit/application/templates/TemplateService.test.ts",
        "/packages/mcp/tests/unit/infrastructure/templates/FileTemplateRepository.test.ts",
        "/packages/mcp/tests/unit/infrastructure/templates/JsonTemplateLoader.test.ts",
        "/packages/mcp/tests/unit/interface/controllers/TemplateController.test.ts"
      ],
      "removalSteps": [
        {
          "step": 1,
          "description": "GlobalControllerからtemplateControllerの参照を削除",
          "details": "GlobalControllerのコンストラクタオプションからtemplateControllerを削除し、関連するフィールド宣言も削除"
        },
        {
          "step": 2,
          "description": "DIコンテナからの参照削除",
          "details": "providers.tsからtemplateServiceとtemplateRepositoryの登録部分を削除"
        },
        {
          "step": 3,
          "description": "コントローラーの削除",
          "details": "TemplateControllerクラスとITemplateControllerインターフェースを削除。controllers/index.tsからのexportも削除"
        },
        {
          "step": 4,
          "description": "サービス層の削除",
          "details": "TemplateServiceクラスを削除"
        },
        {
          "step": 5,
          "description": "インフラ層の実装を削除",
          "details": "FileTemplateRepositoryなどの実装クラスを削除"
        },
        {
          "step": 6,
          "description": "ドメイン層のインターフェースと型定義を削除",
          "details": "ITemplateRepositoryインターフェースとTemplateクラスなどを削除"
        }
      ]
    },
    "markdownRelatedCode": {
      "analysis": {
        "status": "部分的に削除済み、一部残存",
        "usagePattern": "JSONフォーマットに完全移行済みでマークダウン関連コードは不要",
        "completionStatus": "BranchControllerから一部削除済み、DocumentPath.tsなどに残存"
      },
      "removalPriority": "high",
      "components": [
        {
          "name": "DocumentPath Markdown Methods",
          "files": [
            "/packages/mcp/src/domain/entities/DocumentPath.ts"
          ],
          "codeSnippets": [
            {
              "description": "isMarkdownメソッド",
              "location": "DocumentPathクラス内",
              "startLine": 77,
              "endLine": 81,
              "code": "public get isMarkdown(): boolean {\n    const ext = this.extension.toLowerCase();\n    return ext === 'md';\n  }"
            },
            {
              "description": "toAlternateFormatメソッド",
              "location": "DocumentPathクラス内",
              "startLine": 137,
              "endLine": 148,
              "code": "public toAlternateFormat(): DocumentPath {\n    if (this.isJSON) {\n      // Convert JSON to Markdown\n      return this.withExtension('md');\n    } else if (this.isMarkdown) {\n      // Convert Markdown to JSON\n      return this.withExtension('json');\n    } else {\n      // Return same path for other file types\n      return this;\n    }\n  }"
            }
          ]
        },
        {
          "name": "Migration Utilities",
          "files": [
            "/packages/mcp/src/migration/utils/MarkdownParser.ts",
            "/packages/mcp/src/migration/MarkdownToJsonMigrator.ts",
            "/packages/mcp/src/migration/converters/ActiveContextConverter.ts",
            "/packages/mcp/src/migration/converters/BranchContextConverter.ts",
            "/packages/mcp/src/migration/converters/ProgressConverter.ts",
            "/packages/mcp/src/migration/converters/SystemPatternsConverter.ts",
            "/packages/mcp/src/migration/converters/GenericConverter.ts",
            "/packages/mcp/src/migration/converters/BaseConverter.ts"
          ],
          "considerations": "マイグレーション用ユーティリティは残すべきか検討。古いバージョンからのアップグレードに必要か?"
        }
      ],
      "testFiles": [
        "/packages/mcp/tests/unit/domain/entities/DocumentPath.test.ts",
        "/packages/mcp/tests/unit/migration/MarkdownMigrationService.test.ts",
        "/packages/mcp/tests/integration/usecase/markdown-to-json/markdown-to-json-migration.test.ts"
      ],
      "removalSteps": [
        {
          "step": 1,
          "description": "DocumentPath.tsからマークダウン関連メソッドを削除",
          "details": "isMarkdownとtoAlternateFormatメソッドに@deprecatedマークが既についているので完全に削除"
        },
        {
          "step": 2,
          "description": "テストコードの修正",
          "details": "DocumentPath.test.tsからisMarkdownとtoAlternateFormatのテストケースを削除"
        },
        {
          "step": 3,
          "description": "マイグレーションユーティリティの扱いを決定",
          "details": "使用頻度やユースケースを検討し、削除するか残すかを決定する"
        }
      ]
    },
    "verificationSteps": [
      {
        "phase": "各コンポーネント削除後",
        "steps": [
          "ビルドエラーがないことを確認",
          "関連テストがパスするか確認(削除したコンポーネントのテストは除く)",
          "ランタイムエラーがないことを確認"
        ]
      },
      {
        "phase": "すべての削除後",
        "steps": [
          "全体のビルドを実行",
          "全テストスイートを実行",
          "サンプルアプリケーションでの基本機能テスト"
        ]
      }
    ],
    "risks": [
      {
        "risk": "間接的な参照の見落とし",
        "severity": "medium",
        "mitigation": "GrepToolを使用して徹底的に参照を検索。コンパイルエラーで検出される可能性も高い"
      },
      {
        "risk": "削除順序の誤り",
        "severity": "low",
        "mitigation": "依存関係の高い順(APIエンドポイント→コントローラー→サービス→リポジトリ→ドメインモデル)で削除"
      },
      {
        "risk": "テスト範囲への影響",
        "severity": "medium",
        "mitigation": "不要なテストも削除するが、周辺コンポーネントのテストが影響を受けないよう注意する"
      }
    ],
    "additionalBenefits": [
      "コードベースのスリム化",
      "ビルド時間の短縮",
      "コンセプトの明確化(JSONベースのアーキテクチャに焦点を当てる)",
      "依存性の削減",
      "メンテナンスコストの削減"
    ],
    "migrationToolDecision": {
      "decision": "マイグレーションツールは将来的に独立パッケージとして分離",
      "reason": "既存のマークダウンファイルから移行したいユーザーがまだ存在する可能性があるため、移行ツールとして独立させて残す価値がある",
      "implementation": "現在はsrc/migrationのまま維持し、将来的にpackages/migrationなどとして分離することを視野に入れる"
    },
    "completionCriteria": [
      "テンプレート関連コードが完全に削除されている",
      "DocumentPath.tsからマークダウン関連メソッドが削除されている",
      "ビルドが成功し、テストがパスする",
      "migrationディレクトリが影響を受けていないこと"
    ]
  }
}