Skip to content

refactor: Issues #2〜#8 コード品質改善#20

Merged
ktmage merged 19 commits into
developmentfrom
refactor/2-3-4-5-6-7-8/various-improvements
Feb 28, 2026
Merged

refactor: Issues #2〜#8 コード品質改善#20
ktmage merged 19 commits into
developmentfrom
refactor/2-3-4-5-6-7-8/various-improvements

Conversation

@ktmage

@ktmage ktmage commented Feb 25, 2026

Copy link
Copy Markdown
Owner

Summary

webview のコード品質・保守性を一括で改善する。Atomic Design による再設計、XSS 対策、i18n 修正、CSS Modules 化を実施。

Related Issue

Resolves #2, Resolves #3, Resolves #4, Resolves #5, Resolves #6, Resolves #7, Resolves #8

Changes

#2 Split InputArea.tsx responsibilities

  • InputArea.tsx から以下を分割抽出:
    • FileAttachmentBar(Molecule): クリップボタン・ファイルチップ・ファイルピッカー
    • HashFilePopup(Molecule): # トリガーのファイル選択ポップアップ
    • InputActions(Organism): ModelSelector・Terminal/Settings/Send/Abort ボタン群
  • InputArea はテキスト入力 + IME ハンドリング + 子コンポーネント組み合わせに縮小
  • 各コンポーネントの単体テストを作成

#3 Split ToolPartView.tsx into smaller modules

  • ToolPartView.tsx から以下を分割抽出:
    • DiffView(Molecule): ファイル編集の差分表示
    • FileCreateView(Molecule): ファイル新規作成の表示
    • TodoView(Molecule): Todo リストの表示
  • ToolPartView はルーティング的な Organism に縮小
  • ユーティリティ関数(diff.ts, todo.ts, tool-categories.ts)を utils/ に抽出
  • 各コンポーネント・ユーティリティの単体テストを作成

#4 Split global CSS into component-scoped styles

  • 1,628行の単一 styles.css を CSS Modules に分割
  • 25コンポーネントに .module.css ファイルを配置し、スコープ化されたクラス名に変更
  • styles.css は31行(グローバルリセット + .chat-container レイアウトのみ)に削減
  • コンポーネントごとのディレクトリ構造(Component/Component.tsx + Component.module.css + index.ts)に再編

#5 Add XSS protection for Markdown rendering

  • dompurify パッケージを導入
  • TextPartView.tsxmarked.parse() の出力を DOMPurify.sanitize() で処理してから dangerouslySetInnerHTML に渡すように変更
  • biome-ignore コメントの文言を「DOMPurify でサニタイズ済み」に更新

#6 Consolidate inline SVG icons into shared module

  • 全コンポーネントからインライン SVG を抽出し、共通 IconProps 型 + 名前付きコンポーネントとして atoms/icons/icons.tsx に集約(20種以上)
  • 各コンポーネントの SVG を icons.tsx からの import に置換
  • アイコン単体テストを作成

#7 Fix hardcoded time units in SessionList

  • formatRelativeTime() のハードコード英語略語(m, h, d)をロケールファイル経由に変更
  • en.ts / ja.tstime.now, time.minutes, time.hours, time.days キーを追加
  • 日本語 UI で「5分」「2時間」等が正しく表示されるように修正

#8 Improve state management to reduce props drilling

  • AppContext + 5つのカスタムフック(useSession, useMessages, useProviders, usePermissions, useLocale)を導入
  • App.tsx の14個の useState をドメイン別フックに整理
  • Props drilling を Context 経由に変更し、コンポーネント間の結合度を低減
  • 各フックの単体テストを作成(renderHook 使用)

その他

  • Atomic Design の簡易3層(Atoms / Molecules / Organisms)にディレクトリ構造を再設計
  • 全コンポーネント・全フック・全ユーティリティの単体テストを作成(600テスト)
  • 既存シナリオテスト13件を維持・修正

Checklist

  • npm run build passes
  • npm test passes

…s, and session management

- Implemented `useLocale` hook for managing locale settings and strings.
- Created `useMessages` hook for handling chat messages and their parts.
- Developed `usePermissions` hook for managing tool permission requests.
- Added `useProviders` hook for managing AI model providers and their data.
- Introduced `useSession` hook for managing session states and events.
- Added comprehensive tests for each hook to ensure functionality and correctness.
- Created `AppContext` for centralized state management across the application.
- Implemented TodoHeader component to display summary and toggle list of todos.
- Created TodoView component to list individual todos with their status and priority.
- Added ChatHeader component for managing chat sessions with new session and toggle actions.
- Developed InputArea component for user input with file attachment and model selection features.
- Introduced MessageItem and MessagesArea components for displaying chat messages and interactions.
- Implemented PermissionView for handling permission requests in chat.
- Added SessionList component for managing chat sessions with delete and select functionality.
- Created ToolConfigPanel for configuring tool settings and managing locale options.
- Developed ToolPartView for displaying tool actions and outputs, including todo management.
… TextPartView components with functionality for message handling and context management
…ageItem, MessagesArea, TextPartView) to streamline codebase
…sistent styling and improved functionality across multiple components
…stent styling and improved functionality in ToolConfigPanel and ModelSelector
…I consistency and functionality across various components
- Create ContextIndicator.module.css for context indicator styles
- Create IconButton.module.css for icon button styles
- Create LinkButton.module.css for link button styles
- Create ListItem.module.css for list item styles
- Create StatusItem.module.css for status item styles
- Create StreamingIndicator.module.css for streaming indicator styles
- Create DiffView.module.css for diff view styles
- Create EmptyState.module.css for empty state styles
- Create FileAttachmentBar.module.css for file attachment bar styles
- Create HashFilePopup.module.css for hash file popup styles
- Create ModelSelector.module.css for model selector styles
- Create TodoHeader.module.css for todo header styles
- Create TodoView.module.css for todo view styles
- Create ChatHeader.module.css for chat header styles
- Create InputArea.module.css for input area styles
- Create MessageItem.module.css for message item styles
- Create MessagesArea.module.css for messages area styles
- Create PermissionView.module.css for permission view styles
- Create SessionList.module.css for session list styles
- Create ToolConfigPanel.module.css for tool config panel styles
- Create ToolPartView.module.css for tool part view styles
- Add css-modules.d.ts for TypeScript support of CSS modules
- Implemented MessageItem component to display user and assistant messages with editing capabilities.
- Created MessagesArea component to manage and display a list of messages, including checkpoint functionality.
- Added PermissionView component to handle permission requests with user actions.
- Introduced ToolConfigPanel for configuring tool settings and locale preferences.
- Developed ToolPartView to visualize tool actions and outputs, including support for todos and file edits.
- Styled components with corresponding CSS modules for improved UI consistency.
- Added SessionList component to manage and display user sessions with delete functionality.
@ktmage ktmage changed the title Refactor/2-3-4-5-6-7-8/various-improvements refactor: Issues #2〜#8 コード品質改善 Feb 28, 2026
@ktmage ktmage marked this pull request as ready for review February 28, 2026 15:07
@ktmage ktmage merged commit e68cb0f into development Feb 28, 2026
1 check passed
@ktmage ktmage deleted the refactor/2-3-4-5-6-7-8/various-improvements branch March 1, 2026 17:58
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.

1 participant