Newer
Older
TelosDB / journals / 20260223-0015-MIMEタイプ対応の追加.md
@楽曲作りまくりおじさん 楽曲作りまくりおじさん 22 hours ago 4 KB feat: add MIME type support to documents

Journal: 20260223-0015-MIMEタイプ対応の追加 (Adding MIME Type Support)

日本語 (Japanese)

1. 作業実施の理由

ユーザーの提案に基づき、documents テーブルに MIME タイプを保持することで、将来的なファイル形式の拡張(PDF, 画像, 各種コード等)に対応しやすくするため。

2. 指示(背景、観点、意図を含む)

  • 背景: 現状はテキストチャンクのみだが、ソースファイルの形式をメタデータとして保持したい。
  • 観点: スキーマの正規化を維持しつつ、自動検知と明示的指定の両方をサポートする。
  • 意図: フロントエンドでの表示切り替えや、バックエンドでの適切なパース処理の布石とする。

3. 指示事項とその対応

  • スキーマ更新: documents テーブルに mime TEXT カラムを追加。
  • 自動検知の実装: mcp.rs 内で、path の拡張子から主要な MIME タイプ(markdown, rust, javascript 等)を自動判別するロジックを追加。
  • ツール更新: add_item_textmime 引数を追加。また、検索結果に mime 情報を返すように変更。
  • ドキュメント更新: データベース仕様書(03_database_specification.md)に新設カラムを反映。

4. 作業詳細

AIエージェントは以下の手順で作業を実施した。

  1. src/backend/src/db.rs を修正し、テーブル作成 SQL に mime カラムを追加。
  2. src/backend/src/mcp.rs をリファクタリング。
    • add_item_text の引数処理と、拡張子ベースの MIME 推測ロジックを実装。
    • すでにドキュメントが存在する場合の MIME アップデート処理を追加。
    • search_text および get_item_by_id の SQL クエリとレスポンス JSON に mime カラムを追加。
  3. docs/specification/03_database_specification.md を更新。
  4. cargo check により、バックエンドの整合性とビルド可能性を確認。

5. AI視点での結果

今回の変更により、TelosDB は単なるテキスト断片の集まりではなく、「型(MIME)を持ったドキュメントの集合」としての性質が強まりました。自動検知ロジックにより、ユーザーが意識せずとも適切なメタデータが蓄積されるようになり、将来的な UI 改善やマルチモーダル対応への強力な基盤となりました。


English

1. Reason for Work

Based on the user's suggestion, adding MIME types to the documents table to facilitate future support for various file formats (PDF, images, various code types, etc.).

2. Instructions (Background, Perspective, Intent)

  • Background: Currently only text chunks are handled, but we want to retain the source file format as metadata.
  • Perspective: Maintain schema normalization while supporting both automatic detection and explicit specification.
  • Intent: Lay the groundwork for UI display logic and appropriate backend parsing processes.

3. Points and Responses

  • Schema Update: Added a mime TEXT column to the documents table.
  • Automatic Detection Implementation: Added logic in mcp.rs to automatically determine common MIME types (markdown, rust, javascript, etc.) based on file extensions.
  • Tool Updates: Added a mime argument to add_item_text and updated search results to include mime information.
  • Documentation Update: Reflected the new column in the database specification (03_database_specification.md).

4. Work Details

The AI agent carried out the work in the following steps:

  1. Modified src/backend/src/db.rs to add the mime column to the table creation SQL.
  2. Refactored src/backend/src/mcp.rs:
    • Implemented argument processing and extension-based MIME inference logic for add_item_text.
    • Added logic to update the MIME type if the document already exists.
    • Added the mime column to SQL queries and JSON responses for search_text and get_item_by_id.
  3. Updated docs/specification/03_database_specification.md.
  4. Verified backend consistency and buildability with cargo check.

5. Results from AI Perspective

With this change, TelosDB has evolved from a collection of text fragments into a "collection of typed (MIME) documents." The automatic detection logic ensures that appropriate metadata is accumulated without extra user effort, providing a strong foundation for future UI improvements and multimodal support.

graph LR
    A[File Path] --> B{Extension?}
    B -->|md| C[text/markdown]
    B -->|rs| D[text/x-rust]
    B -->|other| E[application/octet-stream]
    C --> F[documents.mime]
    D --> F
    E --> F